typebox 1.0.26 → 1.0.28

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 (60) hide show
  1. package/build/error/errors.d.mts +7 -11
  2. package/build/schema/engine/_base.d.mts +5 -0
  3. package/build/schema/engine/_base.mjs +26 -0
  4. package/build/schema/engine/index.d.mts +1 -1
  5. package/build/schema/engine/index.mjs +1 -1
  6. package/build/schema/engine/items.mjs +3 -3
  7. package/build/schema/engine/prefixItems.mjs +3 -3
  8. package/build/schema/engine/schema.mjs +5 -5
  9. package/build/schema/types/_base.d.mts +10 -0
  10. package/build/schema/types/_base.mjs +16 -0
  11. package/build/schema/types/index.d.mts +1 -1
  12. package/build/schema/types/index.mjs +1 -1
  13. package/build/schema/types/static.d.mts +7 -11
  14. package/build/system/locale/ar_001.mjs +1 -1
  15. package/build/system/locale/bn_BD.mjs +1 -1
  16. package/build/system/locale/cs_CZ.mjs +1 -1
  17. package/build/system/locale/de_DE.mjs +1 -1
  18. package/build/system/locale/el_GR.mjs +1 -1
  19. package/build/system/locale/en_US.mjs +1 -1
  20. package/build/system/locale/es_419.mjs +1 -1
  21. package/build/system/locale/es_AR.mjs +1 -1
  22. package/build/system/locale/es_ES.mjs +1 -1
  23. package/build/system/locale/es_MX.mjs +1 -1
  24. package/build/system/locale/fa_IR.mjs +1 -1
  25. package/build/system/locale/fil_PH.mjs +1 -1
  26. package/build/system/locale/fr_CA.mjs +1 -1
  27. package/build/system/locale/fr_FR.mjs +1 -1
  28. package/build/system/locale/ha_NG.mjs +1 -1
  29. package/build/system/locale/hi_IN.mjs +1 -1
  30. package/build/system/locale/hu_HU.mjs +1 -1
  31. package/build/system/locale/id_ID.mjs +1 -1
  32. package/build/system/locale/it_IT.mjs +1 -1
  33. package/build/system/locale/ja_JP.mjs +1 -1
  34. package/build/system/locale/ko_KR.mjs +1 -1
  35. package/build/system/locale/ms_MY.mjs +1 -1
  36. package/build/system/locale/nl_NL.mjs +1 -1
  37. package/build/system/locale/pl_PL.mjs +1 -1
  38. package/build/system/locale/pt_BR.mjs +1 -1
  39. package/build/system/locale/pt_PT.mjs +1 -1
  40. package/build/system/locale/ro_RO.mjs +1 -1
  41. package/build/system/locale/ru_RU.mjs +1 -1
  42. package/build/system/locale/sv_SE.mjs +1 -1
  43. package/build/system/locale/sw_TZ.mjs +1 -1
  44. package/build/system/locale/th_TH.mjs +1 -1
  45. package/build/system/locale/tr_TR.mjs +1 -1
  46. package/build/system/locale/uk_UA.mjs +1 -1
  47. package/build/system/locale/ur_PK.mjs +1 -1
  48. package/build/system/locale/vi_VN.mjs +1 -1
  49. package/build/system/locale/yo_NG.mjs +1 -1
  50. package/build/system/locale/zh_Hans.mjs +1 -1
  51. package/build/system/locale/zh_Hant.mjs +1 -1
  52. package/build/system/memory/clone.mjs +5 -5
  53. package/build/type/types/base.d.mts +7 -34
  54. package/build/type/types/base.mjs +2 -17
  55. package/package.json +1 -1
  56. package/readme.md +13 -15
  57. package/build/schema/engine/_standard.d.mts +0 -5
  58. package/build/schema/engine/_standard.mjs +0 -27
  59. package/build/schema/types/_standard.d.mts +0 -14
  60. package/build/schema/types/_standard.mjs +0 -19
@@ -1,4 +1,4 @@
1
- export type TValidationError = TAdditionalPropertiesError | TAnyOfError | TBooleanError | TConstError | TContainsError | TDependenciesError | TDependentRequiredError | TEnumError | TExclusiveMaximumError | TExclusiveMinimumError | TFormatError | TIfError | TMaximumError | TMaxItemsError | TMaxLengthError | TMaxPropertiesError | TMinimumError | TMinItemsError | TMinLengthError | TMinPropertiesError | TMultipleOfError | TNotError | TOneOfError | TPatternError | TPropertyNamesError | TRefineError | TRequiredError | TStandardSchemaV1Error | TTypeError | TUnevaluatedItemsError | TUnevaluatedPropertiesError | TUniqueItemsError;
1
+ export type TValidationError = TAdditionalPropertiesError | TAnyOfError | TBaseError | TBooleanError | TConstError | TContainsError | TDependenciesError | TDependentRequiredError | TEnumError | TExclusiveMaximumError | TExclusiveMinimumError | TFormatError | TIfError | TMaximumError | TMaxItemsError | TMaxLengthError | TMaxPropertiesError | TMinimumError | TMinItemsError | TMinLengthError | TMinPropertiesError | TMultipleOfError | TNotError | TOneOfError | TPatternError | TPropertyNamesError | TRefineError | TRequiredError | TTypeError | TUnevaluatedItemsError | TUnevaluatedPropertiesError | TUniqueItemsError;
2
2
  export declare function IsValidationError(value: unknown): value is TValidationError;
