typebox 1.0.42 → 1.0.44

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 (128) hide show
  1. package/build/schema/build.d.mts +6 -6
  2. package/build/schema/build.mjs +6 -4
  3. package/build/schema/check.d.mts +3 -3
  4. package/build/schema/check.mjs +4 -2
  5. package/build/schema/engine/_context.d.mts +6 -16
  6. package/build/schema/engine/_context.mjs +11 -34
  7. package/build/schema/engine/_externals.d.mts +1 -1
  8. package/build/schema/engine/_externals.mjs +2 -2
  9. package/build/schema/engine/_functions.d.mts +3 -2
  10. package/build/schema/engine/_functions.mjs +6 -5
  11. package/build/schema/engine/_guard.d.mts +5 -4
  12. package/build/schema/engine/_guard.mjs +5 -5
  13. package/build/schema/engine/_reducer.d.mts +2 -1
  14. package/build/schema/engine/_reducer.mjs +3 -3
  15. package/build/schema/engine/_refine.d.mts +4 -3
  16. package/build/schema/engine/_refine.mjs +4 -4
  17. package/build/schema/engine/_stack.d.mts +18 -0
  18. package/build/schema/engine/_stack.mjs +73 -0
  19. package/build/schema/engine/_unique.d.mts +2 -0
  20. package/build/schema/engine/_unique.mjs +5 -0
  21. package/build/schema/engine/additionalItems.d.mts +5 -4
  22. package/build/schema/engine/additionalItems.mjs +15 -13
  23. package/build/schema/engine/additionalProperties.d.mts +5 -4
  24. package/build/schema/engine/additionalProperties.mjs +19 -16
  25. package/build/schema/engine/allOf.d.mts +5 -4
  26. package/build/schema/engine/allOf.mjs +15 -15
  27. package/build/schema/engine/anyOf.d.mts +5 -4
  28. package/build/schema/engine/anyOf.mjs +15 -15
  29. package/build/schema/engine/boolean.d.mts +4 -3
  30. package/build/schema/engine/boolean.mjs +4 -4
  31. package/build/schema/engine/const.d.mts +5 -4
  32. package/build/schema/engine/const.mjs +6 -6
  33. package/build/schema/engine/contains.d.mts +5 -4
  34. package/build/schema/engine/contains.mjs +10 -8
  35. package/build/schema/engine/dependencies.d.mts +5 -4
  36. package/build/schema/engine/dependencies.mjs +6 -6
  37. package/build/schema/engine/dependentRequired.d.mts +5 -4
  38. package/build/schema/engine/dependentRequired.mjs +3 -3
  39. package/build/schema/engine/dependentSchemas.d.mts +5 -4
  40. package/build/schema/engine/dependentSchemas.mjs +6 -6
  41. package/build/schema/engine/enum.d.mts +5 -4
  42. package/build/schema/engine/enum.mjs +6 -6
  43. package/build/schema/engine/exclusiveMaximum.d.mts +5 -4
  44. package/build/schema/engine/exclusiveMaximum.mjs +4 -4
  45. package/build/schema/engine/exclusiveMinimum.d.mts +5 -4
  46. package/build/schema/engine/exclusiveMinimum.mjs +4 -4
  47. package/build/schema/engine/format.d.mts +5 -4
  48. package/build/schema/engine/format.mjs +5 -5
  49. package/build/schema/engine/if.d.mts +5 -4
  50. package/build/schema/engine/if.mjs +19 -19
  51. package/build/schema/engine/index.d.mts +12 -11
  52. package/build/schema/engine/index.mjs +13 -12
  53. package/build/schema/engine/items.d.mts +5 -4
  54. package/build/schema/engine/items.mjs +22 -22
  55. package/build/schema/engine/maxContains.d.mts +5 -4
  56. package/build/schema/engine/maxContains.mjs +11 -9
  57. package/build/schema/engine/maxItems.d.mts +5 -4
  58. package/build/schema/engine/maxItems.mjs +4 -4
  59. package/build/schema/engine/maxLength.d.mts +5 -4
  60. package/build/schema/engine/maxLength.mjs +4 -4
  61. package/build/schema/engine/maxProperties.d.mts +5 -4
  62. package/build/schema/engine/maxProperties.mjs +4 -4
  63. package/build/schema/engine/maximum.d.mts +5 -4
  64. package/build/schema/engine/maximum.mjs +4 -4
  65. package/build/schema/engine/minContains.d.mts +5 -4
  66. package/build/schema/engine/minContains.mjs +10 -8
  67. package/build/schema/engine/minItems.d.mts +5 -4
  68. package/build/schema/engine/minItems.mjs +4 -4
  69. package/build/schema/engine/minLength.d.mts +5 -4
  70. package/build/schema/engine/minLength.mjs +4 -4
  71. package/build/schema/engine/minProperties.d.mts +5 -4
  72. package/build/schema/engine/minProperties.mjs +4 -4
  73. package/build/schema/engine/minimum.d.mts +5 -4
  74. package/build/schema/engine/minimum.mjs +4 -4
  75. package/build/schema/engine/multipleOf.d.mts +5 -4
  76. package/build/schema/engine/multipleOf.mjs +4 -4
  77. package/build/schema/engine/not.d.mts +5 -4
  78. package/build/schema/engine/not.mjs +14 -13
  79. package/build/schema/engine/oneOf.d.mts +5 -4
  80. package/build/schema/engine/oneOf.mjs +14 -14
  81. package/build/schema/engine/pattern.d.mts +5 -4
  82. package/build/schema/engine/pattern.mjs +6 -6
  83. package/build/schema/engine/patternProperties.d.mts +5 -4
  84. package/build/schema/engine/patternProperties.mjs +14 -12
  85. package/build/schema/engine/prefixItems.d.mts +5 -4
  86. package/build/schema/engine/prefixItems.mjs +6 -6
  87. package/build/schema/engine/properties.d.mts +5 -4
  88. package/build/schema/engine/properties.mjs +10 -10
  89. package/build/schema/engine/propertyNames.d.mts +5 -4
  90. package/build/schema/engine/propertyNames.mjs +11 -9
  91. package/build/schema/engine/recursiveRef.d.mts +5 -4
  92. package/build/schema/engine/recursiveRef.mjs +11 -22
  93. package/build/schema/engine/ref.d.mts +5 -4
  94. package/build/schema/engine/ref.mjs +44 -29
  95. package/build/schema/engine/required.d.mts +5 -4
  96. package/build/schema/engine/required.mjs +3 -3
  97. package/build/schema/engine/schema.d.mts +5 -4
  98. package/build/schema/engine/schema.mjs +216 -207
  99. package/build/schema/engine/type.d.mts +5 -4
  100. package/build/schema/engine/type.mjs +12 -12
  101. package/build/schema/engine/unevaluatedItems.d.mts +5 -4
  102. package/build/schema/engine/unevaluatedItems.mjs +15 -13
  103. package/build/schema/engine/unevaluatedProperties.d.mts +5 -4
  104. package/build/schema/engine/unevaluatedProperties.mjs +15 -13
  105. package/build/schema/engine/uniqueItems.d.mts +5 -4
  106. package/build/schema/engine/uniqueItems.mjs +3 -3
  107. package/build/schema/errors.d.mts +3 -3
  108. package/build/schema/errors.mjs +4 -4
  109. package/build/schema/pointer/pointer.mjs +10 -2
  110. package/build/schema/resolve/index.d.mts +1 -0
  111. package/build/schema/resolve/index.mjs +1 -0
  112. package/build/schema/resolve/ref.d.mts +2 -0
  113. package/build/schema/{resolver → resolve}/ref.mjs +43 -45
  114. package/build/schema/resolve/resolve.d.mts +1 -0
  115. package/build/schema/resolve/resolve.mjs +1 -0
  116. package/build/schema/schema.d.mts +1 -1
  117. package/build/schema/schema.mjs +1 -1
  118. package/build/schema/types/recursiveAnchor.d.mts +4 -0
  119. package/build/schema/types/recursiveAnchor.mjs +7 -0
  120. package/build/type/types/static.d.mts +4 -4
  121. package/package.json +1 -1
  122. package/build/schema/resolver/index.d.mts +0 -1
  123. package/build/schema/resolver/index.mjs +0 -1
  124. package/build/schema/resolver/recursiveRef.d.mts +0 -2
  125. package/build/schema/resolver/recursiveRef.mjs +0 -47
  126. package/build/schema/resolver/ref.d.mts +0 -1
  127. package/build/schema/resolver/resolver.d.mts +0 -2
  128. package/build/schema/resolver/resolver.mjs +0 -2
