Skip to content

Commit 2988285

Browse files
authored
Merge branch 'master' into feature/query-token-traces
2 parents 11cb1cc + d94eae9 commit 2988285

File tree

15 files changed

+3289
-4972
lines changed

15 files changed

+3289
-4972
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defaults: &defaults
22
working_directory: ~/ReactiveDB
33
docker:
4-
- image: circleci/node:10
4+
- image: circleci/node:16
55

66
version: 2
77
jobs:
@@ -41,7 +41,7 @@ jobs:
4141
- run: npm run test_O1
4242
- run:
4343
name: test-coverage
44-
command: cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
44+
command: npx codecov -f coverage/*.json
4545

4646
deploy:
4747
<<: *defaults

.github/FUNDING.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: [brooooooklyn]
4+

example/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
},
2323
"homepage": "https://github.com/teambition/ReactiveDB#readme",
2424
"dependencies": {
25-
"antd": "^2.7.3",
26-
"react": "^15.4.2",
27-
"react-dom": "^15.4.2"
25+
"antd": "^4.0.0",
26+
"react": "^17.0.0",
27+
"react-dom": "^17.0.0"
2828
},
2929
"devDependencies": {
30-
"typescript": "^2.2.1"
30+
"typescript": "^4.0.0"
3131
}
3232
}

package.json

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
"clean_dist_cjs": "rm -rf ./dist/cjs",
1212
"clean_dist_es": "rm -rf ./dist/es",
1313
"check_circular_dependencies": "madge ./dist/cjs --circular",
14-
"compile_cjs": " tsc dist/cjs/src/index.ts dist/cjs/src/proxy/index.ts -m commonjs --outDir dist/cjs --sourcemap --target ES5 -d --diagnostics --pretty --strict --noImplicitReturns --noUnusedLocals --noUnusedParameters --strict --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --importHelpers --lib es5,es2015,es2016,es2017",
15-
"compile_module_es": "tsc dist/es/src/index.ts dist/es/src/proxy/index.ts -m ES2015 --outDir dist/es --sourcemap --target ES5 -d --diagnostics --pretty --strict --noImplicitReturns --noUnusedLocals --noUnusedParameters --strict --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --importHelpers --lib es5,es2015,es2016,es2017",
14+
"compile_cjs": " tsc dist/cjs/src/index.ts dist/cjs/src/proxy/index.ts -m commonjs --outDir dist/cjs --sourcemap --target ES5 -d --diagnostics --pretty --strict --skipLibCheck --noImplicitReturns --noUnusedLocals --noUnusedParameters --strict --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --importHelpers --lib es5,es2015,es2016,es2017",
15+
"compile_module_es": "tsc dist/es/src/index.ts dist/es/src/proxy/index.ts -m ES2015 --outDir dist/es --sourcemap --target ES5 -d --diagnostics --pretty --strict --skipLibCheck --noImplicitReturns --noUnusedLocals --noUnusedParameters --strict --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --importHelpers --lib es5,es2015,es2016,es2017",
1616
"copy_src_cjs": "shx mkdir -p ./dist/cjs/src && shx cp -r ./src/* ./dist/cjs/src",
1717
"copy_src_es": "shx mkdir -p ./dist/es/src && shx cp -r ./src/* ./dist/es/src",
18-
"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",
18+
"cover": "rm -rf ./.nyc_output ./coverage && cross-env 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\"",
2020
"publish_all": "ts-node ./tools/publish.ts",
2121
"start": "webpack-dev-server --inline --colors --progress --port 3000",
2222
"start-demo": "webpack-dev-server --config ./example/webpack.config.js --inline --colors --progress --port 3001 --open",
2323
"test": "npm run lint && NODE_ENV=test tman --mocha spec-js/test/run.js",
2424
"test_O1": "npm run lint && NODE_ENV=test optimize=true tman --mocha spec-js/test/run.js",
2525
"version": "ts-node tools/version.ts && git add .",
26-
"watch": "NODE_ENV=test ts-node ./tools/watch.ts & npm run watch_test",
26+
"watch": "cross-env NODE_ENV=test ts-node ./tools/watch.ts & npm run watch_test",
2727
"watch_cjs": "tsc src/index.ts -m commonjs --outDir dist --sourcemap --target ES5 -d --diagnostics --pretty --strict --noImplicitReturns --suppressImplicitAnyIndexErrors --moduleResolution node --noEmitHelpers --lib es5,es2015,es2016,es2017 -w",
2828
"watch_test": "tsc -p test/tsconfig.json -w --diagnostics --pretty"
2929
},
@@ -60,54 +60,55 @@
6060
},
6161
"license": "MIT",
6262
"devDependencies": {
63-
"@types/chai": "^4.1.7",
64-
"@types/chai-string": "^1.4.1",
65-
"@types/node": "^12.0.0",
66-
"@types/shelljs": "^0.8.2",
67-
"@types/sinon": "^7.0.5",
68-
"@types/sinon-chai": "^3.2.2",
69-
"chai": "^4.2.0",
63+
"@types/chai": "^4.2.21",
64+
"@types/chai-string": "^1.4.2",
65+
"@types/node": "^16.4.13",
66+
"@types/shelljs": "^0.8.9",
67+
"@types/sinon": "^10.0.2",
68+
"@types/sinon-chai": "^3.2.5",
69+
"chai": "^4.3.4",
7070
"chai-string": "^1.5.0",
71-
"coveralls": "^3.0.2",
72-
"css-loader": "^3.0.0",
71+
"codecov": "^3.8.3",
72+
"cross-env": "^7.0.3",
73+
"css-loader": "^6.2.0",
7374
"extract-text-webpack-plugin": "^4.0.0-beta.0",
74-
"html-webpack-plugin": "^3.2.0",
75-
"husky": "^3.0.1",
76-
"lint-staged": "^9.0.0",
77-
"madge": "^3.4.3",
78-
"moment": "^2.24.0",
79-
"node-watch": "^0.6.0",
75+
"html-webpack-plugin": "^5.3.2",
76+
"husky": "^8.0.0",
77+
"lint-staged": "^11.1.2",
78+
"madge": "^5.0.1",
79+
"moment": "^2.29.1",
80+
"node-watch": "^0.7.1",
8081
"npm-run-all": "^4.1.5",
81-
"nyc": "^13.1.0",
82-
"prettier": "^1.16.3",
83-
"raw-loader": "^3.0.0",
84-
"rxjs": "^6.4.0",
85-
"shelljs": "^0.8.3",
86-
"shx": "^0.3.2",
87-
"sinon": "^7.2.3",
88-
"sinon-chai": "^3.3.0",
89-
"source-map-loader": "^0.2.4",
90-
"style-loader": "^0.23.1",
91-
"tman": "^1.8.1",
92-
"ts-loader": "^5.3.3",
93-
"ts-node": "^8.0.2",
94-
"tslint": "^5.12.1",
95-
"tslint-config-prettier": "^1.17.0",
82+
"nyc": "^15.1.0",
83+
"prettier": "^2.3.2",
84+
"raw-loader": "^4.0.2",
85+
"rxjs": "^7.3.0",
86+
"shelljs": "^0.8.4",
87+
"shx": "^0.3.3",
88+
"sinon": "^12.0.0",
89+
"sinon-chai": "^3.7.0",
90+
"source-map-loader": "^3.0.0",
91+
"style-loader": "^3.2.1",
92+
"tman": "^1.10.0",
93+
"ts-loader": "^9.2.5",
94+
"ts-node": "^10.2.0",
95+
"tslint": "^6.1.3",
96+
"tslint-config-prettier": "^1.18.0",
9697
"tslint-eslint-rules": "^5.4.0",
9798
"tslint-loader": "^3.6.0",
98-
"typescript": "^3.3.1",
99-
"webpack": "^4.29.0",
100-
"webpack-cli": "^3.2.1",
101-
"webpack-dev-server": "^3.1.14"
99+
"typescript": "^4.3.5",
100+
"webpack": "^5.50.0",
101+
"webpack-cli": "^4.7.2",
102+
"webpack-dev-server": "^4.0.0"
102103
},
103104
"dependencies": {
104-
"@types/lovefield": "^2.1.2",
105+
"@types/lovefield": "^2.1.4",
105106
"lovefield": "2.1.12",
106-
"nesthydrationjs": "^1.0.5"
107+
"nesthydrationjs": "^2.0.0"
107108
},
108109
"peerDependencies": {
109-
"rxjs": "^6.0.0",
110-
"tslib": "^1.9.0"
110+
"rxjs": "^7.3.0",
111+
"tslib": "^2.3.0"
111112
},
112113
"typings": "./index.d.ts",
113114
"prettier": {

renovate.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": ["config:base", ":preserveSemverRanges"],
3+
"packageRules": [
4+
{
5+
"automerge": true,
6+
"matchUpdateTypes": ["minor", "patch", "pin", "digest"]
7+
}
8+
],
9+
"lockFileMaintenance": {
10+
"enabled": true,
11+
"extends": [
12+
"schedule:monthly"
13+
]
14+
}
15+
}

src/storage/Database.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ export class Database {
6262

6363
private findSchema = (name: string): ParsedSchema => {
6464
const schema = this.schemas.get(name)
65-
return assertValue(schema, Exception.NonExistentTable, name)
65+
assertValue(schema, Exception.NonExistentTable, name)
66+
return schema
6667
}
6768
private tryCatchFindPrimaryKey = tryCatch((name: string) => {
6869
return this.findSchema(name).pk

src/storage/modules/Mutation.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export class Mutation {
7171
}
7272

7373
private toUpdater() {
74-
const meta = assertValue(this.meta, Exception.PrimaryKeyNotProvided)
74+
assertValue(this.meta, Exception.PrimaryKeyNotProvided)
7575
const query = this.db.update(this.table)
76-
query.where(this.table[meta.key].eq(meta.val))
76+
query.where(this.table[this.meta.key].eq(this.meta.val))
7777

7878
forEach(this.params, (val, key) => {
7979
const column = this.table[key]
@@ -88,11 +88,11 @@ export class Mutation {
8888
}
8989

9090
private toRow() {
91-
const meta = assertValue(this.meta, Exception.PrimaryKeyNotProvided)
91+
assertValue(this.meta, Exception.PrimaryKeyNotProvided)
9292
return {
9393
table: this.table,
9494
row: this.table.createRow({
95-
[meta.key]: meta.val,
95+
[this.meta.key]: this.meta.val,
9696
...this.params,
9797
}),
9898
}

src/storage/modules/PredicateProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class PredicateProvider<T> {
9393

9494
const predicates: lf.Predicate[] = []
9595

96-
forEach(meta, (val, key) => {
96+
forEach(meta, (val: Partial<PredicateMeta<T>> | ValueLiteral, key) => {
9797
let nestedPreds: lf.Predicate[]
9898
let resultPred: lf.Predicate
9999

@@ -127,9 +127,9 @@ export class PredicateProvider<T> {
127127
return typeof compoundPredicateFactory[methodName] === 'function'
128128
}
129129

130-
private checkPredicate(val: Partial<PredicateMeta<T>> | ValueLiteral) {
130+
private checkPredicate(val: Partial<PredicateMeta<T>> | ValueLiteral): boolean {
131131
return (
132-
val &&
132+
!!val &&
133133
typeof val === 'object' &&
134134
!(val instanceof Array) &&
135135
!(val instanceof RegExp) &&

src/storage/modules/Selector.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,15 @@ export class Selector<T> {
117117
// 下面的语句针对两个 lovefield issue 做了特殊调整:
118118
// issue#209: 确保 db.observe 之后立即执行一次查询;
119119
// issue#215: 确保 db.observe “不正确地”立即调用回调的行为,不会给消费方造成初始的重复推送。
120-
return observeQuery(db, query).pipe(
121-
startWith(void 0),
122-
switchMap(queryOnce),
123-
)
120+
return observeQuery(db, query).pipe(startWith(void 0), switchMap(queryOnce))
124121
}
125122

126123
const changesOnQuery =
127124
limit || skip
128125
? this.buildPrefetchingObserve().pipe(switchMap((pks) => observeOn(this.getQuery(this.inPKs(pks)))))
129126
: observeOn(this.getQuery())
130127

131-
return changesOnQuery.pipe(
132-
publishReplay(1),
133-
refCount(),
134-
)
128+
return changesOnQuery.pipe(publishReplay(1), refCount())
135129
}
136130

137131
private set change$(dist$: Observable<T[]>) {

src/utils/assert.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Truthy } from './truthy'
2-
31
type FailureHandler<U extends any[]> = (...args: U) => Error
42

53
export function assert(condition: boolean, failureMsg: string): void
@@ -12,29 +10,29 @@ export function assert<U extends any[]>(
1210
truthyOrThrow(condition, failure, ...failureArgs)
1311
}
1412

15-
export function assertValue<T>(value: T, falsyValueMsg: string): Truthy<T> | never
13+
type Maybe<T> = T | null | undefined
14+
15+
export function assertValue<T>(value: Maybe<T>, falsyValueMsg: string): asserts value is T
1616
export function assertValue<T, U extends any[]>(
17-
value: T,
17+
value: Maybe<T>,
1818
failure: FailureHandler<U>,
1919
...failureArgs: U
20-
): Truthy<T> | never
20+
): asserts value is T
2121
export function assertValue<T, U extends any[]>(
22-
value: T,
22+
value: Maybe<T>,
2323
failure: FailureHandler<U> | string,
2424
...failureArgs: U
25-
): Truthy<T> | never {
26-
return truthyOrThrow(value, failure, ...failureArgs)
25+
): asserts value is T {
26+
truthyOrThrow(value, failure, ...failureArgs)
2727
}
2828

2929
function truthyOrThrow<T, U extends any[]>(
30-
x: T,
30+
x: Maybe<T>,
3131
failure: FailureHandler<U> | string,
3232
...failureArgs: U
33-
): Truthy<T> | never {
34-
if (x) {
35-
return x as Truthy<T>
33+
): asserts x is T {
34+
if ((x as Maybe<unknown>) === false || x == null) {
35+
const error = typeof failure === 'string' ? new Error(failure) : failure(...failureArgs)
36+
throw error
3637
}
37-
38-
const error = typeof failure === 'string' ? new Error(failure) : failure(...failureArgs)
39-
throw error
4038
}

0 commit comments

Comments
 (0)