@crvouga/mockingbird-runtime 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -2
- package/dist/adapter-node.d.ts +2521 -0
- package/dist/adapter-node.js +6920 -0
- package/dist/adapter-node.js.map +7 -0
- package/dist/admin-ui.js +25 -0
- package/dist/admin-ui.js.map +7 -0
- package/dist/chunk-2KDYLZXC.js +118 -0
- package/dist/chunk-2KDYLZXC.js.map +7 -0
- package/dist/chunk-2Y25NPCV.js +1289 -0
- package/dist/chunk-2Y25NPCV.js.map +7 -0
- package/dist/chunk-4SAK6MQT.js +246 -0
- package/dist/chunk-4SAK6MQT.js.map +7 -0
- package/dist/chunk-ANCCZFF2.js +778 -0
- package/dist/chunk-ANCCZFF2.js.map +7 -0
- package/dist/chunk-EBGYPQPA.js +198 -0
- package/dist/chunk-EBGYPQPA.js.map +7 -0
- package/dist/chunk-EQLY2YOA.js +274 -0
- package/dist/chunk-EQLY2YOA.js.map +7 -0
- package/dist/chunk-G62YDIIJ.js +7664 -0
- package/dist/chunk-G62YDIIJ.js.map +7 -0
- package/dist/chunk-HU6IOAFC.js +437 -0
- package/dist/chunk-HU6IOAFC.js.map +7 -0
- package/dist/chunk-RNAHPNUJ.js +97 -0
- package/dist/chunk-RNAHPNUJ.js.map +7 -0
- package/dist/chunk-UP4QOSFD.js +87 -0
- package/dist/chunk-UP4QOSFD.js.map +7 -0
- package/dist/chunk-XNS34BPF.js +2489 -0
- package/dist/chunk-XNS34BPF.js.map +7 -0
- package/dist/core.d.ts +356 -0
- package/dist/core.js +51 -0
- package/dist/core.js.map +7 -0
- package/dist/crypto-XS5XCMRJ.js +21 -0
- package/dist/crypto-XS5XCMRJ.js.map +7 -0
- package/dist/helpers-UD7CG4WQ.js +18 -0
- package/dist/helpers-UD7CG4WQ.js.map +7 -0
- package/dist/http-codec.d.ts +72 -0
- package/dist/http-codec.js +25 -0
- package/dist/http-codec.js.map +7 -0
- package/dist/http-provider.d.ts +3243 -0
- package/dist/http-provider.js +37920 -0
- package/dist/http-provider.js.map +7 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +7 -0
- package/dist/mqtt-broker/node.d.ts +632 -0
- package/dist/mqtt-broker/node.js +355 -0
- package/dist/mqtt-broker/node.js.map +7 -0
- package/dist/mqtt-broker.d.ts +990 -0
- package/dist/mqtt-broker.js +913 -0
- package/dist/mqtt-broker.js.map +7 -0
- package/dist/openapi-metadata.d.ts +290 -0
- package/dist/openapi-metadata.js +28 -0
- package/dist/openapi-metadata.js.map +7 -0
- package/dist/openapi.d.ts +252 -0
- package/dist/openapi.js +45 -0
- package/dist/openapi.js.map +7 -0
- package/dist/preview/artifacts.d.ts +19 -0
- package/dist/preview/artifacts.js +40 -0
- package/dist/preview/artifacts.js.map +7 -0
- package/dist/preview/bridge.d.ts +21 -0
- package/dist/preview/bridge.js +9 -0
- package/dist/preview/bridge.js.map +7 -0
- package/dist/preview/harness.d.ts +12 -0
- package/dist/preview/harness.js +65 -0
- package/dist/preview/harness.js.map +7 -0
- package/dist/preview/host.d.ts +30 -0
- package/dist/preview/host.js +70 -0
- package/dist/preview/host.js.map +7 -0
- package/dist/service/admin.d.ts +106 -0
- package/dist/service/admin.js +340 -0
- package/dist/service/admin.js.map +7 -0
- package/dist/service.d.ts +2665 -0
- package/dist/service.js +264 -0
- package/dist/service.js.map +7 -0
- package/dist/sqlite.d.ts +69 -0
- package/dist/sqlite.js +19 -0
- package/dist/sqlite.js.map +7 -0
- package/dist/ui.d.ts +37 -0
- package/dist/ui.js +702 -0
- package/dist/ui.js.map +7 -0
- package/package.json +135 -4
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
// ../openapi/core/dist/refs.js
|
|
2
|
+
var OpenAPIReferenceError = class extends Error {
|
|
3
|
+
ref;
|
|
4
|
+
constructor(ref) {
|
|
5
|
+
super(`unresolvable $ref: ${ref}`);
|
|
6
|
+
this.ref = ref;
|
|
7
|
+
this.name = "OpenAPIReferenceError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var unescapePointer = (segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
11
|
+
var isReference = (value) => typeof value === "object" && value !== null && typeof value.$ref === "string";
|
|
12
|
+
var resolveRef = (document, ref) => {
|
|
13
|
+
if (!ref.startsWith("#/"))
|
|
14
|
+
throw new OpenAPIReferenceError(ref);
|
|
15
|
+
let cursor = document;
|
|
16
|
+
for (const raw of ref.slice(2).split("/")) {
|
|
17
|
+
const segment = unescapePointer(raw);
|
|
18
|
+
if (typeof cursor !== "object" || cursor === null || !(segment in cursor)) {
|
|
19
|
+
throw new OpenAPIReferenceError(ref);
|
|
20
|
+
}
|
|
21
|
+
cursor = cursor[segment];
|
|
22
|
+
}
|
|
23
|
+
if (cursor === void 0)
|
|
24
|
+
throw new OpenAPIReferenceError(ref);
|
|
25
|
+
return cursor;
|
|
26
|
+
};
|
|
27
|
+
var deref = (document, value) => {
|
|
28
|
+
let current = value;
|
|
29
|
+
const seen = /* @__PURE__ */ new Set();
|
|
30
|
+
while (isReference(current)) {
|
|
31
|
+
if (seen.has(current.$ref))
|
|
32
|
+
throw new OpenAPIReferenceError(`${current.$ref} (cycle)`);
|
|
33
|
+
seen.add(current.$ref);
|
|
34
|
+
current = resolveRef(document, current.$ref);
|
|
35
|
+
}
|
|
36
|
+
return current;
|
|
37
|
+
};
|
|
38
|
+
var componentNameOf = (ref) => {
|
|
39
|
+
const match = /^#\/components\/[^/]+\/(.+)$/.exec(ref);
|
|
40
|
+
return match?.[1] === void 0 ? void 0 : unescapePointer(match[1]);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// ../openapi/core/dist/types.js
|
|
44
|
+
var HTTP_METHODS = [
|
|
45
|
+
"get",
|
|
46
|
+
"put",
|
|
47
|
+
"post",
|
|
48
|
+
"delete",
|
|
49
|
+
"options",
|
|
50
|
+
"head",
|
|
51
|
+
"patch",
|
|
52
|
+
"trace"
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
// ../openapi/core/dist/document.js
|
|
56
|
+
var OpenAPIDocumentError = class extends Error {
|
|
57
|
+
issues;
|
|
58
|
+
constructor(issues) {
|
|
59
|
+
super(`invalid OpenAPI document:
|
|
60
|
+
${issues.map((issue) => ` - ${issue}`).join("\n")}`);
|
|
61
|
+
this.issues = issues;
|
|
62
|
+
this.name = "OpenAPIDocumentError";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
66
|
+
var parseOpenAPIDocument = (value) => {
|
|
67
|
+
const issues = [];
|
|
68
|
+
if (!isRecord(value))
|
|
69
|
+
throw new OpenAPIDocumentError(["document must be an object"]);
|
|
70
|
+
if (typeof value.openapi !== "string" || !/^3\.[01]\./.test(value.openapi)) {
|
|
71
|
+
issues.push(`openapi must be a 3.0.x or 3.1.x version string, got ${JSON.stringify(value.openapi)}`);
|
|
72
|
+
}
|
|
73
|
+
if (!isRecord(value.info) || typeof value.info.title !== "string" || typeof value.info.version !== "string") {
|
|
74
|
+
issues.push("info.title and info.version are required strings");
|
|
75
|
+
}
|
|
76
|
+
if (!isRecord(value.paths))
|
|
77
|
+
issues.push("paths must be an object");
|
|
78
|
+
if (issues.length > 0)
|
|
79
|
+
throw new OpenAPIDocumentError(issues);
|
|
80
|
+
const document = value;
|
|
81
|
+
const problems = validateOpenAPIDocument(document);
|
|
82
|
+
if (problems.length > 0)
|
|
83
|
+
throw new OpenAPIDocumentError(problems);
|
|
84
|
+
return document;
|
|
85
|
+
};
|
|
86
|
+
var walkRefs = (document, node, at, issues, seen) => {
|
|
87
|
+
if (typeof node !== "object" || node === null || seen.has(node))
|
|
88
|
+
return;
|
|
89
|
+
seen.add(node);
|
|
90
|
+
if (isReference(node)) {
|
|
91
|
+
try {
|
|
92
|
+
resolveRef(document, node.$ref);
|
|
93
|
+
} catch {
|
|
94
|
+
issues.push(`${at}: unresolvable $ref ${node.$ref}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const [key, child] of Object.entries(node))
|
|
98
|
+
walkRefs(document, child, `${at}/${key}`, issues, seen);
|
|
99
|
+
};
|
|
100
|
+
var templateParams = (path) => [...path.matchAll(/\{([^}]+)\}/g)].map((m) => m[1]);
|
|
101
|
+
var validateOpenAPIDocument = (document) => {
|
|
102
|
+
const issues = [];
|
|
103
|
+
walkRefs(document, document, "#", issues, /* @__PURE__ */ new Set());
|
|
104
|
+
if (issues.length > 0)
|
|
105
|
+
return issues;
|
|
106
|
+
const seenIds = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const [path, item] of Object.entries(document.paths)) {
|
|
108
|
+
if (!isRecord(item)) {
|
|
109
|
+
issues.push(`paths.${path}: must be an object`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const inTemplate = new Set(templateParams(path));
|
|
113
|
+
for (const method of HTTP_METHODS) {
|
|
114
|
+
const operation = item[method];
|
|
115
|
+
if (operation === void 0)
|
|
116
|
+
continue;
|
|
117
|
+
const label = `${method.toUpperCase()} ${path}`;
|
|
118
|
+
if (typeof operation.operationId !== "string" || operation.operationId.length === 0) {
|
|
119
|
+
issues.push(`${label}: operationId is required`);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const previous = seenIds.get(operation.operationId);
|
|
123
|
+
if (previous !== void 0)
|
|
124
|
+
issues.push(`${label}: duplicate operationId ${operation.operationId} (also ${previous})`);
|
|
125
|
+
seenIds.set(operation.operationId, label);
|
|
126
|
+
if (!isRecord(operation.responses) || Object.keys(operation.responses).length === 0) {
|
|
127
|
+
issues.push(`${label}: responses must declare at least one status`);
|
|
128
|
+
}
|
|
129
|
+
const parameters = mergeParameters(document, item, operation.parameters);
|
|
130
|
+
const declared = new Set(parameters.filter((p) => p.in === "path").map((p) => p.name));
|
|
131
|
+
for (const name of inTemplate) {
|
|
132
|
+
if (!declared.has(name))
|
|
133
|
+
issues.push(`${label}: path parameter {${name}} is not declared`);
|
|
134
|
+
}
|
|
135
|
+
for (const parameter of parameters) {
|
|
136
|
+
if (parameter.in === "path") {
|
|
137
|
+
if (!inTemplate.has(parameter.name))
|
|
138
|
+
issues.push(`${label}: path parameter ${parameter.name} is not in the template`);
|
|
139
|
+
if (parameter.required !== true)
|
|
140
|
+
issues.push(`${label}: path parameter ${parameter.name} must be required`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return issues;
|
|
146
|
+
};
|
|
147
|
+
var mergeParameters = (document, item, own) => {
|
|
148
|
+
const merged = /* @__PURE__ */ new Map();
|
|
149
|
+
for (const raw of item.parameters ?? []) {
|
|
150
|
+
const parameter = deref(document, raw);
|
|
151
|
+
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
152
|
+
}
|
|
153
|
+
for (const raw of own ?? []) {
|
|
154
|
+
const parameter = deref(document, raw);
|
|
155
|
+
merged.set(`${parameter.in}:${parameter.name}`, parameter);
|
|
156
|
+
}
|
|
157
|
+
return [...merged.values()];
|
|
158
|
+
};
|
|
159
|
+
var listOperations = (document) => {
|
|
160
|
+
const operations = [];
|
|
161
|
+
for (const [path, item] of Object.entries(document.paths)) {
|
|
162
|
+
for (const method of HTTP_METHODS) {
|
|
163
|
+
const operation = item[method];
|
|
164
|
+
if (operation?.operationId === void 0)
|
|
165
|
+
continue;
|
|
166
|
+
const responses = {};
|
|
167
|
+
for (const [status, response] of Object.entries(operation.responses)) {
|
|
168
|
+
responses[status] = deref(document, response);
|
|
169
|
+
}
|
|
170
|
+
operations.push({
|
|
171
|
+
operationId: operation.operationId,
|
|
172
|
+
method,
|
|
173
|
+
path,
|
|
174
|
+
operation,
|
|
175
|
+
parameters: mergeParameters(document, item, operation.parameters),
|
|
176
|
+
requestBody: operation.requestBody === void 0 ? void 0 : deref(document, operation.requestBody),
|
|
177
|
+
responses
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return operations;
|
|
182
|
+
};
|
|
183
|
+
var findOperation = (document, operationId) => listOperations(document).find((operation) => operation.operationId === operationId);
|
|
184
|
+
var pathTemplateParameters = templateParams;
|
|
185
|
+
var expandPathTemplate = (template, values) => template.replace(/\{([^}]+)\}/g, (_, name) => {
|
|
186
|
+
const value = values[name];
|
|
187
|
+
if (value === void 0)
|
|
188
|
+
throw new RangeError(`missing path parameter ${name}`);
|
|
189
|
+
return encodeURIComponent(value);
|
|
190
|
+
});
|
|
191
|
+
var responseForStatus = (responses, status) => responses[String(status)] ?? responses[`${Math.floor(status / 100)}XX`] ?? responses.default;
|
|
192
|
+
|
|
193
|
+
// ../openapi/core/dist/schema.js
|
|
194
|
+
var resolveSchema = (document, schema) => {
|
|
195
|
+
let current = schema;
|
|
196
|
+
const seen = /* @__PURE__ */ new Set();
|
|
197
|
+
while (typeof current.$ref === "string") {
|
|
198
|
+
const ref = current.$ref;
|
|
199
|
+
if (seen.has(ref))
|
|
200
|
+
break;
|
|
201
|
+
seen.add(ref);
|
|
202
|
+
const { $ref: _ignored, ...siblings } = current;
|
|
203
|
+
const target = resolveRef(document, ref);
|
|
204
|
+
current = { ...target, ...siblings };
|
|
205
|
+
}
|
|
206
|
+
if (current.nullable === true) {
|
|
207
|
+
const { nullable: _nullable, ...rest } = current;
|
|
208
|
+
const types = schemaTypes(rest);
|
|
209
|
+
if (types.length > 0 && !types.includes("null"))
|
|
210
|
+
current = { ...rest, type: [...types, "null"] };
|
|
211
|
+
else
|
|
212
|
+
current = rest;
|
|
213
|
+
}
|
|
214
|
+
return current;
|
|
215
|
+
};
|
|
216
|
+
var schemaTypes = (schema) => {
|
|
217
|
+
if (Array.isArray(schema.type))
|
|
218
|
+
return schema.type;
|
|
219
|
+
if (schema.type !== void 0)
|
|
220
|
+
return [schema.type];
|
|
221
|
+
const inferred = [];
|
|
222
|
+
if (schema.properties || schema.required || schema.additionalProperties !== void 0)
|
|
223
|
+
inferred.push("object");
|
|
224
|
+
if (schema.items || schema.prefixItems || schema.minItems !== void 0 || schema.maxItems !== void 0)
|
|
225
|
+
inferred.push("array");
|
|
226
|
+
if (schema.minLength !== void 0 || schema.maxLength !== void 0 || schema.pattern !== void 0)
|
|
227
|
+
inferred.push("string");
|
|
228
|
+
if (schema.minimum !== void 0 || schema.maximum !== void 0 || schema.multipleOf !== void 0)
|
|
229
|
+
inferred.push("number");
|
|
230
|
+
return inferred;
|
|
231
|
+
};
|
|
232
|
+
var jsonTypeOf = (value) => {
|
|
233
|
+
if (value === null)
|
|
234
|
+
return "null";
|
|
235
|
+
if (Array.isArray(value))
|
|
236
|
+
return "array";
|
|
237
|
+
switch (typeof value) {
|
|
238
|
+
case "string":
|
|
239
|
+
return "string";
|
|
240
|
+
case "boolean":
|
|
241
|
+
return "boolean";
|
|
242
|
+
case "number":
|
|
243
|
+
return Number.isInteger(value) ? "integer" : "number";
|
|
244
|
+
case "object":
|
|
245
|
+
return "object";
|
|
246
|
+
default:
|
|
247
|
+
return "undefined";
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
var walkSchema = (document, schema, visit, path = []) => {
|
|
251
|
+
const seen = /* @__PURE__ */ new Set();
|
|
252
|
+
const go = (node, at) => {
|
|
253
|
+
if (seen.has(node))
|
|
254
|
+
return;
|
|
255
|
+
seen.add(node);
|
|
256
|
+
const resolved = resolveSchema(document, node);
|
|
257
|
+
if (resolved !== node && seen.has(resolved))
|
|
258
|
+
return;
|
|
259
|
+
seen.add(resolved);
|
|
260
|
+
visit(resolved, at);
|
|
261
|
+
for (const [name, child] of Object.entries(resolved.properties ?? {}))
|
|
262
|
+
go(child, [...at, "properties", name]);
|
|
263
|
+
if (typeof resolved.additionalProperties === "object")
|
|
264
|
+
go(resolved.additionalProperties, [...at, "additionalProperties"]);
|
|
265
|
+
if (resolved.items)
|
|
266
|
+
go(resolved.items, [...at, "items"]);
|
|
267
|
+
resolved.prefixItems?.forEach((child, i) => {
|
|
268
|
+
go(child, [...at, "prefixItems", String(i)]);
|
|
269
|
+
});
|
|
270
|
+
resolved.propertyNames && go(resolved.propertyNames, [...at, "propertyNames"]);
|
|
271
|
+
for (const keyword of ["oneOf", "anyOf", "allOf"]) {
|
|
272
|
+
resolved[keyword]?.forEach((child, i) => {
|
|
273
|
+
go(child, [...at, keyword, String(i)]);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
resolved.not && go(resolved.not, [...at, "not"]);
|
|
277
|
+
};
|
|
278
|
+
go(schema, path);
|
|
279
|
+
};
|
|
280
|
+
var deepEqual = (a, b) => {
|
|
281
|
+
if (a === b)
|
|
282
|
+
return true;
|
|
283
|
+
if (typeof a !== typeof b || a === null || b === null)
|
|
284
|
+
return false;
|
|
285
|
+
if (Array.isArray(a)) {
|
|
286
|
+
return Array.isArray(b) && a.length === b.length && a.every((item, i) => deepEqual(item, b[i]));
|
|
287
|
+
}
|
|
288
|
+
if (typeof a === "object" && typeof b === "object" && !Array.isArray(b)) {
|
|
289
|
+
const ka = Object.keys(a);
|
|
290
|
+
const kb = Object.keys(b);
|
|
291
|
+
return ka.length === kb.length && ka.every((k) => deepEqual(a[k], b[k]));
|
|
292
|
+
}
|
|
293
|
+
return false;
|
|
294
|
+
};
|
|
295
|
+
var FORMAT_PATTERNS = {
|
|
296
|
+
uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,
|
|
297
|
+
date: /^\d{4}-\d{2}-\d{2}$/,
|
|
298
|
+
"date-time": /^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(\.\d+)?([Zz]|[+-]\d{2}:\d{2})$/,
|
|
299
|
+
email: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
|
300
|
+
uri: /^[a-zA-Z][a-zA-Z0-9+.-]*:[^\s]*$/,
|
|
301
|
+
ipv4: /^(25[0-5]|2[0-4]\d|1?\d?\d)(\.(25[0-5]|2[0-4]\d|1?\d?\d)){3}$/
|
|
302
|
+
};
|
|
303
|
+
var graphemeLength = (value) => [...value].length;
|
|
304
|
+
var validateValue = (document, schema, value, path = []) => {
|
|
305
|
+
const errors = [];
|
|
306
|
+
const s = resolveSchema(document, schema);
|
|
307
|
+
const fail = (message) => errors.push({ path, message });
|
|
308
|
+
const actual = jsonTypeOf(value);
|
|
309
|
+
if (actual === "undefined") {
|
|
310
|
+
fail("value is undefined");
|
|
311
|
+
return errors;
|
|
312
|
+
}
|
|
313
|
+
const types = schemaTypes(s);
|
|
314
|
+
if (types.length > 0) {
|
|
315
|
+
const ok = types.some((t) => t === actual || t === "number" && actual === "integer");
|
|
316
|
+
if (!ok) {
|
|
317
|
+
fail(`expected type ${types.join("|")}, got ${actual}`);
|
|
318
|
+
return errors;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (s.enum && !(value === null && types.includes("null")) && !s.enum.some((candidate) => deepEqual(candidate, value))) {
|
|
322
|
+
fail("value not in enum");
|
|
323
|
+
}
|
|
324
|
+
if (s.const !== void 0 && !deepEqual(s.const, value))
|
|
325
|
+
fail("value does not equal const");
|
|
326
|
+
if (typeof value === "string") {
|
|
327
|
+
const length = graphemeLength(value);
|
|
328
|
+
if (s.minLength !== void 0 && length < s.minLength)
|
|
329
|
+
fail(`length ${length} < minLength ${s.minLength}`);
|
|
330
|
+
if (s.maxLength !== void 0 && length > s.maxLength)
|
|
331
|
+
fail(`length ${length} > maxLength ${s.maxLength}`);
|
|
332
|
+
if (s.pattern !== void 0) {
|
|
333
|
+
try {
|
|
334
|
+
if (!new RegExp(s.pattern, "u").test(value))
|
|
335
|
+
fail(`does not match pattern ${s.pattern}`);
|
|
336
|
+
} catch {
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (s.format !== void 0) {
|
|
340
|
+
const pattern = FORMAT_PATTERNS[s.format];
|
|
341
|
+
if (pattern && !pattern.test(value))
|
|
342
|
+
fail(`does not match format ${s.format}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
if (typeof value === "number") {
|
|
346
|
+
if (s.minimum !== void 0 && value < s.minimum)
|
|
347
|
+
fail(`${value} < minimum ${s.minimum}`);
|
|
348
|
+
if (s.maximum !== void 0 && value > s.maximum)
|
|
349
|
+
fail(`${value} > maximum ${s.maximum}`);
|
|
350
|
+
if (s.exclusiveMinimum !== void 0 && value <= s.exclusiveMinimum)
|
|
351
|
+
fail(`${value} <= exclusiveMinimum ${s.exclusiveMinimum}`);
|
|
352
|
+
if (s.exclusiveMaximum !== void 0 && value >= s.exclusiveMaximum)
|
|
353
|
+
fail(`${value} >= exclusiveMaximum ${s.exclusiveMaximum}`);
|
|
354
|
+
if (s.multipleOf !== void 0 && Math.abs(value / s.multipleOf - Math.round(value / s.multipleOf)) > 1e-9) {
|
|
355
|
+
fail(`${value} is not a multiple of ${s.multipleOf}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
if (Array.isArray(value)) {
|
|
359
|
+
if (s.minItems !== void 0 && value.length < s.minItems)
|
|
360
|
+
fail(`${value.length} items < minItems ${s.minItems}`);
|
|
361
|
+
if (s.maxItems !== void 0 && value.length > s.maxItems)
|
|
362
|
+
fail(`${value.length} items > maxItems ${s.maxItems}`);
|
|
363
|
+
if (s.uniqueItems && value.some((item, i) => value.slice(0, i).some((prev) => deepEqual(prev, item))))
|
|
364
|
+
fail("items are not unique");
|
|
365
|
+
value.forEach((item, i) => {
|
|
366
|
+
const itemSchema = s.prefixItems?.[i] ?? s.items;
|
|
367
|
+
if (itemSchema)
|
|
368
|
+
errors.push(...validateValue(document, itemSchema, item, [...path, i]));
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
if (actual === "object") {
|
|
372
|
+
const record = value;
|
|
373
|
+
const keys = Object.keys(record);
|
|
374
|
+
for (const name of s.required ?? [])
|
|
375
|
+
if (!(name in record))
|
|
376
|
+
fail(`missing required property ${name}`);
|
|
377
|
+
if (s.minProperties !== void 0 && keys.length < s.minProperties)
|
|
378
|
+
fail(`${keys.length} properties < minProperties ${s.minProperties}`);
|
|
379
|
+
if (s.maxProperties !== void 0 && keys.length > s.maxProperties)
|
|
380
|
+
fail(`${keys.length} properties > maxProperties ${s.maxProperties}`);
|
|
381
|
+
for (const key of keys) {
|
|
382
|
+
const property = s.properties?.[key];
|
|
383
|
+
if (property) {
|
|
384
|
+
errors.push(...validateValue(document, property, record[key], [...path, key]));
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
if (s.additionalProperties === false)
|
|
388
|
+
fail(`unexpected property ${key}`);
|
|
389
|
+
else if (typeof s.additionalProperties === "object") {
|
|
390
|
+
errors.push(...validateValue(document, s.additionalProperties, record[key], [...path, key]));
|
|
391
|
+
}
|
|
392
|
+
if (s.propertyNames) {
|
|
393
|
+
const nameErrors = validateValue(document, s.propertyNames, key, [...path, key]);
|
|
394
|
+
if (nameErrors.length > 0)
|
|
395
|
+
fail(`property name ${key} is invalid: ${nameErrors[0]?.message}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
if (s.allOf)
|
|
400
|
+
for (const branch of s.allOf)
|
|
401
|
+
errors.push(...validateValue(document, branch, value, path));
|
|
402
|
+
if (s.anyOf && !s.anyOf.some((branch) => validateValue(document, branch, value).length === 0))
|
|
403
|
+
fail("matches no anyOf branch");
|
|
404
|
+
if (s.oneOf) {
|
|
405
|
+
const matches = s.oneOf.filter((branch) => validateValue(document, branch, value).length === 0).length;
|
|
406
|
+
if (matches !== 1)
|
|
407
|
+
fail(`matches ${matches} oneOf branches, expected exactly 1`);
|
|
408
|
+
}
|
|
409
|
+
if (s.not && validateValue(document, s.not, value).length === 0)
|
|
410
|
+
fail("matches forbidden `not` schema");
|
|
411
|
+
return errors;
|
|
412
|
+
};
|
|
413
|
+
var isValid = (document, schema, value) => validateValue(document, schema, value).length === 0;
|
|
414
|
+
|
|
415
|
+
export {
|
|
416
|
+
OpenAPIReferenceError,
|
|
417
|
+
isReference,
|
|
418
|
+
resolveRef,
|
|
419
|
+
deref,
|
|
420
|
+
componentNameOf,
|
|
421
|
+
HTTP_METHODS,
|
|
422
|
+
OpenAPIDocumentError,
|
|
423
|
+
parseOpenAPIDocument,
|
|
424
|
+
validateOpenAPIDocument,
|
|
425
|
+
listOperations,
|
|
426
|
+
findOperation,
|
|
427
|
+
pathTemplateParameters,
|
|
428
|
+
expandPathTemplate,
|
|
429
|
+
responseForStatus,
|
|
430
|
+
resolveSchema,
|
|
431
|
+
schemaTypes,
|
|
432
|
+
jsonTypeOf,
|
|
433
|
+
walkSchema,
|
|
434
|
+
validateValue,
|
|
435
|
+
isValid
|
|
436
|
+
};
|
|
437
|
+
//# sourceMappingURL=chunk-HU6IOAFC.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../openapi/core/src/refs.ts", "../../openapi/core/src/types.ts", "../../openapi/core/src/document.ts", "../../openapi/core/src/schema.ts"],
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIDocument, ReferenceObject } from \"./types.js\"\n\nexport class OpenAPIReferenceError extends Error {\n constructor(readonly ref: string) {\n super(`unresolvable $ref: ${ref}`)\n this.name = \"OpenAPIReferenceError\"\n }\n}\n\nconst unescapePointer = (segment: string) => segment.replace(/~1/g, \"/\").replace(/~0/g, \"~\")\n\n/** True when `value` is a `{ $ref }` object. */\nexport const isReference = (value: unknown): value is ReferenceObject =>\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { $ref?: unknown }).$ref === \"string\"\n\n/** Resolve a local JSON pointer reference (`#/components/schemas/customer`) inside `document`. */\nexport const resolveRef = (document: OpenAPIDocument, ref: string): unknown => {\n if (!ref.startsWith(\"#/\")) throw new OpenAPIReferenceError(ref)\n let cursor: unknown = document\n for (const raw of ref.slice(2).split(\"/\")) {\n const segment = unescapePointer(raw)\n if (typeof cursor !== \"object\" || cursor === null || !(segment in cursor)) {\n throw new OpenAPIReferenceError(ref)\n }\n cursor = (cursor as Record<string, unknown>)[segment]\n }\n if (cursor === undefined) throw new OpenAPIReferenceError(ref)\n return cursor\n}\n\n/**\n * Follow `$ref` chains until a concrete object is reached. Guards against cycles.\n * Sibling keys next to `$ref` are ignored, as in OpenAPI 3.0/3.1 for non-schema objects.\n */\nexport const deref = <T>(document: OpenAPIDocument, value: T | ReferenceObject): T => {\n let current: unknown = value\n const seen = new Set<string>()\n while (isReference(current)) {\n if (seen.has(current.$ref)) throw new OpenAPIReferenceError(`${current.$ref} (cycle)`)\n seen.add(current.$ref)\n current = resolveRef(document, current.$ref)\n }\n return current as T\n}\n\n/** The component name at the end of a `#/components/<kind>/<name>` reference, if any. */\nexport const componentNameOf = (ref: string): string | undefined => {\n const match = /^#\\/components\\/[^/]+\\/(.+)$/.exec(ref)\n return match?.[1] === undefined ? undefined : unescapePointer(match[1])\n}\n", "/**\n * The slice of OpenAPI 3.1 (and JSON Schema 2020-12) Mockingbird understands.\n * Unknown keys (including `x-*` extensions) are preserved on every object.\n */\n\nexport type JsonPrimitive = string | number | boolean | null\nexport type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }\n\nexport type ReferenceObject = { $ref: string; description?: string; summary?: string }\n\nexport type SchemaType = \"string\" | \"number\" | \"integer\" | \"boolean\" | \"object\" | \"array\" | \"null\"\n\nexport type SchemaObject = {\n $ref?: string\n type?: SchemaType | SchemaType[]\n title?: string\n description?: string\n format?: string\n enum?: JsonValue[]\n const?: JsonValue\n default?: JsonValue\n example?: JsonValue\n examples?: JsonValue[]\n nullable?: boolean\n deprecated?: boolean\n readOnly?: boolean\n writeOnly?: boolean\n minimum?: number\n maximum?: number\n exclusiveMinimum?: number\n exclusiveMaximum?: number\n multipleOf?: number\n minLength?: number\n maxLength?: number\n pattern?: string\n minItems?: number\n maxItems?: number\n uniqueItems?: boolean\n items?: SchemaObject\n prefixItems?: SchemaObject[]\n minProperties?: number\n maxProperties?: number\n required?: string[]\n properties?: Record<string, SchemaObject>\n additionalProperties?: boolean | SchemaObject\n propertyNames?: SchemaObject\n oneOf?: SchemaObject[]\n anyOf?: SchemaObject[]\n allOf?: SchemaObject[]\n not?: SchemaObject\n discriminator?: { propertyName: string; mapping?: Record<string, string> }\n [extension: `x-${string}`]: unknown\n}\n\nexport type ParameterLocation = \"path\" | \"query\" | \"header\" | \"cookie\"\n\nexport type ParameterObject = {\n name: string\n in: ParameterLocation\n description?: string\n required?: boolean\n deprecated?: boolean\n style?: string\n explode?: boolean\n schema?: SchemaObject\n content?: Record<string, MediaTypeObject>\n example?: JsonValue\n [extension: `x-${string}`]: unknown\n}\n\nexport type MediaTypeObject = {\n schema?: SchemaObject\n example?: JsonValue\n examples?: Record<string, unknown>\n encoding?: Record<string, unknown>\n [extension: `x-${string}`]: unknown\n}\n\nexport type RequestBodyObject = {\n description?: string\n required?: boolean\n content: Record<string, MediaTypeObject>\n [extension: `x-${string}`]: unknown\n}\n\nexport type HeaderObject = {\n description?: string\n required?: boolean\n schema?: SchemaObject\n [extension: `x-${string}`]: unknown\n}\n\nexport type ResponseObject = {\n description: string\n headers?: Record<string, HeaderObject | ReferenceObject>\n content?: Record<string, MediaTypeObject>\n [extension: `x-${string}`]: unknown\n}\n\nexport type ResponsesObject = Record<string, ResponseObject | ReferenceObject>\n\nexport type SecurityRequirementObject = Record<string, string[]>\n\nexport type OperationObject = {\n operationId?: string\n summary?: string\n description?: string\n tags?: string[]\n deprecated?: boolean\n parameters?: Array<ParameterObject | ReferenceObject>\n requestBody?: RequestBodyObject | ReferenceObject\n responses: ResponsesObject\n security?: SecurityRequirementObject[]\n [extension: `x-${string}`]: unknown\n}\n\nexport const HTTP_METHODS = [\n \"get\",\n \"put\",\n \"post\",\n \"delete\",\n \"options\",\n \"head\",\n \"patch\",\n \"trace\",\n] as const\nexport type HttpMethod = (typeof HTTP_METHODS)[number]\n\nexport type PathItemObject = {\n summary?: string\n description?: string\n parameters?: Array<ParameterObject | ReferenceObject>\n [extension: `x-${string}`]: unknown\n} & Partial<Record<HttpMethod, OperationObject>>\n\nexport type SecuritySchemeObject = {\n type: \"apiKey\" | \"http\" | \"oauth2\" | \"openIdConnect\" | \"mutualTLS\"\n description?: string\n name?: string\n in?: ParameterLocation\n scheme?: string\n bearerFormat?: string\n flows?: Record<string, unknown>\n openIdConnectUrl?: string\n [extension: `x-${string}`]: unknown\n}\n\nexport type ComponentsObject = {\n schemas?: Record<string, SchemaObject>\n responses?: Record<string, ResponseObject>\n parameters?: Record<string, ParameterObject>\n requestBodies?: Record<string, RequestBodyObject>\n headers?: Record<string, HeaderObject>\n securitySchemes?: Record<string, SecuritySchemeObject>\n [extension: `x-${string}`]: unknown\n}\n\nexport type ServerObject = {\n url: string\n description?: string\n variables?: Record<string, unknown>\n [extension: `x-${string}`]: unknown\n}\n\nexport type InfoObject = {\n title: string\n version: string\n description?: string\n [extension: `x-${string}`]: unknown\n}\n\nexport type OpenAPIDocument = {\n openapi: string\n info: InfoObject\n servers?: ServerObject[]\n paths: Record<string, PathItemObject>\n components?: ComponentsObject\n security?: SecurityRequirementObject[]\n tags?: Array<{ name: string; description?: string }>\n [extension: `x-${string}`]: unknown\n}\n\n/** One concrete HTTP operation discovered in a document. */\nexport type Operation = {\n operationId: string\n method: HttpMethod\n /** OpenAPI path template, e.g. `/v1/customers/{customer}`. */\n path: string\n operation: OperationObject\n /** Path-level parameters merged with operation-level ones (operation wins), `$ref`s resolved. */\n parameters: ParameterObject[]\n requestBody: RequestBodyObject | undefined\n responses: Record<string, ResponseObject>\n}\n", "import { deref, isReference, resolveRef } from \"./refs.js\"\nimport {\n HTTP_METHODS,\n type HttpMethod,\n type OpenAPIDocument,\n type Operation,\n type ParameterObject,\n type PathItemObject,\n type RequestBodyObject,\n type ResponseObject,\n} from \"./types.js\"\n\nexport class OpenAPIDocumentError extends Error {\n constructor(readonly issues: string[]) {\n super(`invalid OpenAPI document:\\n${issues.map((issue) => ` - ${issue}`).join(\"\\n\")}`)\n this.name = \"OpenAPIDocumentError\"\n }\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n\n/**\n * Accept an already-parsed JSON/YAML value and return it typed as an {@link OpenAPIDocument}.\n * Performs the structural checks Mockingbird relies on (see {@link validateOpenAPIDocument}) and\n * throws {@link OpenAPIDocumentError} listing every problem.\n */\nexport const parseOpenAPIDocument = (value: unknown): OpenAPIDocument => {\n const issues: string[] = []\n if (!isRecord(value)) throw new OpenAPIDocumentError([\"document must be an object\"])\n if (typeof value.openapi !== \"string\" || !/^3\\.[01]\\./.test(value.openapi)) {\n issues.push(\n `openapi must be a 3.0.x or 3.1.x version string, got ${JSON.stringify(value.openapi)}`,\n )\n }\n if (\n !isRecord(value.info) ||\n typeof value.info.title !== \"string\" ||\n typeof value.info.version !== \"string\"\n ) {\n issues.push(\"info.title and info.version are required strings\")\n }\n if (!isRecord(value.paths)) issues.push(\"paths must be an object\")\n if (issues.length > 0) throw new OpenAPIDocumentError(issues)\n const document = value as unknown as OpenAPIDocument\n const problems = validateOpenAPIDocument(document)\n if (problems.length > 0) throw new OpenAPIDocumentError(problems)\n return document\n}\n\nconst walkRefs = (\n document: OpenAPIDocument,\n node: unknown,\n at: string,\n issues: string[],\n seen: Set<unknown>,\n) => {\n if (typeof node !== \"object\" || node === null || seen.has(node)) return\n seen.add(node)\n if (isReference(node)) {\n try {\n resolveRef(document, node.$ref)\n } catch {\n issues.push(`${at}: unresolvable $ref ${node.$ref}`)\n }\n }\n for (const [key, child] of Object.entries(node))\n walkRefs(document, child, `${at}/${key}`, issues, seen)\n}\n\nconst templateParams = (path: string) =>\n [...path.matchAll(/\\{([^}]+)\\}/g)].map((m) => m[1] as string)\n\n/**\n * Mockingbird's document rules:\n * - every operation has a unique `operationId`\n * - every `$ref` resolves\n * - every `{param}` in a path template has a matching required path parameter\n * - every path parameter appears in the template\n */\nexport const validateOpenAPIDocument = (document: OpenAPIDocument): string[] => {\n const issues: string[] = []\n walkRefs(document, document, \"#\", issues, new Set())\n if (issues.length > 0) return issues\n const seenIds = new Map<string, string>()\n for (const [path, item] of Object.entries(document.paths)) {\n if (!isRecord(item)) {\n issues.push(`paths.${path}: must be an object`)\n continue\n }\n const inTemplate = new Set(templateParams(path))\n for (const method of HTTP_METHODS) {\n const operation = item[method]\n if (operation === undefined) continue\n const label = `${method.toUpperCase()} ${path}`\n if (typeof operation.operationId !== \"string\" || operation.operationId.length === 0) {\n issues.push(`${label}: operationId is required`)\n continue\n }\n const previous = seenIds.get(operation.operationId)\n if (previous !== undefined)\n issues.push(`${label}: duplicate operationId ${operation.operationId} (also ${previous})`)\n seenIds.set(operation.operationId, label)\n if (!isRecord(operation.responses) || Object.keys(operation.responses).length === 0) {\n issues.push(`${label}: responses must declare at least one status`)\n }\n const parameters = mergeParameters(document, item, operation.parameters)\n const declared = new Set(parameters.filter((p) => p.in === \"path\").map((p) => p.name))\n for (const name of inTemplate) {\n if (!declared.has(name)) issues.push(`${label}: path parameter {${name}} is not declared`)\n }\n for (const parameter of parameters) {\n if (parameter.in === \"path\") {\n if (!inTemplate.has(parameter.name))\n issues.push(`${label}: path parameter ${parameter.name} is not in the template`)\n if (parameter.required !== true)\n issues.push(`${label}: path parameter ${parameter.name} must be required`)\n }\n }\n }\n }\n return issues\n}\n\nconst mergeParameters = (\n document: OpenAPIDocument,\n item: PathItemObject,\n own: PathItemObject[\"parameters\"],\n): ParameterObject[] => {\n const merged = new Map<string, ParameterObject>()\n for (const raw of item.parameters ?? []) {\n const parameter = deref<ParameterObject>(document, raw)\n merged.set(`${parameter.in}:${parameter.name}`, parameter)\n }\n for (const raw of own ?? []) {\n const parameter = deref<ParameterObject>(document, raw)\n merged.set(`${parameter.in}:${parameter.name}`, parameter)\n }\n return [...merged.values()]\n}\n\n/** Enumerate every operation in the document in path, then method order. */\nexport const listOperations = (document: OpenAPIDocument): Operation[] => {\n const operations: Operation[] = []\n for (const [path, item] of Object.entries(document.paths)) {\n for (const method of HTTP_METHODS) {\n const operation = item[method]\n if (operation?.operationId === undefined) continue\n const responses: Record<string, ResponseObject> = {}\n for (const [status, response] of Object.entries(operation.responses)) {\n responses[status] = deref<ResponseObject>(document, response)\n }\n operations.push({\n operationId: operation.operationId,\n method,\n path,\n operation,\n parameters: mergeParameters(document, item, operation.parameters),\n requestBody:\n operation.requestBody === undefined\n ? undefined\n : deref<RequestBodyObject>(document, operation.requestBody),\n responses,\n })\n }\n }\n return operations\n}\n\n/** Find one operation by id. */\nexport const findOperation = (\n document: OpenAPIDocument,\n operationId: string,\n): Operation | undefined =>\n listOperations(document).find((operation) => operation.operationId === operationId)\n\n/** Parameter names inside a path template, in order. */\nexport const pathTemplateParameters = templateParams\n\n/** Substitute `{name}` placeholders. Values are percent-encoded as path segments. */\nexport const expandPathTemplate = (template: string, values: Record<string, string>): string =>\n template.replace(/\\{([^}]+)\\}/g, (_, name: string) => {\n const value = values[name]\n if (value === undefined) throw new RangeError(`missing path parameter ${name}`)\n return encodeURIComponent(value)\n })\n\n/** The response object matching an HTTP status: exact match, then `2XX`-style range, then `default`. */\nexport const responseForStatus = (\n responses: Record<string, ResponseObject>,\n status: number,\n): ResponseObject | undefined =>\n responses[String(status)] ?? responses[`${Math.floor(status / 100)}XX`] ?? responses.default\n\nexport type { HttpMethod }\n", "import { resolveRef } from \"./refs.js\"\nimport type { JsonValue, OpenAPIDocument, SchemaObject, SchemaType } from \"./types.js\"\n\n/**\n * Resolve a schema's `$ref` (merging sibling keywords, as JSON Schema 2020-12 allows) and\n * normalise OpenAPI 3.0 `nullable` into a 3.1 type array.\n */\nexport const resolveSchema = (document: OpenAPIDocument, schema: SchemaObject): SchemaObject => {\n let current = schema\n const seen = new Set<string>()\n while (typeof current.$ref === \"string\") {\n const ref = current.$ref\n if (seen.has(ref)) break\n seen.add(ref)\n const { $ref: _ignored, ...siblings } = current\n const target = resolveRef(document, ref) as SchemaObject\n current = { ...target, ...siblings }\n }\n if (current.nullable === true) {\n const { nullable: _nullable, ...rest } = current\n const types = schemaTypes(rest)\n if (types.length > 0 && !types.includes(\"null\")) current = { ...rest, type: [...types, \"null\"] }\n else current = rest\n }\n return current\n}\n\n/** Declared JSON types of a schema (empty when unconstrained). */\nexport const schemaTypes = (schema: SchemaObject): SchemaType[] => {\n if (Array.isArray(schema.type)) return schema.type\n if (schema.type !== undefined) return [schema.type]\n const inferred: SchemaType[] = []\n if (schema.properties || schema.required || schema.additionalProperties !== undefined)\n inferred.push(\"object\")\n if (\n schema.items ||\n schema.prefixItems ||\n schema.minItems !== undefined ||\n schema.maxItems !== undefined\n )\n inferred.push(\"array\")\n if (\n schema.minLength !== undefined ||\n schema.maxLength !== undefined ||\n schema.pattern !== undefined\n )\n inferred.push(\"string\")\n if (\n schema.minimum !== undefined ||\n schema.maximum !== undefined ||\n schema.multipleOf !== undefined\n )\n inferred.push(\"number\")\n return inferred\n}\n\n/** The JSON type name of a runtime value. */\nexport const jsonTypeOf = (value: unknown): SchemaType | \"undefined\" => {\n if (value === null) return \"null\"\n if (Array.isArray(value)) return \"array\"\n switch (typeof value) {\n case \"string\":\n return \"string\"\n case \"boolean\":\n return \"boolean\"\n case \"number\":\n return Number.isInteger(value) ? \"integer\" : \"number\"\n case \"object\":\n return \"object\"\n default:\n return \"undefined\"\n }\n}\n\nexport type SchemaVisitor = (schema: SchemaObject, path: string[]) => void\n\n/**\n * Depth-first walk over a schema tree, resolving `$ref`s, that terminates on recursive schemas.\n * Each schema node is visited once per call: the annotation consumers (identities, refs,\n * volatile/scope marks) only care that a node is reachable, and visiting per path is exponential\n * on densely cross-referenced documents.\n */\nexport const walkSchema = (\n document: OpenAPIDocument,\n schema: SchemaObject,\n visit: SchemaVisitor,\n path: string[] = [],\n) => {\n const seen = new Set<SchemaObject>()\n const go = (node: SchemaObject, at: string[]) => {\n // `resolveSchema` returns a fresh object whenever it follows a `$ref`, so identity of the\n // resolved schema alone never repeats on a recursive schema. The raw node does: every child is\n // an object of the document itself, so remembering raw nodes bounds the walk.\n if (seen.has(node)) return\n seen.add(node)\n const resolved = resolveSchema(document, node)\n if (resolved !== node && seen.has(resolved)) return\n seen.add(resolved)\n visit(resolved, at)\n for (const [name, child] of Object.entries(resolved.properties ?? {}))\n go(child, [...at, \"properties\", name])\n if (typeof resolved.additionalProperties === \"object\")\n go(resolved.additionalProperties, [...at, \"additionalProperties\"])\n if (resolved.items) go(resolved.items, [...at, \"items\"])\n resolved.prefixItems?.forEach((child, i) => {\n go(child, [...at, \"prefixItems\", String(i)])\n })\n resolved.propertyNames && go(resolved.propertyNames, [...at, \"propertyNames\"])\n for (const keyword of [\"oneOf\", \"anyOf\", \"allOf\"] as const) {\n resolved[keyword]?.forEach((child, i) => {\n go(child, [...at, keyword, String(i)])\n })\n }\n resolved.not && go(resolved.not, [...at, \"not\"])\n }\n go(schema, path)\n}\nexport type ValidationError = { path: Array<string | number>; message: string }\n\nconst deepEqual = (a: unknown, b: unknown): boolean => {\n if (a === b) return true\n if (typeof a !== typeof b || a === null || b === null) return false\n if (Array.isArray(a)) {\n return Array.isArray(b) && a.length === b.length && a.every((item, i) => deepEqual(item, b[i]))\n }\n if (typeof a === \"object\" && typeof b === \"object\" && !Array.isArray(b)) {\n const ka = Object.keys(a as object)\n const kb = Object.keys(b as object)\n return (\n ka.length === kb.length &&\n ka.every((k) =>\n deepEqual((a as Record<string, unknown>)[k], (b as Record<string, unknown>)[k]),\n )\n )\n }\n return false\n}\n\nconst FORMAT_PATTERNS: Record<string, RegExp> = {\n uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,\n date: /^\\d{4}-\\d{2}-\\d{2}$/,\n \"date-time\": /^\\d{4}-\\d{2}-\\d{2}[Tt ]\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?([Zz]|[+-]\\d{2}:\\d{2})$/,\n email: /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/,\n uri: /^[a-zA-Z][a-zA-Z0-9+.-]*:[^\\s]*$/,\n ipv4: /^(25[0-5]|2[0-4]\\d|1?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|1?\\d?\\d)){3}$/,\n}\n\nconst graphemeLength = (value: string) => [...value].length\n\n/**\n * Validate `value` against `schema`. Supports the JSON Schema subset Mockingbird generates from\n * (see `@crvouga/mockingbird-openapi-arbitrary`). Returns an empty array when valid.\n */\nexport const validateValue = (\n document: OpenAPIDocument,\n schema: SchemaObject,\n value: unknown,\n path: Array<string | number> = [],\n): ValidationError[] => {\n const errors: ValidationError[] = []\n const s = resolveSchema(document, schema)\n const fail = (message: string) => errors.push({ path, message })\n const actual = jsonTypeOf(value)\n if (actual === \"undefined\") {\n fail(\"value is undefined\")\n return errors\n }\n const types = schemaTypes(s)\n if (types.length > 0) {\n const ok = types.some((t) => t === actual || (t === \"number\" && actual === \"integer\"))\n if (!ok) {\n fail(`expected type ${types.join(\"|\")}, got ${actual}`)\n return errors\n }\n }\n // OpenAPI commonly pairs `type: [\"string\",\"null\"]` with an enum of the non-null values;\n // null is admitted by the type union and must not fail the enum check.\n if (\n s.enum &&\n !(value === null && types.includes(\"null\")) &&\n !s.enum.some((candidate) => deepEqual(candidate, value))\n ) {\n fail(\"value not in enum\")\n }\n if (s.const !== undefined && !deepEqual(s.const, value)) fail(\"value does not equal const\")\n if (typeof value === \"string\") {\n const length = graphemeLength(value)\n if (s.minLength !== undefined && length < s.minLength)\n fail(`length ${length} < minLength ${s.minLength}`)\n if (s.maxLength !== undefined && length > s.maxLength)\n fail(`length ${length} > maxLength ${s.maxLength}`)\n if (s.pattern !== undefined) {\n try {\n if (!new RegExp(s.pattern, \"u\").test(value)) fail(`does not match pattern ${s.pattern}`)\n } catch {\n // unsupported pattern syntax: skip, matching lenient validators\n }\n }\n if (s.format !== undefined) {\n const pattern = FORMAT_PATTERNS[s.format]\n if (pattern && !pattern.test(value)) fail(`does not match format ${s.format}`)\n }\n }\n if (typeof value === \"number\") {\n if (s.minimum !== undefined && value < s.minimum) fail(`${value} < minimum ${s.minimum}`)\n if (s.maximum !== undefined && value > s.maximum) fail(`${value} > maximum ${s.maximum}`)\n if (s.exclusiveMinimum !== undefined && value <= s.exclusiveMinimum)\n fail(`${value} <= exclusiveMinimum ${s.exclusiveMinimum}`)\n if (s.exclusiveMaximum !== undefined && value >= s.exclusiveMaximum)\n fail(`${value} >= exclusiveMaximum ${s.exclusiveMaximum}`)\n if (\n s.multipleOf !== undefined &&\n Math.abs(value / s.multipleOf - Math.round(value / s.multipleOf)) > 1e-9\n ) {\n fail(`${value} is not a multiple of ${s.multipleOf}`)\n }\n }\n if (Array.isArray(value)) {\n if (s.minItems !== undefined && value.length < s.minItems)\n fail(`${value.length} items < minItems ${s.minItems}`)\n if (s.maxItems !== undefined && value.length > s.maxItems)\n fail(`${value.length} items > maxItems ${s.maxItems}`)\n if (\n s.uniqueItems &&\n value.some((item, i) => value.slice(0, i).some((prev) => deepEqual(prev, item)))\n )\n fail(\"items are not unique\")\n value.forEach((item, i) => {\n const itemSchema = s.prefixItems?.[i] ?? s.items\n if (itemSchema) errors.push(...validateValue(document, itemSchema, item, [...path, i]))\n })\n }\n if (actual === \"object\") {\n const record = value as Record<string, unknown>\n const keys = Object.keys(record)\n for (const name of s.required ?? [])\n if (!(name in record)) fail(`missing required property ${name}`)\n if (s.minProperties !== undefined && keys.length < s.minProperties)\n fail(`${keys.length} properties < minProperties ${s.minProperties}`)\n if (s.maxProperties !== undefined && keys.length > s.maxProperties)\n fail(`${keys.length} properties > maxProperties ${s.maxProperties}`)\n for (const key of keys) {\n const property = s.properties?.[key]\n if (property) {\n errors.push(...validateValue(document, property, record[key], [...path, key]))\n continue\n }\n if (s.additionalProperties === false) fail(`unexpected property ${key}`)\n else if (typeof s.additionalProperties === \"object\") {\n errors.push(...validateValue(document, s.additionalProperties, record[key], [...path, key]))\n }\n if (s.propertyNames) {\n const nameErrors = validateValue(document, s.propertyNames, key, [...path, key])\n if (nameErrors.length > 0)\n fail(`property name ${key} is invalid: ${nameErrors[0]?.message}`)\n }\n }\n }\n if (s.allOf)\n for (const branch of s.allOf) errors.push(...validateValue(document, branch, value, path))\n if (s.anyOf && !s.anyOf.some((branch) => validateValue(document, branch, value).length === 0))\n fail(\"matches no anyOf branch\")\n if (s.oneOf) {\n const matches = s.oneOf.filter(\n (branch) => validateValue(document, branch, value).length === 0,\n ).length\n if (matches !== 1) fail(`matches ${matches} oneOf branches, expected exactly 1`)\n }\n if (s.not && validateValue(document, s.not, value).length === 0)\n fail(\"matches forbidden `not` schema\")\n return errors\n}\n\nexport const isValid = (document: OpenAPIDocument, schema: SchemaObject, value: unknown) =>\n validateValue(document, schema, value).length === 0\n\nexport type { JsonValue }\n"],
|
|
5
|
+
"mappings": ";AAEM,IAAO,wBAAP,cAAqC,MAAK;EACzB;EAArB,YAAqB,KAAW;AAC9B,UAAM,sBAAsB,GAAG,EAAE;AADd,SAAA,MAAA;AAEnB,SAAK,OAAO;EACd;;AAGF,IAAM,kBAAkB,CAAC,YAAoB,QAAQ,QAAQ,OAAO,GAAG,EAAE,QAAQ,OAAO,GAAG;AAGpF,IAAM,cAAc,CAAC,UAC1B,OAAO,UAAU,YACjB,UAAU,QACV,OAAQ,MAA6B,SAAS;AAGzC,IAAM,aAAa,CAAC,UAA2B,QAAwB;AAC5E,MAAI,CAAC,IAAI,WAAW,IAAI;AAAG,UAAM,IAAI,sBAAsB,GAAG;AAC9D,MAAI,SAAkB;AACtB,aAAW,OAAO,IAAI,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG;AACzC,UAAM,UAAU,gBAAgB,GAAG;AACnC,QAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,EAAE,WAAW,SAAS;AACzE,YAAM,IAAI,sBAAsB,GAAG;IACrC;AACA,aAAU,OAAmC,OAAO;EACtD;AACA,MAAI,WAAW;AAAW,UAAM,IAAI,sBAAsB,GAAG;AAC7D,SAAO;AACT;AAMO,IAAM,QAAQ,CAAI,UAA2B,UAAiC;AACnF,MAAI,UAA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/crypto.js
|
|
2
|
+
import { hmac } from "@noble/hashes/hmac.js";
|
|
3
|
+
import { sha1 } from "@noble/hashes/legacy.js";
|
|
4
|
+
import { md5 } from "@noble/hashes/legacy.js";
|
|
5
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
6
|
+
import { Buffer } from "buffer";
|
|
7
|
+
var digest = (algorithm) => {
|
|
8
|
+
if (algorithm === "sha256")
|
|
9
|
+
return sha256;
|
|
10
|
+
if (algorithm === "sha1")
|
|
11
|
+
return sha1;
|
|
12
|
+
if (algorithm === "md5")
|
|
13
|
+
return md5;
|
|
14
|
+
throw new Error(`Unsupported digest ${algorithm}`);
|
|
15
|
+
};
|
|
16
|
+
var bytes = (input) => typeof input === "string" ? new TextEncoder().encode(input) : input;
|
|
17
|
+
function createHash(algorithm) {
|
|
18
|
+
const parts = [];
|
|
19
|
+
const hash = {
|
|
20
|
+
update(input) {
|
|
21
|
+
parts.push(bytes(input));
|
|
22
|
+
return hash;
|
|
23
|
+
},
|
|
24
|
+
digest(encoding) {
|
|
25
|
+
const result = Buffer.from(digest(algorithm)(Buffer.concat(parts)));
|
|
26
|
+
return encoding === "base64url" ? result.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "") : encoding ? result.toString(encoding) : result;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return hash;
|
|
30
|
+
}
|
|
31
|
+
function createHmac(algorithm, key) {
|
|
32
|
+
const parts = [];
|
|
33
|
+
const hash = {
|
|
34
|
+
update(input) {
|
|
35
|
+
parts.push(bytes(input));
|
|
36
|
+
return hash;
|
|
37
|
+
},
|
|
38
|
+
digest(encoding) {
|
|
39
|
+
const result = Buffer.from(hmac(digest(algorithm), bytes(key), Buffer.concat(parts)));
|
|
40
|
+
return encoding === "base64url" ? result.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "") : encoding ? result.toString(encoding) : result;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return hash;
|
|
44
|
+
}
|
|
45
|
+
var source;
|
|
46
|
+
function useRandom(next) {
|
|
47
|
+
source = next;
|
|
48
|
+
}
|
|
49
|
+
function withRandom(next, run) {
|
|
50
|
+
const previous = source;
|
|
51
|
+
source = next;
|
|
52
|
+
try {
|
|
53
|
+
return run();
|
|
54
|
+
} finally {
|
|
55
|
+
source = previous;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function random() {
|
|
59
|
+
return source ? source() : Math.random();
|
|
60
|
+
}
|
|
61
|
+
function randomBytes(length) {
|
|
62
|
+
if (!source)
|
|
63
|
+
return Buffer.from(crypto.getRandomValues(new Uint8Array(length)));
|
|
64
|
+
const out = new Uint8Array(length);
|
|
65
|
+
for (let i = 0; i < length; i++)
|
|
66
|
+
out[i] = Math.floor(source() * 256);
|
|
67
|
+
return Buffer.from(out);
|
|
68
|
+
}
|
|
69
|
+
function randomUUID() {
|
|
70
|
+
if (!source)
|
|
71
|
+
return crypto.randomUUID();
|
|
72
|
+
const b = randomBytes(16);
|
|
73
|
+
b[6] = b[6] & 15 | 64;
|
|
74
|
+
b[8] = b[8] & 63 | 128;
|
|
75
|
+
const hex = b.toString("hex");
|
|
76
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
77
|
+
}
|
|
78
|
+
function timingSafeEqual(a, b) {
|
|
79
|
+
if (a.length !== b.length)
|
|
80
|
+
throw new Error("Buffers must have equal lengths");
|
|
81
|
+
let difference = 0;
|
|
82
|
+
for (let i = 0; i < a.length; i++)
|
|
83
|
+
difference |= a[i] ^ b[i];
|
|
84
|
+
return difference === 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export {
|
|
88
|
+
createHash,
|
|
89
|
+
createHmac,
|
|
90
|
+
useRandom,
|
|
91
|
+
withRandom,
|
|
92
|
+
random,
|
|
93
|
+
randomBytes,
|
|
94
|
+
randomUUID,
|
|
95
|
+
timingSafeEqual
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=chunk-RNAHPNUJ.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../http/provider/src/vendor/core/crypto.ts"],
|
|
4
|
+
"sourcesContent": ["import { hmac } from \"@noble/hashes/hmac.js\"\nimport { sha1 } from \"@noble/hashes/legacy.js\"\nimport { md5 } from \"@noble/hashes/legacy.js\"\nimport { sha256 } from \"@noble/hashes/sha2.js\"\nimport { Buffer } from \"buffer\"\n\nconst digest = (algorithm: string) => {\n if (algorithm === \"sha256\") return sha256\n if (algorithm === \"sha1\") return sha1\n if (algorithm === \"md5\") return md5\n throw new Error(`Unsupported digest ${algorithm}`)\n}\nconst bytes = (input: string | Uint8Array) => typeof input === \"string\" ? new TextEncoder().encode(input) : input\ninterface Hash {\n update(input: string | Uint8Array): Hash\n digest(): Buffer\n digest(encoding: string): string\n}\nexport function createHash(algorithm: string): Hash {\n const parts: Uint8Array[] = []\n const hash = {\n update(input: string | Uint8Array) { parts.push(bytes(input)); return hash },\n digest(encoding?: string): Buffer | string {\n const result = Buffer.from(digest(algorithm)(Buffer.concat(parts)))\n return encoding === \"base64url\" ? result.toString(\"base64\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\") : encoding ? result.toString(encoding as BufferEncoding) : result\n },\n }\n return hash as Hash\n}\nexport function createHmac(algorithm: string, key: string | Uint8Array): Hash {\n const parts: Uint8Array[] = []\n const hash = {\n update(input: string | Uint8Array) { parts.push(bytes(input)); return hash },\n digest(encoding?: string): Buffer | string {\n const result = Buffer.from(hmac(digest(algorithm), bytes(key), Buffer.concat(parts)))\n return encoding === \"base64url\" ? result.toString(\"base64\").replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\") : encoding ? result.toString(encoding as BufferEncoding) : result\n },\n }\n return hash as Hash\n}\n/**\n * Mockingbird: where ids and tokens come from. With a seeded stream in place, everything the\n * vendor code mints replays from the seed; without one it is the platform's own randomness.\n */\nlet source: (() => number) | undefined\n/** Mint from `next` (a seeded stream of `[0, 1)`) until told otherwise. */\nexport function useRandom(next: (() => number) | undefined): void { source = next }\n/** Mint from `next` for one synchronous section, then put the previous source back. */\nexport function withRandom<T>(next: (() => number) | undefined, run: () => T): T {\n const previous = source\n source = next\n try { return run() } finally { source = previous }\n}\n/** `Math.random`, from the seeded stream when one is in place. */\nexport function random(): number { return source ? source() : Math.random() }\nexport function randomBytes(length: number): Buffer {\n if (!source) return Buffer.from(crypto.getRandomValues(new Uint8Array(length)))\n const out = new Uint8Array(length)\n for (let i = 0; i < length; i++) out[i] = Math.floor(source() * 256)\n return Buffer.from(out)\n}\nexport function randomUUID(): string {\n if (!source) return crypto.randomUUID()\n const b = randomBytes(16)\n b[6] = (b[6] & 0x0f) | 0x40\n b[8] = (b[8] & 0x3f) | 0x80\n const hex = b.toString(\"hex\")\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`\n}\nexport function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) throw new Error(\"Buffers must have equal lengths\")\n let difference = 0\n for (let i = 0; i < a.length; i++) difference |= a[i] ^ b[i]\n return difference === 0\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,YAAY;AACrB,SAAS,YAAY;AACrB,SAAS,WAAW;AACpB,SAAS,cAAc;AACvB,SAAS,cAAc;AAEvB,IAAM,SAAS,CAAC,cAAqB;AACnC,MAAI,cAAc;AAAU,WAAO;AACnC,MAAI,cAAc;AAAQ,WAAO;AACjC,MAAI,cAAc;AAAO,WAAO;AAChC,QAAM,IAAI,MAAM,sBAAsB,SAAS,EAAE;AACnD;AACA,IAAM,QAAQ,CAAC,UAA+B,OAAO,UAAU,WAAW,IAAI,YAAW,EAAG,OAAO,KAAK,IAAI;AAMtG,SAAU,WAAW,WAAiB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