@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.
Files changed (236) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +4 -4
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/browser.d.ts +1 -1
  5. package/dist/browser.d.ts.map +1 -1
  6. package/dist/browser.js.map +1 -1
  7. package/dist/procedures/invoke.d.ts +6 -1
  8. package/dist/procedures/invoke.d.ts.map +1 -1
  9. package/dist/procedures/invoke.js +2 -2
  10. package/dist/procedures/invoke.js.map +1 -1
  11. package/dist/server/host-policy.d.ts +3 -3
  12. package/dist/server/host-policy.d.ts.map +1 -1
  13. package/dist/server/procedure-server.d.ts +2 -2
  14. package/dist/server/procedure-server.d.ts.map +1 -1
  15. package/dist/server/procedure-server.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/browser.ts +1 -0
  18. package/src/procedures/invoke.ts +10 -4
  19. package/src/server/host-policy.ts +3 -3
  20. package/src/server/procedure-server.ts +2 -2
  21. package/dist/client/middleware/batching.d.ts +0 -102
  22. package/dist/client/middleware/batching.d.ts.map +0 -1
  23. package/dist/client/middleware/batching.js +0 -245
  24. package/dist/client/middleware/batching.js.map +0 -1
  25. package/dist/collections/async/async-queue.d.ts +0 -144
  26. package/dist/collections/async/async-queue.d.ts.map +0 -1
  27. package/dist/collections/async/async-queue.js +0 -347
  28. package/dist/collections/async/async-queue.js.map +0 -1
  29. package/dist/collections/async/channels.d.ts +0 -188
  30. package/dist/collections/async/channels.d.ts.map +0 -1
  31. package/dist/collections/async/channels.js +0 -312
  32. package/dist/collections/async/channels.js.map +0 -1
  33. package/dist/collections/behaviors/bounded.d.ts +0 -79
  34. package/dist/collections/behaviors/bounded.d.ts.map +0 -1
  35. package/dist/collections/behaviors/bounded.js +0 -384
  36. package/dist/collections/behaviors/bounded.js.map +0 -1
  37. package/dist/collections/behaviors/evented.d.ts +0 -154
  38. package/dist/collections/behaviors/evented.d.ts.map +0 -1
  39. package/dist/collections/behaviors/evented.js +0 -299
  40. package/dist/collections/behaviors/evented.js.map +0 -1
  41. package/dist/collections/behaviors/lru.d.ts +0 -84
  42. package/dist/collections/behaviors/lru.d.ts.map +0 -1
  43. package/dist/collections/behaviors/lru.js +0 -330
  44. package/dist/collections/behaviors/lru.js.map +0 -1
  45. package/dist/collections/behaviors/readonly.d.ts +0 -73
  46. package/dist/collections/behaviors/readonly.d.ts.map +0 -1
  47. package/dist/collections/behaviors/readonly.js +0 -158
  48. package/dist/collections/behaviors/readonly.js.map +0 -1
  49. package/dist/collections/behaviors/safe.d.ts +0 -163
  50. package/dist/collections/behaviors/safe.d.ts.map +0 -1
  51. package/dist/collections/behaviors/safe.js +0 -172
  52. package/dist/collections/behaviors/safe.js.map +0 -1
  53. package/dist/collections/behaviors/synchronized.d.ts +0 -88
  54. package/dist/collections/behaviors/synchronized.d.ts.map +0 -1
  55. package/dist/collections/behaviors/synchronized.js +0 -294
  56. package/dist/collections/behaviors/synchronized.js.map +0 -1
  57. package/dist/collections/behaviors/ttl.d.ts +0 -118
  58. package/dist/collections/behaviors/ttl.d.ts.map +0 -1
  59. package/dist/collections/behaviors/ttl.js +0 -338
  60. package/dist/collections/behaviors/ttl.js.map +0 -1
  61. package/dist/collections/core/effects.d.ts +0 -176
  62. package/dist/collections/core/effects.d.ts.map +0 -1
  63. package/dist/collections/core/effects.js +0 -180
  64. package/dist/collections/core/effects.js.map +0 -1
  65. package/dist/collections/core/events.d.ts +0 -192
  66. package/dist/collections/core/events.d.ts.map +0 -1
  67. package/dist/collections/core/events.js +0 -291
  68. package/dist/collections/core/events.js.map +0 -1
  69. package/dist/collections/core/middleware.d.ts +0 -231
  70. package/dist/collections/core/middleware.d.ts.map +0 -1
  71. package/dist/collections/core/middleware.js +0 -161
  72. package/dist/collections/core/middleware.js.map +0 -1
  73. package/dist/collections/core/policies.d.ts +0 -220
  74. package/dist/collections/core/policies.d.ts.map +0 -1
  75. package/dist/collections/core/policies.js +0 -48
  76. package/dist/collections/core/policies.js.map +0 -1
  77. package/dist/collections/core/traits.d.ts +0 -142
  78. package/dist/collections/core/traits.d.ts.map +0 -1
  79. package/dist/collections/core/traits.js +0 -8
  80. package/dist/collections/core/traits.js.map +0 -1
  81. package/dist/collections/examples.d.ts +0 -13
  82. package/dist/collections/examples.d.ts.map +0 -1
  83. package/dist/collections/examples.js +0 -302
  84. package/dist/collections/examples.js.map +0 -1
  85. package/dist/collections/fx/collectors.d.ts +0 -190
  86. package/dist/collections/fx/collectors.d.ts.map +0 -1
  87. package/dist/collections/fx/collectors.js +0 -369
  88. package/dist/collections/fx/collectors.js.map +0 -1
  89. package/dist/collections/fx/iter.d.ts +0 -166
  90. package/dist/collections/fx/iter.d.ts.map +0 -1
  91. package/dist/collections/fx/iter.js +0 -421
  92. package/dist/collections/fx/iter.js.map +0 -1
  93. package/dist/collections/impl/array-deque.d.ts +0 -107
  94. package/dist/collections/impl/array-deque.d.ts.map +0 -1
  95. package/dist/collections/impl/array-deque.js +0 -381
  96. package/dist/collections/impl/array-deque.js.map +0 -1
  97. package/dist/collections/impl/array-list.d.ts +0 -101
  98. package/dist/collections/impl/array-list.d.ts.map +0 -1
  99. package/dist/collections/impl/array-list.js +0 -387
  100. package/dist/collections/impl/array-list.js.map +0 -1
  101. package/dist/collections/impl/hash-map.d.ts +0 -141
  102. package/dist/collections/impl/hash-map.d.ts.map +0 -1
  103. package/dist/collections/impl/hash-map.js +0 -450
  104. package/dist/collections/impl/hash-map.js.map +0 -1
  105. package/dist/collections/impl/hash-set.d.ts +0 -125
  106. package/dist/collections/impl/hash-set.d.ts.map +0 -1
  107. package/dist/collections/impl/hash-set.js +0 -264
  108. package/dist/collections/impl/hash-set.js.map +0 -1
  109. package/dist/collections/impl/linked-hash-map.d.ts +0 -141
  110. package/dist/collections/impl/linked-hash-map.d.ts.map +0 -1
  111. package/dist/collections/impl/linked-hash-map.js +0 -472
  112. package/dist/collections/impl/linked-hash-map.js.map +0 -1
  113. package/dist/collections/impl/linked-list.d.ts +0 -109
  114. package/dist/collections/impl/linked-list.d.ts.map +0 -1
  115. package/dist/collections/impl/linked-list.js +0 -491
  116. package/dist/collections/impl/linked-list.js.map +0 -1
  117. package/dist/collections/impl/priority-queue.d.ts +0 -134
  118. package/dist/collections/impl/priority-queue.d.ts.map +0 -1
  119. package/dist/collections/impl/priority-queue.js +0 -336
  120. package/dist/collections/impl/priority-queue.js.map +0 -1
  121. package/dist/collections/impl/tree-map.d.ts +0 -146
  122. package/dist/collections/impl/tree-map.d.ts.map +0 -1
  123. package/dist/collections/impl/tree-map.js +0 -781
  124. package/dist/collections/impl/tree-map.js.map +0 -1
  125. package/dist/collections/impl/tree-set.d.ts +0 -112
  126. package/dist/collections/impl/tree-set.d.ts.map +0 -1
  127. package/dist/collections/impl/tree-set.js +0 -374
  128. package/dist/collections/impl/tree-set.js.map +0 -1
  129. package/dist/collections/index.d.ts +0 -105
  130. package/dist/collections/index.d.ts.map +0 -1
  131. package/dist/collections/index.js +0 -135
  132. package/dist/collections/index.js.map +0 -1
  133. package/dist/collections/interfaces/collection.d.ts +0 -119
  134. package/dist/collections/interfaces/collection.d.ts.map +0 -1
  135. package/dist/collections/interfaces/collection.js +0 -8
  136. package/dist/collections/interfaces/collection.js.map +0 -1
  137. package/dist/collections/interfaces/list.d.ts +0 -247
  138. package/dist/collections/interfaces/list.d.ts.map +0 -1
  139. package/dist/collections/interfaces/list.js +0 -8
  140. package/dist/collections/interfaces/list.js.map +0 -1
  141. package/dist/collections/interfaces/map.d.ts +0 -344
  142. package/dist/collections/interfaces/map.d.ts.map +0 -1
  143. package/dist/collections/interfaces/map.js +0 -8
  144. package/dist/collections/interfaces/map.js.map +0 -1
  145. package/dist/collections/interfaces/queue.d.ts +0 -304
  146. package/dist/collections/interfaces/queue.d.ts.map +0 -1
  147. package/dist/collections/interfaces/queue.js +0 -8
  148. package/dist/collections/interfaces/queue.js.map +0 -1
  149. package/dist/collections/interfaces/set.d.ts +0 -137
  150. package/dist/collections/interfaces/set.d.ts.map +0 -1
  151. package/dist/collections/interfaces/set.js +0 -8
  152. package/dist/collections/interfaces/set.js.map +0 -1
  153. package/dist/collections/storage/api.d.ts +0 -109
  154. package/dist/collections/storage/api.d.ts.map +0 -1
  155. package/dist/collections/storage/api.js +0 -182
  156. package/dist/collections/storage/api.js.map +0 -1
  157. package/dist/collections/storage/hybrid.d.ts +0 -164
  158. package/dist/collections/storage/hybrid.d.ts.map +0 -1
  159. package/dist/collections/storage/hybrid.js +0 -416
  160. package/dist/collections/storage/hybrid.js.map +0 -1
  161. package/dist/collections/storage/index.d.ts +0 -16
  162. package/dist/collections/storage/index.d.ts.map +0 -1
  163. package/dist/collections/storage/index.js +0 -13
  164. package/dist/collections/storage/index.js.map +0 -1
  165. package/dist/collections/storage/interface.d.ts +0 -141
  166. package/dist/collections/storage/interface.d.ts.map +0 -1
  167. package/dist/collections/storage/interface.js +0 -23
  168. package/dist/collections/storage/interface.js.map +0 -1
  169. package/dist/collections/storage/memory.d.ts +0 -68
  170. package/dist/collections/storage/memory.d.ts.map +0 -1
  171. package/dist/collections/storage/memory.js +0 -154
  172. package/dist/collections/storage/memory.js.map +0 -1
  173. package/dist/collections/utils/defaults.d.ts +0 -135
  174. package/dist/collections/utils/defaults.d.ts.map +0 -1
  175. package/dist/collections/utils/defaults.js +0 -322
  176. package/dist/collections/utils/defaults.js.map +0 -1
  177. package/dist/collections/utils/factories.d.ts +0 -144
  178. package/dist/collections/utils/factories.d.ts.map +0 -1
  179. package/dist/collections/utils/factories.js +0 -293
  180. package/dist/collections/utils/factories.js.map +0 -1
  181. package/dist/collections/utils/helpers.d.ts +0 -137
  182. package/dist/collections/utils/helpers.d.ts.map +0 -1
  183. package/dist/collections/utils/helpers.js +0 -221
  184. package/dist/collections/utils/helpers.js.map +0 -1
  185. package/dist/collections.d.ts +0 -12
  186. package/dist/collections.d.ts.map +0 -1
  187. package/dist/collections.js +0 -10
  188. package/dist/collections.js.map +0 -1
  189. package/dist/components/define.d.ts +0 -134
  190. package/dist/components/define.d.ts.map +0 -1
  191. package/dist/components/define.js +0 -486
  192. package/dist/components/define.js.map +0 -1
  193. package/dist/components/index.d.ts +0 -39
  194. package/dist/components/index.d.ts.map +0 -1
  195. package/dist/components/index.js +0 -38
  196. package/dist/components/index.js.map +0 -1
  197. package/dist/components/types.d.ts +0 -264
  198. package/dist/components/types.d.ts.map +0 -1
  199. package/dist/components/types.js +0 -46
  200. package/dist/components/types.js.map +0 -1
  201. package/dist/procedures/storage/adapter.d.ts +0 -148
  202. package/dist/procedures/storage/adapter.d.ts.map +0 -1
  203. package/dist/procedures/storage/adapter.js +0 -214
  204. package/dist/procedures/storage/adapter.js.map +0 -1
  205. package/dist/procedures/storage/api.d.ts +0 -125
  206. package/dist/procedures/storage/api.d.ts.map +0 -1
  207. package/dist/procedures/storage/api.js +0 -220
  208. package/dist/procedures/storage/api.js.map +0 -1
  209. package/dist/procedures/storage/factory.d.ts +0 -134
  210. package/dist/procedures/storage/factory.d.ts.map +0 -1
  211. package/dist/procedures/storage/factory.js +0 -166
  212. package/dist/procedures/storage/factory.js.map +0 -1
  213. package/dist/procedures/storage/hybrid.d.ts +0 -193
  214. package/dist/procedures/storage/hybrid.d.ts.map +0 -1
  215. package/dist/procedures/storage/hybrid.js +0 -519
  216. package/dist/procedures/storage/hybrid.js.map +0 -1
  217. package/dist/procedures/storage/index.d.ts +0 -17
  218. package/dist/procedures/storage/index.d.ts.map +0 -1
  219. package/dist/procedures/storage/index.js +0 -17
  220. package/dist/procedures/storage/index.js.map +0 -1
  221. package/dist/procedures/storage/procedures.d.ts +0 -39
  222. package/dist/procedures/storage/procedures.d.ts.map +0 -1
  223. package/dist/procedures/storage/procedures.js +0 -261
  224. package/dist/procedures/storage/procedures.js.map +0 -1
  225. package/dist/procedures/storage/serialization.d.ts +0 -123
  226. package/dist/procedures/storage/serialization.d.ts.map +0 -1
  227. package/dist/procedures/storage/serialization.js +0 -216
  228. package/dist/procedures/storage/serialization.js.map +0 -1
  229. package/dist/procedures/storage/synced-registry.d.ts +0 -246
  230. package/dist/procedures/storage/synced-registry.d.ts.map +0 -1
  231. package/dist/procedures/storage/synced-registry.js +0 -575
  232. package/dist/procedures/storage/synced-registry.js.map +0 -1
  233. package/dist/procedures/storage/types.d.ts +0 -130
  234. package/dist/procedures/storage/types.d.ts.map +0 -1
  235. package/dist/procedures/storage/types.js +0 -8
  236. package/dist/procedures/storage/types.js.map +0 -1
