Skip to content

Commit 0569375

Browse files
committed
style: add prettier, run prettier
1 parent 9ae2a64 commit 0569375

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+2475
-1995
lines changed

package.json

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"copy_src_es": "shx mkdir -p ./dist/es/src && shx cp -r ./src/* ./dist/es/src",
1818
"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",
1919
"lint": "tslint -c tslint.json src/*.ts --project ./tsconfig.json \"src/**/*.ts\" \"./test/**/*.ts\" -e \"./test/e2e/*.ts\"",
20+
"precommit": "lint-staged",
2021
"publish_all": "ts-node ./tools/publish.ts",
2122
"start": "webpack-dev-server --inline --colors --progress --port 3000",
2223
"start-demo": "webpack-dev-server --config ./example/webpack.config.js --inline --colors --progress --port 3001 --open",
@@ -70,11 +71,14 @@
7071
"css-loader": "^1.0.0",
7172
"extract-text-webpack-plugin": "^4.0.0-beta.0",
7273
"html-webpack-plugin": "^3.0.6",
74+
"husky": "^0.14.3",
75+
"lint-staged": "^7.2.0",
7376
"madge": "^3.0.1",
7477
"moment": "^2.21.0",
7578
"node-watch": "^0.5.8",
7679
"npm-run-all": "^4.1.2",
7780
"nyc": "^12.0.1",
81+
"prettier": "^1.14.0",
7882
"raw-loader": "^0.5.1",
7983
"rxjs": "^6.2.2",
8084
"shelljs": "^0.8.1",
@@ -100,8 +104,23 @@
100104
"nesthydrationjs": "^1.0.5"
101105
},
102106
"peerDependencies": {
103-
"rxjs": "^5.5.0",
107+
"rxjs": "^6.0.0",
104108
"tslib": "^1.9.0"
105109
},
106-
"typings": "./index.d.ts"
110+
"typings": "./index.d.ts",
111+
"prettier": {
112+
"printWidth": 120,
113+
"semi": false,
114+
"trailingComma": "all",
115+
"singleQuote": true,
116+
"arrowParens": "always",
117+
"parser": "typescript"
118+
},
119+
"lint-staged": {
120+
"*.ts": [
121+
"prettier --write",
122+
"tslint -c tslint.json -p tsconfig.json --fix",
123+
"git add"
124+
]
125+
}
107126
}

