@party-stack/runtime 0.4.1 → 0.5.0

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.
Files changed (80) hide show
  1. package/lib/BrowserAuthenticationError.d.ts +11 -0
  2. package/lib/BrowserAuthenticationError.d.ts.map +1 -0
  3. package/lib/BrowserAuthenticationError.js +15 -0
  4. package/lib/BrowserAuthenticationError.js.map +1 -0
  5. package/lib/MemoryRuntime.d.ts +11 -0
  6. package/lib/MemoryRuntime.d.ts.map +1 -0
  7. package/lib/MemoryRuntime.js +23 -0
  8. package/lib/MemoryRuntime.js.map +1 -0
  9. package/lib/NetworkConnectivity.d.ts +13 -0
  10. package/lib/NetworkConnectivity.d.ts.map +1 -0
  11. package/lib/NetworkConnectivity.js +29 -0
  12. package/lib/NetworkConnectivity.js.map +1 -0
  13. package/lib/Runtime.d.ts +34 -0
  14. package/lib/Runtime.d.ts.map +1 -0
  15. package/lib/Runtime.js +28 -0
  16. package/lib/Runtime.js.map +1 -0
  17. package/lib/RuntimePartition.d.ts +16 -0
  18. package/lib/RuntimePartition.d.ts.map +1 -0
  19. package/lib/RuntimePartition.js +13 -0
  20. package/lib/RuntimePartition.js.map +1 -0
  21. package/lib/Runtimes.d.ts +22 -0
  22. package/lib/Runtimes.d.ts.map +1 -0
  23. package/lib/Runtimes.js +24 -0
  24. package/lib/Runtimes.js.map +1 -0
  25. package/lib/_virtual/_rolldown/runtime.js +13 -0
  26. package/lib/capacity.d.ts +26 -0
  27. package/lib/capacity.d.ts.map +1 -0
  28. package/lib/capacity.js +28 -0
  29. package/lib/capacity.js.map +1 -0
  30. package/lib/encryptionKeys.d.ts +36 -0
  31. package/lib/encryptionKeys.d.ts.map +1 -0
  32. package/lib/encryptionKeys.js +84 -0
  33. package/lib/encryptionKeys.js.map +1 -0
  34. package/lib/index.d.ts +11 -10
  35. package/lib/index.js +10 -9
  36. package/lib/memory/MemoryBlobBytesStore.d.ts +6 -5
  37. package/lib/memory/MemoryBlobBytesStore.d.ts.map +1 -1
  38. package/lib/memory/MemoryBlobBytesStore.js +9 -9
  39. package/lib/memory/MemoryBlobBytesStore.js.map +1 -1
  40. package/lib/testing.d.ts +42 -0
  41. package/lib/testing.d.ts.map +1 -0
  42. package/lib/testing.js +138 -0
  43. package/lib/testing.js.map +1 -0
  44. package/lib/tracing.d.ts +48 -0
  45. package/lib/tracing.d.ts.map +1 -0
  46. package/lib/tracing.js +173 -0
  47. package/lib/tracing.js.map +1 -0
  48. package/lib/types.d.ts +23 -29
  49. package/lib/types.d.ts.map +1 -1
  50. package/package.json +14 -14
  51. package/lib/coordinator/createPersistedCollectionCoordinator.d.ts +0 -6
  52. package/lib/coordinator/createPersistedCollectionCoordinator.d.ts.map +0 -1
  53. package/lib/coordinator/createPersistedCollectionCoordinator.js +0 -499
  54. package/lib/coordinator/createPersistedCollectionCoordinator.js.map +0 -1
  55. package/lib/coordinator/index.d.ts +0 -2
  56. package/lib/coordinator/index.js +0 -2
  57. package/lib/effection/index.d.ts +0 -7
  58. package/lib/effection/index.d.ts.map +0 -1
  59. package/lib/effection/index.js +0 -28
  60. package/lib/effection/index.js.map +0 -1
  61. package/lib/utils/BrowserAuthenticationCancelledError.d.ts +0 -6
  62. package/lib/utils/BrowserAuthenticationCancelledError.d.ts.map +0 -1
  63. package/lib/utils/BrowserAuthenticationCancelledError.js +0 -11
  64. package/lib/utils/BrowserAuthenticationCancelledError.js.map +0 -1
  65. package/lib/utils/createCollectionPersistence.d.ts +0 -7
  66. package/lib/utils/createCollectionPersistence.d.ts.map +0 -1
  67. package/lib/utils/createCollectionPersistence.js +0 -24
  68. package/lib/utils/createCollectionPersistence.js.map +0 -1
  69. package/lib/utils/createDefaultRuntime.d.ts +0 -5
  70. package/lib/utils/createDefaultRuntime.d.ts.map +0 -1
  71. package/lib/utils/createDefaultRuntime.js +0 -19
  72. package/lib/utils/createDefaultRuntime.js.map +0 -1
  73. package/lib/utils/createLocalCollection.d.ts +0 -11
  74. package/lib/utils/createLocalCollection.d.ts.map +0 -1
  75. package/lib/utils/createLocalCollection.js +0 -22
  76. package/lib/utils/createLocalCollection.js.map +0 -1
  77. package/lib/utils/defineRuntime.d.ts +0 -8
  78. package/lib/utils/defineRuntime.d.ts.map +0 -1
  79. package/lib/utils/defineRuntime.js +0 -30
  80. package/lib/utils/defineRuntime.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryBlobBytesStore.d.ts","names":[],"sources":["../../src/memory/MemoryBlobBytesStore.ts"],"mappings":";;qBAEa,gCAAgC;WACpB,OAAK,YAAA;EAA1B,YAAqB,QAAK,YAAA;EAE1B,MAAM,YAAY,MAAM,OAAO;EAK/B,KAAK,aAAa,QAAQ;EAK1B,OAAO,aAAa"}
1
+ {"version":3,"file":"MemoryBlobBytesStore.d.ts","names":[],"sources":["../../src/memory/MemoryBlobBytesStore.ts"],"mappings":";;;qBAQa,gCAAgC;WACpB,OAAK,YAAA;EAA1B,YAAqB,QAAK,YAAA;WAEjB,QAAK,YAAc,OAAS,cAAS,OAAA;WAMrC,OAAI,eAAc,OAAA,qDAAA;WAKlB,SAAM,eAAc,OAAA"}
@@ -1,21 +1,21 @@
1
+ import { Effect } from "effect";
2
+ import { byteSource, collectByteBlob } from "@party-stack/ontology-storage/blobs";
1
3
  //#region src/memory/MemoryBlobBytesStore.ts
2
4
  var MemoryBlobBytesStore = class {
3
5
  blobs;
4
6
  constructor(blobs = /* @__PURE__ */ new Map()) {
5
7
  this.blobs = blobs;
6
8
  }
7
- write(id, blob) {
9
+ write = (id, value) => collectByteBlob(value).pipe(Effect.map((blob) => {
8
10
  this.blobs.set(id, blob);
9
- return Promise.resolve();
10
- }
11
- read(id) {
11
+ }));
12
+ read = (id) => Effect.sync(() => {
12
13
  const blob = this.blobs.get(id);
13
- return blob ? Promise.resolve(blob) : Promise.reject(/* @__PURE__ */ new Error(`Blob bytes not found for "${id}".`));
14
- }
15
- delete(id) {
14
+ return blob === void 0 ? void 0 : byteSource(blob);
15
+ });
16
+ delete = (id) => Effect.sync(() => {
16
17
  this.blobs.delete(id);
17
- return Promise.resolve();
18
- }
18
+ });
19
19
  };
