elysia 2.0.0-beta.13 → 2.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/adapter/bun/index.d.ts +4 -2
  2. package/dist/adapter/bun/index.js +35 -38
  3. package/dist/adapter/bun/index.mjs +35 -39
  4. package/dist/adapter/utils.js +16 -21
  5. package/dist/adapter/utils.mjs +16 -21
  6. package/dist/base.d.ts +28 -0
  7. package/dist/base.js +109 -59
  8. package/dist/base.mjs +110 -60
  9. package/dist/compile/aot.js +14 -21
  10. package/dist/compile/aot.mjs +14 -21
  11. package/dist/compile/handler/frozen-validator.js +51 -42
  12. package/dist/compile/handler/frozen-validator.mjs +51 -42
  13. package/dist/compile/handler/index.js +57 -50
  14. package/dist/compile/handler/index.mjs +57 -50
  15. package/dist/compile/handler/jit.js +36 -26
  16. package/dist/compile/handler/jit.mjs +37 -27
  17. package/dist/compile/handler/params.js +2 -0
  18. package/dist/compile/handler/params.mjs +3 -1
  19. package/dist/compile/handler/utils.d.ts +2 -2
  20. package/dist/compile/handler/utils.js +115 -111
  21. package/dist/compile/handler/utils.mjs +115 -113
  22. package/dist/context.d.ts +3 -1
  23. package/dist/context.js +2 -0
  24. package/dist/context.mjs +3 -1
  25. package/dist/cookie/config.js +6 -7
  26. package/dist/cookie/config.mjs +6 -7
  27. package/dist/error.d.ts +6 -3
  28. package/dist/error.js +26 -28
  29. package/dist/error.mjs +26 -28
  30. package/dist/handler/fetch.js +2 -1
  31. package/dist/handler/fetch.mjs +3 -2
  32. package/dist/handler/utils.d.ts +3 -1
  33. package/dist/handler/utils.js +19 -1
  34. package/dist/handler/utils.mjs +17 -1
  35. package/dist/index.d.ts +3 -3
  36. package/dist/package.js +1 -1
  37. package/dist/package.mjs +1 -1
  38. package/dist/plugin/aot/core.js +4 -0
  39. package/dist/plugin/aot/core.mjs +4 -0
  40. package/dist/sucrose.js +60 -59
  41. package/dist/sucrose.mjs +60 -59
  42. package/dist/trace.js +6 -9
  43. package/dist/trace.mjs +6 -9
  44. package/dist/type/coerce-plan.js +41 -36
  45. package/dist/type/coerce-plan.mjs +41 -36
  46. package/dist/type/coerce.d.ts +1 -1
  47. package/dist/type/constants.d.ts +1 -1
  48. package/dist/type/elysia/cookie.js +8 -17
  49. package/dist/type/elysia/cookie.mjs +8 -17
  50. package/dist/type/elysia/date.js +6 -7
  51. package/dist/type/elysia/date.mjs +6 -7
  52. package/dist/type/elysia/numeric.js +8 -9
  53. package/dist/type/elysia/numeric.mjs +8 -9
  54. package/dist/type/elysia/problem.d.ts +20 -0
  55. package/dist/type/elysia/problem.js +25 -0
  56. package/dist/type/elysia/problem.mjs +24 -0
  57. package/dist/type/exports.d.ts +3 -2
  58. package/dist/type/exports.js +2 -0
  59. package/dist/type/exports.mjs +2 -1
  60. package/dist/type/index.js +2 -0
  61. package/dist/type/index.mjs +2 -0
  62. package/dist/type/validator/clean-safe.d.ts +1 -2
  63. package/dist/type/validator/clean-safe.js +0 -2
  64. package/dist/type/validator/clean-safe.mjs +1 -2
  65. package/dist/type/validator/custom-error.js +37 -26
  66. package/dist/type/validator/custom-error.mjs +37 -26
  67. package/dist/type/validator/default-precompute.js +24 -26
  68. package/dist/type/validator/default-precompute.mjs +24 -26
  69. package/dist/type/validator/exact-mirror.js +6 -8
  70. package/dist/type/validator/exact-mirror.mjs +6 -8
  71. package/dist/type/validator/index.js +64 -66
  72. package/dist/type/validator/index.mjs +65 -67
  73. package/dist/type/validator/validator-cache.d.ts +2 -2
  74. package/dist/type/validator/validator-cache.js +7 -10
  75. package/dist/type/validator/validator-cache.mjs +6 -9
  76. package/dist/types.d.ts +4 -3
  77. package/dist/universal/file.js +2 -6
  78. package/dist/universal/file.mjs +2 -6
  79. package/dist/utils.d.ts +11 -2
  80. package/dist/utils.js +85 -47
  81. package/dist/utils.mjs +82 -48
  82. package/dist/validator/index.js +14 -18
  83. package/dist/validator/index.mjs +14 -18
  84. package/dist/ws/context.js +9 -11
  85. package/dist/ws/context.mjs +9 -11
  86. package/dist/ws/parser.js +23 -20
  87. package/dist/ws/parser.mjs +23 -20
  88. package/dist/ws/route.js +76 -87
  89. package/dist/ws/route.mjs +76 -87
  90. package/package.json +5 -2