@@ -1,36 +1,38 @@
1
1
  // deno-fmt-ignore-file
2
- import * as S from '../types/index.mjs';
2
+ import * as Schema from '../types/index.mjs';
3
+ import { Unique } from './_unique.mjs';
3
4
  import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
4
5
  import { BuildSchema, CheckSchema } from './schema.mjs';
5
6
  // ------------------------------------------------------------------
6
7
  // Valid
7
8
  // ------------------------------------------------------------------
8
9
  function IsValid(schema) {
9
- return S.IsContains(schema);
10
+ return Schema.IsContains(schema);
10
11
  }
11
12
  // ------------------------------------------------------------------
12
13
  // Build
13
14
  // ------------------------------------------------------------------
14
- export function BuildMinContains(context, schema, value) {
15
+ export function BuildMinContains(stack, context, schema, value) {
15
16
  if (!IsValid(schema))
16
17
  return E.Constant(true);
17
- const count = E.Call(E.Member(value, 'reduce'), [E.ArrowFunction(['result', 'value'], E.Ternary(BuildSchema(context, schema.contains, 'value'), E.PrefixIncrement('result'), 'result')), E.Constant(0)]);
18
+ const [result, item] = [Unique(), Unique()];
19
+ const count = E.Call(E.Member(value, 'reduce'), [E.ArrowFunction([result, item], E.Ternary(BuildSchema(stack, context, schema.contains, item), E.PrefixIncrement(result), result)), E.Constant(0)]);
18
20
  return E.IsGreaterEqualThan(count, E.Constant(schema.minContains));
19
21
  }
20
22
  // ------------------------------------------------------------------
21
23
  // Check
22
24
  // ------------------------------------------------------------------
23
- export function CheckMinContains(context, schema, value) {
25
+ export function CheckMinContains(stack, context, schema, value) {
24
26
  if (!IsValid(schema))
25
27
  return true;
26
- const count = value.reduce((result, value) => CheckSchema(context, schema.contains, value) ? ++result : result, 0);
28
+ const count = value.reduce((result, item) => CheckSchema(stack, context, schema.contains, item) ? ++result : result, 0);
27
29
  return G.IsGreaterEqualThan(count, schema.minContains);
28
30
  }
29
31
  // ------------------------------------------------------------------
30
32
  // Error
31
33
  // ------------------------------------------------------------------
32
- export function ErrorMinContains(context, schemaPath, instancePath, schema, value) {
33
- return CheckMinContains(context, schema, value) || context.AddError({
34
+ export function ErrorMinContains(stack, context, schemaPath, instancePath, schema, value) {
35
+ return CheckMinContains(stack, context, schema, value) || context.AddError({
34
36
  keyword: 'contains',
35
37
  schemaPath,
36
38
  instancePath,
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import { Stack } from './_stack.mjs';
2
2
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildMinItems(context: BuildContext, schema: S.XMinItems, value: string): string;
4
- export declare function CheckMinItems(context: CheckContext, schema: S.XMinItems, value: unknown[]): boolean;
5
- export declare function ErrorMinItems(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XMinItems, value: unknown[]): boolean;
3
+ import * as Schema from '../types/index.mjs';
4
+ export declare function BuildMinItems(stack: Stack, context: BuildContext, schema: Schema.XMinItems, value: string): string;
5
+ export declare function CheckMinItems(stack: Stack, context: CheckContext, schema: Schema.XMinItems, value: unknown[]): boolean;
6
+ export declare function ErrorMinItems(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XMinItems, value: unknown[]): boolean;
@@ -3,20 +3,20 @@ import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // Build
5
5
  // ------------------------------------------------------------------
6
- export function BuildMinItems(context, schema, value) {
6
+ export function BuildMinItems(stack, context, schema, value) {
7
7
  return E.IsGreaterEqualThan(E.Member(value, 'length'), E.Constant(schema.minItems));
8
8
  }
9
9
  // ------------------------------------------------------------------
10
10
  // Check
11
11
  // ------------------------------------------------------------------
12
- export function CheckMinItems(context, schema, value) {
12
+ export function CheckMinItems(stack, context, schema, value) {
13
13
  return G.IsGreaterEqualThan(value.length, schema.minItems);
14
14
  }
15
15
  // ------------------------------------------------------------------
16
16
  // Error
17
17
  // ------------------------------------------------------------------
18
- export function ErrorMinItems(context, schemaPath, instancePath, schema, value) {
19
- return CheckMinItems(context, schema, value) || context.AddError({
18
+ export function ErrorMinItems(stack, context, schemaPath, instancePath, schema, value) {
19
+ return CheckMinItems(stack, context, schema, value) || context.AddError({
20
20
  keyword: 'minItems',
21
21
  schemaPath,
22
22
  instancePath,
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildMinLength(context: BuildContext, schema: S.XMinLength, value: string): string;
4
- export declare function CheckMinLength(context: CheckContext, schema: S.XMinLength, value: string): boolean;
5
- export declare function ErrorMinLength(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XMinLength, value: string): boolean;
4
+ export declare function BuildMinLength(stack: Stack, context: BuildContext, schema: Schema.XMinLength, value: string): string;
5
+ export declare function CheckMinLength(stack: Stack, context: CheckContext, schema: Schema.XMinLength, value: string): boolean;
6
+ export declare function ErrorMinLength(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XMinLength, value: string): boolean;
@@ -3,20 +3,20 @@ import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // Build
5
5
  // ------------------------------------------------------------------
6
- export function BuildMinLength(context, schema, value) {
6
+ export function BuildMinLength(stack, context, schema, value) {
7
7
  return E.IsGreaterEqualThan(E.StringGraphemeCount(value), E.Constant(schema.minLength));
8
8
  }
9
9
  // ------------------------------------------------------------------
10
10
  // Check
11
11
  // ------------------------------------------------------------------
12
- export function CheckMinLength(context, schema, value) {
12
+ export function CheckMinLength(stack, context, schema, value) {
13
13
  return G.IsGreaterEqualThan(G.StringGraphemeCount(value), schema.minLength);
14
14
  }
15
15
  // ------------------------------------------------------------------
16
16
  // Error
17
17
  // ------------------------------------------------------------------
18
- export function ErrorMinLength(context, schemaPath, instancePath, schema, value) {
19
- return CheckMinLength(context, schema, value) || context.AddError({
18
+ export function ErrorMinLength(stack, context, schemaPath, instancePath, schema, value) {
19
+ return CheckMinLength(stack, context, schema, value) || context.AddError({
20
20
  keyword: 'minLength',
21
21
  schemaPath,
22
22
  instancePath,
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildMinProperties(context: BuildContext, schema: S.XMinProperties, value: string): string;
4
- export declare function CheckMinProperties(context: CheckContext, schema: S.XMinProperties, value: Record<PropertyKey, unknown>): boolean;
5
- export declare function ErrorMinProperties(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XMinProperties, value: Record<PropertyKey, unknown>): boolean;
4
+ export declare function BuildMinProperties(stack: Stack, context: BuildContext, schema: Schema.XMinProperties, value: string): string;
5
+ export declare function CheckMinProperties(stack: Stack, context: CheckContext, schema: Schema.XMinProperties, value: Record<PropertyKey, unknown>): boolean;
6
+ export declare function ErrorMinProperties(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XMinProperties, value: Record<PropertyKey, unknown>): boolean;
@@ -3,20 +3,20 @@ import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // Build
5
5
  // ------------------------------------------------------------------
6
- export function BuildMinProperties(context, schema, value) {
6
+ export function BuildMinProperties(stack, context, schema, value) {
7
7
  return E.IsGreaterEqualThan(E.Member(E.Keys(value), 'length'), E.Constant(schema.minProperties));
8
8
  }
9
9
  // ------------------------------------------------------------------
10
10
  // Check
11
11
  // ------------------------------------------------------------------
12
- export function CheckMinProperties(context, schema, value) {
12
+ export function CheckMinProperties(stack, context, schema, value) {
13
13
  return G.IsGreaterEqualThan(G.Keys(value).length, schema.minProperties);
14
14
  }
15
15
  // ------------------------------------------------------------------
16
16
  // Error
17
17
  // ------------------------------------------------------------------
18
- export function ErrorMinProperties(context, schemaPath, instancePath, schema, value) {
19
- return CheckMinProperties(context, schema, value) || context.AddError({
18
+ export function ErrorMinProperties(stack, context, schemaPath, instancePath, schema, value) {
19
+ return CheckMinProperties(stack, context, schema, value) || context.AddError({
20
20
  keyword: 'minProperties',
21
21
  schemaPath,
22
22
  instancePath,
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildMinimum(context: BuildContext, schema: S.XMinimum, value: string): string;
4
- export declare function CheckMinimum(context: CheckContext, schema: S.XMinimum, value: number | bigint): boolean;
5
- export declare function ErrorMinimum(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XMinimum, value: number | bigint): boolean;
4
+ export declare function BuildMinimum(stack: Stack, context: BuildContext, schema: Schema.XMinimum, value: string): string;
5
+ export declare function CheckMinimum(stack: Stack, context: CheckContext, schema: Schema.XMinimum, value: number | bigint): boolean;
6
+ export declare function ErrorMinimum(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XMinimum, value: number | bigint): boolean;
@@ -3,20 +3,20 @@ import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // Build
5
5
  // ------------------------------------------------------------------
6
- export function BuildMinimum(context, schema, value) {
6
+ export function BuildMinimum(stack, context, schema, value) {
7
7
  return E.IsGreaterEqualThan(value, E.Constant(schema.minimum));
8
8
  }
9
9
  // ------------------------------------------------------------------
10
10
  // Check
11
11
  // ------------------------------------------------------------------
12
- export function CheckMinimum(context, schema, value) {
12
+ export function CheckMinimum(stack, context, schema, value) {
13
13
  return G.IsGreaterEqualThan(value, schema.minimum);
14
14
  }
15
15
  // ------------------------------------------------------------------
16
16
  // Error
17
17
  // ------------------------------------------------------------------
18
- export function ErrorMinimum(context, schemaPath, instancePath, schema, value) {
19
- return CheckMinimum(context, schema, value) || context.AddError({
18
+ export function ErrorMinimum(stack, context, schemaPath, instancePath, schema, value) {
19
+ return CheckMinimum(stack, context, schema, value) || context.AddError({
20
20
  keyword: 'minimum',
21
21
  schemaPath,
22
22
  instancePath,
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildMultipleOf(context: BuildContext, schema: S.XMultipleOf, value: string): string;
4
- export declare function CheckMultipleOf(context: CheckContext, schema: S.XMultipleOf, value: number | bigint): boolean;
5
- export declare function ErrorMultipleOf(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XMultipleOf, value: number | bigint): boolean;
4
+ export declare function BuildMultipleOf(stack: Stack, context: BuildContext, schema: Schema.XMultipleOf, value: string): string;
5
+ export declare function CheckMultipleOf(stack: Stack, context: CheckContext, schema: Schema.XMultipleOf, value: number | bigint): boolean;
6
+ export declare function ErrorMultipleOf(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XMultipleOf, value: number | bigint): boolean;
@@ -3,20 +3,20 @@ import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // Build
5
5
  // ------------------------------------------------------------------
6
- export function BuildMultipleOf(context, schema, value) {
6
+ export function BuildMultipleOf(stack, context, schema, value) {
7
7
  return E.MultipleOf(value, E.Constant(schema.multipleOf));
8
8
  }
9
9
  // ------------------------------------------------------------------
10
10
  // Check
11
11
  // ------------------------------------------------------------------
12
- export function CheckMultipleOf(context, schema, value) {
12
+ export function CheckMultipleOf(stack, context, schema, value) {
13
13
  return G.IsMultipleOf(value, schema.multipleOf);
14
14
  }
15
15
  // ------------------------------------------------------------------
16
16
  // Error
17
17
  // ------------------------------------------------------------------
18
- export function ErrorMultipleOf(context, schemaPath, instancePath, schema, value) {
19
- return CheckMultipleOf(context, schema, value) || context.AddError({
18
+ export function ErrorMultipleOf(stack, context, schemaPath, instancePath, schema, value) {
19
+ return CheckMultipleOf(stack, context, schema, value) || context.AddError({
20
20
  keyword: 'multipleOf',
21
21
  schemaPath,
22
22
  instancePath,
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildNot(context: BuildContext, schema: S.XNot, value: string): string;
4
- export declare function CheckNot(context: CheckContext, schema: S.XNot, value: unknown): boolean;
5
- export declare function ErrorNot(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XNot, value: unknown): boolean;
4
+ export declare function BuildNot(stack: Stack, context: BuildContext, schema: Schema.XNot, value: string): string;
5
+ export declare function CheckNot(stack: Stack, context: CheckContext, schema: Schema.XNot, value: unknown): boolean;
6
+ export declare function ErrorNot(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XNot, value: unknown): boolean;
@@ -1,33 +1,34 @@
1
1
  // deno-fmt-ignore-file
2
+ import { CheckContext } from './_context.mjs';
3
+ import { Reducer } from './_reducer.mjs';
2
4
  import { EmitGuard as E } from '../../guard/index.mjs';
3
5
  import { BuildSchema, CheckSchema } from './schema.mjs';
4
- import { Reducer } from './_reducer.mjs';
5
6
  // ------------------------------------------------------------------
6
7
  // Build
7
8
  // ------------------------------------------------------------------
8
- function BuildNotUnevaluated(context, schema, value) {
9
- return Reducer(context, [schema.not], value, E.Not(E.IsEqual(E.Member('results', 'length'), E.Constant(1))));
9
+ function BuildNotUnevaluated(stack, context, schema, value) {
10
+ return Reducer(stack, context, [schema.not], value, E.Not(E.IsEqual(E.Member('results', 'length'), E.Constant(1))));
10
11
  }
11
- function BuildNotFast(context, schema, value) {
12
- return E.Not(BuildSchema(context, schema.not, value));
12
+ function BuildNotFast(stack, context, schema, value) {
13
+ return E.Not(BuildSchema(stack, context, schema.not, value));
13
14
  }
14
- export function BuildNot(context, schema, value) {
15
- return context.UseUnevaluated() ? BuildNotUnevaluated(context, schema, value) : BuildNotFast(context, schema, value);
15
+ export function BuildNot(stack, context, schema, value) {
16
+ return context.UseUnevaluated() ? BuildNotUnevaluated(stack, context, schema, value) : BuildNotFast(stack, context, schema, value);
16
17
  }
17
18
  // ------------------------------------------------------------------
18
19
  // Check
19
20
  // ------------------------------------------------------------------
20
- export function CheckNot(context, schema, value) {
21
- const condition = context.Clone();
22
- const isSchema = !CheckSchema(condition, schema.not, value);
23
- const isNot = isSchema && context.Merge([condition]);
21
+ export function CheckNot(stack, context, schema, value) {
22
+ const nextContext = new CheckContext();
23
+ const isSchema = !CheckSchema(stack, nextContext, schema.not, value);
24
+ const isNot = isSchema && context.Merge([nextContext]);
24
25
  return isNot;
25
26
  }
26
27
  // ------------------------------------------------------------------
27
28
  // Error
28
29
  // ------------------------------------------------------------------
29
- export function ErrorNot(context, schemaPath, instancePath, schema, value) {
30
- return CheckNot(context, schema, value) || context.AddError({
30
+ export function ErrorNot(stack, context, schemaPath, instancePath, schema, value) {
31
+ return CheckNot(stack, context, schema, value) || context.AddError({
31
32
  keyword: 'not',
32
33
  schemaPath,
33
34
  instancePath,
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildOneOf(context: BuildContext, schema: S.XOneOf, value: string): string;
4
- export declare function CheckOneOf(context: CheckContext, schema: S.XOneOf, value: unknown): boolean;
5
- export declare function ErrorOneOf(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XOneOf, value: unknown): boolean;
4
+ export declare function BuildOneOf(stack: Stack, context: BuildContext, schema: Schema.XOneOf, value: string): string;
5
+ export declare function CheckOneOf(stack: Stack, context: CheckContext, schema: Schema.XOneOf, value: unknown): boolean;
6
+ export declare function ErrorOneOf(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XOneOf, value: unknown): boolean;
@@ -1,45 +1,45 @@
1
1
  // deno-fmt-ignore-file
2
+ import { CheckContext, AccumulatedErrorContext } from './_context.mjs';
3
+ import { Reducer } from './_reducer.mjs';
2
4
  import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
3
- import { AccumulatedErrorContext } from './_context.mjs';
4
5
  import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
5
- import { Reducer } from './_reducer.mjs';
6
6
  // ------------------------------------------------------------------
7
7
  // Build
8
8
  // ------------------------------------------------------------------
9
- function BuildOneOfUnevaluated(context, schema, value) {
10
- return Reducer(context, schema.oneOf, value, E.IsEqual(E.Member('results', 'length'), E.Constant(1)));
9
+ function BuildOneOfUnevaluated(stack, context, schema, value) {
10
+ return Reducer(stack, context, schema.oneOf, value, E.IsEqual(E.Member('results', 'length'), E.Constant(1)));
11
11
  }
12
- function BuildOneOfFast(context, schema, value) {
13
- const results = E.ArrayLiteral(schema.oneOf.map((schema) => BuildSchema(context, schema, value)));
12
+ function BuildOneOfFast(stack, context, schema, value) {
13
+ const results = E.ArrayLiteral(schema.oneOf.map((schema) => BuildSchema(stack, context, schema, value)));
14
14
  const count = E.Call(E.Member(results, 'reduce'), [
15
15
  E.ArrowFunction(['count', 'result'], E.Ternary(E.IsEqual('result', E.Constant(true)), E.PrefixIncrement('count'), 'count')),
16
16
  E.Constant(0),
17
17
  ]);
18
18
  return E.IsEqual(count, E.Constant(1));
19
19
  }
20
- export function BuildOneOf(context, schema, value) {
21
- return context.UseUnevaluated() ? BuildOneOfUnevaluated(context, schema, value) : BuildOneOfFast(context, schema, value);
20
+ export function BuildOneOf(stack, context, schema, value) {
21
+ return context.UseUnevaluated() ? BuildOneOfUnevaluated(stack, context, schema, value) : BuildOneOfFast(stack, context, schema, value);
22
22
  }
23
23
  // ------------------------------------------------------------------
24
24
  // Check
25
25
  // ------------------------------------------------------------------
26
- export function CheckOneOf(context, schema, value) {
26
+ export function CheckOneOf(stack, context, schema, value) {
27
27
  const passedContexts = schema.oneOf.reduce((result, schema) => {
28
- const nextContext = context.Clone();
29
- return CheckSchema(nextContext, schema, value) ? [...result, nextContext] : result;
28
+ const nextContext = new CheckContext();
29
+ return CheckSchema(stack, nextContext, schema, value) ? [...result, nextContext] : result;
30
30
  }, []);
31
31
  return G.IsEqual(passedContexts.length, 1) && context.Merge(passedContexts);
32
32
  }
33
33
  // ------------------------------------------------------------------
34
34
  // Error
35
35
  // ------------------------------------------------------------------
36
- export function ErrorOneOf(context, schemaPath, instancePath, schema, value) {
36
+ export function ErrorOneOf(stack, context, schemaPath, instancePath, schema, value) {
37
37
  const failedContexts = [];
38
38
  const passingSchemas = [];
39
39
  const passedContexts = schema.oneOf.reduce((result, schema, index) => {
40
- const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
40
+ const nextContext = new AccumulatedErrorContext();
41
41
  const nextSchemaPath = `${schemaPath}/oneOf/${index}`;
42
- const isSchema = ErrorSchema(nextContext, nextSchemaPath, instancePath, schema, value);
42
+ const isSchema = ErrorSchema(stack, nextContext, nextSchemaPath, instancePath, schema, value);
43
43
  if (isSchema)
44
44
  passingSchemas.push(index);
45
45
  if (!isSchema)
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildPattern(context: BuildContext, schema: S.XPattern, value: string): string;
4
- export declare function CheckPattern(context: CheckContext, schema: S.XPattern, value: string): boolean;
5
- export declare function ErrorPattern(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XPattern, value: string): boolean;
4
+ export declare function BuildPattern(stack: Stack, context: BuildContext, schema: Schema.XPattern, value: string): string;
5
+ export declare function CheckPattern(stack: Stack, context: CheckContext, schema: Schema.XPattern, value: string): boolean;
6
+ export declare function ErrorPattern(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XPattern, value: string): boolean;
@@ -1,25 +1,25 @@
1
1
  // deno-fmt-ignore-file
2
- import * as V from './_externals.mjs';
2
+ import * as Externals from './_externals.mjs';
3
3
  import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  // Build
6
6
  // ------------------------------------------------------------------
7
- export function BuildPattern(context, schema, value) {
8
- const regexp = V.CreateExternalVariable(G.IsString(schema.pattern) ? new RegExp(schema.pattern) : schema.pattern);
7
+ export function BuildPattern(stack, context, schema, value) {
8
+ const regexp = Externals.CreateVariable(G.IsString(schema.pattern) ? new RegExp(schema.pattern) : schema.pattern);
9
9
  return E.Call(E.Member(regexp, 'test'), [value]);
10
10
  }
11
11
  // ------------------------------------------------------------------
12
12
  // Check
13
13
  // ------------------------------------------------------------------
14
- export function CheckPattern(context, schema, value) {
14
+ export function CheckPattern(stack, context, schema, value) {
15
15
  const regexp = G.IsString(schema.pattern) ? new RegExp(schema.pattern) : schema.pattern;
16
16
  return regexp.test(value);
17
17
  }
18
18
  // ------------------------------------------------------------------
19
19
  // Error
20
20
  // ------------------------------------------------------------------
21
- export function ErrorPattern(context, schemaPath, instancePath, schema, value) {
22
- return CheckPattern(context, schema, value) || context.AddError({
21
+ export function ErrorPattern(stack, context, schemaPath, instancePath, schema, value) {
22
+ return CheckPattern(stack, context, schema, value) || context.AddError({
23
23
  keyword: 'pattern',
24
24
  schemaPath,
25
25
  instancePath,
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildPatternProperties(context: BuildContext, schema: S.XPatternProperties, value: string): string;
4
- export declare function CheckPatternProperties(context: CheckContext, schema: S.XPatternProperties, value: Record<PropertyKey, unknown>): boolean;
5
- export declare function ErrorPatternProperties(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XPatternProperties, value: Record<PropertyKey, unknown>): boolean;
4
+ export declare function BuildPatternProperties(stack: Stack, context: BuildContext, schema: Schema.XPatternProperties, value: string): string;
5
+ export declare function CheckPatternProperties(stack: Stack, context: CheckContext, schema: Schema.XPatternProperties, value: Record<PropertyKey, unknown>): boolean;
6
+ export declare function ErrorPatternProperties(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XPatternProperties, value: Record<PropertyKey, unknown>): boolean;
@@ -1,42 +1,44 @@
1
1
  // deno-fmt-ignore-file
2
- import * as V from './_externals.mjs';
2
+ import * as Externals from './_externals.mjs';
3
+ import { Unique } from './_unique.mjs';
3
4
  import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
4
5
  import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
5
6
  // ------------------------------------------------------------------
6
7
  // Build
7
8
  // ------------------------------------------------------------------
8
- export function BuildPatternProperties(context, schema, value) {
9
+ export function BuildPatternProperties(stack, context, schema, value) {
9
10
  return E.ReduceAnd(G.Entries(schema.patternProperties).map(([pattern, schema]) => {
10
- const regexp = V.CreateExternalVariable(new RegExp(pattern));
11
- const notKey = E.Not(E.Call(E.Member(regexp, 'test'), ['key']));
12
- const isSchema = BuildSchema(context, schema, 'value');
13
- const addKey = context.AddKey('key');
11
+ const [key, prop] = [Unique(), Unique()];
12
+ const regexp = Externals.CreateVariable(new RegExp(pattern));
13
+ const notKey = E.Not(E.Call(E.Member(regexp, 'test'), [key]));
14
+ const isSchema = BuildSchema(stack, context, schema, prop);
15
+ const addKey = context.AddKey(key);
14
16
  const guarded = context.UseUnevaluated() ? E.Or(notKey, E.And(isSchema, addKey)) : E.Or(notKey, isSchema);
15
- return E.Every(E.Entries(value), E.Constant(0), ['[key, value]', '_'], guarded);
17
+ return E.Every(E.Entries(value), E.Constant(0), [`[${key}, ${prop}]`, '_'], guarded);
16
18
  }));
17
19
  }
18
20
  // ------------------------------------------------------------------
19
21
  // Check
20
22
  // ------------------------------------------------------------------
21
- export function CheckPatternProperties(context, schema, value) {
23
+ export function CheckPatternProperties(stack, context, schema, value) {
22
24
  return G.Every(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
23
25
  const regexp = new RegExp(pattern);
24
- return G.Every(G.Entries(value), 0, ([key, value]) => {
25
- return !regexp.test(key) || CheckSchema(context, schema, value) && context.AddKey(key);
26
+ return G.Every(G.Entries(value), 0, ([key, prop]) => {
27
+ return !regexp.test(key) || CheckSchema(stack, context, schema, prop) && context.AddKey(key);
26
28
  });
27
29
  });
28
30
  }
29
31
  // ------------------------------------------------------------------
30
32
  // Error
31
33
  // ------------------------------------------------------------------
32
- export function ErrorPatternProperties(context, schemaPath, instancePath, schema, value) {
34
+ export function ErrorPatternProperties(stack, context, schemaPath, instancePath, schema, value) {
33
35
  return G.EveryAll(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
34
36
  const nextSchemaPath = `${schemaPath}/patternProperties/${pattern}`;
35
37
  const regexp = new RegExp(pattern);
36
38
  return G.EveryAll(G.Entries(value), 0, ([key, value]) => {
37
39
  const nextInstancePath = `${instancePath}/${key}`;
38
40
  const notKey = !regexp.test(key);
39
- return notKey || ErrorSchema(context, nextSchemaPath, nextInstancePath, schema, value) && context.AddKey(key);
41
+ return notKey || ErrorSchema(stack, context, nextSchemaPath, nextInstancePath, schema, value) && context.AddKey(key);
40
42
  });
41
43
  });
42
44
  }
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildPrefixItems(context: BuildContext, schema: S.XPrefixItems, value: string): string;
4
- export declare function CheckPrefixItems(context: CheckContext, schema: S.XPrefixItems, value: unknown[]): boolean;
5
- export declare function ErrorPrefixItems(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XPrefixItems, value: unknown[]): boolean;
4
+ export declare function BuildPrefixItems(stack: Stack, context: BuildContext, schema: Schema.XPrefixItems, value: string): string;
5
+ export declare function CheckPrefixItems(stack: Stack, context: CheckContext, schema: Schema.XPrefixItems, value: unknown[]): boolean;
6
+ export declare function ErrorPrefixItems(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XPrefixItems, value: unknown[]): boolean;
@@ -4,10 +4,10 @@ import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  // Build
6
6
  // ------------------------------------------------------------------
7
- export function BuildPrefixItems(context, schema, value) {
7
+ export function BuildPrefixItems(stack, context, schema, value) {
8
8
  return E.ReduceAnd(schema.prefixItems.map((schema, index) => {
9
9
  const isLength = E.IsLessEqualThan(E.Member(value, 'length'), E.Constant(index));
10
- const isSchema = BuildSchema(context, schema, `${value}[${index}]`);
10
+ const isSchema = BuildSchema(stack, context, schema, `${value}[${index}]`);
11
11
  const addIndex = context.AddIndex(E.Constant(index));
12
12
  const guarded = context.UseUnevaluated() ? E.And(isSchema, addIndex) : isSchema;
13
13
  return E.Or(isLength, guarded);
@@ -16,20 +16,20 @@ export function BuildPrefixItems(context, schema, value) {
16
16
  // ------------------------------------------------------------------
17
17
  // Check
18
18
  // ------------------------------------------------------------------
19
- export function CheckPrefixItems(context, schema, value) {
19
+ export function CheckPrefixItems(stack, context, schema, value) {
20
20
  return G.IsEqual(value.length, 0) || G.Every(schema.prefixItems, 0, (schema, index) => {
21
21
  return G.IsLessEqualThan(value.length, index)
22
- || (CheckSchema(context, schema, value[index]) && context.AddIndex(index));
22
+ || (CheckSchema(stack, context, schema, value[index]) && context.AddIndex(index));
23
23
  });
24
24
  }
25
25
  // ------------------------------------------------------------------
26
26
  // Error
27
27
  // ------------------------------------------------------------------
28
- export function ErrorPrefixItems(context, schemaPath, instancePath, schema, value) {
28
+ export function ErrorPrefixItems(stack, context, schemaPath, instancePath, schema, value) {
29
29
  return G.IsEqual(value.length, 0) || G.EveryAll(schema.prefixItems, 0, (schema, index) => {
30
30
  const nextSchemaPath = `${schemaPath}/prefixItems/${index}`;
31
31
  const nextInstancePath = `${instancePath}/${index}`;
32
32
  return G.IsLessEqualThan(value.length, index)
33
- || (ErrorSchema(context, nextSchemaPath, nextInstancePath, schema, value[index]) && context.AddIndex(index));
33
+ || (ErrorSchema(stack, context, nextSchemaPath, nextInstancePath, schema, value[index]) && context.AddIndex(index));
34
34
  });
35
35
  }
@@ -1,5 +1,6 @@
1
- import * as S from '../types/index.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import { Stack } from './_stack.mjs';
2
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildProperties(context: BuildContext, schema: S.XProperties, value: string): string;
4
- export declare function CheckProperties(context: CheckContext, schema: S.XProperties, value: Record<PropertyKey, unknown>): boolean;
5
- export declare function ErrorProperties(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XProperties, value: Record<PropertyKey, unknown>): boolean;
4
+ export declare function BuildProperties(stack: Stack, context: BuildContext, schema: Schema.XProperties, value: string): string;
5
+ export declare function CheckProperties(stack: Stack, context: CheckContext, schema: Schema.XProperties, value: Record<PropertyKey, unknown>): boolean;
6
+ export declare function ErrorProperties(stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XProperties, value: Record<PropertyKey, unknown>): boolean;
@@ -1,16 +1,16 @@
1
1
  // deno-fmt-ignore-file
2
+ import * as Schema from '../types/index.mjs';
2
3
  import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
3
- import * as S from '../types/index.mjs';
4
4
  import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
5
5
  import { InexactOptionalCheck, InexactOptionalBuild, IsExactOptional } from './_exact_optional.mjs';
6
6
  // ------------------------------------------------------------------
7
7
  // Build
8
8
  // ------------------------------------------------------------------
9
- export function BuildProperties(context, schema, value) {
10
- const required = S.IsRequired(schema) ? schema.required : [];
9
+ export function BuildProperties(stack, context, schema, value) {
10
+ const required = Schema.IsRequired(schema) ? schema.required : [];
11
11
  const everyKey = G.Entries(schema.properties).map(([key, schema]) => {
12
12
  const notKey = E.Not(E.HasPropertyKey(value, E.Constant(key)));
13
- const isSchema = BuildSchema(context, schema, E.Member(value, key));
13
+ const isSchema = BuildSchema(stack, context, schema, E.Member(value, key));
14
14
  const addKey = context.AddKey(E.Constant(key));
15
15
  const guarded = context.UseUnevaluated() ? E.And(isSchema, addKey) : isSchema;
16
16
  // --------------------------------------------------------------
@@ -47,10 +47,10 @@ export function BuildProperties(context, schema, value) {
47
47
  // ------------------------------------------------------------------
48
48
  // Check
49
49
  // ------------------------------------------------------------------
50
- export function CheckProperties(context, schema, value) {
51
- const required = S.IsRequired(schema) ? schema.required : [];
50
+ export function CheckProperties(stack, context, schema, value) {
51
+ const required = Schema.IsRequired(schema) ? schema.required : [];
52
52
  const isProperties = G.Every(G.Entries(schema.properties), 0, ([key, schema]) => {
53
- const isProperty = !G.HasPropertyKey(value, key) || (CheckSchema(context, schema, value[key]) && context.AddKey(key));
53
+ const isProperty = !G.HasPropertyKey(value, key) || (CheckSchema(stack, context, schema, value[key]) && context.AddKey(key));
54
54
  return IsExactOptional(required, key)
55
55
  ? isProperty
56
56
  : InexactOptionalCheck(value, key) || isProperty;
@@ -60,13 +60,13 @@ export function CheckProperties(context, schema, value) {
60
60
  // ------------------------------------------------------------------
61
61
  // Error
62
62
  // ------------------------------------------------------------------
63
- export function ErrorProperties(context, schemaPath, instancePath, schema, value) {
64
- const required = S.IsRequired(schema) ? schema.required : [];
63
+ export function ErrorProperties(stack, context, schemaPath, instancePath, schema, value) {
64
+ const required = Schema.IsRequired(schema) ? schema.required : [];
65
65
  const isProperties = G.EveryAll(G.Entries(schema.properties), 0, ([key, schema]) => {
66
66
  const nextSchemaPath = `${schemaPath}/properties/${key}`;
67
67
  const nextInstancePath = `${instancePath}/${key}`;
68
68
  // Defer error generation for IsExactOptional
69
- const isProperty = () => (!G.HasPropertyKey(value, key) || (ErrorSchema(context, nextSchemaPath, nextInstancePath, schema, value[key]) && context.AddKey(key)));
69
+ const isProperty = () => (!G.HasPropertyKey(value, key) || (ErrorSchema(stack, context, nextSchemaPath, nextInstancePath, schema, value[key]) && context.AddKey(key)));
70
70
  return IsExactOptional(required, key)
71
71
  ? isProperty()
72
72
  : InexactOptionalCheck(value, key) || isProperty();