20
20
  //#endregion
21
21
  export { MemoryBlobBytesStore };
@@ -1 +1 @@
1
- {"version":3,"file":"MemoryBlobBytesStore.js","names":[],"sources":["../../src/memory/MemoryBlobBytesStore.ts"],"sourcesContent":["import type { BlobBytesStore } from \"../types.js\";\n\nexport class MemoryBlobBytesStore implements BlobBytesStore {\n constructor(readonly blobs = new Map<string, Blob>()) {}\n\n write(id: string, blob: Blob): Promise<void> {\n this.blobs.set(id, blob);\n return Promise.resolve();\n }\n\n read(id: string): Promise<Blob> {\n const blob = this.blobs.get(id);\n return blob ? Promise.resolve(blob) : Promise.reject(new Error(`Blob bytes not found for \"${id}\".`));\n }\n\n delete(id: string): Promise<void> {\n this.blobs.delete(id);\n return Promise.resolve();\n }\n}\n"],"mappings":";AAEA,IAAa,uBAAb,MAA4D;CACnC;CAArB,YAAY,wBAAiB,IAAI,IAAkB,GAAG;EAAjC,KAAA,QAAA;CAAkC;CAEvD,MAAM,IAAY,MAA2B;EACzC,KAAK,MAAM,IAAI,IAAI,IAAI;EACvB,OAAO,QAAQ,QAAQ;CAC3B;CAEA,KAAK,IAA2B;EAC5B,MAAM,OAAO,KAAK,MAAM,IAAI,EAAE;EAC9B,OAAO,OAAO,QAAQ,QAAQ,IAAI,IAAI,QAAQ,uBAAO,IAAI,MAAM,6BAA6B,GAAG,GAAG,CAAC;CACvG;CAEA,OAAO,IAA2B;EAC9B,KAAK,MAAM,OAAO,EAAE;EACpB,OAAO,QAAQ,QAAQ;CAC3B;AACJ"}
1
+ {"version":3,"file":"MemoryBlobBytesStore.js","names":[],"sources":["../../src/memory/MemoryBlobBytesStore.ts"],"sourcesContent":["import {\n byteSource,\n collectByteBlob,\n type ByteInput,\n type BlobBytesService,\n} from \"@party-stack/ontology-storage/blobs\";\nimport { Effect } from \"effect\";\n\nexport class MemoryBlobBytesStore implements BlobBytesService {\n constructor(readonly blobs = new Map<string, Blob>()) {}\n\n readonly write = (id: string, value: ByteInput) =>\n collectByteBlob(value).pipe(\n Effect.map((blob) => {\n this.blobs.set(id, blob);\n })\n );\n readonly read = (id: string) =>\n Effect.sync(() => {\n const blob = this.blobs.get(id);\n return blob === undefined ? undefined : byteSource(blob);\n });\n readonly delete = (id: string) =>\n Effect.sync(() => {\n this.blobs.delete(id);\n });\n}\n"],"mappings":";;;AAQA,IAAa,uBAAb,MAA8D;CACrC;CAArB,YAAY,wBAAiB,IAAI,IAAkB,GAAG;EAAjC,KAAA,QAAA;CAAkC;CAEvD,SAAkB,IAAY,UAC1B,gBAAgB,KAAK,CAAC,CAAC,KACnB,OAAO,KAAK,SAAS;EACjB,KAAK,MAAM,IAAI,IAAI,IAAI;CAC3B,CAAC,CACL;CACJ,QAAiB,OACb,OAAO,WAAW;EACd,MAAM,OAAO,KAAK,MAAM,IAAI,EAAE;EAC9B,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,WAAW,IAAI;CAC3D,CAAC;CACL,UAAmB,OACf,OAAO,WAAW;EACd,KAAK,MAAM,OAAO,EAAE;CACxB,CAAC;AACT"}
@@ -0,0 +1,42 @@
1
+ import { NetworkConnectivity, RuntimeOptions } from "./types.js";
2
+ import { Runtime, RuntimeService } from "./Runtime.js";
3
+ import { Runtimes } from "./Runtimes.js";
4
+ import "./index.js";
5
+ import { Effect, Layer, Scope } from "effect";
6
+ import { EncryptionError, EncryptionKeyringService } from "@party-stack/ontology-storage/encrypted";
7
+ import { OntologyStorageError } from "@party-stack/ontology-storage";
8
+ import { TablesService } from "@party-stack/ontology-storage/tables";
9
+ //#region src/testing.d.ts
10
+ export type RuntimeFixtureOptions = Omit<RuntimeOptions, "destroy" | "tables" | "encryptionKeyring" | "connectivity"> & {
11
+ readonly tables?: Effect.Effect<TablesService, OntologyStorageError, Scope.Scope>;
12
+ readonly encryptionKeyring?: Effect.Effect<EncryptionKeyringService, EncryptionError, Scope.Scope>;
13
+ readonly connectivity?: NetworkConnectivity | {
14
+ isConnected: boolean;
15
+ subscribe(callback: (online: boolean) => void): () => void;
16
+ };
17
+ readonly owner: string;
18
+ readonly namespace: string;
19
+ readonly destroy?: RuntimeOptions["destroy"] | (() => void | Promise<void>);
20
+ };
21
+ export type RuntimeFixture = Omit<RuntimeFixtureOptions, "destroy"> & {
22
+ cleanup(): Promise<void>;
23
+ destroy(): Promise<void>;
24
+ };
25
+ export declare const makeTestRuntime: (options: RuntimeFixtureOptions) => Effect.Effect<RuntimeService, EncryptionError | OntologyStorageError, Scope.Scope>;
26
+ export declare function defineRuntimeFixture(provider: (owner: string, namespace: string) => RuntimeFixtureOptions): (owner: string, namespace: string) => RuntimeFixture;
27
+ export declare const memoryRuntimeFixture: (owner: string, namespace: string) => RuntimeFixture;
28
+ export declare function acquireRuntime<E>(effect: Effect.Effect<RuntimeService, E, Scope.Scope>): Promise<RuntimeFixture>;
29
+ export declare function runtimeFixtureContext(value: RuntimeFixtureOptions): {
30
+ service: RuntimeService;
31
+ scope: Scope.Closeable;
32
+ runtime: {
33
+ runPromise: ReturnType<typeof Effect.runPromiseWith<Runtime>>;
34
+ };
35
+ };
36
+ export declare const closeRuntimeFixture: (value: object) => Promise<void>;
37
+ /** Test Layers supply the same service contract as native platform Layers. */
38
+ export declare const asRuntimeLayer: (provider: (owner: string, namespace: string) => RuntimeFixtureOptions & {
39
+ cleanup?: () => void | Promise<void>;
40
+ }) => Layer.Layer<Runtimes, never, never>;
41
+ //#endregion
42
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","names":[],"sources":["../src/testing.ts"],"mappings":";;;;;;;;;YAaY,wBAAwB,KAChC;WAGS,SAAS,OAAO,OAAO,eAAe,sBAAsB,MAAM;WAClE,oBAAoB,OAAO,OAAO,0BAA0B,iBAAiB,MAAM;WACnF,eACH;IACE;IAAsB,UAAU,WAAW;;WAC1C;WACA;WACA,UAAU,0CAA0C;;YAErD,iBAAiB,KAAK;EAC9B,WAAW;EACX,WAAW;;qBA8CF,kBAAe,SAAa,0BAAqB,OAAA,OAAA,gBAAA,kBAAA,sBAAA,MAAA;wBAe9C,qBAAqB,WAAW,eAAe,sBAAsB,yBAAqB,eACjF,sBAAmB;qBAE/B,uBAAoB,eAFR,sBAAmB;wBAOtB,eAAe,GACjC,QAAQ,OAAO,OAAO,gBAAgB,GAAG,MAAM,SAChD,QAAQ;wBAuBK,sBAAsB,OAAO;EApF5B,SAAA;EACF,OAAA,MAAM;EACJ;IAAE,YAAY,kBAAkB,OAAO,eAAe;;;qBAkH1D,sBAAmB,kBAAiB;;qBAQpC,iBAAc,WAEnB,eACA,sBACC;EAA0B,uBAAuB;MAAe,MAAA,MAAA"}
package/lib/testing.js ADDED
@@ -0,0 +1,138 @@
1
+ import { MemoryBlobBytesStore } from "./memory/MemoryBlobBytesStore.js";
2
+ import { makeNetworkConnectivity } from "./NetworkConnectivity.js";
3
+ import { RuntimePartition } from "./RuntimePartition.js";
4
+ import { Runtime, RuntimeError } from "./Runtime.js";
5
+ import { Runtimes } from "./Runtimes.js";
6
+ import { Context, Effect, Exit, Layer, Scope } from "effect";
7
+ import * as Memory from "@party-stack/ontology-storage/memory/tables";
8
+ //#region src/testing.ts
9
+ /** Test boundaries for driving scoped services from Promise-based assertions. */
10
+ const optionsByFixture = /* @__PURE__ */ new WeakMap();
11
+ const states = /* @__PURE__ */ new WeakMap();
12
+ const bridges = /* @__PURE__ */ new WeakMap();
13
+ const destroyFor = (value) => {
14
+ const destroy = (optionsByFixture.get(value) ?? value).destroy;
15
+ return typeof destroy === "function" ? Effect.tryPromise({
16
+ try: async () => {
17
+ await destroy();
18
+ },
19
+ catch: (cause) => new RuntimeError({
20
+ operation: "destroy",
21
+ cause
22
+ })
23
+ }) : destroy ?? Effect.void;
24
+ };
25
+ const optionsFor = Effect.fnUntraced(function* (value) {
26
+ const original = optionsByFixture.get(value) ?? value;
27
+ const monitor = original.connectivity;
28
+ let connectivity;
29
+ if (monitor && "isConnected" in monitor) {
30
+ const state = yield* makeNetworkConnectivity(monitor.isConnected);
31
+ yield* Effect.acquireRelease(Effect.sync(() => monitor.subscribe((online) => Effect.runSync(state.set(online)))), (unsubscribe) => Effect.sync(unsubscribe));
32
+ connectivity = {
33
+ online: Effect.sync(() => monitor.isConnected),
34
+ changes: state.changes
35
+ };
36
+ } else connectivity = monitor;
37
+ return {
38
+ ...original,
39
+ tables: yield* original.tables ?? Memory.make(),
40
+ encryptionKeyring: original.encryptionKeyring ? yield* original.encryptionKeyring : void 0,
41
+ connectivity,
42
+ destroy: destroyFor(value)
43
+ };
44
+ });
45
+ const makeTestRuntime = (options) => Effect.flatMap(optionsFor(options), Runtime.make).pipe(Effect.provideService(RuntimePartition, {
46
+ owner: options.owner,
47
+ namespace: options.namespace
48
+ }));
49
+ function fixture(options) {
50
+ let destroying;
51
+ const value = {
52
+ ...options,
53
+ cleanup: () => closeRuntimeFixture(value),
54
+ destroy: () => destroying ??= closeRuntimeFixture(value).then(() => Effect.runPromise(destroyFor(value)))
55
+ };
56
+ optionsByFixture.set(value, options);
57
+ return value;
58
+ }
59
+ function defineRuntimeFixture(provider) {
60
+ return (owner, namespace) => fixture(provider(owner, namespace));
61
+ }
62
+ const memoryRuntimeFixture = defineRuntimeFixture((owner, namespace) => ({
63
+ owner,
64
+ namespace,
65
+ blobBytes: new MemoryBlobBytesStore()
66
+ }));
67
+ async function acquireRuntime(effect) {
68
+ const scope = Effect.runSync(Scope.make());
69
+ try {
70
+ const service = await Effect.runPromise(Scope.provide(effect, scope));
71
+ const value = fixture({
72
+ owner: service.owner,
73
+ namespace: service.namespace,
74
+ tables: Effect.succeed(service.tables),
75
+ encryptionKeyring: service.encryptionKeyring ? Effect.succeed(service.encryptionKeyring) : void 0,
76
+ browserAuthentication: service.browserAuthentication,
77
+ connectivity: service.connectivity,
78
+ blobBytes: service.bytes,
79
+ destroy: service.destroy
80
+ });
81
+ states.set(value, {
82
+ service,
83
+ scope,
84
+ closed: false
85
+ });
86
+ return value;
87
+ } catch (cause) {
88
+ await Effect.runPromise(Scope.close(scope, Exit.fail(cause)));
89
+ throw cause;
90
+ }
91
+ }
92
+ function runtimeFixtureContext(value) {
93
+ let state = states.get(value);
94
+ if (state?.closed) throw new Error("Runtime is closed.");
95
+ if (!state) {
96
+ const scope = Effect.runSync(Scope.make());
97
+ state = {
98
+ service: Effect.runSync(Scope.provide(Effect.flatMap(optionsFor(value), Runtime.make).pipe(Effect.provideService(RuntimePartition, {
99
+ owner: value.owner,
100
+ namespace: value.namespace
101
+ })), scope)),
102
+ scope,
103
+ closed: false
104
+ };
105
+ states.set(value, state);
106
+ }
107
+ let bridge = bridges.get(value);
108
+ if (!bridge) {
109
+ bridge = {
110
+ service: state.service,
111
+ scope: state.scope,
112
+ runtime: { runPromise: Effect.runPromiseWith(Context.make(Runtime, state.service)) }
113
+ };
114
+ bridges.set(value, bridge);
115
+ }
116
+ return bridge;
117
+ }
118
+ const closeRuntimeFixture = (value) => {
119
+ const state = states.get(value);
120
+ if (!state) return Promise.resolve();
121
+ if (state.closing) return state.closing;
122
+ state.closed = true;
123
+ return state.closing = Effect.runPromise(Scope.close(state.scope, Exit.void));
124
+ };
125
+ /** Test Layers supply the same service contract as native platform Layers. */
126
+ const asRuntimeLayer = (provider) => Runtimes.layer(Layer.effect(Runtime, Effect.gen(function* () {
127
+ const partition = yield* RuntimePartition;
128
+ const value = yield* Effect.acquireRelease(Effect.sync(() => provider(partition.owner, partition.namespace)), (value) => Effect.promise(async () => {
129
+ await value.cleanup?.();
130
+ }));
131
+ const existing = states.get(value);
132
+ if (existing && !existing.closed) return existing.service;
133
+ return yield* Effect.flatMap(optionsFor(value), Runtime.make);
134
+ })));
135
+ //#endregion
136
+ export { acquireRuntime, asRuntimeLayer, closeRuntimeFixture, defineRuntimeFixture, makeTestRuntime, memoryRuntimeFixture, runtimeFixtureContext };
137
+
138
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","names":[],"sources":["../src/testing.ts"],"sourcesContent":["import * as Memory from \"@party-stack/ontology-storage/memory/tables\";\n/** Test boundaries for driving scoped services from Promise-based assertions. */\nimport { Context, Effect, Exit, Layer, Scope } from \"effect\";\nimport { MemoryBlobBytesStore } from \"./memory/MemoryBlobBytesStore.js\";\nimport { makeNetworkConnectivity } from \"./NetworkConnectivity.js\";\nimport { Runtime, RuntimeError } from \"./Runtime.js\";\nimport { RuntimePartition } from \"./RuntimePartition.js\";\nimport { Runtimes } from \"./Runtimes.js\";\nimport type { RuntimeOptions, RuntimeService, NetworkConnectivity } from \"./index.js\";\nimport type { OntologyStorageError } from \"@party-stack/ontology-storage\";\nimport type { EncryptionError, EncryptionKeyringService } from \"@party-stack/ontology-storage/encrypted\";\nimport type { TablesService } from \"@party-stack/ontology-storage/tables\";\n\nexport type RuntimeFixtureOptions = Omit<\n RuntimeOptions,\n \"destroy\" | \"tables\" | \"encryptionKeyring\" | \"connectivity\"\n> & {\n readonly tables?: Effect.Effect<TablesService, OntologyStorageError, Scope.Scope>;\n readonly encryptionKeyring?: Effect.Effect<EncryptionKeyringService, EncryptionError, Scope.Scope>;\n readonly connectivity?:\n | NetworkConnectivity\n | { isConnected: boolean; subscribe(callback: (online: boolean) => void): () => void };\n readonly owner: string;\n readonly namespace: string;\n readonly destroy?: RuntimeOptions[\"destroy\"] | (() => void | Promise<void>);\n};\nexport type RuntimeFixture = Omit<RuntimeFixtureOptions, \"destroy\"> & {\n cleanup(): Promise<void>;\n destroy(): Promise<void>;\n};\nconst optionsByFixture = new WeakMap<object, RuntimeFixtureOptions>();\nconst states = new WeakMap<\n object,\n { service: RuntimeService; scope: Scope.Closeable; closed: boolean; closing?: Promise<void> }\n>();\nconst bridges = new WeakMap<\n object,\n {\n service: RuntimeService;\n scope: Scope.Closeable;\n runtime: { runPromise: ReturnType<typeof Effect.runPromiseWith<Runtime>> };\n }\n>();\nconst destroyFor = (value: RuntimeFixtureOptions) => {\n const destroy = (optionsByFixture.get(value) ?? value).destroy;\n return typeof destroy === \"function\"\n ? Effect.tryPromise({\n try: async () => {\n await destroy();\n },\n catch: (cause) => new RuntimeError({ operation: \"destroy\", cause }),\n })\n : (destroy ?? Effect.void);\n};\nconst optionsFor = Effect.fnUntraced(function* (value: RuntimeFixtureOptions) {\n const original = optionsByFixture.get(value) ?? value;\n const monitor = original.connectivity;\n let connectivity: NetworkConnectivity | undefined;\n if (monitor && \"isConnected\" in monitor) {\n const state = yield* makeNetworkConnectivity(monitor.isConnected);\n yield* Effect.acquireRelease(\n Effect.sync(() => monitor.subscribe((online) => Effect.runSync(state.set(online)))),\n (unsubscribe) => Effect.sync(unsubscribe)\n );\n connectivity = { online: Effect.sync(() => monitor.isConnected), changes: state.changes };\n } else connectivity = monitor;\n return {\n ...original,\n tables: yield* original.tables ?? Memory.make(),\n encryptionKeyring: original.encryptionKeyring ? yield* original.encryptionKeyring : undefined,\n connectivity,\n destroy: destroyFor(value),\n } satisfies RuntimeOptions;\n});\nexport const makeTestRuntime = (options: RuntimeFixtureOptions) =>\n Effect.flatMap(optionsFor(options), Runtime.make).pipe(\n Effect.provideService(RuntimePartition, { owner: options.owner, namespace: options.namespace })\n );\nfunction fixture(options: RuntimeFixtureOptions): RuntimeFixture {\n let destroying: Promise<void> | undefined;\n const value = {\n ...options,\n cleanup: () => closeRuntimeFixture(value),\n destroy: () =>\n (destroying ??= closeRuntimeFixture(value).then(() => Effect.runPromise(destroyFor(value)))),\n };\n optionsByFixture.set(value, options);\n return value;\n}\nexport function defineRuntimeFixture(provider: (owner: string, namespace: string) => RuntimeFixtureOptions) {\n return (owner: string, namespace: string) => fixture(provider(owner, namespace));\n}\nexport const memoryRuntimeFixture = defineRuntimeFixture((owner, namespace) => ({\n owner,\n namespace,\n blobBytes: new MemoryBlobBytesStore(),\n}));\nexport async function acquireRuntime<E>(\n effect: Effect.Effect<RuntimeService, E, Scope.Scope>\n): Promise<RuntimeFixture> {\n const scope = Effect.runSync(Scope.make());\n try {\n const service = await Effect.runPromise(Scope.provide(effect, scope));\n const value = fixture({\n owner: service.owner,\n namespace: service.namespace,\n tables: Effect.succeed(service.tables),\n encryptionKeyring: service.encryptionKeyring\n ? Effect.succeed(service.encryptionKeyring)\n : undefined,\n browserAuthentication: service.browserAuthentication,\n connectivity: service.connectivity,\n blobBytes: service.bytes,\n destroy: service.destroy,\n });\n states.set(value, { service, scope, closed: false });\n return value;\n } catch (cause) {\n await Effect.runPromise(Scope.close(scope, Exit.fail(cause)));\n throw cause;\n }\n}\nexport function runtimeFixtureContext(value: RuntimeFixtureOptions) {\n let state = states.get(value);\n if (state?.closed) throw new Error(\"Runtime is closed.\");\n if (!state) {\n const scope = Effect.runSync(Scope.make());\n const service = Effect.runSync(\n Scope.provide(\n Effect.flatMap(optionsFor(value), Runtime.make).pipe(\n Effect.provideService(RuntimePartition, {\n owner: value.owner,\n namespace: value.namespace,\n })\n ),\n scope\n )\n );\n state = { service, scope, closed: false };\n states.set(value, state);\n }\n let bridge = bridges.get(value);\n if (!bridge) {\n bridge = {\n service: state.service,\n scope: state.scope,\n runtime: {\n runPromise: Effect.runPromiseWith(Context.make(Runtime, state.service)),\n },\n };\n bridges.set(value, bridge);\n }\n return bridge;\n}\nexport const closeRuntimeFixture = (value: object) => {\n const state = states.get(value);\n if (!state) return Promise.resolve();\n if (state.closing) return state.closing;\n state.closed = true;\n return (state.closing = Effect.runPromise(Scope.close(state.scope, Exit.void)));\n};\n/** Test Layers supply the same service contract as native platform Layers. */\nexport const asRuntimeLayer = (\n provider: (\n owner: string,\n namespace: string\n ) => RuntimeFixtureOptions & { cleanup?: () => void | Promise<void> }\n) =>\n Runtimes.layer(\n Layer.effect(\n Runtime,\n Effect.gen(function* () {\n const partition = yield* RuntimePartition;\n const value = yield* Effect.acquireRelease(\n Effect.sync(() => provider(partition.owner, partition.namespace)),\n (value) =>\n Effect.promise(async () => {\n await value.cleanup?.();\n })\n );\n const existing = states.get(value);\n if (existing && !existing.closed) return existing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name: string;
5
+ readonly at: number;
6
+ readonly attributes: Readonly<Record<string, string | number | boolean>>;
7
+ }
8
+ export interface TraceRecord {
9
+ readonly id: string;
10
+ readonly traceId: string;
11
+ readonly parentId?: string;
12
+ readonly name: string;
13
+ readonly startedAt: number;
14
+ readonly durationMs: number;
15
+ readonly outcome: "running" | "success" | "failure" | "interrupted";
16
+ readonly error?: {
17
+ readonly kind: "Error" | "Defect";
18
+ readonly message: string;
19
+ };
20
+ readonly attributes: Readonly<Record<string, string | number | boolean>>;
21
+ readonly events?: readonly TraceEvent[];
22
+ readonly eventCount?: number;
23
+ }
24
+ export interface TraceStore {
25
+ readonly getSnapshot: () => readonly TraceRecord[];
26
+ readonly subscribe: (listener: (record?: TraceRecord) => void) => () => void;
27
+ readonly clear: () => void;
28
+ }
29
+ /** Bounded Effect spans and error messages; no stacks, error payloads, or arbitrary attributes. */
30
+ export declare function createTraceCapture(capacity?: number, upstream?: Tracer.Tracer, history?: boolean): {
31
+ tracer: Tracer.Tracer;
32
+ getSnapshot: () => readonly TraceRecord[];
33
+ subscribe: (listener: (record?: TraceRecord) => void) => () => void;
34
+ clear: () => void;
35
+ };
36
+ export type TraceCapture = ReturnType<typeof createTraceCapture>;
37
+ /** Diagnostics configuration is independent of platform Runtime acquisition. */
38
+ export type TraceRecordingMode = false | "buffer" | "live";
39
+ export declare const TraceRecording: Context.Reference<TraceRecordingMode>;
40
+ /** Capture alongside the configured Effect tracer; production recording is opt-in. */
41
+ export declare const makeTraceCapture: (mode?: TraceRecordingMode | undefined) => Effect.Effect<{
42
+ tracer: Tracer.Tracer;
43
+ getSnapshot: () => readonly TraceRecord[];
44
+ subscribe: (listener: (record?: TraceRecord) => void) => () => void;
45
+ clear: () => void;
46
+ } | undefined, never, never>;
47
+ //#endregion
48
+ //# sourceMappingURL=tracing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.d.ts","names":[],"sources":["../src/tracing.ts"],"mappings":";;iBAEiB;WACJ;WACA;WACA,YAAY,SAAS;;iBAEjB;WACJ;WACA;WACA;WACA;WACA;WACA;WACA;WACA;aAAmB;aAAmC;;WACtD,YAAY,SAAS;WACrB,kBAAkB;WAClB;;iBAEI;WACJ,4BAA4B;WAC5B,YAAY,WAAW,SAAS;WAChC;;;wBAGG,mBAAmB,mBAAgB,WAAW,OAAO,QAAQ;;;EAyK/C,YAAA,WAAC,SAAS;;;YAa5B,eAAe,kBAAkB;;YAGjC;qBACC,gBAAc,QAAA,UAAA;;qBAMd,mBAAgB,OAAA,mCAAA,OAAA;;;EAvBC,YAAA,WAAC,SAAS"}
package/lib/tracing.js ADDED
@@ -0,0 +1,173 @@
1
+ import { Cause, Context, Effect, Exit, Option, Predicate, Tracer } from "effect";
2
+ //#region src/tracing.ts
3
+ /** Bounded Effect spans and error messages; no stacks, error payloads, or arbitrary attributes. */
4
+ function createTraceCapture(capacity = 500, upstream, history = true) {
5
+ if (!Number.isSafeInteger(capacity) || capacity < 1) throw new RangeError("Trace capacity must be positive.");
6
+ const exporter = upstream === Tracer.nativeTracer ? void 0 : upstream;
7
+ const allowed = /* @__PURE__ */ new Set([
8
+ "objectType",
9
+ "operation",
10
+ "count",
11
+ "revision",
12
+ "state",
13
+ "db.system.name",
14
+ "activity",
15
+ "stage",
16
+ "operationId",
17
+ "streamId",
18
+ "sequence",
19
+ "part",
20
+ "end",
21
+ "changes",
22
+ "records",
23
+ "generation",
24
+ "installed",
25
+ "acknowledged",
26
+ "expected",
27
+ "replay",
28
+ "until",
29
+ "receipt",
30
+ "parentAccepted",
31
+ "errorKind",
32
+ "recovery",
33
+ "hint",
34
+ "reusedCoverage",
35
+ "reason",
36
+ "rows",
37
+ "storedRows",
38
+ "changed",
39
+ "inserted",
40
+ "updated",
41
+ "unchanged",
42
+ "removed",
43
+ "retentionRows",
44
+ "repairCandidates",
45
+ "repairRequests",
46
+ "repairRows",
47
+ "indexes",
48
+ "concurrency",
49
+ "peakWrites",
50
+ "uniqueSlots",
51
+ "uniqueProbes"
52
+ ]);
53
+ let records = [];
54
+ let generation = 0;
55
+ const listeners = /* @__PURE__ */ new Set();
56
+ const changed = (record) => {
57
+ for (const listener of listeners) try {
58
+ listener(record);
59
+ } catch {}
60
+ };
61
+ return {
62
+ tracer: Tracer.make({
63
+ context: exporter?.context?.bind(exporter),
64
+ span(options) {
65
+ const span = exporter ? exporter.span(options) : new Tracer.NativeSpan(options);
66
+ if (!options.sampled) return span;
67
+ const spanGeneration = generation;
68
+ let current = {
69
+ id: span.spanId,
70
+ traceId: span.traceId,
71
+ parentId: Option.getOrUndefined(span.parent)?.spanId,
72
+ name: span.name,
73
+ startedAt: Number(options.startTime / 1000n) / 1e3,
74
+ durationMs: 0,
75
+ outcome: "running",
76
+ attributes: {}
77
+ };
78
+ let ended = false;
79
+ const publish = () => {
80
+ if (generation !== spanGeneration) return;
81
+ const index = records.findIndex((record) => record.id === span.spanId && record.traceId === span.traceId);
82
+ if (history) records = index < 0 ? [...records.slice(Math.max(0, records.length - capacity + 1)), current] : records.map((record, at) => at === index ? current : record);
83
+ changed(current);
84
+ };
85
+ const safeAttributes = (entries) => {
86
+ const result = {};
87
+ for (const [key, value] of entries) if (allowed.has(key) && (typeof value === "string" || typeof value === "number" || typeof value === "boolean")) result[key] = value;
88
+ return result;
89
+ };
90
+ publish();
91
+ const attribute = span.attribute.bind(span);
92
+ span.attribute = (key, value) => {
93
+ attribute(key, value);
94
+ if (!ended && allowed.has(key)) {
95
+ current = {
96
+ ...current,
97
+ attributes: safeAttributes(span.attributes)
98
+ };
99
+ publish();
100
+ }
101
+ };
102
+ const event = exporter ? span.event.bind(span) : void 0;
103
+ span.event = (name, time, attributes = {}) => {
104
+ event?.(name, time, attributes);
105
+ if (ended || attributes.diagnostic !== true) return;
106
+ current = {
107
+ ...current,
108
+ events: [...(current.events ?? []).slice(-99), {
109
+ name,
110
+ at: Number(time) / 1e6,
111
+ attributes: safeAttributes(Object.entries(attributes))
112
+ }],
113
+ eventCount: (current.eventCount ?? 0) + 1
114
+ };
115
+ publish();
116
+ };
117
+ const end = span.end.bind(span);
118
+ span.end = (time, exit) => {
119
+ end(time, exit);
120
+ if (ended) return;
121
+ ended = true;
122
+ const interrupted = Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause);
123
+ let error;
124
+ if (Exit.isFailure(exit) && !interrupted) {
125
+ const reason = exit.cause.reasons.find(Cause.isFailReason) ?? exit.cause.reasons.find(Cause.isDieReason);
126
+ const value = reason?._tag === "Fail" ? reason.error : reason?.defect;
127
+ let message = "Error details were not recorded.";
128
+ try {
129
+ const candidate = Predicate.isError(value) ? value.message : value;
130
+ if (Predicate.isString(candidate)) message = candidate;
131
+ } catch {}
132
+ error = {
133
+ kind: reason?._tag === "Die" ? "Defect" : "Error",
134
+ message: message.slice(0, 500) || "No error message provided."
135
+ };
136
+ }
137
+ current = {
138
+ ...current,
139
+ durationMs: Number(time - options.startTime) / 1e6,
140
+ outcome: Exit.isSuccess(exit) ? "success" : interrupted ? "interrupted" : "failure",
141
+ ...error ? { error } : {},
142
+ attributes: safeAttributes(span.attributes)
143
+ };
144
+ publish();
145
+ };
146
+ return span;
147
+ }
148
+ }),
149
+ getSnapshot: () => records,
150
+ subscribe: (listener) => {
151
+ listeners.add(listener);
152
+ return () => {
153
+ listeners.delete(listener);
154
+ };
155
+ },
156
+ clear: () => {
157
+ generation++;
158
+ records = [];
159
+ changed();
160
+ }
161
+ };
162
+ }
163
+ const TraceRecording = Context.Reference("@party-stack/runtime/tracing/TraceRecording", { defaultValue: () => false });
164
+ /** Capture alongside the configured Effect tracer; production recording is opt-in. */
165
+ const makeTraceCapture = Effect.fnUntraced(function* (mode) {
166
+ const recording = mode ?? (yield* TraceRecording);
167
+ if (!recording) return void 0;
168
+ return createTraceCapture(500, yield* Tracer.Tracer, recording === "buffer");
169
+ });
170
+ //#endregion
171
+ export { TraceRecording, createTraceCapture, makeTraceCapture };
172
+
173
+ //# sourceMappingURL=tracing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tracing.js","names":[],"sources":["../src/tracing.ts"],"sourcesContent":["import { Cause, Context, Effect, Exit, Option, Predicate, Tracer } from \"effect\";\n\nexport interface TraceEvent {\n readonly name: string;\n readonly at: number;\n readonly attributes: Readonly<Record<string, string | number | boolean>>;\n}\nexport interface TraceRecord {\n readonly id: string;\n readonly traceId: string;\n readonly parentId?: string;\n readonly name: string;\n readonly startedAt: number;\n readonly durationMs: number;\n readonly outcome: \"running\" | \"success\" | \"failure\" | \"interrupted\";\n readonly error?: { readonly kind: \"Error\" | \"Defect\"; readonly message: string };\n readonly attributes: Readonly<Record<string, string | number | boolean>>;\n readonly events?: readonly TraceEvent[];\n readonly eventCount?: number;\n}\nexport interface TraceStore {\n readonly getSnapshot: () => readonly TraceRecord[];\n readonly subscribe: (listener: (record?: TraceRecord) => void) => () => void;\n readonly clear: () => void;\n}\n/** Bounded Effect spans and error messages; no stacks, error payloads, or arbitrary attributes. */\nexport function createTraceCapture(capacity = 500, upstream?: Tracer.Tracer, history = true) {\n if (!Number.isSafeInteger(capacity) || capacity < 1)\n throw new RangeError(\"Trace capacity must be positive.\");\n const exporter = upstream === Tracer.nativeTracer ? undefined : upstream;\n const allowed = new Set([\n \"objectType\",\n \"operation\",\n \"count\",\n \"revision\",\n \"state\",\n \"db.system.name\",\n \"activity\",\n \"stage\",\n \"operationId\",\n \"streamId\",\n \"sequence\",\n \"part\",\n \"end\",\n \"changes\",\n \"records\",\n \"generation\",\n \"installed\",\n \"acknowledged\",\n \"expected\",\n \"replay\",\n \"until\",\n \"receipt\",\n \"parentAccepted\",\n \"errorKind\",\n \"recovery\",\n \"hint\",\n \"reusedCoverage\",\n \"reason\",\n \"rows\",\n \"storedRows\",\n \"changed\",\n \"inserted\",\n \"updated\",\n \"unchanged\",\n \"removed\",\n \"retentionRows\",\n \"repairCandidates\",\n \"repairRequests\",\n \"repairRows\",\n \"indexes\",\n \"concurrency\",\n \"peakWrites\",\n \"uniqueSlots\",\n \"uniqueProbes\",\n ]);\n let records: readonly TraceRecord[] = [];\n let generation = 0;\n const listeners = new Set<(record?: TraceRecord) => void>();\n const changed = (record?: TraceRecord) => {\n for (const listener of listeners) {\n try {\n listener(record);\n } catch {\n /* Observers cannot fail an operation. */\n }\n }\n };\n const tracer = Tracer.make({\n context: exporter?.context?.bind(exporter),\n span(options) {\n const span = exporter ? exporter.span(options) : new Tracer.NativeSpan(options);\n if (!options.sampled) return span;\n const spanGeneration = generation;\n const initial: TraceRecord = {\n id: span.spanId,\n traceId: span.traceId,\n parentId: Option.getOrUndefined(span.parent)?.spanId,\n name: span.name,\n startedAt: Number(options.startTime / 1000n) / 1000,\n durationMs: 0,\n outcome: \"running\",\n attributes: {},\n };\n let current = initial;\n let ended = false;\n const publish = () => {\n if (generation !== spanGeneration) return;\n const index = records.findIndex(\n (record) => record.id === span.spanId && record.traceId === span.traceId\n );\n if (history)\n records =\n index < 0\n ? [...records.slice(Math.max(0, records.length - capacity + 1)), current]\n : records.map((record, at) => (at === index ? current : record));\n changed(current);\n };\n const safeAttributes = (entries: Iterable<readonly [string, unknown]>) => {\n const result: Record<string, string | number | boolean> = {};\n for (const [key, value] of entries)\n if (\n allowed.has(key) &&\n (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\")\n )\n result[key] = value;\n return result;\n };\n publish();\n const attribute = span.attribute.bind(span);\n span.attribute = (key, value) => {\n attribute(key, value);\n if (!ended && allowed.has(key)) {\n current = { ...current, attributes: safeAttributes(span.attributes) };\n publish();\n }\n };\n // Producers explicitly opt diagnostic events in; platform code knows no domain event names.\n const event = exporter ? span.event.bind(span) : undefined;\n span.event = (name, time, attributes = {}) => {\n event?.(name, time, attributes);\n if (ended || attributes.diagnostic !== true) return;\n current = {\n ...current,\n events: [\n ...(current.events ?? []).slice(-99),\n {\n name,\n at: Number(time) / 1_000_000,\n attributes: safeAttributes(Object.entries(attributes)),\n },\n ],\n eventCount: (current.eventCount ?? 0) + 1,\n };\n publish();\n };\n const end = span.end.bind(span);\n span.end = (time, exit) => {\n end(time, exit);\n if (ended) return;\n ended = true;\n const interrupted = Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause);\n let error: TraceRecord[\"error\"];\n if (Exit.isFailure(exit) && !interrupted) {\n const reason =\n exit.cause.reasons.find(Cause.isFailReason) ??\n exit.cause.reasons.find(Cause.isDieReason);\n const value = reason?._tag === \"Fail\" ? reason.error : reason?.defect;\n let message = \"Error details were not recorded.\";\n try {\n const candidate = Predicate.isError(value) ? value.message : value;\n if (Predicate.isString(candidate)) message = candidate;\n } catch {\n /* A diagnostic must not fail while inspecting a custom error. */\n }\n error = {\n kind: reason?._tag === \"Die\" ? \"Defect\" : \"Error\",\n message: message.slice(0, 500) || \"No error message provided.\",\n };\n }\n current = {\n ...current,\n durationMs: Number(time - options.startTime) / 1_000_000,\n outcome: Exit.isSuccess(exit) ? \"success\" : interrupted ? \"interrupted\" : \"failure\",\n ...(error ? { error } : {}),\n attributes: safeAttributes(span.attributes),\n };\n publish();\n };\n return span;\n },\n });\n return {\n tracer,\n getSnapshot: () => records,\n subscribe: (listener: (record?: TraceRecord) => void) => {\n listeners.add(listener);\n return () => {\n listeners.delete(listener);\n };\n },\n clear: () => {\n generation++;\n records = [];\n changed();\n },\n };\n}\nexport type TraceCapture = ReturnType<typeof createTraceCapture>;\n\n/** Diagnostics configuration is independent of platform Runtime acquisition. */\nexport type TraceRecordingMode = false | \"buffer\" | \"live\";\nexport const TraceRecording = Context.Reference<TraceRecordingMode>(\n \"@party-stack/runtime/tracing/TraceRecording\",\n { defaultValue: () => false }\n);\n\n/** Capture alongside the configured Effect tracer; production recording is opt-in. */\nexport const makeTraceCapture = Effect.fnUntraced(function* (mode?: TraceRecordingMode) {\n const recording = mode ?? (yield* TraceRecording);\n if (!recording) return undefined;\n return createTraceCapture(500, yield* Tracer.Tracer, recording === \"buffer\");\n});\n"],"mappings":";;;AA0BA,SAAgB,mBAAmB,WAAW,KAAK,UAA0B,UAAU,MAAM;CACzF,IAAI,CAAC,O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;MACtC,MAAM,SACF,KAAK,MAAM,QAAQ,KAAK,MAAM,YAAY,KAC1C,KAAK,MAAM,QAAQ,KAAK,MAAM,WAAW;MAC7C,MAAM,QAAQ,QAAQ,SAAS,SAAS,OAAO,QAAQ,QAAQ;MAC/D,IAAI,UAAU;MACd,IAAI;OACA,MAAM,YAAY,UAAU,QAAQ,KAAK,IAAI,MAAM,UAAU;OAC7D,IAAI,UAAU,SAAS,SAAS,GAAG,UAAU;MACjD,QAAQ,CAER;MACA,QAAQ;OACJ,MAAM,QAAQ,SAAS,QAAQ,WAAW;OAC1C,SAAS,QAAQ,MAAM,GAAG,GAAG,KAAK;MACtC;KACJ;KACA,UAAU;MACN,GAAG;MACH,YAAY,OAAO,OAAO,QAAQ,SAAS,IAAI;MAC/C,SAAS,KAAK,UAAU,IAAI,IAAI,YAAY,cAAc,gBAAgB;MAC1E,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;MACzB,YAAY,eAAe,KAAK,UAAU;KAC9C;KACA,QAAQ;IACZ;IACA,OAAO;GACX;EACJ,CAES;EACL,mBAAmB;EACnB,YAAY,aAA6C;GACrD,UAAU,IAAI,QAAQ;GACtB,aAAa;IACT,UAAU,OAAO,QAAQ;GAC7B;EACJ;EACA,aAAa;GACT;GACA,UAAU,CAAC;GACX,QAAQ;EACZ;CACJ;AACJ;AAKA,MAAa,iBAAiB,QAAQ,UAClC,+CACA,EAAE,oBAAoB,MAAM,CAChC;;AAGA,MAAa,mBAAmB,OAAO,WAAW,WAAW,MAA2B;CACpF,MAAM,YAAY,SAAS,OAAO;CAClC,IAAI,CAAC,WAAW,OAAO,KAAA;CACvB,OAAO,mBAAmB,KAAK,OAAO,OAAO,QAAQ,cAAc,QAAQ;AAC/E,CAAC"}
package/lib/types.d.ts CHANGED
@@ -1,46 +1,40 @@
1
- import { Coordination } from "@party-stack/coordination";
2
- import { PersistedCollectionPersistence, PersistenceAdapter } from "@tanstack/db-sqlite-persistence-core";
1
+ import { BrowserAuthenticationError } from "./BrowserAuthenticationError.js";
2
+ import { ResourceCapacity } from "./capacity.js";
3
+ import { RuntimeError } from "./Runtime.js";
4
+ import { Effect, Scope, Stream } from "effect";
5
+ import { EncryptionError, EncryptionKeyringService } from "@party-stack/ontology-storage/encrypted";
6
+ import { BlobBytesService } from "@party-stack/ontology-storage/blobs";
7
+ import { OntologyStorageError } from "@party-stack/ontology-storage";
8
+ import { TablesService } from "@party-stack/ontology-storage/tables";
3
9
  //#region src/types.d.ts
