elysia 1.4.30 → 1.4.31
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/dist/adapter/bun/compose.js +9 -4
- package/dist/adapter/bun/compose.mjs +9 -4
- package/dist/adapter/bun/index.js +19 -13
- package/dist/adapter/bun/index.mjs +19 -13
- package/dist/adapter/utils.js +63 -18
- package/dist/adapter/utils.mjs +63 -18
- package/dist/adapter/web-standard/index.js +3 -55
- package/dist/adapter/web-standard/index.mjs +3 -55
- package/dist/compose.js +48 -88
- package/dist/compose.mjs +52 -88
- package/dist/dynamic-handle.js +54 -132
- package/dist/dynamic-handle.mjs +66 -133
- package/dist/error.d.ts +7 -19
- package/dist/error.js +281 -38
- package/dist/error.mjs +275 -38
- package/dist/form-data.d.ts +3 -0
- package/dist/form-data.js +124 -0
- package/dist/form-data.mjs +103 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +35 -7
- package/dist/index.mjs +37 -8
- package/dist/replace-schema.js +8 -3
- package/dist/replace-schema.mjs +8 -3
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +354 -0
- package/dist/schema.mjs +352 -0
- package/dist/types.d.ts +12 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +62 -14
- package/dist/utils.mjs +60 -14
- package/dist/ws/index.d.ts +1 -1
- package/dist/ws/index.js +110 -45
- package/dist/ws/index.mjs +110 -45
- package/package.json +4 -4
- package/AGENTS.md +0 -75
- package/AI_POLICY.md +0 -19
- package/CLAUDE.md +0 -75
package/dist/index.js
CHANGED
|
@@ -65,6 +65,9 @@ __export(index_exports, {
|
|
|
65
65
|
});
|
|
66
66
|
module.exports = __toCommonJS(index_exports);
|
|
67
67
|
var import_memoirist = require("memoirist"), import_typebox = require("@sinclair/typebox"), import_fast_decode_uri_component = __toESM(require("fast-decode-uri-component")), import_type_system = require('./type-system/index.js'), import_sucrose = require('./sucrose.js'), import_bun = require('./adapter/bun/index.js'), import_web_standard = require('./adapter/web-standard/index.js'), import_env = require('./universal/env.js'), import_utils = require('./utils.js'), import_schema = require('./schema.js'), import_compose = require('./compose.js'), import_trace = require('./trace.js'), import_utils2 = require('./utils.js'), import_dynamic_handle = require('./dynamic-handle.js'), import_error = require('./error.js'), import_replace_schema = require('./replace-schema.js'), import_type_system2 = require('./type-system/index.js'), import_utils3 = require('./type-system/utils.js'), import_cookies = require('./cookies.js'), import_trace2 = require('./trace.js'), import_schema2 = require('./schema.js'), import_replace_schema2 = require('./replace-schema.js'), import_utils4 = require('./utils.js'), import_error2 = require('./error.js'), import_env2 = require('./universal/env.js'), import_file = require('./universal/file.js'), import_system = require("@sinclair/typebox/system"), _a;
|
|
68
|
+
const decodePathParameter = (value) => (0, import_fast_decode_uri_component.default)(
|
|
69
|
+
value.replace(/%2f/gi, (separator) => `%25${separator.slice(1)}`)
|
|
70
|
+
);
|
|
68
71
|
_a = Symbol.dispose;
|
|
69
72
|
const _Elysia = class _Elysia {
|
|
70
73
|
constructor(config = {}) {
|
|
@@ -121,14 +124,14 @@ const _Elysia = class _Elysia {
|
|
|
121
124
|
get http() {
|
|
122
125
|
return this["~http"] || (this["~http"] = new import_memoirist.Memoirist({
|
|
123
126
|
lazy: !0,
|
|
124
|
-
onParam:
|
|
127
|
+
onParam: decodePathParameter
|
|
125
128
|
})), this["~http"];
|
|
126
129
|
},
|
|
127
130
|
"~dynamic": void 0,
|
|
128
131
|
// Use in non-AOT mode
|
|
129
132
|
get dynamic() {
|
|
130
133
|
return this["~dynamic"] || (this["~dynamic"] = new import_memoirist.Memoirist({
|
|
131
|
-
onParam:
|
|
134
|
+
onParam: decodePathParameter
|
|
132
135
|
})), this["~dynamic"];
|
|
133
136
|
},
|
|
134
137
|
// Static Router
|
|
@@ -208,7 +211,7 @@ const _Elysia = class _Elysia {
|
|
|
208
211
|
},
|
|
209
212
|
experimental: config?.experimental ?? {},
|
|
210
213
|
seed: config?.seed === void 0 ? "" : config?.seed
|
|
211
|
-
}, this["~adapter"] = config.adapter ?? (typeof Bun < "u" ? import_bun.BunAdapter : import_web_standard.WebStandardAdapter), config?.analytic && (config?.name || config?.seed !== void 0) && (this.telemetry = {
|
|
214
|
+
}, this["~cookieConfig"] = config.cookie, this["~adapter"] = config.adapter ?? (typeof Bun < "u" ? import_bun.BunAdapter : import_web_standard.WebStandardAdapter), config?.analytic && (config?.name || config?.seed !== void 0) && (this.telemetry = {
|
|
212
215
|
stack: new Error().stack
|
|
213
216
|
});
|
|
214
217
|
}
|
|
@@ -283,7 +286,9 @@ const _Elysia = class _Elysia {
|
|
|
283
286
|
}
|
|
284
287
|
add(method, path, handle, localHook, options) {
|
|
285
288
|
const skipPrefix = options?.skipPrefix ?? !1, allowMeta = options?.allowMeta ?? !1;
|
|
286
|
-
localHook ??= {}
|
|
289
|
+
localHook ??= {};
|
|
290
|
+
const cookieConfig = localHook.config?.cookie ? (0, import_utils.mergeCookie)(this.config.cookie ?? {}, localHook.config.cookie) : this.config.cookie;
|
|
291
|
+
this.applyMacro(localHook);
|
|
287
292
|
let standaloneValidators = [];
|
|
288
293
|
if (localHook.standaloneValidator && (standaloneValidators = standaloneValidators.concat(
|
|
289
294
|
localHook.standaloneValidator
|
|
@@ -326,7 +331,7 @@ const _Elysia = class _Elysia {
|
|
|
326
331
|
return (0, import_schema.getCookieValidator)({
|
|
327
332
|
modules,
|
|
328
333
|
validator: cloned.cookie,
|
|
329
|
-
defaultConfig:
|
|
334
|
+
defaultConfig: cookieConfig,
|
|
330
335
|
normalize,
|
|
331
336
|
config: cloned.cookie?.config ?? {},
|
|
332
337
|
dynamic,
|
|
@@ -1253,7 +1258,16 @@ const _Elysia = class _Elysia {
|
|
|
1253
1258
|
method,
|
|
1254
1259
|
path,
|
|
1255
1260
|
handler,
|
|
1256
|
-
|
|
1261
|
+
plugin2["~cookieConfig"] ? {
|
|
1262
|
+
...hooks,
|
|
1263
|
+
config: {
|
|
1264
|
+
...hooks.config,
|
|
1265
|
+
cookie: (0, import_utils.mergeCookie)(
|
|
1266
|
+
plugin2["~cookieConfig"],
|
|
1267
|
+
hooks.config?.cookie ?? {}
|
|
1268
|
+
)
|
|
1269
|
+
}
|
|
1270
|
+
} : hooks,
|
|
1257
1271
|
void 0
|
|
1258
1272
|
);
|
|
1259
1273
|
return plugin2 === this ? void 0 : (this.propagatePromiseModules(plugin2), plugin2);
|
|
@@ -1309,7 +1323,21 @@ const _Elysia = class _Elysia {
|
|
|
1309
1323
|
for (const { method, path, handler, hooks } of Object.values(
|
|
1310
1324
|
plugin.router.history
|
|
1311
1325
|
))
|
|
1312
|
-
this.add(
|
|
1326
|
+
this.add(
|
|
1327
|
+
method,
|
|
1328
|
+
path,
|
|
1329
|
+
handler,
|
|
1330
|
+
plugin["~cookieConfig"] ? {
|
|
1331
|
+
...hooks,
|
|
1332
|
+
config: {
|
|
1333
|
+
...hooks.config,
|
|
1334
|
+
cookie: (0, import_utils.mergeCookie)(
|
|
1335
|
+
plugin["~cookieConfig"],
|
|
1336
|
+
hooks.config?.cookie ?? {}
|
|
1337
|
+
)
|
|
1338
|
+
}
|
|
1339
|
+
} : hooks
|
|
1340
|
+
);
|
|
1313
1341
|
if (name) {
|
|
1314
1342
|
name in this.dependencies || (this.dependencies[name] = []);
|
|
1315
1343
|
const current = seed !== void 0 ? (0, import_utils2.checksum)(name + JSON.stringify(seed)) : 0;
|
package/dist/index.mjs
CHANGED
|
@@ -24,7 +24,8 @@ import {
|
|
|
24
24
|
lifeCycleToArray,
|
|
25
25
|
supportPerMethodInlineHandler,
|
|
26
26
|
emptySchema,
|
|
27
|
-
insertStandaloneValidator
|
|
27
|
+
insertStandaloneValidator,
|
|
28
|
+
mergeCookie
|
|
28
29
|
} from "./utils.mjs";
|
|
29
30
|
import {
|
|
30
31
|
getSchemaValidator,
|
|
@@ -61,6 +62,9 @@ import {
|
|
|
61
62
|
queryCoercions,
|
|
62
63
|
stringToStructureCoercions
|
|
63
64
|
} from "./replace-schema.mjs";
|
|
65
|
+
const decodePathParameter = (value) => fastDecodeURIComponent(
|
|
66
|
+
value.replace(/%2f/gi, (separator) => `%25${separator.slice(1)}`)
|
|
67
|
+
);
|
|
64
68
|
_a = Symbol.dispose;
|
|
65
69
|
const _Elysia = class _Elysia {
|
|
66
70
|
constructor(config = {}) {
|
|
@@ -117,14 +121,14 @@ const _Elysia = class _Elysia {
|
|
|
117
121
|
get http() {
|
|
118
122
|
return this["~http"] || (this["~http"] = new Memoirist({
|
|
119
123
|
lazy: !0,
|
|
120
|
-
onParam:
|
|
124
|
+
onParam: decodePathParameter
|
|
121
125
|
})), this["~http"];
|
|
122
126
|
},
|
|
123
127
|
"~dynamic": void 0,
|
|
124
128
|
// Use in non-AOT mode
|
|
125
129
|
get dynamic() {
|
|
126
130
|
return this["~dynamic"] || (this["~dynamic"] = new Memoirist({
|
|
127
|
-
onParam:
|
|
131
|
+
onParam: decodePathParameter
|
|
128
132
|
})), this["~dynamic"];
|
|
129
133
|
},
|
|
130
134
|
// Static Router
|
|
@@ -204,7 +208,7 @@ const _Elysia = class _Elysia {
|
|
|
204
208
|
},
|
|
205
209
|
experimental: config?.experimental ?? {},
|
|
206
210
|
seed: config?.seed === void 0 ? "" : config?.seed
|
|
207
|
-
}, this["~adapter"] = config.adapter ?? (typeof Bun < "u" ? BunAdapter : WebStandardAdapter), config?.analytic && (config?.name || config?.seed !== void 0) && (this.telemetry = {
|
|
211
|
+
}, this["~cookieConfig"] = config.cookie, this["~adapter"] = config.adapter ?? (typeof Bun < "u" ? BunAdapter : WebStandardAdapter), config?.analytic && (config?.name || config?.seed !== void 0) && (this.telemetry = {
|
|
208
212
|
stack: new Error().stack
|
|
209
213
|
});
|
|
210
214
|
}
|
|
@@ -279,7 +283,9 @@ const _Elysia = class _Elysia {
|
|
|
279
283
|
}
|
|
280
284
|
add(method, path, handle, localHook, options) {
|
|
281
285
|
const skipPrefix = options?.skipPrefix ?? !1, allowMeta = options?.allowMeta ?? !1;
|
|
282
|
-
localHook ??= {}
|
|
286
|
+
localHook ??= {};
|
|
287
|
+
const cookieConfig = localHook.config?.cookie ? mergeCookie(this.config.cookie ?? {}, localHook.config.cookie) : this.config.cookie;
|
|
288
|
+
this.applyMacro(localHook);
|
|
283
289
|
let standaloneValidators = [];
|
|
284
290
|
if (localHook.standaloneValidator && (standaloneValidators = standaloneValidators.concat(
|
|
285
291
|
localHook.standaloneValidator
|
|
@@ -322,7 +328,7 @@ const _Elysia = class _Elysia {
|
|
|
322
328
|
return getCookieValidator({
|
|
323
329
|
modules,
|
|
324
330
|
validator: cloned.cookie,
|
|
325
|
-
defaultConfig:
|
|
331
|
+
defaultConfig: cookieConfig,
|
|
326
332
|
normalize,
|
|
327
333
|
config: cloned.cookie?.config ?? {},
|
|
328
334
|
dynamic,
|
|
@@ -1249,7 +1255,16 @@ const _Elysia = class _Elysia {
|
|
|
1249
1255
|
method,
|
|
1250
1256
|
path,
|
|
1251
1257
|
handler,
|
|
1252
|
-
|
|
1258
|
+
plugin2["~cookieConfig"] ? {
|
|
1259
|
+
...hooks,
|
|
1260
|
+
config: {
|
|
1261
|
+
...hooks.config,
|
|
1262
|
+
cookie: mergeCookie(
|
|
1263
|
+
plugin2["~cookieConfig"],
|
|
1264
|
+
hooks.config?.cookie ?? {}
|
|
1265
|
+
)
|
|
1266
|
+
}
|
|
1267
|
+
} : hooks,
|
|
1253
1268
|
void 0
|
|
1254
1269
|
);
|
|
1255
1270
|
return plugin2 === this ? void 0 : (this.propagatePromiseModules(plugin2), plugin2);
|
|
@@ -1305,7 +1320,21 @@ const _Elysia = class _Elysia {
|
|
|
1305
1320
|
for (const { method, path, handler, hooks } of Object.values(
|
|
1306
1321
|
plugin.router.history
|
|
1307
1322
|
))
|
|
1308
|
-
this.add(
|
|
1323
|
+
this.add(
|
|
1324
|
+
method,
|
|
1325
|
+
path,
|
|
1326
|
+
handler,
|
|
1327
|
+
plugin["~cookieConfig"] ? {
|
|
1328
|
+
...hooks,
|
|
1329
|
+
config: {
|
|
1330
|
+
...hooks.config,
|
|
1331
|
+
cookie: mergeCookie(
|
|
1332
|
+
plugin["~cookieConfig"],
|
|
1333
|
+
hooks.config?.cookie ?? {}
|
|
1334
|
+
)
|
|
1335
|
+
}
|
|
1336
|
+
} : hooks
|
|
1337
|
+
);
|
|
1309
1338
|
if (name) {
|
|
1310
1339
|
name in this.dependencies || (this.dependencies[name] = []);
|
|
1311
1340
|
const current = seed !== void 0 ? checksum(name + JSON.stringify(seed)) : 0;
|
package/dist/replace-schema.js
CHANGED
|
@@ -59,9 +59,14 @@ const replaceSchemaTypeFromManyOptions = (schema, options) => {
|
|
|
59
59
|
)), s.not && (withTransformedChildren.not = walk({ ...newWalkInput, s: s.not })), s.properties) {
|
|
60
60
|
withTransformedChildren.properties = {};
|
|
61
61
|
for (const [k, v] of Object.entries(s.properties))
|
|
62
|
-
withTransformedChildren.properties
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
Object.defineProperty(withTransformedChildren.properties, k, {
|
|
63
|
+
value: walk({
|
|
64
|
+
...newWalkInput,
|
|
65
|
+
s: v
|
|
66
|
+
}),
|
|
67
|
+
enumerable: !0,
|
|
68
|
+
configurable: !0,
|
|
69
|
+
writable: !0
|
|
65
70
|
});
|
|
66
71
|
}
|
|
67
72
|
if (s.items) {
|
package/dist/replace-schema.mjs
CHANGED
|
@@ -35,9 +35,14 @@ const replaceSchemaTypeFromManyOptions = (schema, options) => {
|
|
|
35
35
|
)), s.not && (withTransformedChildren.not = walk({ ...newWalkInput, s: s.not })), s.properties) {
|
|
36
36
|
withTransformedChildren.properties = {};
|
|
37
37
|
for (const [k, v] of Object.entries(s.properties))
|
|
38
|
-
withTransformedChildren.properties
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
Object.defineProperty(withTransformedChildren.properties, k, {
|
|
39
|
+
value: walk({
|
|
40
|
+
...newWalkInput,
|
|
41
|
+
s: v
|
|
42
|
+
}),
|
|
43
|
+
enumerable: !0,
|
|
44
|
+
configurable: !0,
|
|
45
|
+
writable: !0
|
|
41
46
|
});
|
|
42
47
|
}
|
|
43
48
|
if (s.items) {
|
package/dist/schema.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ export declare const getSchemaValidator: <T extends AnySchema | string | undefin
|
|
|
67
67
|
}) => IsAny<T> extends true ? ElysiaTypeCheck<TAnySchema> : undefined extends T ? undefined : ElysiaTypeCheck<NonNullable<Exclude<T, string>>>;
|
|
68
68
|
export declare const isUnion: (schema: TSchema) => boolean;
|
|
69
69
|
export declare const getSchemaProperties: (schema: TAnySchema | undefined) => Record<string, TAnySchema> | undefined;
|
|
70
|
+
export declare const cloneSchemaInput: (value: any) => any;
|
|
71
|
+
export declare const applySchemaDefaults: (checker: TypeCheck<any> | ElysiaTypeCheck<any>, value: unknown, nullish?: boolean) => any;
|
|
70
72
|
export declare const mergeObjectSchemas: (schemas: TSchema[]) => {
|
|
71
73
|
schema: TObject | undefined;
|
|
72
74
|
notObjects: TSchema[];
|
package/dist/schema.js
CHANGED
|
@@ -15,6 +15,8 @@ var __export = (target, all) => {
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
16
|
var schema_exports = {};
|
|
17
17
|
__export(schema_exports, {
|
|
18
|
+
applySchemaDefaults: () => applySchemaDefaults,
|
|
19
|
+
cloneSchemaInput: () => cloneSchemaInput,
|
|
18
20
|
getCookieValidator: () => getCookieValidator,
|
|
19
21
|
getResponseSchemaValidator: () => getResponseSchemaValidator,
|
|
20
22
|
getSchemaProperties: () => getSchemaProperties,
|
|
@@ -671,6 +673,356 @@ const isOptional = (schema) => schema ? schema?.[import_typebox.Kind] === "Impor
|
|
|
671
673
|
}
|
|
672
674
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
673
675
|
}
|
|
676
|
+
}, hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key), cloneDefaultValue = (value) => {
|
|
677
|
+
if (Array.isArray(value)) return value.map(cloneDefaultValue);
|
|
678
|
+
if (value instanceof Date) return new Date(value);
|
|
679
|
+
if (value instanceof Map)
|
|
680
|
+
return new Map(
|
|
681
|
+
[...value].map(([key, entry]) => [
|
|
682
|
+
cloneDefaultValue(key),
|
|
683
|
+
cloneDefaultValue(entry)
|
|
684
|
+
])
|
|
685
|
+
);
|
|
686
|
+
if (value instanceof Set)
|
|
687
|
+
return new Set([...value].map(cloneDefaultValue));
|
|
688
|
+
if (ArrayBuffer.isView(value) && "slice" in value)
|
|
689
|
+
return value.slice();
|
|
690
|
+
if (value === null || typeof value != "object") return value;
|
|
691
|
+
const cloned = /* @__PURE__ */ Object.create(null);
|
|
692
|
+
for (const key of Reflect.ownKeys(value))
|
|
693
|
+
Object.defineProperty(cloned, key, {
|
|
694
|
+
value: cloneDefaultValue(value[key]),
|
|
695
|
+
enumerable: Object.prototype.propertyIsEnumerable.call(value, key),
|
|
696
|
+
configurable: !0,
|
|
697
|
+
writable: !0
|
|
698
|
+
});
|
|
699
|
+
return cloned;
|
|
700
|
+
}, cloneDefault = (value) => typeof value == "function" ? value() : cloneDefaultValue(value), resolveDefaultSchema = (schema, references) => {
|
|
701
|
+
if (schema[import_typebox.Kind] === "Import") {
|
|
702
|
+
const definitions = Object.values(schema.$defs ?? {}), target = schema.$defs?.[schema.$ref];
|
|
703
|
+
return target ? resolveDefaultSchema(
|
|
704
|
+
target,
|
|
705
|
+
[...references, ...definitions]
|
|
706
|
+
) : schema;
|
|
707
|
+
}
|
|
708
|
+
if (schema[import_typebox.Kind] === "Ref" || schema[import_typebox.Kind] === "This") {
|
|
709
|
+
const reference = references.find(
|
|
710
|
+
(reference2) => reference2.$id === schema.$ref
|
|
711
|
+
);
|
|
712
|
+
if (reference) return resolveDefaultSchema(reference, references);
|
|
713
|
+
}
|
|
714
|
+
return schema;
|
|
715
|
+
}, cloneSchemaInput = (value) => {
|
|
716
|
+
if (Array.isArray(value)) return value.map(cloneForDefaults);
|
|
717
|
+
if (value === null || typeof value != "object" || value instanceof Date || value instanceof Map || value instanceof Set || value instanceof ArrayBuffer || ArrayBuffer.isView(value) || Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null)
|
|
718
|
+
return value;
|
|
719
|
+
const cloned = /* @__PURE__ */ Object.create(null);
|
|
720
|
+
for (const key of Object.getOwnPropertyNames(value))
|
|
721
|
+
Object.defineProperty(cloned, key, {
|
|
722
|
+
value: cloneSchemaInput(value[key]),
|
|
723
|
+
enumerable: Object.prototype.propertyIsEnumerable.call(value, key),
|
|
724
|
+
configurable: !0,
|
|
725
|
+
writable: !0
|
|
726
|
+
});
|
|
727
|
+
for (const key of Object.getOwnPropertySymbols(value))
|
|
728
|
+
Object.defineProperty(cloned, key, {
|
|
729
|
+
value: cloneSchemaInput(value[key]),
|
|
730
|
+
enumerable: Object.prototype.propertyIsEnumerable.call(value, key),
|
|
731
|
+
configurable: !0,
|
|
732
|
+
writable: !0
|
|
733
|
+
});
|
|
734
|
+
return cloned;
|
|
735
|
+
}, cloneForDefaults = cloneSchemaInput, skipFunctionDefaults = (inputSchema, references, functionDefaults, seen = /* @__PURE__ */ new Set()) => {
|
|
736
|
+
const schema = resolveDefaultSchema(inputSchema, references);
|
|
737
|
+
if (!seen.has(schema)) {
|
|
738
|
+
seen.add(schema), typeof schema.default == "function" && !functionDefaults.has(schema) && functionDefaults.set(schema, { skip: !0 });
|
|
739
|
+
for (const child of [
|
|
740
|
+
...Object.values(schema.properties ?? {}),
|
|
741
|
+
...Object.values(schema.patternProperties ?? {}),
|
|
742
|
+
...schema.allOf ?? [],
|
|
743
|
+
...schema.anyOf ?? [],
|
|
744
|
+
...schema.oneOf ?? [],
|
|
745
|
+
...Array.isArray(schema.items) ? schema.items : schema.items ? [schema.items] : [],
|
|
746
|
+
...schema.not ? [schema.not] : [],
|
|
747
|
+
...schema.additionalProperties && typeof schema.additionalProperties == "object" ? [schema.additionalProperties] : []
|
|
748
|
+
])
|
|
749
|
+
skipFunctionDefaults(child, references, functionDefaults, seen);
|
|
750
|
+
}
|
|
751
|
+
}, matchesExistingProperties = (inputSchema, input, references) => {
|
|
752
|
+
const schema = resolveDefaultSchema(inputSchema, references), properties = getSchemaProperties(schema);
|
|
753
|
+
if (!properties || input === null || typeof input != "object")
|
|
754
|
+
return input === void 0 || import_value.Value.Check(schema, references, input);
|
|
755
|
+
for (const [key, propertySchema] of Object.entries(properties))
|
|
756
|
+
if (hasOwn(input, key) && input[key] !== void 0 && !import_value.Value.Check(propertySchema, references, input[key]))
|
|
757
|
+
return !1;
|
|
758
|
+
return !0;
|
|
759
|
+
}, prepareDefaultInput = (inputSchema, input, references, nullish, isRoot, functionDefaults) => {
|
|
760
|
+
const schema = resolveDefaultSchema(inputSchema, references);
|
|
761
|
+
let value = input;
|
|
762
|
+
const missing = value === void 0 || nullish && value === null;
|
|
763
|
+
typeof schema.default == "function" ? missing ? (value = cloneDefault(schema.default), functionDefaults.set(schema, { skip: !1, value })) : functionDefaults.has(schema) || functionDefaults.set(schema, { skip: !0 }) : missing && hasOwn(schema, "default") && (value = cloneDefault(schema.default));
|
|
764
|
+
const properties = getSchemaProperties(schema);
|
|
765
|
+
if (isRoot && value === void 0 && (schema[import_typebox.Kind] === "Object" || schema.type === "object") ? value = /* @__PURE__ */ Object.create(null) : value = cloneForDefaults(value), schema[import_typebox.Kind] === "Object" && properties && value !== null && typeof value == "object")
|
|
766
|
+
for (const [key, propertySchema] of Object.entries(properties)) {
|
|
767
|
+
const rawPropertyValue = hasOwn(value, key) ? value[key] : void 0, propertyValue = prepareDefaultInput(
|
|
768
|
+
propertySchema,
|
|
769
|
+
rawPropertyValue,
|
|
770
|
+
references,
|
|
771
|
+
nullish,
|
|
772
|
+
!1,
|
|
773
|
+
functionDefaults
|
|
774
|
+
);
|
|
775
|
+
propertyValue !== void 0 && Object.defineProperty(value, key, {
|
|
776
|
+
value: propertyValue,
|
|
777
|
+
enumerable: !0,
|
|
778
|
+
configurable: !0,
|
|
779
|
+
writable: !0
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
else if (Array.isArray(value) && schema.items)
|
|
783
|
+
if (Array.isArray(schema.items))
|
|
784
|
+
for (let i = 0; i < schema.items.length; i++)
|
|
785
|
+
value[i] = prepareDefaultInput(
|
|
786
|
+
schema.items[i],
|
|
787
|
+
value[i],
|
|
788
|
+
references,
|
|
789
|
+
nullish,
|
|
790
|
+
!1,
|
|
791
|
+
functionDefaults
|
|
792
|
+
);
|
|
793
|
+
else
|
|
794
|
+
for (let i = 0; i < value.length; i++)
|
|
795
|
+
value[i] = prepareDefaultInput(
|
|
796
|
+
schema.items,
|
|
797
|
+
value[i],
|
|
798
|
+
references,
|
|
799
|
+
nullish,
|
|
800
|
+
!1,
|
|
801
|
+
functionDefaults
|
|
802
|
+
);
|
|
803
|
+
if (schema.allOf)
|
|
804
|
+
for (const member of schema.allOf)
|
|
805
|
+
prepareDefaultInput(
|
|
806
|
+
member,
|
|
807
|
+
input,
|
|
808
|
+
references,
|
|
809
|
+
nullish,
|
|
810
|
+
!1,
|
|
811
|
+
functionDefaults
|
|
812
|
+
);
|
|
813
|
+
for (const members of [schema.anyOf, schema.oneOf])
|
|
814
|
+
if (members) {
|
|
815
|
+
let selected = !1;
|
|
816
|
+
for (const member of members) {
|
|
817
|
+
if (selected || !matchesExistingProperties(member, input, references)) {
|
|
818
|
+
skipFunctionDefaults(
|
|
819
|
+
member,
|
|
820
|
+
references,
|
|
821
|
+
functionDefaults
|
|
822
|
+
);
|
|
823
|
+
continue;
|
|
824
|
+
}
|
|
825
|
+
const candidate = prepareDefaultInput(
|
|
826
|
+
member,
|
|
827
|
+
input,
|
|
828
|
+
references,
|
|
829
|
+
nullish,
|
|
830
|
+
!1,
|
|
831
|
+
functionDefaults
|
|
832
|
+
);
|
|
833
|
+
import_value.Value.Check(member, references, candidate) && (selected = !0, value = candidate);
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
if (schema.patternProperties && value !== null && typeof value == "object")
|
|
837
|
+
for (const [pattern, propertySchema] of Object.entries(
|
|
838
|
+
schema.patternProperties
|
|
839
|
+
))
|
|
840
|
+
for (const key of Object.keys(value))
|
|
841
|
+
new RegExp(pattern).test(key) && (value[key] = prepareDefaultInput(
|
|
842
|
+
propertySchema,
|
|
843
|
+
value[key],
|
|
844
|
+
references,
|
|
845
|
+
nullish,
|
|
846
|
+
!1,
|
|
847
|
+
functionDefaults
|
|
848
|
+
));
|
|
849
|
+
return value;
|
|
850
|
+
}, withResolvedFunctionDefaults = (functionDefaults, run) => {
|
|
851
|
+
const originals = [];
|
|
852
|
+
try {
|
|
853
|
+
for (const [schema, resolved] of functionDefaults) {
|
|
854
|
+
const descriptor = Object.getOwnPropertyDescriptor(schema, "default");
|
|
855
|
+
descriptor && (originals.push([schema, descriptor]), resolved.skip ? delete schema.default : Object.defineProperty(schema, "default", {
|
|
856
|
+
...descriptor,
|
|
857
|
+
value: resolved.value
|
|
858
|
+
}));
|
|
859
|
+
}
|
|
860
|
+
return run();
|
|
861
|
+
} finally {
|
|
862
|
+
for (const [schema, descriptor] of originals)
|
|
863
|
+
Object.defineProperty(schema, "default", descriptor);
|
|
864
|
+
}
|
|
865
|
+
}, restoreArrayBuffers = (inputSchema, input, defaulted, references) => {
|
|
866
|
+
const schema = resolveDefaultSchema(inputSchema, references);
|
|
867
|
+
if (schema[import_typebox.Kind] === "ArrayBuffer" && input instanceof ArrayBuffer)
|
|
868
|
+
return input;
|
|
869
|
+
const properties = getSchemaProperties(schema);
|
|
870
|
+
if (properties && input !== null && typeof input == "object" && defaulted !== null && typeof defaulted == "object")
|
|
871
|
+
for (const [key, propertySchema] of Object.entries(properties))
|
|
872
|
+
!hasOwn(input, key) || !hasOwn(defaulted, key) || Object.defineProperty(defaulted, key, {
|
|
873
|
+
value: restoreArrayBuffers(
|
|
874
|
+
propertySchema,
|
|
875
|
+
input[key],
|
|
876
|
+
defaulted[key],
|
|
877
|
+
references
|
|
878
|
+
),
|
|
879
|
+
enumerable: !0,
|
|
880
|
+
configurable: !0,
|
|
881
|
+
writable: !0
|
|
882
|
+
});
|
|
883
|
+
else if (Array.isArray(input) && Array.isArray(defaulted) && schema.items)
|
|
884
|
+
if (Array.isArray(schema.items))
|
|
885
|
+
for (let i = 0; i < schema.items.length; i++)
|
|
886
|
+
defaulted[i] = restoreArrayBuffers(
|
|
887
|
+
schema.items[i],
|
|
888
|
+
input[i],
|
|
889
|
+
defaulted[i],
|
|
890
|
+
references
|
|
891
|
+
);
|
|
892
|
+
else
|
|
893
|
+
for (let i = 0; i < input.length; i++)
|
|
894
|
+
defaulted[i] = restoreArrayBuffers(
|
|
895
|
+
schema.items,
|
|
896
|
+
input[i],
|
|
897
|
+
defaulted[i],
|
|
898
|
+
references
|
|
899
|
+
);
|
|
900
|
+
return defaulted;
|
|
901
|
+
}, repairPrototypeDefaults = (inputSchema, input, references, nullish) => {
|
|
902
|
+
const schema = resolveDefaultSchema(inputSchema, references);
|
|
903
|
+
if (schema.anyOf || schema.oneOf) {
|
|
904
|
+
const members = schema.anyOf ?? schema.oneOf;
|
|
905
|
+
for (const member of members) {
|
|
906
|
+
const candidate = repairPrototypeDefaults(
|
|
907
|
+
member,
|
|
908
|
+
cloneForDefaults(input),
|
|
909
|
+
references,
|
|
910
|
+
nullish
|
|
911
|
+
);
|
|
912
|
+
if (import_value.Value.Check(member, references, candidate)) return candidate;
|
|
913
|
+
}
|
|
914
|
+
return input;
|
|
915
|
+
}
|
|
916
|
+
if (schema.allOf) {
|
|
917
|
+
let value = input;
|
|
918
|
+
for (const member of schema.allOf)
|
|
919
|
+
value = repairPrototypeDefaults(
|
|
920
|
+
member,
|
|
921
|
+
value,
|
|
922
|
+
references,
|
|
923
|
+
nullish
|
|
924
|
+
);
|
|
925
|
+
return value;
|
|
926
|
+
}
|
|
927
|
+
const properties = getSchemaProperties(schema);
|
|
928
|
+
if (properties && input !== null && typeof input == "object")
|
|
929
|
+
for (const [key, propertySchema] of Object.entries(properties))
|
|
930
|
+
(!hasOwn(input, key) || nullish && input[key] === null) && hasOwn(propertySchema, "default") && Object.defineProperty(input, key, {
|
|
931
|
+
value: cloneDefault(propertySchema.default),
|
|
932
|
+
enumerable: !0,
|
|
933
|
+
configurable: !0,
|
|
934
|
+
writable: !0
|
|
935
|
+
}), hasOwn(input, key) && Object.defineProperty(input, key, {
|
|
936
|
+
value: repairPrototypeDefaults(
|
|
937
|
+
propertySchema,
|
|
938
|
+
input[key],
|
|
939
|
+
references,
|
|
940
|
+
nullish
|
|
941
|
+
),
|
|
942
|
+
enumerable: !0,
|
|
943
|
+
configurable: !0,
|
|
944
|
+
writable: !0
|
|
945
|
+
});
|
|
946
|
+
else if (Array.isArray(input) && schema.items && !Array.isArray(schema.items))
|
|
947
|
+
for (let i = 0; i < input.length; i++)
|
|
948
|
+
input[i] = repairPrototypeDefaults(
|
|
949
|
+
schema.items,
|
|
950
|
+
input[i],
|
|
951
|
+
references,
|
|
952
|
+
nullish
|
|
953
|
+
);
|
|
954
|
+
return input;
|
|
955
|
+
}, removeFileDefaults = (inputSchema, value, references) => {
|
|
956
|
+
const schema = resolveDefaultSchema(inputSchema, references), properties = getSchemaProperties(schema);
|
|
957
|
+
if (properties && value !== null && typeof value == "object")
|
|
958
|
+
for (const [key, propertySchema] of Object.entries(properties))
|
|
959
|
+
hasOwn(value, key) && (propertySchema[import_typebox.Kind] === "File" && value[key] === "File" || propertySchema[import_typebox.Kind] === "Files" && value[key] === "Files" ? delete value[key] : removeFileDefaults(propertySchema, value[key], references));
|
|
960
|
+
else if (Array.isArray(value) && schema.items && !Array.isArray(schema.items))
|
|
961
|
+
for (const item of value) removeFileDefaults(schema.items, item, references);
|
|
962
|
+
}, mergeDefaultResult = (original, defaulted) => {
|
|
963
|
+
if (Array.isArray(defaulted)) {
|
|
964
|
+
const target2 = Array.isArray(original) ? original : [];
|
|
965
|
+
target2.length = defaulted.length;
|
|
966
|
+
for (let i = 0; i < defaulted.length; i++)
|
|
967
|
+
target2[i] = mergeDefaultResult(
|
|
968
|
+
Array.isArray(original) ? original[i] : void 0,
|
|
969
|
+
defaulted[i]
|
|
970
|
+
);
|
|
971
|
+
return target2;
|
|
972
|
+
}
|
|
973
|
+
if (defaulted === null || typeof defaulted != "object" || defaulted instanceof Date || defaulted instanceof Map || defaulted instanceof Set || defaulted instanceof ArrayBuffer || ArrayBuffer.isView(defaulted))
|
|
974
|
+
return defaulted;
|
|
975
|
+
const target = original !== null && typeof original == "object" && !Array.isArray(original) ? original : {};
|
|
976
|
+
for (const key of Object.getOwnPropertyNames(defaulted))
|
|
977
|
+
Object.defineProperty(target, key, {
|
|
978
|
+
value: mergeDefaultResult(
|
|
979
|
+
hasOwn(target, key) ? target[key] : void 0,
|
|
980
|
+
defaulted[key]
|
|
981
|
+
),
|
|
982
|
+
enumerable: Object.prototype.propertyIsEnumerable.call(defaulted, key),
|
|
983
|
+
configurable: !0,
|
|
984
|
+
writable: !0
|
|
985
|
+
});
|
|
986
|
+
for (const key of Object.getOwnPropertySymbols(defaulted))
|
|
987
|
+
Object.defineProperty(target, key, {
|
|
988
|
+
value: mergeDefaultResult(
|
|
989
|
+
hasOwn(target, key) ? target[key] : void 0,
|
|
990
|
+
defaulted[key]
|
|
991
|
+
),
|
|
992
|
+
enumerable: Object.prototype.propertyIsEnumerable.call(defaulted, key),
|
|
993
|
+
configurable: !0,
|
|
994
|
+
writable: !0
|
|
995
|
+
});
|
|
996
|
+
return target;
|
|
997
|
+
}, applySchemaDefaults = (checker, value, nullish = !1) => {
|
|
998
|
+
const schema = checker.schema;
|
|
999
|
+
if (!schema) return value;
|
|
1000
|
+
const references = typeof checker.References == "function" ? checker.References() : Object.values(schema.$defs ?? {}), functionDefaults = /* @__PURE__ */ new Map(), prepared = prepareDefaultInput(
|
|
1001
|
+
schema,
|
|
1002
|
+
value,
|
|
1003
|
+
references,
|
|
1004
|
+
nullish,
|
|
1005
|
+
!0,
|
|
1006
|
+
functionDefaults
|
|
1007
|
+
);
|
|
1008
|
+
return withResolvedFunctionDefaults(functionDefaults, () => {
|
|
1009
|
+
const defaulted = repairPrototypeDefaults(
|
|
1010
|
+
schema,
|
|
1011
|
+
restoreArrayBuffers(
|
|
1012
|
+
schema,
|
|
1013
|
+
prepared,
|
|
1014
|
+
import_value.Value.Default(
|
|
1015
|
+
schema,
|
|
1016
|
+
references,
|
|
1017
|
+
cloneForDefaults(prepared)
|
|
1018
|
+
),
|
|
1019
|
+
references
|
|
1020
|
+
),
|
|
1021
|
+
references,
|
|
1022
|
+
nullish
|
|
1023
|
+
);
|
|
1024
|
+
return removeFileDefaults(schema, defaulted, references), mergeDefaultResult(value, defaulted);
|
|
1025
|
+
});
|
|
674
1026
|
}, mergeObjectSchemas = (schemas) => {
|
|
675
1027
|
if (schemas.length === 0)
|
|
676
1028
|
return {
|
|
@@ -822,6 +1174,8 @@ const isOptional = (schema) => schema ? schema?.[import_typebox.Kind] === "Impor
|
|
|
822
1174
|
}, unwrapImportSchema = (schema) => schema && schema[import_typebox.Kind] === "Import" && schema.$defs[schema.$ref][import_typebox.Kind] === "Object" ? schema.$defs[schema.$ref] : schema;
|
|
823
1175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
824
1176
|
0 && (module.exports = {
|
|
1177
|
+
applySchemaDefaults,
|
|
1178
|
+
cloneSchemaInput,
|
|
825
1179
|
getCookieValidator,
|
|
826
1180
|
getResponseSchemaValidator,
|
|
827
1181
|
getSchemaProperties,
|