Skip to content

Commit

Permalink
style: add prettier, run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Aug 2, 2018
1 parent 9ae2a64 commit 0569375
Show file tree
Hide file tree
Showing 63 changed files with 2,475 additions and 1,995 deletions.
23 changes: 21 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"copy_src_es": "shx mkdir -p ./dist/es/src && shx cp -r ./src/* ./dist/es/src",
"cover": "rm -rf ./.nyc_output ./coverage && NODE_ENV=test nyc --reporter=html --reporter=lcov --exclude=node_modules --exclude=spec-js/test --exclude=spec-js/src/storage/lovefield.js --exclude=spec-js/src/shared/Logger.js --exclude=spec-js/src/utils/option.js --exclude=spec-js/src/utils/valid.js --exclude=spec-js/src/addons/aggresive-optimizer.js tman --mocha spec-js/test/run.js && nyc report",
"lint": "tslint -c tslint.json src/*.ts --project ./tsconfig.json \"src/**/*.ts\" \"./test/**/*.ts\" -e \"./test/e2e/*.ts\"",
"precommit": "lint-staged",
"publish_all": "ts-node ./tools/publish.ts",
"start": "webpack-dev-server --inline --colors --progress --port 3000",
"start-demo": "webpack-dev-server --config ./example/webpack.config.js --inline --colors --progress --port 3001 --open",
Expand Down Expand Up @@ -70,11 +71,14 @@
"css-loader": "^1.0.0",
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"html-webpack-plugin": "^3.0.6",
"husky": "^0.14.3",
"lint-staged": "^7.2.0",
"madge": "^3.0.1",
"moment": "^2.21.0",
"node-watch": "^0.5.8",
"npm-run-all": "^4.1.2",
"nyc": "^12.0.1",
"prettier": "^1.14.0",
"raw-loader": "^0.5.1",
"rxjs": "^6.2.2",
"shelljs": "^0.8.1",
Expand All @@ -100,8 +104,23 @@
"nesthydrationjs": "^1.0.5"
},
"peerDependencies": {
"rxjs": "^5.5.0",
"rxjs": "^6.0.0",
"tslib": "^1.9.0"
},
"typings": "./index.d.ts"
"typings": "./index.d.ts",
"prettier": {
"printWidth": 120,
"semi": false,
"trailingComma": "all",
"singleQuote": true,
"arrowParens": "always",
"parser": "typescript"
},
"lint-staged": {
"*.ts": [
"prettier --write",
"tslint -c tslint.json -p tsconfig.json --fix",
"git add"
]
}
}
2 changes: 1 addition & 1 deletion src/addons/aggresive-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const compareFn = function(ctx: any, left: any, right: any) {
export const aggresiveOptimizer = () => {
lf.ObserverRegistry.Entry_.prototype.updateResults = function(newResults: any[]) {
const oldList: any = (this.lastResults_ && this.lastResults_.entries) || []
const newList: any = (newResults.entries) || []
const newList: any = newResults.entries || []

const hasChanges = compareFn(this.diffCalculator_, oldList, newList)
this.lastResults_ = newResults
Expand Down
6 changes: 2 additions & 4 deletions src/exception/Exception.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
export class ReactiveDBException extends Error {

constructor(message: string) {
super(message)
this.name = 'ReactiveDBError';
(Object as any).setPrototypeOf(this, ReactiveDBException.prototype)
this.name = 'ReactiveDBError'
Object.setPrototypeOf(this, ReactiveDBException.prototype)
}

}
56 changes: 25 additions & 31 deletions src/exception/database.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
import { ReactiveDBException } from './Exception'

export const NonExistentTable =
(tableName: string) => new ReactiveDBException(`Table: \`${tableName}\` cannot be found.`)
export const NonExistentTable = (tableName: string) =>
new ReactiveDBException(`Table: \`${tableName}\` cannot be found.`)

export const UnmodifiableTable =
() => new ReactiveDBException(`Method: defineSchema cannot be invoked since schema is existed or database is connected`)
export const UnmodifiableTable = () =>
new ReactiveDBException(`Method: defineSchema cannot be invoked since schema is existed or database is connected`)

export const InvalidQuery =
() => new ReactiveDBException('Only navigation properties were included in query.')
export const InvalidQuery = () => new ReactiveDBException('Only navigation properties were included in query.')

export const AliasConflict =
(column: string, tableName: string) => new ReactiveDBException(`Definition conflict, Column: \`${column}\` on table: ${tableName}.`)
export const AliasConflict = (column: string, tableName: string) =>
new ReactiveDBException(`Definition conflict, Column: \`${column}\` on table: ${tableName}.`)

export const GraphFailed =
(err: Error) => new ReactiveDBException(`Graphify query result failed, due to: ${err.message}.`)
export const GraphFailed = (err: Error) =>
new ReactiveDBException(`Graphify query result failed, due to: ${err.message}.`)

export const NotImplemented =
() => new ReactiveDBException('Not implemented yet.')
export const NotImplemented = () => new ReactiveDBException('Not implemented yet.')

export const UnexpectedRelationship =
() => new ReactiveDBException('Unexpected relationship was specified.')
export const UnexpectedRelationship = () => new ReactiveDBException('Unexpected relationship was specified.')

export const InvalidType =
(expect?: [string, string]) => {
let message = 'Unexpected data type'
if (expect) {
message += `, expect ${expect[0]} but got ${expect[1]}`
}
return new ReactiveDBException(message + '.')
export const InvalidType = (expect?: [string, string]) => {
let message = 'Unexpected data type'
if (expect) {
message += `, expect ${expect[0]} but got ${expect[1]}`
}
return new ReactiveDBException(message + '.')
}

export const UnexpectedTransactionUse =
() => new ReactiveDBException('Please use Database#transaction to get a transaction scope first.')
export const UnexpectedTransactionUse = () =>
new ReactiveDBException('Please use Database#transaction to get a transaction scope first.')

export const PrimaryKeyNotProvided =
() => new ReactiveDBException(`Primary key was not provided.`)
export const PrimaryKeyNotProvided = () => new ReactiveDBException(`Primary key was not provided.`)

export const PrimaryKeyConflict =
() => new ReactiveDBException(`Primary key was already provided.`)
export const PrimaryKeyConflict = () => new ReactiveDBException(`Primary key was already provided.`)

export const DatabaseIsNotEmpty =
() => new ReactiveDBException('Method: load cannnot be invoked since database is not empty.')
export const DatabaseIsNotEmpty = () =>
new ReactiveDBException('Method: load cannnot be invoked since database is not empty.')

export const NotConnected =
() => new ReactiveDBException('Method: dispose cannnot be invoked before database is connected.')
export const NotConnected = () =>
new ReactiveDBException('Method: dispose cannnot be invoked before database is connected.')
12 changes: 5 additions & 7 deletions src/exception/token.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ReactiveDBException } from './Exception'

export const TokenConsumed =
() => new ReactiveDBException('QueryToken was already consumed.')
export const TokenConsumed = () => new ReactiveDBException('QueryToken was already consumed.')

export const TokenConcatFailed =
(msg?: string) => {
const errMsg = 'Token cannot be concated' + `${ msg ? ' due to: ' + msg : '' }.`
return new ReactiveDBException(errMsg)
}
export const TokenConcatFailed = (msg?: string) => {
const errMsg = 'Token cannot be concated' + `${msg ? ' due to: ' + msg : ''}.`
return new ReactiveDBException(errMsg)
}
10 changes: 5 additions & 5 deletions src/interface/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ export enum RDBType {
NUMBER,
OBJECT,
STRING,
LITERAL_ARRAY
LITERAL_ARRAY,
}

export enum Relationship {
oneToMany = 500,
oneToOne = 501,
manyToMany = 502
manyToMany = 502,
}

export enum DataStoreType {
INDEXED_DB = 0,
MEMORY = 1,
LOCAL_STORAGE = 2,
WEB_SQL = 3,
OBSERVABLE_STORE = 4
OBSERVABLE_STORE = 4,
}

export enum StatementType {
Insert = 1001,
Update = 1002,
Delete = 1003,
Select = 1004
Select = 1004,
}

export enum JoinMode {
imlicit = 2001,
explicit = 2002
explicit = 2002,
}

export enum LeafType {
Expand Down
41 changes: 17 additions & 24 deletions src/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Observable, PartialObserver } from 'rxjs'
import { RDBType, Relationship, LeafType, StatementType, JoinMode, DataStoreType } from './enum'

export type DeepPartial<T> = {
[K in keyof T]?: Partial<T[K]>
}
export type DeepPartial<T> = { [K in keyof T]?: Partial<T[K]> }

export interface SchemaMetadata<T> {
type: RDBType | Relationship
Expand All @@ -20,13 +18,9 @@ export interface SchemaMetadata<T> {
}
}

export type TableShape<T> = lf.schema.Table & {
[P in keyof T]: lf.schema.Column
}
export type TableShape<T> = lf.schema.Table & { [P in keyof T]: lf.schema.Column }

export type SchemaDef<T> = {
[P in keyof T]: SchemaMetadata<T[P]>
} & {
export type SchemaDef<T> = { [P in keyof T]: SchemaMetadata<T[P]> } & {
dispose?: SchemaDisposeFunction<T>
['@@dispose']?: SchemaDisposeFunction<T>
}
Expand Down Expand Up @@ -70,7 +64,7 @@ export interface Query<T> extends Clause<T> {
}

export interface JoinInfo {
table: lf.schema.Table,
table: lf.schema.Table
predicate: lf.Predicate
}

Expand Down Expand Up @@ -100,8 +94,8 @@ export interface TraverseContext {

export interface UpsertContext {
mapper: Function | null
isNavigatorLeaf: boolean,
visited: boolean,
isNavigatorLeaf: boolean
visited: boolean
}

export interface SelectContext {
Expand All @@ -120,18 +114,17 @@ export interface NavigatorLeaf {
assocaiation: Association
}

export type ScopedHandler = [
(where?: Predicate<any>) => Observable<any>,
(ret: any[]) => void
]
export type ScopedHandler = [(where?: Predicate<any>) => Observable<any>, (ret: any[]) => void]

export type SchemaDisposeFunction<T> =
(entities: Partial<T>[], scopedHandler: (name: string) => ScopedHandler) => Observable<Partial<T>>
export type SchemaDisposeFunction<T> = (
entities: Partial<T>[],
scopedHandler: (name: string) => ScopedHandler,
) => Observable<Partial<T>>

export interface ShapeMatcher {
mainTable: lf.schema.Table
pk: {
name: string,
name: string
queried: boolean
}
definition: Object
Expand Down Expand Up @@ -163,7 +156,7 @@ export interface PredicateMeta<T> {
$match: RegExp
$notMatch: RegExp
$has: ValueLiteral
$between: [ number, number ]
$between: [number, number]
$in: ValueLiteral[]
$isNull: boolean
$isNotNull: boolean
Expand All @@ -175,9 +168,7 @@ export type Predicate<T> = {

export { StatementType, JoinMode, LeafType, Relationship, DataStoreType, RDBType }

export type TransactionDescriptor<T> = {
[P in keyof T]: PropertyDescriptor
}
export type TransactionDescriptor<T> = { [P in keyof T]: PropertyDescriptor }

export type TransactionHandler = {
commit: () => Observable<ExecutorResult>
Expand All @@ -186,4 +177,6 @@ export type TransactionHandler = {

export type Transaction<T> = [T, TransactionHandler]

export type TransactionEffects<T = any> = PartialObserver<T> | { next: (x: T) => void, error?: (e: any) => void, complete?: () => void }
export type TransactionEffects<T = any> =
| PartialObserver<T>
| { next: (x: T) => void; error?: (e: any) => void; complete?: () => void }
22 changes: 9 additions & 13 deletions src/shared/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export enum Level {
info = 20,
warning = 30,
error = 40,
test = 1000
test = 1000,
}

export interface LoggerAdapter {
Expand All @@ -16,16 +16,15 @@ export interface LoggerAdapter {
export type Formatter = (name: string, level: Level, ...message: any[]) => string

export class ContextLogger {

public destroy = (): void => void 0
private effects: Map<keyof LoggerAdapter, Function[]> = new Map()

constructor(
private name: string,
private level: Level,
private formatter?: Formatter,
private adapter: LoggerAdapter = console
) { }
private adapter: LoggerAdapter = console,
) {}

private invoke(method: string, message: any[]) {
let output = ''
Expand All @@ -34,7 +33,7 @@ export class ContextLogger {
output = this.formatter.apply(this, params)
}
this.adapter[method].call(this.adapter, output)
const fns = (this.effects.get(method as (keyof LoggerAdapter)) || [])
const fns = this.effects.get(method as keyof LoggerAdapter) || []
fns.forEach((fn) => fn(...message))
}

Expand Down Expand Up @@ -92,19 +91,17 @@ export class ContextLogger {
clearEffects() {
this.effects.clear()
}

}

export class Logger {

private static contextMap = new Map<string, ContextLogger>()
private static defaultLevel = Level.debug
private static outputLogger = new ContextLogger('[ReactiveDB]', Logger.defaultLevel, (name, _, message) => {
const output = Array.isArray(message) ? message.join('') : message
const current = new Date()
const prefix = name ? `[${name}] ` : ''
return `${prefix}at ${current.toLocaleString()}: \r\n ` + output
})
const output = Array.isArray(message) ? message.join('') : message
const current = new Date()
const prefix = name ? `[${name}] ` : ''
return `${prefix}at ${current.toLocaleString()}: \r\n ` + output
})

static get(name: string, formatter?: Formatter, level?: Level, adapter: LoggerAdapter = console) {
const logger = Logger.contextMap.get(name)
Expand Down Expand Up @@ -141,7 +138,6 @@ export class Logger {
static error(...message: string[]) {
Logger.outputLogger.error(...message)
}

}

const envifyLevel = () => {
Expand Down
Loading

0 comments on commit 0569375

Please sign in to comment.