4
- export interface BlobBytesStore {
5
- write(id: string, blob: Blob): Promise<void>;
6
- read(id: string): Promise<Blob>;
7
- delete(id: string): Promise<void>;
8
- }
9
10
  export interface NetworkConnectivity {
10
- readonly isConnected: boolean;
11
- subscribe(callback: (isConnected: boolean) => void): () => void;
12
- }
13
- export interface SecretStore {
14
- get(key: string): Promise<string | undefined>;
15
- set(key: string, value: string): Promise<void>;
16
- delete(key: string): Promise<void>;
11
+ readonly online: Effect.Effect<boolean>;
12
+ /** Includes the current state; intermediate transitions may be coalesced. */
13
+ readonly changes: Stream.Stream<boolean>;
17
14
  }
18
15
  export type BrowserAuthenticationPresentation = "popup" | "redirect";
19
16
  export interface BrowserAuthenticationSession {
20
- open(authorizationUrl: string): Promise<{
17
+ open(authorizationUrl: string): Effect.Effect<{
21
18
  callbackUrl: string;
22
- }>;
23
- close(): void | Promise<void>;
19
+ }, BrowserAuthenticationError>;
24
20
  }
25
21
  export interface BrowserAuthentication {
26
22
  start(options: {
27
23
  redirectUrl: string;
28
24
  presentation?: BrowserAuthenticationPresentation;
29
- }): BrowserAuthenticationSession;
25
+ }): Effect.Effect<BrowserAuthenticationSession, BrowserAuthenticationError, Scope.Scope>;
30
26
  }
