@procedures/store 0.0.0-stage → 0.2.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 (115) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +21 -0
  3. package/README.md +65 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/errors.d.ts +16 -0
  6. package/dist/errors.d.ts.map +1 -0
  7. package/dist/errors.js +18 -0
  8. package/dist/errors.js.map +1 -0
  9. package/dist/index.d.ts +19 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +19 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/module.d.ts +23 -0
  14. package/dist/module.d.ts.map +1 -0
  15. package/dist/module.js +26 -0
  16. package/dist/module.js.map +1 -0
  17. package/dist/procedures.d.ts +13 -0
  18. package/dist/procedures.d.ts.map +1 -0
  19. package/dist/procedures.js +14 -0
  20. package/dist/procedures.js.map +1 -0
  21. package/dist/program-store/attach.d.ts +20 -0
  22. package/dist/program-store/attach.d.ts.map +1 -0
  23. package/dist/program-store/attach.js +36 -0
  24. package/dist/program-store/attach.js.map +1 -0
  25. package/dist/program-store/collection.d.ts +19 -0
  26. package/dist/program-store/collection.d.ts.map +1 -0
  27. package/dist/program-store/collection.js +34 -0
  28. package/dist/program-store/collection.js.map +1 -0
  29. package/dist/program-store/file.d.ts +29 -0
  30. package/dist/program-store/file.d.ts.map +1 -0
  31. package/dist/program-store/file.js +156 -0
  32. package/dist/program-store/file.js.map +1 -0
  33. package/dist/program-store/index.d.ts +11 -0
  34. package/dist/program-store/index.d.ts.map +1 -0
  35. package/dist/program-store/index.js +10 -0
  36. package/dist/program-store/index.js.map +1 -0
  37. package/dist/program-store/memory.d.ts +15 -0
  38. package/dist/program-store/memory.d.ts.map +1 -0
  39. package/dist/program-store/memory.js +25 -0
  40. package/dist/program-store/memory.js.map +1 -0
  41. package/dist/program-store/procedures.d.ts +23 -0
  42. package/dist/program-store/procedures.d.ts.map +1 -0
  43. package/dist/program-store/procedures.js +228 -0
  44. package/dist/program-store/procedures.js.map +1 -0
  45. package/dist/program-store/types.d.ts +50 -0
  46. package/dist/program-store/types.d.ts.map +1 -0
  47. package/dist/program-store/types.js +41 -0
  48. package/dist/program-store/types.js.map +1 -0
  49. package/dist/register.d.ts +7 -0
  50. package/dist/register.d.ts.map +1 -0
  51. package/dist/register.js +9 -0
  52. package/dist/register.js.map +1 -0
  53. package/dist/storage/adapter.d.ts +148 -0
  54. package/dist/storage/adapter.d.ts.map +1 -0
  55. package/dist/storage/adapter.js +214 -0
  56. package/dist/storage/adapter.js.map +1 -0
  57. package/dist/storage/api.d.ts +125 -0
  58. package/dist/storage/api.d.ts.map +1 -0
  59. package/dist/storage/api.js +220 -0
  60. package/dist/storage/api.js.map +1 -0
  61. package/dist/storage/factory.d.ts +134 -0
  62. package/dist/storage/factory.d.ts.map +1 -0
  63. package/dist/storage/factory.js +166 -0
  64. package/dist/storage/factory.js.map +1 -0
  65. package/dist/storage/hybrid.d.ts +193 -0
  66. package/dist/storage/hybrid.d.ts.map +1 -0
  67. package/dist/storage/hybrid.js +519 -0
  68. package/dist/storage/hybrid.js.map +1 -0
  69. package/dist/storage/index.d.ts +21 -0
  70. package/dist/storage/index.d.ts.map +1 -0
  71. package/dist/storage/index.js +20 -0
  72. package/dist/storage/index.js.map +1 -0
  73. package/dist/storage/procedures.d.ts +14 -0
  74. package/dist/storage/procedures.d.ts.map +1 -0
  75. package/dist/storage/procedures.js +101 -0
  76. package/dist/storage/procedures.js.map +1 -0
  77. package/dist/storage/serialization.d.ts +123 -0
  78. package/dist/storage/serialization.d.ts.map +1 -0
  79. package/dist/storage/serialization.js +216 -0
  80. package/dist/storage/serialization.js.map +1 -0
  81. package/dist/storage/synced-registry.d.ts +246 -0
  82. package/dist/storage/synced-registry.d.ts.map +1 -0
  83. package/dist/storage/synced-registry.js +575 -0
  84. package/dist/storage/synced-registry.js.map +1 -0
  85. package/dist/storage/types.d.ts +130 -0
  86. package/dist/storage/types.d.ts.map +1 -0
  87. package/dist/storage/types.js +8 -0
  88. package/dist/storage/types.js.map +1 -0
  89. package/dist/types.d.ts +7 -0
  90. package/dist/types.d.ts.map +1 -0
  91. package/dist/types.js +7 -0
  92. package/dist/types.js.map +1 -0
  93. package/package.json +78 -3
  94. package/src/errors.ts +20 -0
  95. package/src/index.ts +19 -0
  96. package/src/module.ts +30 -0
  97. package/src/procedures.ts +17 -0
  98. package/src/program-store/attach.ts +46 -0
  99. package/src/program-store/collection.ts +39 -0
  100. package/src/program-store/file.ts +157 -0
  101. package/src/program-store/index.ts +17 -0
  102. package/src/program-store/memory.ts +30 -0
  103. package/src/program-store/procedures.ts +351 -0
  104. package/src/program-store/types.ts +78 -0
  105. package/src/register.ts +11 -0
  106. package/src/storage/adapter.ts +273 -0
  107. package/src/storage/api.ts +335 -0
  108. package/src/storage/factory.ts +268 -0
  109. package/src/storage/hybrid.ts +676 -0
  110. package/src/storage/index.ts +61 -0
  111. package/src/storage/procedures.ts +149 -0
  112. package/src/storage/serialization.ts +283 -0
  113. package/src/storage/synced-registry.ts +698 -0
  114. package/src/storage/types.ts +180 -0
  115. package/src/types.ts +7 -0
