elysia 2.0.0-beta.2 → 2.0.0-beta.3
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/utils.js +3 -3
- package/dist/adapter/utils.mjs +4 -4
- package/dist/adapter/web-standard/handler.js +5 -2
- package/dist/adapter/web-standard/handler.mjs +5 -2
- package/dist/base.d.ts +2 -2
- package/dist/base.js +42 -27
- package/dist/base.mjs +43 -28
- package/dist/compile/aot.d.ts +4 -4
- package/dist/compile/aot.js +14 -9
- package/dist/compile/aot.mjs +15 -9
- package/dist/compile/handler/descriptor.js +1 -1
- package/dist/compile/handler/descriptor.mjs +1 -1
- package/dist/compile/handler/index.d.ts +2 -2
- package/dist/compile/handler/index.js +6 -4
- package/dist/compile/handler/index.mjs +6 -4
- package/dist/compile/handler/utils.js +2 -2
- package/dist/compile/handler/utils.mjs +3 -3
- package/dist/context.js +3 -4
- package/dist/context.mjs +3 -4
- package/dist/cookie/config.d.ts +1 -0
- package/dist/cookie/config.js +3 -2
- package/dist/cookie/config.mjs +3 -2
- package/dist/cookie/cookie.d.ts +1 -0
- package/dist/cookie/cookie.js +6 -5
- package/dist/cookie/cookie.mjs +6 -5
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +38 -31
- package/dist/cookie/crypto.mjs +38 -32
- package/dist/cookie/error.js +1 -2
- package/dist/cookie/error.mjs +1 -2
- package/dist/cookie/lib.js +5 -1
- package/dist/cookie/lib.mjs +5 -1
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.js +28 -14
- package/dist/cookie/utils.mjs +29 -15
- package/dist/handler/error.d.ts +23 -12
- package/dist/handler/error.js +24 -21
- package/dist/handler/error.mjs +20 -21
- package/dist/handler/fetch.js +6 -7
- package/dist/handler/fetch.mjs +7 -8
- package/dist/handler/utils.js +4 -2
- package/dist/handler/utils.mjs +5 -3
- package/dist/index.js +1 -8
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +22 -1
- package/dist/plugin/aot/core.js +35 -3
- package/dist/plugin/aot/core.mjs +35 -3
- package/dist/route-table.js +12 -10
- package/dist/route-table.mjs +12 -10
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.js +1 -1
- package/dist/type/bridge-live.mjs +1 -1
- package/dist/type/bridge.d.ts +1 -1
- package/dist/type/coerce-plan.js +3 -4
- package/dist/type/coerce-plan.mjs +1 -1
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +32 -14
- package/dist/type/compat.mjs +27 -8
- package/dist/type/elysia/array-buffer.js +2 -3
- package/dist/type/elysia/array-buffer.mjs +1 -1
- package/dist/type/elysia/array-string.js +7 -4
- package/dist/type/elysia/array-string.mjs +9 -5
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +4 -3
- package/dist/type/elysia/boolean.mjs +4 -2
- package/dist/type/elysia/cookie.js +2 -1
- package/dist/type/elysia/cookie.mjs +2 -1
- package/dist/type/elysia/date.js +7 -7
- package/dist/type/elysia/date.mjs +3 -2
- package/dist/type/elysia/file-type.d.ts +9 -2
- package/dist/type/elysia/file-type.js +16 -1
- package/dist/type/elysia/file-type.mjs +16 -2
- package/dist/type/elysia/file.js +8 -4
- package/dist/type/elysia/file.mjs +8 -3
- package/dist/type/elysia/files.js +6 -4
- package/dist/type/elysia/files.mjs +5 -2
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.js +4 -5
- package/dist/type/elysia/integer-string.mjs +3 -3
- package/dist/type/elysia/integer.js +4 -3
- package/dist/type/elysia/integer.mjs +4 -2
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.js +4 -3
- package/dist/type/elysia/number.mjs +4 -2
- package/dist/type/elysia/numeric-enum.js +2 -3
- package/dist/type/elysia/numeric-enum.mjs +1 -1
- package/dist/type/elysia/numeric.js +5 -5
- package/dist/type/elysia/numeric.mjs +3 -2
- package/dist/type/elysia/object-string.js +7 -4
- package/dist/type/elysia/object-string.mjs +9 -5
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.js +2 -3
- package/dist/type/elysia/uint8-array.mjs +1 -1
- package/dist/type/elysia/union-enum.js +2 -3
- package/dist/type/elysia/union-enum.mjs +1 -1
- package/dist/type/elysia/utils.js +2 -3
- package/dist/type/elysia/utils.mjs +1 -1
- package/dist/type/exports.js +10 -1
- package/dist/type/exports.mjs +7 -0
- package/dist/type/index.d.ts +9 -1
- package/dist/type/index.js +41 -13
- package/dist/type/index.mjs +44 -9
- package/dist/type/typebox-type-live.d.ts +9 -0
- package/dist/type/typebox-type-live.js +31 -0
- package/dist/type/typebox-type-live.mjs +16 -0
- package/dist/type/typebox-type.d.ts +24 -0
- package/dist/type/typebox-type.js +130 -0
- package/dist/type/typebox-type.mjs +66 -0
- package/dist/type/typebox-value-live.d.ts +9 -0
- package/dist/type/typebox-value-live.js +27 -0
- package/dist/type/typebox-value-live.mjs +11 -0
- package/dist/type/typebox-value.d.ts +30 -0
- package/dist/type/typebox-value.js +147 -0
- package/dist/type/typebox-value.mjs +62 -0
- package/dist/type/validator/custom-error.js +4 -5
- package/dist/type/validator/custom-error.mjs +3 -3
- package/dist/type/validator/default-precompute.js +4 -5
- package/dist/type/validator/default-precompute.mjs +1 -1
- package/dist/type/validator/index.js +41 -35
- package/dist/type/validator/index.mjs +23 -16
- package/dist/type/validator/validator-cache.js +10 -5
- package/dist/type/validator/validator-cache.mjs +10 -4
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/utils.d.ts +10 -1
- package/dist/utils.js +18 -3
- package/dist/utils.mjs +14 -3
- package/dist/validator/index.js +2 -1
- package/dist/validator/index.mjs +2 -1
- package/dist/ws/context.d.ts +4 -0
- package/dist/ws/context.js +44 -26
- package/dist/ws/context.mjs +44 -26
- package/dist/ws/route.js +126 -23
- package/dist/ws/route.mjs +128 -25
- package/package.json +4 -2
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_utils = require('../../utils.js');
|
|
4
3
|
const require_type_constants = require('../constants.js');
|
|
5
4
|
const require_error = require('../../error.js');
|
|
@@ -9,14 +8,13 @@ const require_type_elysia_file_type = require('../elysia/file-type.js');
|
|
|
9
8
|
const require_type_validator_clean_safe = require('./clean-safe.js');
|
|
10
9
|
const require_type_utils = require('../utils.js');
|
|
11
10
|
const require_validator_index = require('../../validator/index.js');
|
|
11
|
+
const require_type_typebox_type = require('../typebox-type.js');
|
|
12
|
+
const require_type_typebox_value = require('../typebox-value.js');
|
|
12
13
|
const require_type_coerce = require('../coerce.js');
|
|
13
14
|
const require_type_validator_default_precompute = require('./default-precompute.js');
|
|
14
15
|
const require_type_validator_custom_error = require('./custom-error.js');
|
|
15
16
|
const require_type_validator_exact_mirror = require('./exact-mirror.js');
|
|
16
17
|
const require_type_validator_validator_cache = require('./validator-cache.js');
|
|
17
|
-
let typebox_type = require("typebox/type");
|
|
18
|
-
let typebox_value = require("typebox/value");
|
|
19
|
-
let typebox_schema = require("typebox/schema");
|
|
20
18
|
|
|
21
19
|
//#region src/type/validator/index.ts
|
|
22
20
|
const moduleCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -206,6 +204,18 @@ function findInstancePath(value, target, path = "") {
|
|
|
206
204
|
if (found !== void 0) return found;
|
|
207
205
|
}
|
|
208
206
|
}
|
|
207
|
+
function reportSchema(schema) {
|
|
208
|
+
try {
|
|
209
|
+
return JSON.stringify(schema, (key, value) => key === "secrets" ? "[redacted]" : value);
|
|
210
|
+
} catch {
|
|
211
|
+
return "[unserializable schema]";
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function warnMirrorFailure(schema, error) {
|
|
215
|
+
console.warn("Failed to create exactMirror. Please report the following code to https://github.com/elysiajs/elysia/issues");
|
|
216
|
+
console.warn(reportSchema(schema));
|
|
217
|
+
console.warn(error);
|
|
218
|
+
}
|
|
209
219
|
var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
210
220
|
#decodeMirror;
|
|
211
221
|
#encodeMirror;
|
|
@@ -229,23 +239,23 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
229
239
|
this.#hits = 0;
|
|
230
240
|
if (isIntersectable) {
|
|
231
241
|
const members = [schema, ...options.schemas];
|
|
232
|
-
schema = shallowMergeObjects(members) ??
|
|
242
|
+
schema = shallowMergeObjects(members) ?? require_type_typebox_type.Evaluate(require_type_typebox_type.Intersect(members));
|
|
233
243
|
}
|
|
234
244
|
const originalElyTyp = schema?.["~elyTyp"];
|
|
235
245
|
const rawSchema = schema;
|
|
236
246
|
const frozen = options?.aot && options.slot ? require_compile_aot.Compiled.getValidator(options.aot.method, options.aot.path, options.slot, options.app?.["~programId"]) : void 0;
|
|
237
247
|
let schemaHasRef = false;
|
|
238
248
|
if (name && options?.models) {
|
|
239
|
-
schema = moduleCache.getOrInsertComputed(options.models, () =>
|
|
249
|
+
schema = moduleCache.getOrInsertComputed(options.models, () => require_type_typebox_type.Module(materializeModels(options.models)))[name];
|
|
240
250
|
if (isIntersectable) {
|
|
241
251
|
const members = [schema, ...options.schemas];
|
|
242
|
-
schema = shallowMergeObjects(members) ??
|
|
252
|
+
schema = shallowMergeObjects(members) ?? require_type_typebox_type.Evaluate(require_type_typebox_type.Intersect(members));
|
|
243
253
|
}
|
|
244
254
|
} else if (options?.models && typeof name !== "string") {
|
|
245
255
|
schemaHasRef = frozen ? frozen.r === 1 : require_type_validator_clean_safe.schemaContainsRef(schema);
|
|
246
256
|
if (schemaHasRef) {
|
|
247
257
|
const id = `inline@${++inlineRefId}`;
|
|
248
|
-
schema =
|
|
258
|
+
schema = require_type_typebox_type.Module({
|
|
249
259
|
...options.models,
|
|
250
260
|
[id]: schema
|
|
251
261
|
})[id];
|
|
@@ -256,13 +266,13 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
256
266
|
if (options?.normalize === false && options.slot !== "headers" && options.slot !== "cookie") this.schema = require_type_shared.nonAdditionalProperties(this.schema);
|
|
257
267
|
if (!isFrozen) {
|
|
258
268
|
const capturing = require_compile_aot.Capture.isCapturing();
|
|
259
|
-
this.hasCodec =
|
|
269
|
+
this.hasCodec = require_type_typebox_value.HasCodec(this.schema);
|
|
260
270
|
this.hasDefault = require_type_utils.hasProperty("default", this.schema);
|
|
261
271
|
if (!capturing && !options?.eager && !schemaMayHaveAsyncRefine(this.schema) && !schemaHasCustomError(this.schema)) {
|
|
262
272
|
this.#deferred = true;
|
|
263
273
|
this.isAsync = false;
|
|
264
274
|
} else {
|
|
265
|
-
this.tb = capturing && require_compile_aot.captureImpl ? require_compile_aot.captureImpl.sourceOnlyValidator(this.schema) :
|
|
275
|
+
this.tb = capturing && require_compile_aot.captureImpl ? require_compile_aot.captureImpl.sourceOnlyValidator(this.schema) : require_type_typebox_value.SchemaCompile(this.schema);
|
|
266
276
|
this.isAsync = this.tb.buildResult.external.variables.some(require_type_elysia_file_type.isAsyncPredicate) ?? false;
|
|
267
277
|
if (capturing && require_compile_aot.captureImpl && options?.aot && options.slot) require_compile_aot.captureImpl.maybeCapture({
|
|
268
278
|
aot: options.aot,
|
|
@@ -318,17 +328,15 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
318
328
|
if (isFrozen && frozen.cm) {
|
|
319
329
|
const both = require_compile_aot.reconstruct().instantiateFrozenBoth(frozen, this.schema, schema);
|
|
320
330
|
this.reconstructedCheck = both.check;
|
|
321
|
-
this.Clean = options?.normalize === false ? void 0 : require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) ? (value) =>
|
|
331
|
+
this.Clean = options?.normalize === false ? void 0 : require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) ? (value) => require_type_typebox_value.Clean(this.schema, value) : both.clean;
|
|
322
332
|
} else {
|
|
323
333
|
if (isFrozen) this.reconstructedCheck = frozen.c(frozen.e ? require_compile_aot.reconstruct().collectExternals(this.schema) : require_compile_aot.EMPTY_EXTERNALS);
|
|
324
334
|
if (!require_type_validator_exact_mirror.getExactMirror() && !frozen?.m && !require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) && options?.normalize !== false && options?.normalize !== "typebox" && (options?.normalize === true || options?.normalize === "exactMirror" || !!options?.sanitize)) throw require_type_validator_exact_mirror.exactMirrorRequired();
|
|
325
335
|
try {
|
|
326
|
-
this.Clean = options?.normalize === false ? void 0 : options?.normalize === "typebox" ? (value) =>
|
|
336
|
+
this.Clean = options?.normalize === false ? void 0 : options?.normalize === "typebox" ? (value) => require_type_typebox_value.Clean(this.schema, value) : this.#setupMirror(schema, options, frozen);
|
|
327
337
|
} catch (error) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
console.warn(error);
|
|
331
|
-
if (options?.normalize !== false) this.Clean = (value) => (0, typebox_value.Clean)(this.schema, value);
|
|
338
|
+
warnMirrorFailure(schema, error);
|
|
339
|
+
if (options?.normalize !== false) this.Clean = (value) => require_type_typebox_value.Clean(this.schema, value);
|
|
332
340
|
}
|
|
333
341
|
}
|
|
334
342
|
this.#cleanRedundant = !!this.Clean && !options?.sanitize && options?.normalize !== "typebox" && require_type_validator_clean_safe.isFullyClosedObject(this.schema);
|
|
@@ -361,7 +369,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
361
369
|
}
|
|
362
370
|
}
|
|
363
371
|
#setupMirror(schema, options, frozen) {
|
|
364
|
-
if (require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema)) return (value) =>
|
|
372
|
+
if (require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema)) return (value) => require_type_typebox_value.Clean(this.schema, value);
|
|
365
373
|
const aot = options?.aot;
|
|
366
374
|
const slot = options?.slot;
|
|
367
375
|
if (aot && slot && frozen?.m) {
|
|
@@ -371,9 +379,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
371
379
|
if (clean === void 0) try {
|
|
372
380
|
clean = require_compile_aot.reconstruct().instantiateFrozenMirror(m, schema);
|
|
373
381
|
} catch (error) {
|
|
374
|
-
|
|
375
|
-
console.warn(schema);
|
|
376
|
-
console.warn(error);
|
|
382
|
+
warnMirrorFailure(schema, error);
|
|
377
383
|
clean = (v) => v;
|
|
378
384
|
}
|
|
379
385
|
return clean(value);
|
|
@@ -381,9 +387,9 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
381
387
|
}
|
|
382
388
|
if (aot && slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureMirror(schema, aot, slot, options?.sanitize);
|
|
383
389
|
const createMirror = require_type_validator_exact_mirror.getExactMirror();
|
|
384
|
-
if (!createMirror) return (value) =>
|
|
390
|
+
if (!createMirror) return (value) => require_type_typebox_value.Clean(this.schema, value);
|
|
385
391
|
return createMirror(schema, {
|
|
386
|
-
Compile:
|
|
392
|
+
Compile: require_type_typebox_value.SchemaCompile,
|
|
387
393
|
sanitize: options?.sanitize
|
|
388
394
|
});
|
|
389
395
|
}
|
|
@@ -400,10 +406,10 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
400
406
|
run = require_compile_aot.reconstruct().instantiateFrozenDecodeMirror(m, schema, dir);
|
|
401
407
|
} catch {
|
|
402
408
|
run = dir === "decode" ? (v) => {
|
|
403
|
-
const decoded =
|
|
409
|
+
const decoded = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), schema, v);
|
|
404
410
|
return this.Clean ? this.Clean(decoded) : decoded;
|
|
405
411
|
} : (v) => {
|
|
406
|
-
const out =
|
|
412
|
+
const out = require_type_typebox_value.Encode(schema, v);
|
|
407
413
|
return this.Clean ? this.Clean(out) : out;
|
|
408
414
|
};
|
|
409
415
|
}
|
|
@@ -417,7 +423,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
417
423
|
if (!createMirror) return;
|
|
418
424
|
try {
|
|
419
425
|
return createMirror(schema, {
|
|
420
|
-
Compile:
|
|
426
|
+
Compile: require_type_typebox_value.SchemaCompile,
|
|
421
427
|
sanitize: options?.sanitize,
|
|
422
428
|
...dirOpt
|
|
423
429
|
});
|
|
@@ -447,7 +453,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
447
453
|
}
|
|
448
454
|
#rawCheck(value) {
|
|
449
455
|
if (this.reconstructedCheck) return this.reconstructedCheck(value);
|
|
450
|
-
if (this.#deferred) return
|
|
456
|
+
if (this.#deferred) return require_type_typebox_value.Check(this.schema, value);
|
|
451
457
|
return this.tb.Check(value);
|
|
452
458
|
}
|
|
453
459
|
#tick() {
|
|
@@ -457,7 +463,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
457
463
|
* Promote a deferred validator to the compiled `Check` fast path
|
|
458
464
|
*/
|
|
459
465
|
#materialize() {
|
|
460
|
-
const tb =
|
|
466
|
+
const tb = require_type_typebox_value.SchemaCompile(this.schema);
|
|
461
467
|
this.tb = tb;
|
|
462
468
|
this.#dropCompiledSource();
|
|
463
469
|
this.#deferred = false;
|
|
@@ -477,13 +483,13 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
477
483
|
if (tb.buildResult) tb.buildResult.functions = void 0;
|
|
478
484
|
}
|
|
479
485
|
Errors(value) {
|
|
480
|
-
return
|
|
486
|
+
return require_type_typebox_value.Errors(this.schema, value);
|
|
481
487
|
}
|
|
482
488
|
Decode(value) {
|
|
483
|
-
return
|
|
489
|
+
return require_type_typebox_value.Decode(this.schema, value);
|
|
484
490
|
}
|
|
485
491
|
Encode(value) {
|
|
486
|
-
return this.hasCodec ?
|
|
492
|
+
return this.hasCodec ? require_type_typebox_value.Encode(this.schema, value) : value;
|
|
487
493
|
}
|
|
488
494
|
EncodeFrom(value, type) {
|
|
489
495
|
this.#tick();
|
|
@@ -505,7 +511,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
505
511
|
if (errors) throw new require_error.ValidationError(type, out, errors.length ? errors : () => this.Errors(out), this.schema);
|
|
506
512
|
return out;
|
|
507
513
|
}
|
|
508
|
-
const out = this.#noValidate ?
|
|
514
|
+
const out = this.#noValidate ? require_type_typebox_value.EncodeUnsafe(require_utils.nullObject(), this.schema, value) : require_type_typebox_value.Encode(this.schema, value);
|
|
509
515
|
return this.Clean ? this.Clean(out) : out;
|
|
510
516
|
} catch (e) {
|
|
511
517
|
if (this.#noValidate) return this.Clean ? this.Clean(value) : value;
|
|
@@ -559,7 +565,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
559
565
|
if (defaults) {
|
|
560
566
|
if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
|
|
561
567
|
else if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) value = this.#applyPrecomputedObjectDefault(value);
|
|
562
|
-
} else value =
|
|
568
|
+
} else value = require_type_typebox_value.Default(this.schema, value);
|
|
563
569
|
}
|
|
564
570
|
if (this.#hasOptional) {
|
|
565
571
|
const bypass = this.optionalBypass(value);
|
|
@@ -583,7 +589,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
583
589
|
}
|
|
584
590
|
if (this.#decodeMirror) value = this.#decodeMirror(value);
|
|
585
591
|
else try {
|
|
586
|
-
value =
|
|
592
|
+
value = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), this.schema, value);
|
|
587
593
|
} catch (e) {
|
|
588
594
|
if (e instanceof require_error.ValidationError) throw e;
|
|
589
595
|
if (e?.error) throw e.error;
|
|
@@ -614,7 +620,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
614
620
|
if (defaults) {
|
|
615
621
|
if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
|
|
616
622
|
else if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) value = this.#applyPrecomputedObjectDefault(value);
|
|
617
|
-
} else value =
|
|
623
|
+
} else value = require_type_typebox_value.Default(this.schema, value);
|
|
618
624
|
}
|
|
619
625
|
if (this.#hasOptional) {
|
|
620
626
|
const bypass = this.optionalBypass(value);
|
|
@@ -628,7 +634,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
628
634
|
if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
|
|
629
635
|
if (this.#decodeMirror) value = this.#decodeMirror(value);
|
|
630
636
|
else try {
|
|
631
|
-
value =
|
|
637
|
+
value = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), this.schema, value);
|
|
632
638
|
} catch (e) {
|
|
633
639
|
if (e instanceof require_error.ValidationError) throw e;
|
|
634
640
|
if (e?.error) throw e.error;
|
|
@@ -6,15 +6,14 @@ import { isPureRefinement, nonAdditionalProperties } from "../shared.mjs";
|
|
|
6
6
|
import { collectFileTypeChecks, isAsyncPredicate, takeFileTypeChecks } from "../elysia/file-type.mjs";
|
|
7
7
|
import { isFullyClosedObject, schemaContainsRef, schemaHasDangerousProperties, schemaSome } from "./clean-safe.mjs";
|
|
8
8
|
import { hasProperty } from "../utils.mjs";
|
|
9
|
-
import { Validator
|
|
9
|
+
import { Validator } from "../../validator/index.mjs";
|
|
10
|
+
import { Evaluate, Intersect, Module } from "../typebox-type.mjs";
|
|
11
|
+
import { Check, Clean, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec, SchemaCompile } from "../typebox-value.mjs";
|
|
10
12
|
import { applyCoercions, buildCoercedFromPlan } from "../coerce.mjs";
|
|
11
13
|
import { applyPrecomputed, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, verifyPreallocatableDefault } from "./default-precompute.mjs";
|
|
12
14
|
import { buildFindCustomError } from "./custom-error.mjs";
|
|
13
15
|
import { exactMirrorRequired, getExactMirror } from "./exact-mirror.mjs";
|
|
14
16
|
import { TypeBoxValidatorCache, mayHaveFileType } from "./validator-cache.mjs";
|
|
15
|
-
import { Evaluate, Intersect, Module } from "typebox/type";
|
|
16
|
-
import { Check, Clean, Decode as Decode$1, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
|
|
17
|
-
import { Compile } from "typebox/schema";
|
|
18
17
|
|
|
19
18
|
//#region src/type/validator/index.ts
|
|
20
19
|
const moduleCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -204,7 +203,19 @@ function findInstancePath(value, target, path = "") {
|
|
|
204
203
|
if (found !== void 0) return found;
|
|
205
204
|
}
|
|
206
205
|
}
|
|
207
|
-
|
|
206
|
+
function reportSchema(schema) {
|
|
207
|
+
try {
|
|
208
|
+
return JSON.stringify(schema, (key, value) => key === "secrets" ? "[redacted]" : value);
|
|
209
|
+
} catch {
|
|
210
|
+
return "[unserializable schema]";
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function warnMirrorFailure(schema, error) {
|
|
214
|
+
console.warn("Failed to create exactMirror. Please report the following code to https://github.com/elysiajs/elysia/issues");
|
|
215
|
+
console.warn(reportSchema(schema));
|
|
216
|
+
console.warn(error);
|
|
217
|
+
}
|
|
218
|
+
var TypeBoxValidator = class extends Validator {
|
|
208
219
|
#decodeMirror;
|
|
209
220
|
#encodeMirror;
|
|
210
221
|
#refinements;
|
|
@@ -260,7 +271,7 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
260
271
|
this.#deferred = true;
|
|
261
272
|
this.isAsync = false;
|
|
262
273
|
} else {
|
|
263
|
-
this.tb = capturing && captureImpl ? captureImpl.sourceOnlyValidator(this.schema) :
|
|
274
|
+
this.tb = capturing && captureImpl ? captureImpl.sourceOnlyValidator(this.schema) : SchemaCompile(this.schema);
|
|
264
275
|
this.isAsync = this.tb.buildResult.external.variables.some(isAsyncPredicate) ?? false;
|
|
265
276
|
if (capturing && captureImpl && options?.aot && options.slot) captureImpl.maybeCapture({
|
|
266
277
|
aot: options.aot,
|
|
@@ -323,9 +334,7 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
323
334
|
try {
|
|
324
335
|
this.Clean = options?.normalize === false ? void 0 : options?.normalize === "typebox" ? (value) => Clean(this.schema, value) : this.#setupMirror(schema, options, frozen);
|
|
325
336
|
} catch (error) {
|
|
326
|
-
|
|
327
|
-
console.warn(schema);
|
|
328
|
-
console.warn(error);
|
|
337
|
+
warnMirrorFailure(schema, error);
|
|
329
338
|
if (options?.normalize !== false) this.Clean = (value) => Clean(this.schema, value);
|
|
330
339
|
}
|
|
331
340
|
}
|
|
@@ -369,9 +378,7 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
369
378
|
if (clean === void 0) try {
|
|
370
379
|
clean = reconstruct().instantiateFrozenMirror(m, schema);
|
|
371
380
|
} catch (error) {
|
|
372
|
-
|
|
373
|
-
console.warn(schema);
|
|
374
|
-
console.warn(error);
|
|
381
|
+
warnMirrorFailure(schema, error);
|
|
375
382
|
clean = (v) => v;
|
|
376
383
|
}
|
|
377
384
|
return clean(value);
|
|
@@ -381,7 +388,7 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
381
388
|
const createMirror = getExactMirror();
|
|
382
389
|
if (!createMirror) return (value) => Clean(this.schema, value);
|
|
383
390
|
return createMirror(schema, {
|
|
384
|
-
Compile,
|
|
391
|
+
Compile: SchemaCompile,
|
|
385
392
|
sanitize: options?.sanitize
|
|
386
393
|
});
|
|
387
394
|
}
|
|
@@ -415,7 +422,7 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
415
422
|
if (!createMirror) return;
|
|
416
423
|
try {
|
|
417
424
|
return createMirror(schema, {
|
|
418
|
-
Compile,
|
|
425
|
+
Compile: SchemaCompile,
|
|
419
426
|
sanitize: options?.sanitize,
|
|
420
427
|
...dirOpt
|
|
421
428
|
});
|
|
@@ -455,7 +462,7 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
455
462
|
* Promote a deferred validator to the compiled `Check` fast path
|
|
456
463
|
*/
|
|
457
464
|
#materialize() {
|
|
458
|
-
const tb =
|
|
465
|
+
const tb = SchemaCompile(this.schema);
|
|
459
466
|
this.tb = tb;
|
|
460
467
|
this.#dropCompiledSource();
|
|
461
468
|
this.#deferred = false;
|
|
@@ -478,7 +485,7 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
478
485
|
return Errors(this.schema, value);
|
|
479
486
|
}
|
|
480
487
|
Decode(value) {
|
|
481
|
-
return Decode
|
|
488
|
+
return Decode(this.schema, value);
|
|
482
489
|
}
|
|
483
490
|
Encode(value) {
|
|
484
491
|
return this.hasCodec ? Encode(this.schema, value) : value;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_universal_constants = require('../../universal/constants.js');
|
|
4
3
|
const require_utils = require('../../utils.js');
|
|
5
4
|
const require_type_constants = require('../constants.js');
|
|
6
5
|
const require_type_coerce = require('../coerce.js');
|
|
7
|
-
let typebox_value = require("typebox/value");
|
|
8
6
|
|
|
9
7
|
//#region src/type/validator/validator-cache.ts
|
|
10
8
|
const DEFAULT_CACHE_LIMIT = 1024;
|
|
@@ -46,6 +44,13 @@ function walk(value, key, mode, state) {
|
|
|
46
44
|
if (!state.hasRef && value["$ref"]) state.hasRef = true;
|
|
47
45
|
}
|
|
48
46
|
if (!state.hasFileType && (elyTyp === require_type_constants.ELYSIA_TYPES.File || elyTyp === require_type_constants.ELYSIA_TYPES.Files)) state.hasFileType = true;
|
|
47
|
+
if (!state.hasCodec) {
|
|
48
|
+
const codec = value["~codec"];
|
|
49
|
+
if (codec !== null && typeof codec === "object" && "encode" in codec && "decode" in codec) {
|
|
50
|
+
state.hasCodec = true;
|
|
51
|
+
if (!state.forceKey) state.buildKey = false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
49
54
|
const toJSON = value.toJSON;
|
|
50
55
|
if (typeof toJSON === "function") value = toJSON.call(value, typeof key === "number" ? "" + key : key);
|
|
51
56
|
}
|
|
@@ -119,17 +124,17 @@ function walkArray(value, mode, state) {
|
|
|
119
124
|
return serialized + "]";
|
|
120
125
|
}
|
|
121
126
|
function computeSchemaMeta(schema, forceKey) {
|
|
122
|
-
const hasCodec = (0, typebox_value.HasCodec)(schema);
|
|
123
127
|
const state = {
|
|
124
128
|
isOpaque: false,
|
|
125
129
|
hasRef: false,
|
|
126
130
|
hasFileType: false,
|
|
131
|
+
hasCodec: false,
|
|
127
132
|
forceKey,
|
|
128
|
-
buildKey:
|
|
133
|
+
buildKey: true,
|
|
129
134
|
depth: 0
|
|
130
135
|
};
|
|
131
136
|
const key = walk(schema, "", NODE, state);
|
|
132
|
-
const special = hasCodec || state.isOpaque;
|
|
137
|
+
const special = state.hasCodec || state.isOpaque;
|
|
133
138
|
return {
|
|
134
139
|
special,
|
|
135
140
|
hasRef: state.hasRef,
|
|
@@ -2,7 +2,6 @@ import { isCloudflareWorker } from "../../universal/constants.mjs";
|
|
|
2
2
|
import { evictOldestHalf, nullObject } from "../../utils.mjs";
|
|
3
3
|
import { ELYSIA_TYPES } from "../constants.mjs";
|
|
4
4
|
import { deferCoercions } from "../coerce.mjs";
|
|
5
|
-
import { HasCodec } from "typebox/value";
|
|
6
5
|
|
|
7
6
|
//#region src/type/validator/validator-cache.ts
|
|
8
7
|
const DEFAULT_CACHE_LIMIT = 1024;
|
|
@@ -44,6 +43,13 @@ function walk(value, key, mode, state) {
|
|
|
44
43
|
if (!state.hasRef && value["$ref"]) state.hasRef = true;
|
|
45
44
|
}
|
|
46
45
|
if (!state.hasFileType && (elyTyp === ELYSIA_TYPES.File || elyTyp === ELYSIA_TYPES.Files)) state.hasFileType = true;
|
|
46
|
+
if (!state.hasCodec) {
|
|
47
|
+
const codec = value["~codec"];
|
|
48
|
+
if (codec !== null && typeof codec === "object" && "encode" in codec && "decode" in codec) {
|
|
49
|
+
state.hasCodec = true;
|
|
50
|
+
if (!state.forceKey) state.buildKey = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
47
53
|
const toJSON = value.toJSON;
|
|
48
54
|
if (typeof toJSON === "function") value = toJSON.call(value, typeof key === "number" ? "" + key : key);
|
|
49
55
|
}
|
|
@@ -117,17 +123,17 @@ function walkArray(value, mode, state) {
|
|
|
117
123
|
return serialized + "]";
|
|
118
124
|
}
|
|
119
125
|
function computeSchemaMeta(schema, forceKey) {
|
|
120
|
-
const hasCodec = HasCodec(schema);
|
|
121
126
|
const state = {
|
|
122
127
|
isOpaque: false,
|
|
123
128
|
hasRef: false,
|
|
124
129
|
hasFileType: false,
|
|
130
|
+
hasCodec: false,
|
|
125
131
|
forceKey,
|
|
126
|
-
buildKey:
|
|
132
|
+
buildKey: true,
|
|
127
133
|
depth: 0
|
|
128
134
|
};
|
|
129
135
|
const key = walk(schema, "", NODE, state);
|
|
130
|
-
const special = hasCodec || state.isOpaque;
|
|
136
|
+
const special = state.hasCodec || state.isOpaque;
|
|
131
137
|
return {
|
|
132
138
|
special,
|
|
133
139
|
hasRef: state.hasRef,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//#region src/universal/constants.d.ts
|
|
2
2
|
declare const isBun: boolean;
|
|
3
|
+
declare const isFastly: boolean;
|
|
3
4
|
declare const isCloudflareWorker: boolean;
|
|
4
5
|
declare const hasHeaderShorthand: boolean;
|
|
5
6
|
//#endregion
|
|
6
|
-
export { hasHeaderShorthand, isBun, isCloudflareWorker };
|
|
7
|
+
export { hasHeaderShorthand, isBun, isCloudflareWorker, isFastly };
|
|
@@ -2,6 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
|
|
3
3
|
//#region src/universal/constants.ts
|
|
4
4
|
const isBun = typeof Bun !== "undefined";
|
|
5
|
+
const isFastly = typeof fastly !== "undefined";
|
|
5
6
|
const isCloudflareWorker = (() => {
|
|
6
7
|
try {
|
|
7
8
|
if (typeof caches !== "undefined" && typeof caches.default !== "undefined") return true;
|
|
@@ -16,4 +17,5 @@ const hasHeaderShorthand = isBun ? "toJSON" in new Headers() : false;
|
|
|
16
17
|
//#endregion
|
|
17
18
|
exports.hasHeaderShorthand = hasHeaderShorthand;
|
|
18
19
|
exports.isBun = isBun;
|
|
19
|
-
exports.isCloudflareWorker = isCloudflareWorker;
|
|
20
|
+
exports.isCloudflareWorker = isCloudflareWorker;
|
|
21
|
+
exports.isFastly = isFastly;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
//#region src/universal/constants.ts
|
|
2
2
|
const isBun = typeof Bun !== "undefined";
|
|
3
|
+
const isFastly = typeof fastly !== "undefined";
|
|
3
4
|
const isCloudflareWorker = (() => {
|
|
4
5
|
try {
|
|
5
6
|
if (typeof caches !== "undefined" && typeof caches.default !== "undefined") return true;
|
|
@@ -12,4 +13,4 @@ const isCloudflareWorker = (() => {
|
|
|
12
13
|
const hasHeaderShorthand = isBun ? "toJSON" in new Headers() : false;
|
|
13
14
|
|
|
14
15
|
//#endregion
|
|
15
|
-
export { hasHeaderShorthand, isBun, isCloudflareWorker };
|
|
16
|
+
export { hasHeaderShorthand, isBun, isCloudflareWorker, isFastly };
|
package/dist/utils.d.ts
CHANGED
|
@@ -116,6 +116,7 @@ declare function formToFormData(value: Record<keyof any, unknown>): FormData;
|
|
|
116
116
|
* ```
|
|
117
117
|
*/
|
|
118
118
|
declare const form: <const T extends Record<keyof any, unknown>>(value: T) => ElysiaFormData<T>;
|
|
119
|
+
declare const assignOwn: <T extends object>(target: T, source: any) => T;
|
|
119
120
|
declare const getLoosePath: (path: string) => string;
|
|
120
121
|
/**
|
|
121
122
|
* Certify a byte stream for direct Response body pass-through.
|
|
@@ -129,6 +130,7 @@ declare const isByteStream: (value: unknown) => value is ReadableStream<Uint8Arr
|
|
|
129
130
|
type FormatSSEPayload<T = unknown> = T extends string ? {
|
|
130
131
|
readonly data: T;
|
|
131
132
|
} : Prettify<SSEPayload<T>>;
|
|
133
|
+
declare const sseData: (value: string) => string;
|
|
132
134
|
declare const sse: <const T extends string | SSEPayload | Generator | AsyncGenerator | ReadableStream>(_payload: T) => T extends string ? {
|
|
133
135
|
readonly data: T;
|
|
134
136
|
} : T extends SSEPayload ? T : T extends ReadableStream<infer A> ? ReadableStream<FormatSSEPayload<A>> : T extends Generator<infer A, infer B, infer C> ? Generator<FormatSSEPayload<A>, B, C> : T extends AsyncGenerator<infer A, infer B_1, infer C_1> ? AsyncGenerator<FormatSSEPayload<A>, B_1, C_1> : T;
|
|
@@ -166,7 +168,14 @@ declare function clonePlainDeep<T>(value: T, seen?: WeakMap<object, any>): T;
|
|
|
166
168
|
declare function guardNonPlainLeaves(target: Record<string, unknown>, source: Record<string, unknown>): void;
|
|
167
169
|
declare function joinPath(base: string, path: string): string;
|
|
168
170
|
declare function pushField<K extends keyof any>(target: Record<K, unknown>, key: K, item: unknown, defaultArray?: boolean): void;
|
|
171
|
+
declare const fallbackRequestId: () => string;
|
|
169
172
|
declare const requestId: any;
|
|
173
|
+
/**
|
|
174
|
+
* Offset of the first byte after `://`, so the authority is never scanned as
|
|
175
|
+
* path. A fixed offset would let the client-supplied `Host` decide how many
|
|
176
|
+
* leading path bytes are dropped
|
|
177
|
+
*/
|
|
178
|
+
declare function authorityEnd(url: string): number;
|
|
170
179
|
declare function replaceUrlPath(url: string, path: string): string;
|
|
171
180
|
declare function clonePlainDecorators<T extends Record<string, unknown>>(source: T, seen?: WeakMap<object, any>): T;
|
|
172
181
|
declare function prefix<T extends string, Models extends Record<string, AnySchema>>(prefix: T, models: Models): { [k in keyof Models as `${T}.${k & string}`]: Models[k] };
|
|
@@ -175,4 +184,4 @@ declare namespace prefix {
|
|
|
175
184
|
}
|
|
176
185
|
declare function serializeMacroSeed(_key: string, value: unknown): unknown;
|
|
177
186
|
//#endregion
|
|
178
|
-
export { ChainNode, CompactBeforeHandleChunk, CompactBeforeHandlePrefix, DeriveEntry, ELYSIA_FORM_PROTOTYPE, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, constantTimeEqual, createErrorEventHandler, deriveEntryFn, eventProperties, evictOldestHalf, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isElysiaForm, isEmpty, isLocalScope, isMapDeriveEntry, isNotEmpty, isRecordNumber, joinPath, macroEpoch, macroOrigin, mapDeriveEntry, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, prefix, pushField, redirect, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse };
|
|
187
|
+
export { ChainNode, CompactBeforeHandleChunk, CompactBeforeHandlePrefix, DeriveEntry, ELYSIA_FORM_PROTOTYPE, assignOwn, authorityEnd, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, constantTimeEqual, createErrorEventHandler, deriveEntryFn, eventProperties, evictOldestHalf, fallbackRequestId, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isElysiaForm, isEmpty, isLocalScope, isMapDeriveEntry, isNotEmpty, isRecordNumber, joinPath, macroEpoch, macroOrigin, mapDeriveEntry, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, prefix, pushField, redirect, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse, sseData };
|
package/dist/utils.js
CHANGED
|
@@ -287,6 +287,7 @@ function formToFormData(value) {
|
|
|
287
287
|
* ```
|
|
288
288
|
*/
|
|
289
289
|
const form = (value) => Object.setPrototypeOf({ ...value }, ELYSIA_FORM_PROTOTYPE);
|
|
290
|
+
const assignOwn = (target, source) => source != null && Object.hasOwn(source, "__proto__") ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : Object.assign(target, source);
|
|
290
291
|
const getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, -1) : path + "/";
|
|
291
292
|
const byteStreams = /* @__PURE__ */ new WeakSet();
|
|
292
293
|
/**
|
|
@@ -625,9 +626,19 @@ function pushField(target, key, item, defaultArray = false) {
|
|
|
625
626
|
else target[key] = [v, item];
|
|
626
627
|
else target[key] = defaultArray ? [item] : item;
|
|
627
628
|
}
|
|
628
|
-
|
|
629
|
+
let fallbackRequestIdCounter = 0;
|
|
630
|
+
const fallbackRequestId = () => Date.now().toString(36) + "-" + (++fallbackRequestIdCounter).toString(36);
|
|
631
|
+
const requestId = require_universal_constants.isBun ? Bun.randomUUIDv7 : typeof crypto !== "undefined" ? crypto.randomUUIDv7?.bind(crypto) ?? crypto.randomUUID?.bind(crypto) ?? fallbackRequestId : fallbackRequestId;
|
|
632
|
+
/**
|
|
633
|
+
* Offset of the first byte after `://`, so the authority is never scanned as
|
|
634
|
+
* path. A fixed offset would let the client-supplied `Host` decide how many
|
|
635
|
+
* leading path bytes are dropped
|
|
636
|
+
*/
|
|
637
|
+
function authorityEnd(url) {
|
|
638
|
+
return url.charCodeAt(4) === 58 ? 7 : url.charCodeAt(5) === 58 ? 8 : url.indexOf("://") + 3;
|
|
639
|
+
}
|
|
629
640
|
function replaceUrlPath(url, path) {
|
|
630
|
-
const i = url.indexOf("/",
|
|
641
|
+
const i = url.indexOf("/", authorityEnd(url));
|
|
631
642
|
const qs = url.indexOf("?", i);
|
|
632
643
|
return `${url.slice(0, i)}${path.charCodeAt(0) === 47 ? "" : "/"}${path}${qs === -1 ? "" : url.slice(qs)}`;
|
|
633
644
|
}
|
|
@@ -682,6 +693,8 @@ function serializeMacroSeed(_key, value) {
|
|
|
682
693
|
|
|
683
694
|
//#endregion
|
|
684
695
|
exports.ELYSIA_FORM_PROTOTYPE = ELYSIA_FORM_PROTOTYPE;
|
|
696
|
+
exports.assignOwn = assignOwn;
|
|
697
|
+
exports.authorityEnd = authorityEnd;
|
|
685
698
|
exports.bytes = bytes;
|
|
686
699
|
exports.clearFlattenChainMemo = clearFlattenChainMemo;
|
|
687
700
|
exports.cloneHook = cloneHook;
|
|
@@ -695,6 +708,7 @@ exports.createErrorEventHandler = createErrorEventHandler;
|
|
|
695
708
|
exports.deriveEntryFn = deriveEntryFn;
|
|
696
709
|
exports.eventProperties = eventProperties;
|
|
697
710
|
exports.evictOldestHalf = evictOldestHalf;
|
|
711
|
+
exports.fallbackRequestId = fallbackRequestId;
|
|
698
712
|
exports.flattenChain = flattenChain;
|
|
699
713
|
exports.flattenChainMemo = flattenChainMemo;
|
|
700
714
|
exports.flattenChainMemoReadonly = flattenChainMemoReadonly;
|
|
@@ -731,4 +745,5 @@ exports.replaceUrlPath = replaceUrlPath;
|
|
|
731
745
|
exports.requestId = requestId;
|
|
732
746
|
exports.schemaProperties = schemaProperties;
|
|
733
747
|
exports.serializeMacroSeed = serializeMacroSeed;
|
|
734
|
-
exports.sse = sse;
|
|
748
|
+
exports.sse = sse;
|
|
749
|
+
exports.sseData = sseData;
|
package/dist/utils.mjs
CHANGED
|
@@ -286,6 +286,7 @@ function formToFormData(value) {
|
|
|
286
286
|
* ```
|
|
287
287
|
*/
|
|
288
288
|
const form = (value) => Object.setPrototypeOf({ ...value }, ELYSIA_FORM_PROTOTYPE);
|
|
289
|
+
const assignOwn = (target, source) => source != null && Object.hasOwn(source, "__proto__") ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : Object.assign(target, source);
|
|
289
290
|
const getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, -1) : path + "/";
|
|
290
291
|
const byteStreams = /* @__PURE__ */ new WeakSet();
|
|
291
292
|
/**
|
|
@@ -624,9 +625,19 @@ function pushField(target, key, item, defaultArray = false) {
|
|
|
624
625
|
else target[key] = [v, item];
|
|
625
626
|
else target[key] = defaultArray ? [item] : item;
|
|
626
627
|
}
|
|
627
|
-
|
|
628
|
+
let fallbackRequestIdCounter = 0;
|
|
629
|
+
const fallbackRequestId = () => Date.now().toString(36) + "-" + (++fallbackRequestIdCounter).toString(36);
|
|
630
|
+
const requestId = isBun ? Bun.randomUUIDv7 : typeof crypto !== "undefined" ? crypto.randomUUIDv7?.bind(crypto) ?? crypto.randomUUID?.bind(crypto) ?? fallbackRequestId : fallbackRequestId;
|
|
631
|
+
/**
|
|
632
|
+
* Offset of the first byte after `://`, so the authority is never scanned as
|
|
633
|
+
* path. A fixed offset would let the client-supplied `Host` decide how many
|
|
634
|
+
* leading path bytes are dropped
|
|
635
|
+
*/
|
|
636
|
+
function authorityEnd(url) {
|
|
637
|
+
return url.charCodeAt(4) === 58 ? 7 : url.charCodeAt(5) === 58 ? 8 : url.indexOf("://") + 3;
|
|
638
|
+
}
|
|
628
639
|
function replaceUrlPath(url, path) {
|
|
629
|
-
const i = url.indexOf("/",
|
|
640
|
+
const i = url.indexOf("/", authorityEnd(url));
|
|
630
641
|
const qs = url.indexOf("?", i);
|
|
631
642
|
return `${url.slice(0, i)}${path.charCodeAt(0) === 47 ? "" : "/"}${path}${qs === -1 ? "" : url.slice(qs)}`;
|
|
632
643
|
}
|
|
@@ -680,4 +691,4 @@ function serializeMacroSeed(_key, value) {
|
|
|
680
691
|
}
|
|
681
692
|
|
|
682
693
|
//#endregion
|
|
683
|
-
export { ELYSIA_FORM_PROTOTYPE, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, constantTimeEqual, createErrorEventHandler, deriveEntryFn, eventProperties, evictOldestHalf, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isElysiaForm, isEmpty, isLocalScope, isMapDeriveEntry, isNotEmpty, isRecordNumber, joinPath, macroEpoch, macroOrigin, mapDeriveEntry, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, prefix, pushField, redirect, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse };
|
|
694
|
+
export { ELYSIA_FORM_PROTOTYPE, assignOwn, authorityEnd, bytes, clearFlattenChainMemo, cloneHook, clonePlainDecorators, clonePlainDeep, coalesceSchemas, compactBeforeHandleConflicts, compactBeforeHandlePrefix, constantTimeEqual, createErrorEventHandler, deriveEntryFn, eventProperties, evictOldestHalf, fallbackRequestId, flattenChain, flattenChainMemo, flattenChainMemoReadonly, fnOrigin, fnv1a, form, formToFormData, getLoosePath, guardNonPlainLeaves, hookToGuard, invalidateMacroEpoch, isBlob, isByteStream, isCompactBeforeHandleOnly, isElysiaForm, isEmpty, isLocalScope, isMapDeriveEntry, isNotEmpty, isRecordNumber, joinPath, macroEpoch, macroOrigin, mapDeriveEntry, mergeArray, mergeDeep, mergeHook, mergeResponse, nullObject, prefix, pushField, redirect, replaceUrlPath, requestId, schemaProperties, serializeMacroSeed, sse, sseData };
|
package/dist/validator/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_utils = require('../utils.js');
|
|
2
3
|
const require_type_bridge = require('../type/bridge.js');
|
|
3
4
|
const require_error = require('../error.js');
|
|
4
5
|
const require_compile_aot = require('../compile/aot.js');
|
|
@@ -205,7 +206,7 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
205
206
|
snapshot.push(...result);
|
|
206
207
|
return snapshot;
|
|
207
208
|
}
|
|
208
|
-
if (typeof snapshot === "object" && typeof result === "object") return
|
|
209
|
+
if (typeof snapshot === "object" && typeof result === "object") return require_utils.assignOwn(snapshot, result);
|
|
209
210
|
throw new Error("Unable to merged value with different type");
|
|
210
211
|
}
|
|
211
212
|
static #syncStandard(schema, value) {
|
package/dist/validator/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignOwn } from "../utils.mjs";
|
|
1
2
|
import { Clone, Compile, Default, HasCodec, Intersect, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions } from "../type/bridge.mjs";
|
|
2
3
|
import { ValidationError } from "../error.mjs";
|
|
3
4
|
import { Capture, Compiled } from "../compile/aot.mjs";
|
|
@@ -204,7 +205,7 @@ var MultiValidator = class MultiValidator extends Validator {
|
|
|
204
205
|
snapshot.push(...result);
|
|
205
206
|
return snapshot;
|
|
206
207
|
}
|
|
207
|
-
if (typeof snapshot === "object" && typeof result === "object") return
|
|
208
|
+
if (typeof snapshot === "object" && typeof result === "object") return assignOwn(snapshot, result);
|
|
208
209
|
throw new Error("Unable to merged value with different type");
|
|
209
210
|
}
|
|
210
211
|
static #syncStandard(schema, value) {
|
package/dist/ws/context.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ interface WSConnectionData {
|
|
|
11
11
|
ping?: (elysia: ElysiaWS<any>, data: Buffer) => void | Promise<void>;
|
|
12
12
|
pong?: (elysia: ElysiaWS<any>, data: Buffer) => void | Promise<void>;
|
|
13
13
|
closeHandlerInvoked?: boolean;
|
|
14
|
+
/** in-flight `message` handlers, bounded by `MAX_INFLIGHT_MESSAGES` */
|
|
15
|
+
inflight?: number;
|
|
16
|
+
/** settles when an async `open` hook finished; dispatch chains onto it */
|
|
17
|
+
opening?: Promise<void>;
|
|
14
18
|
elysia?: ElysiaWS<any>;
|
|
15
19
|
context?: Record<string, unknown>;
|
|
16
20
|
resumeWaiters?: Set<() => void>;
|