31
- export interface RuntimeAdapter {
32
- readonly owner: string;
33
- readonly namespace: string;
34
- blobBytes: BlobBytesStore;
35
- coordination: Coordination;
27
+ /** Platform-acquired capabilities; Runtime.make assembles the RuntimeService. */
28
+ export interface RuntimeOptions {
29
+ readonly capacity?: ResourceCapacity;
30
+ blobBytes: BlobBytesService;
36
31
  connectivity?: NetworkConnectivity;
37
32
  browserAuthentication?: BrowserAuthentication;
38
- secrets?: SecretStore;
39
- persistence?: PersistedCollectionPersistence;
40
- cleanup?: () => void | Promise<void>;
41
- destroy?: () => void | Promise<void>;
33
+ encryptionKeyring?: EncryptionKeyringService;
34
+ /** Acquired by the platform layer in its scope, including explicit memory tables. */
35
+ tables: TablesService;
36
+ destroy?: Effect.Effect<void, RuntimeError>;
42
37
  }
43
- export type RuntimeAdapterProvider = (owner: string, namespace: string) => RuntimeAdapter | Promise<RuntimeAdapter>;
38
+ export type RuntimeAcquisitionError = RuntimeError | OntologyStorageError | EncryptionError;
44
39
  //#endregion
45
- export type { PersistenceAdapter };
46
40
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;iBAGiB;EACb,MAAM,YAAY,MAAM,OAAO;EAC/B,KAAK,aAAa,QAAQ;EAC1B,OAAO,aAAa;;iBAGP;WACJ;EACT,UAAU,WAAW;;iBAGR;EACb,IAAI,cAAc;EAClB,IAAI,aAAa,gBAAgB;EACjC,OAAO,cAAc;;YAGb;iBAEK;EACb,KAAK,2BAA2B;IAAU;;EAC1C,gBAAgB;;iBAGH;EACb,MAAM;IACF;IACA,eAAe;MACf;;iBAKS;WACJ;WACA;EACT,WAAW;EACX,cAAc;EACd,eAAe;EACf,wBAAwB;EACxB,UAAU;EACV,cAAc;EACd,uBAAuB;EACvB,uBAAuB;;YAGf,0BACR,eACA,sBACC,iBAAiB,QAAQ"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;iBASiB;WACJ,QAAQ,OAAO;;WAEf,SAAS,OAAO;;YAGjB;iBAEK;EACb,KAAK,2BAA2B,OAAO;IAAS;KAAuB;;iBAG1D;EACb,MAAM;IACF;IACA,eAAe;MACf,OAAO,OAAO,8BAA8B,4BAA4B,MAAM;;;iBAIrE;WACJ,WAAW;EACpB,WAAW;EACX,eAAe;EACf,wBAAwB;EACxB,oBAAoB;;EAEpB,QAAQ;EACR,UAAU,OAAO,aAAa;;YAGtB,0BAA0B,eAAe,uBAAuB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@party-stack/runtime",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "files": [
5
5
  "lib"
6
6
  ],
@@ -10,24 +10,24 @@
10
10
  "types": "./lib/index.d.ts",
11
11
  "default": "./lib/index.js"
12
12
  },