@@ -15,27 +15,18 @@ const COOKIE_OPTION_KEYS = [
15
15
  "sign",
16
16
  "legacySignature"
17
17
  ];
18
- function extractConfig(options) {
19
- if (!options) return {
20
- config: void 0,
21
- rest: void 0
22
- };
23
- let config;
18
+ const isSchema = (value) => !!value && typeof value === "object" && "~kind" in value;
19
+ function Cookie(first, options) {
20
+ const raw = options;
21
+ let configRaw;
24
22
  let rest;
25
- for (const key in options) {
26
- const value = options[key];
23
+ if (raw) for (const key in raw) {
24
+ const value = raw[key];
27
25
  if (value === void 0) continue;
28
- if (COOKIE_OPTION_KEYS.includes(key)) (config ??= {})[key] = value;
26
+ if (COOKIE_OPTION_KEYS.includes(key)) (configRaw ??= {})[key] = value;
29
27
  else (rest ??= {})[key] = value;
30
28
  }
31
- return {
32
- config,
33
- rest
34
- };
35
- }
36
- const isSchema = (value) => !!value && typeof value === "object" && "~kind" in value;
37
- function Cookie(first, options) {
38
- const { config, rest } = extractConfig(options);
29
+ const config = configRaw;
39
30
  if (isSchema(first)) {
40
31
  if (!config) return first;
41
32
  const target = Object.create(Object.getPrototypeOf(first), Object.getOwnPropertyDescriptors(first));
@@ -10,12 +10,6 @@ const require_type_elysia_number = require('./number.js');
10
10
  //#region src/type/elysia/date.ts
11
11
  const ISO8601 = /T\d\d(?::\d\d){1,2} \d\d:\d\d$/;
12
12
  const removeTime = / (\d{2}:\d{2})$/;
13
- const toTimestamp = (value) => {
14
- if (value instanceof Date) return value.getTime();
15
- let t = new Date(value).getTime();
16
- if (isNaN(t) && typeof value === "string" && /T\d{2}:\d{2}(:\d{2})? \d{2}:\d{2}$/.test(value)) t = new Date(value.replace(/ (\d{2}:\d{2})$/, "+$1")).getTime();
17
- return t;
18
- };
19
13
  let StringifiedDate;
20
14
  let emptyDate;
21
15
  let sharedDate;
@@ -57,7 +51,12 @@ function DateWithProperty(options) {
57
51
  if (minMessage || maxMessage || xMinMessage || xMaxMessage || stepMessage) {
58
52
  let failed = "must be Date";
59
53
  schema = require_type_typebox_type.Refine(schema, (value) => {
60
- const t = toTimestamp(value);
54
+ let t;
55
+ if (value instanceof Date) t = value.getTime();
56
+ else {
57
+ t = new Date(value).getTime();
58
+ if (isNaN(t) && typeof value === "string" && /T\d{2}:\d{2}(:\d{2})? \d{2}:\d{2}$/.test(value)) t = new Date(value.replace(/ (\d{2}:\d{2})$/, "+$1")).getTime();
59
+ }
61
60
  if (minMessage && t < min) {
62
61
  failed = minMessage;
63
62
  return false;
@@ -9,12 +9,6 @@ import { NumberType } from "./number.mjs";
9
9
  //#region src/type/elysia/date.ts
10
10
  const ISO8601 = /T\d\d(?::\d\d){1,2} \d\d:\d\d$/;
11
11
  const removeTime = / (\d{2}:\d{2})$/;
12
- const toTimestamp = (value) => {
13
- if (value instanceof Date) return value.getTime();
14
- let t = new Date(value).getTime();
15
- if (isNaN(t) && typeof value === "string" && /T\d{2}:\d{2}(:\d{2})? \d{2}:\d{2}$/.test(value)) t = new Date(value.replace(/ (\d{2}:\d{2})$/, "+$1")).getTime();
16
- return t;
17
- };
18
12
  let StringifiedDate;
19
13
  let emptyDate;
20
14
  let sharedDate;
@@ -56,7 +50,12 @@ function DateWithProperty(options) {
56
50
  if (minMessage || maxMessage || xMinMessage || xMaxMessage || stepMessage) {
57
51
  let failed = "must be Date";
58
52
  schema = Refine(schema, (value) => {
59
- const t = toTimestamp(value);
53
+ let t;
54
+ if (value instanceof Date) t = value.getTime();
55
+ else {
56
+ t = new Date(value).getTime();
57
+ if (isNaN(t) && typeof value === "string" && /T\d{2}:\d{2}(:\d{2})? \d{2}:\d{2}$/.test(value)) t = new Date(value.replace(/ (\d{2}:\d{2})$/, "+$1")).getTime();
58
+ }
60
59
  if (minMessage && t < min) {
61
60
  failed = minMessage;
62
61
  return false;
@@ -37,14 +37,6 @@ function isDecimalString(value) {
37
37
  }
38
38
  let StringifiedNumber;
39
39
  let emptyNumeric;
40
- function passesConstraints(n, c) {
41
- if (typeof c.minimum === "number" && n < c.minimum) return false;
42
- if (typeof c.maximum === "number" && n > c.maximum) return false;
43
- if (typeof c.exclusiveMinimum === "number" && n <= c.exclusiveMinimum) return false;
44
- if (typeof c.exclusiveMaximum === "number" && n >= c.exclusiveMaximum) return false;
45
- if (typeof c.multipleOf === "number" && n % c.multipleOf !== 0) return false;
46
- return true;
47
- }
48
40
  function Numeric(property) {
49
41
  StringifiedNumber ??= require_type_shared.pureRefine(require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), isDecimalString, () => "must be number"), (value) => +value));
50
42
  if (!property || require_utils.isEmpty(property)) return emptyNumeric ??= Object.freeze(require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.Numeric, require_type_elysia_union.Union([require_type_elysia_number.NumberType(), StringifiedNumber])));
@@ -52,7 +44,14 @@ function Numeric(property) {
52
44
  const number = require_type_elysia_number.NumberType(constraints);
53
45
  const stringified = require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), (value) => {
54
46
  if (!isDecimalString(value)) return false;
55
- return passesConstraints(+value, constraints);
47
+ const n = +value;
48
+ const c = constraints;
49
+ if (typeof c.minimum === "number" && n < c.minimum) return false;
50
+ if (typeof c.maximum === "number" && n > c.maximum) return false;
51
+ if (typeof c.exclusiveMinimum === "number" && n <= c.exclusiveMinimum) return false;
52
+ if (typeof c.exclusiveMaximum === "number" && n >= c.exclusiveMaximum) return false;
53
+ if (typeof c.multipleOf === "number" && n % c.multipleOf !== 0) return false;
54
+ return true;
56
55
  }, () => "must be number"), (value) => +value);
57
56
  require_type_shared.pureRefine(stringified);
58
57
  return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.Numeric, require_type_elysia_union.Union([number, stringified], meta));
@@ -36,14 +36,6 @@ function isDecimalString(value) {
36
36
  }
37
37
  let StringifiedNumber;
38
38
  let emptyNumeric;
39
- function passesConstraints(n, c) {
40
- if (typeof c.minimum === "number" && n < c.minimum) return false;
41
- if (typeof c.maximum === "number" && n > c.maximum) return false;
42
- if (typeof c.exclusiveMinimum === "number" && n <= c.exclusiveMinimum) return false;
43
- if (typeof c.exclusiveMaximum === "number" && n >= c.exclusiveMaximum) return false;
44
- if (typeof c.multipleOf === "number" && n % c.multipleOf !== 0) return false;
45
- return true;
46
- }
47
39
  function Numeric(property) {
48
40
  StringifiedNumber ??= pureRefine(Decode(Refine(StringType(), isDecimalString, () => "must be number"), (value) => +value));
49
41
  if (!property || isEmpty(property)) return emptyNumeric ??= Object.freeze(elyType(ELYSIA_TYPES.Numeric, Union([NumberType(), StringifiedNumber])));
@@ -51,7 +43,14 @@ function Numeric(property) {
51
43
  const number = NumberType(constraints);
52
44
  const stringified = Decode(Refine(StringType(), (value) => {
53
45
  if (!isDecimalString(value)) return false;
54
- return passesConstraints(+value, constraints);
46
+ const n = +value;
47
+ const c = constraints;
48
+ if (typeof c.minimum === "number" && n < c.minimum) return false;
49
+ if (typeof c.maximum === "number" && n > c.maximum) return false;
50
+ if (typeof c.exclusiveMinimum === "number" && n <= c.exclusiveMinimum) return false;
51
+ if (typeof c.exclusiveMaximum === "number" && n >= c.exclusiveMaximum) return false;
52
+ if (typeof c.multipleOf === "number" && n % c.multipleOf !== 0) return false;
53
+ return true;
55
54
  }, () => "must be number"), (value) => +value);
56
55
  pureRefine(stringified);
57
56
  return elyType(ELYSIA_TYPES.Numeric, Union([number, stringified], meta));
@@ -0,0 +1,20 @@
1
+ import { TInteger, TObject, TObjectOptions, TOptional, TProperties, TString } from "typebox";
2
+
3
+ //#region src/type/elysia/problem.d.ts
4
+ interface TProblemBase {
5
+ type: TString;
6
+ code: TOptional<TString>;
7
+ title: TString;
8
+ status: TInteger;
9
+ detail: TOptional<TString>;
10
+ instance: TOptional<TString>;
11
+ }
12
+ /**
13
+ * RFC 9457 Problem Details schema. Extension members are spread last, so they
14
+ * may override a base member.
15
+ *
16
+ * @see https://www.rfc-editor.org/info/rfc9457
17
+ */
18
+ declare const Problem: <T extends TProperties = {}>(extension?: T, options?: TObjectOptions) => TObject<Omit<TProblemBase, keyof T> & T>;
19
+ //#endregion
20
+ export { Problem };
@@ -0,0 +1,25 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_type_elysia_string = require('./string.js');
3
+ const require_type_elysia_object = require('./object.js');
4
+ const require_type_elysia_integer = require('./integer.js');
5
+ const require_type_elysia_optional = require('./optional.js');
6
+
7
+ //#region src/type/elysia/problem.ts
8
+ /**
9
+ * RFC 9457 Problem Details schema. Extension members are spread last, so they
10
+ * may override a base member.
11
+ *
12
+ * @see https://www.rfc-editor.org/info/rfc9457
13
+ */
14
+ const Problem = (extension, options) => require_type_elysia_object.ObjectType({
15
+ type: require_type_elysia_string.StringType(),
16
+ code: require_type_elysia_optional.Optional(require_type_elysia_string.StringType()),
17
+ title: require_type_elysia_string.StringType(),
18
+ status: require_type_elysia_integer.Integer(),
19
+ detail: require_type_elysia_optional.Optional(require_type_elysia_string.StringType()),
20
+ instance: require_type_elysia_optional.Optional(require_type_elysia_string.StringType()),
21
+ ...extension
22
+ }, options);
23
+
24
+ //#endregion
25
+ exports.Problem = Problem;
@@ -0,0 +1,24 @@
1
+ import { StringType } from "./string.mjs";
2
+ import { ObjectType } from "./object.mjs";
3
+ import { Integer } from "./integer.mjs";
4
+ import { Optional } from "./optional.mjs";
5
+
6
+ //#region src/type/elysia/problem.ts
7
+ /**
8
+ * RFC 9457 Problem Details schema. Extension members are spread last, so they
9
+ * may override a base member.
10
+ *
11
+ * @see https://www.rfc-editor.org/info/rfc9457
12
+ */
13
+ const Problem = (extension, options) => ObjectType({
14
+ type: StringType(),
15
+ code: Optional(StringType()),
16
+ title: StringType(),
17
+ status: Integer(),
18
+ detail: Optional(StringType()),
19
+ instance: Optional(StringType()),
20
+ ...extension
21
+ }, options);
22
+
23
+ //#endregion
24
+ export { Problem };
@@ -21,6 +21,7 @@ import { NumericEnum } from "./elysia/numeric-enum.js";
21
21
  import { ObjectType } from "./elysia/object.js";
22
22
  import { ObjectString } from "./elysia/object-string.js";
23
23
  import { Optional } from "./elysia/optional.js";
24
+ import { Problem } from "./elysia/problem.js";
24
25
  import { StringType } from "./elysia/string.js";
25
26
  import { Uint8ArrayType } from "./elysia/uint8-array.js";
26
27
  import { Union } from "./elysia/union.js";
@@ -29,8 +30,8 @@ export * from "typebox/type";
29
30
 
30
31
  //#region src/type/exports.d.ts
31
32
  declare namespace exports_d_exports {
32
- export { Accelerate, ArrayType as Array, ArrayBufferType as ArrayBuffer, ArrayString, BooleanType as Boolean, BooleanString, Cookie, DateType as Date, File, Files, Form, Integer, IntegerString, Intersect, MaybeEmpty, NoValidate, Nullable, NumberType as Number, Numeric, NumericEnum, ObjectType as Object, ObjectString, Optional, StringType as String, Uint8ArrayType as Uint8Array, Union, UnionEnum };
33
+ export { Accelerate, ArrayType as Array, ArrayBufferType as ArrayBuffer, ArrayString, BooleanType as Boolean, BooleanString, Cookie, DateType as Date, File, Files, Form, Integer, IntegerString, Intersect, MaybeEmpty, NoValidate, Nullable, NumberType as Number, Numeric, NumericEnum, ObjectType as Object, ObjectString, Optional, Problem, StringType as String, Uint8ArrayType as Uint8Array, Union, UnionEnum };
33
34
  }
34
35
  import * as import_typebox_type from "typebox/type";
35
36
  //#endregion
36
- export { Accelerate, ArrayType as Array, ArrayBufferType as ArrayBuffer, ArrayString, BooleanType as Boolean, BooleanString, Cookie, DateType as Date, File, Files, Form, Integer, IntegerString, Intersect, MaybeEmpty, NoValidate, Nullable, NumberType as Number, Numeric, NumericEnum, ObjectType as Object, ObjectString, Optional, StringType as String, Uint8ArrayType as Uint8Array, Union, UnionEnum, exports_d_exports };
37
+ export { Accelerate, ArrayType as Array, ArrayBufferType as ArrayBuffer, ArrayString, BooleanType as Boolean, BooleanString, Cookie, DateType as Date, File, Files, Form, Integer, IntegerString, Intersect, MaybeEmpty, NoValidate, Nullable, NumberType as Number, Numeric, NumericEnum, ObjectType as Object, ObjectString, Optional, Problem, StringType as String, Uint8ArrayType as Uint8Array, Union, UnionEnum, exports_d_exports };
@@ -27,6 +27,7 @@ const require_type_elysia_no_validate = require('./elysia/no-validate.js');
27
27
  const require_type_elysia_nullable = require('./elysia/nullable.js');
28
28
  const require_type_elysia_numeric_enum = require('./elysia/numeric-enum.js');
29
29
  const require_type_elysia_optional = require('./elysia/optional.js');
30
+ const require_type_elysia_problem = require('./elysia/problem.js');
30
31
  const require_type_elysia_uint8_array = require('./elysia/uint8-array.js');
31
32
  const require_type_elysia_union_enum = require('./elysia/union-enum.js');
32
33
  let typebox_type = require("typebox/type");
@@ -65,6 +66,7 @@ exports.NumericEnum = require_type_elysia_numeric_enum.NumericEnum;
65
66
  exports.Object = require_type_elysia_object.ObjectType;
66
67
  exports.ObjectString = require_type_elysia_object_string.ObjectString;
67
68
  exports.Optional = require_type_elysia_optional.Optional;
69
+ exports.Problem = require_type_elysia_problem.Problem;
68
70
  exports.String = require_type_elysia_string.StringType;
69
71
  exports.Uint8Array = require_type_elysia_uint8_array.Uint8ArrayType;
70
72
  exports.Union = require_type_elysia_union.Union;
@@ -25,6 +25,7 @@ import { NoValidate } from "./elysia/no-validate.mjs";
25
25
  import { Nullable } from "./elysia/nullable.mjs";
26
26
  import { NumericEnum } from "./elysia/numeric-enum.mjs";
27
27
  import { Optional } from "./elysia/optional.mjs";
28
+ import { Problem } from "./elysia/problem.mjs";
28
29
  import { Uint8ArrayType } from "./elysia/uint8-array.mjs";
29
30
  import { UnionEnum } from "./elysia/union-enum.mjs";
30
31
  import * as type from "typebox/type";
@@ -40,4 +41,4 @@ injectTypeboxType({
40
41
  setupTypebox();
41
42
 
42
43
  //#endregion
43
- export { Accelerate, ArrayType as Array, ArrayBufferType as ArrayBuffer, ArrayString, BooleanType as Boolean, BooleanString, Cookie, DateType as Date, File, Files, Form, Integer, IntegerString, Intersect, MaybeEmpty, NoValidate, Nullable, NumberType as Number, Numeric, NumericEnum, ObjectType as Object, ObjectString, Optional, StringType as String, Uint8ArrayType as Uint8Array, Union, UnionEnum };
44
+ export { Accelerate, ArrayType as Array, ArrayBufferType as ArrayBuffer, ArrayString, BooleanType as Boolean, BooleanString, Cookie, DateType as Date, File, Files, Form, Integer, IntegerString, Intersect, MaybeEmpty, NoValidate, Nullable, NumberType as Number, Numeric, NumericEnum, ObjectType as Object, ObjectString, Optional, Problem, StringType as String, Uint8ArrayType as Uint8Array, Union, UnionEnum };
@@ -28,6 +28,7 @@ const require_type_elysia_no_validate = require('./elysia/no-validate.js');
28
28
  const require_type_elysia_nullable = require('./elysia/nullable.js');
29
29
  const require_type_elysia_numeric_enum = require('./elysia/numeric-enum.js');
30
30
  const require_type_elysia_optional = require('./elysia/optional.js');
31
+ const require_type_elysia_problem = require('./elysia/problem.js');
31
32
  const require_type_elysia_uint8_array = require('./elysia/uint8-array.js');
32
33
  const require_type_elysia_union_enum = require('./elysia/union-enum.js');
33
34
 
@@ -86,6 +87,7 @@ const t = lazyNamespace(() => require_type_typebox_type.loadTypeNamespace().type
86
87
  Object: require_type_elysia_object.ObjectType,
87
88
  ObjectString: require_type_elysia_object_string.ObjectString,
88
89
  Optional: require_type_elysia_optional.Optional,
90
+ Problem: require_type_elysia_problem.Problem,
89
91
  String: require_type_elysia_string.StringType,
90
92
  Uint8Array: require_type_elysia_uint8_array.Uint8ArrayType,
91
93
  Union: require_type_elysia_union.Union,
@@ -27,6 +27,7 @@ import { NoValidate } from "./elysia/no-validate.mjs";
27
27
  import { Nullable } from "./elysia/nullable.mjs";
28
28
  import { NumericEnum } from "./elysia/numeric-enum.mjs";
29
29
  import { Optional } from "./elysia/optional.mjs";
30
+ import { Problem } from "./elysia/problem.mjs";
30
31
  import { Uint8ArrayType } from "./elysia/uint8-array.mjs";
31
32
  import { UnionEnum } from "./elysia/union-enum.mjs";
32
33
 
@@ -85,6 +86,7 @@ const t = lazyNamespace(() => loadTypeNamespace().type, {
85
86
  Object: ObjectType,
86
87
  ObjectString,
87
88
  Optional,
89
+ Problem,
88
90
  String: StringType,
89
91
  Uint8Array: Uint8ArrayType,
90
92
  Union,
@@ -1,8 +1,7 @@
1
1
  //#region src/type/validator/clean-safe.d.ts
2
2
  declare function schemaSome(schema: any, test: (node: any) => boolean, seen?: WeakSet<object>, prune?: (node: any) => boolean): boolean;
3
3
  declare const schemaHasDangerousProperties: (schema: any) => boolean;
4
- declare const schemaContainsRef: (node: any, seen?: WeakSet<WeakKey>) => boolean;
5
4
  declare function isCleanSafeNode(node: any, visiting: WeakSet<object>, clean: WeakSet<object>): boolean;
6
5
  declare function isFullyClosedObject(schema: any): boolean;
7
6
  //#endregion
8
- export { isCleanSafeNode, isFullyClosedObject, schemaContainsRef, schemaHasDangerousProperties, schemaSome };
7
+ export { isCleanSafeNode, isFullyClosedObject, schemaHasDangerousProperties, schemaSome };
@@ -39,7 +39,6 @@ const schemaHasDangerousProperties = (schema) => schemaSome(schema, (node) => {
39
39
  for (const key of require_constants.dangerousKeys) if (Object.hasOwn(properties, key)) return true;
40
40
  return false;
41
41
  });
42
- const schemaContainsRef = (node, seen = /* @__PURE__ */ new WeakSet()) => schemaSome(node, (n) => !!n.$ref, seen);
43
42
  function isCleanSafeNode(node, visiting, clean) {
44
43
  if (!node || typeof node !== "object") return true;
45
44
  if (clean.has(node)) return true;
@@ -77,6 +76,5 @@ function isFullyClosedObject(schema) {
77
76
  //#endregion
78
77
  exports.isCleanSafeNode = isCleanSafeNode;
79
78
  exports.isFullyClosedObject = isFullyClosedObject;
80
- exports.schemaContainsRef = schemaContainsRef;
81
79
  exports.schemaHasDangerousProperties = schemaHasDangerousProperties;
82
80
  exports.schemaSome = schemaSome;
@@ -38,7 +38,6 @@ const schemaHasDangerousProperties = (schema) => schemaSome(schema, (node) => {
38
38
  for (const key of dangerousKeys) if (Object.hasOwn(properties, key)) return true;
39
39
  return false;
40
40
  });
41
- const schemaContainsRef = (node, seen = /* @__PURE__ */ new WeakSet()) => schemaSome(node, (n) => !!n.$ref, seen);
42
41
  function isCleanSafeNode(node, visiting, clean) {
43
42
  if (!node || typeof node !== "object") return true;
44
43
  if (clean.has(node)) return true;
@@ -74,4 +73,4 @@ function isFullyClosedObject(schema) {
74
73
  }
75
74
 
76
75
  //#endregion
77
- export { isCleanSafeNode, isFullyClosedObject, schemaContainsRef, schemaHasDangerousProperties, schemaSome };
76
+ export { isCleanSafeNode, isFullyClosedObject, schemaHasDangerousProperties, schemaSome };
@@ -49,31 +49,6 @@ const literalOf = (propSchema) => {
49
49
  if ("const" in propSchema) return { value: propSchema.const };
50
50
  if (Array.isArray(propSchema.enum) && propSchema.enum.length === 1) return { value: propSchema.enum[0] };
51
51
  };
52
- function computeDiscriminators(branches) {
53
- let candidates;
54
- for (const branch of branches) {
55
- if (!branch || !branch.properties) return;
56
- const keys = /* @__PURE__ */ new Set();
57
- for (const k in branch.properties) if (literalOf(branch.properties[k])) keys.add(k);
58
- if (!keys.size) return;
59
- if (!candidates) candidates = keys;
60
- else for (const c of [...candidates]) if (!keys.has(c)) candidates.delete(c);
61
- if (!candidates.size) return;
62
- }
63
- if (!candidates || !candidates.size) return;
64
- const perBranch = branches.map(require_utils.nullObject);
65
- let hasDisambiguating = false;
66
- for (const key of candidates) {
67
- const seenValues = [];
68
- for (let i = 0; i < branches.length; i++) {
69
- const lit = literalOf(branches[i].properties[key]);
70
- perBranch[i][key] = lit.value;
71
- seenValues.push(lit.value);
72
- }
73
- if (new Set(seenValues).size === branches.length) hasDisambiguating = true;
74
- }
75
- return hasDisambiguating ? perBranch : void 0;
76
- }
77
52
  function buildFindCustomError(schema, frozen) {
78
53
  const nodes = collectCustomErrorNodes(schema, [], [], /* @__PURE__ */ new WeakSet());
79
54
  if (!nodes.length) return;
@@ -94,7 +69,43 @@ function buildFindCustomError(schema, frozen) {
94
69
  };
95
70
  const discriminatorsOf = (node, branches) => {
96
71
  if (discriminatorCache.has(node)) return discriminatorCache.get(node) ?? void 0;
97
- const d = computeDiscriminators(branches) ?? null;
72
+ let discriminators;
73
+ let rejected = false;
74
+ let candidates;
75
+ for (const branch of branches) {
76
+ if (!branch || !branch.properties) {
77
+ rejected = true;
78
+ break;
79
+ }
80
+ const keys = /* @__PURE__ */ new Set();
81
+ for (const k in branch.properties) if (literalOf(branch.properties[k])) keys.add(k);
82
+ if (!keys.size) {
83
+ rejected = true;
84
+ break;
85
+ }
86
+ if (!candidates) candidates = keys;
87
+ else for (const c of [...candidates]) if (!keys.has(c)) candidates.delete(c);
88
+ if (!candidates.size) {
89
+ rejected = true;
90
+ break;
91
+ }
92
+ }
93
+ if (rejected || !candidates || !candidates.size) discriminators = void 0;
94
+ else {
95
+ const perBranch = branches.map(require_utils.nullObject);
96
+ let hasDisambiguating = false;
97
+ for (const key of candidates) {
98
+ const seenValues = [];
99
+ for (let i = 0; i < branches.length; i++) {
100
+ const lit = literalOf(branches[i].properties[key]);
101
+ perBranch[i][key] = lit.value;
102
+ seenValues.push(lit.value);
103
+ }
104
+ if (new Set(seenValues).size === branches.length) hasDisambiguating = true;
105
+ }
106
+ discriminators = hasDisambiguating ? perBranch : void 0;
107
+ }
108
+ const d = discriminators ?? null;
98
109
  discriminatorCache.set(node, d);
99
110
  return d ?? void 0;
100
111
  };
@@ -48,31 +48,6 @@ const literalOf = (propSchema) => {
48
48
  if ("const" in propSchema) return { value: propSchema.const };
49
49
  if (Array.isArray(propSchema.enum) && propSchema.enum.length === 1) return { value: propSchema.enum[0] };
50
50
  };
51
- function computeDiscriminators(branches) {
52
- let candidates;
53
- for (const branch of branches) {
54
- if (!branch || !branch.properties) return;
55
- const keys = /* @__PURE__ */ new Set();
56
- for (const k in branch.properties) if (literalOf(branch.properties[k])) keys.add(k);
57
- if (!keys.size) return;
58
- if (!candidates) candidates = keys;
59
- else for (const c of [...candidates]) if (!keys.has(c)) candidates.delete(c);
60
- if (!candidates.size) return;
61
- }
62
- if (!candidates || !candidates.size) return;
63
- const perBranch = branches.map(nullObject);
64
- let hasDisambiguating = false;
65
- for (const key of candidates) {
66
- const seenValues = [];
67
- for (let i = 0; i < branches.length; i++) {
68
- const lit = literalOf(branches[i].properties[key]);
69
- perBranch[i][key] = lit.value;
70
- seenValues.push(lit.value);
71
- }
72
- if (new Set(seenValues).size === branches.length) hasDisambiguating = true;
73
- }
74
- return hasDisambiguating ? perBranch : void 0;
75
- }
76
51
  function buildFindCustomError(schema, frozen) {
77
52
  const nodes = collectCustomErrorNodes(schema, [], [], /* @__PURE__ */ new WeakSet());
78
53
  if (!nodes.length) return;
@@ -93,7 +68,43 @@ function buildFindCustomError(schema, frozen) {
93
68
  };
94
69
  const discriminatorsOf = (node, branches) => {
95
70
  if (discriminatorCache.has(node)) return discriminatorCache.get(node) ?? void 0;
96
- const d = computeDiscriminators(branches) ?? null;
71
+ let discriminators;
72
+ let rejected = false;
73
+ let candidates;
74
+ for (const branch of branches) {
75
+ if (!branch || !branch.properties) {
76
+ rejected = true;
77
+ break;
78
+ }
79
+ const keys = /* @__PURE__ */ new Set();
80
+ for (const k in branch.properties) if (literalOf(branch.properties[k])) keys.add(k);
81
+ if (!keys.size) {
82
+ rejected = true;
83
+ break;
84
+ }
85
+ if (!candidates) candidates = keys;
86
+ else for (const c of [...candidates]) if (!keys.has(c)) candidates.delete(c);
87
+ if (!candidates.size) {
88
+ rejected = true;
89
+ break;
90
+ }
91
+ }
92
+ if (rejected || !candidates || !candidates.size) discriminators = void 0;
93
+ else {
94
+ const perBranch = branches.map(nullObject);
95
+ let hasDisambiguating = false;
96
+ for (const key of candidates) {
97
+ const seenValues = [];
98
+ for (let i = 0; i < branches.length; i++) {
99
+ const lit = literalOf(branches[i].properties[key]);
100
+ perBranch[i][key] = lit.value;
101
+ seenValues.push(lit.value);
102
+ }
103
+ if (new Set(seenValues).size === branches.length) hasDisambiguating = true;
104
+ }
105
+ discriminators = hasDisambiguating ? perBranch : void 0;
106
+ }
107
+ const d = discriminators ?? null;
97
108
  discriminatorCache.set(node, d);
98
109
  return d ?? void 0;
99
110
  };
@@ -110,20 +110,19 @@ function containsRefLike(node, seen = /* @__PURE__ */ new WeakSet()) {
110
110
  if (node.$ref !== void 0 || node["~kind"] === "Ref" || node["~kind"] === "This" || node["~kind"] === "Cyclic") return true;
111
111
  return childSchemaSome(node, (child) => containsRefLike(child, seen));
112
112
  }
113
- function hasDivergentDefaultBelow(node) {
114
- const ownKey = "default" in node ? canonical(node.default) : void 0;
115
- let bad = false;
116
- const visit = (n) => {
117
- if (!n || typeof n !== "object") return false;
118
- if ("default" in n && (ownKey === void 0 || canonical(n.default) !== ownKey)) return bad = true;
119
- return childSchemaSome(n, visit);
120
- };
121
- childSchemaSome(node, visit);
122
- return bad;
123
- }
124
113
  function structuralPreallocatable(schema, depth = 0) {
125
114
  if (!schema || typeof schema !== "object") return true;
126
- if (!((schema["~kind"] === "Object" || schema.type === "object") && !schema["~codec"] && !schema["~refine"] && !Array.isArray(schema.anyOf) && !Array.isArray(schema.allOf) && !Array.isArray(schema.oneOf) && schema.$ref === void 0 && schema.if === void 0 && schema.not === void 0)) return !hasDivergentDefaultBelow(schema);
115
+ if (!((schema["~kind"] === "Object" || schema.type === "object") && !schema["~codec"] && !schema["~refine"] && !Array.isArray(schema.anyOf) && !Array.isArray(schema.allOf) && !Array.isArray(schema.oneOf) && schema.$ref === void 0 && schema.if === void 0 && schema.not === void 0)) {
116
+ const ownKey = "default" in schema ? canonical(schema.default) : void 0;
117
+ let bad = false;
118
+ const visit = (n) => {
119
+ if (!n || typeof n !== "object") return false;
120
+ if ("default" in n && (ownKey === void 0 || canonical(n.default) !== ownKey)) return bad = true;
121
+ return childSchemaSome(n, visit);
122
+ };
123
+ childSchemaSome(schema, visit);
124
+ return !bad;
125
+ }
127
126
  if (depth > 0 && schema.default === void 0 && hasDefaultBelow(schema)) return false;
128
127
  if (typeof schema.additionalProperties === "object" && subtreeHasDefault(schema.additionalProperties)) return false;
129
128
  if (schema.patternProperties) {
@@ -296,10 +295,6 @@ function mergeCategory(node) {
296
295
  if ((kind === "Array" || node.type === "array") && node.items) return !Array.isArray(node.items) && subtreeHasDefault(node.items) ? "array" : "identity";
297
296
  return "identity";
298
297
  }
299
- function presentExpr(child, isObject, varName) {
300
- if (child === "") return varName;
301
- return isObject ? `(${varName}!==null&&typeof ${varName}==='object'&&!Array.isArray(${varName})?${child}(${varName}):${varName})` : `(Array.isArray(${varName})?${child}(${varName}):${varName})`;
302
- }
303
298
  function mergeExpression(schema, varName, helpers, memo) {
304
299
  const full = require_type_typebox_value.Default(schema, void 0);
305
300
  const child = emitMerger(schema, helpers, memo);
@@ -307,9 +302,13 @@ function mergeExpression(schema, varName, helpers, memo) {
307
302
  const absent = full === void 0 ? void 0 : cloneExpression(full);
308
303
  if (full !== void 0 && absent === void 0) return;
309
304
  const isObject = mergeCategory(schema) === "object";
305
+ let present;
306
+ if (child === "") present = varName;
307
+ else if (isObject) present = `(${varName}!==null&&typeof ${varName}==='object'&&!Array.isArray(${varName})?${child}(${varName}):${varName})`;
308
+ else present = `(Array.isArray(${varName})?${child}(${varName}):${varName})`;
310
309
  return {
311
310
  absent,
312
- present: presentExpr(child, isObject, varName),
311
+ present,
313
312
  child,
314
313
  isObject
315
314
  };
@@ -375,14 +374,6 @@ function emitMerger(node, helpers, memo = /* @__PURE__ */ new WeakMap()) {
375
374
  helpers[+name.slice(2)] = `function ${name}(v){if(!Array.isArray(v))return v;const o=new Array(v.length);let e;for(let i=0;i<v.length;i++){e=v[i];o[i]=${assign}}return o}`;
376
375
  return name;
377
376
  }
378
- function buildMergeSource(schema) {
379
- const category = mergeCategory(schema);
380
- if (category !== "object" && category !== "array") return;
381
- const helpers = [];
382
- const root = emitMerger(schema, helpers, /* @__PURE__ */ new WeakMap());
383
- if (!root) return;
384
- return `(function(){${helpers.join(";")};return ${root}})()`;
385
- }
386
377
  let probeImpl;
387
378
  function setDefaultProbeImpl(impl) {
388
379
  probeImpl = impl;
@@ -414,7 +405,14 @@ function verifyPreallocatableDefault(schema, validate = true) {
414
405
  if (containsRefLike(schema)) return;
415
406
  if (!isEmittable(pd, /* @__PURE__ */ new Set(), true) || pod !== void 0 && !isEmittable(pod, /* @__PURE__ */ new Set(), true)) return;
416
407
  const nullDefault = isPrecomputeSafe(schema);
417
- let ms = buildMergeSource(schema);
408
+ let ms;
409
+ const category = mergeCategory(schema);
410
+ if (category !== "object" && category !== "array") ms = void 0;
411
+ else {
412
+ const helpers = [];
413
+ const root = emitMerger(schema, helpers, /* @__PURE__ */ new WeakMap());
414
+ ms = root ? `(function(){${helpers.join(";")};return ${root}})()` : void 0;
415
+ }
418
416
  if (ms !== void 0 && validate && !probe().validateMergeSource(schema, ms)) ms = void 0;
419
417
  if (!nullDefault && ms === void 0) {
420
418
  if (!rootIsObject) return;