@elpapi42/pi-fleet 0.1.0-beta.1 → 0.1.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +180 -3
- package/README.md +118 -120
- package/bin/pifleet-runtime.mjs +1 -1
- package/dist/cli-meta.json +5555 -175
- package/dist/cli.mjs +4391 -471
- package/dist/cli.mjs.map +4 -4
- package/dist/client/agent-target.d.ts +33 -0
- package/dist/client/contracts.d.ts +81 -0
- package/dist/client/fleet-client.d.ts +118 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/sdk-connector.d.ts +7 -0
- package/dist/client/sdk-facade.d.ts +84 -0
- package/dist/client/sdk-transport.d.ts +24 -0
- package/dist/client/shared-client.d.ts +18 -0
- package/dist/client/socket-fleet-client.d.ts +21 -0
- package/dist/client-meta.json +5736 -0
- package/dist/client.mjs +4434 -0
- package/dist/client.mjs.map +7 -0
- package/dist/installer-meta.json +87 -13
- package/dist/installer.mjs +589 -95
- package/dist/installer.mjs.map +4 -4
- package/dist/journal-sqlite-worker-meta.json +149 -0
- package/dist/journal-sqlite-worker.mjs +1110 -0
- package/dist/journal-sqlite-worker.mjs.map +7 -0
- package/dist/pi/external-installation.d.ts +23 -0
- package/dist/platform/client/start-runtime.d.ts +25 -0
- package/dist/platform/install/runtime-release.d.ts +8 -0
- package/dist/platform/install/tree-integrity.d.ts +7 -0
- package/dist/platform/shared/paths.d.ts +8 -0
- package/dist/platform/shared/runtime-ownership.d.ts +14 -0
- package/dist/protocol/jsonl.d.ts +3 -0
- package/dist/protocol/pi-identity.d.ts +16 -0
- package/dist/protocol/semantic-segmentation.d.ts +22 -0
- package/dist/protocol/version.d.ts +2 -0
- package/dist/runtime/semantic-events.d.ts +43 -0
- package/dist/runtime-manifest.json +167 -48
- package/dist/runtime-meta.json +3241 -2808
- package/dist/runtime.mjs +9290 -5641
- package/dist/runtime.mjs.map +4 -4
- package/dist/shared/result.d.ts +9 -0
- package/package.json +24 -5
- package/dist/sqlite-worker-meta.json +0 -84
- package/dist/sqlite-worker.mjs +0 -304
- package/dist/sqlite-worker.mjs.map +0 -7
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,4434 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/client/sdk-facade.ts
|
|
8
|
+
function createConnectPiFleet(connector) {
|
|
9
|
+
return async (options = {}) => createPiFleetClient(await connector.connect(options));
|
|
10
|
+
}
|
|
11
|
+
function createPiFleetClient(transport) {
|
|
12
|
+
return new PiFleetClientImpl(transport);
|
|
13
|
+
}
|
|
14
|
+
var PiFleetClientImpl = class {
|
|
15
|
+
constructor(transport) {
|
|
16
|
+
this.transport = transport;
|
|
17
|
+
}
|
|
18
|
+
#closed = false;
|
|
19
|
+
#closedController = new AbortController();
|
|
20
|
+
async create(input, options = {}) {
|
|
21
|
+
return this.agent(
|
|
22
|
+
await this.callAgent(() => this.transport.create(input, this.signal(options.signal)))
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
async get(name, options = {}) {
|
|
26
|
+
const summary = await this.callAgent(
|
|
27
|
+
() => this.transport.get(name, this.signal(options.signal))
|
|
28
|
+
);
|
|
29
|
+
if (summary === null) {
|
|
30
|
+
throw new PiFleetError("agent_not_found", `Agent ${name} was not found.`);
|
|
31
|
+
}
|
|
32
|
+
return this.agent(summary);
|
|
33
|
+
}
|
|
34
|
+
async list(options = {}) {
|
|
35
|
+
return this.callAgent(() => this.transport.list(this.signal(options.signal)));
|
|
36
|
+
}
|
|
37
|
+
async close() {
|
|
38
|
+
if (this.#closed) return;
|
|
39
|
+
this.#closed = true;
|
|
40
|
+
this.#closedController.abort();
|
|
41
|
+
await this.transport.close();
|
|
42
|
+
}
|
|
43
|
+
agent(summary) {
|
|
44
|
+
return new AgentImpl(this, this.transport, summary);
|
|
45
|
+
}
|
|
46
|
+
async callAgent(operation) {
|
|
47
|
+
this.assertOpen();
|
|
48
|
+
try {
|
|
49
|
+
return await operation();
|
|
50
|
+
} catch (error) {
|
|
51
|
+
throw PiFleetError.from(error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
signal(signal) {
|
|
55
|
+
this.assertOpen();
|
|
56
|
+
return signal === void 0 ? this.#closedController.signal : AbortSignal.any([signal, this.#closedController.signal]);
|
|
57
|
+
}
|
|
58
|
+
assertOpen() {
|
|
59
|
+
if (this.#closed) throw new PiFleetError("runtime_unavailable", "pi-fleet client is closed");
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var agentInternals = /* @__PURE__ */ new WeakMap();
|
|
63
|
+
var AgentImpl = class {
|
|
64
|
+
constructor(client, transport, initialSummary) {
|
|
65
|
+
this.client = client;
|
|
66
|
+
this.transport = transport;
|
|
67
|
+
this.id = initialSummary.id;
|
|
68
|
+
this.name = initialSummary.name;
|
|
69
|
+
agentInternals.set(this, { client, transport, initialSummary });
|
|
70
|
+
}
|
|
71
|
+
id;
|
|
72
|
+
name;
|
|
73
|
+
status(options = {}) {
|
|
74
|
+
return this.client.callAgent(
|
|
75
|
+
() => this.transport.status(this.target(), this.client.signal(options.signal))
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
send(message, options = {}) {
|
|
79
|
+
return this.client.callAgent(
|
|
80
|
+
() => this.transport.send(
|
|
81
|
+
this.target(),
|
|
82
|
+
message,
|
|
83
|
+
options.delivery ?? "steer",
|
|
84
|
+
this.client.signal(options.signal)
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
receive(options = {}) {
|
|
89
|
+
return this.receiveInternal(options, false);
|
|
90
|
+
}
|
|
91
|
+
receiveInternal(options, untilIdle) {
|
|
92
|
+
return this.client.callAgent(
|
|
93
|
+
() => this.transport.receive(
|
|
94
|
+
this.target(),
|
|
95
|
+
receiveStart(options),
|
|
96
|
+
this.client.signal(options.signal),
|
|
97
|
+
untilIdle
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
compact(options = {}) {
|
|
102
|
+
return this.client.callAgent(
|
|
103
|
+
() => this.transport.compact(this.target(), this.client.signal(options.signal))
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
destroy(options = {}) {
|
|
107
|
+
return this.client.callAgent(
|
|
108
|
+
() => this.transport.destroy(this.target(), this.client.signal(options.signal))
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
target() {
|
|
112
|
+
return { name: this.name, expectedAgentId: this.id };
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
function receiveStart(options) {
|
|
116
|
+
if ("after" in options && options.after !== void 0) {
|
|
117
|
+
return { kind: "after", cursor: options.after };
|
|
118
|
+
}
|
|
119
|
+
if ("fromStart" in options && options.fromStart === true) return { kind: "start" };
|
|
120
|
+
return { kind: "live" };
|
|
121
|
+
}
|
|
122
|
+
var PiFleetError = class _PiFleetError extends Error {
|
|
123
|
+
constructor(code, message, details) {
|
|
124
|
+
super(message);
|
|
125
|
+
this.code = code;
|
|
126
|
+
this.details = details;
|
|
127
|
+
this.name = "PiFleetError";
|
|
128
|
+
}
|
|
129
|
+
static from(error) {
|
|
130
|
+
if (error instanceof _PiFleetError) return error;
|
|
131
|
+
return new _PiFleetError("internal_error", "pi-fleet client operation failed");
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/client/shared-client.ts
|
|
136
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
137
|
+
|
|
138
|
+
// src/pi/external-installation.ts
|
|
139
|
+
import { spawn } from "node:child_process";
|
|
140
|
+
import { createHash } from "node:crypto";
|
|
141
|
+
import { constants } from "node:fs";
|
|
142
|
+
import { createReadStream } from "node:fs";
|
|
143
|
+
import { access, realpath, stat } from "node:fs/promises";
|
|
144
|
+
import { delimiter, dirname, isAbsolute, join } from "node:path";
|
|
145
|
+
var VERSION_TIMEOUT_MS = 3e3;
|
|
146
|
+
var MAX_VERSION_OUTPUT_BYTES = 4 * 1024;
|
|
147
|
+
var ExternalPiResolutionError = class extends Error {
|
|
148
|
+
constructor(code, message) {
|
|
149
|
+
super(message);
|
|
150
|
+
this.code = code;
|
|
151
|
+
this.name = "ExternalPiResolutionError";
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
function installationIdentity(installation) {
|
|
155
|
+
return {
|
|
156
|
+
mode: "external",
|
|
157
|
+
selectedPath: installation.selectedPath,
|
|
158
|
+
nodePath: installation.nodePath,
|
|
159
|
+
realPath: installation.realPath,
|
|
160
|
+
version: installation.version,
|
|
161
|
+
fingerprint: installation.fingerprint
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
async function resolveExternalPiInstallation(options = {}) {
|
|
165
|
+
const env = options.env ?? process.env;
|
|
166
|
+
const selectedPath = await resolveSelectedPath(env);
|
|
167
|
+
const nodePath = options.nodePath ?? await resolveNodePath(env);
|
|
168
|
+
await inspectNode(nodePath);
|
|
169
|
+
const executionEnv = externalPiExecutionEnvironment(env, selectedPath, nodePath);
|
|
170
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
171
|
+
const observation = await observeInstallation(selectedPath, executionEnv, options);
|
|
172
|
+
if (observation !== null) {
|
|
173
|
+
return {
|
|
174
|
+
selectedPath,
|
|
175
|
+
nodePath,
|
|
176
|
+
...observation
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
throw new ExternalPiResolutionError(
|
|
181
|
+
"pi_installation_changed",
|
|
182
|
+
"Pi changed while its installation was being observed."
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
function externalPiExecutionEnvironment(env, selectedPath, nodePath) {
|
|
186
|
+
return {
|
|
187
|
+
...env,
|
|
188
|
+
PATH: [dirname(nodePath), dirname(selectedPath), env.PATH].filter((value) => value !== void 0 && value.length > 0).join(delimiter)
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
async function observeInstallation(selectedPath, env, options) {
|
|
192
|
+
const beforeRealPath = await inspectExecutable(selectedPath, "Pi");
|
|
193
|
+
const beforeHash = await hashFile(beforeRealPath);
|
|
194
|
+
const versionOutput = await (options.versionCommand ?? ((executable) => readVersion(executable, env, options.versionTimeoutMs, options.maxVersionOutputBytes)))(selectedPath);
|
|
195
|
+
const version = parseVersion(versionOutput);
|
|
196
|
+
const afterRealPath = await inspectExecutable(selectedPath, "Pi");
|
|
197
|
+
const afterHash = await hashFile(afterRealPath);
|
|
198
|
+
if (beforeRealPath !== afterRealPath || beforeHash !== afterHash) return null;
|
|
199
|
+
return {
|
|
200
|
+
realPath: afterRealPath,
|
|
201
|
+
version,
|
|
202
|
+
fingerprint: createHash("sha256").update(JSON.stringify([selectedPath, afterRealPath, version, afterHash])).digest("hex")
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
async function resolveSelectedPath(env) {
|
|
206
|
+
const explicit = env.PIFLEET_PI_EXECUTABLE;
|
|
207
|
+
if (explicit !== void 0) {
|
|
208
|
+
if (!isAbsolute(explicit)) {
|
|
209
|
+
throw new ExternalPiResolutionError(
|
|
210
|
+
"invalid_arguments",
|
|
211
|
+
"PIFLEET_PI_EXECUTABLE must be an absolute path."
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
return explicit;
|
|
215
|
+
}
|
|
216
|
+
return resolvePathExecutable(env, "pi", "Pi", "pi_not_found");
|
|
217
|
+
}
|
|
218
|
+
async function resolveNodePath(env) {
|
|
219
|
+
return resolvePathExecutable(env, "node", "Node", "pi_not_executable");
|
|
220
|
+
}
|
|
221
|
+
async function resolvePathExecutable(env, name, label, missingCode) {
|
|
222
|
+
const path = env.PATH;
|
|
223
|
+
if (path === void 0 || path.length === 0) {
|
|
224
|
+
throw new ExternalPiResolutionError(missingCode, `${label} was not found on PATH.`);
|
|
225
|
+
}
|
|
226
|
+
for (const directory of path.split(delimiter)) {
|
|
227
|
+
if (!isAbsolute(directory)) {
|
|
228
|
+
throw new ExternalPiResolutionError(
|
|
229
|
+
"invalid_arguments",
|
|
230
|
+
`PATH entries used to select ${label} must be absolute paths.`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const candidate = join(directory, name);
|
|
234
|
+
try {
|
|
235
|
+
await inspectExecutable(candidate, label);
|
|
236
|
+
return candidate;
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (!(error instanceof ExternalPiResolutionError) || error.code !== "pi_not_executable" && error.code !== "pi_not_found") {
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
throw new ExternalPiResolutionError(missingCode, `${label} was not found on PATH.`);
|
|
244
|
+
}
|
|
245
|
+
async function inspectExecutable(path, label) {
|
|
246
|
+
try {
|
|
247
|
+
const target = await realpath(path);
|
|
248
|
+
const metadata = await stat(target);
|
|
249
|
+
if (!metadata.isFile()) {
|
|
250
|
+
throw new ExternalPiResolutionError("pi_not_executable", `${label} is not a file: ${path}`);
|
|
251
|
+
}
|
|
252
|
+
await access(path, constants.X_OK);
|
|
253
|
+
return target;
|
|
254
|
+
} catch (error) {
|
|
255
|
+
if (error instanceof ExternalPiResolutionError) throw error;
|
|
256
|
+
if (error.code === "ENOENT") {
|
|
257
|
+
throw new ExternalPiResolutionError("pi_not_found", `${label} was not found: ${path}`);
|
|
258
|
+
}
|
|
259
|
+
throw new ExternalPiResolutionError("pi_not_executable", `${label} is not executable: ${path}`);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
async function inspectNode(nodePath) {
|
|
263
|
+
if (!isAbsolute(nodePath)) {
|
|
264
|
+
throw new ExternalPiResolutionError("invalid_arguments", "Node must be an absolute path.");
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
await inspectExecutable(nodePath, "Node");
|
|
268
|
+
} catch {
|
|
269
|
+
throw new ExternalPiResolutionError("pi_not_executable", `Node is not executable: ${nodePath}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async function hashFile(path) {
|
|
273
|
+
const hash = createHash("sha256");
|
|
274
|
+
await new Promise((resolveHash, rejectHash) => {
|
|
275
|
+
const stream = createReadStream(path);
|
|
276
|
+
stream.on("data", (chunk) => hash.update(chunk));
|
|
277
|
+
stream.once("error", rejectHash);
|
|
278
|
+
stream.once("end", resolveHash);
|
|
279
|
+
});
|
|
280
|
+
return hash.digest("hex");
|
|
281
|
+
}
|
|
282
|
+
async function readVersion(executable, env, timeoutMs = VERSION_TIMEOUT_MS, maxOutputBytes = MAX_VERSION_OUTPUT_BYTES) {
|
|
283
|
+
const child = spawn(executable, ["--version"], {
|
|
284
|
+
detached: process.platform !== "win32",
|
|
285
|
+
env,
|
|
286
|
+
shell: false,
|
|
287
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
288
|
+
});
|
|
289
|
+
const chunks = [];
|
|
290
|
+
let outputBytes = 0;
|
|
291
|
+
let terminalError = null;
|
|
292
|
+
let terminated = false;
|
|
293
|
+
const terminate = () => {
|
|
294
|
+
if (terminated) return;
|
|
295
|
+
terminated = true;
|
|
296
|
+
if (process.platform !== "win32" && child.pid !== void 0) {
|
|
297
|
+
try {
|
|
298
|
+
process.kill(-child.pid, "SIGKILL");
|
|
299
|
+
return;
|
|
300
|
+
} catch {
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
child.kill("SIGKILL");
|
|
304
|
+
};
|
|
305
|
+
child.stdout.on("data", (chunk) => {
|
|
306
|
+
if (terminalError !== null) return;
|
|
307
|
+
outputBytes += chunk.byteLength;
|
|
308
|
+
if (outputBytes > maxOutputBytes) {
|
|
309
|
+
terminalError = new ExternalPiResolutionError(
|
|
310
|
+
"pi_version_unavailable",
|
|
311
|
+
"Pi version output exceeded its limit."
|
|
312
|
+
);
|
|
313
|
+
terminate();
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
chunks.push(chunk);
|
|
317
|
+
});
|
|
318
|
+
child.stderr.resume();
|
|
319
|
+
return new Promise((resolveVersion, rejectVersion) => {
|
|
320
|
+
const timer = setTimeout(() => {
|
|
321
|
+
terminalError = new ExternalPiResolutionError(
|
|
322
|
+
"pi_version_unavailable",
|
|
323
|
+
"Pi version command timed out."
|
|
324
|
+
);
|
|
325
|
+
terminate();
|
|
326
|
+
}, timeoutMs);
|
|
327
|
+
child.once("error", () => {
|
|
328
|
+
terminalError ??= new ExternalPiResolutionError(
|
|
329
|
+
"pi_version_unavailable",
|
|
330
|
+
"Pi version command failed."
|
|
331
|
+
);
|
|
332
|
+
});
|
|
333
|
+
child.once("close", (code) => {
|
|
334
|
+
clearTimeout(timer);
|
|
335
|
+
if (terminalError !== null) {
|
|
336
|
+
rejectVersion(terminalError);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
if (code !== 0) {
|
|
340
|
+
rejectVersion(
|
|
341
|
+
new ExternalPiResolutionError("pi_version_unavailable", "Pi version command failed.")
|
|
342
|
+
);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
try {
|
|
346
|
+
resolveVersion(new TextDecoder("utf-8", { fatal: true }).decode(Buffer.concat(chunks)));
|
|
347
|
+
} catch {
|
|
348
|
+
rejectVersion(
|
|
349
|
+
new ExternalPiResolutionError(
|
|
350
|
+
"pi_version_unavailable",
|
|
351
|
+
"Pi version command returned invalid UTF-8."
|
|
352
|
+
)
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
function parseVersion(output) {
|
|
359
|
+
const match = /^(?:pi\s+)?(\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)\s*$/i.exec(output);
|
|
360
|
+
if (match?.[1] === void 0) {
|
|
361
|
+
throw new ExternalPiResolutionError(
|
|
362
|
+
"pi_version_unavailable",
|
|
363
|
+
"Pi version command returned an invalid version."
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
return match[1];
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// src/platform/client/start-runtime.ts
|
|
370
|
+
import { execFile, spawn as spawn2 } from "node:child_process";
|
|
371
|
+
import { access as access2, readFile as readFile3 } from "node:fs/promises";
|
|
372
|
+
import { homedir as homedir2 } from "node:os";
|
|
373
|
+
import { dirname as dirname2, join as join5, resolve as resolve4 } from "node:path";
|
|
374
|
+
import { fileURLToPath } from "node:url";
|
|
375
|
+
import { promisify } from "node:util";
|
|
376
|
+
|
|
377
|
+
// src/platform/shared/runtime-ownership.ts
|
|
378
|
+
import { lstat } from "node:fs/promises";
|
|
379
|
+
import { createConnection } from "node:net";
|
|
380
|
+
var RuntimeOwnershipBlockedError = class extends Error {
|
|
381
|
+
code = "runtime_upgrade_deferred";
|
|
382
|
+
constructor(message) {
|
|
383
|
+
super(message);
|
|
384
|
+
this.name = "RuntimeOwnershipBlockedError";
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
async function inspectControlSocketOwnership(socketPath, probe = probeControlSocket) {
|
|
388
|
+
const stats = await lstat(socketPath).catch((error) => {
|
|
389
|
+
if (error.code === "ENOENT") return null;
|
|
390
|
+
throw error;
|
|
391
|
+
});
|
|
392
|
+
if (stats === null) return "absent";
|
|
393
|
+
if (!stats.isSocket()) {
|
|
394
|
+
throw new RuntimeOwnershipBlockedError(
|
|
395
|
+
`Refusing to replace non-socket pi-fleet control path ${socketPath}`
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
return probe(socketPath);
|
|
399
|
+
}
|
|
400
|
+
function probeControlSocket(socketPath) {
|
|
401
|
+
return new Promise((resolveProbe) => {
|
|
402
|
+
const socket = createConnection(socketPath);
|
|
403
|
+
let settled = false;
|
|
404
|
+
const settle = (result) => {
|
|
405
|
+
if (settled) return;
|
|
406
|
+
settled = true;
|
|
407
|
+
clearTimeout(timer);
|
|
408
|
+
socket.destroy();
|
|
409
|
+
resolveProbe(result);
|
|
410
|
+
};
|
|
411
|
+
const timer = setTimeout(() => settle("uncertain"), 200);
|
|
412
|
+
socket.once("connect", () => settle("responsive"));
|
|
413
|
+
socket.once("error", (error) => {
|
|
414
|
+
settle(error.code === "ECONNREFUSED" || error.code === "ENOENT" ? "stale" : "uncertain");
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
// src/platform/install/runtime-release.ts
|
|
420
|
+
import { createHash as createHash3, randomUUID } from "node:crypto";
|
|
421
|
+
import { chmod, cp, lstat as lstat3, mkdir, readFile as readFile2, rename, rm, writeFile } from "node:fs/promises";
|
|
422
|
+
import { join as join3, posix, resolve as resolve2, sep as sep2 } from "node:path";
|
|
423
|
+
|
|
424
|
+
// src/platform/install/tree-integrity.ts
|
|
425
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
426
|
+
import { lstat as lstat2, readFile, readdir, realpath as realpath2, stat as stat2 } from "node:fs/promises";
|
|
427
|
+
import { join as join2, relative, resolve, sep } from "node:path";
|
|
428
|
+
async function hashDirectoryTree(root, manifestPath) {
|
|
429
|
+
const resolvedRoot = resolve(root);
|
|
430
|
+
const entries = await collectFiles(resolvedRoot, resolvedRoot);
|
|
431
|
+
const hash = createHash2("sha256");
|
|
432
|
+
let bytes = 0;
|
|
433
|
+
for (const entry of entries) {
|
|
434
|
+
const contents = await readFile(entry.absolutePath);
|
|
435
|
+
bytes += contents.length;
|
|
436
|
+
hash.update(entry.relativePath);
|
|
437
|
+
hash.update("\0");
|
|
438
|
+
hash.update(String(contents.length));
|
|
439
|
+
hash.update("\0");
|
|
440
|
+
hash.update(contents);
|
|
441
|
+
hash.update("\0");
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
path: manifestPath,
|
|
445
|
+
files: entries.length,
|
|
446
|
+
bytes,
|
|
447
|
+
sha256: hash.digest("hex")
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
async function collectFiles(root, directory) {
|
|
451
|
+
const output = [];
|
|
452
|
+
for (const name of (await readdir(directory)).sort()) {
|
|
453
|
+
const absolutePath = join2(directory, name);
|
|
454
|
+
const linkInfo = await lstat2(absolutePath);
|
|
455
|
+
const info = linkInfo.isSymbolicLink() ? await stat2(absolutePath) : linkInfo;
|
|
456
|
+
if (info.isDirectory()) {
|
|
457
|
+
if (linkInfo.isSymbolicLink()) {
|
|
458
|
+
throw new Error(`Runtime dependency tree contains a directory symlink: ${absolutePath}`);
|
|
459
|
+
}
|
|
460
|
+
output.push(...await collectFiles(root, absolutePath));
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
if (!info.isFile()) {
|
|
464
|
+
throw new Error(`Runtime dependency tree contains an unsupported entry: ${absolutePath}`);
|
|
465
|
+
}
|
|
466
|
+
if (linkInfo.isSymbolicLink()) {
|
|
467
|
+
const target = await realpath2(absolutePath);
|
|
468
|
+
if (target !== root && !target.startsWith(`${root}${sep}`)) {
|
|
469
|
+
throw new Error(
|
|
470
|
+
`Runtime dependency tree contains an external file symlink: ${absolutePath}`
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const relativePath = relative(root, absolutePath).split(sep).join("/");
|
|
475
|
+
if (relativePath.length === 0 || relativePath.startsWith("../")) {
|
|
476
|
+
throw new Error(`Runtime dependency path escapes its root: ${absolutePath}`);
|
|
477
|
+
}
|
|
478
|
+
output.push({ absolutePath, relativePath });
|
|
479
|
+
}
|
|
480
|
+
return output.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// src/platform/install/runtime-release.ts
|
|
484
|
+
var requiredRuntimeArtifacts = /* @__PURE__ */ new Set([
|
|
485
|
+
"package.json",
|
|
486
|
+
"bin/pifleet.mjs",
|
|
487
|
+
"bin/pifleet-runtime.mjs",
|
|
488
|
+
"dist/cli.mjs",
|
|
489
|
+
"dist/runtime.mjs",
|
|
490
|
+
"dist/journal-sqlite-worker.mjs",
|
|
491
|
+
"dist/client.mjs",
|
|
492
|
+
"dist/client-meta.json",
|
|
493
|
+
"dist/client/index.d.ts",
|
|
494
|
+
"dist/client/sdk-facade.d.ts",
|
|
495
|
+
"dist/client/contracts.d.ts"
|
|
496
|
+
]);
|
|
497
|
+
var dependencyTreePath = "node_modules";
|
|
498
|
+
async function materializeRuntime(options) {
|
|
499
|
+
const sourceRoot = resolve2(options.sourceRoot);
|
|
500
|
+
const manifestBytes = await readFile2(join3(sourceRoot, "dist", "runtime-manifest.json"));
|
|
501
|
+
const sourceManifest = await parseRuntimeManifest(manifestBytes, sourceRoot);
|
|
502
|
+
if (sourceManifest.closure !== void 0) {
|
|
503
|
+
await verifyRuntime(sourceRoot);
|
|
504
|
+
return sourceRoot;
|
|
505
|
+
}
|
|
506
|
+
await verifyRuntimeFiles(sourceRoot, sourceManifest);
|
|
507
|
+
await verifyDependencyIdentities(sourceRoot, sourceManifest.dependencies);
|
|
508
|
+
const sourceTreeRoot = resolveInside(sourceRoot, dependencyTreePath);
|
|
509
|
+
const sourceTreeBefore = await hashDirectoryTree(sourceTreeRoot, dependencyTreePath);
|
|
510
|
+
const sourceManifestSha256 = createHash3("sha256").update(manifestBytes).digest("hex");
|
|
511
|
+
const materializedManifest = {
|
|
512
|
+
...sourceManifest,
|
|
513
|
+
closure: { sourceManifestSha256, tree: sourceTreeBefore }
|
|
514
|
+
};
|
|
515
|
+
const materializedManifestBytes = serializeManifest(materializedManifest);
|
|
516
|
+
const closureHash = createHash3("sha256").update(sourceManifestSha256).update("\0").update(JSON.stringify(sourceTreeBefore)).digest("hex").slice(0, 16);
|
|
517
|
+
const applicationRoot = resolve2(options.applicationRoot);
|
|
518
|
+
await ensurePrivateDirectory(applicationRoot);
|
|
519
|
+
const releasesRoot = join3(applicationRoot, "releases");
|
|
520
|
+
await ensurePrivateDirectory(releasesRoot);
|
|
521
|
+
const destination = join3(releasesRoot, `${sourceManifest.package.version}-${closureHash}`);
|
|
522
|
+
if (await pathExists(destination)) {
|
|
523
|
+
await verifyExpectedRuntime(destination, materializedManifest, materializedManifestBytes);
|
|
524
|
+
return destination;
|
|
525
|
+
}
|
|
526
|
+
const staging = join3(releasesRoot, `.staging-${randomUUID()}`);
|
|
527
|
+
await mkdir(staging, { mode: 448 });
|
|
528
|
+
try {
|
|
529
|
+
await cp(join3(sourceRoot, "dist"), join3(staging, "dist"), {
|
|
530
|
+
recursive: true,
|
|
531
|
+
dereference: true
|
|
532
|
+
});
|
|
533
|
+
await cp(join3(sourceRoot, "bin"), join3(staging, "bin"), {
|
|
534
|
+
recursive: true,
|
|
535
|
+
dereference: true
|
|
536
|
+
});
|
|
537
|
+
await cp(join3(sourceRoot, "package.json"), join3(staging, "package.json"));
|
|
538
|
+
await cp(sourceTreeRoot, join3(staging, dependencyTreePath), {
|
|
539
|
+
recursive: true,
|
|
540
|
+
dereference: true
|
|
541
|
+
});
|
|
542
|
+
await options.hooks?.afterDependencyCopy?.();
|
|
543
|
+
const stagedTree = await hashDirectoryTree(
|
|
544
|
+
join3(staging, dependencyTreePath),
|
|
545
|
+
dependencyTreePath
|
|
546
|
+
);
|
|
547
|
+
assertSameTree(sourceTreeBefore, stagedTree, "copied dependency closure");
|
|
548
|
+
const sourceTreeAfter = await hashDirectoryTree(sourceTreeRoot, dependencyTreePath);
|
|
549
|
+
assertSameTree(sourceTreeBefore, sourceTreeAfter, "source dependency closure");
|
|
550
|
+
await writeFile(join3(staging, "dist", "runtime-manifest.json"), materializedManifestBytes);
|
|
551
|
+
await verifyExpectedRuntime(staging, materializedManifest, materializedManifestBytes);
|
|
552
|
+
await chmod(staging, 448);
|
|
553
|
+
try {
|
|
554
|
+
await rename(staging, destination);
|
|
555
|
+
} catch (error) {
|
|
556
|
+
if (!isDestinationRace(error) || !await pathExists(destination)) throw error;
|
|
557
|
+
await verifyExpectedRuntime(destination, materializedManifest, materializedManifestBytes);
|
|
558
|
+
}
|
|
559
|
+
return destination;
|
|
560
|
+
} finally {
|
|
561
|
+
await rm(staging, { recursive: true, force: true });
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
async function verifyRuntime(root) {
|
|
565
|
+
const resolvedRoot = resolve2(root);
|
|
566
|
+
const manifestBytes = await readFile2(join3(resolvedRoot, "dist", "runtime-manifest.json"));
|
|
567
|
+
const manifest = await parseRuntimeManifest(manifestBytes, resolvedRoot);
|
|
568
|
+
if (manifest.closure === void 0) {
|
|
569
|
+
throw new Error("Runtime release manifest is missing its materialized closure");
|
|
570
|
+
}
|
|
571
|
+
await verifyRuntimeFiles(resolvedRoot, manifest);
|
|
572
|
+
await verifyDependencyIdentities(resolvedRoot, manifest.dependencies);
|
|
573
|
+
const actualTree = await hashDirectoryTree(
|
|
574
|
+
resolveInside(resolvedRoot, dependencyTreePath),
|
|
575
|
+
dependencyTreePath
|
|
576
|
+
);
|
|
577
|
+
assertSameTree(manifest.closure.tree, actualTree, "materialized dependency closure");
|
|
578
|
+
}
|
|
579
|
+
async function verifyExpectedRuntime(root, expected, expectedBytes) {
|
|
580
|
+
const manifestPath = join3(root, "dist", "runtime-manifest.json");
|
|
581
|
+
const actualBytes = await readFile2(manifestPath);
|
|
582
|
+
if (!actualBytes.equals(expectedBytes)) {
|
|
583
|
+
throw new Error("Materialized runtime manifest does not match the expected closure");
|
|
584
|
+
}
|
|
585
|
+
const actual = await parseRuntimeManifest(actualBytes, root);
|
|
586
|
+
if (actual.closure === void 0 || expected.closure === void 0) {
|
|
587
|
+
throw new Error("Materialized runtime manifest is missing its closure");
|
|
588
|
+
}
|
|
589
|
+
await verifyRuntimeFiles(root, actual);
|
|
590
|
+
await verifyDependencyIdentities(root, actual.dependencies);
|
|
591
|
+
const actualTree = await hashDirectoryTree(
|
|
592
|
+
resolveInside(root, dependencyTreePath),
|
|
593
|
+
dependencyTreePath
|
|
594
|
+
);
|
|
595
|
+
assertSameTree(expected.closure.tree, actualTree, "materialized dependency closure");
|
|
596
|
+
}
|
|
597
|
+
async function verifyRuntimeFiles(root, manifest) {
|
|
598
|
+
for (const file of manifest.files) {
|
|
599
|
+
const path = resolveInside(root, file.path);
|
|
600
|
+
const info = await lstat3(path);
|
|
601
|
+
if (info.isSymbolicLink()) {
|
|
602
|
+
throw new Error(`Runtime artifact ${file.path} must not be a symbolic link`);
|
|
603
|
+
}
|
|
604
|
+
if (!info.isFile() || info.size !== file.bytes) {
|
|
605
|
+
throw new Error(`Runtime artifact ${file.path} has changed`);
|
|
606
|
+
}
|
|
607
|
+
const hash = createHash3("sha256").update(await readFile2(path)).digest("hex");
|
|
608
|
+
if (hash !== file.sha256) {
|
|
609
|
+
throw new Error(`Runtime artifact ${file.path} failed verification`);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
async function verifyDependencyIdentities(root, dependencies) {
|
|
614
|
+
const nodeModules = resolveInside(root, dependencyTreePath);
|
|
615
|
+
const modulesInfo = await lstat3(nodeModules);
|
|
616
|
+
if (!modulesInfo.isDirectory() || modulesInfo.isSymbolicLink()) {
|
|
617
|
+
throw new Error("Runtime dependency closure must be a regular directory");
|
|
618
|
+
}
|
|
619
|
+
for (const dependency of dependencies) {
|
|
620
|
+
const packageRoot = resolveInside(root, dependency.path);
|
|
621
|
+
const packageInfo = await lstat3(packageRoot);
|
|
622
|
+
if (!packageInfo.isDirectory() || packageInfo.isSymbolicLink()) {
|
|
623
|
+
throw new Error(`Runtime dependency ${dependency.name} must be a regular directory`);
|
|
624
|
+
}
|
|
625
|
+
const packageJsonPath = join3(packageRoot, "package.json");
|
|
626
|
+
const packageJsonInfo = await lstat3(packageJsonPath);
|
|
627
|
+
if (!packageJsonInfo.isFile() || packageJsonInfo.isSymbolicLink()) {
|
|
628
|
+
throw new Error(`Runtime dependency ${dependency.name} has an unsafe package.json`);
|
|
629
|
+
}
|
|
630
|
+
const identity = await readPackageMetadata(packageRoot);
|
|
631
|
+
if (identity.name !== dependency.name || identity.version !== dependency.version) {
|
|
632
|
+
throw new Error(`Runtime dependency ${dependency.name} has an unexpected identity`);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
async function parseRuntimeManifest(bytes, root) {
|
|
637
|
+
let candidate;
|
|
638
|
+
try {
|
|
639
|
+
candidate = JSON.parse(bytes.toString("utf8"));
|
|
640
|
+
} catch {
|
|
641
|
+
throw new Error("Runtime manifest is not valid JSON");
|
|
642
|
+
}
|
|
643
|
+
await validateRuntimeManifest(candidate, root);
|
|
644
|
+
return candidate;
|
|
645
|
+
}
|
|
646
|
+
async function validateRuntimeManifest(candidate, root) {
|
|
647
|
+
if (!isRecord(candidate) || candidate.schemaVersion !== 4) {
|
|
648
|
+
throw new Error("Runtime manifest has an unsupported schema version");
|
|
649
|
+
}
|
|
650
|
+
if (!isRecord(candidate.package) || typeof candidate.package.name !== "string" || typeof candidate.package.version !== "string" || !isRecord(candidate.piRuntime) || candidate.piRuntime.mode !== "external" || !isRuntimeContract(candidate.runtime)) {
|
|
651
|
+
throw new Error("Runtime manifest has an invalid package identity");
|
|
652
|
+
}
|
|
653
|
+
const packageMetadata = await readPackageMetadata(root, true);
|
|
654
|
+
if (candidate.package.name !== packageMetadata.name || candidate.package.version !== packageMetadata.version || packageMetadata.runtime === void 0 || !sameRuntimeContract(candidate.runtime, packageMetadata.runtime) || packageMetadata.clientExport === void 0) {
|
|
655
|
+
throw new Error("Runtime manifest package identity does not match package.json");
|
|
656
|
+
}
|
|
657
|
+
if (!Array.isArray(candidate.files) || !Array.isArray(candidate.dependencies)) {
|
|
658
|
+
throw new Error("Runtime manifest has invalid artifact lists");
|
|
659
|
+
}
|
|
660
|
+
const filePaths = /* @__PURE__ */ new Set();
|
|
661
|
+
for (const file of candidate.files) {
|
|
662
|
+
if (!isRecord(file) || !isManifestPath(file.path) || !isValidSize(file.bytes) || !isSha256(file.sha256)) {
|
|
663
|
+
throw new Error("Runtime manifest contains an invalid artifact");
|
|
664
|
+
}
|
|
665
|
+
if (filePaths.has(file.path)) {
|
|
666
|
+
throw new Error(`Runtime manifest has duplicate path ${file.path}`);
|
|
667
|
+
}
|
|
668
|
+
filePaths.add(file.path);
|
|
669
|
+
}
|
|
670
|
+
for (const required of requiredRuntimeArtifacts) {
|
|
671
|
+
if (!filePaths.has(required)) {
|
|
672
|
+
throw new Error(`Runtime manifest is missing required artifact ${required}`);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
const dependencyPaths = /* @__PURE__ */ new Set();
|
|
676
|
+
const dependencyNames = /* @__PURE__ */ new Set();
|
|
677
|
+
for (const dependency of candidate.dependencies) {
|
|
678
|
+
if (!isRecord(dependency) || !isManifestPath(dependency.path) || typeof dependency.name !== "string" || dependency.name.length === 0 || typeof dependency.version !== "string" || dependency.version.length === 0 || dependency.path !== `node_modules/${dependency.name}`) {
|
|
679
|
+
throw new Error("Runtime manifest contains an invalid dependency declaration");
|
|
680
|
+
}
|
|
681
|
+
if (dependencyPaths.has(dependency.path) || dependencyNames.has(dependency.name)) {
|
|
682
|
+
throw new Error(`Runtime manifest has duplicate dependency ${dependency.name}`);
|
|
683
|
+
}
|
|
684
|
+
dependencyPaths.add(dependency.path);
|
|
685
|
+
dependencyNames.add(dependency.name);
|
|
686
|
+
}
|
|
687
|
+
const expectedDependencies = packageMetadata.dependencies;
|
|
688
|
+
if (dependencyNames.size !== Object.keys(expectedDependencies).length || [...dependencyNames].some(
|
|
689
|
+
(name) => expectedDependencies[name] !== candidate.dependencies.find(
|
|
690
|
+
(dependency) => dependency.name === name
|
|
691
|
+
)?.version
|
|
692
|
+
)) {
|
|
693
|
+
throw new Error("Runtime manifest dependencies do not match package.json");
|
|
694
|
+
}
|
|
695
|
+
for (const filePath of filePaths) {
|
|
696
|
+
for (const dependencyPath of dependencyPaths) {
|
|
697
|
+
if (filePath === dependencyPath || filePath.startsWith(`${dependencyPath}/`) || dependencyPath.startsWith(`${filePath}/`)) {
|
|
698
|
+
throw new Error(`Runtime manifest has overlapping paths ${filePath} and ${dependencyPath}`);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
if (candidate.closure !== void 0) {
|
|
703
|
+
if (!isRecord(candidate.closure) || !isSha256(candidate.closure.sourceManifestSha256) || !isTreeIntegrity(candidate.closure.tree) || candidate.closure.tree.path !== dependencyTreePath) {
|
|
704
|
+
throw new Error("Runtime manifest contains an invalid materialized closure");
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
async function readPackageMetadata(root, requireRuntimeContract = false) {
|
|
709
|
+
let candidate;
|
|
710
|
+
try {
|
|
711
|
+
candidate = JSON.parse(await readFile2(join3(root, "package.json"), "utf8"));
|
|
712
|
+
} catch {
|
|
713
|
+
throw new Error("Runtime package.json is not valid JSON");
|
|
714
|
+
}
|
|
715
|
+
if (!isRecord(candidate) || typeof candidate.name !== "string" || typeof candidate.version !== "string" || requireRuntimeContract && !isRuntimeContract(candidate.pifleet) || candidate.dependencies !== void 0 && !isRecord(candidate.dependencies) || isRecord(candidate.dependencies) && Object.values(candidate.dependencies).some((version) => typeof version !== "string")) {
|
|
716
|
+
throw new Error("Runtime package.json has invalid package metadata");
|
|
717
|
+
}
|
|
718
|
+
const clientExport = isRecord(candidate.exports) ? candidate.exports["./client"] : void 0;
|
|
719
|
+
return {
|
|
720
|
+
name: candidate.name,
|
|
721
|
+
version: candidate.version,
|
|
722
|
+
...isRuntimeContract(candidate.pifleet) ? { runtime: candidate.pifleet } : {},
|
|
723
|
+
...isRecord(clientExport) && clientExport.types === "./dist/client/index.d.ts" && clientExport.import === "./dist/client.mjs" ? {
|
|
724
|
+
clientExport: {
|
|
725
|
+
types: "./dist/client/index.d.ts",
|
|
726
|
+
import: "./dist/client.mjs"
|
|
727
|
+
}
|
|
728
|
+
} : {},
|
|
729
|
+
dependencies: isRecord(candidate.dependencies) ? candidate.dependencies : {}
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
function serializeManifest(manifest) {
|
|
733
|
+
return Buffer.from(`${JSON.stringify(manifest, null, 2)}
|
|
734
|
+
`);
|
|
735
|
+
}
|
|
736
|
+
function assertSameTree(expected, actual, label) {
|
|
737
|
+
if (expected.path !== actual.path || expected.files !== actual.files || expected.bytes !== actual.bytes || expected.sha256 !== actual.sha256) {
|
|
738
|
+
throw new Error(`Runtime ${label} changed during materialization`);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
function resolveInside(root, path) {
|
|
742
|
+
if (!isManifestPath(path)) throw new Error(`Runtime manifest contains an unsafe path ${path}`);
|
|
743
|
+
const resolved = resolve2(root, path);
|
|
744
|
+
if (!resolved.startsWith(`${root}${sep2}`)) {
|
|
745
|
+
throw new Error(`Runtime manifest contains an unsafe path ${path}`);
|
|
746
|
+
}
|
|
747
|
+
return resolved;
|
|
748
|
+
}
|
|
749
|
+
function isRecord(value) {
|
|
750
|
+
return typeof value === "object" && value !== null;
|
|
751
|
+
}
|
|
752
|
+
function isRuntimeContract(value) {
|
|
753
|
+
return isRecord(value) && value.protocolVersion === 3 && value.journalSchemaVersion === 3 && value.clientExport === "./client";
|
|
754
|
+
}
|
|
755
|
+
function sameRuntimeContract(left, right) {
|
|
756
|
+
return left.protocolVersion === right.protocolVersion && left.journalSchemaVersion === right.journalSchemaVersion && left.clientExport === right.clientExport;
|
|
757
|
+
}
|
|
758
|
+
function isManifestPath(value) {
|
|
759
|
+
return typeof value === "string" && value.length > 0 && !value.includes("\\") && !value.startsWith("/") && posix.normalize(value) === value && value.split("/").every((part) => part.length > 0 && part !== "." && part !== "..");
|
|
760
|
+
}
|
|
761
|
+
function isValidSize(value) {
|
|
762
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
763
|
+
}
|
|
764
|
+
function isSha256(value) {
|
|
765
|
+
return typeof value === "string" && /^[a-f0-9]{64}$/.test(value);
|
|
766
|
+
}
|
|
767
|
+
function isTreeIntegrity(value) {
|
|
768
|
+
return isRecord(value) && isManifestPath(value.path) && isValidSize(value.files) && isValidSize(value.bytes) && isSha256(value.sha256);
|
|
769
|
+
}
|
|
770
|
+
function isDestinationRace(error) {
|
|
771
|
+
const code = error.code;
|
|
772
|
+
return code === "EEXIST" || code === "ENOTEMPTY";
|
|
773
|
+
}
|
|
774
|
+
async function ensurePrivateDirectory(path) {
|
|
775
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
776
|
+
const info = await lstat3(path);
|
|
777
|
+
if (!info.isDirectory() || info.isSymbolicLink()) {
|
|
778
|
+
throw new Error(`Refusing unsafe runtime release path ${path}`);
|
|
779
|
+
}
|
|
780
|
+
if (typeof process.getuid === "function" && info.uid !== process.getuid()) {
|
|
781
|
+
throw new Error(`Runtime release path ${path} is not owned by the current user`);
|
|
782
|
+
}
|
|
783
|
+
await chmod(path, 448);
|
|
784
|
+
}
|
|
785
|
+
async function pathExists(path) {
|
|
786
|
+
try {
|
|
787
|
+
await lstat3(path);
|
|
788
|
+
return true;
|
|
789
|
+
} catch (error) {
|
|
790
|
+
if (error.code === "ENOENT") return false;
|
|
791
|
+
throw error;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// src/platform/shared/paths.ts
|
|
796
|
+
import { homedir, tmpdir } from "node:os";
|
|
797
|
+
import { join as join4, resolve as resolve3 } from "node:path";
|
|
798
|
+
function resolveApplicationRoot(env = process.env) {
|
|
799
|
+
return env.PIFLEET_APPLICATION_ROOT ?? (process.platform === "darwin" ? join4(homedir(), "Library", "Application Support", "pi-fleet", "runtime") : join4(env.XDG_DATA_HOME ?? join4(homedir(), ".local", "share"), "pi-fleet"));
|
|
800
|
+
}
|
|
801
|
+
function resolveFleetPaths(env = process.env) {
|
|
802
|
+
const explicitRoot = env.PIFLEET_STATE_ROOT;
|
|
803
|
+
if (explicitRoot !== void 0) {
|
|
804
|
+
const root = resolve3(explicitRoot);
|
|
805
|
+
return {
|
|
806
|
+
runtimeRoot: root,
|
|
807
|
+
stateRoot: root,
|
|
808
|
+
socketPath: join4(root, "control.sock"),
|
|
809
|
+
databasePath: join4(root, "fleet.sqlite")
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
const runtimeRoot = join4(
|
|
813
|
+
env.XDG_RUNTIME_DIR ?? tmpdir(),
|
|
814
|
+
`pifleet-${process.getuid?.() ?? "user"}`
|
|
815
|
+
);
|
|
816
|
+
const stateRoot = process.platform === "darwin" ? join4(homedir(), "Library", "Application Support", "pi-fleet") : join4(env.XDG_STATE_HOME ?? join4(homedir(), ".local", "state"), "pi-fleet");
|
|
817
|
+
return {
|
|
818
|
+
runtimeRoot,
|
|
819
|
+
stateRoot,
|
|
820
|
+
socketPath: join4(runtimeRoot, "control.sock"),
|
|
821
|
+
databasePath: join4(stateRoot, "fleet.sqlite")
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// src/platform/client/start-runtime.ts
|
|
826
|
+
var execFileAsync = promisify(execFile);
|
|
827
|
+
async function ensureRuntime(options) {
|
|
828
|
+
const inspectOwnership = options.inspectOwnership ?? inspectControlSocketOwnership;
|
|
829
|
+
const initialOwnership = await inspectOwnership(options.socketPath);
|
|
830
|
+
if (initialOwnership === "responsive") return;
|
|
831
|
+
assertRuntimeStartAllowed(initialOwnership, options.socketPath);
|
|
832
|
+
let env = { ...process.env, ...options.env };
|
|
833
|
+
const registered = env.PIFLEET_DISABLE_REGISTERED_SERVICE === "1" ? false : options.registeredRuntimeStarter !== void 0 ? await options.registeredRuntimeStarter(env) : await startRegisteredRuntime({
|
|
834
|
+
env,
|
|
835
|
+
...options.home === void 0 ? {} : { home: options.home }
|
|
836
|
+
});
|
|
837
|
+
if (!registered) {
|
|
838
|
+
if (options.piInstallation !== void 0) {
|
|
839
|
+
const installation = await options.piInstallation();
|
|
840
|
+
if (installation !== null) {
|
|
841
|
+
env = {
|
|
842
|
+
...env,
|
|
843
|
+
PIFLEET_PI_EXECUTABLE: installation.selectedPath,
|
|
844
|
+
PIFLEET_PI_NODE: installation.nodePath
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
const sourceRoot = options.sourceRoot ?? await findPackageRoot(fileURLToPath(import.meta.url));
|
|
849
|
+
const release = await materializeRuntime({
|
|
850
|
+
sourceRoot,
|
|
851
|
+
applicationRoot: options.applicationRoot ?? resolveApplicationRoot(env)
|
|
852
|
+
});
|
|
853
|
+
const runtimePath = join5(release, "bin", "pifleet-runtime.mjs");
|
|
854
|
+
const child = spawn2(process.execPath, [runtimePath], {
|
|
855
|
+
detached: true,
|
|
856
|
+
env,
|
|
857
|
+
stdio: "ignore"
|
|
858
|
+
});
|
|
859
|
+
child.unref();
|
|
860
|
+
}
|
|
861
|
+
const deadline = Date.now() + (options.timeoutMs ?? 5e3);
|
|
862
|
+
while (Date.now() < deadline) {
|
|
863
|
+
const ownership = await inspectOwnership(options.socketPath);
|
|
864
|
+
if (ownership === "responsive") return;
|
|
865
|
+
if (ownership === "uncertain") {
|
|
866
|
+
throw new RuntimeOwnershipBlockedError(
|
|
867
|
+
`pi-fleet control socket ownership is uncertain for ${options.socketPath}`
|
|
868
|
+
);
|
|
869
|
+
}
|
|
870
|
+
await new Promise((resolveDelay) => setTimeout(resolveDelay, 25));
|
|
871
|
+
}
|
|
872
|
+
throw new Error(`pi-fleet runtime did not become ready at ${options.socketPath}`);
|
|
873
|
+
}
|
|
874
|
+
function assertRuntimeStartAllowed(ownership, socketPath) {
|
|
875
|
+
if (ownership === "uncertain") {
|
|
876
|
+
throw new RuntimeOwnershipBlockedError(
|
|
877
|
+
`pi-fleet control socket ownership is uncertain for ${socketPath}`
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
async function startRegisteredRuntime(options) {
|
|
882
|
+
const home = options.home ?? homedir2();
|
|
883
|
+
if (process.platform === "linux") {
|
|
884
|
+
const unit = join5(home, ".config", "systemd", "user", "pi-fleet.service");
|
|
885
|
+
if (!await exists(unit)) return false;
|
|
886
|
+
await assertRegisteredStateRoot(unit, "linux", options.env);
|
|
887
|
+
await execFileAsync("systemctl", ["--user", "start", "pi-fleet.service"]);
|
|
888
|
+
return true;
|
|
889
|
+
}
|
|
890
|
+
if (process.platform === "darwin") {
|
|
891
|
+
const plist = join5(home, "Library", "LaunchAgents", "works.elpapi.pifleet.plist");
|
|
892
|
+
if (!await exists(plist)) return false;
|
|
893
|
+
await assertRegisteredStateRoot(plist, "darwin", options.env);
|
|
894
|
+
const domain = `gui/${process.getuid?.() ?? 0}`;
|
|
895
|
+
await execFileAsync("launchctl", ["kickstart", `${domain}/works.elpapi.pifleet`]);
|
|
896
|
+
return true;
|
|
897
|
+
}
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
function installedServiceStateRoot(contents, platform) {
|
|
901
|
+
const encoded = platform === "linux" ? /^Environment=PIFLEET_STATE_ROOT=(.+)$/m.exec(contents)?.[1] : /<key>PIFLEET_STATE_ROOT<\/key><string>([^<]+)<\/string>/.exec(contents)?.[1];
|
|
902
|
+
if (encoded === void 0) return void 0;
|
|
903
|
+
if (platform === "linux") return encoded;
|
|
904
|
+
return encoded.replaceAll("'", "'").replaceAll(""", '"').replaceAll(">", ">").replaceAll("<", "<").replaceAll("&", "&");
|
|
905
|
+
}
|
|
906
|
+
var PiServiceMismatchError = class extends Error {
|
|
907
|
+
code = "pi_service_mismatch";
|
|
908
|
+
constructor(message) {
|
|
909
|
+
super(message);
|
|
910
|
+
this.name = "PiServiceMismatchError";
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
async function assertRegisteredPiSelection(options) {
|
|
914
|
+
const home = options.home ?? homedir2();
|
|
915
|
+
const platform = process.platform;
|
|
916
|
+
if (platform !== "linux" && platform !== "darwin") return;
|
|
917
|
+
const path = platform === "linux" ? join5(home, ".config", "systemd", "user", "pi-fleet.service") : join5(home, "Library", "LaunchAgents", "works.elpapi.pifleet.plist");
|
|
918
|
+
if (!await exists(path)) return;
|
|
919
|
+
const contents = await readFile3(path, "utf8");
|
|
920
|
+
const installed = installedServicePiExecutable(contents, platform);
|
|
921
|
+
const installedNode = installedServicePiNode(contents, platform);
|
|
922
|
+
if (installed === void 0 || installedNode === void 0 || resolve4(installed) !== resolve4(options.selectedPath) || resolve4(installedNode) !== resolve4(options.nodePath)) {
|
|
923
|
+
throw new PiServiceMismatchError(
|
|
924
|
+
`The installed pi-fleet service uses a different Pi executable or Node interpreter; repair it from the environment selecting ${options.selectedPath}.`
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
function installedServicePiExecutable(contents, platform) {
|
|
929
|
+
return installedServiceEnvironmentValue(contents, platform, "PIFLEET_PI_EXECUTABLE");
|
|
930
|
+
}
|
|
931
|
+
function installedServicePiNode(contents, platform) {
|
|
932
|
+
return installedServiceEnvironmentValue(contents, platform, "PIFLEET_PI_NODE");
|
|
933
|
+
}
|
|
934
|
+
function installedServiceEnvironmentValue(contents, platform, key) {
|
|
935
|
+
const encoded = platform === "linux" ? new RegExp(`Environment=(?:"${key}=([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|${key}=(.+))$`, "m").exec(contents)?.slice(1).find(Boolean) : new RegExp(`<key>${key}<\\/key><string>([^<]+)<\\/string>`).exec(contents)?.[1];
|
|
936
|
+
if (encoded === void 0) return void 0;
|
|
937
|
+
if (platform === "darwin") {
|
|
938
|
+
return encoded.replaceAll("'", "'").replaceAll(""", '"').replaceAll(">", ">").replaceAll("<", "<").replaceAll("&", "&");
|
|
939
|
+
}
|
|
940
|
+
return encoded.replaceAll('\\"', '"').replaceAll("\\\\", "\\");
|
|
941
|
+
}
|
|
942
|
+
async function assertRegisteredStateRoot(definitionPath, platform, env) {
|
|
943
|
+
const installed = installedServiceStateRoot(await readFile3(definitionPath, "utf8"), platform);
|
|
944
|
+
const requested = resolve4(resolveFleetPaths(env).stateRoot);
|
|
945
|
+
if (installed === void 0) {
|
|
946
|
+
if (env.PIFLEET_STATE_ROOT === void 0) return;
|
|
947
|
+
throw new Error(
|
|
948
|
+
`Registered pi-fleet service uses the default state root, but this command requested ${requested}. Run the pi-fleet installer with PIFLEET_STATE_ROOT=${requested} to repair the service, or omit the override.`
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
if (resolve4(installed) !== requested) {
|
|
952
|
+
throw new Error(
|
|
953
|
+
`Registered pi-fleet service uses state root ${installed}, but this command requested ${requested}. Repair the service with the intended PIFLEET_STATE_ROOT before retrying.`
|
|
954
|
+
);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
async function findPackageRoot(modulePath) {
|
|
958
|
+
let candidate = dirname2(modulePath);
|
|
959
|
+
for (let depth = 0; depth < 6; depth += 1) {
|
|
960
|
+
if (await exists(join5(candidate, "dist", "runtime-manifest.json"))) return candidate;
|
|
961
|
+
const parent = dirname2(candidate);
|
|
962
|
+
if (parent === candidate) break;
|
|
963
|
+
candidate = parent;
|
|
964
|
+
}
|
|
965
|
+
throw new Error("Unable to locate the pi-fleet package runtime manifest.");
|
|
966
|
+
}
|
|
967
|
+
async function exists(path) {
|
|
968
|
+
try {
|
|
969
|
+
await access2(path);
|
|
970
|
+
return true;
|
|
971
|
+
} catch {
|
|
972
|
+
return false;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// src/client/socket-fleet-client.ts
|
|
977
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
978
|
+
import { createConnection as createConnection2 } from "node:net";
|
|
979
|
+
|
|
980
|
+
// src/protocol/version.ts
|
|
981
|
+
var PROTOCOL_VERSION = 3;
|
|
982
|
+
var MAX_PROTOCOL_FRAME_BYTES = 1024 * 1024;
|
|
983
|
+
|
|
984
|
+
// src/protocol/jsonl.ts
|
|
985
|
+
function readJsonLines(socket, onValue, onError, maxFrameBytes = MAX_PROTOCOL_FRAME_BYTES) {
|
|
986
|
+
let buffer = Buffer.alloc(0);
|
|
987
|
+
const onData = (chunk) => {
|
|
988
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
989
|
+
while (true) {
|
|
990
|
+
const newline = buffer.indexOf(10);
|
|
991
|
+
if (newline < 0) {
|
|
992
|
+
if (buffer.length > maxFrameBytes) {
|
|
993
|
+
onError(new Error("Protocol frame exceeds maximum size"));
|
|
994
|
+
}
|
|
995
|
+
return;
|
|
996
|
+
}
|
|
997
|
+
if (newline > maxFrameBytes) {
|
|
998
|
+
onError(new Error("Protocol frame exceeds maximum size"));
|
|
999
|
+
return;
|
|
1000
|
+
}
|
|
1001
|
+
const line = buffer.subarray(0, newline).toString("utf8").replace(/\r$/, "");
|
|
1002
|
+
buffer = buffer.subarray(newline + 1);
|
|
1003
|
+
if (line.length === 0) continue;
|
|
1004
|
+
try {
|
|
1005
|
+
onValue(JSON.parse(line));
|
|
1006
|
+
} catch {
|
|
1007
|
+
onError(new Error("Malformed JSON protocol frame"));
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
socket.on("data", onData);
|
|
1013
|
+
return () => socket.off("data", onData);
|
|
1014
|
+
}
|
|
1015
|
+
function writeJsonLine(socket, value) {
|
|
1016
|
+
return socket.write(`${JSON.stringify(value)}
|
|
1017
|
+
`);
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
// node_modules/@sinclair/typebox/build/esm/type/guard/value.mjs
|
|
1021
|
+
var value_exports = {};
|
|
1022
|
+
__export(value_exports, {
|
|
1023
|
+
HasPropertyKey: () => HasPropertyKey,
|
|
1024
|
+
IsArray: () => IsArray,
|
|
1025
|
+
IsAsyncIterator: () => IsAsyncIterator,
|
|
1026
|
+
IsBigInt: () => IsBigInt,
|
|
1027
|
+
IsBoolean: () => IsBoolean,
|
|
1028
|
+
IsDate: () => IsDate,
|
|
1029
|
+
IsFunction: () => IsFunction,
|
|
1030
|
+
IsIterator: () => IsIterator,
|
|
1031
|
+
IsNull: () => IsNull,
|
|
1032
|
+
IsNumber: () => IsNumber,
|
|
1033
|
+
IsObject: () => IsObject,
|
|
1034
|
+
IsRegExp: () => IsRegExp,
|
|
1035
|
+
IsString: () => IsString,
|
|
1036
|
+
IsSymbol: () => IsSymbol,
|
|
1037
|
+
IsUint8Array: () => IsUint8Array,
|
|
1038
|
+
IsUndefined: () => IsUndefined
|
|
1039
|
+
});
|
|
1040
|
+
function HasPropertyKey(value, key) {
|
|
1041
|
+
return key in value;
|
|
1042
|
+
}
|
|
1043
|
+
function IsAsyncIterator(value) {
|
|
1044
|
+
return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.asyncIterator in value;
|
|
1045
|
+
}
|
|
1046
|
+
function IsArray(value) {
|
|
1047
|
+
return Array.isArray(value);
|
|
1048
|
+
}
|
|
1049
|
+
function IsBigInt(value) {
|
|
1050
|
+
return typeof value === "bigint";
|
|
1051
|
+
}
|
|
1052
|
+
function IsBoolean(value) {
|
|
1053
|
+
return typeof value === "boolean";
|
|
1054
|
+
}
|
|
1055
|
+
function IsDate(value) {
|
|
1056
|
+
return value instanceof globalThis.Date;
|
|
1057
|
+
}
|
|
1058
|
+
function IsFunction(value) {
|
|
1059
|
+
return typeof value === "function";
|
|
1060
|
+
}
|
|
1061
|
+
function IsIterator(value) {
|
|
1062
|
+
return IsObject(value) && !IsArray(value) && !IsUint8Array(value) && Symbol.iterator in value;
|
|
1063
|
+
}
|
|
1064
|
+
function IsNull(value) {
|
|
1065
|
+
return value === null;
|
|
1066
|
+
}
|
|
1067
|
+
function IsNumber(value) {
|
|
1068
|
+
return typeof value === "number";
|
|
1069
|
+
}
|
|
1070
|
+
function IsObject(value) {
|
|
1071
|
+
return typeof value === "object" && value !== null;
|
|
1072
|
+
}
|
|
1073
|
+
function IsRegExp(value) {
|
|
1074
|
+
return value instanceof globalThis.RegExp;
|
|
1075
|
+
}
|
|
1076
|
+
function IsString(value) {
|
|
1077
|
+
return typeof value === "string";
|
|
1078
|
+
}
|
|
1079
|
+
function IsSymbol(value) {
|
|
1080
|
+
return typeof value === "symbol";
|
|
1081
|
+
}
|
|
1082
|
+
function IsUint8Array(value) {
|
|
1083
|
+
return value instanceof globalThis.Uint8Array;
|
|
1084
|
+
}
|
|
1085
|
+
function IsUndefined(value) {
|
|
1086
|
+
return value === void 0;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// node_modules/@sinclair/typebox/build/esm/type/clone/value.mjs
|
|
1090
|
+
function ArrayType(value) {
|
|
1091
|
+
return value.map((value2) => Visit(value2));
|
|
1092
|
+
}
|
|
1093
|
+
function DateType(value) {
|
|
1094
|
+
return new Date(value.getTime());
|
|
1095
|
+
}
|
|
1096
|
+
function Uint8ArrayType(value) {
|
|
1097
|
+
return new Uint8Array(value);
|
|
1098
|
+
}
|
|
1099
|
+
function RegExpType(value) {
|
|
1100
|
+
return new RegExp(value.source, value.flags);
|
|
1101
|
+
}
|
|
1102
|
+
function ObjectType(value) {
|
|
1103
|
+
const result = {};
|
|
1104
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
1105
|
+
result[key] = Visit(value[key]);
|
|
1106
|
+
}
|
|
1107
|
+
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
1108
|
+
result[key] = Visit(value[key]);
|
|
1109
|
+
}
|
|
1110
|
+
return result;
|
|
1111
|
+
}
|
|
1112
|
+
function Visit(value) {
|
|
1113
|
+
return IsArray(value) ? ArrayType(value) : IsDate(value) ? DateType(value) : IsUint8Array(value) ? Uint8ArrayType(value) : IsRegExp(value) ? RegExpType(value) : IsObject(value) ? ObjectType(value) : value;
|
|
1114
|
+
}
|
|
1115
|
+
function Clone(value) {
|
|
1116
|
+
return Visit(value);
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// node_modules/@sinclair/typebox/build/esm/type/clone/type.mjs
|
|
1120
|
+
function CloneType(schema, options) {
|
|
1121
|
+
return options === void 0 ? Clone(schema) : Clone({ ...options, ...schema });
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// node_modules/@sinclair/typebox/build/esm/value/guard/guard.mjs
|
|
1125
|
+
function IsObject2(value) {
|
|
1126
|
+
return value !== null && typeof value === "object";
|
|
1127
|
+
}
|
|
1128
|
+
function IsArray2(value) {
|
|
1129
|
+
return globalThis.Array.isArray(value) && !globalThis.ArrayBuffer.isView(value);
|
|
1130
|
+
}
|
|
1131
|
+
function IsUndefined2(value) {
|
|
1132
|
+
return value === void 0;
|
|
1133
|
+
}
|
|
1134
|
+
function IsNumber2(value) {
|
|
1135
|
+
return typeof value === "number";
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
// node_modules/@sinclair/typebox/build/esm/system/policy.mjs
|
|
1139
|
+
var TypeSystemPolicy;
|
|
1140
|
+
(function(TypeSystemPolicy2) {
|
|
1141
|
+
TypeSystemPolicy2.InstanceMode = "default";
|
|
1142
|
+
TypeSystemPolicy2.ExactOptionalPropertyTypes = false;
|
|
1143
|
+
TypeSystemPolicy2.AllowArrayObject = false;
|
|
1144
|
+
TypeSystemPolicy2.AllowNaN = false;
|
|
1145
|
+
TypeSystemPolicy2.AllowNullVoid = false;
|
|
1146
|
+
function IsExactOptionalProperty(value, key) {
|
|
1147
|
+
return TypeSystemPolicy2.ExactOptionalPropertyTypes ? key in value : value[key] !== void 0;
|
|
1148
|
+
}
|
|
1149
|
+
TypeSystemPolicy2.IsExactOptionalProperty = IsExactOptionalProperty;
|
|
1150
|
+
function IsObjectLike(value) {
|
|
1151
|
+
const isObject = IsObject2(value);
|
|
1152
|
+
return TypeSystemPolicy2.AllowArrayObject ? isObject : isObject && !IsArray2(value);
|
|
1153
|
+
}
|
|
1154
|
+
TypeSystemPolicy2.IsObjectLike = IsObjectLike;
|
|
1155
|
+
function IsRecordLike(value) {
|
|
1156
|
+
return IsObjectLike(value) && !(value instanceof Date) && !(value instanceof Uint8Array);
|
|
1157
|
+
}
|
|
1158
|
+
TypeSystemPolicy2.IsRecordLike = IsRecordLike;
|
|
1159
|
+
function IsNumberLike(value) {
|
|
1160
|
+
return TypeSystemPolicy2.AllowNaN ? IsNumber2(value) : Number.isFinite(value);
|
|
1161
|
+
}
|
|
1162
|
+
TypeSystemPolicy2.IsNumberLike = IsNumberLike;
|
|
1163
|
+
function IsVoidLike(value) {
|
|
1164
|
+
const isUndefined = IsUndefined2(value);
|
|
1165
|
+
return TypeSystemPolicy2.AllowNullVoid ? isUndefined || value === null : isUndefined;
|
|
1166
|
+
}
|
|
1167
|
+
TypeSystemPolicy2.IsVoidLike = IsVoidLike;
|
|
1168
|
+
})(TypeSystemPolicy || (TypeSystemPolicy = {}));
|
|
1169
|
+
|
|
1170
|
+
// node_modules/@sinclair/typebox/build/esm/type/create/immutable.mjs
|
|
1171
|
+
function ImmutableArray(value) {
|
|
1172
|
+
return globalThis.Object.freeze(value).map((value2) => Immutable(value2));
|
|
1173
|
+
}
|
|
1174
|
+
function ImmutableDate(value) {
|
|
1175
|
+
return value;
|
|
1176
|
+
}
|
|
1177
|
+
function ImmutableUint8Array(value) {
|
|
1178
|
+
return value;
|
|
1179
|
+
}
|
|
1180
|
+
function ImmutableRegExp(value) {
|
|
1181
|
+
return value;
|
|
1182
|
+
}
|
|
1183
|
+
function ImmutableObject(value) {
|
|
1184
|
+
const result = {};
|
|
1185
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
1186
|
+
result[key] = Immutable(value[key]);
|
|
1187
|
+
}
|
|
1188
|
+
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
1189
|
+
result[key] = Immutable(value[key]);
|
|
1190
|
+
}
|
|
1191
|
+
return globalThis.Object.freeze(result);
|
|
1192
|
+
}
|
|
1193
|
+
function Immutable(value) {
|
|
1194
|
+
return IsArray(value) ? ImmutableArray(value) : IsDate(value) ? ImmutableDate(value) : IsUint8Array(value) ? ImmutableUint8Array(value) : IsRegExp(value) ? ImmutableRegExp(value) : IsObject(value) ? ImmutableObject(value) : value;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
// node_modules/@sinclair/typebox/build/esm/type/create/type.mjs
|
|
1198
|
+
function CreateType(schema, options) {
|
|
1199
|
+
const result = options !== void 0 ? { ...options, ...schema } : schema;
|
|
1200
|
+
switch (TypeSystemPolicy.InstanceMode) {
|
|
1201
|
+
case "freeze":
|
|
1202
|
+
return Immutable(result);
|
|
1203
|
+
case "clone":
|
|
1204
|
+
return Clone(result);
|
|
1205
|
+
default:
|
|
1206
|
+
return result;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
// node_modules/@sinclair/typebox/build/esm/type/error/error.mjs
|
|
1211
|
+
var TypeBoxError = class extends Error {
|
|
1212
|
+
constructor(message) {
|
|
1213
|
+
super(message);
|
|
1214
|
+
}
|
|
1215
|
+
};
|
|
1216
|
+
|
|
1217
|
+
// node_modules/@sinclair/typebox/build/esm/type/symbols/symbols.mjs
|
|
1218
|
+
var TransformKind = Symbol.for("TypeBox.Transform");
|
|
1219
|
+
var ReadonlyKind = Symbol.for("TypeBox.Readonly");
|
|
1220
|
+
var OptionalKind = Symbol.for("TypeBox.Optional");
|
|
1221
|
+
var Hint = Symbol.for("TypeBox.Hint");
|
|
1222
|
+
var Kind = Symbol.for("TypeBox.Kind");
|
|
1223
|
+
|
|
1224
|
+
// node_modules/@sinclair/typebox/build/esm/type/guard/kind.mjs
|
|
1225
|
+
function IsReadonly(value) {
|
|
1226
|
+
return IsObject(value) && value[ReadonlyKind] === "Readonly";
|
|
1227
|
+
}
|
|
1228
|
+
function IsOptional(value) {
|
|
1229
|
+
return IsObject(value) && value[OptionalKind] === "Optional";
|
|
1230
|
+
}
|
|
1231
|
+
function IsAny(value) {
|
|
1232
|
+
return IsKindOf(value, "Any");
|
|
1233
|
+
}
|
|
1234
|
+
function IsArgument(value) {
|
|
1235
|
+
return IsKindOf(value, "Argument");
|
|
1236
|
+
}
|
|
1237
|
+
function IsArray3(value) {
|
|
1238
|
+
return IsKindOf(value, "Array");
|
|
1239
|
+
}
|
|
1240
|
+
function IsAsyncIterator2(value) {
|
|
1241
|
+
return IsKindOf(value, "AsyncIterator");
|
|
1242
|
+
}
|
|
1243
|
+
function IsBigInt2(value) {
|
|
1244
|
+
return IsKindOf(value, "BigInt");
|
|
1245
|
+
}
|
|
1246
|
+
function IsBoolean2(value) {
|
|
1247
|
+
return IsKindOf(value, "Boolean");
|
|
1248
|
+
}
|
|
1249
|
+
function IsComputed(value) {
|
|
1250
|
+
return IsKindOf(value, "Computed");
|
|
1251
|
+
}
|
|
1252
|
+
function IsConstructor(value) {
|
|
1253
|
+
return IsKindOf(value, "Constructor");
|
|
1254
|
+
}
|
|
1255
|
+
function IsDate2(value) {
|
|
1256
|
+
return IsKindOf(value, "Date");
|
|
1257
|
+
}
|
|
1258
|
+
function IsFunction2(value) {
|
|
1259
|
+
return IsKindOf(value, "Function");
|
|
1260
|
+
}
|
|
1261
|
+
function IsInteger(value) {
|
|
1262
|
+
return IsKindOf(value, "Integer");
|
|
1263
|
+
}
|
|
1264
|
+
function IsIntersect(value) {
|
|
1265
|
+
return IsKindOf(value, "Intersect");
|
|
1266
|
+
}
|
|
1267
|
+
function IsIterator2(value) {
|
|
1268
|
+
return IsKindOf(value, "Iterator");
|
|
1269
|
+
}
|
|
1270
|
+
function IsKindOf(value, kind) {
|
|
1271
|
+
return IsObject(value) && Kind in value && value[Kind] === kind;
|
|
1272
|
+
}
|
|
1273
|
+
function IsLiteralValue(value) {
|
|
1274
|
+
return IsBoolean(value) || IsNumber(value) || IsString(value);
|
|
1275
|
+
}
|
|
1276
|
+
function IsLiteral(value) {
|
|
1277
|
+
return IsKindOf(value, "Literal");
|
|
1278
|
+
}
|
|
1279
|
+
function IsMappedKey(value) {
|
|
1280
|
+
return IsKindOf(value, "MappedKey");
|
|
1281
|
+
}
|
|
1282
|
+
function IsMappedResult(value) {
|
|
1283
|
+
return IsKindOf(value, "MappedResult");
|
|
1284
|
+
}
|
|
1285
|
+
function IsNever(value) {
|
|
1286
|
+
return IsKindOf(value, "Never");
|
|
1287
|
+
}
|
|
1288
|
+
function IsNot(value) {
|
|
1289
|
+
return IsKindOf(value, "Not");
|
|
1290
|
+
}
|
|
1291
|
+
function IsNull2(value) {
|
|
1292
|
+
return IsKindOf(value, "Null");
|
|
1293
|
+
}
|
|
1294
|
+
function IsNumber3(value) {
|
|
1295
|
+
return IsKindOf(value, "Number");
|
|
1296
|
+
}
|
|
1297
|
+
function IsObject3(value) {
|
|
1298
|
+
return IsKindOf(value, "Object");
|
|
1299
|
+
}
|
|
1300
|
+
function IsPromise(value) {
|
|
1301
|
+
return IsKindOf(value, "Promise");
|
|
1302
|
+
}
|
|
1303
|
+
function IsRecord(value) {
|
|
1304
|
+
return IsKindOf(value, "Record");
|
|
1305
|
+
}
|
|
1306
|
+
function IsRef(value) {
|
|
1307
|
+
return IsKindOf(value, "Ref");
|
|
1308
|
+
}
|
|
1309
|
+
function IsRegExp2(value) {
|
|
1310
|
+
return IsKindOf(value, "RegExp");
|
|
1311
|
+
}
|
|
1312
|
+
function IsString2(value) {
|
|
1313
|
+
return IsKindOf(value, "String");
|
|
1314
|
+
}
|
|
1315
|
+
function IsSymbol2(value) {
|
|
1316
|
+
return IsKindOf(value, "Symbol");
|
|
1317
|
+
}
|
|
1318
|
+
function IsTemplateLiteral(value) {
|
|
1319
|
+
return IsKindOf(value, "TemplateLiteral");
|
|
1320
|
+
}
|
|
1321
|
+
function IsThis(value) {
|
|
1322
|
+
return IsKindOf(value, "This");
|
|
1323
|
+
}
|
|
1324
|
+
function IsTransform(value) {
|
|
1325
|
+
return IsObject(value) && TransformKind in value;
|
|
1326
|
+
}
|
|
1327
|
+
function IsTuple(value) {
|
|
1328
|
+
return IsKindOf(value, "Tuple");
|
|
1329
|
+
}
|
|
1330
|
+
function IsUndefined3(value) {
|
|
1331
|
+
return IsKindOf(value, "Undefined");
|
|
1332
|
+
}
|
|
1333
|
+
function IsUnion(value) {
|
|
1334
|
+
return IsKindOf(value, "Union");
|
|
1335
|
+
}
|
|
1336
|
+
function IsUint8Array2(value) {
|
|
1337
|
+
return IsKindOf(value, "Uint8Array");
|
|
1338
|
+
}
|
|
1339
|
+
function IsUnknown(value) {
|
|
1340
|
+
return IsKindOf(value, "Unknown");
|
|
1341
|
+
}
|
|
1342
|
+
function IsUnsafe(value) {
|
|
1343
|
+
return IsKindOf(value, "Unsafe");
|
|
1344
|
+
}
|
|
1345
|
+
function IsVoid(value) {
|
|
1346
|
+
return IsKindOf(value, "Void");
|
|
1347
|
+
}
|
|
1348
|
+
function IsKind(value) {
|
|
1349
|
+
return IsObject(value) && Kind in value && IsString(value[Kind]);
|
|
1350
|
+
}
|
|
1351
|
+
function IsSchema(value) {
|
|
1352
|
+
return IsAny(value) || IsArgument(value) || IsArray3(value) || IsBoolean2(value) || IsBigInt2(value) || IsAsyncIterator2(value) || IsComputed(value) || IsConstructor(value) || IsDate2(value) || IsFunction2(value) || IsInteger(value) || IsIntersect(value) || IsIterator2(value) || IsLiteral(value) || IsMappedKey(value) || IsMappedResult(value) || IsNever(value) || IsNot(value) || IsNull2(value) || IsNumber3(value) || IsObject3(value) || IsPromise(value) || IsRecord(value) || IsRef(value) || IsRegExp2(value) || IsString2(value) || IsSymbol2(value) || IsTemplateLiteral(value) || IsThis(value) || IsTuple(value) || IsUndefined3(value) || IsUnion(value) || IsUint8Array2(value) || IsUnknown(value) || IsUnsafe(value) || IsVoid(value) || IsKind(value);
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
// node_modules/@sinclair/typebox/build/esm/type/guard/type.mjs
|
|
1356
|
+
var type_exports = {};
|
|
1357
|
+
__export(type_exports, {
|
|
1358
|
+
IsAny: () => IsAny2,
|
|
1359
|
+
IsArgument: () => IsArgument2,
|
|
1360
|
+
IsArray: () => IsArray4,
|
|
1361
|
+
IsAsyncIterator: () => IsAsyncIterator3,
|
|
1362
|
+
IsBigInt: () => IsBigInt3,
|
|
1363
|
+
IsBoolean: () => IsBoolean3,
|
|
1364
|
+
IsComputed: () => IsComputed2,
|
|
1365
|
+
IsConstructor: () => IsConstructor2,
|
|
1366
|
+
IsDate: () => IsDate3,
|
|
1367
|
+
IsFunction: () => IsFunction3,
|
|
1368
|
+
IsImport: () => IsImport,
|
|
1369
|
+
IsInteger: () => IsInteger2,
|
|
1370
|
+
IsIntersect: () => IsIntersect2,
|
|
1371
|
+
IsIterator: () => IsIterator3,
|
|
1372
|
+
IsKind: () => IsKind2,
|
|
1373
|
+
IsKindOf: () => IsKindOf2,
|
|
1374
|
+
IsLiteral: () => IsLiteral2,
|
|
1375
|
+
IsLiteralBoolean: () => IsLiteralBoolean,
|
|
1376
|
+
IsLiteralNumber: () => IsLiteralNumber,
|
|
1377
|
+
IsLiteralString: () => IsLiteralString,
|
|
1378
|
+
IsLiteralValue: () => IsLiteralValue2,
|
|
1379
|
+
IsMappedKey: () => IsMappedKey2,
|
|
1380
|
+
IsMappedResult: () => IsMappedResult2,
|
|
1381
|
+
IsNever: () => IsNever2,
|
|
1382
|
+
IsNot: () => IsNot2,
|
|
1383
|
+
IsNull: () => IsNull3,
|
|
1384
|
+
IsNumber: () => IsNumber4,
|
|
1385
|
+
IsObject: () => IsObject4,
|
|
1386
|
+
IsOptional: () => IsOptional2,
|
|
1387
|
+
IsPromise: () => IsPromise2,
|
|
1388
|
+
IsProperties: () => IsProperties,
|
|
1389
|
+
IsReadonly: () => IsReadonly2,
|
|
1390
|
+
IsRecord: () => IsRecord2,
|
|
1391
|
+
IsRecursive: () => IsRecursive,
|
|
1392
|
+
IsRef: () => IsRef2,
|
|
1393
|
+
IsRegExp: () => IsRegExp3,
|
|
1394
|
+
IsSchema: () => IsSchema2,
|
|
1395
|
+
IsString: () => IsString3,
|
|
1396
|
+
IsSymbol: () => IsSymbol3,
|
|
1397
|
+
IsTemplateLiteral: () => IsTemplateLiteral2,
|
|
1398
|
+
IsThis: () => IsThis2,
|
|
1399
|
+
IsTransform: () => IsTransform2,
|
|
1400
|
+
IsTuple: () => IsTuple2,
|
|
1401
|
+
IsUint8Array: () => IsUint8Array3,
|
|
1402
|
+
IsUndefined: () => IsUndefined4,
|
|
1403
|
+
IsUnion: () => IsUnion2,
|
|
1404
|
+
IsUnionLiteral: () => IsUnionLiteral,
|
|
1405
|
+
IsUnknown: () => IsUnknown2,
|
|
1406
|
+
IsUnsafe: () => IsUnsafe2,
|
|
1407
|
+
IsVoid: () => IsVoid2,
|
|
1408
|
+
TypeGuardUnknownTypeError: () => TypeGuardUnknownTypeError
|
|
1409
|
+
});
|
|
1410
|
+
var TypeGuardUnknownTypeError = class extends TypeBoxError {
|
|
1411
|
+
};
|
|
1412
|
+
var KnownTypes = [
|
|
1413
|
+
"Argument",
|
|
1414
|
+
"Any",
|
|
1415
|
+
"Array",
|
|
1416
|
+
"AsyncIterator",
|
|
1417
|
+
"BigInt",
|
|
1418
|
+
"Boolean",
|
|
1419
|
+
"Computed",
|
|
1420
|
+
"Constructor",
|
|
1421
|
+
"Date",
|
|
1422
|
+
"Enum",
|
|
1423
|
+
"Function",
|
|
1424
|
+
"Integer",
|
|
1425
|
+
"Intersect",
|
|
1426
|
+
"Iterator",
|
|
1427
|
+
"Literal",
|
|
1428
|
+
"MappedKey",
|
|
1429
|
+
"MappedResult",
|
|
1430
|
+
"Not",
|
|
1431
|
+
"Null",
|
|
1432
|
+
"Number",
|
|
1433
|
+
"Object",
|
|
1434
|
+
"Promise",
|
|
1435
|
+
"Record",
|
|
1436
|
+
"Ref",
|
|
1437
|
+
"RegExp",
|
|
1438
|
+
"String",
|
|
1439
|
+
"Symbol",
|
|
1440
|
+
"TemplateLiteral",
|
|
1441
|
+
"This",
|
|
1442
|
+
"Tuple",
|
|
1443
|
+
"Undefined",
|
|
1444
|
+
"Union",
|
|
1445
|
+
"Uint8Array",
|
|
1446
|
+
"Unknown",
|
|
1447
|
+
"Void"
|
|
1448
|
+
];
|
|
1449
|
+
function IsPattern(value) {
|
|
1450
|
+
try {
|
|
1451
|
+
new RegExp(value);
|
|
1452
|
+
return true;
|
|
1453
|
+
} catch {
|
|
1454
|
+
return false;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
function IsControlCharacterFree(value) {
|
|
1458
|
+
if (!IsString(value))
|
|
1459
|
+
return false;
|
|
1460
|
+
for (let i = 0; i < value.length; i++) {
|
|
1461
|
+
const code = value.charCodeAt(i);
|
|
1462
|
+
if (code >= 7 && code <= 13 || code === 27 || code === 127) {
|
|
1463
|
+
return false;
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
function IsAdditionalProperties(value) {
|
|
1469
|
+
return IsOptionalBoolean(value) || IsSchema2(value);
|
|
1470
|
+
}
|
|
1471
|
+
function IsOptionalBigInt(value) {
|
|
1472
|
+
return IsUndefined(value) || IsBigInt(value);
|
|
1473
|
+
}
|
|
1474
|
+
function IsOptionalNumber(value) {
|
|
1475
|
+
return IsUndefined(value) || IsNumber(value);
|
|
1476
|
+
}
|
|
1477
|
+
function IsOptionalBoolean(value) {
|
|
1478
|
+
return IsUndefined(value) || IsBoolean(value);
|
|
1479
|
+
}
|
|
1480
|
+
function IsOptionalString(value) {
|
|
1481
|
+
return IsUndefined(value) || IsString(value);
|
|
1482
|
+
}
|
|
1483
|
+
function IsOptionalPattern(value) {
|
|
1484
|
+
return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value) && IsPattern(value);
|
|
1485
|
+
}
|
|
1486
|
+
function IsOptionalFormat(value) {
|
|
1487
|
+
return IsUndefined(value) || IsString(value) && IsControlCharacterFree(value);
|
|
1488
|
+
}
|
|
1489
|
+
function IsOptionalSchema(value) {
|
|
1490
|
+
return IsUndefined(value) || IsSchema2(value);
|
|
1491
|
+
}
|
|
1492
|
+
function IsReadonly2(value) {
|
|
1493
|
+
return IsObject(value) && value[ReadonlyKind] === "Readonly";
|
|
1494
|
+
}
|
|
1495
|
+
function IsOptional2(value) {
|
|
1496
|
+
return IsObject(value) && value[OptionalKind] === "Optional";
|
|
1497
|
+
}
|
|
1498
|
+
function IsAny2(value) {
|
|
1499
|
+
return IsKindOf2(value, "Any") && IsOptionalString(value.$id);
|
|
1500
|
+
}
|
|
1501
|
+
function IsArgument2(value) {
|
|
1502
|
+
return IsKindOf2(value, "Argument") && IsNumber(value.index);
|
|
1503
|
+
}
|
|
1504
|
+
function IsArray4(value) {
|
|
1505
|
+
return IsKindOf2(value, "Array") && value.type === "array" && IsOptionalString(value.$id) && IsSchema2(value.items) && IsOptionalNumber(value.minItems) && IsOptionalNumber(value.maxItems) && IsOptionalBoolean(value.uniqueItems) && IsOptionalSchema(value.contains) && IsOptionalNumber(value.minContains) && IsOptionalNumber(value.maxContains);
|
|
1506
|
+
}
|
|
1507
|
+
function IsAsyncIterator3(value) {
|
|
1508
|
+
return IsKindOf2(value, "AsyncIterator") && value.type === "AsyncIterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
|
|
1509
|
+
}
|
|
1510
|
+
function IsBigInt3(value) {
|
|
1511
|
+
return IsKindOf2(value, "BigInt") && value.type === "bigint" && IsOptionalString(value.$id) && IsOptionalBigInt(value.exclusiveMaximum) && IsOptionalBigInt(value.exclusiveMinimum) && IsOptionalBigInt(value.maximum) && IsOptionalBigInt(value.minimum) && IsOptionalBigInt(value.multipleOf);
|
|
1512
|
+
}
|
|
1513
|
+
function IsBoolean3(value) {
|
|
1514
|
+
return IsKindOf2(value, "Boolean") && value.type === "boolean" && IsOptionalString(value.$id);
|
|
1515
|
+
}
|
|
1516
|
+
function IsComputed2(value) {
|
|
1517
|
+
return IsKindOf2(value, "Computed") && IsString(value.target) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema));
|
|
1518
|
+
}
|
|
1519
|
+
function IsConstructor2(value) {
|
|
1520
|
+
return IsKindOf2(value, "Constructor") && value.type === "Constructor" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
|
|
1521
|
+
}
|
|
1522
|
+
function IsDate3(value) {
|
|
1523
|
+
return IsKindOf2(value, "Date") && value.type === "Date" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximumTimestamp) && IsOptionalNumber(value.exclusiveMinimumTimestamp) && IsOptionalNumber(value.maximumTimestamp) && IsOptionalNumber(value.minimumTimestamp) && IsOptionalNumber(value.multipleOfTimestamp);
|
|
1524
|
+
}
|
|
1525
|
+
function IsFunction3(value) {
|
|
1526
|
+
return IsKindOf2(value, "Function") && value.type === "Function" && IsOptionalString(value.$id) && IsArray(value.parameters) && value.parameters.every((schema) => IsSchema2(schema)) && IsSchema2(value.returns);
|
|
1527
|
+
}
|
|
1528
|
+
function IsImport(value) {
|
|
1529
|
+
return IsKindOf2(value, "Import") && HasPropertyKey(value, "$defs") && IsObject(value.$defs) && IsProperties(value.$defs) && HasPropertyKey(value, "$ref") && IsString(value.$ref) && value.$ref in value.$defs;
|
|
1530
|
+
}
|
|
1531
|
+
function IsInteger2(value) {
|
|
1532
|
+
return IsKindOf2(value, "Integer") && value.type === "integer" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf);
|
|
1533
|
+
}
|
|
1534
|
+
function IsProperties(value) {
|
|
1535
|
+
return IsObject(value) && Object.entries(value).every(([key, schema]) => IsControlCharacterFree(key) && IsSchema2(schema));
|
|
1536
|
+
}
|
|
1537
|
+
function IsIntersect2(value) {
|
|
1538
|
+
return IsKindOf2(value, "Intersect") && (IsString(value.type) && value.type !== "object" ? false : true) && IsArray(value.allOf) && value.allOf.every((schema) => IsSchema2(schema) && !IsTransform2(schema)) && IsOptionalString(value.type) && (IsOptionalBoolean(value.unevaluatedProperties) || IsOptionalSchema(value.unevaluatedProperties)) && IsOptionalString(value.$id);
|
|
1539
|
+
}
|
|
1540
|
+
function IsIterator3(value) {
|
|
1541
|
+
return IsKindOf2(value, "Iterator") && value.type === "Iterator" && IsOptionalString(value.$id) && IsSchema2(value.items);
|
|
1542
|
+
}
|
|
1543
|
+
function IsKindOf2(value, kind) {
|
|
1544
|
+
return IsObject(value) && Kind in value && value[Kind] === kind;
|
|
1545
|
+
}
|
|
1546
|
+
function IsLiteralString(value) {
|
|
1547
|
+
return IsLiteral2(value) && IsString(value.const);
|
|
1548
|
+
}
|
|
1549
|
+
function IsLiteralNumber(value) {
|
|
1550
|
+
return IsLiteral2(value) && IsNumber(value.const);
|
|
1551
|
+
}
|
|
1552
|
+
function IsLiteralBoolean(value) {
|
|
1553
|
+
return IsLiteral2(value) && IsBoolean(value.const);
|
|
1554
|
+
}
|
|
1555
|
+
function IsLiteral2(value) {
|
|
1556
|
+
return IsKindOf2(value, "Literal") && IsOptionalString(value.$id) && IsLiteralValue2(value.const);
|
|
1557
|
+
}
|
|
1558
|
+
function IsLiteralValue2(value) {
|
|
1559
|
+
return IsBoolean(value) || IsNumber(value) || IsString(value);
|
|
1560
|
+
}
|
|
1561
|
+
function IsMappedKey2(value) {
|
|
1562
|
+
return IsKindOf2(value, "MappedKey") && IsArray(value.keys) && value.keys.every((key) => IsNumber(key) || IsString(key));
|
|
1563
|
+
}
|
|
1564
|
+
function IsMappedResult2(value) {
|
|
1565
|
+
return IsKindOf2(value, "MappedResult") && IsProperties(value.properties);
|
|
1566
|
+
}
|
|
1567
|
+
function IsNever2(value) {
|
|
1568
|
+
return IsKindOf2(value, "Never") && IsObject(value.not) && Object.getOwnPropertyNames(value.not).length === 0;
|
|
1569
|
+
}
|
|
1570
|
+
function IsNot2(value) {
|
|
1571
|
+
return IsKindOf2(value, "Not") && IsSchema2(value.not);
|
|
1572
|
+
}
|
|
1573
|
+
function IsNull3(value) {
|
|
1574
|
+
return IsKindOf2(value, "Null") && value.type === "null" && IsOptionalString(value.$id);
|
|
1575
|
+
}
|
|
1576
|
+
function IsNumber4(value) {
|
|
1577
|
+
return IsKindOf2(value, "Number") && value.type === "number" && IsOptionalString(value.$id) && IsOptionalNumber(value.exclusiveMaximum) && IsOptionalNumber(value.exclusiveMinimum) && IsOptionalNumber(value.maximum) && IsOptionalNumber(value.minimum) && IsOptionalNumber(value.multipleOf);
|
|
1578
|
+
}
|
|
1579
|
+
function IsObject4(value) {
|
|
1580
|
+
return IsKindOf2(value, "Object") && value.type === "object" && IsOptionalString(value.$id) && IsProperties(value.properties) && IsAdditionalProperties(value.additionalProperties) && IsOptionalNumber(value.minProperties) && IsOptionalNumber(value.maxProperties);
|
|
1581
|
+
}
|
|
1582
|
+
function IsPromise2(value) {
|
|
1583
|
+
return IsKindOf2(value, "Promise") && value.type === "Promise" && IsOptionalString(value.$id) && IsSchema2(value.item);
|
|
1584
|
+
}
|
|
1585
|
+
function IsRecord2(value) {
|
|
1586
|
+
return IsKindOf2(value, "Record") && value.type === "object" && IsOptionalString(value.$id) && IsAdditionalProperties(value.additionalProperties) && IsObject(value.patternProperties) && ((schema) => {
|
|
1587
|
+
const keys = Object.getOwnPropertyNames(schema.patternProperties);
|
|
1588
|
+
return keys.length === 1 && IsPattern(keys[0]) && IsObject(schema.patternProperties) && IsSchema2(schema.patternProperties[keys[0]]);
|
|
1589
|
+
})(value);
|
|
1590
|
+
}
|
|
1591
|
+
function IsRecursive(value) {
|
|
1592
|
+
return IsObject(value) && Hint in value && value[Hint] === "Recursive";
|
|
1593
|
+
}
|
|
1594
|
+
function IsRef2(value) {
|
|
1595
|
+
return IsKindOf2(value, "Ref") && IsOptionalString(value.$id) && IsString(value.$ref);
|
|
1596
|
+
}
|
|
1597
|
+
function IsRegExp3(value) {
|
|
1598
|
+
return IsKindOf2(value, "RegExp") && IsOptionalString(value.$id) && IsString(value.source) && IsString(value.flags) && IsOptionalNumber(value.maxLength) && IsOptionalNumber(value.minLength);
|
|
1599
|
+
}
|
|
1600
|
+
function IsString3(value) {
|
|
1601
|
+
return IsKindOf2(value, "String") && value.type === "string" && IsOptionalString(value.$id) && IsOptionalNumber(value.minLength) && IsOptionalNumber(value.maxLength) && IsOptionalPattern(value.pattern) && IsOptionalFormat(value.format);
|
|
1602
|
+
}
|
|
1603
|
+
function IsSymbol3(value) {
|
|
1604
|
+
return IsKindOf2(value, "Symbol") && value.type === "symbol" && IsOptionalString(value.$id);
|
|
1605
|
+
}
|
|
1606
|
+
function IsTemplateLiteral2(value) {
|
|
1607
|
+
return IsKindOf2(value, "TemplateLiteral") && value.type === "string" && IsString(value.pattern) && value.pattern[0] === "^" && value.pattern[value.pattern.length - 1] === "$";
|
|
1608
|
+
}
|
|
1609
|
+
function IsThis2(value) {
|
|
1610
|
+
return IsKindOf2(value, "This") && IsOptionalString(value.$id) && IsString(value.$ref);
|
|
1611
|
+
}
|
|
1612
|
+
function IsTransform2(value) {
|
|
1613
|
+
return IsObject(value) && TransformKind in value;
|
|
1614
|
+
}
|
|
1615
|
+
function IsTuple2(value) {
|
|
1616
|
+
return IsKindOf2(value, "Tuple") && value.type === "array" && IsOptionalString(value.$id) && IsNumber(value.minItems) && IsNumber(value.maxItems) && value.minItems === value.maxItems && // empty
|
|
1617
|
+
(IsUndefined(value.items) && IsUndefined(value.additionalItems) && value.minItems === 0 || IsArray(value.items) && value.items.every((schema) => IsSchema2(schema)));
|
|
1618
|
+
}
|
|
1619
|
+
function IsUndefined4(value) {
|
|
1620
|
+
return IsKindOf2(value, "Undefined") && value.type === "undefined" && IsOptionalString(value.$id);
|
|
1621
|
+
}
|
|
1622
|
+
function IsUnionLiteral(value) {
|
|
1623
|
+
return IsUnion2(value) && value.anyOf.every((schema) => IsLiteralString(schema) || IsLiteralNumber(schema));
|
|
1624
|
+
}
|
|
1625
|
+
function IsUnion2(value) {
|
|
1626
|
+
return IsKindOf2(value, "Union") && IsOptionalString(value.$id) && IsObject(value) && IsArray(value.anyOf) && value.anyOf.every((schema) => IsSchema2(schema));
|
|
1627
|
+
}
|
|
1628
|
+
function IsUint8Array3(value) {
|
|
1629
|
+
return IsKindOf2(value, "Uint8Array") && value.type === "Uint8Array" && IsOptionalString(value.$id) && IsOptionalNumber(value.minByteLength) && IsOptionalNumber(value.maxByteLength);
|
|
1630
|
+
}
|
|
1631
|
+
function IsUnknown2(value) {
|
|
1632
|
+
return IsKindOf2(value, "Unknown") && IsOptionalString(value.$id);
|
|
1633
|
+
}
|
|
1634
|
+
function IsUnsafe2(value) {
|
|
1635
|
+
return IsKindOf2(value, "Unsafe");
|
|
1636
|
+
}
|
|
1637
|
+
function IsVoid2(value) {
|
|
1638
|
+
return IsKindOf2(value, "Void") && value.type === "void" && IsOptionalString(value.$id);
|
|
1639
|
+
}
|
|
1640
|
+
function IsKind2(value) {
|
|
1641
|
+
return IsObject(value) && Kind in value && IsString(value[Kind]) && !KnownTypes.includes(value[Kind]);
|
|
1642
|
+
}
|
|
1643
|
+
function IsSchema2(value) {
|
|
1644
|
+
return IsObject(value) && (IsAny2(value) || IsArgument2(value) || IsArray4(value) || IsBoolean3(value) || IsBigInt3(value) || IsAsyncIterator3(value) || IsComputed2(value) || IsConstructor2(value) || IsDate3(value) || IsFunction3(value) || IsInteger2(value) || IsIntersect2(value) || IsIterator3(value) || IsLiteral2(value) || IsMappedKey2(value) || IsMappedResult2(value) || IsNever2(value) || IsNot2(value) || IsNull3(value) || IsNumber4(value) || IsObject4(value) || IsPromise2(value) || IsRecord2(value) || IsRef2(value) || IsRegExp3(value) || IsString3(value) || IsSymbol3(value) || IsTemplateLiteral2(value) || IsThis2(value) || IsTuple2(value) || IsUndefined4(value) || IsUnion2(value) || IsUint8Array3(value) || IsUnknown2(value) || IsUnsafe2(value) || IsVoid2(value) || IsKind2(value));
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
// node_modules/@sinclair/typebox/build/esm/type/patterns/patterns.mjs
|
|
1648
|
+
var PatternBoolean = "(true|false)";
|
|
1649
|
+
var PatternNumber = "(0|[1-9][0-9]*)";
|
|
1650
|
+
var PatternString = "(.*)";
|
|
1651
|
+
var PatternNever = "(?!.*)";
|
|
1652
|
+
var PatternBooleanExact = `^${PatternBoolean}$`;
|
|
1653
|
+
var PatternNumberExact = `^${PatternNumber}$`;
|
|
1654
|
+
var PatternStringExact = `^${PatternString}$`;
|
|
1655
|
+
var PatternNeverExact = `^${PatternNever}$`;
|
|
1656
|
+
|
|
1657
|
+
// node_modules/@sinclair/typebox/build/esm/type/sets/set.mjs
|
|
1658
|
+
function SetIncludes(T, S) {
|
|
1659
|
+
return T.includes(S);
|
|
1660
|
+
}
|
|
1661
|
+
function SetDistinct(T) {
|
|
1662
|
+
return [...new Set(T)];
|
|
1663
|
+
}
|
|
1664
|
+
function SetIntersect(T, S) {
|
|
1665
|
+
return T.filter((L) => S.includes(L));
|
|
1666
|
+
}
|
|
1667
|
+
function SetIntersectManyResolve(T, Init) {
|
|
1668
|
+
return T.reduce((Acc, L) => {
|
|
1669
|
+
return SetIntersect(Acc, L);
|
|
1670
|
+
}, Init);
|
|
1671
|
+
}
|
|
1672
|
+
function SetIntersectMany(T) {
|
|
1673
|
+
return T.length === 1 ? T[0] : T.length > 1 ? SetIntersectManyResolve(T.slice(1), T[0]) : [];
|
|
1674
|
+
}
|
|
1675
|
+
function SetUnionMany(T) {
|
|
1676
|
+
const Acc = [];
|
|
1677
|
+
for (const L of T)
|
|
1678
|
+
Acc.push(...L);
|
|
1679
|
+
return Acc;
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
// node_modules/@sinclair/typebox/build/esm/type/any/any.mjs
|
|
1683
|
+
function Any(options) {
|
|
1684
|
+
return CreateType({ [Kind]: "Any" }, options);
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
// node_modules/@sinclair/typebox/build/esm/type/array/array.mjs
|
|
1688
|
+
function Array2(items, options) {
|
|
1689
|
+
return CreateType({ [Kind]: "Array", type: "array", items }, options);
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// node_modules/@sinclair/typebox/build/esm/type/argument/argument.mjs
|
|
1693
|
+
function Argument(index) {
|
|
1694
|
+
return CreateType({ [Kind]: "Argument", index });
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// node_modules/@sinclair/typebox/build/esm/type/async-iterator/async-iterator.mjs
|
|
1698
|
+
function AsyncIterator(items, options) {
|
|
1699
|
+
return CreateType({ [Kind]: "AsyncIterator", type: "AsyncIterator", items }, options);
|
|
1700
|
+
}
|
|
1701
|
+
|
|
1702
|
+
// node_modules/@sinclair/typebox/build/esm/type/computed/computed.mjs
|
|
1703
|
+
function Computed(target, parameters, options) {
|
|
1704
|
+
return CreateType({ [Kind]: "Computed", target, parameters }, options);
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
// node_modules/@sinclair/typebox/build/esm/type/discard/discard.mjs
|
|
1708
|
+
function DiscardKey(value, key) {
|
|
1709
|
+
const { [key]: _, ...rest } = value;
|
|
1710
|
+
return rest;
|
|
1711
|
+
}
|
|
1712
|
+
function Discard(value, keys) {
|
|
1713
|
+
return keys.reduce((acc, key) => DiscardKey(acc, key), value);
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1716
|
+
// node_modules/@sinclair/typebox/build/esm/type/never/never.mjs
|
|
1717
|
+
function Never(options) {
|
|
1718
|
+
return CreateType({ [Kind]: "Never", not: {} }, options);
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
// node_modules/@sinclair/typebox/build/esm/type/mapped/mapped-result.mjs
|
|
1722
|
+
function MappedResult(properties) {
|
|
1723
|
+
return CreateType({
|
|
1724
|
+
[Kind]: "MappedResult",
|
|
1725
|
+
properties
|
|
1726
|
+
});
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// node_modules/@sinclair/typebox/build/esm/type/constructor/constructor.mjs
|
|
1730
|
+
function Constructor(parameters, returns, options) {
|
|
1731
|
+
return CreateType({ [Kind]: "Constructor", type: "Constructor", parameters, returns }, options);
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
// node_modules/@sinclair/typebox/build/esm/type/function/function.mjs
|
|
1735
|
+
function Function(parameters, returns, options) {
|
|
1736
|
+
return CreateType({ [Kind]: "Function", type: "Function", parameters, returns }, options);
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
// node_modules/@sinclair/typebox/build/esm/type/union/union-create.mjs
|
|
1740
|
+
function UnionCreate(T, options) {
|
|
1741
|
+
return CreateType({ [Kind]: "Union", anyOf: T }, options);
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
// node_modules/@sinclair/typebox/build/esm/type/union/union-evaluated.mjs
|
|
1745
|
+
function IsUnionOptional(types) {
|
|
1746
|
+
return types.some((type) => IsOptional(type));
|
|
1747
|
+
}
|
|
1748
|
+
function RemoveOptionalFromRest(types) {
|
|
1749
|
+
return types.map((left) => IsOptional(left) ? RemoveOptionalFromType(left) : left);
|
|
1750
|
+
}
|
|
1751
|
+
function RemoveOptionalFromType(T) {
|
|
1752
|
+
return Discard(T, [OptionalKind]);
|
|
1753
|
+
}
|
|
1754
|
+
function ResolveUnion(types, options) {
|
|
1755
|
+
const isOptional = IsUnionOptional(types);
|
|
1756
|
+
return isOptional ? Optional(UnionCreate(RemoveOptionalFromRest(types), options)) : UnionCreate(RemoveOptionalFromRest(types), options);
|
|
1757
|
+
}
|
|
1758
|
+
function UnionEvaluated(T, options) {
|
|
1759
|
+
return T.length === 1 ? CreateType(T[0], options) : T.length === 0 ? Never(options) : ResolveUnion(T, options);
|
|
1760
|
+
}
|
|
1761
|
+
|
|
1762
|
+
// node_modules/@sinclair/typebox/build/esm/type/union/union.mjs
|
|
1763
|
+
function Union(types, options) {
|
|
1764
|
+
return types.length === 0 ? Never(options) : types.length === 1 ? CreateType(types[0], options) : UnionCreate(types, options);
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
// node_modules/@sinclair/typebox/build/esm/type/template-literal/parse.mjs
|
|
1768
|
+
var TemplateLiteralParserError = class extends TypeBoxError {
|
|
1769
|
+
};
|
|
1770
|
+
function Unescape(pattern) {
|
|
1771
|
+
return pattern.replace(/\\\$/g, "$").replace(/\\\*/g, "*").replace(/\\\^/g, "^").replace(/\\\|/g, "|").replace(/\\\(/g, "(").replace(/\\\)/g, ")");
|
|
1772
|
+
}
|
|
1773
|
+
function IsNonEscaped(pattern, index, char) {
|
|
1774
|
+
return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
|
|
1775
|
+
}
|
|
1776
|
+
function IsOpenParen(pattern, index) {
|
|
1777
|
+
return IsNonEscaped(pattern, index, "(");
|
|
1778
|
+
}
|
|
1779
|
+
function IsCloseParen(pattern, index) {
|
|
1780
|
+
return IsNonEscaped(pattern, index, ")");
|
|
1781
|
+
}
|
|
1782
|
+
function IsSeparator(pattern, index) {
|
|
1783
|
+
return IsNonEscaped(pattern, index, "|");
|
|
1784
|
+
}
|
|
1785
|
+
function IsGroup(pattern) {
|
|
1786
|
+
if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
|
|
1787
|
+
return false;
|
|
1788
|
+
let count = 0;
|
|
1789
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1790
|
+
if (IsOpenParen(pattern, index))
|
|
1791
|
+
count += 1;
|
|
1792
|
+
if (IsCloseParen(pattern, index))
|
|
1793
|
+
count -= 1;
|
|
1794
|
+
if (count === 0 && index !== pattern.length - 1)
|
|
1795
|
+
return false;
|
|
1796
|
+
}
|
|
1797
|
+
return true;
|
|
1798
|
+
}
|
|
1799
|
+
function InGroup(pattern) {
|
|
1800
|
+
return pattern.slice(1, pattern.length - 1);
|
|
1801
|
+
}
|
|
1802
|
+
function IsPrecedenceOr(pattern) {
|
|
1803
|
+
let count = 0;
|
|
1804
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1805
|
+
if (IsOpenParen(pattern, index))
|
|
1806
|
+
count += 1;
|
|
1807
|
+
if (IsCloseParen(pattern, index))
|
|
1808
|
+
count -= 1;
|
|
1809
|
+
if (IsSeparator(pattern, index) && count === 0)
|
|
1810
|
+
return true;
|
|
1811
|
+
}
|
|
1812
|
+
return false;
|
|
1813
|
+
}
|
|
1814
|
+
function IsPrecedenceAnd(pattern) {
|
|
1815
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1816
|
+
if (IsOpenParen(pattern, index))
|
|
1817
|
+
return true;
|
|
1818
|
+
}
|
|
1819
|
+
return false;
|
|
1820
|
+
}
|
|
1821
|
+
function Or(pattern) {
|
|
1822
|
+
let [count, start] = [0, 0];
|
|
1823
|
+
const expressions = [];
|
|
1824
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1825
|
+
if (IsOpenParen(pattern, index))
|
|
1826
|
+
count += 1;
|
|
1827
|
+
if (IsCloseParen(pattern, index))
|
|
1828
|
+
count -= 1;
|
|
1829
|
+
if (IsSeparator(pattern, index) && count === 0) {
|
|
1830
|
+
const range2 = pattern.slice(start, index);
|
|
1831
|
+
if (range2.length > 0)
|
|
1832
|
+
expressions.push(TemplateLiteralParse(range2));
|
|
1833
|
+
start = index + 1;
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
const range = pattern.slice(start);
|
|
1837
|
+
if (range.length > 0)
|
|
1838
|
+
expressions.push(TemplateLiteralParse(range));
|
|
1839
|
+
if (expressions.length === 0)
|
|
1840
|
+
return { type: "const", const: "" };
|
|
1841
|
+
if (expressions.length === 1)
|
|
1842
|
+
return expressions[0];
|
|
1843
|
+
return { type: "or", expr: expressions };
|
|
1844
|
+
}
|
|
1845
|
+
function And(pattern) {
|
|
1846
|
+
function Group(value, index) {
|
|
1847
|
+
if (!IsOpenParen(value, index))
|
|
1848
|
+
throw new TemplateLiteralParserError(`TemplateLiteralParser: Index must point to open parens`);
|
|
1849
|
+
let count = 0;
|
|
1850
|
+
for (let scan = index; scan < value.length; scan++) {
|
|
1851
|
+
if (IsOpenParen(value, scan))
|
|
1852
|
+
count += 1;
|
|
1853
|
+
if (IsCloseParen(value, scan))
|
|
1854
|
+
count -= 1;
|
|
1855
|
+
if (count === 0)
|
|
1856
|
+
return [index, scan];
|
|
1857
|
+
}
|
|
1858
|
+
throw new TemplateLiteralParserError(`TemplateLiteralParser: Unclosed group parens in expression`);
|
|
1859
|
+
}
|
|
1860
|
+
function Range(pattern2, index) {
|
|
1861
|
+
for (let scan = index; scan < pattern2.length; scan++) {
|
|
1862
|
+
if (IsOpenParen(pattern2, scan))
|
|
1863
|
+
return [index, scan];
|
|
1864
|
+
}
|
|
1865
|
+
return [index, pattern2.length];
|
|
1866
|
+
}
|
|
1867
|
+
const expressions = [];
|
|
1868
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
1869
|
+
if (IsOpenParen(pattern, index)) {
|
|
1870
|
+
const [start, end] = Group(pattern, index);
|
|
1871
|
+
const range = pattern.slice(start, end + 1);
|
|
1872
|
+
expressions.push(TemplateLiteralParse(range));
|
|
1873
|
+
index = end;
|
|
1874
|
+
} else {
|
|
1875
|
+
const [start, end] = Range(pattern, index);
|
|
1876
|
+
const range = pattern.slice(start, end);
|
|
1877
|
+
if (range.length > 0)
|
|
1878
|
+
expressions.push(TemplateLiteralParse(range));
|
|
1879
|
+
index = end - 1;
|
|
1880
|
+
}
|
|
1881
|
+
}
|
|
1882
|
+
return expressions.length === 0 ? { type: "const", const: "" } : expressions.length === 1 ? expressions[0] : { type: "and", expr: expressions };
|
|
1883
|
+
}
|
|
1884
|
+
function TemplateLiteralParse(pattern) {
|
|
1885
|
+
return IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) : IsPrecedenceOr(pattern) ? Or(pattern) : IsPrecedenceAnd(pattern) ? And(pattern) : { type: "const", const: Unescape(pattern) };
|
|
1886
|
+
}
|
|
1887
|
+
function TemplateLiteralParseExact(pattern) {
|
|
1888
|
+
return TemplateLiteralParse(pattern.slice(1, pattern.length - 1));
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
// node_modules/@sinclair/typebox/build/esm/type/template-literal/finite.mjs
|
|
1892
|
+
var TemplateLiteralFiniteError = class extends TypeBoxError {
|
|
1893
|
+
};
|
|
1894
|
+
function IsNumberExpression(expression) {
|
|
1895
|
+
return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "0" && expression.expr[1].type === "const" && expression.expr[1].const === "[1-9][0-9]*";
|
|
1896
|
+
}
|
|
1897
|
+
function IsBooleanExpression(expression) {
|
|
1898
|
+
return expression.type === "or" && expression.expr.length === 2 && expression.expr[0].type === "const" && expression.expr[0].const === "true" && expression.expr[1].type === "const" && expression.expr[1].const === "false";
|
|
1899
|
+
}
|
|
1900
|
+
function IsStringExpression(expression) {
|
|
1901
|
+
return expression.type === "const" && expression.const === ".*";
|
|
1902
|
+
}
|
|
1903
|
+
function IsTemplateLiteralExpressionFinite(expression) {
|
|
1904
|
+
return IsNumberExpression(expression) || IsStringExpression(expression) ? false : IsBooleanExpression(expression) ? true : expression.type === "and" ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) : expression.type === "or" ? expression.expr.every((expr) => IsTemplateLiteralExpressionFinite(expr)) : expression.type === "const" ? true : (() => {
|
|
1905
|
+
throw new TemplateLiteralFiniteError(`Unknown expression type`);
|
|
1906
|
+
})();
|
|
1907
|
+
}
|
|
1908
|
+
function IsTemplateLiteralFinite(schema) {
|
|
1909
|
+
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
1910
|
+
return IsTemplateLiteralExpressionFinite(expression);
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
// node_modules/@sinclair/typebox/build/esm/type/template-literal/generate.mjs
|
|
1914
|
+
var TemplateLiteralGenerateError = class extends TypeBoxError {
|
|
1915
|
+
};
|
|
1916
|
+
function* GenerateReduce(buffer) {
|
|
1917
|
+
if (buffer.length === 1)
|
|
1918
|
+
return yield* buffer[0];
|
|
1919
|
+
for (const left of buffer[0]) {
|
|
1920
|
+
for (const right of GenerateReduce(buffer.slice(1))) {
|
|
1921
|
+
yield `${left}${right}`;
|
|
1922
|
+
}
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
function* GenerateAnd(expression) {
|
|
1926
|
+
return yield* GenerateReduce(expression.expr.map((expr) => [...TemplateLiteralExpressionGenerate(expr)]));
|
|
1927
|
+
}
|
|
1928
|
+
function* GenerateOr(expression) {
|
|
1929
|
+
for (const expr of expression.expr)
|
|
1930
|
+
yield* TemplateLiteralExpressionGenerate(expr);
|
|
1931
|
+
}
|
|
1932
|
+
function* GenerateConst(expression) {
|
|
1933
|
+
return yield expression.const;
|
|
1934
|
+
}
|
|
1935
|
+
function* TemplateLiteralExpressionGenerate(expression) {
|
|
1936
|
+
return expression.type === "and" ? yield* GenerateAnd(expression) : expression.type === "or" ? yield* GenerateOr(expression) : expression.type === "const" ? yield* GenerateConst(expression) : (() => {
|
|
1937
|
+
throw new TemplateLiteralGenerateError("Unknown expression");
|
|
1938
|
+
})();
|
|
1939
|
+
}
|
|
1940
|
+
function TemplateLiteralGenerate(schema) {
|
|
1941
|
+
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
1942
|
+
return IsTemplateLiteralExpressionFinite(expression) ? [...TemplateLiteralExpressionGenerate(expression)] : [];
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
// node_modules/@sinclair/typebox/build/esm/type/literal/literal.mjs
|
|
1946
|
+
function Literal(value, options) {
|
|
1947
|
+
return CreateType({
|
|
1948
|
+
[Kind]: "Literal",
|
|
1949
|
+
const: value,
|
|
1950
|
+
type: typeof value
|
|
1951
|
+
}, options);
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
// node_modules/@sinclair/typebox/build/esm/type/boolean/boolean.mjs
|
|
1955
|
+
function Boolean2(options) {
|
|
1956
|
+
return CreateType({ [Kind]: "Boolean", type: "boolean" }, options);
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1959
|
+
// node_modules/@sinclair/typebox/build/esm/type/bigint/bigint.mjs
|
|
1960
|
+
function BigInt(options) {
|
|
1961
|
+
return CreateType({ [Kind]: "BigInt", type: "bigint" }, options);
|
|
1962
|
+
}
|
|
1963
|
+
|
|
1964
|
+
// node_modules/@sinclair/typebox/build/esm/type/number/number.mjs
|
|
1965
|
+
function Number2(options) {
|
|
1966
|
+
return CreateType({ [Kind]: "Number", type: "number" }, options);
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
// node_modules/@sinclair/typebox/build/esm/type/string/string.mjs
|
|
1970
|
+
function String2(options) {
|
|
1971
|
+
return CreateType({ [Kind]: "String", type: "string" }, options);
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
// node_modules/@sinclair/typebox/build/esm/type/template-literal/syntax.mjs
|
|
1975
|
+
function* FromUnion(syntax) {
|
|
1976
|
+
const trim = syntax.trim().replace(/"|'/g, "");
|
|
1977
|
+
return trim === "boolean" ? yield Boolean2() : trim === "number" ? yield Number2() : trim === "bigint" ? yield BigInt() : trim === "string" ? yield String2() : yield (() => {
|
|
1978
|
+
const literals = trim.split("|").map((literal) => Literal(literal.trim()));
|
|
1979
|
+
return literals.length === 0 ? Never() : literals.length === 1 ? literals[0] : UnionEvaluated(literals);
|
|
1980
|
+
})();
|
|
1981
|
+
}
|
|
1982
|
+
function* FromTerminal(syntax) {
|
|
1983
|
+
if (syntax[1] !== "{") {
|
|
1984
|
+
const L = Literal("$");
|
|
1985
|
+
const R = FromSyntax(syntax.slice(1));
|
|
1986
|
+
return yield* [L, ...R];
|
|
1987
|
+
}
|
|
1988
|
+
for (let i = 2; i < syntax.length; i++) {
|
|
1989
|
+
if (syntax[i] === "}") {
|
|
1990
|
+
const L = FromUnion(syntax.slice(2, i));
|
|
1991
|
+
const R = FromSyntax(syntax.slice(i + 1));
|
|
1992
|
+
return yield* [...L, ...R];
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
yield Literal(syntax);
|
|
1996
|
+
}
|
|
1997
|
+
function* FromSyntax(syntax) {
|
|
1998
|
+
for (let i = 0; i < syntax.length; i++) {
|
|
1999
|
+
if (syntax[i] === "$") {
|
|
2000
|
+
const L = Literal(syntax.slice(0, i));
|
|
2001
|
+
const R = FromTerminal(syntax.slice(i));
|
|
2002
|
+
return yield* [L, ...R];
|
|
2003
|
+
}
|
|
2004
|
+
}
|
|
2005
|
+
yield Literal(syntax);
|
|
2006
|
+
}
|
|
2007
|
+
function TemplateLiteralSyntax(syntax) {
|
|
2008
|
+
return [...FromSyntax(syntax)];
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
// node_modules/@sinclair/typebox/build/esm/type/template-literal/pattern.mjs
|
|
2012
|
+
var TemplateLiteralPatternError = class extends TypeBoxError {
|
|
2013
|
+
};
|
|
2014
|
+
function Escape(value) {
|
|
2015
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2016
|
+
}
|
|
2017
|
+
function Visit2(schema, acc) {
|
|
2018
|
+
return IsTemplateLiteral(schema) ? schema.pattern.slice(1, schema.pattern.length - 1) : IsUnion(schema) ? `(${schema.anyOf.map((schema2) => Visit2(schema2, acc)).join("|")})` : IsNumber3(schema) ? `${acc}${PatternNumber}` : IsInteger(schema) ? `${acc}${PatternNumber}` : IsBigInt2(schema) ? `${acc}${PatternNumber}` : IsString2(schema) ? `${acc}${PatternString}` : IsLiteral(schema) ? `${acc}${Escape(schema.const.toString())}` : IsBoolean2(schema) ? `${acc}${PatternBoolean}` : (() => {
|
|
2019
|
+
throw new TemplateLiteralPatternError(`Unexpected Kind '${schema[Kind]}'`);
|
|
2020
|
+
})();
|
|
2021
|
+
}
|
|
2022
|
+
function TemplateLiteralPattern(kinds) {
|
|
2023
|
+
return `^${kinds.map((schema) => Visit2(schema, "")).join("")}$`;
|
|
2024
|
+
}
|
|
2025
|
+
|
|
2026
|
+
// node_modules/@sinclair/typebox/build/esm/type/template-literal/union.mjs
|
|
2027
|
+
function TemplateLiteralToUnion(schema) {
|
|
2028
|
+
const R = TemplateLiteralGenerate(schema);
|
|
2029
|
+
const L = R.map((S) => Literal(S));
|
|
2030
|
+
return UnionEvaluated(L);
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
// node_modules/@sinclair/typebox/build/esm/type/template-literal/template-literal.mjs
|
|
2034
|
+
function TemplateLiteral(unresolved, options) {
|
|
2035
|
+
const pattern = IsString(unresolved) ? TemplateLiteralPattern(TemplateLiteralSyntax(unresolved)) : TemplateLiteralPattern(unresolved);
|
|
2036
|
+
return CreateType({ [Kind]: "TemplateLiteral", type: "string", pattern }, options);
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
// node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-property-keys.mjs
|
|
2040
|
+
function FromTemplateLiteral(templateLiteral) {
|
|
2041
|
+
const keys = TemplateLiteralGenerate(templateLiteral);
|
|
2042
|
+
return keys.map((key) => key.toString());
|
|
2043
|
+
}
|
|
2044
|
+
function FromUnion2(types) {
|
|
2045
|
+
const result = [];
|
|
2046
|
+
for (const type of types)
|
|
2047
|
+
result.push(...IndexPropertyKeys(type));
|
|
2048
|
+
return result;
|
|
2049
|
+
}
|
|
2050
|
+
function FromLiteral(literalValue) {
|
|
2051
|
+
return [literalValue.toString()];
|
|
2052
|
+
}
|
|
2053
|
+
function IndexPropertyKeys(type) {
|
|
2054
|
+
return [...new Set(IsTemplateLiteral(type) ? FromTemplateLiteral(type) : IsUnion(type) ? FromUnion2(type.anyOf) : IsLiteral(type) ? FromLiteral(type.const) : IsNumber3(type) ? ["[number]"] : IsInteger(type) ? ["[number]"] : [])];
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
// node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-from-mapped-result.mjs
|
|
2058
|
+
function FromProperties(type, properties, options) {
|
|
2059
|
+
const result = {};
|
|
2060
|
+
for (const K2 of Object.getOwnPropertyNames(properties)) {
|
|
2061
|
+
result[K2] = Index(type, IndexPropertyKeys(properties[K2]), options);
|
|
2062
|
+
}
|
|
2063
|
+
return result;
|
|
2064
|
+
}
|
|
2065
|
+
function FromMappedResult(type, mappedResult, options) {
|
|
2066
|
+
return FromProperties(type, mappedResult.properties, options);
|
|
2067
|
+
}
|
|
2068
|
+
function IndexFromMappedResult(type, mappedResult, options) {
|
|
2069
|
+
const properties = FromMappedResult(type, mappedResult, options);
|
|
2070
|
+
return MappedResult(properties);
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
// node_modules/@sinclair/typebox/build/esm/type/indexed/indexed.mjs
|
|
2074
|
+
function FromRest(types, key) {
|
|
2075
|
+
return types.map((type) => IndexFromPropertyKey(type, key));
|
|
2076
|
+
}
|
|
2077
|
+
function FromIntersectRest(types) {
|
|
2078
|
+
return types.filter((type) => !IsNever(type));
|
|
2079
|
+
}
|
|
2080
|
+
function FromIntersect(types, key) {
|
|
2081
|
+
return IntersectEvaluated(FromIntersectRest(FromRest(types, key)));
|
|
2082
|
+
}
|
|
2083
|
+
function FromUnionRest(types) {
|
|
2084
|
+
return types.some((L) => IsNever(L)) ? [] : types;
|
|
2085
|
+
}
|
|
2086
|
+
function FromUnion3(types, key) {
|
|
2087
|
+
return UnionEvaluated(FromUnionRest(FromRest(types, key)));
|
|
2088
|
+
}
|
|
2089
|
+
function FromTuple(types, key) {
|
|
2090
|
+
return key in types ? types[key] : key === "[number]" ? UnionEvaluated(types) : Never();
|
|
2091
|
+
}
|
|
2092
|
+
function FromArray(type, key) {
|
|
2093
|
+
return key === "[number]" ? type : Never();
|
|
2094
|
+
}
|
|
2095
|
+
function FromProperty(properties, propertyKey) {
|
|
2096
|
+
return propertyKey in properties ? properties[propertyKey] : Never();
|
|
2097
|
+
}
|
|
2098
|
+
function IndexFromPropertyKey(type, propertyKey) {
|
|
2099
|
+
return IsIntersect(type) ? FromIntersect(type.allOf, propertyKey) : IsUnion(type) ? FromUnion3(type.anyOf, propertyKey) : IsTuple(type) ? FromTuple(type.items ?? [], propertyKey) : IsArray3(type) ? FromArray(type.items, propertyKey) : IsObject3(type) ? FromProperty(type.properties, propertyKey) : Never();
|
|
2100
|
+
}
|
|
2101
|
+
function IndexFromPropertyKeys(type, propertyKeys) {
|
|
2102
|
+
return propertyKeys.map((propertyKey) => IndexFromPropertyKey(type, propertyKey));
|
|
2103
|
+
}
|
|
2104
|
+
function FromSchema(type, propertyKeys) {
|
|
2105
|
+
return UnionEvaluated(IndexFromPropertyKeys(type, propertyKeys));
|
|
2106
|
+
}
|
|
2107
|
+
function Index(type, key, options) {
|
|
2108
|
+
if (IsRef(type) || IsRef(key)) {
|
|
2109
|
+
const error = `Index types using Ref parameters require both Type and Key to be of TSchema`;
|
|
2110
|
+
if (!IsSchema(type) || !IsSchema(key))
|
|
2111
|
+
throw new TypeBoxError(error);
|
|
2112
|
+
return Computed("Index", [type, key]);
|
|
2113
|
+
}
|
|
2114
|
+
if (IsMappedResult(key))
|
|
2115
|
+
return IndexFromMappedResult(type, key, options);
|
|
2116
|
+
if (IsMappedKey(key))
|
|
2117
|
+
return IndexFromMappedKey(type, key, options);
|
|
2118
|
+
return CreateType(IsSchema(key) ? FromSchema(type, IndexPropertyKeys(key)) : FromSchema(type, key), options);
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
// node_modules/@sinclair/typebox/build/esm/type/indexed/indexed-from-mapped-key.mjs
|
|
2122
|
+
function MappedIndexPropertyKey(type, key, options) {
|
|
2123
|
+
return { [key]: Index(type, [key], Clone(options)) };
|
|
2124
|
+
}
|
|
2125
|
+
function MappedIndexPropertyKeys(type, propertyKeys, options) {
|
|
2126
|
+
return propertyKeys.reduce((result, left) => {
|
|
2127
|
+
return { ...result, ...MappedIndexPropertyKey(type, left, options) };
|
|
2128
|
+
}, {});
|
|
2129
|
+
}
|
|
2130
|
+
function MappedIndexProperties(type, mappedKey, options) {
|
|
2131
|
+
return MappedIndexPropertyKeys(type, mappedKey.keys, options);
|
|
2132
|
+
}
|
|
2133
|
+
function IndexFromMappedKey(type, mappedKey, options) {
|
|
2134
|
+
const properties = MappedIndexProperties(type, mappedKey, options);
|
|
2135
|
+
return MappedResult(properties);
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2138
|
+
// node_modules/@sinclair/typebox/build/esm/type/iterator/iterator.mjs
|
|
2139
|
+
function Iterator(items, options) {
|
|
2140
|
+
return CreateType({ [Kind]: "Iterator", type: "Iterator", items }, options);
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
// node_modules/@sinclair/typebox/build/esm/type/object/object.mjs
|
|
2144
|
+
function RequiredArray(properties) {
|
|
2145
|
+
return globalThis.Object.keys(properties).filter((key) => !IsOptional(properties[key]));
|
|
2146
|
+
}
|
|
2147
|
+
function _Object_(properties, options) {
|
|
2148
|
+
const required = RequiredArray(properties);
|
|
2149
|
+
const schema = required.length > 0 ? { [Kind]: "Object", type: "object", required, properties } : { [Kind]: "Object", type: "object", properties };
|
|
2150
|
+
return CreateType(schema, options);
|
|
2151
|
+
}
|
|
2152
|
+
var Object2 = _Object_;
|
|
2153
|
+
|
|
2154
|
+
// node_modules/@sinclair/typebox/build/esm/type/promise/promise.mjs
|
|
2155
|
+
function Promise2(item, options) {
|
|
2156
|
+
return CreateType({ [Kind]: "Promise", type: "Promise", item }, options);
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
// node_modules/@sinclair/typebox/build/esm/type/readonly/readonly.mjs
|
|
2160
|
+
function RemoveReadonly(schema) {
|
|
2161
|
+
return CreateType(Discard(schema, [ReadonlyKind]));
|
|
2162
|
+
}
|
|
2163
|
+
function AddReadonly(schema) {
|
|
2164
|
+
return CreateType({ ...schema, [ReadonlyKind]: "Readonly" });
|
|
2165
|
+
}
|
|
2166
|
+
function ReadonlyWithFlag(schema, F) {
|
|
2167
|
+
return F === false ? RemoveReadonly(schema) : AddReadonly(schema);
|
|
2168
|
+
}
|
|
2169
|
+
function Readonly(schema, enable) {
|
|
2170
|
+
const F = enable ?? true;
|
|
2171
|
+
return IsMappedResult(schema) ? ReadonlyFromMappedResult(schema, F) : ReadonlyWithFlag(schema, F);
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
// node_modules/@sinclair/typebox/build/esm/type/readonly/readonly-from-mapped-result.mjs
|
|
2175
|
+
function FromProperties2(K, F) {
|
|
2176
|
+
const Acc = {};
|
|
2177
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
2178
|
+
Acc[K2] = Readonly(K[K2], F);
|
|
2179
|
+
return Acc;
|
|
2180
|
+
}
|
|
2181
|
+
function FromMappedResult2(R, F) {
|
|
2182
|
+
return FromProperties2(R.properties, F);
|
|
2183
|
+
}
|
|
2184
|
+
function ReadonlyFromMappedResult(R, F) {
|
|
2185
|
+
const P = FromMappedResult2(R, F);
|
|
2186
|
+
return MappedResult(P);
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
// node_modules/@sinclair/typebox/build/esm/type/tuple/tuple.mjs
|
|
2190
|
+
function Tuple(types, options) {
|
|
2191
|
+
return CreateType(types.length > 0 ? { [Kind]: "Tuple", type: "array", items: types, additionalItems: false, minItems: types.length, maxItems: types.length } : { [Kind]: "Tuple", type: "array", minItems: types.length, maxItems: types.length }, options);
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
// node_modules/@sinclair/typebox/build/esm/type/mapped/mapped.mjs
|
|
2195
|
+
function FromMappedResult3(K, P) {
|
|
2196
|
+
return K in P ? FromSchemaType(K, P[K]) : MappedResult(P);
|
|
2197
|
+
}
|
|
2198
|
+
function MappedKeyToKnownMappedResultProperties(K) {
|
|
2199
|
+
return { [K]: Literal(K) };
|
|
2200
|
+
}
|
|
2201
|
+
function MappedKeyToUnknownMappedResultProperties(P) {
|
|
2202
|
+
const Acc = {};
|
|
2203
|
+
for (const L of P)
|
|
2204
|
+
Acc[L] = Literal(L);
|
|
2205
|
+
return Acc;
|
|
2206
|
+
}
|
|
2207
|
+
function MappedKeyToMappedResultProperties(K, P) {
|
|
2208
|
+
return SetIncludes(P, K) ? MappedKeyToKnownMappedResultProperties(K) : MappedKeyToUnknownMappedResultProperties(P);
|
|
2209
|
+
}
|
|
2210
|
+
function FromMappedKey(K, P) {
|
|
2211
|
+
const R = MappedKeyToMappedResultProperties(K, P);
|
|
2212
|
+
return FromMappedResult3(K, R);
|
|
2213
|
+
}
|
|
2214
|
+
function FromRest2(K, T) {
|
|
2215
|
+
return T.map((L) => FromSchemaType(K, L));
|
|
2216
|
+
}
|
|
2217
|
+
function FromProperties3(K, T) {
|
|
2218
|
+
const Acc = {};
|
|
2219
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(T))
|
|
2220
|
+
Acc[K2] = FromSchemaType(K, T[K2]);
|
|
2221
|
+
return Acc;
|
|
2222
|
+
}
|
|
2223
|
+
function FromSchemaType(K, T) {
|
|
2224
|
+
const options = { ...T };
|
|
2225
|
+
return (
|
|
2226
|
+
// unevaluated modifier types
|
|
2227
|
+
IsOptional(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) : IsReadonly(T) ? Readonly(FromSchemaType(K, Discard(T, [ReadonlyKind]))) : (
|
|
2228
|
+
// unevaluated mapped types
|
|
2229
|
+
IsMappedResult(T) ? FromMappedResult3(K, T.properties) : IsMappedKey(T) ? FromMappedKey(K, T.keys) : (
|
|
2230
|
+
// unevaluated types
|
|
2231
|
+
IsConstructor(T) ? Constructor(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) : IsFunction2(T) ? Function(FromRest2(K, T.parameters), FromSchemaType(K, T.returns), options) : IsAsyncIterator2(T) ? AsyncIterator(FromSchemaType(K, T.items), options) : IsIterator2(T) ? Iterator(FromSchemaType(K, T.items), options) : IsIntersect(T) ? Intersect(FromRest2(K, T.allOf), options) : IsUnion(T) ? Union(FromRest2(K, T.anyOf), options) : IsTuple(T) ? Tuple(FromRest2(K, T.items ?? []), options) : IsObject3(T) ? Object2(FromProperties3(K, T.properties), options) : IsArray3(T) ? Array2(FromSchemaType(K, T.items), options) : IsPromise(T) ? Promise2(FromSchemaType(K, T.item), options) : T
|
|
2232
|
+
)
|
|
2233
|
+
)
|
|
2234
|
+
);
|
|
2235
|
+
}
|
|
2236
|
+
function MappedFunctionReturnType(K, T) {
|
|
2237
|
+
const Acc = {};
|
|
2238
|
+
for (const L of K)
|
|
2239
|
+
Acc[L] = FromSchemaType(L, T);
|
|
2240
|
+
return Acc;
|
|
2241
|
+
}
|
|
2242
|
+
function Mapped(key, map, options) {
|
|
2243
|
+
const K = IsSchema(key) ? IndexPropertyKeys(key) : key;
|
|
2244
|
+
const RT = map({ [Kind]: "MappedKey", keys: K });
|
|
2245
|
+
const R = MappedFunctionReturnType(K, RT);
|
|
2246
|
+
return Object2(R, options);
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
// node_modules/@sinclair/typebox/build/esm/type/optional/optional.mjs
|
|
2250
|
+
function RemoveOptional(schema) {
|
|
2251
|
+
return CreateType(Discard(schema, [OptionalKind]));
|
|
2252
|
+
}
|
|
2253
|
+
function AddOptional(schema) {
|
|
2254
|
+
return CreateType({ ...schema, [OptionalKind]: "Optional" });
|
|
2255
|
+
}
|
|
2256
|
+
function OptionalWithFlag(schema, F) {
|
|
2257
|
+
return F === false ? RemoveOptional(schema) : AddOptional(schema);
|
|
2258
|
+
}
|
|
2259
|
+
function Optional(schema, enable) {
|
|
2260
|
+
const F = enable ?? true;
|
|
2261
|
+
return IsMappedResult(schema) ? OptionalFromMappedResult(schema, F) : OptionalWithFlag(schema, F);
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
// node_modules/@sinclair/typebox/build/esm/type/optional/optional-from-mapped-result.mjs
|
|
2265
|
+
function FromProperties4(P, F) {
|
|
2266
|
+
const Acc = {};
|
|
2267
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
2268
|
+
Acc[K2] = Optional(P[K2], F);
|
|
2269
|
+
return Acc;
|
|
2270
|
+
}
|
|
2271
|
+
function FromMappedResult4(R, F) {
|
|
2272
|
+
return FromProperties4(R.properties, F);
|
|
2273
|
+
}
|
|
2274
|
+
function OptionalFromMappedResult(R, F) {
|
|
2275
|
+
const P = FromMappedResult4(R, F);
|
|
2276
|
+
return MappedResult(P);
|
|
2277
|
+
}
|
|
2278
|
+
|
|
2279
|
+
// node_modules/@sinclair/typebox/build/esm/type/intersect/intersect-create.mjs
|
|
2280
|
+
function IntersectCreate(T, options = {}) {
|
|
2281
|
+
const allObjects = T.every((schema) => IsObject3(schema));
|
|
2282
|
+
const clonedUnevaluatedProperties = IsSchema(options.unevaluatedProperties) ? { unevaluatedProperties: options.unevaluatedProperties } : {};
|
|
2283
|
+
return CreateType(options.unevaluatedProperties === false || IsSchema(options.unevaluatedProperties) || allObjects ? { ...clonedUnevaluatedProperties, [Kind]: "Intersect", type: "object", allOf: T } : { ...clonedUnevaluatedProperties, [Kind]: "Intersect", allOf: T }, options);
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
// node_modules/@sinclair/typebox/build/esm/type/intersect/intersect-evaluated.mjs
|
|
2287
|
+
function IsIntersectOptional(types) {
|
|
2288
|
+
return types.every((left) => IsOptional(left));
|
|
2289
|
+
}
|
|
2290
|
+
function RemoveOptionalFromType2(type) {
|
|
2291
|
+
return Discard(type, [OptionalKind]);
|
|
2292
|
+
}
|
|
2293
|
+
function RemoveOptionalFromRest2(types) {
|
|
2294
|
+
return types.map((left) => IsOptional(left) ? RemoveOptionalFromType2(left) : left);
|
|
2295
|
+
}
|
|
2296
|
+
function ResolveIntersect(types, options) {
|
|
2297
|
+
return IsIntersectOptional(types) ? Optional(IntersectCreate(RemoveOptionalFromRest2(types), options)) : IntersectCreate(RemoveOptionalFromRest2(types), options);
|
|
2298
|
+
}
|
|
2299
|
+
function IntersectEvaluated(types, options = {}) {
|
|
2300
|
+
if (types.length === 1)
|
|
2301
|
+
return CreateType(types[0], options);
|
|
2302
|
+
if (types.length === 0)
|
|
2303
|
+
return Never(options);
|
|
2304
|
+
if (types.some((schema) => IsTransform(schema)))
|
|
2305
|
+
throw new Error("Cannot intersect transform types");
|
|
2306
|
+
return ResolveIntersect(types, options);
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
// node_modules/@sinclair/typebox/build/esm/type/intersect/intersect.mjs
|
|
2310
|
+
function Intersect(types, options) {
|
|
2311
|
+
if (types.length === 1)
|
|
2312
|
+
return CreateType(types[0], options);
|
|
2313
|
+
if (types.length === 0)
|
|
2314
|
+
return Never(options);
|
|
2315
|
+
if (types.some((schema) => IsTransform(schema)))
|
|
2316
|
+
throw new Error("Cannot intersect transform types");
|
|
2317
|
+
return IntersectCreate(types, options);
|
|
2318
|
+
}
|
|
2319
|
+
|
|
2320
|
+
// node_modules/@sinclair/typebox/build/esm/type/ref/ref.mjs
|
|
2321
|
+
function Ref(...args) {
|
|
2322
|
+
const [$ref, options] = typeof args[0] === "string" ? [args[0], args[1]] : [args[0].$id, args[1]];
|
|
2323
|
+
if (typeof $ref !== "string")
|
|
2324
|
+
throw new TypeBoxError("Ref: $ref must be a string");
|
|
2325
|
+
return CreateType({ [Kind]: "Ref", $ref }, options);
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
// node_modules/@sinclair/typebox/build/esm/type/awaited/awaited.mjs
|
|
2329
|
+
function FromComputed(target, parameters) {
|
|
2330
|
+
return Computed("Awaited", [Computed(target, parameters)]);
|
|
2331
|
+
}
|
|
2332
|
+
function FromRef($ref) {
|
|
2333
|
+
return Computed("Awaited", [Ref($ref)]);
|
|
2334
|
+
}
|
|
2335
|
+
function FromIntersect2(types) {
|
|
2336
|
+
return Intersect(FromRest3(types));
|
|
2337
|
+
}
|
|
2338
|
+
function FromUnion4(types) {
|
|
2339
|
+
return Union(FromRest3(types));
|
|
2340
|
+
}
|
|
2341
|
+
function FromPromise(type) {
|
|
2342
|
+
return Awaited(type);
|
|
2343
|
+
}
|
|
2344
|
+
function FromRest3(types) {
|
|
2345
|
+
return types.map((type) => Awaited(type));
|
|
2346
|
+
}
|
|
2347
|
+
function Awaited(type, options) {
|
|
2348
|
+
return CreateType(IsComputed(type) ? FromComputed(type.target, type.parameters) : IsIntersect(type) ? FromIntersect2(type.allOf) : IsUnion(type) ? FromUnion4(type.anyOf) : IsPromise(type) ? FromPromise(type.item) : IsRef(type) ? FromRef(type.$ref) : type, options);
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
// node_modules/@sinclair/typebox/build/esm/type/keyof/keyof-property-keys.mjs
|
|
2352
|
+
function FromRest4(types) {
|
|
2353
|
+
const result = [];
|
|
2354
|
+
for (const L of types)
|
|
2355
|
+
result.push(KeyOfPropertyKeys(L));
|
|
2356
|
+
return result;
|
|
2357
|
+
}
|
|
2358
|
+
function FromIntersect3(types) {
|
|
2359
|
+
const propertyKeysArray = FromRest4(types);
|
|
2360
|
+
const propertyKeys = SetUnionMany(propertyKeysArray);
|
|
2361
|
+
return propertyKeys;
|
|
2362
|
+
}
|
|
2363
|
+
function FromUnion5(types) {
|
|
2364
|
+
const propertyKeysArray = FromRest4(types);
|
|
2365
|
+
const propertyKeys = SetIntersectMany(propertyKeysArray);
|
|
2366
|
+
return propertyKeys;
|
|
2367
|
+
}
|
|
2368
|
+
function FromTuple2(types) {
|
|
2369
|
+
return types.map((_, indexer) => indexer.toString());
|
|
2370
|
+
}
|
|
2371
|
+
function FromArray2(_) {
|
|
2372
|
+
return ["[number]"];
|
|
2373
|
+
}
|
|
2374
|
+
function FromProperties5(T) {
|
|
2375
|
+
return globalThis.Object.getOwnPropertyNames(T);
|
|
2376
|
+
}
|
|
2377
|
+
function FromPatternProperties(patternProperties) {
|
|
2378
|
+
if (!includePatternProperties)
|
|
2379
|
+
return [];
|
|
2380
|
+
const patternPropertyKeys = globalThis.Object.getOwnPropertyNames(patternProperties);
|
|
2381
|
+
return patternPropertyKeys.map((key) => {
|
|
2382
|
+
return key[0] === "^" && key[key.length - 1] === "$" ? key.slice(1, key.length - 1) : key;
|
|
2383
|
+
});
|
|
2384
|
+
}
|
|
2385
|
+
function KeyOfPropertyKeys(type) {
|
|
2386
|
+
return IsIntersect(type) ? FromIntersect3(type.allOf) : IsUnion(type) ? FromUnion5(type.anyOf) : IsTuple(type) ? FromTuple2(type.items ?? []) : IsArray3(type) ? FromArray2(type.items) : IsObject3(type) ? FromProperties5(type.properties) : IsRecord(type) ? FromPatternProperties(type.patternProperties) : [];
|
|
2387
|
+
}
|
|
2388
|
+
var includePatternProperties = false;
|
|
2389
|
+
|
|
2390
|
+
// node_modules/@sinclair/typebox/build/esm/type/keyof/keyof.mjs
|
|
2391
|
+
function FromComputed2(target, parameters) {
|
|
2392
|
+
return Computed("KeyOf", [Computed(target, parameters)]);
|
|
2393
|
+
}
|
|
2394
|
+
function FromRef2($ref) {
|
|
2395
|
+
return Computed("KeyOf", [Ref($ref)]);
|
|
2396
|
+
}
|
|
2397
|
+
function KeyOfFromType(type, options) {
|
|
2398
|
+
const propertyKeys = KeyOfPropertyKeys(type);
|
|
2399
|
+
const propertyKeyTypes = KeyOfPropertyKeysToRest(propertyKeys);
|
|
2400
|
+
const result = UnionEvaluated(propertyKeyTypes);
|
|
2401
|
+
return CreateType(result, options);
|
|
2402
|
+
}
|
|
2403
|
+
function KeyOfPropertyKeysToRest(propertyKeys) {
|
|
2404
|
+
return propertyKeys.map((L) => L === "[number]" ? Number2() : Literal(L));
|
|
2405
|
+
}
|
|
2406
|
+
function KeyOf(type, options) {
|
|
2407
|
+
return IsComputed(type) ? FromComputed2(type.target, type.parameters) : IsRef(type) ? FromRef2(type.$ref) : IsMappedResult(type) ? KeyOfFromMappedResult(type, options) : KeyOfFromType(type, options);
|
|
2408
|
+
}
|
|
2409
|
+
|
|
2410
|
+
// node_modules/@sinclair/typebox/build/esm/type/keyof/keyof-from-mapped-result.mjs
|
|
2411
|
+
function FromProperties6(properties, options) {
|
|
2412
|
+
const result = {};
|
|
2413
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
|
|
2414
|
+
result[K2] = KeyOf(properties[K2], Clone(options));
|
|
2415
|
+
return result;
|
|
2416
|
+
}
|
|
2417
|
+
function FromMappedResult5(mappedResult, options) {
|
|
2418
|
+
return FromProperties6(mappedResult.properties, options);
|
|
2419
|
+
}
|
|
2420
|
+
function KeyOfFromMappedResult(mappedResult, options) {
|
|
2421
|
+
const properties = FromMappedResult5(mappedResult, options);
|
|
2422
|
+
return MappedResult(properties);
|
|
2423
|
+
}
|
|
2424
|
+
|
|
2425
|
+
// node_modules/@sinclair/typebox/build/esm/type/composite/composite.mjs
|
|
2426
|
+
function CompositeKeys(T) {
|
|
2427
|
+
const Acc = [];
|
|
2428
|
+
for (const L of T)
|
|
2429
|
+
Acc.push(...KeyOfPropertyKeys(L));
|
|
2430
|
+
return SetDistinct(Acc);
|
|
2431
|
+
}
|
|
2432
|
+
function FilterNever(T) {
|
|
2433
|
+
return T.filter((L) => !IsNever(L));
|
|
2434
|
+
}
|
|
2435
|
+
function CompositeProperty(T, K) {
|
|
2436
|
+
const Acc = [];
|
|
2437
|
+
for (const L of T)
|
|
2438
|
+
Acc.push(...IndexFromPropertyKeys(L, [K]));
|
|
2439
|
+
return FilterNever(Acc);
|
|
2440
|
+
}
|
|
2441
|
+
function CompositeProperties(T, K) {
|
|
2442
|
+
const Acc = {};
|
|
2443
|
+
for (const L of K) {
|
|
2444
|
+
Acc[L] = IntersectEvaluated(CompositeProperty(T, L));
|
|
2445
|
+
}
|
|
2446
|
+
return Acc;
|
|
2447
|
+
}
|
|
2448
|
+
function Composite(T, options) {
|
|
2449
|
+
const K = CompositeKeys(T);
|
|
2450
|
+
const P = CompositeProperties(T, K);
|
|
2451
|
+
const R = Object2(P, options);
|
|
2452
|
+
return R;
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
// node_modules/@sinclair/typebox/build/esm/type/date/date.mjs
|
|
2456
|
+
function Date2(options) {
|
|
2457
|
+
return CreateType({ [Kind]: "Date", type: "Date" }, options);
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
// node_modules/@sinclair/typebox/build/esm/type/null/null.mjs
|
|
2461
|
+
function Null(options) {
|
|
2462
|
+
return CreateType({ [Kind]: "Null", type: "null" }, options);
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
// node_modules/@sinclair/typebox/build/esm/type/symbol/symbol.mjs
|
|
2466
|
+
function Symbol2(options) {
|
|
2467
|
+
return CreateType({ [Kind]: "Symbol", type: "symbol" }, options);
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
// node_modules/@sinclair/typebox/build/esm/type/undefined/undefined.mjs
|
|
2471
|
+
function Undefined(options) {
|
|
2472
|
+
return CreateType({ [Kind]: "Undefined", type: "undefined" }, options);
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
// node_modules/@sinclair/typebox/build/esm/type/uint8array/uint8array.mjs
|
|
2476
|
+
function Uint8Array2(options) {
|
|
2477
|
+
return CreateType({ [Kind]: "Uint8Array", type: "Uint8Array" }, options);
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
// node_modules/@sinclair/typebox/build/esm/type/unknown/unknown.mjs
|
|
2481
|
+
function Unknown(options) {
|
|
2482
|
+
return CreateType({ [Kind]: "Unknown" }, options);
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
// node_modules/@sinclair/typebox/build/esm/type/const/const.mjs
|
|
2486
|
+
function FromArray3(T) {
|
|
2487
|
+
return T.map((L) => FromValue(L, false));
|
|
2488
|
+
}
|
|
2489
|
+
function FromProperties7(value) {
|
|
2490
|
+
const Acc = {};
|
|
2491
|
+
for (const K of globalThis.Object.getOwnPropertyNames(value))
|
|
2492
|
+
Acc[K] = Readonly(FromValue(value[K], false));
|
|
2493
|
+
return Acc;
|
|
2494
|
+
}
|
|
2495
|
+
function ConditionalReadonly(T, root) {
|
|
2496
|
+
return root === true ? T : Readonly(T);
|
|
2497
|
+
}
|
|
2498
|
+
function FromValue(value, root) {
|
|
2499
|
+
return IsAsyncIterator(value) ? ConditionalReadonly(Any(), root) : IsIterator(value) ? ConditionalReadonly(Any(), root) : IsArray(value) ? Readonly(Tuple(FromArray3(value))) : IsUint8Array(value) ? Uint8Array2() : IsDate(value) ? Date2() : IsObject(value) ? ConditionalReadonly(Object2(FromProperties7(value)), root) : IsFunction(value) ? ConditionalReadonly(Function([], Unknown()), root) : IsUndefined(value) ? Undefined() : IsNull(value) ? Null() : IsSymbol(value) ? Symbol2() : IsBigInt(value) ? BigInt() : IsNumber(value) ? Literal(value) : IsBoolean(value) ? Literal(value) : IsString(value) ? Literal(value) : Object2({});
|
|
2500
|
+
}
|
|
2501
|
+
function Const(T, options) {
|
|
2502
|
+
return CreateType(FromValue(T, true), options);
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
// node_modules/@sinclair/typebox/build/esm/type/constructor-parameters/constructor-parameters.mjs
|
|
2506
|
+
function ConstructorParameters(schema, options) {
|
|
2507
|
+
return IsConstructor(schema) ? Tuple(schema.parameters, options) : Never(options);
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
// node_modules/@sinclair/typebox/build/esm/type/enum/enum.mjs
|
|
2511
|
+
function Enum(item, options) {
|
|
2512
|
+
if (IsUndefined(item))
|
|
2513
|
+
throw new Error("Enum undefined or empty");
|
|
2514
|
+
const values1 = globalThis.Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
|
|
2515
|
+
const values2 = [...new Set(values1)];
|
|
2516
|
+
const anyOf = values2.map((value) => Literal(value));
|
|
2517
|
+
return Union(anyOf, { ...options, [Hint]: "Enum" });
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
// node_modules/@sinclair/typebox/build/esm/type/extends/extends-check.mjs
|
|
2521
|
+
var ExtendsResolverError = class extends TypeBoxError {
|
|
2522
|
+
};
|
|
2523
|
+
var ExtendsResult;
|
|
2524
|
+
(function(ExtendsResult2) {
|
|
2525
|
+
ExtendsResult2[ExtendsResult2["Union"] = 0] = "Union";
|
|
2526
|
+
ExtendsResult2[ExtendsResult2["True"] = 1] = "True";
|
|
2527
|
+
ExtendsResult2[ExtendsResult2["False"] = 2] = "False";
|
|
2528
|
+
})(ExtendsResult || (ExtendsResult = {}));
|
|
2529
|
+
function IntoBooleanResult(result) {
|
|
2530
|
+
return result === ExtendsResult.False ? result : ExtendsResult.True;
|
|
2531
|
+
}
|
|
2532
|
+
function Throw(message) {
|
|
2533
|
+
throw new ExtendsResolverError(message);
|
|
2534
|
+
}
|
|
2535
|
+
function IsStructuralRight(right) {
|
|
2536
|
+
return type_exports.IsNever(right) || type_exports.IsIntersect(right) || type_exports.IsUnion(right) || type_exports.IsUnknown(right) || type_exports.IsAny(right);
|
|
2537
|
+
}
|
|
2538
|
+
function StructuralRight(left, right) {
|
|
2539
|
+
return type_exports.IsNever(right) ? FromNeverRight(left, right) : type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsUnknown(right) ? FromUnknownRight(left, right) : type_exports.IsAny(right) ? FromAnyRight(left, right) : Throw("StructuralRight");
|
|
2540
|
+
}
|
|
2541
|
+
function FromAnyRight(left, right) {
|
|
2542
|
+
return ExtendsResult.True;
|
|
2543
|
+
}
|
|
2544
|
+
function FromAny(left, right) {
|
|
2545
|
+
return type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) && right.anyOf.some((schema) => type_exports.IsAny(schema) || type_exports.IsUnknown(schema)) ? ExtendsResult.True : type_exports.IsUnion(right) ? ExtendsResult.Union : type_exports.IsUnknown(right) ? ExtendsResult.True : type_exports.IsAny(right) ? ExtendsResult.True : ExtendsResult.Union;
|
|
2546
|
+
}
|
|
2547
|
+
function FromArrayRight(left, right) {
|
|
2548
|
+
return type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : type_exports.IsNever(left) ? ExtendsResult.True : ExtendsResult.False;
|
|
2549
|
+
}
|
|
2550
|
+
function FromArray4(left, right) {
|
|
2551
|
+
return type_exports.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsArray(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
|
|
2552
|
+
}
|
|
2553
|
+
function FromAsyncIterator(left, right) {
|
|
2554
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsAsyncIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
|
|
2555
|
+
}
|
|
2556
|
+
function FromBigInt(left, right) {
|
|
2557
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsBigInt(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2558
|
+
}
|
|
2559
|
+
function FromBooleanRight(left, right) {
|
|
2560
|
+
return type_exports.IsLiteralBoolean(left) ? ExtendsResult.True : type_exports.IsBoolean(left) ? ExtendsResult.True : ExtendsResult.False;
|
|
2561
|
+
}
|
|
2562
|
+
function FromBoolean(left, right) {
|
|
2563
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsBoolean(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2564
|
+
}
|
|
2565
|
+
function FromConstructor(left, right) {
|
|
2566
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsConstructor(right) ? ExtendsResult.False : left.parameters.length > right.parameters.length ? ExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit3(right.parameters[index], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.returns, right.returns));
|
|
2567
|
+
}
|
|
2568
|
+
function FromDate(left, right) {
|
|
2569
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsDate(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2570
|
+
}
|
|
2571
|
+
function FromFunction(left, right) {
|
|
2572
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsFunction(right) ? ExtendsResult.False : left.parameters.length > right.parameters.length ? ExtendsResult.False : !left.parameters.every((schema, index) => IntoBooleanResult(Visit3(right.parameters[index], schema)) === ExtendsResult.True) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.returns, right.returns));
|
|
2573
|
+
}
|
|
2574
|
+
function FromIntegerRight(left, right) {
|
|
2575
|
+
return type_exports.IsLiteral(left) && value_exports.IsNumber(left.const) ? ExtendsResult.True : type_exports.IsNumber(left) || type_exports.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False;
|
|
2576
|
+
}
|
|
2577
|
+
function FromInteger(left, right) {
|
|
2578
|
+
return type_exports.IsInteger(right) || type_exports.IsNumber(right) ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : ExtendsResult.False;
|
|
2579
|
+
}
|
|
2580
|
+
function FromIntersectRight(left, right) {
|
|
2581
|
+
return right.allOf.every((schema) => Visit3(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
|
|
2582
|
+
}
|
|
2583
|
+
function FromIntersect4(left, right) {
|
|
2584
|
+
return left.allOf.some((schema) => Visit3(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
|
|
2585
|
+
}
|
|
2586
|
+
function FromIterator(left, right) {
|
|
2587
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : !type_exports.IsIterator(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.items, right.items));
|
|
2588
|
+
}
|
|
2589
|
+
function FromLiteral2(left, right) {
|
|
2590
|
+
return type_exports.IsLiteral(right) && right.const === left.const ? ExtendsResult.True : IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsString(right) ? FromStringRight(left, right) : type_exports.IsNumber(right) ? FromNumberRight(left, right) : type_exports.IsInteger(right) ? FromIntegerRight(left, right) : type_exports.IsBoolean(right) ? FromBooleanRight(left, right) : ExtendsResult.False;
|
|
2591
|
+
}
|
|
2592
|
+
function FromNeverRight(left, right) {
|
|
2593
|
+
return ExtendsResult.False;
|
|
2594
|
+
}
|
|
2595
|
+
function FromNever(left, right) {
|
|
2596
|
+
return ExtendsResult.True;
|
|
2597
|
+
}
|
|
2598
|
+
function UnwrapTNot(schema) {
|
|
2599
|
+
let [current, depth] = [schema, 0];
|
|
2600
|
+
while (true) {
|
|
2601
|
+
if (!type_exports.IsNot(current))
|
|
2602
|
+
break;
|
|
2603
|
+
current = current.not;
|
|
2604
|
+
depth += 1;
|
|
2605
|
+
}
|
|
2606
|
+
return depth % 2 === 0 ? current : Unknown();
|
|
2607
|
+
}
|
|
2608
|
+
function FromNot(left, right) {
|
|
2609
|
+
return type_exports.IsNot(left) ? Visit3(UnwrapTNot(left), right) : type_exports.IsNot(right) ? Visit3(left, UnwrapTNot(right)) : Throw("Invalid fallthrough for Not");
|
|
2610
|
+
}
|
|
2611
|
+
function FromNull(left, right) {
|
|
2612
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsNull(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2613
|
+
}
|
|
2614
|
+
function FromNumberRight(left, right) {
|
|
2615
|
+
return type_exports.IsLiteralNumber(left) ? ExtendsResult.True : type_exports.IsNumber(left) || type_exports.IsInteger(left) ? ExtendsResult.True : ExtendsResult.False;
|
|
2616
|
+
}
|
|
2617
|
+
function FromNumber(left, right) {
|
|
2618
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsInteger(right) || type_exports.IsNumber(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2619
|
+
}
|
|
2620
|
+
function IsObjectPropertyCount(schema, count) {
|
|
2621
|
+
return Object.getOwnPropertyNames(schema.properties).length === count;
|
|
2622
|
+
}
|
|
2623
|
+
function IsObjectStringLike(schema) {
|
|
2624
|
+
return IsObjectArrayLike(schema);
|
|
2625
|
+
}
|
|
2626
|
+
function IsObjectSymbolLike(schema) {
|
|
2627
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "description" in schema.properties && type_exports.IsUnion(schema.properties.description) && schema.properties.description.anyOf.length === 2 && (type_exports.IsString(schema.properties.description.anyOf[0]) && type_exports.IsUndefined(schema.properties.description.anyOf[1]) || type_exports.IsString(schema.properties.description.anyOf[1]) && type_exports.IsUndefined(schema.properties.description.anyOf[0]));
|
|
2628
|
+
}
|
|
2629
|
+
function IsObjectNumberLike(schema) {
|
|
2630
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2631
|
+
}
|
|
2632
|
+
function IsObjectBooleanLike(schema) {
|
|
2633
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2634
|
+
}
|
|
2635
|
+
function IsObjectBigIntLike(schema) {
|
|
2636
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2637
|
+
}
|
|
2638
|
+
function IsObjectDateLike(schema) {
|
|
2639
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2640
|
+
}
|
|
2641
|
+
function IsObjectUint8ArrayLike(schema) {
|
|
2642
|
+
return IsObjectArrayLike(schema);
|
|
2643
|
+
}
|
|
2644
|
+
function IsObjectFunctionLike(schema) {
|
|
2645
|
+
const length = Number2();
|
|
2646
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit3(schema.properties["length"], length)) === ExtendsResult.True;
|
|
2647
|
+
}
|
|
2648
|
+
function IsObjectConstructorLike(schema) {
|
|
2649
|
+
return IsObjectPropertyCount(schema, 0);
|
|
2650
|
+
}
|
|
2651
|
+
function IsObjectArrayLike(schema) {
|
|
2652
|
+
const length = Number2();
|
|
2653
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "length" in schema.properties && IntoBooleanResult(Visit3(schema.properties["length"], length)) === ExtendsResult.True;
|
|
2654
|
+
}
|
|
2655
|
+
function IsObjectPromiseLike(schema) {
|
|
2656
|
+
const then = Function([Any()], Any());
|
|
2657
|
+
return IsObjectPropertyCount(schema, 0) || IsObjectPropertyCount(schema, 1) && "then" in schema.properties && IntoBooleanResult(Visit3(schema.properties["then"], then)) === ExtendsResult.True;
|
|
2658
|
+
}
|
|
2659
|
+
function Property(left, right) {
|
|
2660
|
+
return Visit3(left, right) === ExtendsResult.False ? ExtendsResult.False : type_exports.IsOptional(left) && !type_exports.IsOptional(right) ? ExtendsResult.False : ExtendsResult.True;
|
|
2661
|
+
}
|
|
2662
|
+
function FromObjectRight(left, right) {
|
|
2663
|
+
return type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : type_exports.IsNever(left) || type_exports.IsLiteralString(left) && IsObjectStringLike(right) || type_exports.IsLiteralNumber(left) && IsObjectNumberLike(right) || type_exports.IsLiteralBoolean(left) && IsObjectBooleanLike(right) || type_exports.IsSymbol(left) && IsObjectSymbolLike(right) || type_exports.IsBigInt(left) && IsObjectBigIntLike(right) || type_exports.IsString(left) && IsObjectStringLike(right) || type_exports.IsSymbol(left) && IsObjectSymbolLike(right) || type_exports.IsNumber(left) && IsObjectNumberLike(right) || type_exports.IsInteger(left) && IsObjectNumberLike(right) || type_exports.IsBoolean(left) && IsObjectBooleanLike(right) || type_exports.IsUint8Array(left) && IsObjectUint8ArrayLike(right) || type_exports.IsDate(left) && IsObjectDateLike(right) || type_exports.IsConstructor(left) && IsObjectConstructorLike(right) || type_exports.IsFunction(left) && IsObjectFunctionLike(right) ? ExtendsResult.True : type_exports.IsRecord(left) && type_exports.IsString(RecordKey(left)) ? (() => {
|
|
2664
|
+
return right[Hint] === "Record" ? ExtendsResult.True : ExtendsResult.False;
|
|
2665
|
+
})() : type_exports.IsRecord(left) && type_exports.IsNumber(RecordKey(left)) ? (() => {
|
|
2666
|
+
return IsObjectPropertyCount(right, 0) ? ExtendsResult.True : ExtendsResult.False;
|
|
2667
|
+
})() : ExtendsResult.False;
|
|
2668
|
+
}
|
|
2669
|
+
function FromObject(left, right) {
|
|
2670
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : !type_exports.IsObject(right) ? ExtendsResult.False : (() => {
|
|
2671
|
+
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
2672
|
+
if (!(key in left.properties) && !type_exports.IsOptional(right.properties[key])) {
|
|
2673
|
+
return ExtendsResult.False;
|
|
2674
|
+
}
|
|
2675
|
+
if (type_exports.IsOptional(right.properties[key])) {
|
|
2676
|
+
return ExtendsResult.True;
|
|
2677
|
+
}
|
|
2678
|
+
if (Property(left.properties[key], right.properties[key]) === ExtendsResult.False) {
|
|
2679
|
+
return ExtendsResult.False;
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
return ExtendsResult.True;
|
|
2683
|
+
})();
|
|
2684
|
+
}
|
|
2685
|
+
function FromPromise2(left, right) {
|
|
2686
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) && IsObjectPromiseLike(right) ? ExtendsResult.True : !type_exports.IsPromise(right) ? ExtendsResult.False : IntoBooleanResult(Visit3(left.item, right.item));
|
|
2687
|
+
}
|
|
2688
|
+
function RecordKey(schema) {
|
|
2689
|
+
return PatternNumberExact in schema.patternProperties ? Number2() : PatternStringExact in schema.patternProperties ? String2() : Throw("Unknown record key pattern");
|
|
2690
|
+
}
|
|
2691
|
+
function RecordValue(schema) {
|
|
2692
|
+
return PatternNumberExact in schema.patternProperties ? schema.patternProperties[PatternNumberExact] : PatternStringExact in schema.patternProperties ? schema.patternProperties[PatternStringExact] : Throw("Unable to get record value schema");
|
|
2693
|
+
}
|
|
2694
|
+
function FromRecordRight(left, right) {
|
|
2695
|
+
const [Key, Value] = [RecordKey(right), RecordValue(right)];
|
|
2696
|
+
return type_exports.IsLiteralString(left) && type_exports.IsNumber(Key) && IntoBooleanResult(Visit3(left, Value)) === ExtendsResult.True ? ExtendsResult.True : type_exports.IsUint8Array(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsString(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsArray(left) && type_exports.IsNumber(Key) ? Visit3(left, Value) : type_exports.IsObject(left) ? (() => {
|
|
2697
|
+
for (const key of Object.getOwnPropertyNames(left.properties)) {
|
|
2698
|
+
if (Property(Value, left.properties[key]) === ExtendsResult.False) {
|
|
2699
|
+
return ExtendsResult.False;
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
return ExtendsResult.True;
|
|
2703
|
+
})() : ExtendsResult.False;
|
|
2704
|
+
}
|
|
2705
|
+
function FromRecord(left, right) {
|
|
2706
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : !type_exports.IsRecord(right) ? ExtendsResult.False : Visit3(RecordValue(left), RecordValue(right));
|
|
2707
|
+
}
|
|
2708
|
+
function FromRegExp(left, right) {
|
|
2709
|
+
const L = type_exports.IsRegExp(left) ? String2() : left;
|
|
2710
|
+
const R = type_exports.IsRegExp(right) ? String2() : right;
|
|
2711
|
+
return Visit3(L, R);
|
|
2712
|
+
}
|
|
2713
|
+
function FromStringRight(left, right) {
|
|
2714
|
+
return type_exports.IsLiteral(left) && value_exports.IsString(left.const) ? ExtendsResult.True : type_exports.IsString(left) ? ExtendsResult.True : ExtendsResult.False;
|
|
2715
|
+
}
|
|
2716
|
+
function FromString(left, right) {
|
|
2717
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsString(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2718
|
+
}
|
|
2719
|
+
function FromSymbol(left, right) {
|
|
2720
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsSymbol(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2721
|
+
}
|
|
2722
|
+
function FromTemplateLiteral2(left, right) {
|
|
2723
|
+
return type_exports.IsTemplateLiteral(left) ? Visit3(TemplateLiteralToUnion(left), right) : type_exports.IsTemplateLiteral(right) ? Visit3(left, TemplateLiteralToUnion(right)) : Throw("Invalid fallthrough for TemplateLiteral");
|
|
2724
|
+
}
|
|
2725
|
+
function IsArrayOfTuple(left, right) {
|
|
2726
|
+
return type_exports.IsArray(right) && left.items !== void 0 && left.items.every((schema) => Visit3(schema, right.items) === ExtendsResult.True);
|
|
2727
|
+
}
|
|
2728
|
+
function FromTupleRight(left, right) {
|
|
2729
|
+
return type_exports.IsNever(left) ? ExtendsResult.True : type_exports.IsUnknown(left) ? ExtendsResult.False : type_exports.IsAny(left) ? ExtendsResult.Union : ExtendsResult.False;
|
|
2730
|
+
}
|
|
2731
|
+
function FromTuple3(left, right) {
|
|
2732
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) && IsObjectArrayLike(right) ? ExtendsResult.True : type_exports.IsArray(right) && IsArrayOfTuple(left, right) ? ExtendsResult.True : !type_exports.IsTuple(right) ? ExtendsResult.False : value_exports.IsUndefined(left.items) && !value_exports.IsUndefined(right.items) || !value_exports.IsUndefined(left.items) && value_exports.IsUndefined(right.items) ? ExtendsResult.False : value_exports.IsUndefined(left.items) && !value_exports.IsUndefined(right.items) ? ExtendsResult.True : left.items.every((schema, index) => Visit3(schema, right.items[index]) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
|
|
2733
|
+
}
|
|
2734
|
+
function FromUint8Array(left, right) {
|
|
2735
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsUint8Array(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2736
|
+
}
|
|
2737
|
+
function FromUndefined(left, right) {
|
|
2738
|
+
return IsStructuralRight(right) ? StructuralRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsRecord(right) ? FromRecordRight(left, right) : type_exports.IsVoid(right) ? FromVoidRight(left, right) : type_exports.IsUndefined(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2739
|
+
}
|
|
2740
|
+
function FromUnionRight(left, right) {
|
|
2741
|
+
return right.anyOf.some((schema) => Visit3(left, schema) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
|
|
2742
|
+
}
|
|
2743
|
+
function FromUnion6(left, right) {
|
|
2744
|
+
return left.anyOf.every((schema) => Visit3(schema, right) === ExtendsResult.True) ? ExtendsResult.True : ExtendsResult.False;
|
|
2745
|
+
}
|
|
2746
|
+
function FromUnknownRight(left, right) {
|
|
2747
|
+
return ExtendsResult.True;
|
|
2748
|
+
}
|
|
2749
|
+
function FromUnknown(left, right) {
|
|
2750
|
+
return type_exports.IsNever(right) ? FromNeverRight(left, right) : type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsAny(right) ? FromAnyRight(left, right) : type_exports.IsString(right) ? FromStringRight(left, right) : type_exports.IsNumber(right) ? FromNumberRight(left, right) : type_exports.IsInteger(right) ? FromIntegerRight(left, right) : type_exports.IsBoolean(right) ? FromBooleanRight(left, right) : type_exports.IsArray(right) ? FromArrayRight(left, right) : type_exports.IsTuple(right) ? FromTupleRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsUnknown(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2751
|
+
}
|
|
2752
|
+
function FromVoidRight(left, right) {
|
|
2753
|
+
return type_exports.IsUndefined(left) ? ExtendsResult.True : type_exports.IsUndefined(left) ? ExtendsResult.True : ExtendsResult.False;
|
|
2754
|
+
}
|
|
2755
|
+
function FromVoid(left, right) {
|
|
2756
|
+
return type_exports.IsIntersect(right) ? FromIntersectRight(left, right) : type_exports.IsUnion(right) ? FromUnionRight(left, right) : type_exports.IsUnknown(right) ? FromUnknownRight(left, right) : type_exports.IsAny(right) ? FromAnyRight(left, right) : type_exports.IsObject(right) ? FromObjectRight(left, right) : type_exports.IsVoid(right) ? ExtendsResult.True : ExtendsResult.False;
|
|
2757
|
+
}
|
|
2758
|
+
function Visit3(left, right) {
|
|
2759
|
+
return (
|
|
2760
|
+
// resolvable
|
|
2761
|
+
type_exports.IsTemplateLiteral(left) || type_exports.IsTemplateLiteral(right) ? FromTemplateLiteral2(left, right) : type_exports.IsRegExp(left) || type_exports.IsRegExp(right) ? FromRegExp(left, right) : type_exports.IsNot(left) || type_exports.IsNot(right) ? FromNot(left, right) : (
|
|
2762
|
+
// standard
|
|
2763
|
+
type_exports.IsAny(left) ? FromAny(left, right) : type_exports.IsArray(left) ? FromArray4(left, right) : type_exports.IsBigInt(left) ? FromBigInt(left, right) : type_exports.IsBoolean(left) ? FromBoolean(left, right) : type_exports.IsAsyncIterator(left) ? FromAsyncIterator(left, right) : type_exports.IsConstructor(left) ? FromConstructor(left, right) : type_exports.IsDate(left) ? FromDate(left, right) : type_exports.IsFunction(left) ? FromFunction(left, right) : type_exports.IsInteger(left) ? FromInteger(left, right) : type_exports.IsIntersect(left) ? FromIntersect4(left, right) : type_exports.IsIterator(left) ? FromIterator(left, right) : type_exports.IsLiteral(left) ? FromLiteral2(left, right) : type_exports.IsNever(left) ? FromNever(left, right) : type_exports.IsNull(left) ? FromNull(left, right) : type_exports.IsNumber(left) ? FromNumber(left, right) : type_exports.IsObject(left) ? FromObject(left, right) : type_exports.IsRecord(left) ? FromRecord(left, right) : type_exports.IsString(left) ? FromString(left, right) : type_exports.IsSymbol(left) ? FromSymbol(left, right) : type_exports.IsTuple(left) ? FromTuple3(left, right) : type_exports.IsPromise(left) ? FromPromise2(left, right) : type_exports.IsUint8Array(left) ? FromUint8Array(left, right) : type_exports.IsUndefined(left) ? FromUndefined(left, right) : type_exports.IsUnion(left) ? FromUnion6(left, right) : type_exports.IsUnknown(left) ? FromUnknown(left, right) : type_exports.IsVoid(left) ? FromVoid(left, right) : Throw(`Unknown left type operand '${left[Kind]}'`)
|
|
2764
|
+
)
|
|
2765
|
+
);
|
|
2766
|
+
}
|
|
2767
|
+
function ExtendsCheck(left, right) {
|
|
2768
|
+
return Visit3(left, right);
|
|
2769
|
+
}
|
|
2770
|
+
|
|
2771
|
+
// node_modules/@sinclair/typebox/build/esm/type/extends/extends-from-mapped-result.mjs
|
|
2772
|
+
function FromProperties8(P, Right, True, False, options) {
|
|
2773
|
+
const Acc = {};
|
|
2774
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
2775
|
+
Acc[K2] = Extends(P[K2], Right, True, False, Clone(options));
|
|
2776
|
+
return Acc;
|
|
2777
|
+
}
|
|
2778
|
+
function FromMappedResult6(Left, Right, True, False, options) {
|
|
2779
|
+
return FromProperties8(Left.properties, Right, True, False, options);
|
|
2780
|
+
}
|
|
2781
|
+
function ExtendsFromMappedResult(Left, Right, True, False, options) {
|
|
2782
|
+
const P = FromMappedResult6(Left, Right, True, False, options);
|
|
2783
|
+
return MappedResult(P);
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
// node_modules/@sinclair/typebox/build/esm/type/extends/extends.mjs
|
|
2787
|
+
function ExtendsResolve(left, right, trueType, falseType) {
|
|
2788
|
+
const R = ExtendsCheck(left, right);
|
|
2789
|
+
return R === ExtendsResult.Union ? Union([trueType, falseType]) : R === ExtendsResult.True ? trueType : falseType;
|
|
2790
|
+
}
|
|
2791
|
+
function Extends(L, R, T, F, options) {
|
|
2792
|
+
return IsMappedResult(L) ? ExtendsFromMappedResult(L, R, T, F, options) : IsMappedKey(L) ? CreateType(ExtendsFromMappedKey(L, R, T, F, options)) : CreateType(ExtendsResolve(L, R, T, F), options);
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
// node_modules/@sinclair/typebox/build/esm/type/extends/extends-from-mapped-key.mjs
|
|
2796
|
+
function FromPropertyKey(K, U, L, R, options) {
|
|
2797
|
+
return {
|
|
2798
|
+
[K]: Extends(Literal(K), U, L, R, Clone(options))
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
function FromPropertyKeys(K, U, L, R, options) {
|
|
2802
|
+
return K.reduce((Acc, LK) => {
|
|
2803
|
+
return { ...Acc, ...FromPropertyKey(LK, U, L, R, options) };
|
|
2804
|
+
}, {});
|
|
2805
|
+
}
|
|
2806
|
+
function FromMappedKey2(K, U, L, R, options) {
|
|
2807
|
+
return FromPropertyKeys(K.keys, U, L, R, options);
|
|
2808
|
+
}
|
|
2809
|
+
function ExtendsFromMappedKey(T, U, L, R, options) {
|
|
2810
|
+
const P = FromMappedKey2(T, U, L, R, options);
|
|
2811
|
+
return MappedResult(P);
|
|
2812
|
+
}
|
|
2813
|
+
|
|
2814
|
+
// node_modules/@sinclair/typebox/build/esm/type/exclude/exclude-from-template-literal.mjs
|
|
2815
|
+
function ExcludeFromTemplateLiteral(L, R) {
|
|
2816
|
+
return Exclude(TemplateLiteralToUnion(L), R);
|
|
2817
|
+
}
|
|
2818
|
+
|
|
2819
|
+
// node_modules/@sinclair/typebox/build/esm/type/exclude/exclude.mjs
|
|
2820
|
+
function ExcludeRest(L, R) {
|
|
2821
|
+
const excluded = L.filter((inner) => ExtendsCheck(inner, R) === ExtendsResult.False);
|
|
2822
|
+
return excluded.length === 1 ? excluded[0] : Union(excluded);
|
|
2823
|
+
}
|
|
2824
|
+
function Exclude(L, R, options = {}) {
|
|
2825
|
+
if (IsTemplateLiteral(L))
|
|
2826
|
+
return CreateType(ExcludeFromTemplateLiteral(L, R), options);
|
|
2827
|
+
if (IsMappedResult(L))
|
|
2828
|
+
return CreateType(ExcludeFromMappedResult(L, R), options);
|
|
2829
|
+
return CreateType(IsUnion(L) ? ExcludeRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? Never() : L, options);
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
// node_modules/@sinclair/typebox/build/esm/type/exclude/exclude-from-mapped-result.mjs
|
|
2833
|
+
function FromProperties9(P, U) {
|
|
2834
|
+
const Acc = {};
|
|
2835
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
2836
|
+
Acc[K2] = Exclude(P[K2], U);
|
|
2837
|
+
return Acc;
|
|
2838
|
+
}
|
|
2839
|
+
function FromMappedResult7(R, T) {
|
|
2840
|
+
return FromProperties9(R.properties, T);
|
|
2841
|
+
}
|
|
2842
|
+
function ExcludeFromMappedResult(R, T) {
|
|
2843
|
+
const P = FromMappedResult7(R, T);
|
|
2844
|
+
return MappedResult(P);
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
// node_modules/@sinclair/typebox/build/esm/type/extract/extract-from-template-literal.mjs
|
|
2848
|
+
function ExtractFromTemplateLiteral(L, R) {
|
|
2849
|
+
return Extract(TemplateLiteralToUnion(L), R);
|
|
2850
|
+
}
|
|
2851
|
+
|
|
2852
|
+
// node_modules/@sinclair/typebox/build/esm/type/extract/extract.mjs
|
|
2853
|
+
function ExtractRest(L, R) {
|
|
2854
|
+
const extracted = L.filter((inner) => ExtendsCheck(inner, R) !== ExtendsResult.False);
|
|
2855
|
+
return extracted.length === 1 ? extracted[0] : Union(extracted);
|
|
2856
|
+
}
|
|
2857
|
+
function Extract(L, R, options) {
|
|
2858
|
+
if (IsTemplateLiteral(L))
|
|
2859
|
+
return CreateType(ExtractFromTemplateLiteral(L, R), options);
|
|
2860
|
+
if (IsMappedResult(L))
|
|
2861
|
+
return CreateType(ExtractFromMappedResult(L, R), options);
|
|
2862
|
+
return CreateType(IsUnion(L) ? ExtractRest(L.anyOf, R) : ExtendsCheck(L, R) !== ExtendsResult.False ? L : Never(), options);
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
// node_modules/@sinclair/typebox/build/esm/type/extract/extract-from-mapped-result.mjs
|
|
2866
|
+
function FromProperties10(P, T) {
|
|
2867
|
+
const Acc = {};
|
|
2868
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
2869
|
+
Acc[K2] = Extract(P[K2], T);
|
|
2870
|
+
return Acc;
|
|
2871
|
+
}
|
|
2872
|
+
function FromMappedResult8(R, T) {
|
|
2873
|
+
return FromProperties10(R.properties, T);
|
|
2874
|
+
}
|
|
2875
|
+
function ExtractFromMappedResult(R, T) {
|
|
2876
|
+
const P = FromMappedResult8(R, T);
|
|
2877
|
+
return MappedResult(P);
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2880
|
+
// node_modules/@sinclair/typebox/build/esm/type/instance-type/instance-type.mjs
|
|
2881
|
+
function InstanceType(schema, options) {
|
|
2882
|
+
return IsConstructor(schema) ? CreateType(schema.returns, options) : Never(options);
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
// node_modules/@sinclair/typebox/build/esm/type/readonly-optional/readonly-optional.mjs
|
|
2886
|
+
function ReadonlyOptional(schema) {
|
|
2887
|
+
return Readonly(Optional(schema));
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
// node_modules/@sinclair/typebox/build/esm/type/record/record.mjs
|
|
2891
|
+
function RecordCreateFromPattern(pattern, T, options) {
|
|
2892
|
+
return CreateType({ [Kind]: "Record", type: "object", patternProperties: { [pattern]: T } }, options);
|
|
2893
|
+
}
|
|
2894
|
+
function RecordCreateFromKeys(K, T, options) {
|
|
2895
|
+
const result = {};
|
|
2896
|
+
for (const K2 of K)
|
|
2897
|
+
result[K2] = T;
|
|
2898
|
+
return Object2(result, { ...options, [Hint]: "Record" });
|
|
2899
|
+
}
|
|
2900
|
+
function FromTemplateLiteralKey(K, T, options) {
|
|
2901
|
+
return IsTemplateLiteralFinite(K) ? RecordCreateFromKeys(IndexPropertyKeys(K), T, options) : RecordCreateFromPattern(K.pattern, T, options);
|
|
2902
|
+
}
|
|
2903
|
+
function FromUnionKey(key, type, options) {
|
|
2904
|
+
return RecordCreateFromKeys(IndexPropertyKeys(Union(key)), type, options);
|
|
2905
|
+
}
|
|
2906
|
+
function FromLiteralKey(key, type, options) {
|
|
2907
|
+
return RecordCreateFromKeys([key.toString()], type, options);
|
|
2908
|
+
}
|
|
2909
|
+
function FromRegExpKey(key, type, options) {
|
|
2910
|
+
return RecordCreateFromPattern(key.source, type, options);
|
|
2911
|
+
}
|
|
2912
|
+
function FromStringKey(key, type, options) {
|
|
2913
|
+
const pattern = IsUndefined(key.pattern) ? PatternStringExact : key.pattern;
|
|
2914
|
+
return RecordCreateFromPattern(pattern, type, options);
|
|
2915
|
+
}
|
|
2916
|
+
function FromAnyKey(_, type, options) {
|
|
2917
|
+
return RecordCreateFromPattern(PatternStringExact, type, options);
|
|
2918
|
+
}
|
|
2919
|
+
function FromNeverKey(_key, type, options) {
|
|
2920
|
+
return RecordCreateFromPattern(PatternNeverExact, type, options);
|
|
2921
|
+
}
|
|
2922
|
+
function FromBooleanKey(_key, type, options) {
|
|
2923
|
+
return Object2({ true: type, false: type }, options);
|
|
2924
|
+
}
|
|
2925
|
+
function FromIntegerKey(_key, type, options) {
|
|
2926
|
+
return RecordCreateFromPattern(PatternNumberExact, type, options);
|
|
2927
|
+
}
|
|
2928
|
+
function FromNumberKey(_, type, options) {
|
|
2929
|
+
return RecordCreateFromPattern(PatternNumberExact, type, options);
|
|
2930
|
+
}
|
|
2931
|
+
function Record(key, type, options = {}) {
|
|
2932
|
+
return IsUnion(key) ? FromUnionKey(key.anyOf, type, options) : IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) : IsLiteral(key) ? FromLiteralKey(key.const, type, options) : IsBoolean2(key) ? FromBooleanKey(key, type, options) : IsInteger(key) ? FromIntegerKey(key, type, options) : IsNumber3(key) ? FromNumberKey(key, type, options) : IsRegExp2(key) ? FromRegExpKey(key, type, options) : IsString2(key) ? FromStringKey(key, type, options) : IsAny(key) ? FromAnyKey(key, type, options) : IsNever(key) ? FromNeverKey(key, type, options) : Never(options);
|
|
2933
|
+
}
|
|
2934
|
+
function RecordPattern(record) {
|
|
2935
|
+
return globalThis.Object.getOwnPropertyNames(record.patternProperties)[0];
|
|
2936
|
+
}
|
|
2937
|
+
function RecordKey2(type) {
|
|
2938
|
+
const pattern = RecordPattern(type);
|
|
2939
|
+
return pattern === PatternStringExact ? String2() : pattern === PatternNumberExact ? Number2() : String2({ pattern });
|
|
2940
|
+
}
|
|
2941
|
+
function RecordValue2(type) {
|
|
2942
|
+
return type.patternProperties[RecordPattern(type)];
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
// node_modules/@sinclair/typebox/build/esm/type/instantiate/instantiate.mjs
|
|
2946
|
+
function FromConstructor2(args, type) {
|
|
2947
|
+
type.parameters = FromTypes(args, type.parameters);
|
|
2948
|
+
type.returns = FromType(args, type.returns);
|
|
2949
|
+
return type;
|
|
2950
|
+
}
|
|
2951
|
+
function FromFunction2(args, type) {
|
|
2952
|
+
type.parameters = FromTypes(args, type.parameters);
|
|
2953
|
+
type.returns = FromType(args, type.returns);
|
|
2954
|
+
return type;
|
|
2955
|
+
}
|
|
2956
|
+
function FromIntersect5(args, type) {
|
|
2957
|
+
type.allOf = FromTypes(args, type.allOf);
|
|
2958
|
+
return type;
|
|
2959
|
+
}
|
|
2960
|
+
function FromUnion7(args, type) {
|
|
2961
|
+
type.anyOf = FromTypes(args, type.anyOf);
|
|
2962
|
+
return type;
|
|
2963
|
+
}
|
|
2964
|
+
function FromTuple4(args, type) {
|
|
2965
|
+
if (IsUndefined(type.items))
|
|
2966
|
+
return type;
|
|
2967
|
+
type.items = FromTypes(args, type.items);
|
|
2968
|
+
return type;
|
|
2969
|
+
}
|
|
2970
|
+
function FromArray5(args, type) {
|
|
2971
|
+
type.items = FromType(args, type.items);
|
|
2972
|
+
return type;
|
|
2973
|
+
}
|
|
2974
|
+
function FromAsyncIterator2(args, type) {
|
|
2975
|
+
type.items = FromType(args, type.items);
|
|
2976
|
+
return type;
|
|
2977
|
+
}
|
|
2978
|
+
function FromIterator2(args, type) {
|
|
2979
|
+
type.items = FromType(args, type.items);
|
|
2980
|
+
return type;
|
|
2981
|
+
}
|
|
2982
|
+
function FromPromise3(args, type) {
|
|
2983
|
+
type.item = FromType(args, type.item);
|
|
2984
|
+
return type;
|
|
2985
|
+
}
|
|
2986
|
+
function FromObject2(args, type) {
|
|
2987
|
+
const mappedProperties = FromProperties11(args, type.properties);
|
|
2988
|
+
return { ...type, ...Object2(mappedProperties) };
|
|
2989
|
+
}
|
|
2990
|
+
function FromRecord2(args, type) {
|
|
2991
|
+
const mappedKey = FromType(args, RecordKey2(type));
|
|
2992
|
+
const mappedValue = FromType(args, RecordValue2(type));
|
|
2993
|
+
const result = Record(mappedKey, mappedValue);
|
|
2994
|
+
return { ...type, ...result };
|
|
2995
|
+
}
|
|
2996
|
+
function FromArgument(args, argument) {
|
|
2997
|
+
return argument.index in args ? args[argument.index] : Unknown();
|
|
2998
|
+
}
|
|
2999
|
+
function FromProperty2(args, type) {
|
|
3000
|
+
const isReadonly = IsReadonly(type);
|
|
3001
|
+
const isOptional = IsOptional(type);
|
|
3002
|
+
const mapped = FromType(args, type);
|
|
3003
|
+
return isReadonly && isOptional ? ReadonlyOptional(mapped) : isReadonly && !isOptional ? Readonly(mapped) : !isReadonly && isOptional ? Optional(mapped) : mapped;
|
|
3004
|
+
}
|
|
3005
|
+
function FromProperties11(args, properties) {
|
|
3006
|
+
return globalThis.Object.getOwnPropertyNames(properties).reduce((result, key) => {
|
|
3007
|
+
return { ...result, [key]: FromProperty2(args, properties[key]) };
|
|
3008
|
+
}, {});
|
|
3009
|
+
}
|
|
3010
|
+
function FromTypes(args, types) {
|
|
3011
|
+
return types.map((type) => FromType(args, type));
|
|
3012
|
+
}
|
|
3013
|
+
function FromType(args, type) {
|
|
3014
|
+
return IsConstructor(type) ? FromConstructor2(args, type) : IsFunction2(type) ? FromFunction2(args, type) : IsIntersect(type) ? FromIntersect5(args, type) : IsUnion(type) ? FromUnion7(args, type) : IsTuple(type) ? FromTuple4(args, type) : IsArray3(type) ? FromArray5(args, type) : IsAsyncIterator2(type) ? FromAsyncIterator2(args, type) : IsIterator2(type) ? FromIterator2(args, type) : IsPromise(type) ? FromPromise3(args, type) : IsObject3(type) ? FromObject2(args, type) : IsRecord(type) ? FromRecord2(args, type) : IsArgument(type) ? FromArgument(args, type) : type;
|
|
3015
|
+
}
|
|
3016
|
+
function Instantiate(type, args) {
|
|
3017
|
+
return FromType(args, CloneType(type));
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
// node_modules/@sinclair/typebox/build/esm/type/integer/integer.mjs
|
|
3021
|
+
function Integer(options) {
|
|
3022
|
+
return CreateType({ [Kind]: "Integer", type: "integer" }, options);
|
|
3023
|
+
}
|
|
3024
|
+
|
|
3025
|
+
// node_modules/@sinclair/typebox/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs
|
|
3026
|
+
function MappedIntrinsicPropertyKey(K, M, options) {
|
|
3027
|
+
return {
|
|
3028
|
+
[K]: Intrinsic(Literal(K), M, Clone(options))
|
|
3029
|
+
};
|
|
3030
|
+
}
|
|
3031
|
+
function MappedIntrinsicPropertyKeys(K, M, options) {
|
|
3032
|
+
const result = K.reduce((Acc, L) => {
|
|
3033
|
+
return { ...Acc, ...MappedIntrinsicPropertyKey(L, M, options) };
|
|
3034
|
+
}, {});
|
|
3035
|
+
return result;
|
|
3036
|
+
}
|
|
3037
|
+
function MappedIntrinsicProperties(T, M, options) {
|
|
3038
|
+
return MappedIntrinsicPropertyKeys(T["keys"], M, options);
|
|
3039
|
+
}
|
|
3040
|
+
function IntrinsicFromMappedKey(T, M, options) {
|
|
3041
|
+
const P = MappedIntrinsicProperties(T, M, options);
|
|
3042
|
+
return MappedResult(P);
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
// node_modules/@sinclair/typebox/build/esm/type/intrinsic/intrinsic.mjs
|
|
3046
|
+
function ApplyUncapitalize(value) {
|
|
3047
|
+
const [first, rest] = [value.slice(0, 1), value.slice(1)];
|
|
3048
|
+
return [first.toLowerCase(), rest].join("");
|
|
3049
|
+
}
|
|
3050
|
+
function ApplyCapitalize(value) {
|
|
3051
|
+
const [first, rest] = [value.slice(0, 1), value.slice(1)];
|
|
3052
|
+
return [first.toUpperCase(), rest].join("");
|
|
3053
|
+
}
|
|
3054
|
+
function ApplyUppercase(value) {
|
|
3055
|
+
return value.toUpperCase();
|
|
3056
|
+
}
|
|
3057
|
+
function ApplyLowercase(value) {
|
|
3058
|
+
return value.toLowerCase();
|
|
3059
|
+
}
|
|
3060
|
+
function FromTemplateLiteral3(schema, mode, options) {
|
|
3061
|
+
const expression = TemplateLiteralParseExact(schema.pattern);
|
|
3062
|
+
const finite = IsTemplateLiteralExpressionFinite(expression);
|
|
3063
|
+
if (!finite)
|
|
3064
|
+
return { ...schema, pattern: FromLiteralValue(schema.pattern, mode) };
|
|
3065
|
+
const strings = [...TemplateLiteralExpressionGenerate(expression)];
|
|
3066
|
+
const literals = strings.map((value) => Literal(value));
|
|
3067
|
+
const mapped = FromRest5(literals, mode);
|
|
3068
|
+
const union = Union(mapped);
|
|
3069
|
+
return TemplateLiteral([union], options);
|
|
3070
|
+
}
|
|
3071
|
+
function FromLiteralValue(value, mode) {
|
|
3072
|
+
return typeof value === "string" ? mode === "Uncapitalize" ? ApplyUncapitalize(value) : mode === "Capitalize" ? ApplyCapitalize(value) : mode === "Uppercase" ? ApplyUppercase(value) : mode === "Lowercase" ? ApplyLowercase(value) : value : value.toString();
|
|
3073
|
+
}
|
|
3074
|
+
function FromRest5(T, M) {
|
|
3075
|
+
return T.map((L) => Intrinsic(L, M));
|
|
3076
|
+
}
|
|
3077
|
+
function Intrinsic(schema, mode, options = {}) {
|
|
3078
|
+
return (
|
|
3079
|
+
// Intrinsic-Mapped-Inference
|
|
3080
|
+
IsMappedKey(schema) ? IntrinsicFromMappedKey(schema, mode, options) : (
|
|
3081
|
+
// Standard-Inference
|
|
3082
|
+
IsTemplateLiteral(schema) ? FromTemplateLiteral3(schema, mode, options) : IsUnion(schema) ? Union(FromRest5(schema.anyOf, mode), options) : IsLiteral(schema) ? Literal(FromLiteralValue(schema.const, mode), options) : (
|
|
3083
|
+
// Default Type
|
|
3084
|
+
CreateType(schema, options)
|
|
3085
|
+
)
|
|
3086
|
+
)
|
|
3087
|
+
);
|
|
3088
|
+
}
|
|
3089
|
+
|
|
3090
|
+
// node_modules/@sinclair/typebox/build/esm/type/intrinsic/capitalize.mjs
|
|
3091
|
+
function Capitalize(T, options = {}) {
|
|
3092
|
+
return Intrinsic(T, "Capitalize", options);
|
|
3093
|
+
}
|
|
3094
|
+
|
|
3095
|
+
// node_modules/@sinclair/typebox/build/esm/type/intrinsic/lowercase.mjs
|
|
3096
|
+
function Lowercase(T, options = {}) {
|
|
3097
|
+
return Intrinsic(T, "Lowercase", options);
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
// node_modules/@sinclair/typebox/build/esm/type/intrinsic/uncapitalize.mjs
|
|
3101
|
+
function Uncapitalize(T, options = {}) {
|
|
3102
|
+
return Intrinsic(T, "Uncapitalize", options);
|
|
3103
|
+
}
|
|
3104
|
+
|
|
3105
|
+
// node_modules/@sinclair/typebox/build/esm/type/intrinsic/uppercase.mjs
|
|
3106
|
+
function Uppercase(T, options = {}) {
|
|
3107
|
+
return Intrinsic(T, "Uppercase", options);
|
|
3108
|
+
}
|
|
3109
|
+
|
|
3110
|
+
// node_modules/@sinclair/typebox/build/esm/type/omit/omit-from-mapped-result.mjs
|
|
3111
|
+
function FromProperties12(properties, propertyKeys, options) {
|
|
3112
|
+
const result = {};
|
|
3113
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
|
|
3114
|
+
result[K2] = Omit(properties[K2], propertyKeys, Clone(options));
|
|
3115
|
+
return result;
|
|
3116
|
+
}
|
|
3117
|
+
function FromMappedResult9(mappedResult, propertyKeys, options) {
|
|
3118
|
+
return FromProperties12(mappedResult.properties, propertyKeys, options);
|
|
3119
|
+
}
|
|
3120
|
+
function OmitFromMappedResult(mappedResult, propertyKeys, options) {
|
|
3121
|
+
const properties = FromMappedResult9(mappedResult, propertyKeys, options);
|
|
3122
|
+
return MappedResult(properties);
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
// node_modules/@sinclair/typebox/build/esm/type/omit/omit.mjs
|
|
3126
|
+
function FromIntersect6(types, propertyKeys) {
|
|
3127
|
+
return types.map((type) => OmitResolve(type, propertyKeys));
|
|
3128
|
+
}
|
|
3129
|
+
function FromUnion8(types, propertyKeys) {
|
|
3130
|
+
return types.map((type) => OmitResolve(type, propertyKeys));
|
|
3131
|
+
}
|
|
3132
|
+
function FromProperty3(properties, key) {
|
|
3133
|
+
const { [key]: _, ...R } = properties;
|
|
3134
|
+
return R;
|
|
3135
|
+
}
|
|
3136
|
+
function FromProperties13(properties, propertyKeys) {
|
|
3137
|
+
return propertyKeys.reduce((T, K2) => FromProperty3(T, K2), properties);
|
|
3138
|
+
}
|
|
3139
|
+
function FromObject3(type, propertyKeys, properties) {
|
|
3140
|
+
const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
|
|
3141
|
+
const mappedProperties = FromProperties13(properties, propertyKeys);
|
|
3142
|
+
return Object2(mappedProperties, options);
|
|
3143
|
+
}
|
|
3144
|
+
function UnionFromPropertyKeys(propertyKeys) {
|
|
3145
|
+
const result = propertyKeys.reduce((result2, key) => IsLiteralValue(key) ? [...result2, Literal(key)] : result2, []);
|
|
3146
|
+
return Union(result);
|
|
3147
|
+
}
|
|
3148
|
+
function OmitResolve(type, propertyKeys) {
|
|
3149
|
+
return IsIntersect(type) ? Intersect(FromIntersect6(type.allOf, propertyKeys)) : IsUnion(type) ? Union(FromUnion8(type.anyOf, propertyKeys)) : IsObject3(type) ? FromObject3(type, propertyKeys, type.properties) : Object2({});
|
|
3150
|
+
}
|
|
3151
|
+
function Omit(type, key, options) {
|
|
3152
|
+
const typeKey = IsArray(key) ? UnionFromPropertyKeys(key) : key;
|
|
3153
|
+
const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
|
|
3154
|
+
const isTypeRef = IsRef(type);
|
|
3155
|
+
const isKeyRef = IsRef(key);
|
|
3156
|
+
return IsMappedResult(type) ? OmitFromMappedResult(type, propertyKeys, options) : IsMappedKey(key) ? OmitFromMappedKey(type, key, options) : isTypeRef && isKeyRef ? Computed("Omit", [type, typeKey], options) : !isTypeRef && isKeyRef ? Computed("Omit", [type, typeKey], options) : isTypeRef && !isKeyRef ? Computed("Omit", [type, typeKey], options) : CreateType({ ...OmitResolve(type, propertyKeys), ...options });
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
// node_modules/@sinclair/typebox/build/esm/type/omit/omit-from-mapped-key.mjs
|
|
3160
|
+
function FromPropertyKey2(type, key, options) {
|
|
3161
|
+
return { [key]: Omit(type, [key], Clone(options)) };
|
|
3162
|
+
}
|
|
3163
|
+
function FromPropertyKeys2(type, propertyKeys, options) {
|
|
3164
|
+
return propertyKeys.reduce((Acc, LK) => {
|
|
3165
|
+
return { ...Acc, ...FromPropertyKey2(type, LK, options) };
|
|
3166
|
+
}, {});
|
|
3167
|
+
}
|
|
3168
|
+
function FromMappedKey3(type, mappedKey, options) {
|
|
3169
|
+
return FromPropertyKeys2(type, mappedKey.keys, options);
|
|
3170
|
+
}
|
|
3171
|
+
function OmitFromMappedKey(type, mappedKey, options) {
|
|
3172
|
+
const properties = FromMappedKey3(type, mappedKey, options);
|
|
3173
|
+
return MappedResult(properties);
|
|
3174
|
+
}
|
|
3175
|
+
|
|
3176
|
+
// node_modules/@sinclair/typebox/build/esm/type/pick/pick-from-mapped-result.mjs
|
|
3177
|
+
function FromProperties14(properties, propertyKeys, options) {
|
|
3178
|
+
const result = {};
|
|
3179
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(properties))
|
|
3180
|
+
result[K2] = Pick(properties[K2], propertyKeys, Clone(options));
|
|
3181
|
+
return result;
|
|
3182
|
+
}
|
|
3183
|
+
function FromMappedResult10(mappedResult, propertyKeys, options) {
|
|
3184
|
+
return FromProperties14(mappedResult.properties, propertyKeys, options);
|
|
3185
|
+
}
|
|
3186
|
+
function PickFromMappedResult(mappedResult, propertyKeys, options) {
|
|
3187
|
+
const properties = FromMappedResult10(mappedResult, propertyKeys, options);
|
|
3188
|
+
return MappedResult(properties);
|
|
3189
|
+
}
|
|
3190
|
+
|
|
3191
|
+
// node_modules/@sinclair/typebox/build/esm/type/pick/pick.mjs
|
|
3192
|
+
function FromIntersect7(types, propertyKeys) {
|
|
3193
|
+
return types.map((type) => PickResolve(type, propertyKeys));
|
|
3194
|
+
}
|
|
3195
|
+
function FromUnion9(types, propertyKeys) {
|
|
3196
|
+
return types.map((type) => PickResolve(type, propertyKeys));
|
|
3197
|
+
}
|
|
3198
|
+
function FromProperties15(properties, propertyKeys) {
|
|
3199
|
+
const result = {};
|
|
3200
|
+
for (const K2 of propertyKeys)
|
|
3201
|
+
if (K2 in properties)
|
|
3202
|
+
result[K2] = properties[K2];
|
|
3203
|
+
return result;
|
|
3204
|
+
}
|
|
3205
|
+
function FromObject4(Type2, keys, properties) {
|
|
3206
|
+
const options = Discard(Type2, [TransformKind, "$id", "required", "properties"]);
|
|
3207
|
+
const mappedProperties = FromProperties15(properties, keys);
|
|
3208
|
+
return Object2(mappedProperties, options);
|
|
3209
|
+
}
|
|
3210
|
+
function UnionFromPropertyKeys2(propertyKeys) {
|
|
3211
|
+
const result = propertyKeys.reduce((result2, key) => IsLiteralValue(key) ? [...result2, Literal(key)] : result2, []);
|
|
3212
|
+
return Union(result);
|
|
3213
|
+
}
|
|
3214
|
+
function PickResolve(type, propertyKeys) {
|
|
3215
|
+
return IsIntersect(type) ? Intersect(FromIntersect7(type.allOf, propertyKeys)) : IsUnion(type) ? Union(FromUnion9(type.anyOf, propertyKeys)) : IsObject3(type) ? FromObject4(type, propertyKeys, type.properties) : Object2({});
|
|
3216
|
+
}
|
|
3217
|
+
function Pick(type, key, options) {
|
|
3218
|
+
const typeKey = IsArray(key) ? UnionFromPropertyKeys2(key) : key;
|
|
3219
|
+
const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
|
|
3220
|
+
const isTypeRef = IsRef(type);
|
|
3221
|
+
const isKeyRef = IsRef(key);
|
|
3222
|
+
return IsMappedResult(type) ? PickFromMappedResult(type, propertyKeys, options) : IsMappedKey(key) ? PickFromMappedKey(type, key, options) : isTypeRef && isKeyRef ? Computed("Pick", [type, typeKey], options) : !isTypeRef && isKeyRef ? Computed("Pick", [type, typeKey], options) : isTypeRef && !isKeyRef ? Computed("Pick", [type, typeKey], options) : CreateType({ ...PickResolve(type, propertyKeys), ...options });
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
// node_modules/@sinclair/typebox/build/esm/type/pick/pick-from-mapped-key.mjs
|
|
3226
|
+
function FromPropertyKey3(type, key, options) {
|
|
3227
|
+
return {
|
|
3228
|
+
[key]: Pick(type, [key], Clone(options))
|
|
3229
|
+
};
|
|
3230
|
+
}
|
|
3231
|
+
function FromPropertyKeys3(type, propertyKeys, options) {
|
|
3232
|
+
return propertyKeys.reduce((result, leftKey) => {
|
|
3233
|
+
return { ...result, ...FromPropertyKey3(type, leftKey, options) };
|
|
3234
|
+
}, {});
|
|
3235
|
+
}
|
|
3236
|
+
function FromMappedKey4(type, mappedKey, options) {
|
|
3237
|
+
return FromPropertyKeys3(type, mappedKey.keys, options);
|
|
3238
|
+
}
|
|
3239
|
+
function PickFromMappedKey(type, mappedKey, options) {
|
|
3240
|
+
const properties = FromMappedKey4(type, mappedKey, options);
|
|
3241
|
+
return MappedResult(properties);
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
// node_modules/@sinclair/typebox/build/esm/type/partial/partial.mjs
|
|
3245
|
+
function FromComputed3(target, parameters) {
|
|
3246
|
+
return Computed("Partial", [Computed(target, parameters)]);
|
|
3247
|
+
}
|
|
3248
|
+
function FromRef3($ref) {
|
|
3249
|
+
return Computed("Partial", [Ref($ref)]);
|
|
3250
|
+
}
|
|
3251
|
+
function FromProperties16(properties) {
|
|
3252
|
+
const partialProperties = {};
|
|
3253
|
+
for (const K of globalThis.Object.getOwnPropertyNames(properties))
|
|
3254
|
+
partialProperties[K] = Optional(properties[K]);
|
|
3255
|
+
return partialProperties;
|
|
3256
|
+
}
|
|
3257
|
+
function FromObject5(type, properties) {
|
|
3258
|
+
const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
|
|
3259
|
+
const mappedProperties = FromProperties16(properties);
|
|
3260
|
+
return Object2(mappedProperties, options);
|
|
3261
|
+
}
|
|
3262
|
+
function FromRest6(types) {
|
|
3263
|
+
return types.map((type) => PartialResolve(type));
|
|
3264
|
+
}
|
|
3265
|
+
function PartialResolve(type) {
|
|
3266
|
+
return (
|
|
3267
|
+
// Mappable
|
|
3268
|
+
IsComputed(type) ? FromComputed3(type.target, type.parameters) : IsRef(type) ? FromRef3(type.$ref) : IsIntersect(type) ? Intersect(FromRest6(type.allOf)) : IsUnion(type) ? Union(FromRest6(type.anyOf)) : IsObject3(type) ? FromObject5(type, type.properties) : (
|
|
3269
|
+
// Intrinsic
|
|
3270
|
+
IsBigInt2(type) ? type : IsBoolean2(type) ? type : IsInteger(type) ? type : IsLiteral(type) ? type : IsNull2(type) ? type : IsNumber3(type) ? type : IsString2(type) ? type : IsSymbol2(type) ? type : IsUndefined3(type) ? type : (
|
|
3271
|
+
// Passthrough
|
|
3272
|
+
Object2({})
|
|
3273
|
+
)
|
|
3274
|
+
)
|
|
3275
|
+
);
|
|
3276
|
+
}
|
|
3277
|
+
function Partial(type, options) {
|
|
3278
|
+
if (IsMappedResult(type)) {
|
|
3279
|
+
return PartialFromMappedResult(type, options);
|
|
3280
|
+
} else {
|
|
3281
|
+
return CreateType({ ...PartialResolve(type), ...options });
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
// node_modules/@sinclair/typebox/build/esm/type/partial/partial-from-mapped-result.mjs
|
|
3286
|
+
function FromProperties17(K, options) {
|
|
3287
|
+
const Acc = {};
|
|
3288
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(K))
|
|
3289
|
+
Acc[K2] = Partial(K[K2], Clone(options));
|
|
3290
|
+
return Acc;
|
|
3291
|
+
}
|
|
3292
|
+
function FromMappedResult11(R, options) {
|
|
3293
|
+
return FromProperties17(R.properties, options);
|
|
3294
|
+
}
|
|
3295
|
+
function PartialFromMappedResult(R, options) {
|
|
3296
|
+
const P = FromMappedResult11(R, options);
|
|
3297
|
+
return MappedResult(P);
|
|
3298
|
+
}
|
|
3299
|
+
|
|
3300
|
+
// node_modules/@sinclair/typebox/build/esm/type/required/required.mjs
|
|
3301
|
+
function FromComputed4(target, parameters) {
|
|
3302
|
+
return Computed("Required", [Computed(target, parameters)]);
|
|
3303
|
+
}
|
|
3304
|
+
function FromRef4($ref) {
|
|
3305
|
+
return Computed("Required", [Ref($ref)]);
|
|
3306
|
+
}
|
|
3307
|
+
function FromProperties18(properties) {
|
|
3308
|
+
const requiredProperties = {};
|
|
3309
|
+
for (const K of globalThis.Object.getOwnPropertyNames(properties))
|
|
3310
|
+
requiredProperties[K] = Discard(properties[K], [OptionalKind]);
|
|
3311
|
+
return requiredProperties;
|
|
3312
|
+
}
|
|
3313
|
+
function FromObject6(type, properties) {
|
|
3314
|
+
const options = Discard(type, [TransformKind, "$id", "required", "properties"]);
|
|
3315
|
+
const mappedProperties = FromProperties18(properties);
|
|
3316
|
+
return Object2(mappedProperties, options);
|
|
3317
|
+
}
|
|
3318
|
+
function FromRest7(types) {
|
|
3319
|
+
return types.map((type) => RequiredResolve(type));
|
|
3320
|
+
}
|
|
3321
|
+
function RequiredResolve(type) {
|
|
3322
|
+
return (
|
|
3323
|
+
// Mappable
|
|
3324
|
+
IsComputed(type) ? FromComputed4(type.target, type.parameters) : IsRef(type) ? FromRef4(type.$ref) : IsIntersect(type) ? Intersect(FromRest7(type.allOf)) : IsUnion(type) ? Union(FromRest7(type.anyOf)) : IsObject3(type) ? FromObject6(type, type.properties) : (
|
|
3325
|
+
// Intrinsic
|
|
3326
|
+
IsBigInt2(type) ? type : IsBoolean2(type) ? type : IsInteger(type) ? type : IsLiteral(type) ? type : IsNull2(type) ? type : IsNumber3(type) ? type : IsString2(type) ? type : IsSymbol2(type) ? type : IsUndefined3(type) ? type : (
|
|
3327
|
+
// Passthrough
|
|
3328
|
+
Object2({})
|
|
3329
|
+
)
|
|
3330
|
+
)
|
|
3331
|
+
);
|
|
3332
|
+
}
|
|
3333
|
+
function Required(type, options) {
|
|
3334
|
+
if (IsMappedResult(type)) {
|
|
3335
|
+
return RequiredFromMappedResult(type, options);
|
|
3336
|
+
} else {
|
|
3337
|
+
return CreateType({ ...RequiredResolve(type), ...options });
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3340
|
+
|
|
3341
|
+
// node_modules/@sinclair/typebox/build/esm/type/required/required-from-mapped-result.mjs
|
|
3342
|
+
function FromProperties19(P, options) {
|
|
3343
|
+
const Acc = {};
|
|
3344
|
+
for (const K2 of globalThis.Object.getOwnPropertyNames(P))
|
|
3345
|
+
Acc[K2] = Required(P[K2], options);
|
|
3346
|
+
return Acc;
|
|
3347
|
+
}
|
|
3348
|
+
function FromMappedResult12(R, options) {
|
|
3349
|
+
return FromProperties19(R.properties, options);
|
|
3350
|
+
}
|
|
3351
|
+
function RequiredFromMappedResult(R, options) {
|
|
3352
|
+
const P = FromMappedResult12(R, options);
|
|
3353
|
+
return MappedResult(P);
|
|
3354
|
+
}
|
|
3355
|
+
|
|
3356
|
+
// node_modules/@sinclair/typebox/build/esm/type/module/compute.mjs
|
|
3357
|
+
function DereferenceParameters(moduleProperties, types) {
|
|
3358
|
+
return types.map((type) => {
|
|
3359
|
+
return IsRef(type) ? Dereference(moduleProperties, type.$ref) : FromType2(moduleProperties, type);
|
|
3360
|
+
});
|
|
3361
|
+
}
|
|
3362
|
+
function Dereference(moduleProperties, ref) {
|
|
3363
|
+
return ref in moduleProperties ? IsRef(moduleProperties[ref]) ? Dereference(moduleProperties, moduleProperties[ref].$ref) : FromType2(moduleProperties, moduleProperties[ref]) : Never();
|
|
3364
|
+
}
|
|
3365
|
+
function FromAwaited(parameters) {
|
|
3366
|
+
return Awaited(parameters[0]);
|
|
3367
|
+
}
|
|
3368
|
+
function FromIndex(parameters) {
|
|
3369
|
+
return Index(parameters[0], parameters[1]);
|
|
3370
|
+
}
|
|
3371
|
+
function FromKeyOf(parameters) {
|
|
3372
|
+
return KeyOf(parameters[0]);
|
|
3373
|
+
}
|
|
3374
|
+
function FromPartial(parameters) {
|
|
3375
|
+
return Partial(parameters[0]);
|
|
3376
|
+
}
|
|
3377
|
+
function FromOmit(parameters) {
|
|
3378
|
+
return Omit(parameters[0], parameters[1]);
|
|
3379
|
+
}
|
|
3380
|
+
function FromPick(parameters) {
|
|
3381
|
+
return Pick(parameters[0], parameters[1]);
|
|
3382
|
+
}
|
|
3383
|
+
function FromRequired(parameters) {
|
|
3384
|
+
return Required(parameters[0]);
|
|
3385
|
+
}
|
|
3386
|
+
function FromComputed5(moduleProperties, target, parameters) {
|
|
3387
|
+
const dereferenced = DereferenceParameters(moduleProperties, parameters);
|
|
3388
|
+
return target === "Awaited" ? FromAwaited(dereferenced) : target === "Index" ? FromIndex(dereferenced) : target === "KeyOf" ? FromKeyOf(dereferenced) : target === "Partial" ? FromPartial(dereferenced) : target === "Omit" ? FromOmit(dereferenced) : target === "Pick" ? FromPick(dereferenced) : target === "Required" ? FromRequired(dereferenced) : Never();
|
|
3389
|
+
}
|
|
3390
|
+
function FromArray6(moduleProperties, type) {
|
|
3391
|
+
return Array2(FromType2(moduleProperties, type));
|
|
3392
|
+
}
|
|
3393
|
+
function FromAsyncIterator3(moduleProperties, type) {
|
|
3394
|
+
return AsyncIterator(FromType2(moduleProperties, type));
|
|
3395
|
+
}
|
|
3396
|
+
function FromConstructor3(moduleProperties, parameters, instanceType) {
|
|
3397
|
+
return Constructor(FromTypes2(moduleProperties, parameters), FromType2(moduleProperties, instanceType));
|
|
3398
|
+
}
|
|
3399
|
+
function FromFunction3(moduleProperties, parameters, returnType) {
|
|
3400
|
+
return Function(FromTypes2(moduleProperties, parameters), FromType2(moduleProperties, returnType));
|
|
3401
|
+
}
|
|
3402
|
+
function FromIntersect8(moduleProperties, types) {
|
|
3403
|
+
return Intersect(FromTypes2(moduleProperties, types));
|
|
3404
|
+
}
|
|
3405
|
+
function FromIterator3(moduleProperties, type) {
|
|
3406
|
+
return Iterator(FromType2(moduleProperties, type));
|
|
3407
|
+
}
|
|
3408
|
+
function FromObject7(moduleProperties, properties) {
|
|
3409
|
+
return Object2(globalThis.Object.keys(properties).reduce((result, key) => {
|
|
3410
|
+
return { ...result, [key]: FromType2(moduleProperties, properties[key]) };
|
|
3411
|
+
}, {}));
|
|
3412
|
+
}
|
|
3413
|
+
function FromRecord3(moduleProperties, type) {
|
|
3414
|
+
const [value, pattern] = [FromType2(moduleProperties, RecordValue2(type)), RecordPattern(type)];
|
|
3415
|
+
const result = CloneType(type);
|
|
3416
|
+
result.patternProperties[pattern] = value;
|
|
3417
|
+
return result;
|
|
3418
|
+
}
|
|
3419
|
+
function FromTransform(moduleProperties, transform) {
|
|
3420
|
+
return IsRef(transform) ? { ...Dereference(moduleProperties, transform.$ref), [TransformKind]: transform[TransformKind] } : transform;
|
|
3421
|
+
}
|
|
3422
|
+
function FromTuple5(moduleProperties, types) {
|
|
3423
|
+
return Tuple(FromTypes2(moduleProperties, types));
|
|
3424
|
+
}
|
|
3425
|
+
function FromUnion10(moduleProperties, types) {
|
|
3426
|
+
return Union(FromTypes2(moduleProperties, types));
|
|
3427
|
+
}
|
|
3428
|
+
function FromTypes2(moduleProperties, types) {
|
|
3429
|
+
return types.map((type) => FromType2(moduleProperties, type));
|
|
3430
|
+
}
|
|
3431
|
+
function FromType2(moduleProperties, type) {
|
|
3432
|
+
return (
|
|
3433
|
+
// Modifiers
|
|
3434
|
+
IsOptional(type) ? CreateType(FromType2(moduleProperties, Discard(type, [OptionalKind])), type) : IsReadonly(type) ? CreateType(FromType2(moduleProperties, Discard(type, [ReadonlyKind])), type) : (
|
|
3435
|
+
// Transform
|
|
3436
|
+
IsTransform(type) ? CreateType(FromTransform(moduleProperties, type), type) : (
|
|
3437
|
+
// Types
|
|
3438
|
+
IsArray3(type) ? CreateType(FromArray6(moduleProperties, type.items), type) : IsAsyncIterator2(type) ? CreateType(FromAsyncIterator3(moduleProperties, type.items), type) : IsComputed(type) ? CreateType(FromComputed5(moduleProperties, type.target, type.parameters)) : IsConstructor(type) ? CreateType(FromConstructor3(moduleProperties, type.parameters, type.returns), type) : IsFunction2(type) ? CreateType(FromFunction3(moduleProperties, type.parameters, type.returns), type) : IsIntersect(type) ? CreateType(FromIntersect8(moduleProperties, type.allOf), type) : IsIterator2(type) ? CreateType(FromIterator3(moduleProperties, type.items), type) : IsObject3(type) ? CreateType(FromObject7(moduleProperties, type.properties), type) : IsRecord(type) ? CreateType(FromRecord3(moduleProperties, type)) : IsTuple(type) ? CreateType(FromTuple5(moduleProperties, type.items || []), type) : IsUnion(type) ? CreateType(FromUnion10(moduleProperties, type.anyOf), type) : type
|
|
3439
|
+
)
|
|
3440
|
+
)
|
|
3441
|
+
);
|
|
3442
|
+
}
|
|
3443
|
+
function ComputeType(moduleProperties, key) {
|
|
3444
|
+
return key in moduleProperties ? FromType2(moduleProperties, moduleProperties[key]) : Never();
|
|
3445
|
+
}
|
|
3446
|
+
function ComputeModuleProperties(moduleProperties) {
|
|
3447
|
+
return globalThis.Object.getOwnPropertyNames(moduleProperties).reduce((result, key) => {
|
|
3448
|
+
return { ...result, [key]: ComputeType(moduleProperties, key) };
|
|
3449
|
+
}, {});
|
|
3450
|
+
}
|
|
3451
|
+
|
|
3452
|
+
// node_modules/@sinclair/typebox/build/esm/type/module/module.mjs
|
|
3453
|
+
var TModule = class {
|
|
3454
|
+
constructor($defs) {
|
|
3455
|
+
const computed = ComputeModuleProperties($defs);
|
|
3456
|
+
const identified = this.WithIdentifiers(computed);
|
|
3457
|
+
this.$defs = identified;
|
|
3458
|
+
}
|
|
3459
|
+
/** `[Json]` Imports a Type by Key. */
|
|
3460
|
+
Import(key, options) {
|
|
3461
|
+
const $defs = { ...this.$defs, [key]: CreateType(this.$defs[key], options) };
|
|
3462
|
+
return CreateType({ [Kind]: "Import", $defs, $ref: key });
|
|
3463
|
+
}
|
|
3464
|
+
// prettier-ignore
|
|
3465
|
+
WithIdentifiers($defs) {
|
|
3466
|
+
return globalThis.Object.getOwnPropertyNames($defs).reduce((result, key) => {
|
|
3467
|
+
return { ...result, [key]: { ...$defs[key], $id: key } };
|
|
3468
|
+
}, {});
|
|
3469
|
+
}
|
|
3470
|
+
};
|
|
3471
|
+
function Module(properties) {
|
|
3472
|
+
return new TModule(properties);
|
|
3473
|
+
}
|
|
3474
|
+
|
|
3475
|
+
// node_modules/@sinclair/typebox/build/esm/type/not/not.mjs
|
|
3476
|
+
function Not(type, options) {
|
|
3477
|
+
return CreateType({ [Kind]: "Not", not: type }, options);
|
|
3478
|
+
}
|
|
3479
|
+
|
|
3480
|
+
// node_modules/@sinclair/typebox/build/esm/type/parameters/parameters.mjs
|
|
3481
|
+
function Parameters(schema, options) {
|
|
3482
|
+
return IsFunction2(schema) ? Tuple(schema.parameters, options) : Never();
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
// node_modules/@sinclair/typebox/build/esm/type/recursive/recursive.mjs
|
|
3486
|
+
var Ordinal = 0;
|
|
3487
|
+
function Recursive(callback, options = {}) {
|
|
3488
|
+
if (IsUndefined(options.$id))
|
|
3489
|
+
options.$id = `T${Ordinal++}`;
|
|
3490
|
+
const thisType = CloneType(callback({ [Kind]: "This", $ref: `${options.$id}` }));
|
|
3491
|
+
thisType.$id = options.$id;
|
|
3492
|
+
return CreateType({ [Hint]: "Recursive", ...thisType }, options);
|
|
3493
|
+
}
|
|
3494
|
+
|
|
3495
|
+
// node_modules/@sinclair/typebox/build/esm/type/regexp/regexp.mjs
|
|
3496
|
+
function RegExp2(unresolved, options) {
|
|
3497
|
+
const expr = IsString(unresolved) ? new globalThis.RegExp(unresolved) : unresolved;
|
|
3498
|
+
return CreateType({ [Kind]: "RegExp", type: "RegExp", source: expr.source, flags: expr.flags }, options);
|
|
3499
|
+
}
|
|
3500
|
+
|
|
3501
|
+
// node_modules/@sinclair/typebox/build/esm/type/rest/rest.mjs
|
|
3502
|
+
function RestResolve(T) {
|
|
3503
|
+
return IsIntersect(T) ? T.allOf : IsUnion(T) ? T.anyOf : IsTuple(T) ? T.items ?? [] : [];
|
|
3504
|
+
}
|
|
3505
|
+
function Rest(T) {
|
|
3506
|
+
return RestResolve(T);
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3509
|
+
// node_modules/@sinclair/typebox/build/esm/type/return-type/return-type.mjs
|
|
3510
|
+
function ReturnType(schema, options) {
|
|
3511
|
+
return IsFunction2(schema) ? CreateType(schema.returns, options) : Never(options);
|
|
3512
|
+
}
|
|
3513
|
+
|
|
3514
|
+
// node_modules/@sinclair/typebox/build/esm/type/transform/transform.mjs
|
|
3515
|
+
var TransformDecodeBuilder = class {
|
|
3516
|
+
constructor(schema) {
|
|
3517
|
+
this.schema = schema;
|
|
3518
|
+
}
|
|
3519
|
+
Decode(decode) {
|
|
3520
|
+
return new TransformEncodeBuilder(this.schema, decode);
|
|
3521
|
+
}
|
|
3522
|
+
};
|
|
3523
|
+
var TransformEncodeBuilder = class {
|
|
3524
|
+
constructor(schema, decode) {
|
|
3525
|
+
this.schema = schema;
|
|
3526
|
+
this.decode = decode;
|
|
3527
|
+
}
|
|
3528
|
+
EncodeTransform(encode, schema) {
|
|
3529
|
+
const Encode = (value) => schema[TransformKind].Encode(encode(value));
|
|
3530
|
+
const Decode = (value) => this.decode(schema[TransformKind].Decode(value));
|
|
3531
|
+
const Codec = { Encode, Decode };
|
|
3532
|
+
return { ...schema, [TransformKind]: Codec };
|
|
3533
|
+
}
|
|
3534
|
+
EncodeSchema(encode, schema) {
|
|
3535
|
+
const Codec = { Decode: this.decode, Encode: encode };
|
|
3536
|
+
return { ...schema, [TransformKind]: Codec };
|
|
3537
|
+
}
|
|
3538
|
+
Encode(encode) {
|
|
3539
|
+
return IsTransform(this.schema) ? this.EncodeTransform(encode, this.schema) : this.EncodeSchema(encode, this.schema);
|
|
3540
|
+
}
|
|
3541
|
+
};
|
|
3542
|
+
function Transform(schema) {
|
|
3543
|
+
return new TransformDecodeBuilder(schema);
|
|
3544
|
+
}
|
|
3545
|
+
|
|
3546
|
+
// node_modules/@sinclair/typebox/build/esm/type/unsafe/unsafe.mjs
|
|
3547
|
+
function Unsafe(options = {}) {
|
|
3548
|
+
return CreateType({ [Kind]: options[Kind] ?? "Unsafe" }, options);
|
|
3549
|
+
}
|
|
3550
|
+
|
|
3551
|
+
// node_modules/@sinclair/typebox/build/esm/type/void/void.mjs
|
|
3552
|
+
function Void(options) {
|
|
3553
|
+
return CreateType({ [Kind]: "Void", type: "void" }, options);
|
|
3554
|
+
}
|
|
3555
|
+
|
|
3556
|
+
// node_modules/@sinclair/typebox/build/esm/type/type/type.mjs
|
|
3557
|
+
var type_exports2 = {};
|
|
3558
|
+
__export(type_exports2, {
|
|
3559
|
+
Any: () => Any,
|
|
3560
|
+
Argument: () => Argument,
|
|
3561
|
+
Array: () => Array2,
|
|
3562
|
+
AsyncIterator: () => AsyncIterator,
|
|
3563
|
+
Awaited: () => Awaited,
|
|
3564
|
+
BigInt: () => BigInt,
|
|
3565
|
+
Boolean: () => Boolean2,
|
|
3566
|
+
Capitalize: () => Capitalize,
|
|
3567
|
+
Composite: () => Composite,
|
|
3568
|
+
Const: () => Const,
|
|
3569
|
+
Constructor: () => Constructor,
|
|
3570
|
+
ConstructorParameters: () => ConstructorParameters,
|
|
3571
|
+
Date: () => Date2,
|
|
3572
|
+
Enum: () => Enum,
|
|
3573
|
+
Exclude: () => Exclude,
|
|
3574
|
+
Extends: () => Extends,
|
|
3575
|
+
Extract: () => Extract,
|
|
3576
|
+
Function: () => Function,
|
|
3577
|
+
Index: () => Index,
|
|
3578
|
+
InstanceType: () => InstanceType,
|
|
3579
|
+
Instantiate: () => Instantiate,
|
|
3580
|
+
Integer: () => Integer,
|
|
3581
|
+
Intersect: () => Intersect,
|
|
3582
|
+
Iterator: () => Iterator,
|
|
3583
|
+
KeyOf: () => KeyOf,
|
|
3584
|
+
Literal: () => Literal,
|
|
3585
|
+
Lowercase: () => Lowercase,
|
|
3586
|
+
Mapped: () => Mapped,
|
|
3587
|
+
Module: () => Module,
|
|
3588
|
+
Never: () => Never,
|
|
3589
|
+
Not: () => Not,
|
|
3590
|
+
Null: () => Null,
|
|
3591
|
+
Number: () => Number2,
|
|
3592
|
+
Object: () => Object2,
|
|
3593
|
+
Omit: () => Omit,
|
|
3594
|
+
Optional: () => Optional,
|
|
3595
|
+
Parameters: () => Parameters,
|
|
3596
|
+
Partial: () => Partial,
|
|
3597
|
+
Pick: () => Pick,
|
|
3598
|
+
Promise: () => Promise2,
|
|
3599
|
+
Readonly: () => Readonly,
|
|
3600
|
+
ReadonlyOptional: () => ReadonlyOptional,
|
|
3601
|
+
Record: () => Record,
|
|
3602
|
+
Recursive: () => Recursive,
|
|
3603
|
+
Ref: () => Ref,
|
|
3604
|
+
RegExp: () => RegExp2,
|
|
3605
|
+
Required: () => Required,
|
|
3606
|
+
Rest: () => Rest,
|
|
3607
|
+
ReturnType: () => ReturnType,
|
|
3608
|
+
String: () => String2,
|
|
3609
|
+
Symbol: () => Symbol2,
|
|
3610
|
+
TemplateLiteral: () => TemplateLiteral,
|
|
3611
|
+
Transform: () => Transform,
|
|
3612
|
+
Tuple: () => Tuple,
|
|
3613
|
+
Uint8Array: () => Uint8Array2,
|
|
3614
|
+
Uncapitalize: () => Uncapitalize,
|
|
3615
|
+
Undefined: () => Undefined,
|
|
3616
|
+
Union: () => Union,
|
|
3617
|
+
Unknown: () => Unknown,
|
|
3618
|
+
Unsafe: () => Unsafe,
|
|
3619
|
+
Uppercase: () => Uppercase,
|
|
3620
|
+
Void: () => Void
|
|
3621
|
+
});
|
|
3622
|
+
|
|
3623
|
+
// node_modules/@sinclair/typebox/build/esm/type/type/index.mjs
|
|
3624
|
+
var Type = type_exports2;
|
|
3625
|
+
|
|
3626
|
+
// src/protocol/pi-identity.ts
|
|
3627
|
+
var MANAGED_PI_ARTIFACT_ID = "@earendil-works/pi-coding-agent@0.80.10";
|
|
3628
|
+
var PiRuntimeIdentitySchema = Type.Union([
|
|
3629
|
+
Type.Object(
|
|
3630
|
+
{
|
|
3631
|
+
mode: Type.Literal("managed"),
|
|
3632
|
+
artifactId: Type.String({ minLength: 1 })
|
|
3633
|
+
},
|
|
3634
|
+
{ additionalProperties: false }
|
|
3635
|
+
),
|
|
3636
|
+
Type.Object(
|
|
3637
|
+
{
|
|
3638
|
+
mode: Type.Literal("external"),
|
|
3639
|
+
selectedPath: Type.String({ minLength: 1 }),
|
|
3640
|
+
nodePath: Type.String({ minLength: 1 }),
|
|
3641
|
+
realPath: Type.String({ minLength: 1 }),
|
|
3642
|
+
version: Type.String({ minLength: 1 }),
|
|
3643
|
+
fingerprint: Type.String({ minLength: 1 })
|
|
3644
|
+
},
|
|
3645
|
+
{ additionalProperties: false }
|
|
3646
|
+
)
|
|
3647
|
+
]);
|
|
3648
|
+
var MANAGED_PI_RUNTIME_IDENTITY = Object.freeze({
|
|
3649
|
+
mode: "managed",
|
|
3650
|
+
artifactId: MANAGED_PI_ARTIFACT_ID
|
|
3651
|
+
});
|
|
3652
|
+
|
|
3653
|
+
// src/protocol/semantic-segmentation.ts
|
|
3654
|
+
var SemanticEventReassembler = class {
|
|
3655
|
+
#maxEventBytes;
|
|
3656
|
+
#maxSegments;
|
|
3657
|
+
#current;
|
|
3658
|
+
constructor(maxEventBytes, maxSegments = 4096) {
|
|
3659
|
+
assertPositiveInteger(maxEventBytes, "Semantic event reassembly limit");
|
|
3660
|
+
assertPositiveInteger(maxSegments, "Semantic segment limit");
|
|
3661
|
+
this.#maxEventBytes = maxEventBytes;
|
|
3662
|
+
this.#maxSegments = maxSegments;
|
|
3663
|
+
}
|
|
3664
|
+
push(frame) {
|
|
3665
|
+
assertFrame(frame);
|
|
3666
|
+
if (frame.count > this.#maxSegments) {
|
|
3667
|
+
throw new Error("Semantic event segment count exceeds reassembly limit");
|
|
3668
|
+
}
|
|
3669
|
+
if (frame.data.length === 0) throw new Error("Semantic event segment must not be empty");
|
|
3670
|
+
if (frame.index === 0) {
|
|
3671
|
+
if (this.#current !== void 0) throw new Error("Semantic event reassembly was interrupted");
|
|
3672
|
+
this.#current = {
|
|
3673
|
+
eventId: frame.eventId,
|
|
3674
|
+
precedingCursor: frame.precedingCursor,
|
|
3675
|
+
eventCursor: frame.eventCursor,
|
|
3676
|
+
count: frame.count,
|
|
3677
|
+
chunks: [],
|
|
3678
|
+
bytes: 0
|
|
3679
|
+
};
|
|
3680
|
+
}
|
|
3681
|
+
const current = this.#current;
|
|
3682
|
+
if (current === void 0) throw new Error("Semantic event segment has no start");
|
|
3683
|
+
if (frame.eventId !== current.eventId || frame.precedingCursor !== current.precedingCursor || frame.eventCursor !== current.eventCursor || frame.count !== current.count || frame.index !== current.chunks.length) {
|
|
3684
|
+
this.reset();
|
|
3685
|
+
throw new Error("Semantic event segment sequence is invalid");
|
|
3686
|
+
}
|
|
3687
|
+
const chunk = decodeBase64(frame.data);
|
|
3688
|
+
if (current.bytes + chunk.length > this.#maxEventBytes) {
|
|
3689
|
+
this.reset();
|
|
3690
|
+
throw new Error("Semantic event exceeds reassembly limit");
|
|
3691
|
+
}
|
|
3692
|
+
current.chunks.push(chunk);
|
|
3693
|
+
current.bytes += chunk.length;
|
|
3694
|
+
if (current.chunks.length < current.count) return null;
|
|
3695
|
+
const precedingCursor = current.precedingCursor;
|
|
3696
|
+
const eventCursor = current.eventCursor;
|
|
3697
|
+
const eventId = current.eventId;
|
|
3698
|
+
const bytes = Buffer.concat(current.chunks, current.bytes);
|
|
3699
|
+
this.reset();
|
|
3700
|
+
let event;
|
|
3701
|
+
try {
|
|
3702
|
+
event = JSON.parse(bytes.toString("utf8"));
|
|
3703
|
+
} catch {
|
|
3704
|
+
throw new Error("Semantic event payload is invalid JSON");
|
|
3705
|
+
}
|
|
3706
|
+
if (event.id !== eventId || event.cursor !== eventCursor) {
|
|
3707
|
+
throw new Error("Semantic event payload identity does not match its segments");
|
|
3708
|
+
}
|
|
3709
|
+
return { event, precedingCursor };
|
|
3710
|
+
}
|
|
3711
|
+
reset() {
|
|
3712
|
+
this.#current = void 0;
|
|
3713
|
+
}
|
|
3714
|
+
};
|
|
3715
|
+
function assertFrame(frame) {
|
|
3716
|
+
if (frame.type !== "semantic.segment" || !Number.isSafeInteger(frame.index) || !Number.isSafeInteger(frame.count) || frame.index < 0 || frame.count <= 0 || frame.index >= frame.count) {
|
|
3717
|
+
throw new Error("Semantic event segment metadata is invalid");
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
function decodeBase64(value) {
|
|
3721
|
+
const decoded = Buffer.from(value, "base64");
|
|
3722
|
+
if (decoded.toString("base64") !== value)
|
|
3723
|
+
throw new Error("Semantic event segment is invalid base64");
|
|
3724
|
+
return decoded;
|
|
3725
|
+
}
|
|
3726
|
+
function assertPositiveInteger(value, label) {
|
|
3727
|
+
if (!Number.isSafeInteger(value) || value <= 0) throw new Error(`${label} must be positive`);
|
|
3728
|
+
}
|
|
3729
|
+
|
|
3730
|
+
// src/client/contracts.ts
|
|
3731
|
+
var PI_FLEET_ERROR_CODES = [
|
|
3732
|
+
"agent_busy",
|
|
3733
|
+
"agent_destroyed",
|
|
3734
|
+
"agent_destroying",
|
|
3735
|
+
"agent_not_found",
|
|
3736
|
+
"capacity_exceeded",
|
|
3737
|
+
"cancelled",
|
|
3738
|
+
"compaction_failed",
|
|
3739
|
+
"compaction_uncertain",
|
|
3740
|
+
"cursor_expired",
|
|
3741
|
+
"cursor_invalid",
|
|
3742
|
+
"cursor_wrong_agent",
|
|
3743
|
+
"delivery_uncertain",
|
|
3744
|
+
"destroy_incomplete",
|
|
3745
|
+
"incarnation_cleanup_uncertain",
|
|
3746
|
+
"internal_error",
|
|
3747
|
+
"invalid_arguments",
|
|
3748
|
+
"invalid_request",
|
|
3749
|
+
"name_taken",
|
|
3750
|
+
"nothing_to_compact",
|
|
3751
|
+
"observation_uncertain",
|
|
3752
|
+
"operation_conflict",
|
|
3753
|
+
"operation_in_progress",
|
|
3754
|
+
"pi_installation_changed",
|
|
3755
|
+
"pi_not_executable",
|
|
3756
|
+
"pi_not_found",
|
|
3757
|
+
"pi_runtime_mismatch",
|
|
3758
|
+
"pi_service_mismatch",
|
|
3759
|
+
"pi_start_failed",
|
|
3760
|
+
"pi_version_unavailable",
|
|
3761
|
+
"pi_version_unsupported",
|
|
3762
|
+
"protocol_error",
|
|
3763
|
+
"protocol_incompatible",
|
|
3764
|
+
"receive_resource_exhausted",
|
|
3765
|
+
"runtime_interrupted",
|
|
3766
|
+
"runtime_unavailable",
|
|
3767
|
+
"runtime_upgrade_deferred",
|
|
3768
|
+
"semantic_event_too_large",
|
|
3769
|
+
"stale_agent",
|
|
3770
|
+
"state_corrupt",
|
|
3771
|
+
"storage_unavailable",
|
|
3772
|
+
"timeout"
|
|
3773
|
+
];
|
|
3774
|
+
var piFleetErrorCodeSet = new Set(PI_FLEET_ERROR_CODES);
|
|
3775
|
+
function isPiFleetErrorCode(value) {
|
|
3776
|
+
return typeof value === "string" && piFleetErrorCodeSet.has(value);
|
|
3777
|
+
}
|
|
3778
|
+
|
|
3779
|
+
// src/shared/result.ts
|
|
3780
|
+
function ok(value) {
|
|
3781
|
+
return { ok: true, value };
|
|
3782
|
+
}
|
|
3783
|
+
function err(error) {
|
|
3784
|
+
return { ok: false, error };
|
|
3785
|
+
}
|
|
3786
|
+
|
|
3787
|
+
// src/client/socket-fleet-client.ts
|
|
3788
|
+
var SocketFleetClient = class {
|
|
3789
|
+
constructor(options) {
|
|
3790
|
+
this.options = options;
|
|
3791
|
+
}
|
|
3792
|
+
create(input, options) {
|
|
3793
|
+
return this.#request("agent.create", input, options);
|
|
3794
|
+
}
|
|
3795
|
+
async send(input, options) {
|
|
3796
|
+
const bound = await this.#bind(input, options);
|
|
3797
|
+
if (!bound.ok) return bound;
|
|
3798
|
+
return this.#request("agent.send", bound.value, options);
|
|
3799
|
+
}
|
|
3800
|
+
async *receive(input, options) {
|
|
3801
|
+
const bound = await this.#bind(input, options);
|
|
3802
|
+
if (!bound.ok) {
|
|
3803
|
+
yield bound;
|
|
3804
|
+
return;
|
|
3805
|
+
}
|
|
3806
|
+
let socket;
|
|
3807
|
+
try {
|
|
3808
|
+
await this.options.beforeConnect?.();
|
|
3809
|
+
socket = await connect(this.options.socketPath, options.signal);
|
|
3810
|
+
} catch (error) {
|
|
3811
|
+
yield err(connectionError(error));
|
|
3812
|
+
return;
|
|
3813
|
+
}
|
|
3814
|
+
const requestId = randomUUID2();
|
|
3815
|
+
const frames = frameIterator(socket, options.signal);
|
|
3816
|
+
let reassembler = null;
|
|
3817
|
+
let expectedCursor = null;
|
|
3818
|
+
writeJsonLine(socket, {
|
|
3819
|
+
v: PROTOCOL_VERSION,
|
|
3820
|
+
requestId,
|
|
3821
|
+
method: "agent.receive",
|
|
3822
|
+
params: receiveParams(bound.value)
|
|
3823
|
+
});
|
|
3824
|
+
let ready = false;
|
|
3825
|
+
let ended = false;
|
|
3826
|
+
try {
|
|
3827
|
+
for await (const frame of frames) {
|
|
3828
|
+
if (!isRecord2(frame) || frame.requestId !== requestId) continue;
|
|
3829
|
+
if (frame.v !== PROTOCOL_VERSION) {
|
|
3830
|
+
yield err(protocolIncompatible());
|
|
3831
|
+
return;
|
|
3832
|
+
}
|
|
3833
|
+
if (frame.stream === "ready" && typeof frame.cursor === "string") {
|
|
3834
|
+
if (ready || !isRecord2(frame.limits) || !isPositiveSafeInteger(frame.limits.maxEventBytes) || !isPositiveSafeInteger(frame.limits.maxSegments)) {
|
|
3835
|
+
yield err({ code: "protocol_error", message: "Invalid receive readiness frame." });
|
|
3836
|
+
return;
|
|
3837
|
+
}
|
|
3838
|
+
ready = true;
|
|
3839
|
+
expectedCursor = frame.cursor;
|
|
3840
|
+
reassembler = new SemanticEventReassembler(
|
|
3841
|
+
frame.limits.maxEventBytes,
|
|
3842
|
+
frame.limits.maxSegments
|
|
3843
|
+
);
|
|
3844
|
+
yield ok({ type: "ready", cursor: expectedCursor });
|
|
3845
|
+
continue;
|
|
3846
|
+
}
|
|
3847
|
+
if (frame.stream === "semantic.segment" && isSemanticSegment(frame.segment)) {
|
|
3848
|
+
if (!ready) {
|
|
3849
|
+
yield err({
|
|
3850
|
+
code: "protocol_error",
|
|
3851
|
+
message: "Receive event arrived before readiness."
|
|
3852
|
+
});
|
|
3853
|
+
return;
|
|
3854
|
+
}
|
|
3855
|
+
try {
|
|
3856
|
+
if (reassembler === null || expectedCursor === null) {
|
|
3857
|
+
throw new Error("Receive stream is not ready");
|
|
3858
|
+
}
|
|
3859
|
+
const complete = reassembler.push(frame.segment);
|
|
3860
|
+
if (complete !== null) {
|
|
3861
|
+
if (complete.precedingCursor !== expectedCursor) {
|
|
3862
|
+
throw new Error("Receive event cursor chain is discontinuous");
|
|
3863
|
+
}
|
|
3864
|
+
expectedCursor = complete.event.cursor;
|
|
3865
|
+
yield ok({ type: "event", cursor: complete.event.cursor, event: complete.event });
|
|
3866
|
+
}
|
|
3867
|
+
} catch {
|
|
3868
|
+
yield err({ code: "protocol_error", message: "Receive stream segmentation failed." });
|
|
3869
|
+
return;
|
|
3870
|
+
}
|
|
3871
|
+
continue;
|
|
3872
|
+
}
|
|
3873
|
+
if (frame.stream === "end") {
|
|
3874
|
+
ended = true;
|
|
3875
|
+
return;
|
|
3876
|
+
}
|
|
3877
|
+
if (frame.stream === "error" && isErrorRecord(frame.error)) {
|
|
3878
|
+
yield err(frame.error);
|
|
3879
|
+
return;
|
|
3880
|
+
}
|
|
3881
|
+
yield err({ code: "protocol_error", message: "Invalid receive stream frame." });
|
|
3882
|
+
return;
|
|
3883
|
+
}
|
|
3884
|
+
if (!ended && !options.signal.aborted) {
|
|
3885
|
+
yield err({
|
|
3886
|
+
code: "runtime_unavailable",
|
|
3887
|
+
message: "Runtime connection closed before the receive stream ended."
|
|
3888
|
+
});
|
|
3889
|
+
}
|
|
3890
|
+
} catch (error) {
|
|
3891
|
+
if (!options.signal.aborted) yield err(connectionError(error));
|
|
3892
|
+
} finally {
|
|
3893
|
+
socket.destroy();
|
|
3894
|
+
}
|
|
3895
|
+
}
|
|
3896
|
+
status(input, options) {
|
|
3897
|
+
return this.#request("agent.status", input, options);
|
|
3898
|
+
}
|
|
3899
|
+
list(options) {
|
|
3900
|
+
return this.#request("agent.list", {}, options);
|
|
3901
|
+
}
|
|
3902
|
+
async destroy(input, options) {
|
|
3903
|
+
const bound = await this.#bind(input, options);
|
|
3904
|
+
if (!bound.ok) return bound;
|
|
3905
|
+
return this.#request("agent.destroy", bound.value, options);
|
|
3906
|
+
}
|
|
3907
|
+
async compact(input, options) {
|
|
3908
|
+
const bound = await this.#bind(input, options);
|
|
3909
|
+
if (!bound.ok) return bound;
|
|
3910
|
+
return this.#request("agent.compact", bound.value, options);
|
|
3911
|
+
}
|
|
3912
|
+
async #bind(input, options) {
|
|
3913
|
+
if (input.expectedAgentId !== void 0) {
|
|
3914
|
+
return ok({ ...input, expectedAgentId: input.expectedAgentId });
|
|
3915
|
+
}
|
|
3916
|
+
const status = await this.status(
|
|
3917
|
+
{ name: input.name },
|
|
3918
|
+
{
|
|
3919
|
+
signal: options.signal,
|
|
3920
|
+
...options.timeoutMs === void 0 ? {} : { timeoutMs: options.timeoutMs }
|
|
3921
|
+
}
|
|
3922
|
+
);
|
|
3923
|
+
if (!status.ok) return status;
|
|
3924
|
+
return ok({ ...input, expectedAgentId: status.value.agent.id });
|
|
3925
|
+
}
|
|
3926
|
+
async #request(method, params, options) {
|
|
3927
|
+
let socket;
|
|
3928
|
+
try {
|
|
3929
|
+
await this.options.beforeConnect?.();
|
|
3930
|
+
socket = await connect(this.options.socketPath, options.signal);
|
|
3931
|
+
} catch (error) {
|
|
3932
|
+
return err(connectionError(error));
|
|
3933
|
+
}
|
|
3934
|
+
const requestId = randomUUID2();
|
|
3935
|
+
let piIdentity;
|
|
3936
|
+
try {
|
|
3937
|
+
piIdentity = requiresPiIdentity(method) ? await this.#piIdentity() : void 0;
|
|
3938
|
+
} catch (error) {
|
|
3939
|
+
socket.destroy();
|
|
3940
|
+
return err(piSelectionError(error));
|
|
3941
|
+
}
|
|
3942
|
+
const response = firstMatchingFrame(socket, requestId, options.signal);
|
|
3943
|
+
writeJsonLine(socket, {
|
|
3944
|
+
v: PROTOCOL_VERSION,
|
|
3945
|
+
requestId,
|
|
3946
|
+
method,
|
|
3947
|
+
params,
|
|
3948
|
+
...isMutationOptions(options) ? { operation: options.operation } : {},
|
|
3949
|
+
...piIdentity === void 0 ? {} : { runtime: { pi: piIdentity } }
|
|
3950
|
+
});
|
|
3951
|
+
try {
|
|
3952
|
+
const frame = await response;
|
|
3953
|
+
if (!isRecord2(frame) || frame.requestId !== requestId || typeof frame.ok !== "boolean") {
|
|
3954
|
+
return err({ code: "protocol_error", message: "Invalid runtime response." });
|
|
3955
|
+
}
|
|
3956
|
+
if (frame.v !== PROTOCOL_VERSION) return err(protocolIncompatible());
|
|
3957
|
+
if (frame.ok) return ok(frame.result);
|
|
3958
|
+
if (isErrorRecord(frame.error)) return err(frame.error);
|
|
3959
|
+
return err({ code: "protocol_error", message: "Runtime returned an invalid error." });
|
|
3960
|
+
} catch (error) {
|
|
3961
|
+
return err(connectionError(error));
|
|
3962
|
+
} finally {
|
|
3963
|
+
socket.destroy();
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
async #piIdentity() {
|
|
3967
|
+
const configured = this.options.piIdentity;
|
|
3968
|
+
if (configured === void 0) return MANAGED_PI_RUNTIME_IDENTITY;
|
|
3969
|
+
return typeof configured === "function" ? configured() : configured;
|
|
3970
|
+
}
|
|
3971
|
+
};
|
|
3972
|
+
function receiveParams(input) {
|
|
3973
|
+
const start = input.start ?? { kind: "live" };
|
|
3974
|
+
return {
|
|
3975
|
+
name: input.name,
|
|
3976
|
+
...input.expectedAgentId === void 0 ? {} : { expectedAgentId: input.expectedAgentId },
|
|
3977
|
+
...start.kind === "after" ? { after: start.cursor } : {},
|
|
3978
|
+
...start.kind === "start" ? { fromStart: true } : {},
|
|
3979
|
+
...input.untilIdle === true ? { untilIdle: true } : {}
|
|
3980
|
+
};
|
|
3981
|
+
}
|
|
3982
|
+
function protocolIncompatible() {
|
|
3983
|
+
return {
|
|
3984
|
+
code: "protocol_incompatible",
|
|
3985
|
+
message: "The running pi-fleet runtime is incompatible with this client; repair or restart it."
|
|
3986
|
+
};
|
|
3987
|
+
}
|
|
3988
|
+
function piSelectionError(error) {
|
|
3989
|
+
const code = error.code;
|
|
3990
|
+
if (code === "pi_not_found" || code === "pi_not_executable" || code === "pi_version_unavailable" || code === "pi_version_unsupported" || code === "pi_installation_changed" || code === "pi_service_mismatch") {
|
|
3991
|
+
return { code, message: error instanceof Error ? error.message : "Pi is unavailable." };
|
|
3992
|
+
}
|
|
3993
|
+
return { code: "internal_error", message: "Pi selection failed." };
|
|
3994
|
+
}
|
|
3995
|
+
function isMutationOptions(options) {
|
|
3996
|
+
return "operation" in options;
|
|
3997
|
+
}
|
|
3998
|
+
function requiresPiIdentity(method) {
|
|
3999
|
+
return method === "agent.create" || method === "agent.send" || method === "agent.compact";
|
|
4000
|
+
}
|
|
4001
|
+
function connect(socketPath, signal) {
|
|
4002
|
+
return new Promise((resolveConnect, rejectConnect) => {
|
|
4003
|
+
if (signal.aborted) {
|
|
4004
|
+
rejectConnect(new Error("Request cancelled"));
|
|
4005
|
+
return;
|
|
4006
|
+
}
|
|
4007
|
+
const socket = createConnection2(socketPath);
|
|
4008
|
+
const onAbort = () => socket.destroy(new Error("Request cancelled"));
|
|
4009
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4010
|
+
socket.once("connect", () => {
|
|
4011
|
+
signal.removeEventListener("abort", onAbort);
|
|
4012
|
+
resolveConnect(socket);
|
|
4013
|
+
});
|
|
4014
|
+
socket.once("error", rejectConnect);
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
function firstMatchingFrame(socket, requestId, signal) {
|
|
4018
|
+
return new Promise((resolveFrame, rejectFrame) => {
|
|
4019
|
+
let settled = false;
|
|
4020
|
+
const finish = (action) => {
|
|
4021
|
+
if (settled) return;
|
|
4022
|
+
settled = true;
|
|
4023
|
+
stop();
|
|
4024
|
+
signal.removeEventListener("abort", onAbort);
|
|
4025
|
+
action();
|
|
4026
|
+
};
|
|
4027
|
+
const stop = readJsonLines(
|
|
4028
|
+
socket,
|
|
4029
|
+
(frame) => {
|
|
4030
|
+
if (!isRecord2(frame) || frame.requestId !== requestId) return;
|
|
4031
|
+
finish(() => resolveFrame(frame));
|
|
4032
|
+
},
|
|
4033
|
+
(error) => finish(() => rejectFrame(error))
|
|
4034
|
+
);
|
|
4035
|
+
const onAbort = () => finish(() => rejectFrame(new Error("Request cancelled")));
|
|
4036
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4037
|
+
socket.once(
|
|
4038
|
+
"close",
|
|
4039
|
+
() => finish(() => rejectFrame(new Error("Runtime connection closed before responding")))
|
|
4040
|
+
);
|
|
4041
|
+
});
|
|
4042
|
+
}
|
|
4043
|
+
async function* frameIterator(socket, signal, maxQueuedBytes = 1024 * 1024) {
|
|
4044
|
+
const queue = [];
|
|
4045
|
+
let queuedBytes = 0;
|
|
4046
|
+
let paused = false;
|
|
4047
|
+
let ended = false;
|
|
4048
|
+
let failure = null;
|
|
4049
|
+
let wake = null;
|
|
4050
|
+
const notify = () => {
|
|
4051
|
+
wake?.();
|
|
4052
|
+
wake = null;
|
|
4053
|
+
};
|
|
4054
|
+
const stop = readJsonLines(
|
|
4055
|
+
socket,
|
|
4056
|
+
(frame) => {
|
|
4057
|
+
const bytes = Buffer.byteLength(JSON.stringify(frame));
|
|
4058
|
+
queue.push({ value: frame, bytes });
|
|
4059
|
+
queuedBytes += bytes;
|
|
4060
|
+
if (queuedBytes >= maxQueuedBytes && !paused) {
|
|
4061
|
+
socket.pause();
|
|
4062
|
+
paused = true;
|
|
4063
|
+
}
|
|
4064
|
+
notify();
|
|
4065
|
+
},
|
|
4066
|
+
(error) => {
|
|
4067
|
+
failure = error;
|
|
4068
|
+
ended = true;
|
|
4069
|
+
notify();
|
|
4070
|
+
}
|
|
4071
|
+
);
|
|
4072
|
+
socket.once("end", () => {
|
|
4073
|
+
failure = new Error("Runtime connection closed before completing the stream");
|
|
4074
|
+
ended = true;
|
|
4075
|
+
notify();
|
|
4076
|
+
});
|
|
4077
|
+
const onAbort = () => {
|
|
4078
|
+
failure = new Error("Request cancelled");
|
|
4079
|
+
ended = true;
|
|
4080
|
+
notify();
|
|
4081
|
+
};
|
|
4082
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4083
|
+
try {
|
|
4084
|
+
while (!ended || queue.length > 0) {
|
|
4085
|
+
if (queue.length === 0) {
|
|
4086
|
+
await new Promise((resolveWake) => {
|
|
4087
|
+
wake = resolveWake;
|
|
4088
|
+
});
|
|
4089
|
+
continue;
|
|
4090
|
+
}
|
|
4091
|
+
const item = queue.shift();
|
|
4092
|
+
if (item === void 0) continue;
|
|
4093
|
+
queuedBytes -= item.bytes;
|
|
4094
|
+
if (paused && queuedBytes < maxQueuedBytes / 2) {
|
|
4095
|
+
socket.resume();
|
|
4096
|
+
paused = false;
|
|
4097
|
+
}
|
|
4098
|
+
yield item.value;
|
|
4099
|
+
}
|
|
4100
|
+
if (failure !== null) throw failure;
|
|
4101
|
+
} finally {
|
|
4102
|
+
stop();
|
|
4103
|
+
signal.removeEventListener("abort", onAbort);
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
function isSemanticSegment(value) {
|
|
4107
|
+
return isRecord2(value) && value.type === "semantic.segment";
|
|
4108
|
+
}
|
|
4109
|
+
function isRecord2(value) {
|
|
4110
|
+
return typeof value === "object" && value !== null;
|
|
4111
|
+
}
|
|
4112
|
+
function isPositiveSafeInteger(value) {
|
|
4113
|
+
return Number.isSafeInteger(value) && typeof value === "number" && value > 0;
|
|
4114
|
+
}
|
|
4115
|
+
function isErrorRecord(value) {
|
|
4116
|
+
return isRecord2(value) && isPiFleetErrorCode(value.code) && typeof value.message === "string" && isSafeErrorDetails(value.code, value.details);
|
|
4117
|
+
}
|
|
4118
|
+
function isSafeErrorDetails(code, details) {
|
|
4119
|
+
if (details === void 0) return true;
|
|
4120
|
+
if (!isRecord2(details)) return false;
|
|
4121
|
+
const allowed = code === "observation_uncertain" ? ["lastSafeCursor", "continuationCursor"] : ["lastSafeCursor"];
|
|
4122
|
+
if (Object.keys(details).some((key) => !allowed.includes(key))) return false;
|
|
4123
|
+
if (!(typeof details.lastSafeCursor === "string" || details.lastSafeCursor === void 0)) {
|
|
4124
|
+
return false;
|
|
4125
|
+
}
|
|
4126
|
+
if (code !== "observation_uncertain") return true;
|
|
4127
|
+
return typeof details.continuationCursor === "string" || details.continuationCursor === null;
|
|
4128
|
+
}
|
|
4129
|
+
function connectionError(error) {
|
|
4130
|
+
void error;
|
|
4131
|
+
return {
|
|
4132
|
+
code: "runtime_unavailable",
|
|
4133
|
+
message: "Unable to connect to pi-fleet runtime."
|
|
4134
|
+
};
|
|
4135
|
+
}
|
|
4136
|
+
|
|
4137
|
+
// src/client/shared-client.ts
|
|
4138
|
+
function createSharedClientConnection(options) {
|
|
4139
|
+
const env = {
|
|
4140
|
+
...process.env,
|
|
4141
|
+
...options.env,
|
|
4142
|
+
...options.stateRoot === void 0 ? {} : { PIFLEET_STATE_ROOT: options.stateRoot }
|
|
4143
|
+
};
|
|
4144
|
+
const paths = resolveFleetPaths(env);
|
|
4145
|
+
let installation;
|
|
4146
|
+
const selectedPi = () => installation ??= resolveExternalPiInstallation({ env });
|
|
4147
|
+
const selectPiForMutation = async () => {
|
|
4148
|
+
const selected = await selectedPi();
|
|
4149
|
+
if (env.PIFLEET_DISABLE_REGISTERED_SERVICE !== "1") {
|
|
4150
|
+
await assertRegisteredPiSelection({
|
|
4151
|
+
selectedPath: selected.selectedPath,
|
|
4152
|
+
nodePath: selected.nodePath
|
|
4153
|
+
});
|
|
4154
|
+
}
|
|
4155
|
+
return selected;
|
|
4156
|
+
};
|
|
4157
|
+
const ensureControlPlane = () => ensureRuntime({
|
|
4158
|
+
socketPath: paths.socketPath,
|
|
4159
|
+
env,
|
|
4160
|
+
...options.applicationRoot === void 0 ? {} : { applicationRoot: options.applicationRoot },
|
|
4161
|
+
piInstallation: async () => {
|
|
4162
|
+
try {
|
|
4163
|
+
return await selectedPi();
|
|
4164
|
+
} catch {
|
|
4165
|
+
return null;
|
|
4166
|
+
}
|
|
4167
|
+
}
|
|
4168
|
+
});
|
|
4169
|
+
const client = new SocketFleetClient({
|
|
4170
|
+
socketPath: paths.socketPath,
|
|
4171
|
+
...options.autoStartRuntime ? { beforeConnect: ensureControlPlane } : {},
|
|
4172
|
+
piIdentity: async () => installationIdentity(await selectPiForMutation())
|
|
4173
|
+
});
|
|
4174
|
+
return {
|
|
4175
|
+
client,
|
|
4176
|
+
operationIds: () => ({
|
|
4177
|
+
operationId: randomUUID3(),
|
|
4178
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4179
|
+
}),
|
|
4180
|
+
ensureControlPlane,
|
|
4181
|
+
selectPiForMutation
|
|
4182
|
+
};
|
|
4183
|
+
}
|
|
4184
|
+
|
|
4185
|
+
// src/client/sdk-transport.ts
|
|
4186
|
+
var FleetClientSdkTransport = class {
|
|
4187
|
+
constructor(client, operationIds, options = {}) {
|
|
4188
|
+
this.client = client;
|
|
4189
|
+
this.operationIds = operationIds;
|
|
4190
|
+
this.#reconnectDelayMs = options.reconnectDelayMs ?? 50;
|
|
4191
|
+
this.#autoReconnect = options.autoReconnect !== false;
|
|
4192
|
+
}
|
|
4193
|
+
#reconnectDelayMs;
|
|
4194
|
+
#autoReconnect;
|
|
4195
|
+
#activeReceiveIterators = /* @__PURE__ */ new Set();
|
|
4196
|
+
#closed = false;
|
|
4197
|
+
async create(input, signal) {
|
|
4198
|
+
const result = await this.client.create(
|
|
4199
|
+
{
|
|
4200
|
+
name: input.name,
|
|
4201
|
+
...input.instructions === void 0 ? {} : { instructions: input.instructions },
|
|
4202
|
+
cwd: input.cwd,
|
|
4203
|
+
piArgv: input.piArgs ?? []
|
|
4204
|
+
},
|
|
4205
|
+
{ signal, operation: this.operationIds() }
|
|
4206
|
+
);
|
|
4207
|
+
return unwrap(result).agent;
|
|
4208
|
+
}
|
|
4209
|
+
async get(name, signal) {
|
|
4210
|
+
const result = await this.client.status({ name }, { signal });
|
|
4211
|
+
if (!result.ok && result.error.code === "agent_not_found") return null;
|
|
4212
|
+
return unwrap(result).agent;
|
|
4213
|
+
}
|
|
4214
|
+
async list(signal) {
|
|
4215
|
+
return unwrap(await this.client.list({ signal })).agents;
|
|
4216
|
+
}
|
|
4217
|
+
async status(target, signal) {
|
|
4218
|
+
return unwrap(await this.client.status(target, { signal })).agent;
|
|
4219
|
+
}
|
|
4220
|
+
async send(target, message, delivery, signal) {
|
|
4221
|
+
const result = unwrap(
|
|
4222
|
+
await this.client.send(
|
|
4223
|
+
{ ...target, message, delivery },
|
|
4224
|
+
{ signal, operation: this.operationIds() }
|
|
4225
|
+
)
|
|
4226
|
+
);
|
|
4227
|
+
return { acceptedAt: result.acceptedAt };
|
|
4228
|
+
}
|
|
4229
|
+
async receive(target, start, signal, untilIdle = false) {
|
|
4230
|
+
const initial = await this.#attach(target, start, signal, void 0, untilIdle);
|
|
4231
|
+
let iterated = false;
|
|
4232
|
+
return {
|
|
4233
|
+
cursor: initial.cursor,
|
|
4234
|
+
[Symbol.asyncIterator]: () => {
|
|
4235
|
+
if (iterated) {
|
|
4236
|
+
throw new PiFleetError("invalid_request", "A receive stream can be iterated only once.");
|
|
4237
|
+
}
|
|
4238
|
+
iterated = true;
|
|
4239
|
+
return this.#events(target, initial, signal, untilIdle);
|
|
4240
|
+
}
|
|
4241
|
+
};
|
|
4242
|
+
}
|
|
4243
|
+
async compact(target, signal) {
|
|
4244
|
+
return unwrap(await this.client.compact(target, { signal, operation: this.operationIds() })).compaction;
|
|
4245
|
+
}
|
|
4246
|
+
async destroy(target, signal) {
|
|
4247
|
+
unwrap(await this.client.destroy(target, { signal, operation: this.operationIds() }));
|
|
4248
|
+
}
|
|
4249
|
+
async close() {
|
|
4250
|
+
if (this.#closed) return;
|
|
4251
|
+
this.#closed = true;
|
|
4252
|
+
const iterators = [...this.#activeReceiveIterators];
|
|
4253
|
+
this.#activeReceiveIterators.clear();
|
|
4254
|
+
await Promise.allSettled(iterators.map(async (iterator) => iterator.return?.()));
|
|
4255
|
+
}
|
|
4256
|
+
async *#events(target, initial, signal, untilIdle) {
|
|
4257
|
+
let attachment = initial;
|
|
4258
|
+
let cursor = initial.cursor;
|
|
4259
|
+
while (true) {
|
|
4260
|
+
let reconnect = false;
|
|
4261
|
+
try {
|
|
4262
|
+
while (true) {
|
|
4263
|
+
const next = await attachment.iterator.next();
|
|
4264
|
+
if (next.done) {
|
|
4265
|
+
throwIfAborted(signal);
|
|
4266
|
+
return;
|
|
4267
|
+
}
|
|
4268
|
+
const result = next.value;
|
|
4269
|
+
if (!result.ok) {
|
|
4270
|
+
if (result.error.code === "runtime_unavailable" && !untilIdle && this.#autoReconnect) {
|
|
4271
|
+
reconnect = true;
|
|
4272
|
+
break;
|
|
4273
|
+
}
|
|
4274
|
+
throw publicError(result.error);
|
|
4275
|
+
}
|
|
4276
|
+
if (result.value.type === "ready") {
|
|
4277
|
+
throw new PiFleetError("protocol_error", "Receive emitted duplicate readiness.");
|
|
4278
|
+
}
|
|
4279
|
+
cursor = result.value.cursor;
|
|
4280
|
+
yield result.value.event;
|
|
4281
|
+
}
|
|
4282
|
+
} finally {
|
|
4283
|
+
await this.#release(attachment.iterator);
|
|
4284
|
+
}
|
|
4285
|
+
if (!reconnect) return;
|
|
4286
|
+
await abortableDelay(this.#reconnectDelayMs, signal);
|
|
4287
|
+
attachment = await this.#attach(target, { kind: "after", cursor }, signal, cursor, false);
|
|
4288
|
+
}
|
|
4289
|
+
}
|
|
4290
|
+
async #attach(target, start, signal, expectedCursor, untilIdle = false) {
|
|
4291
|
+
while (true) {
|
|
4292
|
+
throwIfAborted(signal);
|
|
4293
|
+
if (this.#closed) {
|
|
4294
|
+
throw new PiFleetError("runtime_unavailable", "pi-fleet client is closed");
|
|
4295
|
+
}
|
|
4296
|
+
const input = {
|
|
4297
|
+
...target,
|
|
4298
|
+
start,
|
|
4299
|
+
...untilIdle ? { untilIdle: true } : {}
|
|
4300
|
+
};
|
|
4301
|
+
const iterator = this.client.receive(input, { signal })[Symbol.asyncIterator]();
|
|
4302
|
+
this.#activeReceiveIterators.add(iterator);
|
|
4303
|
+
let first;
|
|
4304
|
+
try {
|
|
4305
|
+
first = await iterator.next();
|
|
4306
|
+
} catch (error) {
|
|
4307
|
+
await this.#release(iterator);
|
|
4308
|
+
throw error;
|
|
4309
|
+
}
|
|
4310
|
+
if (first.done) {
|
|
4311
|
+
await this.#release(iterator);
|
|
4312
|
+
throwIfAborted(signal);
|
|
4313
|
+
throw new PiFleetError(
|
|
4314
|
+
"runtime_unavailable",
|
|
4315
|
+
"Runtime connection closed before receive readiness."
|
|
4316
|
+
);
|
|
4317
|
+
}
|
|
4318
|
+
if (!first.value.ok) {
|
|
4319
|
+
await this.#release(iterator);
|
|
4320
|
+
if (first.value.error.code === "runtime_unavailable" && this.#autoReconnect) {
|
|
4321
|
+
await abortableDelay(this.#reconnectDelayMs, signal);
|
|
4322
|
+
continue;
|
|
4323
|
+
}
|
|
4324
|
+
throw publicError(first.value.error);
|
|
4325
|
+
}
|
|
4326
|
+
if (first.value.value.type !== "ready") {
|
|
4327
|
+
await this.#release(iterator);
|
|
4328
|
+
throw new PiFleetError("protocol_error", "Receive event arrived before readiness.");
|
|
4329
|
+
}
|
|
4330
|
+
if (expectedCursor !== void 0 && first.value.value.cursor !== expectedCursor) {
|
|
4331
|
+
await this.#release(iterator);
|
|
4332
|
+
throw new PiFleetError(
|
|
4333
|
+
"protocol_error",
|
|
4334
|
+
"Reconnected receive boundary does not match the last emitted cursor."
|
|
4335
|
+
);
|
|
4336
|
+
}
|
|
4337
|
+
return { cursor: first.value.value.cursor, iterator };
|
|
4338
|
+
}
|
|
4339
|
+
}
|
|
4340
|
+
async #release(iterator) {
|
|
4341
|
+
this.#activeReceiveIterators.delete(iterator);
|
|
4342
|
+
await iterator.return?.();
|
|
4343
|
+
}
|
|
4344
|
+
};
|
|
4345
|
+
function unwrap(result) {
|
|
4346
|
+
if (result.ok) return result.value;
|
|
4347
|
+
throw publicError(result.error);
|
|
4348
|
+
}
|
|
4349
|
+
function publicError(error) {
|
|
4350
|
+
if (!isPiFleetErrorCode(error.code)) {
|
|
4351
|
+
return new PiFleetError("internal_error", "pi-fleet client operation failed");
|
|
4352
|
+
}
|
|
4353
|
+
return new PiFleetError(error.code, error.message, error.details);
|
|
4354
|
+
}
|
|
4355
|
+
function throwIfAborted(signal) {
|
|
4356
|
+
if (signal.aborted) throw new PiFleetError("cancelled", "Operation cancelled.");
|
|
4357
|
+
}
|
|
4358
|
+
function abortableDelay(durationMs, signal) {
|
|
4359
|
+
throwIfAborted(signal);
|
|
4360
|
+
if (durationMs === 0) return Promise.resolve();
|
|
4361
|
+
return new Promise((resolveDelay, rejectDelay) => {
|
|
4362
|
+
const onAbort = () => {
|
|
4363
|
+
clearTimeout(timer);
|
|
4364
|
+
rejectDelay(new PiFleetError("cancelled", "Operation cancelled."));
|
|
4365
|
+
};
|
|
4366
|
+
const timer = setTimeout(() => {
|
|
4367
|
+
signal.removeEventListener("abort", onAbort);
|
|
4368
|
+
resolveDelay();
|
|
4369
|
+
}, durationMs);
|
|
4370
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4371
|
+
});
|
|
4372
|
+
}
|
|
4373
|
+
|
|
4374
|
+
// src/client/sdk-connector.ts
|
|
4375
|
+
function createSdkConnector(dependencies = {}) {
|
|
4376
|
+
const createConnection3 = dependencies.createConnection ?? createSharedClientConnection;
|
|
4377
|
+
return {
|
|
4378
|
+
async connect(options) {
|
|
4379
|
+
throwIfConnectionAborted(options.signal);
|
|
4380
|
+
const connection = createConnection3({
|
|
4381
|
+
...options.stateRoot === void 0 ? {} : { stateRoot: options.stateRoot },
|
|
4382
|
+
...options.applicationRoot === void 0 ? {} : { applicationRoot: options.applicationRoot },
|
|
4383
|
+
autoStartRuntime: options.autoStartRuntime !== false
|
|
4384
|
+
});
|
|
4385
|
+
if (options.autoStartRuntime !== false) {
|
|
4386
|
+
try {
|
|
4387
|
+
await waitForLocalCompletion(connection.ensureControlPlane(), options.signal);
|
|
4388
|
+
} catch (error) {
|
|
4389
|
+
throw PiFleetError.from(error);
|
|
4390
|
+
}
|
|
4391
|
+
}
|
|
4392
|
+
throwIfConnectionAborted(options.signal);
|
|
4393
|
+
const reachable = await waitForLocalCompletion(
|
|
4394
|
+
connection.client.list({ signal: options.signal ?? new AbortController().signal }),
|
|
4395
|
+
options.signal
|
|
4396
|
+
);
|
|
4397
|
+
if (!reachable.ok) throw new PiFleetError(reachable.error.code, reachable.error.message);
|
|
4398
|
+
return new FleetClientSdkTransport(connection.client, connection.operationIds);
|
|
4399
|
+
}
|
|
4400
|
+
};
|
|
4401
|
+
}
|
|
4402
|
+
function throwIfConnectionAborted(signal) {
|
|
4403
|
+
if (signal?.aborted === true) {
|
|
4404
|
+
throw new PiFleetError("cancelled", "Connection cancelled.");
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
function waitForLocalCompletion(operation, signal) {
|
|
4408
|
+
throwIfConnectionAborted(signal);
|
|
4409
|
+
if (signal === void 0) return operation;
|
|
4410
|
+
return new Promise((resolve5, reject) => {
|
|
4411
|
+
const onAbort = () => {
|
|
4412
|
+
reject(new PiFleetError("cancelled", "Connection cancelled."));
|
|
4413
|
+
};
|
|
4414
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4415
|
+
operation.then(
|
|
4416
|
+
(value) => {
|
|
4417
|
+
signal.removeEventListener("abort", onAbort);
|
|
4418
|
+
resolve5(value);
|
|
4419
|
+
},
|
|
4420
|
+
(error) => {
|
|
4421
|
+
signal.removeEventListener("abort", onAbort);
|
|
4422
|
+
reject(error);
|
|
4423
|
+
}
|
|
4424
|
+
);
|
|
4425
|
+
});
|
|
4426
|
+
}
|
|
4427
|
+
|
|
4428
|
+
// src/client/index.ts
|
|
4429
|
+
var connectPiFleet = createConnectPiFleet(createSdkConnector());
|
|
4430
|
+
export {
|
|
4431
|
+
PiFleetError,
|
|
4432
|
+
connectPiFleet
|
|
4433
|
+
};
|
|
4434
|
+
//# sourceMappingURL=client.mjs.map
|