toolsplice 0.0.0-stage → 0.0.2

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 (172) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -2
  3. package/dist/abortable.d.ts +6 -0
  4. package/dist/abortable.js +50 -0
  5. package/dist/adaptive-read.d.ts +50 -0
  6. package/dist/adaptive-read.js +780 -0
  7. package/dist/answer-wait.d.ts +7 -0
  8. package/dist/answer-wait.js +45 -0
  9. package/dist/cache-reads.d.ts +18 -0
  10. package/dist/cache-reads.js +89 -0
  11. package/dist/calibration-ledger.d.ts +37 -0
  12. package/dist/calibration-ledger.js +148 -0
  13. package/dist/calibration-marker.d.ts +4 -0
  14. package/dist/calibration-marker.js +77 -0
  15. package/dist/catalog-setup.d.ts +33 -0
  16. package/dist/catalog-setup.js +89 -0
  17. package/dist/catalog.d.ts +10 -0
  18. package/dist/catalog.js +42 -0
  19. package/dist/checkpoint-files.d.ts +15 -0
  20. package/dist/checkpoint-files.js +99 -0
  21. package/dist/cli.d.ts +2 -0
  22. package/dist/cli.js +1454 -0
  23. package/dist/coalesce-reads.d.ts +6 -0
  24. package/dist/coalesce-reads.js +33 -0
  25. package/dist/codegen.d.ts +44 -0
  26. package/dist/codegen.js +479 -0
  27. package/dist/contract-caller.d.ts +23 -0
  28. package/dist/contract-caller.js +326 -0
  29. package/dist/contract-corrections.d.ts +35 -0
  30. package/dist/contract-corrections.js +159 -0
  31. package/dist/contract-schema.d.ts +7 -0
  32. package/dist/contract-schema.js +156 -0
  33. package/dist/contracts.d.ts +72 -0
  34. package/dist/contracts.js +370 -0
  35. package/dist/core.d.ts +44 -0
  36. package/dist/core.js +43 -0
  37. package/dist/db-final-answer.d.ts +9 -0
  38. package/dist/db-final-answer.js +62 -0
  39. package/dist/define.d.ts +78 -0
  40. package/dist/define.js +14 -0
  41. package/dist/doctor.d.ts +22 -0
  42. package/dist/doctor.js +91 -0
  43. package/dist/drift.d.ts +23 -0
  44. package/dist/drift.js +111 -0
  45. package/dist/execution.d.ts +38 -0
  46. package/dist/execution.js +66 -0
  47. package/dist/extract.d.ts +34 -0
  48. package/dist/extract.js +73 -0
  49. package/dist/final-answer-stores.d.ts +71 -0
  50. package/dist/final-answer-stores.js +72 -0
  51. package/dist/final-answer.d.ts +32 -0
  52. package/dist/final-answer.js +104 -0
  53. package/dist/impact.d.ts +48 -0
  54. package/dist/impact.js +71 -0
  55. package/dist/index.d.ts +51 -0
  56. package/dist/index.js +47 -0
  57. package/dist/local-tool.d.ts +18 -0
  58. package/dist/local-tool.js +32 -0
  59. package/dist/mcp-apps.d.ts +53 -0
  60. package/dist/mcp-apps.js +32 -0
  61. package/dist/mcp-event-delivery.d.ts +98 -0
  62. package/dist/mcp-event-delivery.js +211 -0
  63. package/dist/mcp-extensions.d.ts +46 -0
  64. package/dist/mcp-extensions.js +200 -0
  65. package/dist/mcp-peer.d.ts +45 -0
  66. package/dist/mcp-peer.js +207 -0
  67. package/dist/mcp-server-card.d.ts +21 -0
  68. package/dist/mcp-server-card.js +54 -0
  69. package/dist/ordered-transport.d.ts +12 -0
  70. package/dist/ordered-transport.js +106 -0
  71. package/dist/page-checkpoint.d.ts +71 -0
  72. package/dist/page-checkpoint.js +286 -0
  73. package/dist/page-read-gate.d.ts +15 -0
  74. package/dist/page-read-gate.js +48 -0
  75. package/dist/pattern.d.ts +3 -0
  76. package/dist/pattern.js +54 -0
  77. package/dist/postgres.d.ts +41 -0
  78. package/dist/postgres.js +264 -0
  79. package/dist/probe.d.ts +29 -0
  80. package/dist/probe.js +121 -0
  81. package/dist/proxy.d.ts +40 -0
  82. package/dist/proxy.js +436 -0
  83. package/dist/read-pages.d.ts +25 -0
  84. package/dist/read-pages.js +85 -0
  85. package/dist/read-policy.d.ts +6 -0
  86. package/dist/read-policy.js +16 -0
  87. package/dist/read-steps.d.ts +12 -0
  88. package/dist/read-steps.js +36 -0
  89. package/dist/result-session.d.ts +109 -0
  90. package/dist/result-session.js +620 -0
  91. package/dist/route-checkpoint.d.ts +3 -0
  92. package/dist/route-checkpoint.js +80 -0
  93. package/dist/route-driver-cli.d.ts +3 -0
  94. package/dist/route-driver-cli.js +43 -0
  95. package/dist/route-evaluation.d.ts +141 -0
  96. package/dist/route-evaluation.js +329 -0
  97. package/dist/row-groups.d.ts +17 -0
  98. package/dist/row-groups.js +79 -0
  99. package/dist/row-query.d.ts +62 -0
  100. package/dist/row-query.js +172 -0
  101. package/dist/rules.d.ts +30 -0
  102. package/dist/rules.js +72 -0
  103. package/dist/run-diagnostics.d.ts +75 -0
  104. package/dist/run-diagnostics.js +212 -0
  105. package/dist/runtime.d.ts +6 -0
  106. package/dist/runtime.js +26 -0
  107. package/dist/schema.d.ts +17 -0
  108. package/dist/schema.js +299 -0
  109. package/dist/search-fetch.d.ts +50 -0
  110. package/dist/search-fetch.js +264 -0
  111. package/dist/shape.d.ts +91 -0
  112. package/dist/shape.js +499 -0
  113. package/dist/skill-files.d.ts +9 -0
  114. package/dist/skill-files.js +49 -0
  115. package/dist/splice-diagnostics.d.ts +44 -0
  116. package/dist/splice-diagnostics.js +88 -0
  117. package/dist/splice-measure.d.ts +33 -0
  118. package/dist/splice-measure.js +55 -0
  119. package/dist/splice-project.d.ts +125 -0
  120. package/dist/splice-project.js +348 -0
  121. package/dist/splice-recording.d.ts +132 -0
  122. package/dist/splice-recording.js +481 -0
  123. package/dist/splice.d.ts +181 -0
  124. package/dist/splice.js +1263 -0
  125. package/dist/sqlite-checkpoint-store.d.ts +5 -0
  126. package/dist/sqlite-checkpoint-store.js +91 -0
  127. package/dist/sqlite-checkpoint-worker.d.ts +1 -0
  128. package/dist/sqlite-checkpoint-worker.js +115 -0
  129. package/dist/storage.d.ts +17 -0
  130. package/dist/storage.js +1 -0
  131. package/dist/store.d.ts +151 -0
  132. package/dist/store.js +735 -0
  133. package/dist/test-difference.d.ts +13 -0
  134. package/dist/test-difference.js +42 -0
  135. package/dist/testing.d.ts +122 -0
  136. package/dist/testing.js +261 -0
  137. package/dist/text-pages.d.ts +24 -0
  138. package/dist/text-pages.js +36 -0
  139. package/dist/tool-discovery.d.ts +59 -0
  140. package/dist/tool-discovery.js +136 -0
  141. package/dist/unevaluated.d.ts +7 -0
  142. package/dist/unevaluated.js +156 -0
  143. package/dist/v2.d.ts +49 -0
  144. package/dist/v2.js +413 -0
  145. package/dist/validate-output.d.ts +3 -0
  146. package/dist/validate-output.js +73 -0
  147. package/dist/version.d.ts +1 -0
  148. package/dist/version.js +1 -0
  149. package/dist/workflow-json.d.ts +8 -0
  150. package/dist/workflow-json.js +74 -0
  151. package/docs/AGENT-FRAMEWORKS.md +431 -0
  152. package/docs/BENCHMARKS.md +43 -0
  153. package/docs/INTEGRATION-QUICKSTART.md +859 -0
  154. package/docs/LEARNING-AND-STORAGE.md +393 -0
  155. package/docs/MCP.md +204 -0
  156. package/docs/PROJECTS-AND-UPGRADES.md +173 -0
  157. package/docs/PYTHON-REFERENCE.md +348 -0
  158. package/docs/PYTHON.md +120 -0
  159. package/docs/RECORDING-AND-CORRECTIONS.md +205 -0
  160. package/docs/TESTING.md +259 -0
  161. package/examples/mcp-app/build.mjs +11 -0
  162. package/examples/mcp-app/view.mjs +22 -0
  163. package/examples/quickstart.mjs +43 -0
  164. package/examples/route-driver.mjs +67 -0
  165. package/integrations/ai.d.mts +36 -0
  166. package/integrations/ai.mjs +178 -0
  167. package/integrations/call-options.mjs +9 -0
  168. package/integrations/langchain.d.mts +31 -0
  169. package/integrations/langchain.mjs +114 -0
  170. package/integrations/managed.mjs +154 -0
  171. package/integrations/types.d.mts +13 -0
  172. package/package.json +139 -4