@@ -0,0 +1,228 @@
1
+ /**
2
+ * The procedures of the program store (roadmap 3.2):
3
+ *
4
+ * - `procedure.store`: write the program of a runtime-defined procedure to the store.
5
+ * - `procedure.load`: define the stored programs again, through `procedure.define`.
6
+ * - `procedure.sync`: push the programs of the registry, pull the stored ones, or both.
7
+ * - `procedure.remote`: the status of the store. A store's backend is fixed when a host makes
8
+ * it, so `connect` and `disconnect` are NOT_IMPLEMENTED: a procedure that could point the
9
+ * store at a new endpoint would give a caller network reach.
10
+ *
11
+ * They use the program store of the caller's registry (`attachProgramStore`). A loaded program
12
+ * is a runtime-defined procedure again: data-driven, so a server with an expose rule lets it
13
+ * call only the exposed procedures. Load programs only from a store that you trust: a host with
14
+ * no expose rule runs whatever a program calls.
15
+ */
16
+ import { z } from "zod";
17
+ import { createProcedure, getAllRuntimeProcedures, keyToPath, outputSchema, pathToKey, runtimeProgramOf, zodAdapter, } from "@procedures/client";
18
+ import { ProcedureStoreError } from "../errors.js";
19
+ import { callerRegistry, getProgramStore, requireProgramStore } from "./attach.js";
20
+ // =============================================================================
21
+ // Shared
22
+ // =============================================================================
23
+ const pathField = z
24
+ .union([z.array(z.string().min(1)).min(1), z.string().min(1)])
25
+ .describe('The path of the procedure: a list of segments, or a dotted key such as "reports.weekly"');
26
+ function toPath(path) {
27
+ return typeof path === "string" ? keyToPath(path) : path;
28
+ }
29
+ /** The metadata to store: the procedure's metadata without the program (the store keeps that). */
30
+ function storedMetadata(metadata) {
31
+ if (!metadata)
32
+ return undefined;
33
+ const { aggregation: _aggregation, generatedFrom: _generatedFrom, ...rest } = metadata;
34
+ return Object.keys(rest).length > 0 ? rest : undefined;
35
+ }
36
+ /** The record of a runtime-defined procedure, or a NOT_A_PROGRAM error for a code procedure. */
37
+ function recordOf(ctx, path) {
38
+ const key = pathToKey(path);
39
+ const procedure = callerRegistry(ctx).get(path);
40
+ if (!procedure) {
41
+ throw new Error(`Procedure not found: ${key}`);
42
+ }
43
+ const program = runtimeProgramOf(procedure);
44
+ if (!program) {
45
+ throw new ProcedureStoreError("NOT_A_PROGRAM", `${key} is a code procedure. Only a procedure that procedure.define made is a program: code lives in a package.`);
46
+ }
47
+ return { key, path: [...procedure.path], program, metadata: storedMetadata(procedure.metadata), storedAt: Date.now() };
48
+ }
49
+ /** Define each program again in the caller's registry, through procedure.define. */
50
+ async function definePrograms(ctx, programs) {
51
+ const result = { loaded: 0, conflicts: [] };
52
+ for (const stored of programs) {
53
+ try {
54
+ await ctx.client.call(["procedure", "define"], {
55
+ path: stored.path,
56
+ aggregation: stored.program,
57
+ ...(stored.metadata ? { metadata: stored.metadata } : {}),
58
+ // A stored program replaces a runtime-defined procedure. procedure.define never replaces
59
+ // a code procedure: that is a conflict.
60
+ replace: true,
61
+ });
62
+ result.loaded++;
63
+ }
64
+ catch (error) {
65
+ result.conflicts.push({ path: stored.path, reason: error instanceof Error ? error.message : String(error) });
66
+ }
67
+ }
68
+ return result;
69
+ }
70
+ export const procedureStoreProcedure = createProcedure()
71
+ .path(["procedure", "store"])
72
+ .input(zodAdapter(z.object({ path: pathField })))
73
+ .output(zodAdapter(z.object({
74
+ stored: z.literal(true).describe("True: the store has the program"),
75
+ path: z.array(z.string()).describe("The path of the procedure"),
76
+ storedAt: z.number().describe("When the store got the program, in milliseconds since 1970"),
77
+ })))
78
+ .meta({
79
+ description: "Write the program of a procedure that procedure.define made to the program store",
80
+ tags: ["procedure", "registry", "storage"],
81
+ // It replaces a stored program of the same key. A FileProgramStore keeps the programs in a file.
82
+ effects: { reads: ["registry"], writes: ["fs", "programs"] },
83
+ args: ["path"],
84
+ })
85
+ .handler(async (input, ctx) => {
86
+ const store = requireProgramStore(ctx, "procedure.store");
87
+ const record = recordOf(ctx, toPath(input.path));
88
+ await store.put(record);
89
+ return { stored: true, path: record.path, storedAt: record.storedAt };
90
+ })
91
+ .build();
92
+ const conflictsField = z
93
+ .array(z.object({ path: z.array(z.string()), reason: z.string() }))
94
+ .describe("The programs that could not be defined, with the reason");
95
+ export const procedureLoadProcedure = createProcedure()
96
+ .path(["procedure", "load"])
97
+ .input(zodAdapter(z.object({
98
+ path: pathField.optional(),
99
+ prefix: pathField.optional().describe("Load the programs of this path and under it"),
100
+ all: z.boolean().optional().describe("Load every stored program"),
101
+ })))
102
+ .output(zodAdapter(z.object({
103
+ loaded: z.number().describe("The number of programs that the load defined"),
104
+ paths: z.array(z.array(z.string())).describe("The paths of the stored programs that matched"),
105
+ conflicts: conflictsField,
106
+ message: z.string(),
107
+ })))
108
+ .meta({
109
+ description: "Define the stored programs again (procedure.define), after a restart",
110
+ tags: ["procedure", "registry", "storage"],
111
+ calls: ["procedure.define"],
112
+ // A loaded program replaces a runtime-defined procedure of the same path
113
+ effects: { reads: ["fs", "programs", "registry"], writes: ["registry"] },
114
+ })
115
+ .handler(async (input, ctx) => {
116
+ const chosen = [input.path !== undefined, input.prefix !== undefined, input.all === true].filter(Boolean).length;
117
+ if (chosen !== 1) {
118
+ throw new Error("procedure.load needs exactly one of `path`, `prefix` or `all: true`");
119
+ }
120
+ const store = requireProgramStore(ctx, "procedure.load");
121
+ let programs;
122
+ let what;
123
+ if (input.path !== undefined) {
124
+ what = pathToKey(toPath(input.path));
125
+ const program = await store.get(what);
126
+ programs = program ? [program] : [];
127
+ }
128
+ else if (input.prefix !== undefined) {
129
+ const prefix = pathToKey(toPath(input.prefix));
130
+ what = `${prefix}.*`;
131
+ programs = await store.list(prefix);
132
+ }
133
+ else {
134
+ what = "all programs";
135
+ programs = await store.list();
136
+ }
137
+ const result = await definePrograms(ctx, programs);
138
+ return {
139
+ loaded: result.loaded,
140
+ paths: programs.map((p) => p.path),
141
+ conflicts: result.conflicts,
142
+ message: `Loaded ${result.loaded} of ${programs.length} stored program(s) for ${what}`,
143
+ };
144
+ })
145
+ .build();
146
+ /** Write each runtime-defined procedure of the caller's registry to the store. */
147
+ async function push(ctx, store) {
148
+ let pushed = 0;
149
+ for (const procedure of getAllRuntimeProcedures(callerRegistry(ctx))) {
150
+ await store.put(recordOf(ctx, procedure.path));
151
+ pushed++;
152
+ }
153
+ return pushed;
154
+ }
155
+ export const procedureSyncProcedure = createProcedure()
156
+ .path(["procedure", "sync"])
157
+ .input(zodAdapter(z.object({
158
+ direction: z
159
+ .enum(["push", "pull", "both"])
160
+ .optional()
161
+ .describe("push: write the programs of the registry to the store. pull: define the stored programs. " +
162
+ "both (the default): push, then pull the stored programs that the registry does not have"),
163
+ })))
164
+ .output(zodAdapter(z.object({
165
+ pushed: z.number().describe("The number of programs written to the store"),
166
+ pulled: z.number().describe("The number of stored programs defined in the registry"),
167
+ conflicts: conflictsField,
168
+ message: z.string(),
169
+ })))
170
+ .meta({
171
+ description: "Synchronize the runtime-defined procedures of the registry with the program store",
172
+ tags: ["procedure", "registry", "storage"],
173
+ calls: ["procedure.define"],
174
+ effects: { reads: ["fs", "programs", "registry"], writes: ["fs", "programs", "registry"] },
175
+ })
176
+ .handler(async (input, ctx) => {
177
+ const direction = input.direction ?? "both";
178
+ const store = requireProgramStore(ctx, "procedure.sync");
179
+ const pushed = direction === "pull" ? 0 : await push(ctx, store);
180
+ let pulled = 0;
181
+ let conflicts = [];
182
+ if (direction !== "push") {
183
+ const registry = callerRegistry(ctx);
184
+ const stored = await store.list();
185
+ // With "both", the registry wins: a program that it has was pushed, and is not pulled back
186
+ const toPull = direction === "pull" ? stored : stored.filter((p) => !registry.get(p.path));
187
+ const result = await definePrograms(ctx, toPull);
188
+ pulled = result.loaded;
189
+ conflicts = result.conflicts;
190
+ }
191
+ return { pushed, pulled, conflicts, message: `Sync ${direction}: pushed ${pushed}, pulled ${pulled}` };
192
+ })
193
+ .build();
194
+ export const procedureRemoteProcedure = createProcedure()
195
+ .path(["procedure", "remote"])
196
+ .input(zodAdapter(z.object({
197
+ action: z
198
+ .enum(["status", "connect", "disconnect"])
199
+ .describe("status: the store of the registry. connect and disconnect: not implemented (the host makes the store)"),
200
+ })))
201
+ .output(outputSchema())
202
+ .meta({
203
+ description: "The status of the program store of the registry",
204
+ tags: ["procedure", "registry", "storage"],
205
+ // It gives the kind of the store. `connect` and `disconnect` change nothing: they fail.
206
+ effects: { reads: ["programs"], writes: [] },
207
+ args: ["action"],
208
+ })
209
+ .handler(async (input, ctx) => {
210
+ if (input.action === "status") {
211
+ const store = getProgramStore(callerRegistry(ctx));
212
+ return store
213
+ ? { configured: true, kind: store.kind, message: `The registry has a ${store.kind} program store` }
214
+ : { configured: false, message: "The registry has no program store" };
215
+ }
216
+ throw new ProcedureStoreError("NOT_IMPLEMENTED", `procedure.remote ${input.action} cannot change the store of a registry at run time. A host makes the store, ` +
217
+ "for example new CollectionProgramStore(new ApiStorage(client, { collection: \"programs\" })), and gives it " +
218
+ "to the registry with attachProgramStore().");
219
+ })
220
+ .build();
221
+ /** The procedures of the program store. */
222
+ export const programStoreProcedures = [
223
+ procedureStoreProcedure,
224
+ procedureLoadProcedure,
225
+ procedureSyncProcedure,
226
+ procedureRemoteProcedure,
227
+ ];
228
+ //# sourceMappingURL=procedures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"procedures.js","sourceRoot":"","sources":["../../src/program-store/procedures.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,SAAS,EACT,YAAY,EACZ,SAAS,EACT,gBAAgB,EAChB,UAAU,GAIX,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGnF,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF,MAAM,SAAS,GAAG,CAAC;KAChB,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7D,QAAQ,CAAC,yFAAyF,CAAC,CAAC;AAEvG,SAAS,MAAM,CAAC,IAA4B;IAC1C,OAAO,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC3D,CAAC;AAED,kGAAkG;AAClG,SAAS,cAAc,CAAC,QAA6C;IACnE,IAAI,CAAC,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IACvF,OAAO,MAAM,CA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AC;IACJ,WAAW,EAAE,iDAAiD;IAC9D,IAAI,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,SAAS,CAAC;IAC1C,wFAAwF;IACxF,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;IAC5C,IAAI,EAAE,CAAC,QAAQ,CAAC;CACjB,CAAC;KACD,OAAO,CAAC,KAAK,EAAE,KAAkB,EAAE,GAAqB,EAAyB,EAAE;IAClF,IAAI,KAAK,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,eAAe,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;QACnD,OAAO,KAAK;YACV,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,sBAAsB,KAAK,CAAC,IAAI,gBAAgB,EAAE;YACnG,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,mCAAmC,EAAE,CAAC;IAC1E,CAAC;IACD,MAAM,IAAI,mBAAmB,CAC3B,iBAAiB,EACjB,oBAAoB,KAAK,CAAC,MAAM,8EAA8E;QAC5G,6GAA6G;QAC7G,4CAA4C,CAC/C,CAAC;AACJ,CAAC,CAAC;KACD,KAAK,EAAE,CAAC;AAEX,2CAA2C;AAC3C,MAAM,CAAC,MAAM,sBAAsB,GAAmB;IACpD,uBAAuB;IACvB,sBAAsB;IACtB,sBAAsB;IACtB,wBAAwB;CACzB,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * The types of the program store.
3
+ *
4
+ * A program is procedure-as-data: the aggregation that `procedure.define` turns into a
5
+ * procedure. A program store keeps programs after the process ends. `procedure.load` defines
6
+ * them again, so a stored program is a runtime-defined procedure again: a data-driven one, which
7
+ * a server with an expose rule lets call only the exposed procedures.
8
+ */
9
+ import type { AggregationDefinition, ProcedurePath } from "@procedures/client";
10
+ /** One stored program. */
11
+ export interface StoredProgram {
12
+ /** The dotted key of the path: `reports.weekly`. */
13
+ key: string;
14
+ /** The path of the procedure. */
15
+ path: ProcedurePath;
16
+ /** The program: the aggregation of `procedure.define`. */
17
+ program: AggregationDefinition;
18
+ /** The metadata of the procedure (its description, its tags), without the program. */
19
+ metadata?: Record<string, unknown> | undefined;
20
+ /** When the store got this version, in milliseconds since 1970. */
21
+ storedAt: number;
22
+ }
23
+ /**
24
+ * A store of programs. Each method gives a Promise: a caller cannot tell a local store from a
25
+ * remote one.
26
+ */
27
+ export interface ProgramStore {
28
+ /** The kind of the backend: "memory", "file", "collection" or another name. */
29
+ readonly kind: string;
30
+ /** The program of a key, or undefined. */
31
+ get(key: string): Promise<StoredProgram | undefined>;
32
+ /** The programs, sorted by key. With a prefix, only the key and the keys under it (`prefix.x`). */
33
+ list(prefix?: string): Promise<StoredProgram[]>;
34
+ /** Write a program. A program of the same key is replaced. */
35
+ put(program: StoredProgram): Promise<void>;
36
+ /** Delete the program of a key. True when it existed. */
37
+ delete(key: string): Promise<boolean>;
38
+ /** Release the resources of the store. */
39
+ close?(): Promise<void>;
40
+ }
41
+ /** True when a key is the prefix or under it (`a.b` for the prefix `a`). */
42
+ export declare function keyMatches(key: string, prefix: string | undefined): boolean;
43
+ /** Programs sorted by key, so a listing is the same for each backend. */
44
+ export declare function byKey(programs: StoredProgram[]): StoredProgram[];
45
+ /**
46
+ * The record to store, checked: a stored program comes back from a file or a remote service, so
47
+ * its shape is not trusted.
48
+ */
49
+ export declare function checkStoredProgram(value: unknown): StoredProgram;
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/program-store/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE/E,0BAA0B;AAC1B,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,GAAG,EAAE,MAAM,CAAC;IACZ,iCAAiC;IACjC,IAAI,EAAE,aAAa,CAAC;IACpB,0DAA0D;IAC1D,OAAO,EAAE,qBAAqB,CAAC;IAC/B,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IAC/C,mEAAmE;IACnE,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAAC;IACrD,mGAAmG;IACnG,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAChD,8DAA8D;IAC9D,GAAG,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3C,yDAAyD;IACzD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACtC,0CAA0C;IAC1C,KAAK,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAE3E;AAED,yEAAyE;AACzE,wBAAgB,KAAK,CAAC,QAAQ,EAAE,aAAa,EAAE,GAAG,aAAa,EAAE,CAEhE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,aAAa,CAmBhE"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The types of the program store.
3
+ *
4
+ * A program is procedure-as-data: the aggregation that `procedure.define` turns into a
5
+ * procedure. A program store keeps programs after the process ends. `procedure.load` defines
6
+ * them again, so a stored program is a runtime-defined procedure again: a data-driven one, which
7
+ * a server with an expose rule lets call only the exposed procedures.
8
+ */
9
+ /** True when a key is the prefix or under it (`a.b` for the prefix `a`). */
10
+ export function keyMatches(key, prefix) {
11
+ return prefix === undefined || prefix === "" || key === prefix || key.startsWith(`${prefix}.`);
12
+ }
13
+ /** Programs sorted by key, so a listing is the same for each backend. */
14
+ export function byKey(programs) {
15
+ return programs.sort((a, b) => (a.key < b.key ? -1 : a.key > b.key ? 1 : 0));
16
+ }
17
+ /**
18
+ * The record to store, checked: a stored program comes back from a file or a remote service, so
19
+ * its shape is not trusted.
20
+ */
21
+ export function checkStoredProgram(value) {
22
+ if (typeof value !== "object" || value === null) {
23
+ throw new TypeError("A stored program must be an object");
24
+ }
25
+ const record = value;
26
+ if (!Array.isArray(record.path) || record.path.length === 0 || !record.path.every((s) => typeof s === "string" && s !== "")) {
27
+ throw new TypeError("A stored program needs a path: a list of non-empty strings");
28
+ }
29
+ if (record.key !== record.path.join(".")) {
30
+ throw new TypeError(`The key of a stored program must be its path with dots: ${record.path.join(".")}`);
31
+ }
32
+ const program = record.program;
33
+ if (typeof program !== "object" || program === null || !Array.isArray(program.$proc)) {
34
+ throw new TypeError(`The program of ${record.key} must be a procedure ref: { "$proc": [...], "input": ... }`);
35
+ }
36
+ if (typeof record.storedAt !== "number" || !Number.isFinite(record.storedAt)) {
37
+ throw new TypeError(`The program of ${record.key} needs storedAt, a time in milliseconds`);
38
+ }
39
+ return record;
40
+ }
41
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/program-store/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAqCH,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,MAA0B;IAChE,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,EAAE,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,CAAC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,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACrF,MAAM,IAAI,SAAS,CAAC,kBAAkB,MAAM,CAAC,GAAG,4DAA4D,CAAC,CAAC;IAChH,CAAC;IACD,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7E,MAAM,IAAI,SAAS,CAAC,kBAAkB,MAAM,CAAC,GAAG,yCAAyC,CAAC,CAAC;IAC7F,CAAC;IACD,OAAO,MAAuB,CAAC;AACjC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Importing this file registers the procedures of @procedures/store, and of the modules that it
3
+ * requires, in the global registry: `import "@procedures/store/register"`. The package root and the
4
+ * `./module` entry register nothing (ARCHITECTURE-PROPOSALS-2026-10, P9).
5
+ */
6
+ export * from "./module.js";
7
+ //# sourceMappingURL=register.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,aAAa,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Importing this file registers the procedures of @procedures/store, and of the modules that it
3
+ * requires, in the global registry: `import "@procedures/store/register"`. The package root and the
4
+ * `./module` entry register nothing (ARCHITECTURE-PROPOSALS-2026-10, P9).
5
+ */
6
+ import { registerStoreProcedures } from "./module.js";
7
+ export * from "./module.js";
8
+ registerStoreProcedures();
9
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,cAAc,aAAa,CAAC;AAE5B,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Procedure Storage Adapter
3
+ *
4
+ * Wraps CollectionStorage<SerializedProcedure> to provide procedure-specific
5
+ * storage operations with serialization/deserialization.
6
+ */
7
+ import type { CollectionStorage } from "@procedures/collections";
8
+ import type { AnyProcedure, ProcedurePath } from "@procedures/client";
9
+ import type { SerializedProcedure, HandlerLoader } from "./types.js";
10
+ import { type SerializeOptions } from "./serialization.js";
11
+ /**
12
+ * Options for ProcedureStorageAdapter.
13
+ */
14
+ export interface ProcedureStorageAdapterOptions {
15
+ /** Handler loader for restoring handlers from references */
16
+ handlerLoader?: HandlerLoader | undefined;
17
+ /** Default serialization options */
18
+ serializeOptions?: SerializeOptions | undefined;
19
+ }
20
+ /**
21
+ * Adapter that wraps CollectionStorage for procedure-specific operations.
22
+ *
23
+ * Handles serialization/deserialization of procedures and provides
24
+ * convenience methods for common operations.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const storage = new InMemoryStorage<SerializedProcedure>();
29
+ * const adapter = new ProcedureStorageAdapter(storage, {
30
+ * handlerLoader: createDynamicHandlerLoader(),
31
+ * });
32
+ *
33
+ * // Store a procedure
34
+ * await adapter.store(myProcedure);
35
+ *
36
+ * // Load a procedure
37
+ * const proc = await adapter.load(['lib', 'scan']);
38
+ * ```
39
+ */
40
+ export declare class ProcedureStorageAdapter {
41
+ private readonly storage;
42
+ private readonly handlerLoader;
43
+ private readonly serializeOptions;
44
+ constructor(storage: CollectionStorage<SerializedProcedure>, options?: ProcedureStorageAdapterOptions);
45
+ /**
46
+ * Store a procedure.
47
+ *
48
+ * @param procedure - Procedure to store
49
+ * @param options - Override default serialization options
50
+ * @returns The record that the storage got
51
+ */
52
+ store(procedure: AnyProcedure, options?: SerializeOptions): Promise<SerializedProcedure>;
53
+ /**
54
+ * Load a procedure by path.
55
+ *
56
+ * @param path - Procedure path
57
+ * @returns Procedure or undefined if not found
58
+ */
59
+ load(path: ProcedurePath): Promise<AnyProcedure | undefined>;
60
+ /**
61
+ * Check if a procedure exists in storage.
62
+ *
63
+ * @param path - Procedure path
64
+ * @returns True if procedure exists
65
+ */
66
+ has(path: ProcedurePath): Promise<boolean>;
67
+ /**
68
+ * Remove a procedure from storage.
69
+ *
70
+ * @param path - Procedure path
71
+ * @returns True if procedure was removed
72
+ */
73
+ remove(path: ProcedurePath): Promise<boolean>;
74
+ /**
75
+ * Load all procedures from storage.
76
+ *
77
+ * @returns Array of all procedures
78
+ */
79
+ loadAll(): Promise<AnyProcedure[]>;
80
+ /**
81
+ * Load procedures matching a path prefix.
82
+ *
83
+ * @param prefix - Path prefix to match
84
+ * @returns Array of matching procedures
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // Load all lib.* procedures
89
+ * const libProcedures = await adapter.loadByPrefix(['lib']);
90
+ * ```
91
+ */
92
+ loadByPrefix(prefix: ProcedurePath): Promise<AnyProcedure[]>;
93
+ /**
94
+ * Store multiple procedures.
95
+ *
96
+ * @param procedures - Procedures to store
97
+ * @param options - Override default serialization options, or a function that gives the
98
+ * options of each procedure (for example, its handler reference)
99
+ * @returns The records that the storage got
100
+ */
101
+ storeAll(procedures: AnyProcedure[], options?: SerializeOptions | ((procedure: AnyProcedure) => SerializeOptions | undefined)): Promise<SerializedProcedure[]>;
102
+ /**
103
+ * Remove multiple procedures.
104
+ *
105
+ * @param paths - Procedure paths to remove
106
+ * @returns Number of procedures removed
107
+ */
108
+ removeAll(paths: ProcedurePath[]): Promise<number>;
109
+ /**
110
+ * Clear all procedures from storage.
111
+ */
112
+ clear(): Promise<void>;
113
+ /**
114
+ * Get the number of stored procedures.
115
+ */
116
+ size(): Promise<number>;
117
+ /**
118
+ * List all stored procedure paths.
119
+ *
120
+ * @returns Array of procedure paths
121
+ */
122
+ listPaths(): Promise<ProcedurePath[]>;
123
+ /**
124
+ * Get the raw serialized data for a procedure.
125
+ * Useful for debugging or custom processing.
126
+ *
127
+ * @param path - Procedure path
128
+ * @returns Serialized procedure data or undefined
129
+ */
130
+ getRaw(path: ProcedurePath): Promise<SerializedProcedure | undefined>;
131
+ /**
132
+ * Get all raw serialized data.
133
+ * Useful for debugging or backup.
134
+ *
135
+ * @returns Array of serialized procedures
136
+ */
137
+ getAllRaw(): Promise<SerializedProcedure[]>;
138
+ /**
139
+ * Close the underlying storage.
140
+ */
141
+ close(): Promise<void>;
142
+ /**
143
+ * Get the underlying storage instance.
144
+ * Use for advanced operations or testing.
145
+ */
146
+ getStorage(): CollectionStorage<SerializedProcedure>;
147
+ }
148
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/storage/adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAIL,KAAK,gBAAgB,EACtB,MAAM,oBAAoB,CAAC;AAM5B;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,4DAA4D;IAC5D,aAAa,CAAC,EAAE,aAAa,GAAG,SAAS,CAAC;IAE1C,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyC;IACjE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAC1D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAmB;IAEpD,YACE,OAAO,EAAE,iBAAiB,CAAC,mBAAmB,CAAC,EAC/C,OAAO,GAAE,8BAAmC,EAK7C;IAMD;;;;;;OAMG;IACG,KAAK,CAAC,SAAS,EAAE,YAAY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