typebox 1.0.25 → 1.0.27

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.
@@ -35,6 +35,7 @@ export declare function IsLessThan(left: string, right: string): string;
35
35
  export declare function IsLessEqualThan(left: string, right: string): string;
36
36
  export declare function IsGreaterEqualThan(left: string, right: string): string;
37
37
  export declare function StringGraphemeCount(value: string): string;
38
+ export declare function Every(value: string, offset: string, params: [value: string, index: string], expression: string): string;
38
39
  export declare function Entries(value: string): string;
39
40
  export declare function Keys(value: string): string;
40
41
  export declare function HasPropertyKey(value: string, key: string): string;
@@ -108,6 +108,14 @@ export function StringGraphemeCount(value) {
108
108
  return `Guard.StringGraphemeCount(${value})`;
109
109
  }
110
110
  // --------------------------------------------------------------------------
111
+ // Array
112
+ // --------------------------------------------------------------------------
113
+ export function Every(value, offset, params, expression) {
114
+ return G.IsEqual(offset, '0')
115
+ ? `${value}.every((${params[0]}, ${params[1]}) => ${expression})`
116
+ : `((value, callback) => { for(let index = ${offset}; index < value.length; index++) if (!callback(value[index], index)) return false; return true })(${value}, (${params[0]}, ${params[1]}) => ${expression})`;
117
+ }
118
+ // --------------------------------------------------------------------------
111
119
  // Objects
112
120
  // --------------------------------------------------------------------------
