@procedures/client 0.2.0 → 0.2.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/CHANGELOG.md +6 -0
- package/README.md +4 -4
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js.map +1 -1
- package/dist/procedures/invoke.d.ts +6 -1
- package/dist/procedures/invoke.d.ts.map +1 -1
- package/dist/procedures/invoke.js +2 -2
- package/dist/procedures/invoke.js.map +1 -1
- package/dist/server/host-policy.d.ts +3 -3
- package/dist/server/host-policy.d.ts.map +1 -1
- package/dist/server/procedure-server.d.ts +2 -2
- package/dist/server/procedure-server.d.ts.map +1 -1
- package/dist/server/procedure-server.js.map +1 -1
- package/package.json +1 -1
- package/src/browser.ts +1 -0
- package/src/procedures/invoke.ts +10 -4
- package/src/server/host-policy.ts +3 -3
- package/src/server/procedure-server.ts +2 -2
- package/dist/client/middleware/batching.d.ts +0 -102
- package/dist/client/middleware/batching.d.ts.map +0 -1
- package/dist/client/middleware/batching.js +0 -245
- package/dist/client/middleware/batching.js.map +0 -1
- package/dist/collections/async/async-queue.d.ts +0 -144
- package/dist/collections/async/async-queue.d.ts.map +0 -1
- package/dist/collections/async/async-queue.js +0 -347
- package/dist/collections/async/async-queue.js.map +0 -1
- package/dist/collections/async/channels.d.ts +0 -188
- package/dist/collections/async/channels.d.ts.map +0 -1
- package/dist/collections/async/channels.js +0 -312
- package/dist/collections/async/channels.js.map +0 -1
- package/dist/collections/behaviors/bounded.d.ts +0 -79
- package/dist/collections/behaviors/bounded.d.ts.map +0 -1
- package/dist/collections/behaviors/bounded.js +0 -384
- package/dist/collections/behaviors/bounded.js.map +0 -1
- package/dist/collections/behaviors/evented.d.ts +0 -154
- package/dist/collections/behaviors/evented.d.ts.map +0 -1
- package/dist/collections/behaviors/evented.js +0 -299
- package/dist/collections/behaviors/evented.js.map +0 -1
- package/dist/collections/behaviors/lru.d.ts +0 -84
- package/dist/collections/behaviors/lru.d.ts.map +0 -1
- package/dist/collections/behaviors/lru.js +0 -330
- package/dist/collections/behaviors/lru.js.map +0 -1
- package/dist/collections/behaviors/readonly.d.ts +0 -73
- package/dist/collections/behaviors/readonly.d.ts.map +0 -1
- package/dist/collections/behaviors/readonly.js +0 -158
- package/dist/collections/behaviors/readonly.js.map +0 -1
- package/dist/collections/behaviors/safe.d.ts +0 -163
- package/dist/collections/behaviors/safe.d.ts.map +0 -1
- package/dist/collections/behaviors/safe.js +0 -172
- package/dist/collections/behaviors/safe.js.map +0 -1
- package/dist/collections/behaviors/synchronized.d.ts +0 -88
- package/dist/collections/behaviors/synchronized.d.ts.map +0 -1
- package/dist/collections/behaviors/synchronized.js +0 -294
- package/dist/collections/behaviors/synchronized.js.map +0 -1
- package/dist/collections/behaviors/ttl.d.ts +0 -118
- package/dist/collections/behaviors/ttl.d.ts.map +0 -1
- package/dist/collections/behaviors/ttl.js +0 -338
- package/dist/collections/behaviors/ttl.js.map +0 -1
- package/dist/collections/core/effects.d.ts +0 -176
- package/dist/collections/core/effects.d.ts.map +0 -1
- package/dist/collections/core/effects.js +0 -180
- package/dist/collections/core/effects.js.map +0 -1
- package/dist/collections/core/events.d.ts +0 -192
- package/dist/collections/core/events.d.ts.map +0 -1
- package/dist/collections/core/events.js +0 -291
- package/dist/collections/core/events.js.map +0 -1
- package/dist/collections/core/middleware.d.ts +0 -231
- package/dist/collections/core/middleware.d.ts.map +0 -1
- package/dist/collections/core/middleware.js +0 -161
- package/dist/collections/core/middleware.js.map +0 -1
- package/dist/collections/core/policies.d.ts +0 -220
- package/dist/collections/core/policies.d.ts.map +0 -1
- package/dist/collections/core/policies.js +0 -48
- package/dist/collections/core/policies.js.map +0 -1
- package/dist/collections/core/traits.d.ts +0 -142
- package/dist/collections/core/traits.d.ts.map +0 -1
- package/dist/collections/core/traits.js +0 -8
- package/dist/collections/core/traits.js.map +0 -1
- package/dist/collections/examples.d.ts +0 -13
- package/dist/collections/examples.d.ts.map +0 -1
- package/dist/collections/examples.js +0 -302
- package/dist/collections/examples.js.map +0 -1
- package/dist/collections/fx/collectors.d.ts +0 -190
- package/dist/collections/fx/collectors.d.ts.map +0 -1
- package/dist/collections/fx/collectors.js +0 -369
- package/dist/collections/fx/collectors.js.map +0 -1
- package/dist/collections/fx/iter.d.ts +0 -166
- package/dist/collections/fx/iter.d.ts.map +0 -1
- package/dist/collections/fx/iter.js +0 -421
- package/dist/collections/fx/iter.js.map +0 -1
- package/dist/collections/impl/array-deque.d.ts +0 -107
- package/dist/collections/impl/array-deque.d.ts.map +0 -1
- package/dist/collections/impl/array-deque.js +0 -381
- package/dist/collections/impl/array-deque.js.map +0 -1
- package/dist/collections/impl/array-list.d.ts +0 -101
- package/dist/collections/impl/array-list.d.ts.map +0 -1
- package/dist/collections/impl/array-list.js +0 -387
- package/dist/collections/impl/array-list.js.map +0 -1
- package/dist/collections/impl/hash-map.d.ts +0 -141
- package/dist/collections/impl/hash-map.d.ts.map +0 -1
- package/dist/collections/impl/hash-map.js +0 -450
- package/dist/collections/impl/hash-map.js.map +0 -1
- package/dist/collections/impl/hash-set.d.ts +0 -125
- package/dist/collections/impl/hash-set.d.ts.map +0 -1
- package/dist/collections/impl/hash-set.js +0 -264
- package/dist/collections/impl/hash-set.js.map +0 -1
- package/dist/collections/impl/linked-hash-map.d.ts +0 -141
- package/dist/collections/impl/linked-hash-map.d.ts.map +0 -1
- package/dist/collections/impl/linked-hash-map.js +0 -472
- package/dist/collections/impl/linked-hash-map.js.map +0 -1
- package/dist/collections/impl/linked-list.d.ts +0 -109
- package/dist/collections/impl/linked-list.d.ts.map +0 -1
- package/dist/collections/impl/linked-list.js +0 -491
- package/dist/collections/impl/linked-list.js.map +0 -1
- package/dist/collections/impl/priority-queue.d.ts +0 -134
- package/dist/collections/impl/priority-queue.d.ts.map +0 -1
- package/dist/collections/impl/priority-queue.js +0 -336
- package/dist/collections/impl/priority-queue.js.map +0 -1
- package/dist/collections/impl/tree-map.d.ts +0 -146
- package/dist/collections/impl/tree-map.d.ts.map +0 -1
- package/dist/collections/impl/tree-map.js +0 -781
- package/dist/collections/impl/tree-map.js.map +0 -1
- package/dist/collections/impl/tree-set.d.ts +0 -112
- package/dist/collections/impl/tree-set.d.ts.map +0 -1
- package/dist/collections/impl/tree-set.js +0 -374
- package/dist/collections/impl/tree-set.js.map +0 -1
- package/dist/collections/index.d.ts +0 -105
- package/dist/collections/index.d.ts.map +0 -1
- package/dist/collections/index.js +0 -135
- package/dist/collections/index.js.map +0 -1
- package/dist/collections/interfaces/collection.d.ts +0 -119
- package/dist/collections/interfaces/collection.d.ts.map +0 -1
- package/dist/collections/interfaces/collection.js +0 -8
- package/dist/collections/interfaces/collection.js.map +0 -1
- package/dist/collections/interfaces/list.d.ts +0 -247
- package/dist/collections/interfaces/list.d.ts.map +0 -1
- package/dist/collections/interfaces/list.js +0 -8
- package/dist/collections/interfaces/list.js.map +0 -1
- package/dist/collections/interfaces/map.d.ts +0 -344
- package/dist/collections/interfaces/map.d.ts.map +0 -1
- package/dist/collections/interfaces/map.js +0 -8
- package/dist/collections/interfaces/map.js.map +0 -1
- package/dist/collections/interfaces/queue.d.ts +0 -304
- package/dist/collections/interfaces/queue.d.ts.map +0 -1
- package/dist/collections/interfaces/queue.js +0 -8
- package/dist/collections/interfaces/queue.js.map +0 -1
- package/dist/collections/interfaces/set.d.ts +0 -137
- package/dist/collections/interfaces/set.d.ts.map +0 -1
- package/dist/collections/interfaces/set.js +0 -8
- package/dist/collections/interfaces/set.js.map +0 -1
- package/dist/collections/storage/api.d.ts +0 -109
- package/dist/collections/storage/api.d.ts.map +0 -1
- package/dist/collections/storage/api.js +0 -182
- package/dist/collections/storage/api.js.map +0 -1
- package/dist/collections/storage/hybrid.d.ts +0 -164
- package/dist/collections/storage/hybrid.d.ts.map +0 -1
- package/dist/collections/storage/hybrid.js +0 -416
- package/dist/collections/storage/hybrid.js.map +0 -1
- package/dist/collections/storage/index.d.ts +0 -16
- package/dist/collections/storage/index.d.ts.map +0 -1
- package/dist/collections/storage/index.js +0 -13
- package/dist/collections/storage/index.js.map +0 -1
- package/dist/collections/storage/interface.d.ts +0 -141
- package/dist/collections/storage/interface.d.ts.map +0 -1
- package/dist/collections/storage/interface.js +0 -23
- package/dist/collections/storage/interface.js.map +0 -1
- package/dist/collections/storage/memory.d.ts +0 -68
- package/dist/collections/storage/memory.d.ts.map +0 -1
- package/dist/collections/storage/memory.js +0 -154
- package/dist/collections/storage/memory.js.map +0 -1
- package/dist/collections/utils/defaults.d.ts +0 -135
- package/dist/collections/utils/defaults.d.ts.map +0 -1
- package/dist/collections/utils/defaults.js +0 -322
- package/dist/collections/utils/defaults.js.map +0 -1
- package/dist/collections/utils/factories.d.ts +0 -144
- package/dist/collections/utils/factories.d.ts.map +0 -1
- package/dist/collections/utils/factories.js +0 -293
- package/dist/collections/utils/factories.js.map +0 -1
- package/dist/collections/utils/helpers.d.ts +0 -137
- package/dist/collections/utils/helpers.d.ts.map +0 -1
- package/dist/collections/utils/helpers.js +0 -221
- package/dist/collections/utils/helpers.js.map +0 -1
- package/dist/collections.d.ts +0 -12
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -10
- package/dist/collections.js.map +0 -1
- package/dist/components/define.d.ts +0 -134
- package/dist/components/define.d.ts.map +0 -1
- package/dist/components/define.js +0 -486
- package/dist/components/define.js.map +0 -1
- package/dist/components/index.d.ts +0 -39
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -38
- package/dist/components/index.js.map +0 -1
- package/dist/components/types.d.ts +0 -264
- package/dist/components/types.d.ts.map +0 -1
- package/dist/components/types.js +0 -46
- package/dist/components/types.js.map +0 -1
- package/dist/procedures/storage/adapter.d.ts +0 -148
- package/dist/procedures/storage/adapter.d.ts.map +0 -1
- package/dist/procedures/storage/adapter.js +0 -214
- package/dist/procedures/storage/adapter.js.map +0 -1
- package/dist/procedures/storage/api.d.ts +0 -125
- package/dist/procedures/storage/api.d.ts.map +0 -1
- package/dist/procedures/storage/api.js +0 -220
- package/dist/procedures/storage/api.js.map +0 -1
- package/dist/procedures/storage/factory.d.ts +0 -134
- package/dist/procedures/storage/factory.d.ts.map +0 -1
- package/dist/procedures/storage/factory.js +0 -166
- package/dist/procedures/storage/factory.js.map +0 -1
- package/dist/procedures/storage/hybrid.d.ts +0 -193
- package/dist/procedures/storage/hybrid.d.ts.map +0 -1
- package/dist/procedures/storage/hybrid.js +0 -519
- package/dist/procedures/storage/hybrid.js.map +0 -1
- package/dist/procedures/storage/index.d.ts +0 -17
- package/dist/procedures/storage/index.d.ts.map +0 -1
- package/dist/procedures/storage/index.js +0 -17
- package/dist/procedures/storage/index.js.map +0 -1
- package/dist/procedures/storage/procedures.d.ts +0 -39
- package/dist/procedures/storage/procedures.d.ts.map +0 -1
- package/dist/procedures/storage/procedures.js +0 -261
- package/dist/procedures/storage/procedures.js.map +0 -1
- package/dist/procedures/storage/serialization.d.ts +0 -123
- package/dist/procedures/storage/serialization.d.ts.map +0 -1
- package/dist/procedures/storage/serialization.js +0 -216
- package/dist/procedures/storage/serialization.js.map +0 -1
- package/dist/procedures/storage/synced-registry.d.ts +0 -246
- package/dist/procedures/storage/synced-registry.d.ts.map +0 -1
- package/dist/procedures/storage/synced-registry.js +0 -575
- package/dist/procedures/storage/synced-registry.js.map +0 -1
- package/dist/procedures/storage/types.d.ts +0 -130
- package/dist/procedures/storage/types.d.ts.map +0 -1
- package/dist/procedures/storage/types.js +0 -8
- package/dist/procedures/storage/types.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/procedures/storage/adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,GAEhB,MAAM,oBAAoB,CAAC;AAiB5B;;;;;;;;;;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CAAC,IAAI,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,SAAS;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED,8EAA8E;IAC9E,YAAY;IACZ,8EAA8E;IAE9E;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API Storage Implementation
|
|
3
|
-
*
|
|
4
|
-
* Remote storage backed by universal client.
|
|
5
|
-
* Enables collections to be persisted on a server.
|
|
6
|
-
*
|
|
7
|
-
* This is the KEY integration between Collections and Universal Client!
|
|
8
|
-
*/
|
|
9
|
-
import type { CollectionStorage, StorageMetadata } from "@mark1russell7/client-collections";
|
|
10
|
-
import type { Client } from "../../client/client.js";
|
|
11
|
-
/**
|
|
12
|
-
* API storage configuration options.
|
|
13
|
-
*/
|
|
14
|
-
export interface ApiStorageOptions {
|
|
15
|
-
/**
|
|
16
|
-
* The collection of the core collection procedures. The calls go to
|
|
17
|
-
* `collections.<collection>.<operation>`, as `createCollectionProcedures(collection)` registers them.
|
|
18
|
-
* @example "users", "procedures"
|
|
19
|
-
*/
|
|
20
|
-
collection?: string;
|
|
21
|
-
/**
|
|
22
|
-
* Service name for RPC calls. The default is `collections.<collection>`. Give a service only
|
|
23
|
-
* for a server with other paths.
|
|
24
|
-
* @example "users", "orders", "products"
|
|
25
|
-
*/
|
|
26
|
-
service?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Optional API version
|
|
29
|
-
* @example "v1", "v2"
|
|
30
|
-
*/
|
|
31
|
-
version?: string;
|
|
32
|
-
/**
|
|
33
|
-
* Custom operation names (override defaults)
|
|
34
|
-
*/
|
|
35
|
-
operations?: {
|
|
36
|
-
get?: string;
|
|
37
|
-
getAll?: string;
|
|
38
|
-
find?: string;
|
|
39
|
-
has?: string;
|
|
40
|
-
size?: string;
|
|
41
|
-
set?: string;
|
|
42
|
-
delete?: string;
|
|
43
|
-
clear?: string;
|
|
44
|
-
setBatch?: string;
|
|
45
|
-
deleteBatch?: string;
|
|
46
|
-
getBatch?: string;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Request timeout in milliseconds. A call that takes longer fails. 0: no timeout.
|
|
50
|
-
* @default 30000 (30 seconds)
|
|
51
|
-
*/
|
|
52
|
-
timeout?: number;
|
|
53
|
-
/**
|
|
54
|
-
* Retry a call that fails with a retryable error: true (3 attempts), false (1 attempt), or the
|
|
55
|
-
* number of attempts.
|
|
56
|
-
* @default true
|
|
57
|
-
*/
|
|
58
|
-
retry?: boolean | number;
|
|
59
|
-
/**
|
|
60
|
-
* The first delay between attempts in milliseconds. Each later delay is two times longer.
|
|
61
|
-
* @default 100
|
|
62
|
-
*/
|
|
63
|
-
retryDelay?: number;
|
|
64
|
-
/**
|
|
65
|
-
* AbortSignal for cancelling requests
|
|
66
|
-
*/
|
|
67
|
-
signal?: AbortSignal;
|
|
68
|
-
/**
|
|
69
|
-
* True: `close()` closes the client. The default is false: the client belongs to the caller.
|
|
70
|
-
* @default false
|
|
71
|
-
*/
|
|
72
|
-
closeClient?: boolean;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* API storage backed by universal client.
|
|
76
|
-
*
|
|
77
|
-
* Maps collection operations to the core collection procedures
|
|
78
|
-
* (`createCollectionProcedures`), which take and return raw values:
|
|
79
|
-
* - get(id) → `collections.<collection>.get` with `{ id }`
|
|
80
|
-
* - set(id, value) → `collections.<collection>.set` with `{ id, value }`
|
|
81
|
-
* - setBatch(items) → `collections.<collection>.setBatch` with `{ items: [{ id, value }] }`
|
|
82
|
-
* - etc.
|
|
83
|
-
*
|
|
84
|
-
* Before, the class expected a `{ data }` envelope and called `<service>.get`: no core
|
|
85
|
-
* procedure matched, and every read was undefined (deep dive CORE-9, DATA-9).
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```typescript
|
|
89
|
-
* // Create API storage
|
|
90
|
-
* const client = new Client({
|
|
91
|
-
* transport: new HttpTransport({ baseUrl: "https://api.example.com" })
|
|
92
|
-
* });
|
|
93
|
-
*
|
|
94
|
-
* const storage = new ApiStorage(client, { collection: "users" });
|
|
95
|
-
*
|
|
96
|
-
* // Operations are automatically sent to server
|
|
97
|
-
* await storage.set("123", { name: "John" });
|
|
98
|
-
* const user = await storage.get("123"); // Fetched from server
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
export declare class ApiStorage<T> implements CollectionStorage<T> {
|
|
102
|
-
private client;
|
|
103
|
-
private options;
|
|
104
|
-
constructor(client: Client, options: ApiStorageOptions);
|
|
105
|
-
get(id: string): Promise<T | undefined>;
|
|
106
|
-
getAll(): Promise<T[]>;
|
|
107
|
-
find(predicate: (item: T) => boolean): Promise<T[]>;
|
|
108
|
-
has(id: string): Promise<boolean>;
|
|
109
|
-
size(): Promise<number>;
|
|
110
|
-
set(id: string, value: T): Promise<void>;
|
|
111
|
-
delete(id: string): Promise<boolean>;
|
|
112
|
-
clear(): Promise<void>;
|
|
113
|
-
setBatch(items: Array<[string, T]>): Promise<void>;
|
|
114
|
-
deleteBatch(ids: string[]): Promise<number>;
|
|
115
|
-
getBatch(ids: string[]): Promise<Map<string, T>>;
|
|
116
|
-
close(): Promise<void>;
|
|
117
|
-
getMetadata(): Promise<StorageMetadata>;
|
|
118
|
-
/**
|
|
119
|
-
* Make an RPC call via the universal client, with the timeout, the signal and the retries.
|
|
120
|
-
*/
|
|
121
|
-
private call;
|
|
122
|
-
/** One attempt: the call ends at the timeout, or when the signal of the options aborts. */
|
|
123
|
-
private attempt;
|
|
124
|
-
}
|
|
125
|
-
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/procedures/storage/api.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAC5F,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAIrD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,UAAU,CAAC,EAAE;QACX,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IAEF;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAEzB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AA+BD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0B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;IAC3F,OAAO,CAAC,OAAO;CAsBhB"}
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API Storage Implementation
|
|
3
|
-
*
|
|
4
|
-
* Remote storage backed by universal client.
|
|
5
|
-
* Enables collections to be persisted on a server.
|
|
6
|
-
*
|
|
7
|
-
* This is the KEY integration between Collections and Universal Client!
|
|
8
|
-
*/
|
|
9
|
-
/** An error that says whether another attempt can succeed (a ClientError does). */
|
|
10
|
-
function isRetryable(error) {
|
|
11
|
-
return (typeof error === "object" &&
|
|
12
|
-
error !== null &&
|
|
13
|
-
error.retryable === true);
|
|
14
|
-
}
|
|
15
|
-
/** A promise that rejects when the signal aborts first. */
|
|
16
|
-
function untilAborted(promise, signal, describe) {
|
|
17
|
-
if (!signal)
|
|
18
|
-
return promise;
|
|
19
|
-
if (signal.aborted)
|
|
20
|
-
return Promise.reject(describe());
|
|
21
|
-
return new Promise((resolve, reject) => {
|
|
22
|
-
const onAbort = () => reject(describe());
|
|
23
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
24
|
-
promise.then((value) => {
|
|
25
|
-
signal.removeEventListener("abort", onAbort);
|
|
26
|
-
resolve(value);
|
|
27
|
-
}, (error) => {
|
|
28
|
-
signal.removeEventListener("abort", onAbort);
|
|
29
|
-
reject(error);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* API storage backed by universal client.
|
|
35
|
-
*
|
|
36
|
-
* Maps collection operations to the core collection procedures
|
|
37
|
-
* (`createCollectionProcedures`), which take and return raw values:
|
|
38
|
-
* - get(id) → `collections.<collection>.get` with `{ id }`
|
|
39
|
-
* - set(id, value) → `collections.<collection>.set` with `{ id, value }`
|
|
40
|
-
* - setBatch(items) → `collections.<collection>.setBatch` with `{ items: [{ id, value }] }`
|
|
41
|
-
* - etc.
|
|
42
|
-
*
|
|
43
|
-
* Before, the class expected a `{ data }` envelope and called `<service>.get`: no core
|
|
44
|
-
* procedure matched, and every read was undefined (deep dive CORE-9, DATA-9).
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* // Create API storage
|
|
49
|
-
* const client = new Client({
|
|
50
|
-
* transport: new HttpTransport({ baseUrl: "https://api.example.com" })
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* const storage = new ApiStorage(client, { collection: "users" });
|
|
54
|
-
*
|
|
55
|
-
* // Operations are automatically sent to server
|
|
56
|
-
* await storage.set("123", { name: "John" });
|
|
57
|
-
* const user = await storage.get("123"); // Fetched from server
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
export class ApiStorage {
|
|
61
|
-
client;
|
|
62
|
-
options;
|
|
63
|
-
constructor(client, options) {
|
|
64
|
-
const service = options.service ?? (options.collection !== undefined ? `collections.${options.collection}` : undefined);
|
|
65
|
-
if (!service) {
|
|
66
|
-
throw new Error("ApiStorage requires a collection or a service");
|
|
67
|
-
}
|
|
68
|
-
this.client = client;
|
|
69
|
-
this.options = {
|
|
70
|
-
service,
|
|
71
|
-
...(options.version !== undefined && { version: options.version }),
|
|
72
|
-
operations: {
|
|
73
|
-
get: "get",
|
|
74
|
-
getAll: "getAll",
|
|
75
|
-
find: "find",
|
|
76
|
-
has: "has",
|
|
77
|
-
size: "size",
|
|
78
|
-
set: "set",
|
|
79
|
-
delete: "delete",
|
|
80
|
-
clear: "clear",
|
|
81
|
-
setBatch: "setBatch",
|
|
82
|
-
deleteBatch: "deleteBatch",
|
|
83
|
-
getBatch: "getBatch",
|
|
84
|
-
...options.operations,
|
|
85
|
-
},
|
|
86
|
-
timeout: options.timeout ?? 30000,
|
|
87
|
-
attempts: options.retry === false ? 1 : options.retry === true || options.retry === undefined ? 3 : Math.max(1, options.retry),
|
|
88
|
-
retryDelay: options.retryDelay ?? 100,
|
|
89
|
-
...(options.signal !== undefined && { signal: options.signal }),
|
|
90
|
-
closeClient: options.closeClient ?? false,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
//
|
|
94
|
-
// ═══ Read Operations ═══
|
|
95
|
-
//
|
|
96
|
-
async get(id) {
|
|
97
|
-
const value = await this.call("get", { id });
|
|
98
|
-
return value ?? undefined;
|
|
99
|
-
}
|
|
100
|
-
async getAll() {
|
|
101
|
-
const values = await this.call("getAll", {});
|
|
102
|
-
if (!Array.isArray(values)) {
|
|
103
|
-
throw new Error(`${this.options.service}.getAll did not return an array`);
|
|
104
|
-
}
|
|
105
|
-
return values;
|
|
106
|
-
}
|
|
107
|
-
async find(predicate) {
|
|
108
|
-
// A predicate cannot go over the network: read all items, then filter here
|
|
109
|
-
const all = await this.getAll();
|
|
110
|
-
return all.filter(predicate);
|
|
111
|
-
}
|
|
112
|
-
async has(id) {
|
|
113
|
-
return (await this.call("has", { id })) === true;
|
|
114
|
-
}
|
|
115
|
-
async size() {
|
|
116
|
-
return Number(await this.call("size", {}));
|
|
117
|
-
}
|
|
118
|
-
//
|
|
119
|
-
// ═══ Write Operations ═══
|
|
120
|
-
//
|
|
121
|
-
async set(id, value) {
|
|
122
|
-
await this.call("set", { id, value });
|
|
123
|
-
}
|
|
124
|
-
async delete(id) {
|
|
125
|
-
return (await this.call("delete", { id })) === true;
|
|
126
|
-
}
|
|
127
|
-
async clear() {
|
|
128
|
-
await this.call("clear", {});
|
|
129
|
-
}
|
|
130
|
-
//
|
|
131
|
-
// ═══ Bulk Operations ═══
|
|
132
|
-
//
|
|
133
|
-
async setBatch(items) {
|
|
134
|
-
// The collection procedure takes objects, not tuples
|
|
135
|
-
await this.call("setBatch", { items: items.map(([id, value]) => ({ id, value })) });
|
|
136
|
-
}
|
|
137
|
-
async deleteBatch(ids) {
|
|
138
|
-
return Number(await this.call("deleteBatch", { ids }));
|
|
139
|
-
}
|
|
140
|
-
async getBatch(ids) {
|
|
141
|
-
const values = (await this.call("getBatch", { ids })) ?? {};
|
|
142
|
-
// Convert object to Map
|
|
143
|
-
const result = new Map();
|
|
144
|
-
for (const [id, value] of Object.entries(values)) {
|
|
145
|
-
result.set(id, value);
|
|
146
|
-
}
|
|
147
|
-
return result;
|
|
148
|
-
}
|
|
149
|
-
//
|
|
150
|
-
// ═══ Lifecycle & Metadata ═══
|
|
151
|
-
//
|
|
152
|
-
async close() {
|
|
153
|
-
// The client belongs to the caller, unless the caller gave it to this storage
|
|
154
|
-
if (this.options.closeClient) {
|
|
155
|
-
await this.client.close();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
async getMetadata() {
|
|
159
|
-
const storageSize = await this.size();
|
|
160
|
-
return {
|
|
161
|
-
type: "api",
|
|
162
|
-
size: storageSize,
|
|
163
|
-
stats: {
|
|
164
|
-
service: this.options.service,
|
|
165
|
-
version: this.options.version,
|
|
166
|
-
timeout: this.options.timeout,
|
|
167
|
-
},
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
//
|
|
171
|
-
// ═══ Internal Helpers ═══
|
|
172
|
-
//
|
|
173
|
-
/**
|
|
174
|
-
* Make an RPC call via the universal client, with the timeout, the signal and the retries.
|
|
175
|
-
*/
|
|
176
|
-
async call(operation, payload) {
|
|
177
|
-
const method = {
|
|
178
|
-
service: this.options.service,
|
|
179
|
-
operation: this.options.operations[operation] ?? operation,
|
|
180
|
-
...(this.options.version !== undefined && { version: this.options.version }),
|
|
181
|
-
};
|
|
182
|
-
const label = `${method.service}.${method.operation}`;
|
|
183
|
-
for (let attempt = 1;; attempt++) {
|
|
184
|
-
try {
|
|
185
|
-
return await this.attempt(method, payload, label);
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
if (attempt >= this.options.attempts || !isRetryable(error) || this.options.signal?.aborted) {
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
const delay = this.options.retryDelay * 2 ** (attempt - 1);
|
|
192
|
-
await untilAborted(new Promise((resolve) => setTimeout(resolve, delay)), this.options.signal, () => error);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/** One attempt: the call ends at the timeout, or when the signal of the options aborts. */
|
|
197
|
-
attempt(method, payload, label) {
|
|
198
|
-
const signals = [];
|
|
199
|
-
if (this.options.signal)
|
|
200
|
-
signals.push(this.options.signal);
|
|
201
|
-
const timer = this.options.timeout > 0 ? new AbortController() : undefined;
|
|
202
|
-
let timeoutHandle;
|
|
203
|
-
if (timer) {
|
|
204
|
-
timeoutHandle = setTimeout(() => timer.abort(), this.options.timeout);
|
|
205
|
-
signals.push(timer.signal);
|
|
206
|
-
}
|
|
207
|
-
const signal = signals.length === 0 ? undefined : signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
208
|
-
// The signal goes in the call options, so the transport can stop the request too. (Before,
|
|
209
|
-
// it went into the metadata, and the timeout was dropped: deep dive CORE-9.)
|
|
210
|
-
const callOptions = {};
|
|
211
|
-
if (signal)
|
|
212
|
-
callOptions.signal = signal;
|
|
213
|
-
const call = this.client.call(method, payload, callOptions);
|
|
214
|
-
return untilAborted(call, signal, () => timer?.signal.aborted ? new Error(`${label} timed out after ${this.options.timeout} ms`) : new Error(`${label} was aborted`)).finally(() => {
|
|
215
|
-
if (timeoutHandle !== undefined)
|
|
216
|
-
clearTimeout(timeoutHandle);
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
//# sourceMappingURL=api.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/procedures/storage/api.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AA+EH,mFAAmF;AACnF,SAAS,WAAW,CAAC,KAAc;IACjC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACb,KAAiC,CAAC,SAAS,KAAK,IAAI,CACtD,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,SAAS,YAAY,CAAI,OAAmB,EAAE,MAA+B,EAAE,QAAqB;IAClG,IAAI,CAAC,MAAM;QAAE,OAAO,O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O,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,KAAK,cAAc,CAAC,CAC7H,CAAC,OAAO,CAAC,GAAG,EAAE;YACb,IAAI,aAAa,KAAK,SAAS;gBAAE,YAAY,CAAC,aAAa,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Procedure Storage Factory
|
|
3
|
-
*
|
|
4
|
-
* Factory functions for creating storage-backed procedure registries.
|
|
5
|
-
*/
|
|
6
|
-
import type { Client } from "../../client/client.js";
|
|
7
|
-
import type { CollectionStorage } from "@mark1russell7/client-collections";
|
|
8
|
-
import type { HybridStorageOptions } from "./hybrid.js";
|
|
9
|
-
import { ProcedureRegistry } from "../registry.js";
|
|
10
|
-
import type { SerializedProcedure, SyncedRegistryOptions, HandlerLoader } from "./types.js";
|
|
11
|
-
import { SyncedProcedureRegistry } from "./synced-registry.js";
|
|
12
|
-
/**
|
|
13
|
-
* Configuration for creating a synced procedure registry.
|
|
14
|
-
*/
|
|
15
|
-
export interface CreateSyncedRegistryConfig {
|
|
16
|
-
/**
|
|
17
|
-
* Storage type to use.
|
|
18
|
-
* - "memory": In-memory only (fast, volatile)
|
|
19
|
-
* - "api": Remote storage via client procedures
|
|
20
|
-
* - "hybrid": Local cache + remote sync
|
|
21
|
-
*/
|
|
22
|
-
type: "memory" | "api" | "hybrid";
|
|
23
|
-
/**
|
|
24
|
-
* Universal client instance (required for "api" and "hybrid" types).
|
|
25
|
-
*/
|
|
26
|
-
client?: Client | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* The collection of the core collection procedures on the server: the calls go to
|
|
29
|
-
* `collections.<collection>.<operation>`.
|
|
30
|
-
* @default "procedures"
|
|
31
|
-
*/
|
|
32
|
-
collection?: string | undefined;
|
|
33
|
-
/**
|
|
34
|
-
* The service of the calls, for a server with other paths. The default is
|
|
35
|
-
* `collections.<collection>`.
|
|
36
|
-
*/
|
|
37
|
-
service?: string | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Additional options for hybrid storage.
|
|
40
|
-
*/
|
|
41
|
-
hybridOptions?: Partial<HybridStorageOptions> | undefined;
|
|
42
|
-
/**
|
|
43
|
-
* Options for the synced registry.
|
|
44
|
-
*/
|
|
45
|
-
registryOptions?: Partial<SyncedRegistryOptions> | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Base registry to wrap.
|
|
48
|
-
* @default PROCEDURE_REGISTRY (global singleton)
|
|
49
|
-
*/
|
|
50
|
-
baseRegistry?: ProcedureRegistry | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* Custom handler loader.
|
|
53
|
-
* @default Dynamic import loader
|
|
54
|
-
*/
|
|
55
|
-
handlerLoader?: HandlerLoader | undefined;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Create a synced procedure registry with the specified storage backend.
|
|
59
|
-
*
|
|
60
|
-
* @param config - Configuration for the registry
|
|
61
|
-
* @returns SyncedProcedureRegistry instance
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* // In-memory only (for testing)
|
|
66
|
-
* const registry = createSyncedRegistry({ type: 'memory' });
|
|
67
|
-
*
|
|
68
|
-
* // API storage (remote persistence)
|
|
69
|
-
* const registry = createSyncedRegistry({
|
|
70
|
-
* type: 'api',
|
|
71
|
-
* client: myClient,
|
|
72
|
-
* service: 'procedures',
|
|
73
|
-
* });
|
|
74
|
-
*
|
|
75
|
-
* // Hybrid storage (offline-first)
|
|
76
|
-
* const registry = createSyncedRegistry({
|
|
77
|
-
* type: 'hybrid',
|
|
78
|
-
* client: myClient,
|
|
79
|
-
* service: 'procedures',
|
|
80
|
-
* hybridOptions: {
|
|
81
|
-
* writeStrategy: 'write-through',
|
|
82
|
-
* conflictResolution: 'remote',
|
|
83
|
-
* },
|
|
84
|
-
* });
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export declare function createSyncedRegistry(config: CreateSyncedRegistryConfig): SyncedProcedureRegistry;
|
|
88
|
-
/**
|
|
89
|
-
* Create an in-memory synced registry.
|
|
90
|
-
* Useful for testing or when persistence isn't needed.
|
|
91
|
-
*
|
|
92
|
-
* @param baseRegistry - Base registry to wrap
|
|
93
|
-
* @returns SyncedProcedureRegistry with in-memory storage
|
|
94
|
-
*/
|
|
95
|
-
export declare function createMemorySyncedRegistry(baseRegistry?: ProcedureRegistry): SyncedProcedureRegistry;
|
|
96
|
-
/**
|
|
97
|
-
* Create an API-backed synced registry.
|
|
98
|
-
*
|
|
99
|
-
* @param client - Universal client instance
|
|
100
|
-
* @param collection - The collection of the core collection procedures on the server
|
|
101
|
-
* @param baseRegistry - Base registry to wrap
|
|
102
|
-
* @returns SyncedProcedureRegistry with API storage
|
|
103
|
-
*/
|
|
104
|
-
export declare function createApiSyncedRegistry(client: Client, collection?: string, baseRegistry?: ProcedureRegistry): SyncedProcedureRegistry;
|
|
105
|
-
/**
|
|
106
|
-
* Create a hybrid synced registry (offline-first).
|
|
107
|
-
*
|
|
108
|
-
* @param client - Universal client instance
|
|
109
|
-
* @param collection - The collection of the core collection procedures on the server
|
|
110
|
-
* @param options - Hybrid storage options
|
|
111
|
-
* @param baseRegistry - Base registry to wrap
|
|
112
|
-
* @returns SyncedProcedureRegistry with hybrid storage
|
|
113
|
-
*/
|
|
114
|
-
export declare function createHybridSyncedRegistry(client: Client, collection?: string, options?: Partial<HybridStorageOptions>, baseRegistry?: ProcedureRegistry): SyncedProcedureRegistry;
|
|
115
|
-
/**
|
|
116
|
-
* Create a synced registry with a custom storage backend.
|
|
117
|
-
*
|
|
118
|
-
* @param storage - Custom CollectionStorage implementation
|
|
119
|
-
* @param options - Registry options
|
|
120
|
-
* @param baseRegistry - Base registry to wrap
|
|
121
|
-
* @returns SyncedProcedureRegistry with custom storage
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* // Use MongoDB storage
|
|
126
|
-
* const mongoStorage = new MongoCollectionStorage<SerializedProcedure>(
|
|
127
|
-
* mongoClient,
|
|
128
|
-
* 'procedures'
|
|
129
|
-
* );
|
|
130
|
-
* const registry = createCustomSyncedRegistry(mongoStorage);
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
export declare function createCustomSyncedRegistry(storage: CollectionStorage<SerializedProcedure>, options?: Partial<SyncedRegistryOptions>, baseRegistry?: ProcedureRegistry): SyncedProcedureRegistry;
|
|
134
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/procedures/storage/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAI3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAsB,MAAM,gBAAgB,CAAC;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAO/D;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,IAAI,EAAE,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;IAElC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE5B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEhC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAE7B;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,SAAS,CAAC;IAE1D;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GAAG,SAAS,CAAC;IAE7D;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAE7C;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CAC3C;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,0BAA0B,GAAG,uBAAuB,CA6DhG;AAMD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,YAAY,GAAE,iBAAsC,GACnD,uBAAuB,CAKzB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,UAAU,SAAe,EACzB,YAAY,GAAE,iBAAsC,GACnD,uBAAuB,CAOzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,UAAU,SAAe,EACzB,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,EACvC,YAAY,GAAE,iBAAsC,GACnD,uBAAuB,CAQzB;AAMD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,EAC/C,OAAO,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,EACxC,YAAY,GAAE,iBAAsC,GACnD,uBAAuB,CAKzB"}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Procedure Storage Factory
|
|
3
|
-
*
|
|
4
|
-
* Factory functions for creating storage-backed procedure registries.
|
|
5
|
-
*/
|
|
6
|
-
import { InMemoryStorage } from "@mark1russell7/client-collections";
|
|
7
|
-
import { ApiStorage } from "./api.js";
|
|
8
|
-
import { HybridStorage } from "./hybrid.js";
|
|
9
|
-
import { ProcedureRegistry, PROCEDURE_REGISTRY } from "../registry.js";
|
|
10
|
-
import { SyncedProcedureRegistry } from "./synced-registry.js";
|
|
11
|
-
import { getSerializedKey } from "./serialization.js";
|
|
12
|
-
// =============================================================================
|
|
13
|
-
// Factory Function
|
|
14
|
-
// =============================================================================
|
|
15
|
-
/**
|
|
16
|
-
* Create a synced procedure registry with the specified storage backend.
|
|
17
|
-
*
|
|
18
|
-
* @param config - Configuration for the registry
|
|
19
|
-
* @returns SyncedProcedureRegistry instance
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* // In-memory only (for testing)
|
|
24
|
-
* const registry = createSyncedRegistry({ type: 'memory' });
|
|
25
|
-
*
|
|
26
|
-
* // API storage (remote persistence)
|
|
27
|
-
* const registry = createSyncedRegistry({
|
|
28
|
-
* type: 'api',
|
|
29
|
-
* client: myClient,
|
|
30
|
-
* service: 'procedures',
|
|
31
|
-
* });
|
|
32
|
-
*
|
|
33
|
-
* // Hybrid storage (offline-first)
|
|
34
|
-
* const registry = createSyncedRegistry({
|
|
35
|
-
* type: 'hybrid',
|
|
36
|
-
* client: myClient,
|
|
37
|
-
* service: 'procedures',
|
|
38
|
-
* hybridOptions: {
|
|
39
|
-
* writeStrategy: 'write-through',
|
|
40
|
-
* conflictResolution: 'remote',
|
|
41
|
-
* },
|
|
42
|
-
* });
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export function createSyncedRegistry(config) {
|
|
46
|
-
const { type, client, collection = "procedures", service, hybridOptions, registryOptions = {}, baseRegistry = PROCEDURE_REGISTRY,
|
|
47
|
-
// No loader unless the caller gives one: stored records load as stubs. (Before, the default
|
|
48
|
-
// imported any module a stored record named: BUGS-2026-07 M11, deep dive CORE-7.)
|
|
49
|
-
handlerLoader, } = config;
|
|
50
|
-
// Validate client is provided for api/hybrid
|
|
51
|
-
if ((type === "api" || type === "hybrid") && !client) {
|
|
52
|
-
throw new Error(`Client is required for storage type: ${type}`);
|
|
53
|
-
}
|
|
54
|
-
// Create the appropriate storage backend
|
|
55
|
-
let storage;
|
|
56
|
-
switch (type) {
|
|
57
|
-
case "memory":
|
|
58
|
-
storage = new InMemoryStorage();
|
|
59
|
-
break;
|
|
60
|
-
case "api":
|
|
61
|
-
storage = new ApiStorage(client, {
|
|
62
|
-
collection,
|
|
63
|
-
...(service !== undefined && { service }),
|
|
64
|
-
});
|
|
65
|
-
break;
|
|
66
|
-
case "hybrid": {
|
|
67
|
-
const remoteStorage = new ApiStorage(client, {
|
|
68
|
-
collection,
|
|
69
|
-
...(service !== undefined && { service }),
|
|
70
|
-
});
|
|
71
|
-
storage = new HybridStorage(remoteStorage, {
|
|
72
|
-
writeStrategy: hybridOptions?.writeStrategy ?? "write-through",
|
|
73
|
-
conflictResolution: hybridOptions?.conflictResolution ?? "local",
|
|
74
|
-
// A procedure record has no id: its key is its path (deep dive DATA-9)
|
|
75
|
-
keyOf: getSerializedKey,
|
|
76
|
-
...hybridOptions,
|
|
77
|
-
});
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
default:
|
|
81
|
-
throw new Error(`Unknown storage type: ${type}`);
|
|
82
|
-
}
|
|
83
|
-
// Create and return the synced registry
|
|
84
|
-
return new SyncedProcedureRegistry(baseRegistry, storage, {
|
|
85
|
-
...registryOptions,
|
|
86
|
-
handlerLoader,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
// =============================================================================
|
|
90
|
-
// Convenience Functions
|
|
91
|
-
// =============================================================================
|
|
92
|
-
/**
|
|
93
|
-
* Create an in-memory synced registry.
|
|
94
|
-
* Useful for testing or when persistence isn't needed.
|
|
95
|
-
*
|
|
96
|
-
* @param baseRegistry - Base registry to wrap
|
|
97
|
-
* @returns SyncedProcedureRegistry with in-memory storage
|
|
98
|
-
*/
|
|
99
|
-
export function createMemorySyncedRegistry(baseRegistry = PROCEDURE_REGISTRY) {
|
|
100
|
-
return createSyncedRegistry({
|
|
101
|
-
type: "memory",
|
|
102
|
-
baseRegistry,
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Create an API-backed synced registry.
|
|
107
|
-
*
|
|
108
|
-
* @param client - Universal client instance
|
|
109
|
-
* @param collection - The collection of the core collection procedures on the server
|
|
110
|
-
* @param baseRegistry - Base registry to wrap
|
|
111
|
-
* @returns SyncedProcedureRegistry with API storage
|
|
112
|
-
*/
|
|
113
|
-
export function createApiSyncedRegistry(client, collection = "procedures", baseRegistry = PROCEDURE_REGISTRY) {
|
|
114
|
-
return createSyncedRegistry({
|
|
115
|
-
type: "api",
|
|
116
|
-
client,
|
|
117
|
-
collection,
|
|
118
|
-
baseRegistry,
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Create a hybrid synced registry (offline-first).
|
|
123
|
-
*
|
|
124
|
-
* @param client - Universal client instance
|
|
125
|
-
* @param collection - The collection of the core collection procedures on the server
|
|
126
|
-
* @param options - Hybrid storage options
|
|
127
|
-
* @param baseRegistry - Base registry to wrap
|
|
128
|
-
* @returns SyncedProcedureRegistry with hybrid storage
|
|
129
|
-
*/
|
|
130
|
-
export function createHybridSyncedRegistry(client, collection = "procedures", options, baseRegistry = PROCEDURE_REGISTRY) {
|
|
131
|
-
return createSyncedRegistry({
|
|
132
|
-
type: "hybrid",
|
|
133
|
-
client,
|
|
134
|
-
collection,
|
|
135
|
-
hybridOptions: options,
|
|
136
|
-
baseRegistry,
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
// =============================================================================
|
|
140
|
-
// Custom Storage Factory
|
|
141
|
-
// =============================================================================
|
|
142
|
-
/**
|
|
143
|
-
* Create a synced registry with a custom storage backend.
|
|
144
|
-
*
|
|
145
|
-
* @param storage - Custom CollectionStorage implementation
|
|
146
|
-
* @param options - Registry options
|
|
147
|
-
* @param baseRegistry - Base registry to wrap
|
|
148
|
-
* @returns SyncedProcedureRegistry with custom storage
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* // Use MongoDB storage
|
|
153
|
-
* const mongoStorage = new MongoCollectionStorage<SerializedProcedure>(
|
|
154
|
-
* mongoClient,
|
|
155
|
-
* 'procedures'
|
|
156
|
-
* );
|
|
157
|
-
* const registry = createCustomSyncedRegistry(mongoStorage);
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
160
|
-
export function createCustomSyncedRegistry(storage, options, baseRegistry = PROCEDURE_REGISTRY) {
|
|
161
|
-
// No default loader: see createSyncedRegistry
|
|
162
|
-
return new SyncedProcedureRegistry(baseRegistry, storage, {
|
|
163
|
-
...options,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
//# sourceMappingURL=factory.js.map
|