@@ -0,0 +1,286 @@
1
+ import { isDeepStrictEqual } from "node:util";
2
+ import { createHash } from "node:crypto";
3
+ import { mkdirSync } from "node:fs";
4
+ import { join, resolve } from "node:path";
5
+ import { publish, read as readRecord, syncDirectory, } from "./checkpoint-files.js";
6
+ import { abortable } from "./abortable.js";
7
+ import { pageLimits, RetryablePageError, utf8Bytes, } from "./read-pages.js";
8
+ import { jsonFingerprint, jsonObject } from "./workflow-json.js";
9
+ /** The source adapter can explicitly report that its saved snapshot cursor expired. */
10
+ export class ExpiredPageCursorError extends Error {
11
+ }
12
+ /** The dispatched source read may have completed. Keep its claim for reconciliation. */
13
+ export class UncertainPageReadError extends Error {
14
+ name = "UncertainPageReadError";
15
+ }
16
+ function fileStore(directory) {
17
+ let initialized = false;
18
+ const path = (job) => join(directory, "pages-" + job);
19
+ return {
20
+ async read(job) {
21
+ const saved = readRecord(path(job) + ".json", 96 * 1024 * 1024);
22
+ if (saved) {
23
+ if (typeof saved.identity !== "string" ||
24
+ typeof saved.payload !== "string")
25
+ throw new Error("Invalid page checkpoint.");
26
+ return { identity: saved.identity, payload: saved.payload };
27
+ }
28
+ const claim = readRecord(path(job) + ".claim");
29
+ return claim ? { identity: String(claim.identity), payload: null } : null;
30
+ },
31
+ async claim(job, identity) {
32
+ if (!initialized) {
33
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
34
+ initialized = true;
35
+ }
36
+ return publish(path(job) + ".claim", { identity });
37
+ },
38
+ async complete(job, identity, payload) {
39
+ const saved = publish(path(job) + ".json", { identity, payload });
40
+ if (!saved)
41
+ syncDirectory(directory);
42
+ return saved;
43
+ },
44
+ };
45
+ }
46
+ const digest = (body) => createHash("sha256").update(body).digest("hex");
47
+ function decode(encoded, normalizeZero = false) {
48
+ if (typeof encoded !== "string" ||
49
+ Buffer.byteLength(encoded) > 16 * 1024 * 1024)
50
+ throw new Error("Invalid page checkpoint.");
51
+ const body = encoded.slice(65);
52
+ if (encoded[64] !== "\n" || digest(body) !== encoded.slice(0, 64))
53
+ throw new Error("Invalid page checkpoint digest.");
54
+ const entry = normalizeZero
55
+ ? JSON.parse(body, (_key, value) => (value === 0 ? 0 : value))
56
+ : JSON.parse(body);
57
+ if (!jsonObject(entry) ||
58
+ !["page", "retry", "expired", "failed"].includes(String(entry.kind)))
59
+ throw new Error("Invalid page checkpoint entry.");
60
+ return entry;
61
+ }
62
+ function encode(entry) {
63
+ const body = JSON.stringify(entry);
64
+ if (Buffer.byteLength(body) > 12 * 1024 * 1024)
65
+ throw new Error("Page contribution exceeds the 12 MiB checkpoint limit.");
66
+ return digest(body) + "\n" + body;
67
+ }
68
+ function sameContribution(saved, candidate) {
69
+ if (saved === candidate)
70
+ return true;
71
+ // Older Python records may spell JSON zero as -0.0. Normalize it to the JS wire form.
72
+ return isDeepStrictEqual(decode(saved, true), decode(candidate));
73
+ }
74
+ // Another worker can confirm the same source contribution before the original writer returns.
75
+ async function save(backend, job, identity, payload) {
76
+ if (await backend.complete(job, identity, payload))
77
+ return;
78
+ const row = await backend.read(job);
79
+ if (row?.identity !== identity ||
80
+ row.payload === null ||
81
+ !sameContribution(row.payload, payload))
82
+ throw new Error("Conflicting or unacknowledged page checkpoint.");
83
+ }
84
+ /** Bound to one query and snapshot. Every invocation builds its own accumulator. */
85
+ export function createPageJob(checkpoint, kind, query, options, projection) {
86
+ const { maxPages, maxBytes } = pageLimits(options);
87
+ const { jobId, context, directory, store } = checkpoint;
88
+ const { maxReadAttempts = 3, maxRetryWaitMs = 60000, signal } = options;
89
+ if (typeof jobId !== "string" ||
90
+ !jobId ||
91
+ !jsonObject(context) ||
92
+ (store === undefined
93
+ ? typeof directory !== "string" || !directory
94
+ : !store || directory !== undefined))
95
+ throw new TypeError("Choose a page checkpoint directory or store, job ID and context.");
96
+ if (!Number.isInteger(maxReadAttempts) ||
97
+ maxReadAttempts < 1 ||
98
+ maxReadAttempts > 5 ||
99
+ !Number.isInteger(maxRetryWaitMs) ||
100
+ maxRetryWaitMs < 0 ||
101
+ maxRetryWaitMs > 60000)
102
+ throw new RangeError("Invalid page retry limits.");
103
+ const folder = directory === undefined ? undefined : resolve(directory);
104
+ const backend = store ?? fileStore(folder);
105
+ const format = "toolsplice-pages-v1";
106
+ const scope = jsonFingerprint({
107
+ format,
108
+ jobId,
109
+ context,
110
+ kind,
111
+ query,
112
+ maxPages,
113
+ maxBytes,
114
+ maxReadAttempts,
115
+ maxRetryWaitMs,
116
+ });
117
+ async function traverse(op) {
118
+ const { project, append, finish } = projection();
119
+ const missing = () => {
120
+ throw new Error("No matching claimed page attempt.");
121
+ };
122
+ const seen = new Set();
123
+ let cursor;
124
+ let claimNext = false;
125
+ let bytes = 0, remaining = maxRetryWaitMs;
126
+ function contribution(received, page) {
127
+ const next = received.nextCursor ?? null;
128
+ if (next !== null &&
129
+ (typeof next !== "string" ||
130
+ utf8Bytes(next) > 4096 ||
131
+ seen.has(next) ||
132
+ page === maxPages))
133
+ throw new Error("Invalid continuation or page limit exceeded.");
134
+ const data = project(received);
135
+ if (bytes + data.bytes > maxBytes)
136
+ throw new Error("Read exceeded the byte limit.");
137
+ return { kind: "page", next, ...data };
138
+ }
139
+ for (let page = 1; page <= maxPages; page++) {
140
+ for (let attempt = 1; attempt <= maxReadAttempts; attempt++) {
141
+ signal?.throwIfAborted();
142
+ const job = jsonFingerprint([format, jobId, page, attempt]);
143
+ const identity = jsonFingerprint([
144
+ scope,
145
+ page,
146
+ attempt,
147
+ cursor ?? null,
148
+ ]);
149
+ // After saving a fresh page, the next database key is usually absent.
150
+ // A lost claim still reads the winner's row and validates its identity.
151
+ const ownsClaim = claimNext && (await backend.claim(job, identity));
152
+ const row = ownsClaim ? null : await backend.read(job);
153
+ if (row && row.identity !== identity)
154
+ throw new Error("Page checkpoint identity mismatch.");
155
+ const receipt = {
156
+ key: identity,
157
+ page,
158
+ attempt,
159
+ cursor: cursor ?? null,
160
+ };
161
+ const position = { ...receipt, acceptedPages: page - 1 };
162
+ if (op.mode === "confirm" && op.key === identity) {
163
+ if (!row)
164
+ return missing();
165
+ const payload = encode(contribution(op.value, page));
166
+ if (row.payload === null)
167
+ await save(backend, job, identity, payload);
168
+ else {
169
+ if (!sameContribution(row.payload, payload))
170
+ throw new Error("Conflicting page confirmation.");
171
+ // A concurrent file publisher may still be syncing this visible directory entry.
172
+ if (folder)
173
+ syncDirectory(folder);
174
+ }
175
+ return;
176
+ }
177
+ let entry;
178
+ if (row?.payload != null) {
179
+ entry = decode(row.payload);
180
+ claimNext = false;
181
+ }
182
+ else {
183
+ if (op.mode === "inspect")
184
+ return { ...position, state: row ? "outcome_unknown" : "ready" };
185
+ if (op.mode === "confirm")
186
+ return missing();
187
+ if (!ownsClaim &&
188
+ (row || claimNext || !(await backend.claim(job, identity))))
189
+ return { state: "busy", page };
190
+ let cause;
191
+ let reading = true;
192
+ try {
193
+ const received = await abortable(() => op.read(receipt, signal), signal);
194
+ reading = false;
195
+ entry = contribution(received, page);
196
+ }
197
+ catch (error) {
198
+ signal?.throwIfAborted();
199
+ if (reading && error instanceof UncertainPageReadError)
200
+ throw error;
201
+ cause = error;
202
+ entry = {
203
+ kind: reading && error instanceof ExpiredPageCursorError
204
+ ? "expired"
205
+ : "failed",
206
+ };
207
+ if (reading &&
208
+ error instanceof RetryablePageError &&
209
+ attempt < maxReadAttempts) {
210
+ const delay = Math.max(error.retryAfterMs ?? 0, Math.floor(100 * 2 ** (attempt - 1) * (1 + Math.random())));
211
+ if (delay <= remaining)
212
+ entry = { kind: "retry", delay, at: Date.now() + delay };
213
+ }
214
+ }
215
+ let payload;
216
+ try {
217
+ payload = encode(entry);
218
+ }
219
+ catch (error) {
220
+ cause = error;
221
+ entry = { kind: "failed" };
222
+ payload = encode(entry);
223
+ }
224
+ await save(backend, job, identity, payload);
225
+ claimNext = store !== undefined;
226
+ if (entry.kind === "failed")
227
+ throw cause;
228
+ }
229
+ if (entry.kind === "expired" || entry.kind === "failed") {
230
+ if (op.mode === "inspect")
231
+ return { ...position, state: entry.kind };
232
+ if (op.mode === "confirm")
233
+ return missing();
234
+ }
235
+ if (entry.kind === "expired")
236
+ return { state: "expired", page };
237
+ if (entry.kind === "failed")
238
+ throw new Error("Page read previously failed for this job.");
239
+ if (entry.kind === "retry") {
240
+ if (!Number.isSafeInteger(entry.delay) ||
241
+ entry.delay < 0 ||
242
+ entry.delay > remaining ||
243
+ !Number.isSafeInteger(entry.at) ||
244
+ attempt >= maxReadAttempts)
245
+ throw new Error("Invalid saved page retry.");
246
+ remaining -= entry.delay;
247
+ if (Date.now() < entry.at) {
248
+ if (op.mode === "confirm")
249
+ return missing();
250
+ return op.mode === "inspect"
251
+ ? { ...position, state: "deferred", retryAt: entry.at }
252
+ : { state: "deferred", page, retryAt: entry.at };
253
+ }
254
+ continue;
255
+ }
256
+ if (entry.kind !== "page" ||
257
+ !Number.isSafeInteger(entry.bytes) ||
258
+ entry.bytes < 0 ||
259
+ (bytes += entry.bytes) > maxBytes)
260
+ throw new Error("Invalid saved page size.");
261
+ if (op.mode === "run")
262
+ append(entry.part);
263
+ if (entry.next === null) {
264
+ if (op.mode === "confirm")
265
+ return missing();
266
+ return op.mode === "inspect"
267
+ ? { state: "complete", acceptedPages: page }
268
+ : { state: "complete", result: finish() };
269
+ }
270
+ if (typeof entry.next !== "string" ||
271
+ utf8Bytes(entry.next) > 4096 ||
272
+ seen.has(entry.next))
273
+ throw new Error("Invalid saved continuation.");
274
+ cursor = entry.next;
275
+ seen.add(cursor);
276
+ break;
277
+ }
278
+ }
279
+ throw new Error("Read exceeded the page limit.");
280
+ }
281
+ return {
282
+ run: (read) => traverse({ mode: "run", read }),
283
+ inspect: () => traverse({ mode: "inspect" }),
284
+ confirm: (key, value) => traverse({ mode: "confirm", key, value }),
285
+ };
286
+ }
@@ -0,0 +1,15 @@
1
+ export interface PageReadGateOptions {
2
+ /** Minimum interval between starts, shared by reads using this gate. */
3
+ minIntervalMs: number;
4
+ /** Refuse a remaining source cooldown longer than this. Queueing is cancellable. Default 60 s. */
5
+ maxCooldownMs?: number;
6
+ }
7
+ /** One in-process upstream queue. Share the instance across idempotent readers. */
8
+ export declare class PageReadGate {
9
+ private tail;
10
+ private nextStart;
11
+ private readonly minIntervalMs;
12
+ private readonly maxCooldownMs;
13
+ constructor({ minIntervalMs, maxCooldownMs }: PageReadGateOptions);
14
+ read<T>(read: () => T | PromiseLike<T>, signal?: AbortSignal): Promise<T>;
15
+ }
@@ -0,0 +1,48 @@
1
+ import { setTimeout as wait } from "node:timers/promises";
2
+ import { abortable } from "./abortable.js";
3
+ import { RetryablePageError } from "./read-pages.js";
4
+ /** One in-process upstream queue. Share the instance across idempotent readers. */
5
+ export class PageReadGate {
6
+ tail = Promise.resolve();
7
+ nextStart = 0;
8
+ minIntervalMs;
9
+ maxCooldownMs;
10
+ constructor({ minIntervalMs, maxCooldownMs = 60000 }) {
11
+ for (const n of [minIntervalMs, maxCooldownMs]) {
12
+ if (!Number.isSafeInteger(n) || n < 0 || n > 60000)
13
+ throw new RangeError("Page read gate durations must be integers from 0 through 60000 ms.");
14
+ }
15
+ this.minIntervalMs = minIntervalMs;
16
+ this.maxCooldownMs = maxCooldownMs;
17
+ }
18
+ async read(read, signal) {
19
+ signal?.throwIfAborted();
20
+ if (typeof read !== "function")
21
+ throw new TypeError("Expected a page read callback.");
22
+ // Every queued turn waits on its predecessor even if its caller has cancelled.
23
+ const work = this.tail.then(async () => {
24
+ signal?.throwIfAborted();
25
+ const now = performance.now();
26
+ const delay = Math.max(0, Math.ceil(this.nextStart - now));
27
+ if (delay > this.maxCooldownMs)
28
+ throw new RetryablePageError("Page read cooldown exceeds the configured limit.", Math.min(Number.MAX_SAFE_INTEGER, delay));
29
+ if (delay)
30
+ await wait(delay, undefined, { signal });
31
+ signal?.throwIfAborted();
32
+ this.nextStart = performance.now() + this.minIntervalMs;
33
+ try {
34
+ return await read();
35
+ }
36
+ catch (error) {
37
+ if (error instanceof RetryablePageError &&
38
+ error.retryAfterMs !== undefined) {
39
+ this.nextStart = Math.max(this.nextStart, performance.now() + error.retryAfterMs);
40
+ }
41
+ throw error;
42
+ }
43
+ });
44
+ this.tail = work.then(() => undefined, () => undefined);
45
+ // Cancelling a caller stops waiting immediately. An in-flight callback still owns the slot.
46
+ return abortable(() => work, signal);
47
+ }
48
+ }
@@ -0,0 +1,3 @@
1
+ import { RE2JS } from "re2js";
2
+ export declare function compileEnginePattern(pattern: string): RE2JS;
3
+ export declare function compilePattern(pattern: string): RE2JS;
@@ -0,0 +1,54 @@
1
+ // The portable subset is checked when a provider schema is loaded. The same
2
+ // engine also compiles Ajv's own meta-schema patterns, which use a wider grammar.
3
+ import { RE2JS } from "re2js";
4
+ // ECMA-262 WhiteSpace and LineTerminator code points. RE2's native \s is ASCII.
5
+ const whitespace = String.raw `[\x09-\x0D\x20\xA0\x{1680}\x{2000}-\x{200A}\x{2028}\x{2029}\x{202F}\x{205F}\x{3000}\x{FEFF}]`;
6
+ export function compileEnginePattern(pattern) {
7
+ let translated = "";
8
+ let inClass = false;
9
+ for (let i = 0; i < pattern.length; i++) {
10
+ const c = pattern[i];
11
+ if (c === "\\" && i + 1 < pattern.length) {
12
+ const escaped = pattern[++i];
13
+ translated += escaped === "s" && !inClass ? whitespace : c + escaped;
14
+ }
15
+ else {
16
+ if (c === "[")
17
+ inClass = true;
18
+ if (c === "]")
19
+ inClass = false;
20
+ translated += c;
21
+ }
22
+ }
23
+ return RE2JS.compile(translated);
24
+ }
25
+ export function compilePattern(pattern) {
26
+ if (pattern.length > 1024)
27
+ throw new Error("pattern limit");
28
+ let inClass = false;
29
+ for (let i = 0; i < pattern.length; i++) {
30
+ const c = pattern[i];
31
+ if (c.charCodeAt(0) > 127)
32
+ throw new Error("non-ASCII pattern");
33
+ if (c === "\\") {
34
+ const n = pattern[++i];
35
+ if (n === "s" && !inClass)
36
+ continue;
37
+ if (!n || !"dwnrtf\\^$.*+?()[]{}|/-".includes(n))
38
+ throw new Error("unsupported escape");
39
+ continue;
40
+ }
41
+ if (c === "[") {
42
+ if (inClass || pattern[i + 1] === "^")
43
+ throw new Error("unsupported character class");
44
+ inClass = true;
45
+ }
46
+ else if (c === "]")
47
+ inClass = false;
48
+ else if (c === "." && !inClass)
49
+ throw new Error("unsupported wildcard");
50
+ }
51
+ // Syntax only. Native regexes never execute against contract values.
52
+ new RegExp(pattern, "u");
53
+ return compileEnginePattern(pattern);
54
+ }
@@ -0,0 +1,41 @@
1
+ import type { LearningStore } from "./storage.js";
2
+ import { type ServerRecord } from "./store.js";
3
+ export interface PostgresStoreOptions {
4
+ connectionString: string;
5
+ /** Separate projects/tenants in one database. This is not a database authorization boundary. */
6
+ namespace?: string;
7
+ /** Auto-create schema v1 on first use. Set false for a pre-migrated restricted runtime role. */
8
+ migrate?: boolean;
9
+ timeoutMs?: number;
10
+ maxConnections?: number;
11
+ pollIntervalMs?: number;
12
+ }
13
+ /** PostgreSQL 14+. Owns its connection pool; call close() after all users stop.
14
+ * All updates and deletes acquire the same transaction-scoped advisory lock,
15
+ * including absent rows. A crashed connection releases its locks automatically.
16
+ * No callback retry after entry, and no file/cache fallback after an outage. */
17
+ export declare class PostgresShapeStore implements LearningStore {
18
+ #private;
19
+ readonly namespace: string;
20
+ private readyPromise?;
21
+ private closed;
22
+ private watchers;
23
+ private revisions;
24
+ private readonly timeout;
25
+ private readonly max;
26
+ private readonly pollInterval;
27
+ constructor(options: PostgresStoreOptions);
28
+ private failure;
29
+ private pool;
30
+ initialize(): Promise<void>;
31
+ private initializeSchema;
32
+ refresh(name: string): Promise<ServerRecord | undefined>;
33
+ load(name: string, version?: string): Promise<ServerRecord>;
34
+ has(name: string): Promise<boolean>;
35
+ list(): Promise<string[]>;
36
+ private transaction;
37
+ transact<T>(name: string, mutate: (record: ServerRecord) => T): Promise<T>;
38
+ remove(name: string): Promise<void>;
39
+ watch(name: string, onChange: () => void, onError?: () => void): () => void;
40
+ close(): Promise<void>;
41
+ }