113
121
  export function Entries(value) {
@@ -39,8 +39,8 @@ export declare function IsClassInstance(value: unknown): boolean;
39
39
  export declare function IsValueLike(value: unknown): value is bigint | boolean | null | number | string | undefined;
40
40
  /** Returns the number of Unicode Grapheme Clusters */
41
41
  export declare function StringGraphemeCount(value: string): number;
42
- export declare function Every<T>(value: T[], callback: (value: T, index: number) => boolean): boolean;
43
- export declare function EveryAll<T>(value: T[], callback: (value: T, index: number) => boolean): boolean;
42
+ export declare function Every<T>(value: T[], offset: number, callback: (value: T, index: number) => boolean): boolean;
43
+ export declare function EveryAll<T>(value: T[], offset: number, callback: (value: T, index: number) => boolean): boolean;
44
44
  /** Returns true if this value has this property key */
45
45
  export declare function HasPropertyKey<Key extends PropertyKey>(value: object, key: Key): value is {
46
46
  [_ in Key]: unknown;
@@ -136,12 +136,16 @@ export function StringGraphemeCount(value) {
136
136
  // --------------------------------------------------------------------------
137
137
  // Array
138
138
  // --------------------------------------------------------------------------
139
- export function Every(value, callback) {
140
- return value.every(callback);
139
+ export function Every(value, offset, callback) {
140
+ for (let index = offset; index < value.length; index++) {
141
+ if (!callback(value[index], index))
142
+ return false;
143
+ }
144
+ return true;
141
145
  }
142
- export function EveryAll(value, callback) {
146
+ export function EveryAll(value, offset, callback) {
143
147
  let result = true;
144
- for (let index = 0; index < value.length; index++) {
148
+ for (let index = offset; index < value.length; index++) {
145
149
  if (!callback(value[index], index))
146
150
  result = false;
147
151
  }
@@ -6,19 +6,19 @@ import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
6
6
  // ------------------------------------------------------------------
7
7
  export function BuildRefine(context, schema, value) {
8
8
  const refinements = V.CreateExternalVariable(schema['~refine'].map((refinement) => refinement));
9
- return E.Call(E.Member(refinements, 'every'), [E.ArrowFunction(['refinement'], E.Call(E.Member('refinement', 'callback'), [value]))]);
9
+ return E.Every(refinements, E.Constant(0), ['refinement', '_'], E.Call(E.Member('refinement', 'callback'), [value]));
10
10
  }
11
11
  // ------------------------------------------------------------------
12
12
  // Check
13
13
  // ------------------------------------------------------------------
14
14
  export function CheckRefine(context, schema, value) {
15
- return G.Every(schema['~refine'], (refinement) => refinement.callback(value));
15
+ return G.Every(schema['~refine'], 0, (refinement, _) => refinement.callback(value));
16
16
  }
17
17
  // ------------------------------------------------------------------
18
18
  // Error
19
19
  // ------------------------------------------------------------------
20
20
  export function ErrorRefine(context, schemaPath, instancePath, schema, value) {
21
- return G.EveryAll(schema['~refine'], (refinement, index) => {
21
+ return G.EveryAll(schema['~refine'], 0, (refinement, index) => {
22
22
  return refinement.callback(value) || context.AddError({
23
23
  keyword: '~refine',
24
24
  schemaPath,
@@ -57,7 +57,7 @@ export function BuildAdditionalPropertiesStandard(context, schema, value) {
57
57
  const isKey = E.Call(E.Member(regexp, 'test'), ['key']);
58
58
  const addKey = context.AddKey('key');
59
59
  const guarded = context.UseUnevaluated() ? E.Or(isKey, E.And(isSchema, addKey)) : E.Or(isKey, isSchema);
60
- return E.Call(E.Member(E.Keys(value), 'every'), [E.ArrowFunction(['key'], guarded)]);
60
+ return E.Every(E.Keys(value), E.Constant(0), ['key', '_'], guarded);
61
61
  }
62
62
  // ------------------------------------------------------------------
63
63
  // Build
@@ -72,7 +72,7 @@ export function BuildAdditionalProperties(context, schema, value) {
72
72
  // ------------------------------------------------------------------
73
73
  export function CheckAdditionalProperties(context, schema, value) {
74
74
  const regexp = new RegExp(GetPropertiesPattern(schema));
75
- const isAdditionalProperties = G.Every(G.Keys(value), (key) => {
75
+ const isAdditionalProperties = G.Every(G.Keys(value), 0, (key) => {
76
76
  return regexp.test(key) ||
77
77
  (CheckSchema(context, schema.additionalProperties, value[key]) && context.AddKey(key));
78
78
  });
@@ -84,7 +84,7 @@ export function CheckAdditionalProperties(context, schema, value) {
84
84
  export function ErrorAdditionalProperties(context, schemaPath, instancePath, schema, value) {
85
85
  const regexp = new RegExp(GetPropertiesPattern(schema));
86
86
  const additionalProperties = [];
87
- const isAdditionalProperties = G.EveryAll(G.Keys(value), (key) => {
87
+ const isAdditionalProperties = G.EveryAll(G.Keys(value), 0, (key) => {
88
88
  const nextSchemaPath = `${schemaPath}/additionalProperties`;
89
89
  const nextInstancePath = `${instancePath}/${key}`;
90
90
  const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
@@ -19,7 +19,7 @@ export function BuildDependencies(context, schema, value) {
19
19
  // ------------------------------------------------------------------
20
20
  export function CheckDependencies(context, schema, value) {
21
21
  const isLength = G.IsEqual(G.Keys(value).length, 0);
22
- const isEvery = G.Every(G.Entries(schema.dependencies), ([key, schema]) => {
22
+ const isEvery = G.Every(G.Entries(schema.dependencies), 0, ([key, schema]) => {
23
23
  return !G.HasPropertyKey(value, key) || (G.IsArray(schema)
24
24
  ? schema.every((key) => G.HasPropertyKey(value, key))
25
25
  : CheckSchema(context, schema, value));
@@ -31,7 +31,7 @@ export function CheckDependencies(context, schema, value) {
31
31
  // ------------------------------------------------------------------
32
32
  export function ErrorDependencies(context, schemaPath, instancePath, schema, value) {
33
33
  const isLength = G.IsEqual(G.Keys(value).length, 0);
34
- const isEvery = G.EveryAll(G.Entries(schema.dependencies), ([key, schema]) => {
34
+ const isEvery = G.EveryAll(G.Entries(schema.dependencies), 0, ([key, schema]) => {
35
35
  const nextSchemaPath = `${schemaPath}/dependencies/${key}`;
36
36
  return !G.HasPropertyKey(value, key) || (G.IsArray(schema)
37
37
  ? schema.every((dependency) => G.HasPropertyKey(value, dependency) || context.AddError({
@@ -17,7 +17,7 @@ export function BuildDependentRequired(context, schema, value) {
17
17
  // ------------------------------------------------------------------
18
18
  export function CheckDependentRequired(context, schema, value) {
19
19
  const isLength = G.IsEqual(G.Keys(value).length, 0);
20
- const isEvery = G.Every(G.Entries(schema.dependentRequired), ([key, keys]) => {
20
+ const isEvery = G.Every(G.Entries(schema.dependentRequired), 0, ([key, keys]) => {
21
21
  return !G.HasPropertyKey(value, key) ||
22
22
  keys.every((key) => G.HasPropertyKey(value, key));
23
23
  });
@@ -28,8 +28,8 @@ export function CheckDependentRequired(context, schema, value) {
28
28
  // ------------------------------------------------------------------
29
29
  export function ErrorDependentRequired(context, schemaPath, instancePath, schema, value) {
30
30
  const isLength = G.IsEqual(G.Keys(value).length, 0);
31
- const isEveryEntry = G.EveryAll(G.Entries(schema.dependentRequired), ([key, keys]) => {
32
- return !G.HasPropertyKey(value, key) || G.EveryAll(keys, (dependency) => G.HasPropertyKey(value, dependency) || context.AddError({
31
+ const isEveryEntry = G.EveryAll(G.Entries(schema.dependentRequired), 0, ([key, keys]) => {
32
+ return !G.HasPropertyKey(value, key) || G.EveryAll(keys, 0, (dependency) => G.HasPropertyKey(value, dependency) || context.AddError({
33
33
  keyword: 'dependentRequired',
34
34
  schemaPath,
35
35
  instancePath,
@@ -18,7 +18,7 @@ export function BuildDependentSchemas(context, schema, value) {
18
18
  // ------------------------------------------------------------------
19
19
  export function CheckDependentSchemas(context, schema, value) {
20
20
  const isLength = G.IsEqual(G.Keys(value).length, 0);
21
- const isEvery = G.Every(G.Entries(schema.dependentSchemas), ([key, schema]) => {
21
+ const isEvery = G.Every(G.Entries(schema.dependentSchemas), 0, ([key, schema]) => {
22
22
  return !G.HasPropertyKey(value, key) ||
23
23
  CheckSchema(context, schema, value);
24
24
  });
@@ -29,7 +29,7 @@ export function CheckDependentSchemas(context, schema, value) {
29
29
  // ------------------------------------------------------------------
30
30
  export function ErrorDependentSchemas(context, schemaPath, instancePath, schema, value) {
31
31
  const isLength = G.IsEqual(G.Keys(value).length, 0);
32
- const isEvery = G.EveryAll(G.Entries(schema.dependentSchemas), ([key, schema]) => {
32
+ const isEvery = G.EveryAll(G.Entries(schema.dependentSchemas), 0, ([key, schema]) => {
33
33
  const nextSchemaPath = `${schemaPath}/dependentSchemas/${key}`;
34
34
  return !G.HasPropertyKey(value, key) ||
35
35
  ErrorSchema(context, nextSchemaPath, instancePath, schema, value);
@@ -7,7 +7,7 @@ import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
7
7
  // ------------------------------------------------------------------
8
8
  function BuildItemsSized(context, schema, value) {
9
9
  return E.ReduceAnd(schema.items.map((schema, index) => {
10
- const isLength = E.IsGreaterEqualThan(E.Constant(index), E.Member(value, 'length'));
10
+ const isLength = E.IsLessEqualThan(E.Member(value, 'length'), E.Constant(index));
11
11
  const isSchema = BuildSchema(context, schema, `${value}[${index}]`);
12
12
  const addIndex = context.AddIndex(E.Constant(index));
13
13
  const guarded = context.UseUnevaluated() ? E.And(isSchema, addIndex) : isSchema;
@@ -15,16 +15,16 @@ function BuildItemsSized(context, schema, value) {
15
15
  }));
16
16
  }
17
17
  function CheckItemsSized(context, schema, value) {
18
- return G.Every(schema.items, (schema, index) => {
19
- return G.IsGreaterEqualThan(index, value.length)
18
+ return G.Every(schema.items, 0, (schema, index) => {
19
+ return G.IsLessEqualThan(value.length, index)
20
20
  || (CheckSchema(context, schema, value[index]) && context.AddIndex(index));
21
21
  });
22
22
  }
23
23
  function ErrorItemsSized(context, schemaPath, instancePath, schema, value) {
24
- return G.EveryAll(schema.items, (schema, index) => {
24
+ return G.EveryAll(schema.items, 0, (schema, index) => {
25
25
  const nextSchemaPath = `${schemaPath}/items/${index}`;
26
26
  const nextInstancePath = `${instancePath}/${index}`;
27
- return G.IsGreaterEqualThan(index, value.length)
27
+ return G.IsLessEqualThan(value.length, index)
28
28
  || (ErrorSchema(context, nextSchemaPath, nextInstancePath, schema, value[index]) && context.AddIndex(index));
29
29
  });
30
30
  }
@@ -32,19 +32,22 @@ function ErrorItemsSized(context, schemaPath, instancePath, schema, value) {
32
32
  // ItemsUnsized
33
33
  // ------------------------------------------------------------------
34
34
  function BuildItemsUnsized(context, schema, value) {
35
+ const offset = S.IsPrefixItems(schema) ? schema.prefixItems.length : 0;
35
36
  const isSchema = BuildSchema(context, schema.items, 'element');
36
37
  const addIndex = context.AddIndex('index');
37
38
  const guarded = context.UseUnevaluated() ? E.And(isSchema, addIndex) : isSchema;
38
- return E.Call(E.Member(value, 'every'), [E.ArrowFunction(['element', 'index'], guarded)]);
39
+ return E.Every(value, E.Constant(offset), ['element', 'index'], guarded);
39
40
  }
40
41
  function CheckItemsUnsized(context, schema, value) {
41
- return G.Every(value, (element, index) => {
42
+ const offset = S.IsPrefixItems(schema) ? schema.prefixItems.length : 0;
43
+ return G.Every(value, offset, (element, index) => {
42
44
  return CheckSchema(context, schema.items, element)
43
45
  && context.AddIndex(index);
44
46
  });
45
47
  }
46
48
  function ErrorItemsUnsized(context, schemaPath, instancePath, schema, value) {
47
- return G.EveryAll(value, (element, index) => {
49
+ const offset = S.IsPrefixItems(schema) ? schema.prefixItems.length : 0;
50
+ return G.EveryAll(value, offset, (element, index) => {
48
51
  const nextSchemaPath = `${schemaPath}/items`;
49
52
  const nextInstancePath = `${instancePath}/${index}`;
50
53
  return ErrorSchema(context, nextSchemaPath, nextInstancePath, schema.items, element)
@@ -12,16 +12,16 @@ export function BuildPatternProperties(context, schema, value) {
12
12
  const isSchema = BuildSchema(context, schema, 'value');
13
13
  const addKey = context.AddKey('key');
14
14
  const guarded = context.UseUnevaluated() ? E.Or(notKey, E.And(isSchema, addKey)) : E.Or(notKey, isSchema);
15
- return E.Call(E.Member(E.Entries(value), 'every'), [E.ArrowFunction(['[key, value]'], guarded)]);
15
+ return E.Every(E.Entries(value), E.Constant(0), ['[key, value]', '_'], guarded);
16
16
  }));
17
17
  }
18
18
  // ------------------------------------------------------------------
19
19
  // Check
20
20
  // ------------------------------------------------------------------
21
21
  export function CheckPatternProperties(context, schema, value) {
22
- return G.Every(G.Entries(schema.patternProperties), ([pattern, schema]) => {
22
+ return G.Every(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
23
23
  const regexp = new RegExp(pattern);
24
- return G.Every(G.Entries(value), ([key, value]) => {
24
+ return G.Every(G.Entries(value), 0, ([key, value]) => {
25
25
  return !regexp.test(key) || CheckSchema(context, schema, value) && context.AddKey(key);
26
26
  });
27
27
  });
@@ -30,10 +30,10 @@ export function CheckPatternProperties(context, schema, value) {
30
30
  // Error
31
31
  // ------------------------------------------------------------------
32
32
  export function ErrorPatternProperties(context, schemaPath, instancePath, schema, value) {
33
- return G.EveryAll(G.Entries(schema.patternProperties), ([pattern, schema]) => {
33
+ return G.EveryAll(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
34
34
  const nextSchemaPath = `${schemaPath}/patternProperties/${pattern}`;
35
35
  const regexp = new RegExp(pattern);
36
- return G.EveryAll(G.Entries(value), ([key, value]) => {
36
+ return G.EveryAll(G.Entries(value), 0, ([key, value]) => {
37
37
  const nextInstancePath = `${instancePath}/${key}`;
38
38
  const notKey = !regexp.test(key);
39
39
  return notKey || ErrorSchema(context, nextSchemaPath, nextInstancePath, schema, value) && context.AddKey(key);
@@ -6,7 +6,7 @@ import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
6
6
  // ------------------------------------------------------------------
7
7
  export function BuildPrefixItems(context, schema, value) {
8
8
  return E.ReduceAnd(schema.prefixItems.map((schema, index) => {
9
- const isLength = E.IsGreaterEqualThan(E.Constant(index), E.Member(value, 'length'));
9
+ const isLength = E.IsLessEqualThan(E.Member(value, 'length'), E.Constant(index));
10
10
  const isSchema = BuildSchema(context, schema, `${value}[${index}]`);
11
11
  const addIndex = context.AddIndex(E.Constant(index));
12
12
  const guarded = context.UseUnevaluated() ? E.And(isSchema, addIndex) : isSchema;
@@ -17,8 +17,8 @@ export function BuildPrefixItems(context, schema, value) {
17
17
  // Check
18
18
  // ------------------------------------------------------------------
19
19
  export function CheckPrefixItems(context, schema, value) {
20
- return G.IsEqual(value.length, 0) || G.Every(schema.prefixItems, (schema, index) => {
21
- return G.IsGreaterEqualThan(index, value.length)
20
+ return G.IsEqual(value.length, 0) || G.Every(schema.prefixItems, 0, (schema, index) => {
21
+ return G.IsLessEqualThan(value.length, index)
22
22
  || (CheckSchema(context, schema, value[index]) && context.AddIndex(index));
23
23
  });
24
24
  }
@@ -26,10 +26,10 @@ export function CheckPrefixItems(context, schema, value) {
26
26
  // Error
27
27
  // ------------------------------------------------------------------
28
28
  export function ErrorPrefixItems(context, schemaPath, instancePath, schema, value) {
29
- return G.IsEqual(value.length, 0) || G.EveryAll(schema.prefixItems, (schema, index) => {
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
- return G.IsGreaterEqualThan(index, value.length)
32
+ return G.IsLessEqualThan(value.length, index)
33
33
  || (ErrorSchema(context, nextSchemaPath, nextInstancePath, schema, value[index]) && context.AddIndex(index));
34
34
  });
35
35
  }
@@ -49,7 +49,7 @@ export function BuildProperties(context, schema, value) {
49
49
  // ------------------------------------------------------------------
50
50
  export function CheckProperties(context, schema, value) {
51
51
  const required = S.IsRequired(schema) ? schema.required : [];
52
- const isProperties = G.Every(G.Entries(schema.properties), ([key, schema]) => {
52
+ const isProperties = G.Every(G.Entries(schema.properties), 0, ([key, schema]) => {
53
53
  const isProperty = !G.HasPropertyKey(value, key) || (CheckSchema(context, schema, value[key]) && context.AddKey(key));
54
54
  return IsExactOptional(required, key)
55
55
  ? isProperty
@@ -62,7 +62,7 @@ export function CheckProperties(context, schema, value) {
62
62
  // ------------------------------------------------------------------
63
63
  export function ErrorProperties(context, schemaPath, instancePath, schema, value) {
64
64
  const required = S.IsRequired(schema) ? schema.required : [];
65
- const isProperties = G.EveryAll(G.Entries(schema.properties), ([key, schema]) => {
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
@@ -12,14 +12,14 @@ export function BuildPropertyNames(context, schema, value) {
12
12
  // Check
13
13
  // ------------------------------------------------------------------
14
14
  export function CheckPropertyNames(context, schema, value) {
15
- return G.Every(G.Keys(value), (key) => CheckSchema(context, schema.propertyNames, key));
15
+ return G.Every(G.Keys(value), 0, (key) => CheckSchema(context, schema.propertyNames, key));
16
16
  }
17
17
  // ------------------------------------------------------------------
18
18
  // Error
19
19
  // ------------------------------------------------------------------
20
20
  export function ErrorPropertyNames(context, schemaPath, instancePath, schema, value) {
21
21
  const propertyNames = [];
22
- const isPropertyNames = G.EveryAll(G.Keys(value), (key) => {
22
+ const isPropertyNames = G.EveryAll(G.Keys(value), 0, (key) => {
23
23
  const nextInstancePath = `${instancePath}/${key}`;
24
24
  const nextSchemaPath = `${schemaPath}/propertyNames`;
25
25
  const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
@@ -10,14 +10,14 @@ export function BuildRequired(context, schema, value) {
10
10
  // Check
11
11
  // ------------------------------------------------------------------
12
12
  export function CheckRequired(context, schema, value) {
13
- return G.Every(schema.required, (key) => G.HasPropertyKey(value, key));
13
+ return G.Every(schema.required, 0, (key) => G.HasPropertyKey(value, key));
14
14
  }
15
15
  // ------------------------------------------------------------------
16
16
  // Error
17
17
  // ------------------------------------------------------------------
18
18
  export function ErrorRequired(context, schemaPath, instancePath, schema, value) {
19
19
  const requiredProperties = [];
20
- const isRequired = G.EveryAll(schema.required, (key) => {
20
+ const isRequired = G.EveryAll(schema.required, 0, (key) => {
21
21
  const hasKey = G.HasPropertyKey(value, key);
22
22
  if (!hasKey)
23
23
  requiredProperties.push(key);
@@ -10,7 +10,7 @@ export function BuildUnevaluatedItems(context, schema, value) {
10
10
  const hasIndex = E.Call(E.Member('indices', 'has'), ['index']);
11
11
  const isSchema = BuildSchema(context, schema.unevaluatedItems, 'value');
12
12
  const addIndex = E.Call(E.Member('context', 'AddIndex'), ['index']);
13
- const isEvery = E.Call(E.Member(value, 'every'), [E.ArrowFunction(['value', 'index'], E.And(E.Or(hasIndex, isSchema), addIndex))]);
13
+ const isEvery = E.Every(value, E.Constant(0), ['value', 'index'], E.And(E.Or(hasIndex, isSchema), addIndex));
14
14
  return E.Call(E.ArrowFunction(['context'], E.Statements([
15
15
  E.ConstDeclaration('indices', indices),
16
16
  E.Return(isEvery)
@@ -21,7 +21,7 @@ export function BuildUnevaluatedItems(context, schema, value) {
21
21
  // ------------------------------------------------------------------
22
22
  export function CheckUnevaluatedItems(context, schema, value) {
23
23
  const indices = context.GetIndices();
24
- return G.Every(value, (value, index) => {
24
+ return G.Every(value, 0, (value, index) => {
25
25
  return (indices.has(index) || CheckSchema(context, schema.unevaluatedItems, value))
26
26
  && context.AddIndex(index);
27
27
  });
@@ -32,7 +32,7 @@ export function CheckUnevaluatedItems(context, schema, value) {
32
32
  export function ErrorUnevaluatedItems(context, schemaPath, instancePath, schema, value) {
33
33
  const indices = context.GetIndices();
34
34
  const unevaluatedItems = [];
35
- const isUnevaluatedItems = G.EveryAll(value, (value, index) => {
35
+ const isUnevaluatedItems = G.EveryAll(value, 0, (value, index) => {
36
36
  const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
37
37
  const isEvaluatedItem = (indices.has(index) || ErrorSchema(nextContext, schemaPath, instancePath, schema.unevaluatedItems, value))
38
38
  && context.AddIndex(index);
@@ -10,7 +10,7 @@ export function BuildUnevaluatedProperties(context, schema, value) {
10
10
  const hasKey = E.Call(E.Member('keys', 'has'), ['key']);
11
11
  const addKey = E.Call(E.Member('context', 'AddKey'), ['key']);
12
12
  const isSchema = BuildSchema(context, schema.unevaluatedProperties, `value`);
13
- const isEvery = E.Call(E.Member(E.Entries(value), 'every'), [E.ArrowFunction(['[key, value]'], E.Or(hasKey, E.And(isSchema, addKey)))]);
13
+ const isEvery = E.Every(E.Entries(value), E.Constant(0), ['[key, value]', '_'], E.Or(hasKey, E.And(isSchema, addKey)));
14
14
  return E.Call(E.ArrowFunction(['context'], E.Statements([
15
15
  E.ConstDeclaration('keys', keys),
16
16
  E.Return(isEvery)
@@ -21,7 +21,7 @@ export function BuildUnevaluatedProperties(context, schema, value) {
21
21
  // ------------------------------------------------------------------
22
22
  export function CheckUnevaluatedProperties(context, schema, value) {
23
23
  const keys = context.GetKeys();
24
- return G.Every(G.Entries(value), ([key, value]) => {
24
+ return G.Every(G.Entries(value), 0, ([key, value]) => {
25
25
  return keys.has(key)
26
26
  || (CheckSchema(context, schema.unevaluatedProperties, value) && context.AddKey(key));
27
27
  });
@@ -32,7 +32,7 @@ export function CheckUnevaluatedProperties(context, schema, value) {
32
32
  export function ErrorUnevaluatedProperties(context, schemaPath, instancePath, schema, value) {
33
33
  const keys = context.GetKeys();
34
34
  const unevaluatedProperties = [];
35
- const isUnevaluatedProperties = G.EveryAll(G.Entries(value), ([key, value]) => {
35
+ const isUnevaluatedProperties = G.EveryAll(G.Entries(value), 0, ([key, value]) => {
36
36
  const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
37
37
  const isEvaluatedProperty = keys.has(key)
38
38
  || (ErrorSchema(nextContext, schemaPath, instancePath, schema.unevaluatedProperties, value) && context.AddKey(key));
@@ -10,7 +10,7 @@ import { Guard } from '../../guard/index.mjs';
10
10
  export function IsRefine(value) {
11
11
  return Guard.HasPropertyKey(value, '~refine')
12
12
  && Guard.IsArray(value["~refine"])
13
- && Guard.Every(value['~refine'], value => Guard.IsObject(value)
13
+ && Guard.Every(value['~refine'], 0, value => Guard.IsObject(value)
14
14
  && Guard.HasPropertyKey(value, 'callback')
15
15
  && Guard.HasPropertyKey(value, 'message')
16
16
  && Guard.IsFunction(value.callback)
@@ -20,7 +20,9 @@ export class BaseNotImplemented extends Error {
20
20
  /** Base class for creating extension types. */
21
21
  export class Base {
22
22
  constructor() {
23
- const validator = new BaseValidator((value) => this.Check(value), (value) => this.Errors(value));
23
+ const validator = new BaseValidator(
24
+ // @ts-ignore TS 5.0.4 - unable to derive guard type
25
+ (value) => this.Check(value), (value) => this.Errors(value));
24
26
  const configuration = {
25
27
  writable: false,
26
28
  configurable: false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "A Runtime Type System for JavaScript",
4
- "version": "1.0.25",
4
+ "version": "1.0.27",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"
package/readme.md CHANGED
@@ -19,16 +19,14 @@
19
19
  ## Install
20
20
 
21
21
  ```bash
22
- $ npm install typebox --save # 1.0.0
23
-
24
- $ npm install @sinclair/typebox --save # 0.34.x
22
+ $ npm install typebox
25
23
  ```
26
24
 
27
25
 
28
26
  ## Usage
29
27
 
30
28
  ```typescript
31
- import Type, { type Static } from 'typebox'
29
+ import Type from 'typebox'
32
30
 
33
31
  const T = Type.Object({ // const T = {
34
32
  x: Type.Number(), // type: 'object',
@@ -40,7 +38,7 @@ const T = Type.Object({ // const T = {
40
38
  // }
41
39
  // }
42
40
 
43
- type T = Static<typeof T> // type T = {
41
+ type T = Type.Static<typeof T> // type T = {
44
42
  // x: number,
45
43
  // y: number,
46
44
  // z: number
@@ -68,7 +66,7 @@ License: MIT
68
66
 
69
67
  ## Upgrade
70
68
 
71
- Refer to the following URL for information on upgrading from 0.34.x to 1.0.
69
+ If upgrading from `@sinclair/typebox` refer to the 1.0 migration guide at the following URL.
72
70
 
73
71
  [Migration Guide](https://github.com/sinclairzx81/typebox/blob/main/changelog/1.0.0-migration.md)
74
72
 
@@ -76,7 +74,7 @@ Refer to the following URL for information on upgrading from 0.34.x to 1.0.
76
74
 
77
75
  ## Type
78
76
 
79
- [Documentation](https://sinclairzx81.github.io/typebox/#/docs/type/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAFQJ5gKYBo4G84xauAZRgEMZgBjOAXzgDMoIQ4ByPNAIwgA8WAoPhQgA7AM7wEcALyJ8AOgDyHAFaoKMABQ44O3Xv0HDAeiNwhYidOx8d3AFyy0cgHIBXEB1RQNASkyGAwICTXXZUBxYIFTUYFnQbOCQHZCc3Dy9ffyDsoJCdKFQAR1dgAoATBwBtFl5MFiQ41gAvFgBdeJ0m5Pk0z28fHMHAvLgwRjRYYFRRByw+agGhpeW9EdtZ3HwI4Xc+lhoOlaPltcSNsO3dr33qQ+P77NOu7E20S-SoG4SHn+NTHWo31+wJ0IUBfDCiCsxDIlAAPGEIHREAA+EGg0yQyQyObo9EjexwHYfO54n4jJJEq5QUlk+4jZ7EvpAunHMFAA)
77
+ [Documentation](https://sinclairzx81.github.io/typebox/#/docs/type/overview) | [Example](https://www.typescriptlang.org/play/#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgYwgDsBneBOAXkSIDoB5YgK1Q0YACgDecSVOkzZcuAHoFcOkxbs4YypLIAuTmi4A5AK4hiqKCICUAGnkPHspVMJp9eCAKEw8t7XBI+siGpuaWNvZO0Q4uklCoAI4mwAkAJvoA2ngU9nhIfvgAXngAuv6SRcHcYRZW1jGNcnFwYNhosMCojPpaAL4NTUPDisrSeppwbqge9GZ1eHB9FSOrjS2SQZPTs-OWi8sBa8exY1JV20S74VAHRycP0i1994+PLi+U04gaIahcAGUYABDGDAGgAHmmEAwiAAfCcXN9WBwtG90aMpBM5jcVhiHi0tji6nj8ccWhdiZZXmSRh8gA)
80
78
 
81
79
  TypeBox includes many functions to create Json Schema types. Each function returns a small Json Schema fragment that corresponds to a TypeScript type. TypeBox uses function composition to combine schema fragments into more complex types. It provides a set of functions that are used to model Json Schema schematics as well as a set of functions that model constructs native to JavaScript and TypeScript.
82
80
 
@@ -85,7 +83,7 @@ TypeBox includes many functions to create Json Schema types. Each function retur
85
83
  The following creates a Json Schema type and infers with Static.
86
84
 
87
85
  ```typescript
88
- import Type, { type Static } from 'typebox'
86
+ import Type from 'typebox'
89
87
 
90
88
  const T = Type.Object({ // const T = {
91
89
  x: Type.Number(), // type: 'object',
@@ -97,7 +95,7 @@ const T = Type.Object({ // const T = {
97
95
  // }
98
96
  // }
99
97
 
100
- type T = Static<typeof T> // type T = {
98
+ type T = Type.Static<typeof T> // type T = {
101
99
  // x: number,
102
100
  // y: number,
103
101
  // z: number
@@ -110,16 +108,16 @@ type T = Static<typeof T> // type T = {
110
108
 
111
109
  ## Script
112
110
 
113
- [Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example](https://www.typescriptlang.org/play/?moduleResolution=99&target=99&jsx=0&module=199#code/JYWwDg9gTgLgBAFQJ5gKYBo4G84xauAZRgEMZgBjOAXzgDMoIQ4ByPNAIwgA8WAoPhQgA7AM7wEcALyJ8AOkIUowMDAAUAAxx84cbgC44wgK4gOqKJh1wkhk2YtXdALzunzUOH2oaAlLoDAoOCQ0LCggHoIuCExCWlsa3DklNTAqID2VEMWCA4AK1QKGBZ0JLSKyvTo3ShUAEdjYDqAE0MAbRZeTBYkUtZnFgBdMqqxqozdMEY0WGBUUUMscvHVsMmAg2xcfBz7DxYaUbWT0I3dW22svfcLQ+pj06eA87hXK93WfbuaFeeTjbUP7-VYZIGCETiIgJZBoBRKFTqHCSB5wLTWdoAaTgwGEcAA1qgkBA6IghoYEFihnAAD5GYwAGwZ3j8IIB0ViUMICWWbKeG2urDyhWKpWBfMqGzqjWaqDacE63VYfR6gxG4olaQ20wgs3ICyWGs1KVeW20xtBNSCJGESAA8nQOkaLesrcEcIKWN8oPcnC6Jm6gh7Pl7GQz7s7-cFXrpqZGo9Ugg94wndK9LubU6kY3AbfbHQqU6mc7pg2gbg4fUcvFns4HAmXsl8wxHayb63A423kq9k93wq93pn+yEc3mHU6R2cO6WduXm5XfTWp9GZx956Gma2V5EO12d4nAn2Dy8rUCT6ffnwstCZMQyJQADxZElEAB8IIyN+5Ml5F7gGxbN6tL0kyjwnhslzAXSJhgUWCYbO80Ggcy-4AdE1BAA)
111
+ [Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example](https://www.typescriptlang.org/play/?moduleResolution=99&target=99&jsx=0&module=199#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgYwgDsBneBOAXkSIDoBlGqYGBgAKAAYBvOJThwyALjj0AriGKooAGikykC5avVbpcAF56VaqFIC+ogJQzHT5y9dv3zgPSe4dJi3Y4cWMPULDwp29HQjQFPAhiACtUGhg8DRCIrOzInxkoVABHJWACgBMFAG08Ci08JHT8EzwAXQycjpyomTBsNFhgVEYFYM6x8O7HeSC4GNQ4-Us8OGt28fW3SZ0R2aIFi3Vl1cyN07gt0x25-YMoI5Oz9cnrB8exqJfaBmY4HkDkNC8fiCESSVirOASYyVADScGA9DgAGtUEgIBhEC0FAhYS04AAfRRKAA2xMotgcb3GUT8Pz+HFGVI2k2u+ASyVS6VeTOykwKxVKqAqcGqtXwDTqzTa3J5EUmvQg-Rgg2GQRlsrCF2mknVGo8FxkAEN6EgAPIYKq6vWbPKuSSsvCLQ4rIzWjoGxz2vb4ZSk+5urq2px4q0B3LOY5hrIXXQzUNR85BxzGs0WkXxqMemRe2I+g53F3aBOapNOHPzPN+lYZsMekPFksRtYN9wXMxxlv60twFPmy2d1vd7O7XOO-NHV0D1xZmYO33E-1Tlx1otL8NOSNr9fVrfhz5zX7-bg8GCG5U0AA8c3RvwAfE8fAf6Wrd45JtMnVZCfPm7vJrHPwJIlSV-LdJnbQDvxJMlXxkD4gA)
114
112
 
115
- TypeBox is a type system designed to use Json Schema as an AST for runtime type representation. The Script function provides a full syntactic frontend to the type system and enables Json Schema to be constructed using native TypeScript syntax. TypeBox provides full static and runtime type safety for string-encoded types.
113
+ TypeBox can translate TypeScript syntax into Json Schema. The Script function is a fully type-safe, syntactic frontend to the TypeBox type builder API, allowing Json Schema to be constructed and mapped using TypeScript type expressions encoded as strings.
116
114
 
117
115
  ### Example
118
116
 
119
117
  The following uses Script to construct and map Json Schema.
120
118
 
121
119
  ```typescript
122
- import Type, { type Static } from 'typebox'
120
+ import Type from 'typebox'
123
121
 
124
122
  const T = Type.Script(`{
125
123
  x: number,
@@ -162,7 +160,7 @@ const S = Type.Script({ T }, `{
162
160
  // }
163
161
  // }
164
162
 
165
- type S = Static<typeof S> // type S = {
163
+ type S = Type.Static<typeof S> // type S = {
166
164
  // x: number | null,
167
165
  // y: number | null,
168
166
  // z: number | null
@@ -175,7 +173,7 @@ type S = Static<typeof S> // type S = {
175
173
 
176
174
  [Documentation](https://sinclairzx81.github.io/typebox/#/docs/value/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoUSWOANQEMAbAV3Sx30LVLIHoAbi3ZVKAYwgA7AM7wEcALyIiAOgDyxAFapxMABQBvSnDhkAXCrSqAcqxDFUUfQEoANCbhJLya3YdOrh6mAF4+av6Ozi6UAL4xlPz8cADCABa6ANaUEtJycACCSgwiqKrpWfoIbnCGpvUNjU1NSXCSsvAFlqQQzKiMUsUwUOyeFnAAjDXNM7Nzs57ecABMwXBhcADMcQmtAAqMUDKoOe35AELFTGxlB0eoVTV18y+mrWfw55bGpuNTrwDAfVWr9LFJ7FE1ktVkDYS8QV4wRCnGsNps4RjZgiNuCAlAdpjCVjkrFiqpyUA)
177
175
 
178
- The TypeBox Value module provides functions to Check and Parse JavaScript values. It also includes functions such as Clone, Repair, Encode, Decode, Diff and Patch which perform various structural operations on JavaScript values. This module provides unified support for both Json Schema and Standard Schema.
176
+ The TypeBox Value module provides functions to Check and Parse JavaScript values. It also includes functions such as Clone, Repair, Encode, Decode, Diff and Patch which perform various structural operations on JavaScript values.
179
177
 
180
178
  The Value module is available via optional import.
181
179
 
@@ -218,7 +216,7 @@ const B = Value.Parse(T, { // const B: {
218
216
 
219
217
  [Documentation](https://sinclairzx81.github.io/typebox/#/docs/compile/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYQuYAbApnAvnAMyjTgHIYBPMLAIwgA8B6AYzTEy1IChRJY4AKlRxES5YXXrcurAHYBneMjgBeFGw4AKIdQB0AeRoArLMxiakcK9Zu3bjRnDmKUALjgA1AIYZgAEy8YaAAeBFwAGkFDEzNQrit6dx0sXQA5AFcQGiwoTQBKSLsi4pKrB2tEwQysnPD4uAok4TTM7NyC0s6u8qtGqtba+oAvJr1qtvyuqZKeuBH+mqguXDy86fWNm3LcAD4dri5y5AALUwBrA+d4AEFVFF0T84tNjfKruGv3OghsL1k7mBQdJYeqVACMhReUNs9T6ACY6lZ5gBmZZ5A7lAAKXig8hBMggCngACE7shdNjcVhntDuo53sT3AhQe4IbT2WVHAl3LIBlBEQ13AiOezZn1eYsBSiRaKuXMeXy0TKZds7rp1UA)
220
218
 
221
- The TypeBox Compile module provides functions to convert types into high-performance validators. The compiler is tuned for fast compilation as well as fast validation. This module provides unified support to compile both Json Schema and Standard Schema, however performance optimizations are only possible with Json Schema.
219
+ The TypeBox Compile module provides functions to convert types into high-performance validators. The compiler is tuned for fast compilation as well as fast validation.
222
220
 
223
221
  The Compile module is available via optional import.
224
222