From c7006e0eb29681f23eec0e894406f382a1900f28 Mon Sep 17 00:00:00 2001 From: waterplea Date: Sun, 24 Jul 2022 16:58:04 +0300 Subject: [PATCH] fix: patchdb should not bundle rxjs but instead rely on the version in the app --- client/lib/store.ts | 46 ++++++++++++++++++++-------------------- client/package-lock.json | 45 +++++++++++++++++++++++++++------------ client/package.json | 4 +++- 3 files changed, 57 insertions(+), 38 deletions(-) diff --git a/client/lib/store.ts b/client/lib/store.ts index 2c5b337..50a6581 100644 --- a/client/lib/store.ts +++ b/client/lib/store.ts @@ -11,10 +11,10 @@ export interface StashEntry { export class Store { cache: DBCache sequence$: BehaviorSubject - private watchedNodes: { [path: string]: ReplaySubject } = {} + private watchedNodes: { [path: string]: ReplaySubject } = { } private stash = new BTree() - constructor( + constructor ( private readonly http: Http, private readonly initialCache: DBCache, ) { @@ -22,14 +22,14 @@ export class Store { this.sequence$ = new BehaviorSubject(initialCache.sequence) } - watch$(): Observable - watch$(p1: P1): Observable> - watch$>(p1: P1, p2: P2): Observable[P2]>> - watch$, P3 extends keyof NonNullable[P2]>>(p1: P1, p2: P2, p3: P3): Observable[P2]>[P3]>> - watch$, P3 extends keyof NonNullable[P2]>, P4 extends keyof NonNullable[P2]>[P3]>>(p1: P1, p2: P2, p3: P3, p4: P4): Observable[P2]>[P3]>[P4]>> - watch$, P3 extends keyof NonNullable[P2]>, P4 extends keyof NonNullable[P2]>[P3]>, P5 extends keyof NonNullable[P2]>[P3]>[P4]>>(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): Observable[P2]>[P3]>[P4]>[P5]>> - watch$, P3 extends keyof NonNullable[P2]>, P4 extends keyof NonNullable[P2]>[P3]>, P5 extends keyof NonNullable[P2]>[P3]>[P4]>, P6 extends keyof NonNullable[P2]>[P3]>[P4]>[P5]>>(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): Observable[P2]>[P3]>[P4]>[P5]>[P6]>> - watch$(...args: (string | number)[]): Observable { + watch$ (): Observable + watch$ (p1: P1): Observable> + watch$> (p1: P1, p2: P2): Observable[P2]>> + watch$, P3 extends keyof NonNullable[P2]>> (p1: P1, p2: P2, p3: P3): Observable[P2]>[P3]>> + watch$, P3 extends keyof NonNullable[P2]>, P4 extends keyof NonNullable[P2]>[P3]>> (p1: P1, p2: P2, p3: P3, p4: P4): Observable[P2]>[P3]>[P4]>> + watch$, P3 extends keyof NonNullable[P2]>, P4 extends keyof NonNullable[P2]>[P3]>, P5 extends keyof NonNullable[P2]>[P3]>[P4]>> (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): Observable[P2]>[P3]>[P4]>[P5]>> + watch$, P3 extends keyof NonNullable[P2]>, P4 extends keyof NonNullable[P2]>[P3]>, P5 extends keyof NonNullable[P2]>[P3]>[P4]>, P6 extends keyof NonNullable[P2]>[P3]>[P4]>[P5]>> (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): Observable[P2]>[P3]>[P4]>[P5]>[P6]>> + watch$ (...args: (string | number)[]): Observable { const path = `/${args.join('/')}` if (!this.watchedNodes[path]) { this.watchedNodes[path] = new ReplaySubject(1) @@ -38,7 +38,7 @@ export class Store { return this.watchedNodes[path].asObservable() } - update(update: Update): void { + update (update: Update): void { if (this.isRevision(update)) { // if old or known, return if (update.id <= this.cache.sequence || this.stash.get(update.id)) return @@ -48,24 +48,24 @@ export class Store { } } - reset(): void { + reset (): void { Object.values(this.watchedNodes).forEach(node => node.complete()) - this.watchedNodes = {} + this.watchedNodes = { } this.stash.clear() this.sequence$.next(0) this.cache = { sequence: 0, - data: {} as any, + data: { } as any, } } - private updateValue(path: string): void { + private updateValue (path: string): void { const value = getValueByPointer(this.cache.data, path) this.watchedNodes[path].next(value) } - private handleRevision(revision: Revision): void { + private handleRevision (revision: Revision): void { // stash the revision this.stash.set(revision.id, { revision, undo: [] }) @@ -77,7 +77,7 @@ export class Store { this.processStashed(revision.id) } - private handleDump({ value, id }: Dump): void { + private handleDump ({ value, id }: Dump): void { this.cache.data = { ...value } this.stash.deleteRange(this.cache.sequence, id, false) this.updateWatchedNodes('') @@ -85,12 +85,12 @@ export class Store { this.processStashed(id + 1) } - private processStashed(id: number): void { + private processStashed (id: number): void { this.undoRevisions(id) this.applyRevisions(id) } - private undoRevisions(id: number): void { + private undoRevisions (id: number): void { let stashEntry = this.stash.get(this.stash.maxKey() as number) while (stashEntry && stashEntry.revision.id > id) { @@ -99,7 +99,7 @@ export class Store { } } - private applyRevisions(id: number): void { + private applyRevisions (id: number): void { let revision = this.stash.get(id)?.revision while (revision) { let undo: Operation[] = [] @@ -136,7 +136,7 @@ export class Store { this.stash.deleteRange(0, this.cache.sequence, false) } - private updateWatchedNodes(revisionPath: string) { + private updateWatchedNodes (revisionPath: string) { const kill = (path: string) => { this.watchedNodes[path].complete() delete this.watchedNodes[path] @@ -151,12 +151,12 @@ export class Store { }) } - private updateSequence(sequence: number): void { + private updateSequence (sequence: number): void { this.cache.sequence = sequence this.sequence$.next(sequence) } - private isRevision(update: Update): update is Revision { + private isRevision (update: Update): update is Revision { return 'patch' in update } } diff --git a/client/package-lock.json b/client/package-lock.json index df9e420..398fe59 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -9,7 +9,6 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "rxjs": "6.6.7", "sorted-btree": "1.5.0", "uuid": "8.3.2" }, @@ -19,6 +18,9 @@ "ts-node": "10.2.0", "tslint": "6.1.3", "typescript": "4.3.5" + }, + "peerDependencies": { + "rxjs": "^7.5.6" } }, "node_modules/@babel/code-frame": { @@ -438,16 +440,20 @@ } }, "node_modules/rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "version": "7.5.6", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.6.tgz", + "integrity": "sha512-dnyv2/YsXhnm461G+R/Pe5bWP41Nm6LBXEYWI6eiFP4fiwx6WRI/CD0zbdVAudd9xwLEF2IDcKXLHit0FYjUzw==", + "peer": true, "dependencies": { - "tslib": "^1.9.0" - }, - "engines": { - "npm": ">=2.0.0" + "tslib": "^2.1.0" } }, + "node_modules/rxjs/node_modules/tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", + "peer": true + }, "node_modules/semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -527,7 +533,8 @@ "node_modules/tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true }, "node_modules/tslint": { "version": "6.1.3", @@ -951,11 +958,20 @@ } }, "rxjs": { - "version": "6.6.7", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.6.7.tgz", - "integrity": "sha512-hTdwr+7yYNIT5n4AMYp85KA6yw2Va0FLa3Rguvbpa4W3I5xynaBZo41cM3XM+4Q6fRMj3sBYIR1VAmZMXYJvRQ==", + "version": "7.5.6", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.5.6.tgz", + "integrity": "sha512-dnyv2/YsXhnm461G+R/Pe5bWP41Nm6LBXEYWI6eiFP4fiwx6WRI/CD0zbdVAudd9xwLEF2IDcKXLHit0FYjUzw==", + "peer": true, "requires": { - "tslib": "^1.9.0" + "tslib": "^2.1.0" + }, + "dependencies": { + "tslib": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", + "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==", + "peer": true + } } }, "semver": { @@ -1007,7 +1023,8 @@ "tslib": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", + "dev": true }, "tslint": { "version": "6.1.3", diff --git a/client/package.json b/client/package.json index 9d92a0b..7b9d0cb 100644 --- a/client/package.json +++ b/client/package.json @@ -10,10 +10,12 @@ "build": "tsc" }, "dependencies": { - "rxjs": "6.6.7", "sorted-btree": "1.5.0", "uuid": "8.3.2" }, + "peerDependencies": { + "rxjs": ">=6.0.0" + }, "devDependencies": { "@types/node": "16.4.13", "@types/uuid": "8.3.1",