@party-stack/runtime 0.3.7 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/coordinator/createPersistedCollectionCoordinator.d.ts +4 -2
- package/lib/coordinator/createPersistedCollectionCoordinator.d.ts.map +1 -1
- package/lib/coordinator/createPersistedCollectionCoordinator.js +492 -280
- package/lib/coordinator/createPersistedCollectionCoordinator.js.map +1 -1
- package/lib/coordinator/index.d.ts +2 -2
- package/lib/coordinator/index.js +2 -2
- package/lib/effection/index.d.ts +4 -2
- package/lib/effection/index.d.ts.map +1 -1
- package/lib/effection/index.js +25 -25
- package/lib/effection/index.js.map +1 -1
- package/lib/index.d.ts +11 -10
- package/lib/index.js +10 -8
- package/lib/memory/MemoryBlobBytesStore.d.ts +8 -6
- package/lib/memory/MemoryBlobBytesStore.d.ts.map +1 -1
- package/lib/memory/MemoryBlobBytesStore.js +22 -20
- package/lib/memory/MemoryBlobBytesStore.js.map +1 -1
- package/lib/types.d.ts +31 -29
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +0 -1
- package/lib/utils/BrowserAuthenticationCancelledError.d.ts +3 -1
- package/lib/utils/BrowserAuthenticationCancelledError.d.ts.map +1 -1
- package/lib/utils/BrowserAuthenticationCancelledError.js +10 -6
- package/lib/utils/BrowserAuthenticationCancelledError.js.map +1 -1
- package/lib/utils/createCollectionPersistence.d.ts +7 -0
- package/lib/utils/createCollectionPersistence.d.ts.map +1 -0
- package/lib/utils/createCollectionPersistence.js +24 -0
- package/lib/utils/createCollectionPersistence.js.map +1 -0
- package/lib/utils/createDefaultRuntime.d.ts +4 -1
- package/lib/utils/createDefaultRuntime.d.ts.map +1 -1
- package/lib/utils/createDefaultRuntime.js +15 -11
- package/lib/utils/createDefaultRuntime.js.map +1 -1
- package/lib/utils/createLocalCollection.d.ts +8 -6
- package/lib/utils/createLocalCollection.d.ts.map +1 -1
- package/lib/utils/createLocalCollection.js +19 -18
- package/lib/utils/createLocalCollection.js.map +1 -1
- package/lib/utils/defineRuntime.d.ts +3 -2
- package/lib/utils/defineRuntime.d.ts.map +1 -1
- package/lib/utils/defineRuntime.js +26 -30
- package/lib/utils/defineRuntime.js.map +1 -1
- package/package.json +12 -18
- package/lib/coordinator/index.d.ts.map +0 -1
- package/lib/coordinator/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/memory/MemoryBlobBytesStore.test.d.ts +0 -2
- package/lib/memory/MemoryBlobBytesStore.test.d.ts.map +0 -1
- package/lib/memory/MemoryBlobBytesStore.test.js +0 -12
- package/lib/memory/MemoryBlobBytesStore.test.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils/createLocalCollection.test.d.ts +0 -2
- package/lib/utils/createLocalCollection.test.d.ts.map +0 -1
- package/lib/utils/createLocalCollection.test.js +0 -237
- package/lib/utils/createLocalCollection.test.js.map +0 -1
- package/lib/utils/defineRuntime.test.d.ts +0 -2
- package/lib/utils/defineRuntime.test.d.ts.map +0 -1
- package/lib/utils/defineRuntime.test.js +0 -40
- package/lib/utils/defineRuntime.test.js.map +0 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { RuntimeAdapter } from "../types.js";
|
|
2
|
+
import { Collection } from "@tanstack/db";
|
|
3
|
+
//#region src/utils/createLocalCollection.d.ts
|
|
3
4
|
export declare function createLocalCollection<T extends object, TKey extends string | number>(options: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
name: string;
|
|
6
|
+
getKey: (value: T) => TKey;
|
|
7
|
+
runtime: RuntimeAdapter;
|
|
8
|
+
schemaVersion?: number;
|
|
8
9
|
}): Collection<T, TKey>;
|
|
10
|
+
//#endregion
|
|
9
11
|
//# sourceMappingURL=createLocalCollection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLocalCollection.d.ts","
|
|
1
|
+
{"version":3,"file":"createLocalCollection.d.ts","names":[],"sources":["../../src/utils/createLocalCollection.ts"],"mappings":";;;wBAKgB,sBAAsB,kBAAkB,8BAA8B;EAClF;EACA,SAAS,OAAO,MAAM;EACtB,SAAS;EACT;IACA,WAAW,GAAG"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createCollectionPersistence } from "./createCollectionPersistence.js";
|
|
2
2
|
import { persistedCollectionOptions } from "@tanstack/db-sqlite-persistence-core";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})
|
|
19
|
-
: localOnlyCollectionOptions(collectionOptions));
|
|
3
|
+
import { BasicIndex, createCollection, localOnlyCollectionOptions } from "@tanstack/db";
|
|
4
|
+
//#region src/utils/createLocalCollection.ts
|
|
5
|
+
function createLocalCollection(options) {
|
|
6
|
+
const collectionOptions = {
|
|
7
|
+
id: `party-stack:${options.runtime.owner}:${options.runtime.namespace}:${options.name}`,
|
|
8
|
+
getKey: options.getKey,
|
|
9
|
+
defaultIndexType: BasicIndex,
|
|
10
|
+
autoIndex: "eager"
|
|
11
|
+
};
|
|
12
|
+
const persistence = options.runtime.persistence;
|
|
13
|
+
return createCollection(persistence ? persistedCollectionOptions({
|
|
14
|
+
...collectionOptions,
|
|
15
|
+
schemaVersion: options.schemaVersion,
|
|
16
|
+
persistence: createCollectionPersistence(options.runtime.coordination, persistence)
|
|
17
|
+
}) : localOnlyCollectionOptions(collectionOptions));
|
|
20
18
|
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { createLocalCollection };
|
|
21
|
+
|
|
21
22
|
//# sourceMappingURL=createLocalCollection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLocalCollection.js","
|
|
1
|
+
{"version":3,"file":"createLocalCollection.js","names":[],"sources":["../../src/utils/createLocalCollection.ts"],"sourcesContent":["import { BasicIndex, createCollection, localOnlyCollectionOptions, type Collection } from \"@tanstack/db\";\nimport { persistedCollectionOptions } from \"@tanstack/db-sqlite-persistence-core\";\nimport { createCollectionPersistence } from \"./createCollectionPersistence.js\";\nimport type { RuntimeAdapter } from \"../types.js\";\n\nexport function createLocalCollection<T extends object, TKey extends string | number>(options: {\n name: string;\n getKey: (value: T) => TKey;\n runtime: RuntimeAdapter;\n schemaVersion?: number;\n}): Collection<T, TKey> {\n const collectionOptions = {\n id: `party-stack:${options.runtime.owner}:${options.runtime.namespace}:${options.name}`,\n getKey: options.getKey,\n defaultIndexType: BasicIndex,\n autoIndex: \"eager\" as const,\n };\n const persistence = options.runtime.persistence;\n\n return createCollection(\n persistence\n ? persistedCollectionOptions<T, TKey>({\n ...collectionOptions,\n schemaVersion: options.schemaVersion,\n persistence: createCollectionPersistence(options.runtime.coordination, persistence),\n })\n : localOnlyCollectionOptions<T, TKey>(collectionOptions)\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,sBAAsE,SAK9D;CACpB,MAAM,oBAAoB;EACtB,IAAI,eAAe,QAAQ,QAAQ,MAAM,GAAG,QAAQ,QAAQ,UAAU,GAAG,QAAQ;EACjF,QAAQ,QAAQ;EAChB,kBAAkB;EAClB,WAAW;CACf;CACA,MAAM,cAAc,QAAQ,QAAQ;CAEpC,OAAO,iBACH,cACM,2BAAoC;EAChC,GAAG;EACH,eAAe,QAAQ;EACvB,aAAa,4BAA4B,QAAQ,QAAQ,cAAc,WAAW;CACtF,CAAC,IACD,2BAAoC,iBAAiB,CAC/D;AACJ"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RuntimeAdapter } from "../types.js";
|
|
2
|
+
//#region src/utils/defineRuntime.d.ts
|
|
2
3
|
type SyncRuntimeAdapterProvider = (owner: string, namespace: string) => RuntimeAdapter;
|
|
3
4
|
type AsyncRuntimeAdapterProvider = (owner: string, namespace: string) => Promise<RuntimeAdapter>;
|
|
4
5
|
export declare function defineRuntime(provider: SyncRuntimeAdapterProvider): SyncRuntimeAdapterProvider;
|
|
5
6
|
export declare function defineRuntime(provider: AsyncRuntimeAdapterProvider): AsyncRuntimeAdapterProvider;
|
|
6
|
-
|
|
7
|
+
//#endregion
|
|
7
8
|
//# sourceMappingURL=defineRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineRuntime.d.ts","
|
|
1
|
+
{"version":3,"file":"defineRuntime.d.ts","names":[],"sources":["../../src/utils/defineRuntime.ts"],"mappings":";;KAEK,8BAA8B,eAAe,sBAAsB;KAEnE,+BAA+B,eAAe,sBAAsB,QAAQ;wBA8BjE,cAAc,UAAU,6BAA6B;wBACrD,cAAc,UAAU,8BAA8B"}
|
|
@@ -1,34 +1,30 @@
|
|
|
1
|
+
//#region src/utils/defineRuntime.ts
|
|
1
2
|
function manageRuntime(runtime) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
: undefined;
|
|
20
|
-
return {
|
|
21
|
-
...runtime,
|
|
22
|
-
cleanup,
|
|
23
|
-
destroy,
|
|
24
|
-
};
|
|
3
|
+
const rawCleanup = runtime.cleanup?.bind(runtime);
|
|
4
|
+
const rawDestroy = runtime.destroy?.bind(runtime);
|
|
5
|
+
let cleanupPromise;
|
|
6
|
+
let destroyPromise;
|
|
7
|
+
const cleanup = () => {
|
|
8
|
+
cleanupPromise ??= Promise.resolve().then(() => rawCleanup?.()).then(() => void 0);
|
|
9
|
+
return cleanupPromise;
|
|
10
|
+
};
|
|
11
|
+
const destroy = rawDestroy ? () => {
|
|
12
|
+
destroyPromise ??= cleanup().then(() => rawDestroy()).then(() => void 0);
|
|
13
|
+
return destroyPromise;
|
|
14
|
+
} : void 0;
|
|
15
|
+
return {
|
|
16
|
+
...runtime,
|
|
17
|
+
cleanup,
|
|
18
|
+
destroy
|
|
19
|
+
};
|
|
25
20
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
: manageRuntime(runtime);
|
|
32
|
-
};
|
|
21
|
+
function defineRuntime(provider) {
|
|
22
|
+
return (owner, namespace) => {
|
|
23
|
+
const runtime = provider(owner, namespace);
|
|
24
|
+
return runtime instanceof Promise ? runtime.then(manageRuntime) : manageRuntime(runtime);
|
|
25
|
+
};
|
|
33
26
|
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { defineRuntime };
|
|
29
|
+
|
|
34
30
|
//# sourceMappingURL=defineRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineRuntime.js","
|
|
1
|
+
{"version":3,"file":"defineRuntime.js","names":[],"sources":["../../src/utils/defineRuntime.ts"],"sourcesContent":["import type { RuntimeAdapter, RuntimeAdapterProvider } from \"../types.js\";\n\ntype SyncRuntimeAdapterProvider = (owner: string, namespace: string) => RuntimeAdapter;\n\ntype AsyncRuntimeAdapterProvider = (owner: string, namespace: string) => Promise<RuntimeAdapter>;\n\nfunction manageRuntime(runtime: RuntimeAdapter): RuntimeAdapter {\n const rawCleanup = runtime.cleanup?.bind(runtime);\n const rawDestroy = runtime.destroy?.bind(runtime);\n let cleanupPromise: Promise<void> | undefined;\n let destroyPromise: Promise<void> | undefined;\n\n const cleanup = (): Promise<void> => {\n cleanupPromise ??= Promise.resolve()\n .then(() => rawCleanup?.())\n .then(() => undefined);\n return cleanupPromise;\n };\n const destroy = rawDestroy\n ? (): Promise<void> => {\n destroyPromise ??= cleanup()\n .then(() => rawDestroy())\n .then(() => undefined);\n return destroyPromise;\n }\n : undefined;\n\n return {\n ...runtime,\n cleanup,\n destroy,\n };\n}\n\nexport function defineRuntime(provider: SyncRuntimeAdapterProvider): SyncRuntimeAdapterProvider;\nexport function defineRuntime(provider: AsyncRuntimeAdapterProvider): AsyncRuntimeAdapterProvider;\nexport function defineRuntime(provider: RuntimeAdapterProvider): RuntimeAdapterProvider {\n return (owner, namespace) => {\n const runtime = provider(owner, namespace);\n return runtime instanceof Promise ? runtime.then(manageRuntime) : manageRuntime(runtime);\n };\n}\n"],"mappings":";AAMA,SAAS,cAAc,SAAyC;CAC5D,MAAM,aAAa,QAAQ,SAAS,KAAK,OAAO;CAChD,MAAM,aAAa,QAAQ,SAAS,KAAK,OAAO;CAChD,IAAI;CACJ,IAAI;CAEJ,MAAM,gBAA+B;EACjC,mBAAmB,QAAQ,QAAQ,CAAC,CAC/B,WAAW,aAAa,CAAC,CAAC,CAC1B,WAAW,KAAA,CAAS;EACzB,OAAO;CACX;CACA,MAAM,UAAU,mBACW;EACjB,mBAAmB,QAAQ,CAAC,CACvB,WAAW,WAAW,CAAC,CAAC,CACxB,WAAW,KAAA,CAAS;EACzB,OAAO;CACX,IACA,KAAA;CAEN,OAAO;EACH,GAAG;EACH;EACA;CACJ;AACJ;AAIA,SAAgB,cAAc,UAA0D;CACpF,QAAQ,OAAO,cAAc;EACzB,MAAM,UAAU,SAAS,OAAO,SAAS;EACzC,OAAO,mBAAmB,UAAU,QAAQ,KAAK,aAAa,IAAI,cAAc,OAAO;CAC3F;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@party-stack/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"files": [
|
|
5
|
+
"lib"
|
|
6
|
+
],
|
|
4
7
|
"type": "module",
|
|
5
8
|
"exports": {
|
|
6
9
|
".": {
|
|
@@ -12,28 +15,19 @@
|
|
|
12
15
|
"default": "./lib/effection/index.js"
|
|
13
16
|
}
|
|
14
17
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
"lib"
|
|
17
|
-
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"effection": "^4.0.2",
|
|
20
|
-
"@party-stack/coordination": "0.
|
|
20
|
+
"@party-stack/coordination": "0.3.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@tanstack/db": "0.
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"vitest": "^3.1.1"
|
|
23
|
+
"@tanstack/db": "0.12.1",
|
|
24
|
+
"@tanstack/db-sqlite-persistence-core": "0.4.5",
|
|
25
|
+
"typescript": "~7.0.2",
|
|
26
|
+
"vite-plus": "1.1.0",
|
|
27
|
+
"@party-stack/build-config": "0.1.1"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
31
|
-
"@tanstack/db": "0.
|
|
32
|
-
"@tanstack/db-sqlite-persistence-core": "0.
|
|
33
|
-
},
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "tsc",
|
|
36
|
-
"lint": "eslint",
|
|
37
|
-
"test": "vitest run"
|
|
30
|
+
"@tanstack/db": "0.12.1",
|
|
31
|
+
"@tanstack/db-sqlite-persistence-core": "0.4.5"
|
|
38
32
|
}
|
|
39
33
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/coordinator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oCAAoC,EAAE,MAAM,2CAA2C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/coordinator/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oCAAoC,EAAE,MAAM,2CAA2C,CAAC"}
|
package/lib/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oCAAoC,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,mCAAmC,EAAE,MAAM,gDAAgD,CAAC;AACrG,OAAO,EACH,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EACxB,6BAA6B,EAC7B,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,GACrB,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACR,cAAc,EACd,qBAAqB,EACrB,iCAAiC,EACjC,4BAA4B,EAC5B,WAAW,EACX,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,sBAAsB,GACzB,MAAM,YAAY,CAAC;AACpB,YAAY,EACR,YAAY,EACZ,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,EACxB,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,0BAA0B,EAC1B,2BAA2B,EAC3B,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,GACnC,MAAM,2BAA2B,CAAC"}
|
package/lib/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oCAAoC,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,mCAAmC,EAAE,MAAM,gDAAgD,CAAC;AACrG,OAAO,EACH,uBAAuB,EACvB,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EACxB,6BAA6B,EAC7B,0BAA0B,EAC1B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,GACrB,MAAM,2BAA2B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryBlobBytesStore.test.d.ts","sourceRoot":"","sources":["../../src/memory/MemoryBlobBytesStore.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { MemoryBlobBytesStore } from "./MemoryBlobBytesStore.js";
|
|
3
|
-
describe("MemoryBlobBytesStore", () => {
|
|
4
|
-
it("stores, reads, and deletes blobs", async () => {
|
|
5
|
-
const store = new MemoryBlobBytesStore();
|
|
6
|
-
await store.write("folder/blob", new Blob(["hello"]));
|
|
7
|
-
expect(await (await store.read("folder/blob")).text()).toBe("hello");
|
|
8
|
-
await store.delete("folder/blob");
|
|
9
|
-
await expect(store.read("folder/blob")).rejects.toThrow('Blob bytes not found for "folder/blob".');
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
//# sourceMappingURL=MemoryBlobBytesStore.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MemoryBlobBytesStore.test.js","sourceRoot":"","sources":["../../src/memory/MemoryBlobBytesStore.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IAClC,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;QAC9C,MAAM,KAAK,GAAG,IAAI,oBAAoB,EAAE,CAAC;QACzC,MAAM,KAAK,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAErE,MAAM,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QAClC,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACnD,yCAAyC,CAC5C,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
package/lib/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createLocalCollection.test.d.ts","sourceRoot":"","sources":["../../src/utils/createLocalCollection.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { SingleProcessCoordination, } from "@party-stack/coordination";
|
|
2
|
-
import { SharedWorkerCoordinationClient, SharedWorkerCoordinationHost, } from "@party-stack/coordination/shared-worker";
|
|
3
|
-
import { describe, expect, it, vi, } from "vitest";
|
|
4
|
-
import { createPersistedCollectionCoordinator } from "../coordinator/createPersistedCollectionCoordinator.js";
|
|
5
|
-
import { MemoryBlobBytesStore } from "../memory/MemoryBlobBytesStore.js";
|
|
6
|
-
import { createLocalCollection } from "./createLocalCollection.js";
|
|
7
|
-
function memoryAdapter() {
|
|
8
|
-
const collections = new Map();
|
|
9
|
-
const positions = new Map();
|
|
10
|
-
const rows = (collectionId) => {
|
|
11
|
-
let collection = collections.get(collectionId);
|
|
12
|
-
if (!collection) {
|
|
13
|
-
collection = new Map();
|
|
14
|
-
collections.set(collectionId, collection);
|
|
15
|
-
}
|
|
16
|
-
return collection;
|
|
17
|
-
};
|
|
18
|
-
return {
|
|
19
|
-
loadSubset: (collectionId) => Promise.resolve([...rows(collectionId)].map(([key, value]) => ({
|
|
20
|
-
key,
|
|
21
|
-
value,
|
|
22
|
-
}))),
|
|
23
|
-
applyCommittedTx: (collectionId, transaction) => {
|
|
24
|
-
const collection = rows(collectionId);
|
|
25
|
-
for (const mutation of transaction.mutations) {
|
|
26
|
-
if (mutation.type === "delete") {
|
|
27
|
-
collection.delete(mutation.key);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
collection.set(mutation.key, mutation.value);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
positions.set(collectionId, {
|
|
34
|
-
latestTerm: transaction.term,
|
|
35
|
-
latestSeq: transaction.seq,
|
|
36
|
-
latestRowVersion: transaction.rowVersion,
|
|
37
|
-
});
|
|
38
|
-
return Promise.resolve();
|
|
39
|
-
},
|
|
40
|
-
ensureIndex: () => Promise.resolve(),
|
|
41
|
-
getStreamPosition: (collectionId) => Promise.resolve(positions.get(collectionId) ?? {
|
|
42
|
-
latestTerm: 0,
|
|
43
|
-
latestSeq: 0,
|
|
44
|
-
latestRowVersion: 0,
|
|
45
|
-
}),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
function coordinatedRuntime(options) {
|
|
49
|
-
const coordination = options.coordination;
|
|
50
|
-
const runtime = {
|
|
51
|
-
owner: "test-owner",
|
|
52
|
-
namespace: "test-runtime",
|
|
53
|
-
blobBytes: new MemoryBlobBytesStore(),
|
|
54
|
-
persistence: options.adapter,
|
|
55
|
-
coordination,
|
|
56
|
-
};
|
|
57
|
-
return { runtime, coordination };
|
|
58
|
-
}
|
|
59
|
-
describe("createLocalCollection", () => {
|
|
60
|
-
it("creates an in-memory collection without runtime persistence", async () => {
|
|
61
|
-
const coordination = new SingleProcessCoordination({
|
|
62
|
-
scope: "memory-items",
|
|
63
|
-
});
|
|
64
|
-
const collection = createLocalCollection({
|
|
65
|
-
name: "memory-items",
|
|
66
|
-
getKey: (item) => item.id,
|
|
67
|
-
runtime: {
|
|
68
|
-
owner: "test-owner",
|
|
69
|
-
namespace: "memory",
|
|
70
|
-
blobBytes: new MemoryBlobBytesStore(),
|
|
71
|
-
coordination,
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
await collection.preload();
|
|
75
|
-
const transaction = collection.insert({
|
|
76
|
-
id: "one",
|
|
77
|
-
title: "In memory",
|
|
78
|
-
});
|
|
79
|
-
await transaction.isPersisted.promise;
|
|
80
|
-
expect(collection.get("one")).toMatchObject({
|
|
81
|
-
id: "one",
|
|
82
|
-
title: "In memory",
|
|
83
|
-
});
|
|
84
|
-
await collection.cleanup();
|
|
85
|
-
await coordination.close();
|
|
86
|
-
});
|
|
87
|
-
it("loads through the runtime persistence adapter when available", async () => {
|
|
88
|
-
const loadSubset = vi.fn(() => Promise.resolve([
|
|
89
|
-
{
|
|
90
|
-
key: "one",
|
|
91
|
-
value: {
|
|
92
|
-
id: "one",
|
|
93
|
-
title: "Persisted",
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
]));
|
|
97
|
-
const adapter = {
|
|
98
|
-
loadSubset,
|
|
99
|
-
applyCommittedTx: vi.fn(() => Promise.resolve()),
|
|
100
|
-
ensureIndex: vi.fn(() => Promise.resolve()),
|
|
101
|
-
};
|
|
102
|
-
const coordination = new SingleProcessCoordination({
|
|
103
|
-
scope: "persisted-items",
|
|
104
|
-
});
|
|
105
|
-
const collection = createLocalCollection({
|
|
106
|
-
name: "persisted-items",
|
|
107
|
-
getKey: (item) => item.id,
|
|
108
|
-
runtime: {
|
|
109
|
-
owner: "test-owner",
|
|
110
|
-
namespace: "persisted",
|
|
111
|
-
blobBytes: new MemoryBlobBytesStore(),
|
|
112
|
-
persistence: adapter,
|
|
113
|
-
coordination,
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
await collection.preload();
|
|
117
|
-
expect(loadSubset).toHaveBeenCalledWith("party-stack:test-owner:persisted:persisted-items", expect.any(Object), expect.any(Object));
|
|
118
|
-
expect(collection.get("one")).toMatchObject({
|
|
119
|
-
id: "one",
|
|
120
|
-
title: "Persisted",
|
|
121
|
-
});
|
|
122
|
-
await collection.cleanup();
|
|
123
|
-
await coordination.close();
|
|
124
|
-
});
|
|
125
|
-
it("propagates committed mutations between coordinated contexts", async () => {
|
|
126
|
-
const adapter = memoryAdapter();
|
|
127
|
-
const coordination = new SingleProcessCoordination({
|
|
128
|
-
scope: "local-collection-test",
|
|
129
|
-
});
|
|
130
|
-
const firstRuntime = coordinatedRuntime({
|
|
131
|
-
adapter,
|
|
132
|
-
coordination,
|
|
133
|
-
});
|
|
134
|
-
const secondRuntime = coordinatedRuntime({
|
|
135
|
-
adapter,
|
|
136
|
-
coordination,
|
|
137
|
-
});
|
|
138
|
-
const createItems = ({ runtime }) => createLocalCollection({
|
|
139
|
-
name: "shared-items",
|
|
140
|
-
getKey: (item) => item.id,
|
|
141
|
-
runtime,
|
|
142
|
-
});
|
|
143
|
-
const first = createItems(firstRuntime);
|
|
144
|
-
const second = createItems(secondRuntime);
|
|
145
|
-
await Promise.all([first.preload(), second.preload()]);
|
|
146
|
-
await second.insert({
|
|
147
|
-
id: "one",
|
|
148
|
-
title: "Shared",
|
|
149
|
-
}).isPersisted.promise;
|
|
150
|
-
await vi.waitFor(() => {
|
|
151
|
-
expect(first.get("one")?.title).toBe("Shared");
|
|
152
|
-
expect(second.get("one")?.title).toBe("Shared");
|
|
153
|
-
});
|
|
154
|
-
await first.cleanup();
|
|
155
|
-
await second.cleanup();
|
|
156
|
-
await coordination.close();
|
|
157
|
-
});
|
|
158
|
-
it("removes non-cloneable subscription and signal state from remote subset requests", async () => {
|
|
159
|
-
const adapter = memoryAdapter();
|
|
160
|
-
const coordination = new SingleProcessCoordination({
|
|
161
|
-
scope: "remote-subset-test",
|
|
162
|
-
});
|
|
163
|
-
const first = coordinatedRuntime({
|
|
164
|
-
adapter,
|
|
165
|
-
coordination,
|
|
166
|
-
});
|
|
167
|
-
const second = coordinatedRuntime({
|
|
168
|
-
adapter,
|
|
169
|
-
coordination,
|
|
170
|
-
});
|
|
171
|
-
const firstCoordinator = createPersistedCollectionCoordinator(first.coordination, adapter);
|
|
172
|
-
const secondCoordinator = createPersistedCollectionCoordinator(second.coordination, adapter);
|
|
173
|
-
await expect(secondCoordinator.requestEnsureRemoteSubset?.("items", {
|
|
174
|
-
signal: new AbortController().signal,
|
|
175
|
-
subscription: {
|
|
176
|
-
callback: () => undefined,
|
|
177
|
-
},
|
|
178
|
-
})).resolves.toBeUndefined();
|
|
179
|
-
await expect(firstCoordinator.requestEnsurePersistedIndex("items", "index", {
|
|
180
|
-
expressionSql: [],
|
|
181
|
-
})).resolves.toBeUndefined();
|
|
182
|
-
await coordination.close();
|
|
183
|
-
});
|
|
184
|
-
it("routes client-only persistence through a SharedWorker host", async () => {
|
|
185
|
-
const adapter = memoryAdapter();
|
|
186
|
-
const channel = new MessageChannel();
|
|
187
|
-
const hostCoordination = new SharedWorkerCoordinationHost({
|
|
188
|
-
scope: "shared-worker-persistence",
|
|
189
|
-
});
|
|
190
|
-
const disconnect = hostCoordination.connect(channel.port1);
|
|
191
|
-
const clientCoordination = new SharedWorkerCoordinationClient({
|
|
192
|
-
scope: "shared-worker-persistence",
|
|
193
|
-
worker: channel.port2,
|
|
194
|
-
});
|
|
195
|
-
const host = createLocalCollection({
|
|
196
|
-
name: "worker-items",
|
|
197
|
-
getKey: (item) => item.id,
|
|
198
|
-
runtime: {
|
|
199
|
-
owner: "test-owner",
|
|
200
|
-
namespace: "worker",
|
|
201
|
-
blobBytes: new MemoryBlobBytesStore(),
|
|
202
|
-
persistence: adapter,
|
|
203
|
-
coordination: hostCoordination,
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
const client = createLocalCollection({
|
|
207
|
-
name: "worker-items",
|
|
208
|
-
getKey: (item) => item.id,
|
|
209
|
-
runtime: {
|
|
210
|
-
owner: "test-owner",
|
|
211
|
-
namespace: "worker",
|
|
212
|
-
blobBytes: new MemoryBlobBytesStore(),
|
|
213
|
-
persistence: adapter,
|
|
214
|
-
coordination: clientCoordination,
|
|
215
|
-
},
|
|
216
|
-
});
|
|
217
|
-
await Promise.all([
|
|
218
|
-
host.preload(),
|
|
219
|
-
client.preload(),
|
|
220
|
-
]);
|
|
221
|
-
await client.insert({
|
|
222
|
-
id: "one",
|
|
223
|
-
title: "From client",
|
|
224
|
-
}).isPersisted.promise;
|
|
225
|
-
await vi.waitFor(() => {
|
|
226
|
-
expect(host.get("one")?.title).toBe("From client");
|
|
227
|
-
expect(client.get("one")?.title).toBe("From client");
|
|
228
|
-
});
|
|
229
|
-
expect(clientCoordination.role).toBe("client");
|
|
230
|
-
await client.cleanup();
|
|
231
|
-
await host.cleanup();
|
|
232
|
-
await clientCoordination.close();
|
|
233
|
-
disconnect();
|
|
234
|
-
await hostCoordination.close();
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
//# sourceMappingURL=createLocalCollection.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createLocalCollection.test.js","sourceRoot":"","sources":["../../src/utils/createLocalCollection.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,yBAAyB,GAE5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACH,8BAA8B,EAC9B,4BAA4B,GAE/B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EACH,QAAQ,EACR,MAAM,EACN,EAAE,EACF,EAAE,GACL,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,oCAAoC,EAAE,MAAM,wDAAwD,CAAC;AAC9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,qBA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YACzB,OAAO,EAAE;gBACL,KAAK,EAAE,YAAY;gBACnB,SAAS,EAAE,QAAQ;gBACnB,SAAS,EAAE,IAAI,oBAAoB,EAAE;gBACrC,WAAW,EAAE,OAAO;gBACpB,YAAY,EAAE,kBAAkB;aACnC;SACJ,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC;YACd,IAAI,CAAC,OAAO,EAAE;YACd,MAAM,CAAC,OAAO,EAAE;SACnB,CAAC,CAAC;QAEH,MAAM,MAAM,CAAC,MAAM,CAAC;YAChB,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,aAAa;SACvB,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC;QAEvB,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE;YAClB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAC/B,aAAa,CAChB,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CACjC,aAAa,CAChB,CAAC;QACN,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAE/C,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;QACvB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,kBAAkB,CAAC,KAAK,EAAE,CAAC;QACjC,UAAU,EAAE,CAAC;QACb,MAAM,gBAAgB,CAAC,KAAK,EAAE,CAAC;IACnC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineRuntime.test.d.ts","sourceRoot":"","sources":["../../src/utils/defineRuntime.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { defineRuntime } from "./defineRuntime.js";
|
|
3
|
-
describe("defineRuntime", () => {
|
|
4
|
-
it("deduplicates lifecycle calls and cleans up before destroying", async () => {
|
|
5
|
-
let resolveCleanup;
|
|
6
|
-
const cleanupResult = new Promise((resolve) => {
|
|
7
|
-
resolveCleanup = resolve;
|
|
8
|
-
});
|
|
9
|
-
const cleanup = vi.fn(() => cleanupResult);
|
|
10
|
-
const destroy = vi.fn(() => Promise.resolve());
|
|
11
|
-
const provider = defineRuntime((owner, namespace) => ({
|
|
12
|
-
owner,
|
|
13
|
-
namespace,
|
|
14
|
-
blobBytes: {},
|
|
15
|
-
coordination: {},
|
|
16
|
-
cleanup,
|
|
17
|
-
destroy,
|
|
18
|
-
}));
|
|
19
|
-
const runtime = provider("test", "runtime");
|
|
20
|
-
if (!runtime.cleanup || !runtime.destroy) {
|
|
21
|
-
throw new Error("Expected managed lifecycle methods.");
|
|
22
|
-
}
|
|
23
|
-
const firstCleanup = runtime.cleanup();
|
|
24
|
-
const secondCleanup = runtime.cleanup();
|
|
25
|
-
const firstDestroy = runtime.destroy();
|
|
26
|
-
const secondDestroy = runtime.destroy();
|
|
27
|
-
await Promise.resolve();
|
|
28
|
-
expect(firstCleanup).toBe(secondCleanup);
|
|
29
|
-
expect(firstDestroy).toBe(secondDestroy);
|
|
30
|
-
expect(cleanup).toHaveBeenCalledOnce();
|
|
31
|
-
expect(destroy).not.toHaveBeenCalled();
|
|
32
|
-
resolveCleanup?.();
|
|
33
|
-
await Promise.all([
|
|
34
|
-
firstCleanup,
|
|
35
|
-
firstDestroy,
|
|
36
|
-
]);
|
|
37
|
-
expect(destroy).toHaveBeenCalledOnce();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
//# sourceMappingURL=defineRuntime.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defineRuntime.test.js","sourceRoot":"","sources":["../../src/utils/defineRuntime.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,Q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