3
3
  export type TLocalizedValidationError = TValidationError & {
4
4
  message: string;
@@ -21,6 +21,12 @@ export interface TAnyOfError extends TValidationErrorBase {
21
21
  keyword: 'anyOf';
22
22
  params: {};
23
23
  }
24
+ export interface TBaseError extends TValidationErrorBase {
25
+ keyword: '~base';
26
+ params: {
27
+ errors: object[];
28
+ };
29
+ }
24
30
  export interface TBooleanError extends TValidationErrorBase {
25
31
  keyword: 'boolean';
26
32
  params: {};
@@ -182,16 +188,6 @@ export interface TRequiredError extends TValidationErrorBase {
182
188
  requiredProperties: string[];
183
189
  };
184
190
  }
185
- export interface TStandardSchemaV1Error extends TValidationErrorBase {
186
- keyword: '~standard';
187
- params: {
188
- vendor: string;
189
- issues: {
190
- message: string;
191
- path?: string[];
192
- }[];
193
- };
194
- }
195
191
  export interface TTypeError extends TValidationErrorBase {
196
192
  keyword: 'type';
197
193
  params: {
@@ -0,0 +1,5 @@
1
+ import * as S from '../types/index.mjs';
2
+ import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
+ export declare function BuildBase(context: BuildContext, schema: S.XBase, value: string): string;
4
+ export declare function CheckBase(context: CheckContext, schema: S.XBase, value: unknown): boolean;
5
+ export declare function ErrorBase(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XBase, value: unknown): boolean;
@@ -0,0 +1,26 @@
1
+ // deno-fmt-ignore-file
2
+ import * as V from './_externals.mjs';
3
+ import { EmitGuard as E } from '../../guard/index.mjs';
4
+ // ------------------------------------------------------------------
5
+ // Build
6
+ // ------------------------------------------------------------------
7
+ export function BuildBase(context, schema, value) {
8
+ return E.Call(E.Member(E.Member(V.CreateExternalVariable(schema), '~base'), 'check'), [value]);
9
+ }
10
+ // ------------------------------------------------------------------
11
+ // Check
12
+ // ------------------------------------------------------------------
13
+ export function CheckBase(context, schema, value) {
14
+ return schema['~base'].check(value);
15
+ }
16
+ // ------------------------------------------------------------------
17
+ // Error
18
+ // ------------------------------------------------------------------
19
+ export function ErrorBase(context, schemaPath, instancePath, schema, value) {
20
+ return schema['~base'].check(value) || context.AddError({
21
+ keyword: '~base',
22
+ schemaPath,
23
+ instancePath,
24
+ params: { errors: schema['~base'].errors(value) },
25
+ });
26
+ }
@@ -2,8 +2,8 @@ export * from './_context.mjs';
2
2
  export * from './_functions.mjs';
3
3
  export * from './_reducer.mjs';
4
4
  export * from './_externals.mjs';
5
+ export * from './_base.mjs';
5
6
  export * from './_refine.mjs';
6
- export * from './_standard.mjs';
7
7
  export * from './additionalProperties.mjs';
8
8
  export * from './additionalItems.mjs';
9
9
  export * from './allOf.mjs';
@@ -8,8 +8,8 @@ export * from './_externals.mjs';
8
8
  // ------------------------------------------------------------------
9
9
  // Schematics
10
10
  // ------------------------------------------------------------------
11
+ export * from './_base.mjs';
11
12
  export * from './_refine.mjs';
12
- export * from './_standard.mjs';
13
13
  export * from './additionalProperties.mjs';
14
14
  export * from './additionalItems.mjs';
15
15
  export * from './allOf.mjs';
@@ -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;
@@ -16,7 +16,7 @@ function BuildItemsSized(context, schema, value) {
16
16
  }
17
17
  function CheckItemsSized(context, schema, value) {
18
18
  return G.Every(schema.items, 0, (schema, index) => {
19
- return G.IsGreaterEqualThan(index, value.length)
19
+ return G.IsLessEqualThan(value.length, index)
20
20
  || (CheckSchema(context, schema, value[index]) && context.AddIndex(index));
21
21
  });
22
22
  }
@@ -24,7 +24,7 @@ function ErrorItemsSized(context, schemaPath, instancePath, schema, value) {
24
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
  }
@@ -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;
@@ -18,7 +18,7 @@ export function BuildPrefixItems(context, schema, value) {
18
18
  // ------------------------------------------------------------------
19
19
  export function CheckPrefixItems(context, schema, value) {
20
20
  return G.IsEqual(value.length, 0) || G.Every(schema.prefixItems, 0, (schema, index) => {
21
- return G.IsGreaterEqualThan(index, value.length)
21
+ return G.IsLessEqualThan(value.length, index)
22
22
  || (CheckSchema(context, schema, value[index]) && context.AddIndex(index));
23
23
  });
24
24
  }
@@ -29,7 +29,7 @@ export function ErrorPrefixItems(context, schemaPath, instancePath, schema, valu
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
- 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
  }
@@ -1,8 +1,8 @@
1
1
  // deno-fmt-ignore-file
2
2
  import * as S from '../types/index.mjs';
3
3
  import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
4
- import { BuildStandardSchemaV1, CheckStandardSchemaV1, ErrorStandardSchemaV1 } from './_standard.mjs';
5
4
  import { BuildRefine, CheckRefine, ErrorRefine } from './_refine.mjs';
5
+ import { BuildBase, CheckBase, ErrorBase } from './_base.mjs';
6
6
  import { BuildAdditionalItems, CheckAdditionalItems, ErrorAdditionalItems } from './additionalItems.mjs';
7
7
  import { BuildAdditionalProperties, CheckAdditionalProperties, ErrorAdditionalProperties } from './additionalProperties.mjs';
8
8
  import { BuildAllOf, CheckAllOf, ErrorAllOf } from './allOf.mjs';
@@ -204,12 +204,12 @@ export function BuildSchema(context, schema, value) {
204
204
  }
205
205
  if (S.IsRef(schema))
206
206
  conditions.push(BuildRef(context, schema, value));
207
+ if (S.IsBase(schema))
208
+ conditions.push(BuildBase(context, schema, value));
207
209
  if (S.IsConst(schema))
208
210
  conditions.push(BuildConst(context, schema, value));
209
211
  if (S.IsEnum(schema))
210
212
  conditions.push(BuildEnum(context, schema, value));
211
- if (S.IsStandardSchemaV1(schema))
212
- conditions.push(BuildStandardSchemaV1(context, schema, value));
213
213
  if (S.IsIf(schema))
214
214
  conditions.push(BuildIf(context, schema, value));
215
215
  if (S.IsNot(schema))
@@ -262,9 +262,9 @@ export function CheckSchema(context, schema, value) {
262
262
  (!S.IsMinimum(schema) || CheckMinimum(context, schema, value)) &&
263
263
  (!S.IsMultipleOf(schema) || CheckMultipleOf(context, schema, value)))) &&
264
264
  (!S.IsRef(schema) || CheckRef(context, schema, value)) &&
265
+ (!S.IsBase(schema) || CheckBase(context, schema, value)) &&
265
266
  (!S.IsConst(schema) || CheckConst(context, schema, value)) &&
266
267
  (!S.IsEnum(schema) || CheckEnum(context, schema, value)) &&
267
- (!S.IsStandardSchemaV1(schema) || CheckStandardSchemaV1(context, schema, value)) &&
268
268
  (!S.IsIf(schema) || CheckIf(context, schema, value)) &&
269
269
  (!S.IsNot(schema) || CheckNot(context, schema, value)) &&
270
270
  (!S.IsAllOf(schema) || CheckAllOf(context, schema, value)) &&
@@ -308,9 +308,9 @@ export function ErrorSchema(context, schemaPath, instancePath, schema, value) {
308
308
  +(!S.IsMinimum(schema) || ErrorMinimum(context, schemaPath, instancePath, schema, value)) &
309
309
  +(!S.IsMultipleOf(schema) || ErrorMultipleOf(context, schemaPath, instancePath, schema, value)))) &
310
310
  +(!S.IsRef(schema) || ErrorRef(context, schemaPath, instancePath, schema, value)) &
311
+ +(!S.IsBase(schema) || ErrorBase(context, schemaPath, instancePath, schema, value)) &
311
312
  +(!S.IsConst(schema) || ErrorConst(context, schemaPath, instancePath, schema, value)) &
312
313
  +(!S.IsEnum(schema) || ErrorEnum(context, schemaPath, instancePath, schema, value)) &
313
- +(!S.IsStandardSchemaV1(schema) || ErrorStandardSchemaV1(context, schemaPath, instancePath, schema, value)) &
314
314
  +(!S.IsIf(schema) || ErrorIf(context, schemaPath, instancePath, schema, value)) &
315
315
  +(!S.IsNot(schema) || ErrorNot(context, schemaPath, instancePath, schema, value)) &
316
316
  +(!S.IsAllOf(schema) || ErrorAllOf(context, schemaPath, instancePath, schema, value)) &
@@ -0,0 +1,10 @@
1
+ import type { XSchema } from './schema.mjs';
2
+ export interface XBaseValidator<Value extends unknown = unknown> {
3
+ check(value: unknown): value is Value;
4
+ errors(value: unknown): object[];
5
+ }
6
+ export interface XBase<Value extends unknown = unknown> {
7
+ '~base': XBaseValidator<Value>;
8
+ }
9
+ export declare function IsBaseValidator(value: unknown): value is XBaseValidator;
10
+ export declare function IsBase(value: XSchema): value is XBase;
@@ -0,0 +1,16 @@
1
+ // deno-fmt-ignore-file
2
+ import { Guard } from '../../guard/index.mjs';
3
+ // ------------------------------------------------------------------
4
+ // Guard
5
+ // ------------------------------------------------------------------
6
+ export function IsBaseValidator(value) {
7
+ return Guard.IsObject(value)
8
+ && Guard.HasPropertyKey(value, 'check')
9
+ && Guard.HasPropertyKey(value, 'errors')
10
+ && Guard.IsFunction(value.check)
11
+ && Guard.IsFunction(value.errors);
12
+ }
13
+ export function IsBase(value) {
14
+ return Guard.HasPropertyKey(value, '~base')
15
+ && IsBaseValidator(value['~base']);
16
+ }
@@ -1,5 +1,5 @@
1
1
  export * from './_refine.mjs';
2
- export * from './_standard.mjs';
2
+ export * from './_base.mjs';
3
3
  export * from './additionalProperties.mjs';
4
4
  export * from './additionalItems.mjs';
5
5
  export * from './allOf.mjs';
@@ -2,7 +2,7 @@
2
2
  // Extensions
3
3
  // ------------------------------------------------------------------
4
4
  export * from './_refine.mjs';
5
- export * from './_standard.mjs';
5
+ export * from './_base.mjs';
6
6
  // ------------------------------------------------------------------
7
7
  // Standard
8
8
  // ------------------------------------------------------------------
@@ -1,5 +1,5 @@
1
- import type { XSchemaLike } from '../types/schema.mjs';
2
- import type { XStandardSchemaV1, XStandardValidatorV1 } from './_standard.mjs';
1
+ import type { XBase } from './_base.mjs';
2
+ import type { XSchemaLike } from './schema.mjs';
3
3
  import type { XAdditionalProperties } from './additionalProperties.mjs';
4
4
  import type { XAnyOf } from './anyOf.mjs';
5
5
  import type { XAllOf } from './allOf.mjs';
@@ -11,11 +11,7 @@ import type { XPatternProperties } from './patternProperties.mjs';
11
11
  import type { XPrefixItems } from './prefixItems.mjs';
12
12
  import type { XProperties } from './properties.mjs';
13
13
  import type { XRequired } from './required.mjs';
14
- export type XStaticStandardSchemaV1<Validator extends XStandardValidatorV1, ValidateResult extends unknown = ReturnType<Validator['validate']>, RemoveAsync extends unknown = Exclude<ValidateResult, Promise<any>>, RemoveIssue extends unknown = Exclude<RemoveAsync, {
15
- issues: any;
16
- }>, Result extends unknown = RemoveIssue extends {
17
- value: infer Value;
18
- } ? Value : unknown> = Result;
14
+ export type XStaticBase<Value extends unknown> = Value;
19
15
  type XStaticAdditionalProperties<Schema extends XSchemaLike, Result extends Record<PropertyKey, unknown> = (Schema extends true ? {
20
16
  [key: string]: unknown;
21
17
  } : Schema extends false ? {} : {
@@ -104,14 +100,14 @@ type XStaticEvaluate<Schema extends unknown, Result extends unknown = Schema ext
104
100
  [Key in keyof Schema]: Schema[Key];
105
101
  } : Schema> = Result;
106
102
  type XStaticJsonSchema<Schema extends unknown, Keywords extends unknown[] = XStaticKeywords<Schema>, Intersect extends unknown = XStaticKeywordIntersect<Keywords>, Result extends unknown = XStaticEvaluate<Intersect>> = Result;
107
- /** Statically infers a JSON Schema or Standard Schema */
108
- export type XStaticType<Schema extends XSchemaLike, Result extends unknown = (Schema extends XStandardSchemaV1<infer Validator extends XStandardValidatorV1> ? XStaticStandardSchemaV1<Validator> : XStaticJsonSchema<Schema>)> = Result;
103
+ /** Statically infers a JSON Schema or Validator */
104
+ export type XStaticType<Schema extends XSchemaLike, Result extends unknown = (Schema extends XBase<infer Value> ? Value : XStaticJsonSchema<Schema>)> = Result;
109
105
  type XStaticMutableTuple<Schemas extends readonly unknown[]> = (Schemas extends [infer Left, ...infer Right extends unknown[]] ? [XStaticMutable<Left>, ...XStaticMutableTuple<Right>] : []);
110
106
  type XStaticMutableArray<Schema extends unknown, Result extends unknown[] = XStaticMutable<Schema>[]> = Result;
111
107
  type XStaticMutableObject<Schema extends object, Result extends Record<PropertyKey, unknown> = {
112
108
  -readonly [K in keyof Schema]: XStaticMutable<Schema[K]>;
113
109
  }> = Result;
114
- type XStaticMutable<Schema> = (Schema extends XStandardSchemaV1 ? Schema : Schema extends readonly [...infer Schemas extends unknown[]] ? XStaticMutableTuple<Schemas> : Schema extends readonly (infer Schema)[] ? XStaticMutableArray<Schema> : Schema extends object ? XStaticMutableObject<Schema> : Schema);
115
- /** Statically infers a JSON Schema or Standard Schema */
110
+ type XStaticMutable<Schema> = (Schema extends XBase ? Schema : Schema extends readonly [...infer Schemas extends unknown[]] ? XStaticMutableTuple<Schemas> : Schema extends readonly (infer Schema)[] ? XStaticMutableArray<Schema> : Schema extends object ? XStaticMutableObject<Schema> : Schema);
111
+ /** Statically infers a JSON Schema */
116
112
  export type XStatic<Schema extends XSchemaLike, Mutable extends XSchemaLike = XStaticMutable<Schema>, Result extends unknown = XStaticType<Mutable>> = Result;
117
113
  export {};
@@ -34,7 +34,7 @@ export function ar_001(error) {
34
34
  case 'unevaluatedProperties': return 'يجب ألا يحتوي على خصائص غير مقيمة';
35
35
  case 'uniqueItems': return `يجب ألا يحتوي على عناصر مكررة`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `يجب أن يتطابق مع مخطط ${error.params.vendor}`;
37
+ case '~base': return `يجب أن يتطابق مع مخطط ${'Base'}`;
38
38
  default: return 'حدث خطأ غير معروف في التحقق من الصحة';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function bn_BD(error) {
34
34
  case 'unevaluatedProperties': return 'অবমূল্যায়িত বৈশিষ্ট্য থাকতে পারবে না';
35
35
  case 'uniqueItems': return `অনুলিপি আইটেম থাকতে পারবে না`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `${error.params.vendor} স্কিমার সাথে মিলতে হবে`;
37
+ case '~base': return `${'Base'} স্কিমার সাথে মিলতে হবে`;
38
38
  default: return 'একটি অজানা বৈধকরণ ত্রুটি ঘটেছে';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function cs_CZ(error) {
34
34
  case 'unevaluatedProperties': return 'nesmí mít nevyhodnocené vlastnosti';
35
35
  case 'uniqueItems': return `nesmí mít duplicitní položky`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `musí odpovídat schématu ${error.params.vendor}`;
37
+ case '~base': return `musí odpovídat schématu ${'Base'}`;
38
38
  default: return 'došlo k neznámé chybě ověření';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function de_DE(error) {
34
34
  case 'unevaluatedProperties': return 'darf keine unbewerteten Eigenschaften haben';
35
35
  case 'uniqueItems': return `darf keine doppelten Elemente haben`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `muss mit dem ${error.params.vendor}-Schema übereinstimmen`;
37
+ case '~base': return `muss mit dem ${'Base'}-Schema übereinstimmen`;
38
38
  default: return 'ein unbekannter Validierungsfehler ist aufgetreten';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function el_GR(error) {
34
34
  case 'unevaluatedProperties': return 'δεν πρέπει να έχει μη αξιολογημένες ιδιότητες';
35
35
  case 'uniqueItems': return `δεν πρέπει να έχει διπλά στοιχεία`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `πρέπει να ταιριάζει με το σχήμα ${error.params.vendor}`;
37
+ case '~base': return `πρέπει να ταιριάζει με το σχήμα ${'Base'}`;
38
38
  default: return 'προέκυψε ένα άγνωστο σφάλμα επικύρωσης';
39
39
  }
40
40
  }
@@ -33,7 +33,7 @@ export function en_US(error) {
33
33
  case 'unevaluatedProperties': return 'must not have unevaluated properties';
34
34
  case 'uniqueItems': return `must not have duplicate items`;
35
35
  case '~refine': return error.params.message;
36
- case '~standard': return `must match against ${error.params.vendor} schema`;
36
+ case '~base': return `must match against ${'Base'} schema`;
37
37
  // deno-coverage-ignore - unreachable
38
38
  default: return 'an unknown validation error occurred';
39
39
  }
@@ -34,7 +34,7 @@ export function es_419(error) {
34
34
  case 'unevaluatedProperties': return 'no debe tener propiedades no evaluadas';
35
35
  case 'uniqueItems': return `no debe tener elementos duplicados`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `debe coincidir con el esquema de ${error.params.vendor}`;
37
+ case '~base': return `debe coincidir con el esquema de ${'Base'}`;
38
38
  default: return 'ocurrió un error de validación desconocido';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function es_AR(error) {
34
34
  case 'unevaluatedProperties': return 'no debe tener propiedades no evaluadas';
35
35
  case 'uniqueItems': return `no debe tener elementos duplicados`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `debe coincidir con el esquema de ${error.params.vendor}`;
37
+ case '~base': return `debe coincidir con el esquema de ${'Base'}`;
38
38
  default: return 'ocurrió un error de validación desconocido';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function es_ES(error) {
34
34
  case 'unevaluatedProperties': return 'no debe tener propiedades no evaluadas';
35
35
  case 'uniqueItems': return `no debe tener elementos duplicados`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `debe coincidir con el esquema de ${error.params.vendor}`;
37
+ case '~base': return `debe coincidir con el esquema de ${'Base'}`;
38
38
  default: return 'ha ocurrido un error de validación desconocido';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function es_MX(error) {
34
34
  case 'unevaluatedProperties': return 'no debe tener propiedades no evaluadas';
35
35
  case 'uniqueItems': return `no debe tener elementos duplicados`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `debe coincidir con el esquema de ${error.params.vendor}`;
37
+ case '~base': return `debe coincidir con el esquema de ${'Base'}`;
38
38
  default: return 'ocurrió un error de validación desconocido';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function fa_IR(error) {
34
34
  case 'unevaluatedProperties': return 'نباید ویژگی‌های ارزیابی نشده داشته باشد';
35
35
  case 'uniqueItems': return `نباید آیتم‌های تکراری داشته باشد`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `باید با طرح‌واره ${error.params.vendor} مطابقت داشته باشد`;
37
+ case '~base': return `باید با طرح‌واره ${'Base'} مطابقت داشته باشد`;
38
38
  default: return 'یک خطای اعتبارسنجی ناشناخته رخ داده است';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function fil_PH(error) {
34
34
  case 'unevaluatedProperties': return 'hindi dapat magkaroon ng mga hindi pa nasusuring katangian';
35
35
  case 'uniqueItems': return `hindi dapat magkaroon ng mga duplicate na item`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `dapat tumugma laban sa ${error.params.vendor} schema`;
37
+ case '~base': return `dapat tumugma laban sa ${'Base'} schema`;
38
38
  default: return 'nagkaroon ng hindi kilalang error sa pagpapatunay';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function fr_CA(error) {
34
34
  case 'unevaluatedProperties': return 'ne doit pas avoir de propriétés non évaluées';
35
35
  case 'uniqueItems': return `ne doit pas avoir d'éléments en double`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `doit correspondre au schéma ${error.params.vendor}`;
37
+ case '~base': return `doit correspondre au schéma ${'Base'}`;
38
38
  default: return 'une erreur de validation inconnue est survenue';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function fr_FR(error) {
34
34
  case 'unevaluatedProperties': return 'ne doit pas avoir de propriétés non évaluées';
35
35
  case 'uniqueItems': return `ne doit pas avoir d'éléments en double`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `doit correspondre au schéma ${error.params.vendor}`;
37
+ case '~base': return `doit correspondre au schéma ${'Base'}`;
38
38
  default: return 'une erreur de validation inconnue est survenue';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function ha_NG(error) {
34
34
  case 'unevaluatedProperties': return 'kada ya kasance yana da kaddarorin da ba a kimanta su ba';
35
35
  case 'uniqueItems': return `kada ya kasance yana da abubuwan da suka yi kama`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `dole ne ya dace da tsarin ${error.params.vendor}`;
37
+ case '~base': return `dole ne ya dace da tsarin ${'Base'}`;
38
38
  default: return 'an sami kuskuren tabbatarwa da ba a sani ba';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function hi_IN(error) {
34
34
  case 'unevaluatedProperties': return 'में अप्रयुक्त गुण नहीं होने चाहिए';
35
35
  case 'uniqueItems': return `में डुप्लिकेट आइटम नहीं होने चाहिए`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `${error.params.vendor} स्कीमा के विरुद्ध मेल खाना चाहिए`;
37
+ case '~base': return `${'Base'} स्कीमा के विरुद्ध मेल खाना चाहिए`;
38
38
  default: return 'एक अज्ञात सत्यापन त्रुटि हुई';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function hu_HU(error) {
34
34
  case 'unevaluatedProperties': return 'nem lehetnek nem értékelt tulajdonságai';
35
35
  case 'uniqueItems': return `nem lehetnek ismétlődő elemei`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `meg kell egyeznie a(z) ${error.params.vendor} sémával`;
37
+ case '~base': return `meg kell egyeznie a(z) ${'Base'} sémával`;
38
38
  default: return 'ismeretlen validációs hiba történt';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function id_ID(error) {
34
34
  case 'unevaluatedProperties': return 'tidak boleh memiliki properti yang belum dievaluasi';
35
35
  case 'uniqueItems': return `tidak boleh memiliki item duplikat`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `harus cocok dengan skema ${error.params.vendor}`;
37
+ case '~base': return `harus cocok dengan skema ${'Base'}`;
38
38
  default: return 'terjadi kesalahan validasi yang tidak diketahui';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function it_IT(error) {
34
34
  case 'unevaluatedProperties': return 'non deve avere proprietà non valutate';
35
35
  case 'uniqueItems': return `non deve avere elementi duplicati`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `deve corrispondere allo schema ${error.params.vendor}`;
37
+ case '~base': return `deve corrispondere allo schema ${'Base'}`;
38
38
  default: return 'si è verificato un errore di validazione sconosciuto';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function ja_JP(error) {
34
34
  case 'unevaluatedProperties': return '未評価のプロパティを持つことはできません';
35
35
  case 'uniqueItems': return `重複するアイテムを持つことはできません`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `${error.params.vendor} スキーマと一致する必要があります`;
37
+ case '~base': return `${'Base'} スキーマと一致する必要があります`;
38
38
  default: return '不明なバリデーションエラーが発生しました';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function ko_KR(error) {
34
34
  case 'unevaluatedProperties': return '평가되지 않은 속성을 가질 수 없습니다';
35
35
  case 'uniqueItems': return `중복 항목을 가질 수 없습니다`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `${error.params.vendor} 스키마와 일치해야 합니다`;
37
+ case '~base': return `${'Base'} 스키마와 일치해야 합니다`;
38
38
  default: return '알 수 없는 유효성 검사 오류가 발생했습니다';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function ms_MY(error) {
34
34
  case 'unevaluatedProperties': return 'tidak boleh mempunyai sifat yang tidak dinilai';
35
35
  case 'uniqueItems': return `tidak boleh mempunyai item pendua`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `mesti sepadan dengan skema ${error.params.vendor}`;
37
+ case '~base': return `mesti sepadan dengan skema ${'Base'}`;
38
38
  default: return 'ralat pengesahan yang tidak diketahui berlaku';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function nl_NL(error) {
34
34
  case 'unevaluatedProperties': return 'mag geen onbeoordeelde eigenschappen hebben';
35
35
  case 'uniqueItems': return `mag geen dubbele items hebben`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `moet overeenkomen met ${error.params.vendor} schema`;
37
+ case '~base': return `moet overeenkomen met ${'Base'} schema`;
38
38
  default: return 'er is een onbekende validatiefout opgetreden';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function pl_PL(error) {
34
34
  case 'unevaluatedProperties': return 'nie może mieć nieewaluowanych właściwości';
35
35
  case 'uniqueItems': return `nie może zawierać zduplikowanych elementów`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `musi pasować do schematu ${error.params.vendor}`;
37
+ case '~base': return `musi pasować do schematu ${'Base'}`;
38
38
  default: return 'wystąpił nieznany błąd walidacji';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function pt_BR(error) {
34
34
  case 'unevaluatedProperties': return 'não deve ter propriedades não avaliadas';
35
35
  case 'uniqueItems': return `não deve ter itens duplicados`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `deve corresponder ao esquema ${error.params.vendor}`;
37
+ case '~base': return `deve corresponder ao esquema ${'Base'}`;
38
38
  default: return 'ocorreu um erro de validação desconhecido';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function pt_PT(error) {
34
34
  case 'unevaluatedProperties': return 'não deve ter propriedades não avaliadas';
35
35
  case 'uniqueItems': return `não deve ter itens duplicados`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `deve corresponder ao esquema ${error.params.vendor}`;
37
+ case '~base': return `deve corresponder ao esquema ${'Base'}`;
38
38
  default: return 'ocorreu um erro de validação desconhecido';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function ro_RO(error) {
34
34
  case 'unevaluatedProperties': return 'nu trebuie să aibă proprietăți neevaluate';
35
35
  case 'uniqueItems': return `nu trebuie să aibă elemente duplicate`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `trebuie să se potrivească cu schema ${error.params.vendor}`;
37
+ case '~base': return `trebuie să se potrivească cu schema ${'Base'}`;
38
38
  default: return 'a apărut o eroare de validare necunoscută';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function ru_RU(error) {
34
34
  case 'unevaluatedProperties': return 'не должно быть нерассмотренных свойств';
35
35
  case 'uniqueItems': return `не должно быть повторяющихся элементов`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `должен соответствовать схеме ${error.params.vendor}`;
37
+ case '~base': return `должен соответствовать схеме ${'Base'}`;
38
38
  default: return 'произошла неизвестная ошибка валидации';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function sv_SE(error) {
34
34
  case 'unevaluatedProperties': return 'får inte ha oidentifierade egenskaper';
35
35
  case 'uniqueItems': return `får inte ha dubbletter`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `måste matcha mot ${error.params.vendor} schema`;
37
+ case '~base': return `måste matcha mot ${'Base'} schema`;
38
38
  default: return 'ett okänt valideringsfel uppstod';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function sw_TZ(error) {
34
34
  case 'unevaluatedProperties': return 'haipaswi kuwa na sifa zisizotathminiwa';
35
35
  case 'uniqueItems': return `haipaswi kuwa na vitu vilivyofanana`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `lazima ilingane na schema ya ${error.params.vendor}`;
37
+ case '~base': return `lazima ilingane na schema ya ${'Base'}`;
38
38
  default: return 'hitilafu isiyojulikana ya uthibitishaji imetokea';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function th_TH(error) {
34
34
  case 'unevaluatedProperties': return 'ต้องไม่มีคุณสมบัติที่ยังไม่ได้ประเมิน';
35
35
  case 'uniqueItems': return `ต้องไม่มีรายการที่ซ้ำกัน`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `ต้องตรงกับ Schema ของ ${error.params.vendor}`;
37
+ case '~base': return `ต้องตรงกับ Schema ของ ${'Base'}`;
38
38
  default: return 'เกิดข้อผิดพลาดในการตรวจสอบที่ไม่รู้จัก';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function tr_TR(error) {
34
34
  case 'unevaluatedProperties': return 'değerlendirilmemiş özelliklere sahip olmamalıdır';
35
35
  case 'uniqueItems': return `yinelenen öğelere sahip olmamalıdır`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `${error.params.vendor} şemasına göre eşleşmelidir`;
37
+ case '~base': return `${'Base'} şemasına göre eşleşmelidir`;
38
38
  default: return 'bilinmeyen bir doğrulama hatası oluştu';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function uk_UA(error) {
34
34
  case 'unevaluatedProperties': return 'не повинно мати неперевірених властивостей';
35
35
  case 'uniqueItems': return `не повинно мати повторюваних елементів`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `має відповідати схемі ${error.params.vendor}`;
37
+ case '~base': return `має відповідати схемі ${'Base'}`;
38
38
  default: return 'виникла невідома помилка валідації';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function ur_PK(error) {
34
34
  case 'unevaluatedProperties': return 'غیر تشخیص شدہ خصوصیات نہیں ہونی چاہئیں';
35
35
  case 'uniqueItems': return `ڈپلیکیٹ آئٹمز نہیں ہونے چاہئیں`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `${error.params.vendor} اسکیما سے مماثل ہونا چاہیے`;
37
+ case '~base': return `${'Base'} اسکیما سے مماثل ہونا چاہیے`;
38
38
  default: return 'تصدیق میں ایک نامعلوم خرابی پیش آئی';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function vi_VN(error) {
34
34
  case 'unevaluatedProperties': return 'không được có các thuộc tính chưa được đánh giá';
35
35
  case 'uniqueItems': return `không được có các mục trùng lặp`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `phải khớp với schema ${error.params.vendor}`;
37
+ case '~base': return `phải khớp với schema ${'Base'}`;
38
38
  default: return 'đã xảy ra lỗi xác thực không xác định';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function yo_NG(error) {
34
34
  case 'unevaluatedProperties': return 'ko gbọdọ ni awọn ohun-ini ti ko ṣe iṣiro';
35
35
  case 'uniqueItems': return `ko gbọdọ ni awọn ohun elo ẹda`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `gbọdọ baramu àlàyé ${error.params.vendor}`;
37
+ case '~base': return `gbọdọ baramu àlàyé ${'Base'}`;
38
38
  default: return 'aṣiṣe ijẹrisi aimọ waye';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function zh_Hans(error) {
34
34
  case 'unevaluatedProperties': return '不得有未评估的属性';
35
35
  case 'uniqueItems': return `不得有重复项`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `必须匹配 ${error.params.vendor} 模式`;
37
+ case '~base': return `必须匹配 ${'Base'} 模式`;
38
38
  default: return '发生未知验证错误';
39
39
  }
40
40
  }
@@ -34,7 +34,7 @@ export function zh_Hant(error) {
34
34
  case 'unevaluatedProperties': return '不得有未評估的屬性';
35
35
  case 'uniqueItems': return `不得有重複項目`;
36
36
  case '~refine': return error.params.message;
37
- case '~standard': return `必須匹配 ${error.params.vendor} 模式`;
37
+ case '~base': return `必須匹配 ${'Base'} 模式`;
38
38
  default: return '發生未知驗證錯誤';
39
39
  }
40
40
  }
@@ -2,12 +2,12 @@
2
2
  import { Guard } from '../../guard/index.mjs';
3
3
  import { Metrics } from './metrics.mjs';
4
4
  // ------------------------------------------------------------------
5
- // StandardSchema
5
+ // Base
6
6
  // ------------------------------------------------------------------
7
- function IsStandardSchema(value) {
8
- return Guard.IsObject(value) && Guard.HasPropertyKey(value, '~standard');
7
+ function IsBase(value) {
8
+ return Guard.IsObject(value) && Guard.HasPropertyKey(value, '~base');
9
9
  }
10
- function FromStandardSchema(value) {
10
+ function FromBase(value) {
11
11
  return value; // non-clonable
12
12
  }
13
13
  // ------------------------------------------------------------------
@@ -47,7 +47,7 @@ function FromUnknown(value) {
47
47
  // ------------------------------------------------------------------
48
48
  function FromValue(value) {
49
49
  return (value instanceof RegExp ? FromRegExp(value) :
50
- IsStandardSchema(value) ? FromStandardSchema(value) :
50
+ IsBase(value) ? FromBase(value) :
51
51
  Guard.IsArray(value) ? FromArray(value) :
52
52
  Guard.IsObject(value) ? FromObject(value) :
53
53
  FromUnknown(value));
@@ -1,4 +1,5 @@
1
1
  import { type TSchema } from './schema.mjs';
2
+ import { type XBase, type XBaseValidator } from '../../schema/types/index.mjs';
2
3
  export declare class BaseNotImplemented extends Error {
3
4
  readonly cause: {
4
5
  type: Base;
@@ -7,9 +8,9 @@ export declare class BaseNotImplemented extends Error {
7
8
  constructor(type: Base, method: string);
8
9
  }
9
10
  /** Base class for creating extension types. */
10
- export declare class Base<Value extends unknown = unknown> implements TSchema {
11
+ export declare class Base<Value extends unknown = unknown> implements TSchema, XBase<Value> {
11
12
  readonly '~kind': 'Base';
12
- readonly '~standard': StandardSchemaV1.Props<Value>;
13
+ readonly '~base': BaseValidator<Value>;
13
14
  constructor();
14
15
  /** Checks a value or returns false if invalid */
15
16
  Check(value: unknown): value is Value;
@@ -26,37 +27,9 @@ export declare class Base<Value extends unknown = unknown> implements TSchema {
26
27
  }
27
28
  /** Returns true if the given value is a Base type. */
28
29
  export declare function IsBase(value: unknown): value is Base;
29
- interface StandardSchemaV1<Input = unknown, Output = Input> {
30
- readonly '~standard': StandardSchemaV1.Props<Input, Output>;
31
- }
32
- declare namespace StandardSchemaV1 {
33
- export interface Props<Input = unknown, Output = Input> {
34
- readonly version: 1;
35
- readonly vendor: string;
36
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
37
- readonly types?: Types<Input, Output> | undefined;
38
- }
39
- export type Result<Output> = SuccessResult<Output> | FailureResult;
40
- export interface SuccessResult<Output> {
41
- readonly value: Output;
42
- readonly issues?: undefined;
43
- }
44
- export interface FailureResult {
45
- readonly issues: ReadonlyArray<Issue>;
46
- }
47
- export interface Issue {
48
- readonly message: string;
49
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
50
- }
51
- export interface PathSegment {
52
- readonly key: PropertyKey;
53
- }
54
- export interface Types<Input = unknown, Output = Input> {
55
- readonly input: Input;
56
- readonly output: Output;
57
- }
58
- export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['input'];
59
- export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema['~standard']['types']>['output'];
60
- export {};
30
+ declare class BaseValidator<Value extends unknown = unknown> implements XBaseValidator<Value> {
31
+ readonly check: (value: unknown) => value is Value;
32
+ readonly errors: (value: unknown) => object[];
33
+ constructor(check: (value: unknown) => value is Value, errors: (value: unknown) => object[]);
61
34
  }
62
35
  export {};
@@ -20,16 +20,14 @@ 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(
24
- // @ts-ignore TS 5.0.4 - unable to derive guard type
25
- (value) => this.Check(value), (value) => this.Errors(value));
23
+ const validator = new BaseValidator((value) => this.Check(value), (value) => this.Errors(value));
26
24
  const configuration = {
27
25
  writable: false,
28
26
  configurable: false,
29
27
  enumerable: false
30
28
  };
31
29
  Object.defineProperty(this, '~kind', { ...configuration, value: 'Base' });
32
- Object.defineProperty(this, '~standard', { ...configuration, value: validator });
30
+ Object.defineProperty(this, '~base', { ...configuration, value: validator });
33
31
  }
34
32
  /** Checks a value or returns false if invalid */
35
33
  Check(value) {
@@ -70,18 +68,5 @@ class BaseValidator {
70
68
  constructor(check, errors) {
71
69
  this.check = check;
72
70
  this.errors = errors;
73
- this.vendor = 'typebox';
74
- this.version = 1;
75
- this.validate = (value) => {
76
- return this.check(value)
77
- ? this.Success(value)
78
- : this.Failure(this.errors(value));
79
- };
80
- }
81
- Success(value) {
82
- return { value };
83
- }
84
- Failure(issues) {
85
- return { issues };
86
71
  }
87
72
  }
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.26",
4
+ "version": "1.0.28",
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
 
@@ -1,5 +0,0 @@
1
- import * as S from '../types/index.mjs';
2
- import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
3
- export declare function BuildStandardSchemaV1(context: BuildContext, schema: S.XStandardSchemaV1, value: string): string;
4
- export declare function CheckStandardSchemaV1(context: CheckContext, schema: S.XStandardSchemaV1, value: unknown): boolean;
5
- export declare function ErrorStandardSchemaV1(context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XStandardSchemaV1, value: unknown): boolean;
@@ -1,27 +0,0 @@
1
- // deno-fmt-ignore-file
2
- import * as V from './_externals.mjs';
3
- import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
4
- // ------------------------------------------------------------------
5
- // Build
6
- // ------------------------------------------------------------------
7
- export function BuildStandardSchemaV1(context, schema, value) {
8
- return E.Not(E.HasPropertyKey(E.Call(E.Member(E.Member(V.CreateExternalVariable(schema), '~standard'), 'validate'), [value]), E.Constant('issues')));
9
- }
10
- // ------------------------------------------------------------------
11
- // Check
12
- // ------------------------------------------------------------------
13
- export function CheckStandardSchemaV1(context, schema, value) {
14
- return !G.HasPropertyKey(schema['~standard'].validate(value), 'issues');
15
- }
16
- // ------------------------------------------------------------------
17
- // Error
18
- // ------------------------------------------------------------------
19
- export function ErrorStandardSchemaV1(context, schemaPath, instancePath, schema, value) {
20
- const result = schema['~standard'].validate(value);
21
- return !G.HasPropertyKey(result, 'issues') || context.AddError({
22
- keyword: '~standard',
23
- schemaPath,
24
- instancePath,
25
- params: { vendor: schema[`~standard`].vendor, issues: result.issues },
26
- });
27
- }
@@ -1,14 +0,0 @@
1
- import type { XSchema } from './schema.mjs';
2
- export interface XStandardValidatorV1 {
3
- version: 1;
4
- vendor: string;
5
- validate: (...args: unknown[]) => object;
6
- }
7
- export interface XStandardSchemaV1<Validator extends XStandardValidatorV1 = XStandardValidatorV1> {
8
- '~standard': Validator;
9
- }
10
- /**
11
- * Returns true if the schema contains an '~standard` keyword
12
- * @specification 'StandardSchema'
13
- */
14
- export declare function IsStandardSchemaV1(value: XSchema): value is XStandardSchemaV1;
@@ -1,19 +0,0 @@
1
- // deno-fmt-ignore-file
2
- import { Guard } from '../../guard/index.mjs';
3
- // ------------------------------------------------------------------
4
- // Guard
5
- // ------------------------------------------------------------------
6
- /**
7
- * Returns true if the schema contains an '~standard` keyword
8
- * @specification 'StandardSchema'
9
- */
10
- export function IsStandardSchemaV1(value) {
11
- return Guard.HasPropertyKey(value, '~standard')
12
- && Guard.IsObject(value["~standard"])
13
- && Guard.HasPropertyKey(value['~standard'], 'version')
14
- && Guard.HasPropertyKey(value['~standard'], 'vendor')
15
- && Guard.HasPropertyKey(value['~standard'], 'validate')
16
- && Guard.IsEqual(value['~standard'].version, 1)
17
- && Guard.IsString(value['~standard'].vendor)
18
- && Guard.IsFunction(value['~standard'].validate);
19
- }