src/addons/aggresive-optimizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const compareFn = function(ctx: any, left: any, right: any) {
3333
export const aggresiveOptimizer = () => {
3434
lf.ObserverRegistry.Entry_.prototype.updateResults = function(newResults: any[]) {
3535
const oldList: any = (this.lastResults_ && this.lastResults_.entries) || []
36-
const newList: any = (newResults.entries) || []
36+
const newList: any = newResults.entries || []
3737

3838
const hasChanges = compareFn(this.diffCalculator_, oldList, newList)
3939
this.lastResults_ = newResults

src/exception/Exception.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
export class ReactiveDBException extends Error {
2-
32
constructor(message: string) {
43
super(message)
5-
this.name = 'ReactiveDBError';
6-
(Object as any).setPrototypeOf(this, ReactiveDBException.prototype)
4+
this.name = 'ReactiveDBError'
5+
Object.setPrototypeOf(this, ReactiveDBException.prototype)
76
}
8-
97
}

src/exception/database.ts

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
import { ReactiveDBException } from './Exception'
22

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

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

9-
export const InvalidQuery =
10-
() => new ReactiveDBException('Only navigation properties were included in query.')
9+
export const InvalidQuery = () => new ReactiveDBException('Only navigation properties were included in query.')
1110

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

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

18-
export const NotImplemented =
19-
() => new ReactiveDBException('Not implemented yet.')
17+
export const NotImplemented = () => new ReactiveDBException('Not implemented yet.')
2018

21-
export const UnexpectedRelationship =
22-
() => new ReactiveDBException('Unexpected relationship was specified.')
19+
export const UnexpectedRelationship = () => new ReactiveDBException('Unexpected relationship was specified.')
2320

24-
export const InvalidType =
25-
(expect?: [string, string]) => {
26-
let message = 'Unexpected data type'
27-
if (expect) {
28-
message += `, expect ${expect[0]} but got ${expect[1]}`
29-
}
30-
return new ReactiveDBException(message + '.')
21+
export const InvalidType = (expect?: [string, string]) => {
22+
let message = 'Unexpected data type'
23+
if (expect) {
24+
message += `, expect ${expect[0]} but got ${expect[1]}`
3125
}
26+
return new ReactiveDBException(message + '.')
27+
}
3228

33-
export const UnexpectedTransactionUse =
34-
() => new ReactiveDBException('Please use Database#transaction to get a transaction scope first.')
29+
export const UnexpectedTransactionUse = () =>
30+
new ReactiveDBException('Please use Database#transaction to get a transaction scope first.')
3531

36-
export const PrimaryKeyNotProvided =
37-
() => new ReactiveDBException(`Primary key was not provided.`)
32+
export const PrimaryKeyNotProvided = () => new ReactiveDBException(`Primary key was not provided.`)
3833

39-
export const PrimaryKeyConflict =
40-
() => new ReactiveDBException(`Primary key was already provided.`)
34+
export const PrimaryKeyConflict = () => new ReactiveDBException(`Primary key was already provided.`)
4135

42-
export const DatabaseIsNotEmpty =
43-
() => new ReactiveDBException('Method: load cannnot be invoked since database is not empty.')
36+
export const DatabaseIsNotEmpty = () =>
37+
new ReactiveDBException('Method: load cannnot be invoked since database is not empty.')
4438

45-
export const NotConnected =
46-
() => new ReactiveDBException('Method: dispose cannnot be invoked before database is connected.')
39+
export const NotConnected = () =>
40+
new ReactiveDBException('Method: dispose cannnot be invoked before database is connected.')

src/exception/token.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { ReactiveDBException } from './Exception'
22

3-
export const TokenConsumed =
4-
() => new ReactiveDBException('QueryToken was already consumed.')
3+
export const TokenConsumed = () => new ReactiveDBException('QueryToken was already consumed.')
54

6-
export const TokenConcatFailed =
7-
(msg?: string) => {
8-
const errMsg = 'Token cannot be concated' + `${ msg ? ' due to: ' + msg : '' }.`
9-
return new ReactiveDBException(errMsg)
10-
}
5+
export const TokenConcatFailed = (msg?: string) => {
6+
const errMsg = 'Token cannot be concated' + `${msg ? ' due to: ' + msg : ''}.`
7+
return new ReactiveDBException(errMsg)
8+
}

src/interface/enum.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ export enum RDBType {
66
NUMBER,
77
OBJECT,
88
STRING,
9-
LITERAL_ARRAY
9+
LITERAL_ARRAY,
1010
}
1111

1212
export enum Relationship {
1313
oneToMany = 500,
1414
oneToOne = 501,
15-
manyToMany = 502
15+
manyToMany = 502,
1616
}
1717

1818
export enum DataStoreType {
1919
INDEXED_DB = 0,
2020
MEMORY = 1,
2121
LOCAL_STORAGE = 2,
2222
WEB_SQL = 3,
23-
OBSERVABLE_STORE = 4
23+
OBSERVABLE_STORE = 4,
2424
}
2525

2626
export enum StatementType {
2727
Insert = 1001,
2828
Update = 1002,
2929
Delete = 1003,
30-
Select = 1004
30+
Select = 1004,
3131
}
3232

3333
export enum JoinMode {
3434
imlicit = 2001,
35-
explicit = 2002
35+
explicit = 2002,
3636
}
3737

3838
export enum LeafType {

src/interface/index.ts

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { Observable, PartialObserver } from 'rxjs'
22
import { RDBType, Relationship, LeafType, StatementType, JoinMode, DataStoreType } from './enum'
33

4-
export type DeepPartial<T> = {
5-
[K in keyof T]?: Partial<T[K]>
6-
}
4+
export type DeepPartial<T> = { [K in keyof T]?: Partial<T[K]> }
75

86
export interface SchemaMetadata<T> {
97
type: RDBType | Relationship
@@ -20,13 +18,9 @@ export interface SchemaMetadata<T> {
2018
}
2119
}
2220

23-
export type TableShape<T> = lf.schema.Table & {
24-
[P in keyof T]: lf.schema.Column
25-
}
21+
export type TableShape<T> = lf.schema.Table & { [P in keyof T]: lf.schema.Column }
2622

27-
export type SchemaDef<T> = {
28-
[P in keyof T]: SchemaMetadata<T[P]>
29-
} & {
23+
export type SchemaDef<T> = { [P in keyof T]: SchemaMetadata<T[P]> } & {
3024
dispose?: SchemaDisposeFunction<T>
3125
['@@dispose']?: SchemaDisposeFunction<T>
3226
}
@@ -70,7 +64,7 @@ export interface Query<T> extends Clause<T> {
7064
}
7165

7266
export interface JoinInfo {
73-
table: lf.schema.Table,
67+
table: lf.schema.Table
7468
predicate: lf.Predicate
7569
}
7670

@@ -100,8 +94,8 @@ export interface TraverseContext {
10094

10195
export interface UpsertContext {
10296
mapper: Function | null
103-
isNavigatorLeaf: boolean,
104-
visited: boolean,
97+
isNavigatorLeaf: boolean
98+
visited: boolean
10599
}
106100

107101
export interface SelectContext {
@@ -120,18 +114,17 @@ export interface NavigatorLeaf {
120114
assocaiation: Association
121115
}
122116

123-
export type ScopedHandler = [
124-
(where?: Predicate<any>) => Observable<any>,
125-
(ret: any[]) => void
126-
]
117+
export type ScopedHandler = [(where?: Predicate<any>) => Observable<any>, (ret: any[]) => void]
127118

128-
export type SchemaDisposeFunction<T> =
129-
(entities: Partial<T>[], scopedHandler: (name: string) => ScopedHandler) => Observable<Partial<T>>
119+
export type SchemaDisposeFunction<T> = (
120+
entities: Partial<T>[],
121+
scopedHandler: (name: string) => ScopedHandler,
122+
) => Observable<Partial<T>>
130123

131124
export interface ShapeMatcher {
132125
mainTable: lf.schema.Table
133126
pk: {
134-
name: string,
127+
name: string
135128
queried: boolean
136129
}
137130
definition: Object
@@ -163,7 +156,7 @@ export interface PredicateMeta<T> {
163156
$match: RegExp
164157
$notMatch: RegExp
165158
$has: ValueLiteral
166-
$between: [ number, number ]
159+
$between: [number, number]
167160
$in: ValueLiteral[]
168161
$isNull: boolean
169162
$isNotNull: boolean
@@ -175,9 +168,7 @@ export type Predicate<T> = {
175168

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

178-
export type TransactionDescriptor<T> = {
179-
[P in keyof T]: PropertyDescriptor
180-
}
171+
export type TransactionDescriptor<T> = { [P in keyof T]: PropertyDescriptor }
181172

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

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

189-
export type TransactionEffects<T = any> = PartialObserver<T> | { next: (x: T) => void, error?: (e: any) => void, complete?: () => void }
180+
export type TransactionEffects<T = any> =
181+
| PartialObserver<T>
182+
| { next: (x: T) => void; error?: (e: any) => void; complete?: () => void }

src/shared/Logger.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export enum Level {
33
info = 20,
44
warning = 30,
55
error = 40,
6-
test = 1000
6+
test = 1000,
77
}
88

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

1818
export class ContextLogger {
19-
2019
public destroy = (): void => void 0
2120
private effects: Map<keyof LoggerAdapter, Function[]> = new Map()
2221

2322
constructor(
2423
private name: string,
2524
private level: Level,
2625
private formatter?: Formatter,
27-
private adapter: LoggerAdapter = console
28-
) { }
26+
private adapter: LoggerAdapter = console,
27+
) {}
2928

3029
private invoke(method: string, message: any[]) {
3130
let output = ''
@@ -34,7 +33,7 @@ export class ContextLogger {
3433
output = this.formatter.apply(this, params)
3534
}
3635
this.adapter[method].call(this.adapter, output)
37-
const fns = (this.effects.get(method as (keyof LoggerAdapter)) || [])
36+
const fns = this.effects.get(method as keyof LoggerAdapter) || []
3837
fns.forEach((fn) => fn(...message))
3938
}
4039

@@ -92,19 +91,17 @@ export class ContextLogger {
9291
clearEffects() {
9392
this.effects.clear()
9493
}
95-
9694
}
9795

9896
export class Logger {
99-
10097
private static contextMap = new Map<string, ContextLogger>()
10198
private static defaultLevel = Level.debug
10299
private static outputLogger = new ContextLogger('[ReactiveDB]', Logger.defaultLevel, (name, _, message) => {
103-
const output = Array.isArray(message) ? message.join('') : message
104-
const current = new Date()
105-
const prefix = name ? `[${name}] ` : ''
106-
return `${prefix}at ${current.toLocaleString()}: \r\n ` + output
107-
})
100+
const output = Array.isArray(message) ? message.join('') : message
101+
const current = new Date()
102+
const prefix = name ? `[${name}] ` : ''
103+
return `${prefix}at ${current.toLocaleString()}: \r\n ` + output
104+
})
108105

109106
static get(name: string, formatter?: Formatter, level?: Level, adapter: LoggerAdapter = console) {
110107
const logger = Logger.contextMap.get(name)
@@ -141,7 +138,6 @@ export class Logger {
141138
static error(...message: string[]) {
142139
Logger.outputLogger.error(...message)
143140
}
144-
145141
}
146142

147143
const envifyLevel = () => {

0 commit comments

Comments
 (0)