13
- "./effection": {
14
- "types": "./lib/effection/index.d.ts",
15
- "default": "./lib/effection/index.js"
13
+ "./testing": {
14
+ "types": "./lib/testing.d.ts",
15
+ "default": "./lib/testing.js"
16
+ },
17
+ "./tracing": {
18
+ "types": "./lib/tracing.d.ts",
19
+ "default": "./lib/tracing.js"
16
20
  }
17
21
  },
18
22
  "dependencies": {
19
- "effection": "^4.0.2",
20
- "@party-stack/coordination": "0.3.1"
23
+ "effect": "^4.0.5",
24
+ "@party-stack/ontology-storage": "0.2.0"
21
25
  },
22
26
  "devDependencies": {
23
- "@tanstack/db": "0.12.1",
24
- "@tanstack/db-sqlite-persistence-core": "0.4.5",
27
+ "temporal-polyfill": "^0.3.0",
25
28
  "typescript": "~7.0.2",
26
- "vite-plus": "1.1.0",
27
- "@party-stack/build-config": "0.1.1"
28
- },
29
- "peerDependencies": {
30
- "@tanstack/db": "0.12.1",
31
- "@tanstack/db-sqlite-persistence-core": "0.4.5"
29
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.2.0",
30
+ "vite-plus": "1.2.0",
31
+ "@party-stack/build-config": "0.2.0"
32
32
  }
33
33
  }
@@ -1,6 +0,0 @@
1
- import { Coordination } from "@party-stack/coordination";
2
- import { PersistedCollectionCoordinator, PersistenceAdapter } from "@tanstack/db-sqlite-persistence-core";
3
- //#region src/coordinator/createPersistedCollectionCoordinator.d.ts
4
- export declare function createPersistedCollectionCoordinator(coordination: Coordination, adapter: PersistenceAdapter): PersistedCollectionCoordinator;
5
- //#endregion
6
- //# sourceMappingURL=createPersistedCollectionCoordinator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createPersistedCollectionCoordinator.d.ts","names":[],"sources":["../../src/coordinator/createPersistedCollectionCoordinator.ts"],"mappings":";;;wBA+IgB,qCACZ,cAAc,cACd,SAAS,qBACV"}