@@ -1,261 +0,0 @@
1
- /**
2
- * Procedure Storage Procedures
3
- *
4
- * CLI procedures for managing the procedure registry storage:
5
- * - procedure.register - Register a procedure at runtime
6
- * - procedure.store - Persist a procedure to storage
7
- * - procedure.load - Load procedures from storage
8
- * - procedure.sync - Sync registry with storage
9
- * - procedure.remote - Configure remote connection
10
- *
11
- * The procedures work on the store of the caller's registry: the `SyncedProcedureRegistry`
12
- * that wraps it (`createSyncedRegistry()`). When the registry has no store, they fail with
13
- * the code `NOT_CONFIGURED`. (Before, they reported success and did nothing: deep dive
14
- * CORE-16, DATA-10.)
15
- */
16
- import { defineProcedure } from "../define.js";
17
- import { PROCEDURE_REGISTRY } from "../registry.js";
18
- import { pathToKey, keyToPath } from "../types.js";
19
- import { deserializeProcedure, deserializeProcedureSync } from "./serialization.js";
20
- import { getProcedureStore } from "./synced-registry.js";
21
- // =============================================================================
22
- // Any Schema Helper
23
- // =============================================================================
24
- const anySchema = {
25
- parse: (data) => data,
26
- safeParse: (data) => ({ success: true, data }),
27
- _output: undefined,
28
- };
29
- // =============================================================================
30
- // The store of the caller
31
- // =============================================================================
32
- /** An error of a storage procedure that cannot do its work. */
33
- export class ProcedureStoreError extends Error {
34
- name = "ProcedureStoreError";
35
- code;
36
- constructor(code, message) {
37
- super(message);
38
- this.code = code;
39
- }
40
- }
41
- /** The registry of the caller: the context's registry when it has one, else the global one. */
42
- function callerRegistry(ctx) {
43
- return ctx?.registry ?? PROCEDURE_REGISTRY;
44
- }
45
- /** The store of the caller's registry, or a NOT_CONFIGURED error. */
46
- function requireStore(ctx, what) {
47
- const store = getProcedureStore(callerRegistry(ctx));
48
- if (!store) {
49
- throw new ProcedureStoreError("NOT_CONFIGURED", `${what} needs a procedure store, and this registry has none. ` +
50
- "Wrap the registry with createSyncedRegistry() or new SyncedProcedureRegistry().");
51
- }
52
- return store;
53
- }
54
- function toPath(path) {
55
- return typeof path === "string" ? keyToPath(path) : path;
56
- }
57
- export const procedureRegisterProcedure = defineProcedure({
58
- path: ["procedure", "register"],
59
- input: anySchema,
60
- output: anySchema,
61
- metadata: {
62
- description: "Register a procedure at runtime",
63
- tags: ["procedure", "registry", "storage"],
64
- },
65
- handler: async (input, ctx) => {
66
- const { path, metadata = {}, streaming, handlerRef, persist = false } = input;
67
- const key = pathToKey(path);
68
- const serialized = {
69
- path,
70
- metadata,
71
- streaming,
72
- handlerRef,
73
- storedAt: Date.now(),
74
- };
75
- if (persist) {
76
- // A stored procedure needs a handler: never store a stub (deep dive CORE-16)
77
- const store = requireStore(ctx, "procedure.register with persist");
78
- const loader = store.getHandlerLoader();
79
- const procedure = handlerRef && loader ? await deserializeProcedure(serialized, { handlerLoader: loader }) : undefined;
80
- if (!procedure?.handler) {
81
- throw new ProcedureStoreError("NO_HANDLER", `procedure.register with persist needs a handler for ${key}: give a handlerRef ` +
82
- "that the handler loader of the store allows.");
83
- }
84
- store.register(procedure, { override: false, handlerRef });
85
- await store.flushWrites();
86
- return { success: true, message: `Registered and stored ${key}`, path, hasHandler: true };
87
- }
88
- // No persist: load the handler when the store's loader allows it, else declare a stub
89
- const loader = getProcedureStore(callerRegistry(ctx))?.getHandlerLoader();
90
- const procedure = handlerRef && loader ? await deserializeProcedure(serialized, { handlerLoader: loader }) : deserializeProcedureSync(serialized);
91
- try {
92
- callerRegistry(ctx).register(procedure, { override: false });
93
- }
94
- catch (error) {
95
- return {
96
- success: false,
97
- message: error instanceof Error ? error.message : "Registration failed",
98
- path,
99
- hasHandler: false,
100
- };
101
- }
102
- const hasHandler = typeof procedure.handler === "function";
103
- return {
104
- success: true,
105
- message: hasHandler
106
- ? `Registered ${key}`
107
- : `Registered ${key} with no handler: a Client sends the calls of this path to its transport`,
108
- path,
109
- hasHandler,
110
- };
111
- },
112
- });
113
- export const procedureStoreProcedure = defineProcedure({
114
- path: ["procedure", "store"],
115
- input: anySchema,
116
- output: anySchema,
117
- metadata: {
118
- description: "Persist a procedure definition to storage",
119
- tags: ["procedure", "registry", "storage"],
120
- },
121
- handler: async (input, ctx) => {
122
- const path = toPath(input.path);
123
- const store = requireStore(ctx, "procedure.store");
124
- const record = await store.storeProcedure(path, { handlerRef: input.handlerRef });
125
- if (!record) {
126
- return {
127
- stored: false,
128
- path,
129
- message: `Procedure not found: ${pathToKey(path)}`,
130
- };
131
- }
132
- const output = { stored: true, path, message: `Stored ${pathToKey(path)}` };
133
- if (record.storedAt !== undefined)
134
- output.storedAt = record.storedAt;
135
- return output;
136
- },
137
- });
138
- export const procedureLoadProcedure = defineProcedure({
139
- path: ["procedure", "load"],
140
- input: anySchema,
141
- output: anySchema,
142
- metadata: {
143
- description: "Load procedures from storage into registry",
144
- tags: ["procedure", "registry", "storage"],
145
- },
146
- handler: async (input, ctx) => {
147
- let matches;
148
- let what;
149
- if (input.all) {
150
- matches = () => true;
151
- what = "all procedures";
152
- }
153
- else if (input.path) {
154
- const key = pathToKey(toPath(input.path));
155
- matches = (record) => pathToKey(record.path) === key;
156
- what = key;
157
- }
158
- else if (input.prefix) {
159
- const prefix = pathToKey(toPath(input.prefix));
160
- matches = (record) => {
161
- const key = pathToKey(record.path);
162
- return key === prefix || key.startsWith(`${prefix}.`);
163
- };
164
- what = `${prefix}.*`;
165
- }
166
- else {
167
- throw new Error("procedure.load needs `path`, `prefix` or `all: true`");
168
- }
169
- const store = requireStore(ctx, "procedure.load");
170
- const paths = (await store.getAdapter().getAllRaw()).filter(matches).map((record) => record.path);
171
- const result = await store.syncFromStorage(matches);
172
- return {
173
- loaded: result.pulled,
174
- paths,
175
- conflicts: result.conflicts.map(({ path, resolution }) => ({ path, resolution })),
176
- message: `Loaded ${result.pulled} of ${paths.length} stored procedure(s) for ${what}`,
177
- };
178
- },
179
- });
180
- export const procedureSyncProcedure = defineProcedure({
181
- path: ["procedure", "sync"],
182
- input: anySchema,
183
- output: anySchema,
184
- metadata: {
185
- description: "Synchronize procedure registry with storage",
186
- tags: ["procedure", "registry", "storage"],
187
- },
188
- handler: async (input, ctx) => {
189
- const direction = input.direction ?? "both";
190
- const store = requireStore(ctx, "procedure.sync");
191
- const result = await store.sync(direction);
192
- return {
193
- pushed: result.pushed,
194
- pulled: result.pulled,
195
- conflicts: result.conflicts.map(({ path, resolution }) => ({ path, resolution })),
196
- message: `Sync ${direction}: pushed ${result.pushed}, pulled ${result.pulled}`,
197
- };
198
- },
199
- });
200
- export const procedureRemoteProcedure = defineProcedure({
201
- path: ["procedure", "remote"],
202
- input: anySchema,
203
- output: anySchema,
204
- metadata: {
205
- description: "Configure remote procedure registry connection",
206
- tags: ["procedure", "registry", "storage"],
207
- },
208
- handler: async (input, ctx) => {
209
- switch (input.action) {
210
- case "status": {
211
- const store = getProcedureStore(callerRegistry(ctx));
212
- if (!store) {
213
- return { connected: false, message: "This registry has no procedure store" };
214
- }
215
- const status = store.getStatus();
216
- const output = {
217
- connected: status.connected,
218
- pendingChanges: status.pendingChanges,
219
- message: status.connected ? `Connected to ${status.endpoint}` : "The store is not connected to an endpoint",
220
- };
221
- if (status.endpoint !== undefined)
222
- output.endpoint = status.endpoint;
223
- if (status.lastSync !== undefined)
224
- output.lastSync = status.lastSync;
225
- return output;
226
- }
227
- case "connect":
228
- // The storage of a store is fixed when it is made: no call changes it at run time
229
- throw new ProcedureStoreError("NOT_IMPLEMENTED", "procedure.remote connect cannot change the storage of a registry at run time. " +
230
- 'Make the registry with createSyncedRegistry({ type: "api", client }) for the endpoint.');
231
- case "disconnect": {
232
- const store = requireStore(ctx, "procedure.remote disconnect");
233
- store.disconnect();
234
- return { connected: false, message: "Stopped the auto-sync, and cleared the endpoint" };
235
- }
236
- default:
237
- throw new Error(`Unknown action: ${String(input.action)}`);
238
- }
239
- },
240
- });
241
- // =============================================================================
242
- // Module Export
243
- // =============================================================================
244
- /**
245
- * All procedure storage procedures as a module.
246
- */
247
- export const procedureStorageModule = {
248
- name: "procedure-storage",
249
- procedures: [
250
- procedureRegisterProcedure,
251
- procedureStoreProcedure,
252
- procedureLoadProcedure,
253
- procedureSyncProcedure,
254
- procedureRemoteProcedure,
255
- ],
256
- };
257
- /**
258
- * Array of all procedure storage procedures.
259
- */
260
- export const procedureStorageProcedures = procedureStorageModule.procedures;
261
- //# sourceMappingURL=procedures.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"procedures.js","sourceRoot":"","sources":["../../../src/procedures/storage/procedures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAA0B,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAgC,MAAM,sBAAsB,CAAC;AAEvF,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF,MAAM,SAAS,GAIX;IACF,KAAK,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,IAAI;IAC9B,SAAS,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAa,EAAE,IAAI,EAAE,CAAC;IAChE,OAAO,EAAE,SAAoB;CAC9B,CAAC;AAEF,gFAAgF;AAChF,0BAA0B;AAC1B,gFAAgF;AAEhF,+DAA+D;AAC/D,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC1B,IAAI,GAAG,qBAAqB,CAA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AAE,mBAAmB;IACzB,UAAU,EAAE;QACV,0BAA0B;QAC1B,uBAAuB;QACvB,sBAAsB;QACtB,sBAAsB;QACtB,wBAAwB;KACP;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAmB,sBAAsB,CAAC,UAAU,CAAC"}
@@ -1,123 +0,0 @@
1
- /**
2
- * Procedure Serialization
3
- *
4
- * Utilities for converting procedures to/from serialized format.
5
- * Enables storage and transmission of procedure definitions.
6
- */
7
- import type { AnyProcedure, ProcedurePath } from "../types.js";
8
- import type { SerializedProcedure, HandlerReference, HandlerLoader } from "./types.js";
9
- /**
10
- * Options for serializing a procedure.
11
- */
12
- export interface SerializeOptions {
13
- /** Handler reference to store (optional, handlers can't be serialized directly) */
14
- handlerRef?: HandlerReference | undefined;
15
- /** Whether to include version info */
16
- includeVersion?: boolean | undefined;
17
- }
18
- /**
19
- * Serialize a procedure to storable format.
20
- *
21
- * Note: Handler functions cannot be serialized. If the procedure has a handler,
22
- * you should provide a `handlerRef` that can be used to load it later.
23
- *
24
- * @param procedure - Procedure to serialize
25
- * @param options - Serialization options
26
- * @returns Serialized procedure definition
27
- *
28
- * @example
29
- * ```typescript
30
- * const serialized = serializeProcedure(myProcedure, {
31
- * handlerRef: {
32
- * module: "@mark1russell7/client-cli",
33
- * export: "libScanHandler",
34
- * },
35
- * });
36
- * ```
37
- */
38
- export declare function serializeProcedure(procedure: AnyProcedure, options?: SerializeOptions): SerializedProcedure;
39
- /**
40
- * Options for deserializing a procedure.
41
- */
42
- export interface DeserializeOptions {
43
- /** Handler loader to restore handlers from references */
44
- handlerLoader?: HandlerLoader | undefined;
45
- }
46
- /**
47
- * Deserialize a procedure from stored format.
48
- *
49
- * Returns a stub procedure without a handler unless a handlerLoader is provided
50
- * and the serialized procedure has a handlerRef.
51
- *
52
- * @param data - Serialized procedure data
53
- * @param options - Deserialization options
54
- * @returns Procedure (stub if no handler can be loaded)
55
- *
56
- * @example
57
- * ```typescript
58
- * // Deserialize as stub (no handler)
59
- * const stub = await deserializeProcedure(data);
60
- *
61
- * // Deserialize with handler loading
62
- * const proc = await deserializeProcedure(data, {
63
- * handlerLoader: myLoader,
64
- * });
65
- * ```
66
- */
67
- export declare function deserializeProcedure(data: SerializedProcedure, options?: DeserializeOptions): Promise<AnyProcedure>;
68
- /**
69
- * Synchronous version that always returns a stub.
70
- * Use when you don't need to load handlers.
71
- */
72
- export declare function deserializeProcedureSync(data: SerializedProcedure): AnyProcedure;
73
- /**
74
- * Get the storage key (ID) for a procedure.
75
- * Uses the dot-separated path as the key.
76
- *
77
- * @param pathOrProcedure - Procedure path or procedure object
78
- * @returns Storage key string
79
- */
80
- export declare function getProcedureKey(pathOrProcedure: ProcedurePath | AnyProcedure): string;
81
- /**
82
- * Get the storage key from a serialized procedure.
83
- */
84
- export declare function getSerializedKey(data: SerializedProcedure): string;
85
- /**
86
- * Serialize multiple procedures.
87
- *
88
- * @param procedures - Procedures to serialize
89
- * @param options - Serialization options
90
- * @returns Array of [key, serialized] tuples for batch storage
91
- */
92
- export declare function serializeProcedures(procedures: AnyProcedure[], options?: SerializeOptions): Array<[string, SerializedProcedure]>;
93
- /**
94
- * Deserialize multiple procedures.
95
- *
96
- * @param items - Array of serialized procedures
97
- * @param options - Deserialization options
98
- * @returns Array of procedures
99
- */
100
- export declare function deserializeProcedures(items: SerializedProcedure[], options?: DeserializeOptions): Promise<AnyProcedure[]>;
101
- /**
102
- * Create a handler loader using dynamic imports of the allowed modules only.
103
- *
104
- * A stored procedure record names the module of its handler, and the storage can be remote
105
- * (`api`, `hybrid`). So the loader imports only the modules in `allowedModules` (exact package
106
- * names, or a prefix that ends with "*"), and never a URL or a path (`data:`, `file:`, `node:`,
107
- * `./x`, `/x`, a drive letter). Before, it imported any module that a record named: a record
108
- * with `node:child_process` ran a shell command (BUGS-2026-07 M11, deep dive CORE-7, DATA-11).
109
- *
110
- * @param allowedModules - Module names the loader may import, such as "@mark1russell7/client-git"
111
- * @returns Handler loader that uses import() to load allowed modules
112
- *
113
- * @example
114
- * ```typescript
115
- * const loader = createDynamicHandlerLoader(["@mark1russell7/client-*"]);
116
- * const handler = await loader.load({
117
- * module: "@mark1russell7/client-cli",
118
- * export: "libScanHandler",
119
- * });
120
- * ```
121
- */
122
- export declare function createDynamicHandlerLoader(allowedModules: readonly string[]): HandlerLoader;
123
- //# sourceMappingURL=serialization.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialization.d.ts","sourceRoot":"","sources":["../../../src/procedures/storage/serialization.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAwBvF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mFAAmF;IACnF,UAAU,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAE1C,sCAAsC;IACtC,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,YAAY,EACvB,OAAO,GAAE,gBAAqB,GAC7B,mBAAmB,CAuBrB;AAMD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,yDAAyD;IACzD,aAAa,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,mBAAmB,EACzB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,YAAY,CAAC,CA0BvB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,mBAAmB,GAAG,YAAY,CAahF;AAMD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,eAAe,EAAE,aAAa,GAAG,YAAY,GAAG,MAAM,CAGrF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,mBAAmB,GAAG,MAAM,CAElE;AAMD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,YAAY,EAAE,EAC1B,OAAO,GAAE,gBAAqB,GAC7B,KAAK,CAAC,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAKtC;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,mBAAmB,EAAE,EAC5B,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,YAAY,EAAE,CAAC,CAEzB;AAMD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,0BAA0B,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,GAAG,aAAa,CAwB3F"}
@@ -1,216 +0,0 @@
1
- /**
2
- * Procedure Serialization
3
- *
4
- * Utilities for converting procedures to/from serialized format.
5
- * Enables storage and transmission of procedure definitions.
6
- */
7
- import { pathToKey } from "../types.js";
8
- // =============================================================================
9
- // Any Schema (for deserialized procedures without schemas)
10
- // =============================================================================
11
- /**
12
- * Passthrough schema that accepts any value.
13
- * Used for deserialized procedures where original schemas aren't available.
14
- */
15
- const anySchema = {
16
- parse: (data) => data,
17
- safeParse: (data) => ({ success: true, data }),
18
- _output: undefined,
19
- };
20
- /**
21
- * Serialize a procedure to storable format.
22
- *
23
- * Note: Handler functions cannot be serialized. If the procedure has a handler,
24
- * you should provide a `handlerRef` that can be used to load it later.
25
- *
26
- * @param procedure - Procedure to serialize
27
- * @param options - Serialization options
28
- * @returns Serialized procedure definition
29
- *
30
- * @example
31
- * ```typescript
32
- * const serialized = serializeProcedure(myProcedure, {
33
- * handlerRef: {
34
- * module: "@mark1russell7/client-cli",
35
- * export: "libScanHandler",
36
- * },
37
- * });
38
- * ```
39
- */
40
- export function serializeProcedure(procedure, options = {}) {
41
- const serialized = {
42
- path: procedure.path,
43
- metadata: { ...procedure.metadata },
44
- storedAt: Date.now(),
45
- };
46
- // Only include streaming if explicitly set
47
- if (procedure.streaming !== undefined) {
48
- serialized.streaming = procedure.streaming;
49
- }
50
- // Include handler reference if provided
51
- if (options.handlerRef) {
52
- serialized.handlerRef = options.handlerRef;
53
- }
54
- // Include version if requested
55
- if (options.includeVersion) {
56
- serialized.version = 1;
57
- }
58
- return serialized;
59
- }
60
- /**
61
- * Deserialize a procedure from stored format.
62
- *
63
- * Returns a stub procedure without a handler unless a handlerLoader is provided
64
- * and the serialized procedure has a handlerRef.
65
- *
66
- * @param data - Serialized procedure data
67
- * @param options - Deserialization options
68
- * @returns Procedure (stub if no handler can be loaded)
69
- *
70
- * @example
71
- * ```typescript
72
- * // Deserialize as stub (no handler)
73
- * const stub = await deserializeProcedure(data);
74
- *
75
- * // Deserialize with handler loading
76
- * const proc = await deserializeProcedure(data, {
77
- * handlerLoader: myLoader,
78
- * });
79
- * ```
80
- */
81
- export async function deserializeProcedure(data, options = {}) {
82
- const procedure = {
83
- path: data.path,
84
- input: anySchema,
85
- output: anySchema,
86
- metadata: { ...data.metadata },
87
- };
88
- // Set streaming if present
89
- if (data.streaming !== undefined) {
90
- procedure.streaming = data.streaming;
91
- }
92
- // Try to load handler if reference exists and loader is provided
93
- if (data.handlerRef && options.handlerLoader) {
94
- try {
95
- const handler = await options.handlerLoader.load(data.handlerRef);
96
- if (handler && typeof handler === "function") {
97
- procedure.handler = handler;
98
- }
99
- }
100
- catch {
101
- // Handler loading failed, procedure remains a stub
102
- }
103
- }
104
- return procedure;
105
- }
106
- /**
107
- * Synchronous version that always returns a stub.
108
- * Use when you don't need to load handlers.
109
- */
110
- export function deserializeProcedureSync(data) {
111
- const procedure = {
112
- path: data.path,
113
- input: anySchema,
114
- output: anySchema,
115
- metadata: { ...data.metadata },
116
- };
117
- if (data.streaming !== undefined) {
118
- procedure.streaming = data.streaming;
119
- }
120
- return procedure;
121
- }
122
- // =============================================================================
123
- // Storage Key Utilities
124
- // =============================================================================
125
- /**
126
- * Get the storage key (ID) for a procedure.
127
- * Uses the dot-separated path as the key.
128
- *
129
- * @param pathOrProcedure - Procedure path or procedure object
130
- * @returns Storage key string
131
- */
132
- export function getProcedureKey(pathOrProcedure) {
133
- const path = Array.isArray(pathOrProcedure) ? pathOrProcedure : pathOrProcedure.path;
134
- return pathToKey(path);
135
- }
136
- /**
137
- * Get the storage key from a serialized procedure.
138
- */
139
- export function getSerializedKey(data) {
140
- return pathToKey(data.path);
141
- }
142
- // =============================================================================
143
- // Batch Operations
144
- // =============================================================================
145
- /**
146
- * Serialize multiple procedures.
147
- *
148
- * @param procedures - Procedures to serialize
149
- * @param options - Serialization options
150
- * @returns Array of [key, serialized] tuples for batch storage
151
- */
152
- export function serializeProcedures(procedures, options = {}) {
153
- return procedures.map((proc) => [
154
- getProcedureKey(proc),
155
- serializeProcedure(proc, options),
156
- ]);
157
- }
158
- /**
159
- * Deserialize multiple procedures.
160
- *
161
- * @param items - Array of serialized procedures
162
- * @param options - Deserialization options
163
- * @returns Array of procedures
164
- */
165
- export async function deserializeProcedures(items, options = {}) {
166
- return Promise.all(items.map((item) => deserializeProcedure(item, options)));
167
- }
168
- // =============================================================================
169
- // Default Handler Loader
170
- // =============================================================================
171
- /**
172
- * Create a handler loader using dynamic imports of the allowed modules only.
173
- *
174
- * A stored procedure record names the module of its handler, and the storage can be remote
175
- * (`api`, `hybrid`). So the loader imports only the modules in `allowedModules` (exact package
176
- * names, or a prefix that ends with "*"), and never a URL or a path (`data:`, `file:`, `node:`,
177
- * `./x`, `/x`, a drive letter). Before, it imported any module that a record named: a record
178
- * with `node:child_process` ran a shell command (BUGS-2026-07 M11, deep dive CORE-7, DATA-11).
179
- *
180
- * @param allowedModules - Module names the loader may import, such as "@mark1russell7/client-git"
181
- * @returns Handler loader that uses import() to load allowed modules
182
- *
183
- * @example
184
- * ```typescript
185
- * const loader = createDynamicHandlerLoader(["@mark1russell7/client-*"]);
186
- * const handler = await loader.load({
187
- * module: "@mark1russell7/client-cli",
188
- * export: "libScanHandler",
189
- * });
190
- * ```
191
- */
192
- export function createDynamicHandlerLoader(allowedModules) {
193
- const allowed = (specifier) => {
194
- // A URL scheme (data:, file:, node:, C:) or a relative or absolute path is never allowed
195
- if (/^[a-z][a-z0-9+.-]*:/i.test(specifier) || /^[./\\]/.test(specifier)) {
196
- return false;
197
- }
198
- return allowedModules.some((entry) => entry.endsWith("*") ? specifier.startsWith(entry.slice(0, -1)) : specifier === entry);
199
- };
200
- return {
201
- async load(ref) {
202
- if (!allowed(ref.module)) {
203
- return undefined;
204
- }
205
- try {
206
- // The specifier is checked against the allowlist above. A bundler cannot follow it.
207
- const module = await import(/* @vite-ignore */ ref.module);
208
- return module[ref.export];
209
- }
210
- catch {
211
- return undefined;
212
- }
213
- },
214
- };
215
- }
216
- //# sourceMappingURL=serialization.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serialization.js","sourceRoot":"","sources":["../../../src/procedures/storage/serialization.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,gFAAgF;AAChF,2DAA2D;AAC3D,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,SAAS,GAIX;IACF,KAAK,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,IAAI;IAC9B,SAAS,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,IAAa,EAAE,IAAI,EAAE,CAAC;IAChE,OAAO,EAAE,SAAoB;CAC9B,CAAC;AAiBF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,kBAAkB,CAChC,SAAuB,EACvB,OAAO,GAAqB,EAAE;IAE9B,MAAM,UAAU,GAAwB;QACtC,IAAI,EAAE,SAAS,CAAC,IAAI;QACpB,QAAQ,EAAE,EAAE,GAAG,SAAS,CAAC,QAAQ,EAAE;QACnC,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE;KACrB,CA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