From 2c25d46fd1a4127e374cf26174372010cf14c81b Mon Sep 17 00:00:00 2001 From: Erik Arvidsson Date: Mon, 22 Jul 2024 09:26:59 +0200 Subject: [PATCH 1/2] Fix scan type signature We need all those overloads to match the Replicache interface. --- src/replicache-transaction.ts | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/replicache-transaction.ts b/src/replicache-transaction.ts index 364d757..d25c6b8 100644 --- a/src/replicache-transaction.ts +++ b/src/replicache-transaction.ts @@ -5,8 +5,11 @@ import { makeScanResult, mergeAsyncIterables, ReadonlyJSONValue, + ScanIndexOptions, ScanNoIndexOptions, ScanOptions, + ScanResult, + TransactionLocation, WriteTransaction, } from 'replicache'; @@ -39,20 +42,33 @@ export class ReplicacheTransaction implements WriteTransaction { } readonly reason = 'authoritative'; + + /** @deprecated Use {@link location} instead. */ readonly environment = 'server'; + readonly location: TransactionLocation = 'server'; clientID: string; mutationID = 0; + /** + * @deprecated Use {@link set} instead. + */ // eslint-disable-next-line require-await async put(key: string, value: ReadonlyJSONValue): Promise { this.#cache.set(key, {value, dirty: true}); } + + // eslint-disable-next-line require-await + async set(key: string, value: ReadonlyJSONValue): Promise { + this._cache.set(key, {value, dirty: true}); + } + async del(key: string): Promise { const had = await this.has(key); this.#cache.set(key, {value: undefined, dirty: true}); return had; } + async get(key: string): Promise { const entry = this.#cache.get(key); if (entry) { @@ -62,6 +78,7 @@ export class ReplicacheTransaction implements WriteTransaction { this.#cache.set(key, {value, dirty: false}); return value; } + async has(key: string): Promise { const val = await this.get(key); return val !== undefined; @@ -75,7 +92,21 @@ export class ReplicacheTransaction implements WriteTransaction { return true; } - scan(options: ScanOptions = {} as ScanNoIndexOptions) { + scan(options: ScanIndexOptions): ScanResult; + scan(options?: ScanNoIndexOptions): ScanResult; + scan(options?: ScanOptions): ScanResult; + scan( + options: ScanIndexOptions, + ): ScanResult>; + scan( + options?: ScanNoIndexOptions, + ): ScanResult>; + scan( + options?: ScanOptions, + ): ScanResult>; + scan( + options: ScanOptions = {}, + ): ScanResult { if (isScanIndexOptions(options)) { throw new Error('not implemented'); } @@ -83,7 +114,7 @@ export class ReplicacheTransaction implements WriteTransaction { const storage = this.#storage; const cache = this.#cache; - return makeScanResult(options, (fromKey: string) => { + return makeScanResult(options, (fromKey: string) => { const source = storage.getEntries(fromKey); const pending = getCacheEntries(cache, fromKey); const merged = mergeAsyncIterables(source, pending, entryCompare); From 4022fd8821cd3aa2a6e14034d15d5fff085d857e Mon Sep 17 00:00:00 2001 From: Cesar Alaestante Date: Mon, 22 Jul 2024 12:47:48 -0700 Subject: [PATCH 2/2] chore: Replicache 15.0.1 --- package-lock.json | 88 ++++++++++++++++++++--------------- package.json | 2 +- src/replicache-transaction.ts | 4 +- 3 files changed, 55 insertions(+), 39 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7a05a7c..eee5533 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "devDependencies": { "@rocicorp/eslint-config": "^0.5.1", "@rocicorp/prettier-config": "^0.2.0", - "replicache": "13.0.0-beta.0", + "replicache": "^15.0.1", "typescript": "5.5.3", "vitest": "^2.0.3" } @@ -32,6 +32,15 @@ "node": ">=6.0.0" } }, + "node_modules/@badrap/valita": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@badrap/valita/-/valita-0.3.9.tgz", + "integrity": "sha512-keFt5iCwI6H5lbvhg2ZJCWa1xRffdpk6/LHCaayubaRM2zhnRIIBE1d+2NEzXLSk4Fe/aklGNXVPt7hNkvBH6g==", + "dev": true, + "engines": { + "node": ">= 16" + } + }, "node_modules/@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -631,25 +640,22 @@ } }, "node_modules/@rocicorp/lock": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@rocicorp/lock/-/lock-1.0.1.tgz", - "integrity": "sha512-sYbcbiyEf61guk2DfcA6zzgDrW6ncJJW11JIFNSbByqYx80olhyp0IyXUMA3xmNK0YQSkAuufWvLExaWQXuzUQ==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@rocicorp/lock/-/lock-1.0.4.tgz", + "integrity": "sha512-FavTiO8ETXFXDVfA87IThGduTTTR8iqzBnr/c60gUUmbk7knGEXPmf2B+yiNuluJD0ku0fL2V2r62UXnsLXl6w==", "dev": true, "dependencies": { - "@rocicorp/resolver": "^1.0.0" + "@rocicorp/resolver": "^1.0.2" }, "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" } }, "node_modules/@rocicorp/logger": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@rocicorp/logger/-/logger-4.1.0.tgz", - "integrity": "sha512-RdXs1oowcSdgaYHIdROc0td0GIG5LnYMYZgK/forGfAu65ytDC59dz4VGe5+08Q8Ko3xg8KM7aDM5podnfFJ7w==", - "dev": true, - "engines": { - "node": "^14.13.1 || >=16.0.0" - } + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/@rocicorp/logger/-/logger-5.2.2.tgz", + "integrity": "sha512-lqS/SUUBdiGzsIPD2awMiOzwo0DpAjMriPtqpALausplVHDjyJjUyScrB0Y7QcvxDfSPFkJzT5FncgIU3uBF2g==", + "dev": true }, "node_modules/@rocicorp/prettier-config": { "version": "0.2.0", @@ -661,9 +667,9 @@ } }, "node_modules/@rocicorp/resolver": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@rocicorp/resolver/-/resolver-1.0.0.tgz", - "integrity": "sha512-iK0QW74BKR0ogY4QwBEAMoevqypi5S/jjKqL6mc7KH7z2PFuOinOebsD1Ol8VIxrh23IPrMNwDNSrnfhKga9Vw==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@rocicorp/resolver/-/resolver-1.0.2.tgz", + "integrity": "sha512-TfjMTQp9cNNqNtHFfa+XHEGdA7NnmDRu+ZJH4YF3dso0Xk/b9DMhg/sl+b6CR4ThFZArXXDsG1j8Mwl34wcOZQ==", "dev": true, "engines": { "node": "^12.20.0 || ^14.13.1 || >=16.0.0" @@ -2511,14 +2517,15 @@ ] }, "node_modules/replicache": { - "version": "13.0.0-beta.0", - "resolved": "https://registry.npmjs.org/replicache/-/replicache-13.0.0-beta.0.tgz", - "integrity": "sha512-vMf/xzDBY4Bz7svqZ7cI5BzsGbo5OL58LsC3uzkAq5kWuYnwh7Zt7FIq6/38E6BKSdPgmDzswNz+HgUU/PQZsg==", + "version": "15.0.1", + "resolved": "https://registry.npmjs.org/replicache/-/replicache-15.0.1.tgz", + "integrity": "sha512-I7HK6h2eT2QNxO4mwQFDqbuxhvCQgSlU4QuwfN9dqA6EKnO73VYiKB676r36N3q5W7L+htLgAcrSsrX+JPsRlQ==", "dev": true, "dependencies": { - "@rocicorp/lock": "^1.0.1", - "@rocicorp/logger": "^4.1.0", - "@rocicorp/resolver": "^1.0.0" + "@badrap/valita": "^0.3.0", + "@rocicorp/lock": "^1.0.4", + "@rocicorp/logger": "^5.2.2", + "@rocicorp/resolver": "^1.0.2" }, "bin": { "replicache": "out/cli.cjs" @@ -3069,6 +3076,12 @@ "@jridgewell/trace-mapping": "^0.3.24" } }, + "@badrap/valita": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@badrap/valita/-/valita-0.3.9.tgz", + "integrity": "sha512-keFt5iCwI6H5lbvhg2ZJCWa1xRffdpk6/LHCaayubaRM2zhnRIIBE1d+2NEzXLSk4Fe/aklGNXVPt7hNkvBH6g==", + "dev": true + }, "@esbuild/aix-ppc64": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", @@ -3411,18 +3424,18 @@ } }, "@rocicorp/lock": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@rocicorp/lock/-/lock-1.0.1.tgz", - "integrity": "sha512-sYbcbiyEf61guk2DfcA6zzgDrW6ncJJW11JIFNSbByqYx80olhyp0IyXUMA3xmNK0YQSkAuufWvLExaWQXuzUQ==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@rocicorp/lock/-/lock-1.0.4.tgz", + "integrity": "sha512-FavTiO8ETXFXDVfA87IThGduTTTR8iqzBnr/c60gUUmbk7knGEXPmf2B+yiNuluJD0ku0fL2V2r62UXnsLXl6w==", "dev": true, "requires": { - "@rocicorp/resolver": "^1.0.0" + "@rocicorp/resolver": "^1.0.2" } }, "@rocicorp/logger": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@rocicorp/logger/-/logger-4.1.0.tgz", - "integrity": "sha512-RdXs1oowcSdgaYHIdROc0td0GIG5LnYMYZgK/forGfAu65ytDC59dz4VGe5+08Q8Ko3xg8KM7aDM5podnfFJ7w==", + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/@rocicorp/logger/-/logger-5.2.2.tgz", + "integrity": "sha512-lqS/SUUBdiGzsIPD2awMiOzwo0DpAjMriPtqpALausplVHDjyJjUyScrB0Y7QcvxDfSPFkJzT5FncgIU3uBF2g==", "dev": true }, "@rocicorp/prettier-config": { @@ -3435,9 +3448,9 @@ } }, "@rocicorp/resolver": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@rocicorp/resolver/-/resolver-1.0.0.tgz", - "integrity": "sha512-iK0QW74BKR0ogY4QwBEAMoevqypi5S/jjKqL6mc7KH7z2PFuOinOebsD1Ol8VIxrh23IPrMNwDNSrnfhKga9Vw==", + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@rocicorp/resolver/-/resolver-1.0.2.tgz", + "integrity": "sha512-TfjMTQp9cNNqNtHFfa+XHEGdA7NnmDRu+ZJH4YF3dso0Xk/b9DMhg/sl+b6CR4ThFZArXXDsG1j8Mwl34wcOZQ==", "dev": true }, "@rollup/rollup-android-arm-eabi": { @@ -4709,14 +4722,15 @@ "dev": true }, "replicache": { - "version": "13.0.0-beta.0", - "resolved": "https://registry.npmjs.org/replicache/-/replicache-13.0.0-beta.0.tgz", - "integrity": "sha512-vMf/xzDBY4Bz7svqZ7cI5BzsGbo5OL58LsC3uzkAq5kWuYnwh7Zt7FIq6/38E6BKSdPgmDzswNz+HgUU/PQZsg==", + "version": "15.0.1", + "resolved": "https://registry.npmjs.org/replicache/-/replicache-15.0.1.tgz", + "integrity": "sha512-I7HK6h2eT2QNxO4mwQFDqbuxhvCQgSlU4QuwfN9dqA6EKnO73VYiKB676r36N3q5W7L+htLgAcrSsrX+JPsRlQ==", "dev": true, "requires": { - "@rocicorp/lock": "^1.0.1", - "@rocicorp/logger": "^4.1.0", - "@rocicorp/resolver": "^1.0.0" + "@badrap/valita": "^0.3.0", + "@rocicorp/lock": "^1.0.4", + "@rocicorp/logger": "^5.2.2", + "@rocicorp/resolver": "^1.0.2" } }, "resolve-from": { diff --git a/package.json b/package.json index 760d646..6c7ed15 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "devDependencies": { "@rocicorp/eslint-config": "^0.5.1", "@rocicorp/prettier-config": "^0.2.0", - "replicache": "13.0.0-beta.0", + "replicache": "^15.0.1", "typescript": "5.5.3", "vitest": "^2.0.3" }, diff --git a/src/replicache-transaction.ts b/src/replicache-transaction.ts index d25c6b8..e5f12e2 100644 --- a/src/replicache-transaction.ts +++ b/src/replicache-transaction.ts @@ -1,6 +1,8 @@ import {compareUTF8} from 'compare-utf8'; import { + DeepReadonly, filterAsyncIterable, + IndexKey, isScanIndexOptions, makeScanResult, mergeAsyncIterables, @@ -60,7 +62,7 @@ export class ReplicacheTransaction implements WriteTransaction { // eslint-disable-next-line require-await async set(key: string, value: ReadonlyJSONValue): Promise { - this._cache.set(key, {value, dirty: true}); + this.#cache.set(key, {value, dirty: true}); } async del(key: string): Promise {