@nmtjs/type 0.6.5 → 0.7.1

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 (76) hide show
  1. package/dist/index.js +34 -31
  2. package/dist/index.js.map +1 -1
  3. package/dist/temporal.js +0 -1
  4. package/dist/temporal.js.map +1 -1
  5. package/dist/types/any.js +4 -4
  6. package/dist/types/any.js.map +1 -1
  7. package/dist/types/array.js +21 -23
  8. package/dist/types/array.js.map +1 -1
  9. package/dist/types/base.js +65 -66
  10. package/dist/types/base.js.map +1 -1
  11. package/dist/types/boolean.js +4 -4
  12. package/dist/types/boolean.js.map +1 -1
  13. package/dist/types/custom.js +9 -8
  14. package/dist/types/custom.js.map +1 -1
  15. package/dist/types/date.js +8 -13
  16. package/dist/types/date.js.map +1 -1
  17. package/dist/types/enum.js +7 -16
  18. package/dist/types/enum.js.map +1 -1
  19. package/dist/types/literal.js +7 -6
  20. package/dist/types/literal.js.map +1 -1
  21. package/dist/types/never.js +4 -4
  22. package/dist/types/never.js.map +1 -1
  23. package/dist/types/number.js +39 -92
  24. package/dist/types/number.js.map +1 -1
  25. package/dist/types/object.js +42 -31
  26. package/dist/types/object.js.map +1 -1
  27. package/dist/types/string.js +49 -47
  28. package/dist/types/string.js.map +1 -1
  29. package/dist/types/temporal.js +75 -41
  30. package/dist/types/temporal.js.map +1 -1
  31. package/dist/types/union.js +26 -18
  32. package/dist/types/union.js.map +1 -1
  33. package/package.json +7 -19
  34. package/src/index.ts +22 -24
  35. package/src/temporal.ts +1 -1
  36. package/src/types/any.ts +5 -3
  37. package/src/types/array.ts +37 -22
  38. package/src/types/base.ts +149 -81
  39. package/src/types/boolean.ts +5 -3
  40. package/src/types/custom.ts +59 -26
  41. package/src/types/date.ts +13 -17
  42. package/src/types/enum.ts +12 -22
  43. package/src/types/literal.ts +9 -6
  44. package/src/types/never.ts +5 -3
  45. package/src/types/number.ts +43 -90
  46. package/src/types/object.ts +45 -37
  47. package/src/types/string.ts +68 -37
  48. package/src/types/temporal.ts +69 -53
  49. package/src/types/union.ts +54 -50
  50. package/dist/compiler.js +0 -55
  51. package/dist/compiler.js.map +0 -1
  52. package/dist/formats.js +0 -127
  53. package/dist/formats.js.map +0 -1
  54. package/dist/inference.js +0 -1
  55. package/dist/inference.js.map +0 -1
  56. package/dist/parse.js +0 -145
  57. package/dist/parse.js.map +0 -1
  58. package/dist/runtime.js +0 -73
  59. package/dist/runtime.js.map +0 -1
  60. package/dist/schemas/default.js +0 -6
  61. package/dist/schemas/default.js.map +0 -1
  62. package/dist/schemas/discriminated-union.js +0 -9
  63. package/dist/schemas/discriminated-union.js.map +0 -1
  64. package/dist/schemas/nullable.js +0 -11
  65. package/dist/schemas/nullable.js.map +0 -1
  66. package/dist/utils.js +0 -1
  67. package/dist/utils.js.map +0 -1
  68. package/src/compiler.ts +0 -100
  69. package/src/formats.ts +0 -182
  70. package/src/inference.ts +0 -128
  71. package/src/parse.ts +0 -217
  72. package/src/runtime.ts +0 -137
  73. package/src/schemas/default.ts +0 -12
  74. package/src/schemas/discriminated-union.ts +0 -49
  75. package/src/schemas/nullable.ts +0 -20
  76. package/src/utils.ts +0 -24
@@ -1,4 +1,4 @@
1
- import { type TString, Type } from '@sinclair/typebox'
1
+ import { iso, regex, string, type ZodMiniString } from '@zod/mini'
2
2
  import { Temporal } from 'temporal-polyfill'
3
3
  import { CustomType, TransformType } from './custom.ts'
4
4
 
@@ -29,102 +29,118 @@ const createTemporalTransformer = <T extends Types>(
29
29
  } as TemporalTransformer<T>
30
30
  }
31
31
 
32
- export class PlainDateType extends TransformType<Temporal.PlainDate, TString> {
33
- static readonly transformer = createTemporalTransformer('PlainDate')
32
+ type EncodedType = ZodMiniString<string>
33
+
34
+ export class PlainDateType extends TransformType<
35
+ Temporal.PlainDate,
36
+ EncodedType
37
+ > {
38
+ static transformer = createTemporalTransformer('PlainDate')
34
39
 
35
40
  static factory() {
36
- return CustomType.factory(
37
- PlainDateType.transformer.decode,
38
- PlainDateType.transformer.encode,
39
- Type.String(),
40
- )
41
+ return CustomType.factory<Temporal.PlainDate, EncodedType>({
42
+ decode: PlainDateType.transformer.decode,
43
+ encode: PlainDateType.transformer.encode,
44
+ type: iso.date(),
45
+ error: 'Invalid date format',
46
+ })
41
47
  }
42
48
  }
43
49
 
44
50
  export class PlainDateTimeType extends TransformType<
45
51
  Temporal.PlainDateTime,
46
- TString
52
+ EncodedType
47
53
  > {
48
- static readonly transformer = createTemporalTransformer('PlainDateTime')
49
- protected _encode = PlainDateTimeType.transformer.encode
54
+ static transformer = createTemporalTransformer('PlainDateTime')
50
55
 
51
56
  static factory() {
52
- return CustomType.factory(
53
- PlainDateTimeType.transformer.decode,
54
- PlainDateTimeType.transformer.encode,
55
- Type.String(),
56
- )
57
+ return CustomType.factory<Temporal.PlainDateTime, EncodedType>({
58
+ decode: PlainDateTimeType.transformer.decode,
59
+ encode: PlainDateTimeType.transformer.encode,
60
+ type: iso.datetime({ local: true }),
61
+ error: 'Invalid datetime format',
62
+ })
57
63
  }
58
64
  }
59
65
 
60
66
  export class ZonedDateTimeType extends TransformType<
61
67
  Temporal.ZonedDateTime,
62
- TString
68
+ EncodedType
63
69
  > {
64
- static readonly transformer = createTemporalTransformer(
65
- 'ZonedDateTime',
66
- (value) => Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),
70
+ static transformer = createTemporalTransformer('ZonedDateTime', (value) =>
71
+ Temporal.Instant.from(value).toZonedDateTimeISO('UTC'),
67
72
  )
68
73
 
69
74
  static factory() {
70
- return CustomType.factory(
71
- ZonedDateTimeType.transformer.decode,
72
- ZonedDateTimeType.transformer.encode,
73
- Type.String(),
74
- )
75
+ return CustomType.factory<Temporal.ZonedDateTime, EncodedType>({
76
+ decode: ZonedDateTimeType.transformer.decode,
77
+ encode: ZonedDateTimeType.transformer.encode,
78
+ type: iso.datetime({ local: true }),
79
+ error: 'Invalid datetime format',
80
+ })
75
81
  }
76
82
  }
77
83
 
78
- export class PlainTimeType extends TransformType<Temporal.PlainTime, TString> {
79
- static readonly transformer = createTemporalTransformer('PlainTime')
84
+ export class PlainTimeType extends TransformType<
85
+ Temporal.PlainTime,
86
+ EncodedType
87
+ > {
88
+ static transformer = createTemporalTransformer('PlainTime')
80
89
 
81
90
  static factory() {
82
- return CustomType.factory(
83
- PlainTimeType.transformer.decode,
84
- PlainTimeType.transformer.encode,
85
- Type.String(),
86
- )
91
+ return CustomType.factory<Temporal.PlainTime, EncodedType>({
92
+ decode: PlainTimeType.transformer.decode,
93
+ encode: PlainTimeType.transformer.encode,
94
+ type: iso.time(),
95
+ error: 'Invalid time format',
96
+ })
87
97
  }
88
98
  }
89
99
 
90
- export class DurationType extends TransformType<Temporal.Duration, TString> {
91
- static readonly transformer = createTemporalTransformer('Duration')
100
+ export class DurationType extends TransformType<
101
+ Temporal.Duration,
102
+ EncodedType
103
+ > {
104
+ static transformer = createTemporalTransformer('Duration')
92
105
 
93
106
  static factory() {
94
- return CustomType.factory(
95
- DurationType.transformer.decode,
96
- DurationType.transformer.encode,
97
- Type.String(),
98
- )
107
+ return CustomType.factory<Temporal.Duration, EncodedType>({
108
+ decode: DurationType.transformer.decode,
109
+ encode: DurationType.transformer.encode,
110
+ type: iso.duration(),
111
+ error: 'Invalid duration format',
112
+ })
99
113
  }
100
114
  }
101
115
 
102
116
  export class PlainYearMonthType extends TransformType<
103
117
  Temporal.PlainYearMonth,
104
- TString
118
+ EncodedType
105
119
  > {
106
- static readonly transformer = createTemporalTransformer('PlainYearMonth')
120
+ static transformer = createTemporalTransformer('PlainYearMonth')
107
121
 
108
122
  static factory() {
109
- return CustomType.factory(
110
- PlainYearMonthType.transformer.decode,
111
- PlainYearMonthType.transformer.encode,
112
- Type.String(),
113
- )
123
+ return CustomType.factory<Temporal.PlainYearMonth, EncodedType>({
124
+ decode: PlainYearMonthType.transformer.decode,
125
+ encode: PlainYearMonthType.transformer.encode,
126
+ type: string().check(regex(/^\d{4}-\d{2}$/)),
127
+ error: 'Invalid year-month format',
128
+ })
114
129
  }
115
130
  }
116
131
 
117
132
  export class PlainMonthDayType extends TransformType<
118
133
  Temporal.PlainMonthDay,
119
- TString
134
+ EncodedType
120
135
  > {
121
- static readonly transformer = createTemporalTransformer('PlainMonthDay')
136
+ static transformer = createTemporalTransformer('PlainMonthDay')
122
137
 
123
138
  static factory() {
124
- return CustomType.factory(
125
- PlainMonthDayType.transformer.decode,
126
- PlainMonthDayType.transformer.encode,
127
- Type.String(),
128
- )
139
+ return CustomType.factory<Temporal.PlainMonthDay, EncodedType>({
140
+ decode: PlainMonthDayType.transformer.decode,
141
+ encode: PlainMonthDayType.transformer.encode,
142
+ type: string().check(regex(/^\d{2}-\d{2}$/)),
143
+ error: 'Invalid month-day format',
144
+ })
129
145
  }
130
146
  }
@@ -1,56 +1,59 @@
1
1
  import {
2
- type TIntersect,
3
- type TObject,
4
- type TSchema,
5
- type TUnion,
6
- Type,
7
- type UnionToTuple,
8
- } from '@sinclair/typebox'
9
- import type { StaticInputDecode } from '../inference.ts'
10
- import {
11
- DiscriminatedUnion,
12
- type DiscriminatedUnionProperties,
13
- type TDiscriminatedUnion,
14
- } from '../schemas/discriminated-union.ts'
2
+ type core,
3
+ discriminatedUnion,
4
+ intersection,
5
+ union,
6
+ type ZodMiniDiscriminatedUnion,
7
+ type ZodMiniIntersection,
8
+ type ZodMiniUnion,
9
+ } from '@zod/mini'
15
10
  import { BaseType, type BaseTypeAny } from './base.ts'
11
+ import type { LiteralType } from './literal.ts'
16
12
  import type { ObjectType, ObjectTypeProps } from './object.ts'
17
13
 
18
14
  export class UnionType<
19
15
  T extends readonly BaseType[] = readonly BaseType[],
20
- S extends TSchema[] = UnionToTuple<T[number]['schema']>,
21
- > extends BaseType<TUnion<S>, { options: T }, StaticInputDecode<TUnion<S>>> {
22
- static factory<
23
- T extends readonly BaseType[] = readonly BaseType[],
24
- S extends TSchema[] = UnionToTuple<T[number]['schema']>,
25
- >(...options: T) {
26
- return new UnionType<T, S>(
27
- Type.Union(options.map((t) => t.schema)) as any,
28
- {
29
- options,
30
- },
31
- )
16
+ > extends BaseType<
17
+ ZodMiniUnion<core.utils.Flatten<T[number]['encodedZodType'][]>>,
18
+ ZodMiniUnion<core.utils.Flatten<T[number]['decodedZodType'][]>>,
19
+ { options: T }
20
+ > {
21
+ static factory<T extends readonly BaseType[] = readonly BaseType[]>(
22
+ ...options: T
23
+ ) {
24
+ return new UnionType<T>({
25
+ encodedZodType: union(options.map((t) => t.encodedZodType)),
26
+ decodedZodType: union(options.map((t) => t.decodedZodType)),
27
+ props: { options },
28
+ })
32
29
  }
33
30
  }
34
31
 
35
32
  export class IntersactionType<
36
- T extends readonly BaseType[] = readonly BaseType[],
37
- S extends TSchema[] = UnionToTuple<T[number]['schema']>,
33
+ T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],
38
34
  > extends BaseType<
39
- TIntersect<S>,
40
- { options: T },
41
- StaticInputDecode<TIntersect<S>>
35
+ ZodMiniIntersection<T[0]['encodedZodType'], T[1]['encodedZodType']>,
36
+ ZodMiniIntersection<T[0]['decodedZodType'], T[1]['decodedZodType']>,
37
+ { options: T }
42
38
  > {
43
39
  static factory<
44
- T extends readonly BaseType[] = readonly BaseType[],
45
- S extends TSchema[] = UnionToTuple<T[number]['schema']>,
40
+ T extends readonly [BaseType, BaseType] = readonly [BaseType, BaseType],
46
41
  >(...options: T) {
47
- return new IntersactionType<T, S>(
48
- Type.Intersect(options.map((t) => t.schema)) as any,
49
- { options },
50
- )
42
+ const [first, second] = options
43
+ return new IntersactionType<T>({
44
+ encodedZodType: intersection(first.encodedZodType, second.encodedZodType),
45
+ decodedZodType: intersection(first.decodedZodType, second.decodedZodType),
46
+ props: { options },
47
+ })
51
48
  }
52
49
  }
53
50
 
51
+ export type DiscriminatedUnionProperties<K extends string = string> = {
52
+ [OK in K]: LiteralType<string>
53
+ } & {
54
+ [OK in string]: any
55
+ }
56
+
54
57
  export type DiscriminatedUnionOptionType<K extends string> = ObjectType<
55
58
  ObjectTypeProps & { [_ in K]: BaseTypeAny }
56
59
  >
@@ -59,26 +62,27 @@ export class DiscriminatedUnionType<
59
62
  K extends string = string,
60
63
  T extends
61
64
  readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],
62
- S extends TObject<DiscriminatedUnionProperties<K>>[] = [],
63
65
  > extends BaseType<
64
- TDiscriminatedUnion<K, S>,
66
+ ZodMiniDiscriminatedUnion<core.utils.Flatten<T[number]['encodedZodType'][]>>,
67
+ ZodMiniDiscriminatedUnion<core.utils.Flatten<T[number]['decodedZodType'][]>>,
65
68
  {
66
69
  key: K
67
70
  options: T
68
- },
69
- StaticInputDecode<TDiscriminatedUnion<K, S>>
71
+ }
70
72
  > {
71
73
  static factory<
72
- K extends string,
73
- T extends readonly DiscriminatedUnionOptionType<K>[],
74
- //@ts-expect-error
75
- S extends TObject<DiscriminatedUnionProperties<K>>[] = UnionToTuple<
76
- T[number]['schema']
77
- >,
74
+ K extends string = string,
75
+ T extends
76
+ readonly DiscriminatedUnionOptionType<K>[] = DiscriminatedUnionOptionType<K>[],
78
77
  >(key: K, ...options: T) {
79
- return new DiscriminatedUnionType<K, T, S>(
80
- DiscriminatedUnion(key, options.map((t) => t.schema) as any),
81
- { key, options },
82
- )
78
+ return new DiscriminatedUnionType<K, T>({
79
+ encodedZodType: discriminatedUnion(
80
+ options.map((t) => t.encodedZodType) as any,
81
+ ),
82
+ decodedZodType: discriminatedUnion(
83
+ options.map((t) => t.decodedZodType) as any,
84
+ ),
85
+ props: { key, options },
86
+ })
83
87
  }
84
88
  }
package/dist/compiler.js DELETED
@@ -1,55 +0,0 @@
1
- import { TypeCompiler } from '@sinclair/typebox/compiler';
2
- import { TransformDecode, TransformEncode } from '@sinclair/typebox/value';
3
- import { _applyDefaults, _parse, _traversErrors } from "./runtime.js";
4
- function compileType(type) {
5
- const { schema } = type;
6
- const compiled = TypeCompiler.Compile(schema);
7
- const check = (value)=>compiled.Check(value);
8
- const applyDefaults = (value)=>_applyDefaults(schema, value);
9
- const parse = (value, cloneOptions)=>_parse(schema, value, cloneOptions);
10
- const errors = (value)=>_traversErrors(compiled.Errors(value));
11
- const decode = TransformDecode.bind(null, schema, compiled.References());
12
- const encode = TransformEncode.bind(null, schema, compiled.References());
13
- return {
14
- check,
15
- parse,
16
- errors,
17
- applyDefaults,
18
- decode,
19
- encode
20
- };
21
- }
22
- export function compile(type) {
23
- const compiled = compileType(type);
24
- function decodeSafe(val) {
25
- try {
26
- return {
27
- success: true,
28
- value: compiled.decode(val)
29
- };
30
- } catch (error) {
31
- return {
32
- success: false,
33
- error
34
- };
35
- }
36
- }
37
- function encodeSafe(val) {
38
- try {
39
- return {
40
- success: true,
41
- value: compiled.encode(val)
42
- };
43
- } catch (error) {
44
- return {
45
- success: false,
46
- error
47
- };
48
- }
49
- }
50
- return {
51
- ...compiled,
52
- decodeSafe,
53
- encodeSafe
54
- };
55
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/compiler.ts"],"sourcesContent":["import { TypeCompiler } from '@sinclair/typebox/compiler'\nimport { TransformDecode, TransformEncode } from '@sinclair/typebox/value'\nimport type {\n StaticInputEncode,\n StaticOutputDecode,\n StaticOutputEncode,\n} from './inference.ts'\nimport {\n _applyDefaults,\n _parse,\n _traversErrors,\n type CloneOptions,\n type ValidationError,\n} from './runtime.ts'\nimport type { BaseType } from './types/base.ts'\n\nexport type Compiled<T extends BaseType = BaseType> = {\n check: (val: unknown) => val is StaticInputEncode<T['schema']>\n errors: (val: unknown) => ValidationError[]\n parse: (val: unknown, cloneOptions?: CloneOptions) => unknown\n applyDefaults: (val: unknown) => unknown\n /**\n * Requires to `check` before calling\n */\n decode: (val: unknown) => StaticOutputDecode<T['schema']>\n /**\n * Requires to `check` before calling\n */\n encode: (val: unknown) => StaticOutputEncode<T['schema']>\n /**\n * Requires to `check` before calling\n */\n decodeSafe: (\n val: unknown,\n ) =>\n | { success: true; value: StaticOutputDecode<T['schema']> }\n | { success: false; error: any }\n /**\n * Requires to `check` before calling\n */\n encodeSafe: (\n val: unknown,\n ) =>\n | { success: true; value: StaticOutputEncode<T['schema']> }\n | { success: false; error: any }\n}\n\nfunction compileType(type: BaseType) {\n const { schema } = type\n const compiled = TypeCompiler.Compile(schema)\n\n const check = (value: unknown) => compiled.Check(value)\n const applyDefaults = (value: unknown) => _applyDefaults(schema, value)\n const parse = (value: unknown, cloneOptions?: CloneOptions) =>\n _parse(schema, value, cloneOptions)\n const errors = (value: unknown) => _traversErrors(compiled.Errors(value))\n const decode = TransformDecode.bind(null, schema, compiled.References())\n const encode = TransformEncode.bind(null, schema, compiled.References())\n\n return {\n check,\n parse,\n errors,\n applyDefaults,\n decode,\n encode,\n }\n}\n\nexport function compile<T extends BaseType>(type: T): Compiled<T> {\n const compiled = compileType(type)\n\n function decodeSafe(val: unknown) {\n try {\n return {\n success: true as const,\n value: compiled.decode(val),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n }\n\n function encodeSafe(val: unknown) {\n try {\n return {\n success: true as const,\n value: compiled.encode(val),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n }\n\n return {\n ...compiled,\n decodeSafe,\n encodeSafe,\n } as any\n}\n"],"names":["TypeCompiler","TransformDecode","TransformEncode","_applyDefaults","_parse","_traversErrors","compileType","type","schema","compiled","Compile","check","value","Check","applyDefaults","parse","cloneOptions","errors","Errors","decode","bind","References","encode","compile","decodeSafe","val","success","error","encodeSafe"],"mappings":"AAAA,SAASA,YAAY,QAAQ,6BAA4B;AACzD,SAASC,eAAe,EAAEC,eAAe,QAAQ,0BAAyB;AAM1E,SACEC,cAAc,EACdC,MAAM,EACNC,cAAc,QAGT,eAAc;AAkCrB,SAASC,YAAYC,IAAc;IACjC,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,MAAME,WAAWT,aAAaU,OAAO,CAACF;IAEtC,MAAMG,QAAQ,CAACC,QAAmBH,SAASI,KAAK,CAACD;IACjD,MAAME,gBAAgB,CAACF,QAAmBT,eAAeK,QAAQI;IACjE,MAAMG,QAAQ,CAACH,OAAgBI,eAC7BZ,OAAOI,QAAQI,OAAOI;IACxB,MAAMC,SAAS,CAACL,QAAmBP,eAAeI,SAASS,MAAM,CAACN;IAClE,MAAMO,SAASlB,gBAAgBmB,IAAI,CAAC,MAAMZ,QAAQC,SAASY,UAAU;IACrE,MAAMC,SAASpB,gBAAgBkB,IAAI,CAAC,MAAMZ,QAAQC,SAASY,UAAU;IAErE,OAAO;QACLV;QACAI;QACAE;QACAH;QACAK;QACAG;IACF;AACF;AAEA,OAAO,SAASC,QAA4BhB,IAAO;IACjD,MAAME,WAAWH,YAAYC;IAE7B,SAASiB,WAAWC,GAAY;QAC9B,IAAI;YACF,OAAO;gBACLC,SAAS;gBACTd,OAAOH,SAASU,MAAM,CAACM;YACzB;QACF,EAAE,OAAOE,OAAO;YACd,OAAO;gBAAED,SAAS;gBAAgBC;YAAM;QAC1C;IACF;IAEA,SAASC,WAAWH,GAAY;QAC9B,IAAI;YACF,OAAO;gBACLC,SAAS;gBACTd,OAAOH,SAASa,MAAM,CAACG;YACzB;QACF,EAAE,OAAOE,OAAO;YACd,OAAO;gBAAED,SAAS;gBAAgBC;YAAM;QAC1C;IACF;IAEA,OAAO;QACL,GAAGlB,QAAQ;QACXe;QACAI;IACF;AACF"}
package/dist/formats.js DELETED
@@ -1,127 +0,0 @@
1
- import { FormatRegistry } from '@sinclair/typebox/type';
2
- export const register = ()=>{
3
- for (const [name, format] of Object.entries(fullFormats)){
4
- if (format === true) {
5
- FormatRegistry.Set(name, ()=>true);
6
- continue;
7
- }
8
- if (typeof format === 'function') {
9
- FormatRegistry.Set(name, format);
10
- continue;
11
- }
12
- FormatRegistry.Set(name, (value)=>format.test(value));
13
- }
14
- };
15
- export const fullFormats = {
16
- date,
17
- time: getTime(true),
18
- 'date-time': getDateTime(true),
19
- 'iso-time': getTime(),
20
- 'iso-date-time': getDateTime(),
21
- duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\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*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\?(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,
24
- 'uri-template': /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i,
25
- url: /^(?:https?|ftp):\/\/(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)(?:\.(?:[a-z0-9\u{00a1}-\u{ffff}]+-)*[a-z0-9\u{00a1}-\u{ffff}]+)*(?:\.(?:[a-z\u{00a1}-\u{ffff}]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?$/iu,
26
- email: /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
27
- hostname: /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i,
28
- ipv4: /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/,
29
- ipv6: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i,
30
- regex,
31
- uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,
32
- 'json-pointer': /^(?:\/(?:[^~/]|~0|~1)*)*$/,
33
- 'json-pointer-uri-fragment': /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,
34
- 'relative-json-pointer': /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,
35
- byte,
36
- int32: validateInt32,
37
- int64: validateInt64,
38
- float: validateNumber,
39
- double: validateNumber,
40
- password: true,
41
- binary: true
42
- };
43
- function isLeapYear(year) {
44
- return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
45
- }
46
- const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
47
- const DAYS = [
48
- 0,
49
- 31,
50
- 28,
51
- 31,
52
- 30,
53
- 31,
54
- 30,
55
- 31,
56
- 31,
57
- 30,
58
- 31,
59
- 30,
60
- 31
61
- ];
62
- function date(str) {
63
- const matches = DATE.exec(str);
64
- if (!matches) return false;
65
- const year = +matches[1];
66
- const month = +matches[2];
67
- const day = +matches[3];
68
- return month >= 1 && month <= 12 && day >= 1 && day <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month]);
69
- }
70
- const TIME = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i;
71
- function getTime(strictTimeZone) {
72
- return function time(str) {
73
- const matches = TIME.exec(str);
74
- if (!matches) return false;
75
- const hr = +matches[1];
76
- const min = +matches[2];
77
- const sec = +matches[3];
78
- const tz = matches[4];
79
- const tzSign = matches[5] === '-' ? -1 : 1;
80
- const tzH = +(matches[6] || 0);
81
- const tzM = +(matches[7] || 0);
82
- if (tzH > 23 || tzM > 59 || strictTimeZone && !tz) return false;
83
- if (hr <= 23 && min <= 59 && sec < 60) return true;
84
- const utcMin = min - tzM * tzSign;
85
- const utcHr = hr - tzH * tzSign - (utcMin < 0 ? 1 : 0);
86
- return (utcHr === 23 || utcHr === -1) && (utcMin === 59 || utcMin === -1) && sec < 61;
87
- };
88
- }
89
- const DATE_TIME_SEPARATOR = /t|\s/i;
90
- function getDateTime(strictTimeZone) {
91
- const time = getTime(strictTimeZone);
92
- return function date_time(str) {
93
- const dateTime = str.split(DATE_TIME_SEPARATOR);
94
- return dateTime.length === 2 && date(dateTime[0]) && time(dateTime[1]);
95
- };
96
- }
97
- const NOT_URI_FRAGMENT = /\/|:/;
98
- const URI = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i;
99
- function uri(str) {
100
- return NOT_URI_FRAGMENT.test(str) && URI.test(str);
101
- }
102
- const BYTE = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
103
- function byte(str) {
104
- BYTE.lastIndex = 0;
105
- return BYTE.test(str);
106
- }
107
- const MIN_INT32 = -(2 ** 31);
108
- const MAX_INT32 = 2 ** 31 - 1;
109
- function validateInt32(value) {
110
- return Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32;
111
- }
112
- function validateInt64(value) {
113
- return Number.isInteger(value);
114
- }
115
- function validateNumber() {
116
- return true;
117
- }
118
- const Z_ANCHOR = /[^\\]\\Z/;
119
- function regex(str) {
120
- if (Z_ANCHOR.test(str)) return false;
121
- try {
122
- new RegExp(str);
123
- return true;
124
- } catch (e) {
125
- return false;
126
- }
127
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/formats.ts"],"sourcesContent":["// Source: https://gist.github.com/ChuckJonas/74d9cfb6ba46244ef4eaa5818c06987b\n// TODO: review all of this\n\nimport { FormatRegistry } from '@sinclair/typebox/type'\n\nexport const register = () => {\n for (const [name, format] of Object.entries(fullFormats)) {\n if (format === true) {\n FormatRegistry.Set(name, () => true)\n continue\n }\n\n if (typeof format === 'function') {\n FormatRegistry.Set(name, format)\n continue\n }\n\n FormatRegistry.Set(name, (value) => format.test(value))\n }\n}\n\nexport const fullFormats: Record<\n string,\n RegExp | ((v: any) => boolean) | true\n> = {\n // date: http://tools.ietf.org/html/rfc3339#section-5.6\n date,\n // date-time: http://tools.ietf.org/html/rfc3339#section-5.6\n time: getTime(true),\n 'date-time': getDateTime(true),\n 'iso-time': getTime(),\n 'iso-date-time': getDateTime(),\n // duration: https://tools.ietf.org/html/rfc3339#appendix-A\n duration:\n /^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?((\\d+|\\d+\\.\\d+)S)?)?|(\\d+W)?)$/,\n uri,\n 'uri-reference':\n /^(?:[a-z][a-z0-9+\\-.]*:)?(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\\.[a-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)|(?:[a-z0-9\\-._~!$&'\"()*+,;=]|%[0-9a-f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'\"()*+,;=:@]|%[0-9a-f]{2})*)*)?(?:\\?(?:[a-z0-9\\-._~!$&'\"()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'\"()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i,\n // uri-template: https://tools.ietf.org/html/rfc6570\n 'uri-template':\n // biome-ignore lint/suspicious/noControlCharactersInRegex:\n /^(?:(?:[^\\x00-\\x20\"'<>%\\\\^`{|}]|%[0-9a-f]{2})|\\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\\*)?)*\\})*$/i,\n // For the source: https://gist.github.com/dperini/729294\n // For test cases: https://mathiasbynens.be/demo/url-regex\n url: /^(?:https?|ftp):\\/\\/(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\.\\d{1,3}){3})(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)(?:\\.(?:[a-z0-9\\u{00a1}-\\u{ffff}]+-)*[a-z0-9\\u{00a1}-\\u{ffff}]+)*(?:\\.(?:[a-z\\u{00a1}-\\u{ffff}]{2,})))(?::\\d{2,5})?(?:\\/[^\\s]*)?$/iu,\n email:\n /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,\n hostname:\n /^(?=.{1,253}\\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\\.?$/i,\n // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html\n ipv4: /^(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)$/,\n ipv6: /^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))$/i,\n regex,\n // uuid: http://tools.ietf.org/html/rfc4122\n uuid: /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,\n // JSON-pointer: https://tools.ietf.org/html/rfc6901\n // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A\n 'json-pointer': /^(?:\\/(?:[^~/]|~0|~1)*)*$/,\n 'json-pointer-uri-fragment':\n /^#(?:\\/(?:[a-z0-9_\\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,\n // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00\n 'relative-json-pointer': /^(?:0|[1-9][0-9]*)(?:#|(?:\\/(?:[^~/]|~0|~1)*)*)$/,\n // the following formats are used by the openapi specification: https://spec.openapis.org/oas/v3.0.0#data-types\n // byte: https://github.com/miguelmota/is-base64\n byte,\n // signed 32 bit integer\n int32: validateInt32,\n // signed 64 bit integer\n int64: validateInt64,\n // C-type float\n float: validateNumber,\n // C-type double\n double: validateNumber,\n // hint to the UI to hide input strings\n password: true,\n // unchecked string payload\n binary: true,\n}\n\nfunction isLeapYear(year: number): boolean {\n // https://tools.ietf.org/html/rfc3339#appendix-C\n return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)\n}\n\nconst DATE = /^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)$/\nconst DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]\n\nfunction date(str: string): boolean {\n // full-date from http://tools.ietf.org/html/rfc3339#section-5.6\n const matches: string[] | null = DATE.exec(str)\n if (!matches) return false\n const year: number = +matches[1]\n const month: number = +matches[2]\n const day: number = +matches[3]\n return (\n month >= 1 &&\n month <= 12 &&\n day >= 1 &&\n day <= (month === 2 && isLeapYear(year) ? 29 : DAYS[month])\n )\n}\n\nconst TIME = /^(\\d\\d):(\\d\\d):(\\d\\d(?:\\.\\d+)?)(z|([+-])(\\d\\d)(?::?(\\d\\d))?)?$/i\n\nfunction getTime(strictTimeZone?: boolean): (str: string) => boolean {\n return function time(str: string): boolean {\n const matches: string[] | null = TIME.exec(str)\n if (!matches) return false\n const hr: number = +matches[1]\n const min: number = +matches[2]\n const sec: number = +matches[3]\n const tz: string | undefined = matches[4]\n const tzSign: number = matches[5] === '-' ? -1 : 1\n const tzH: number = +(matches[6] || 0)\n const tzM: number = +(matches[7] || 0)\n if (tzH > 23 || tzM > 59 || (strictTimeZone && !tz)) return false\n if (hr <= 23 && min <= 59 && sec < 60) return true\n // leap second\n const utcMin = min - tzM * tzSign\n const utcHr = hr - tzH * tzSign - (utcMin < 0 ? 1 : 0)\n return (\n (utcHr === 23 || utcHr === -1) &&\n (utcMin === 59 || utcMin === -1) &&\n sec < 61\n )\n }\n}\n\nconst DATE_TIME_SEPARATOR = /t|\\s/i\nfunction getDateTime(strictTimeZone?: boolean): (str: string) => boolean {\n const time = getTime(strictTimeZone)\n\n return function date_time(str: string): boolean {\n // http://tools.ietf.org/html/rfc3339#section-5.6\n const dateTime: string[] = str.split(DATE_TIME_SEPARATOR)\n return dateTime.length === 2 && date(dateTime[0]) && time(dateTime[1])\n }\n}\n\nconst NOT_URI_FRAGMENT = /\\/|:/\nconst URI =\n /^(?:[a-z][a-z0-9+\\-.]*:)(?:\\/?\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\\.[a-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d?)|(?:[a-z0-9\\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\\d*)?(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\\/(?:(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\\/(?:[a-z0-9\\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\\?(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?(?:#(?:[a-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9a-f]{2})*)?$/i\n\nfunction uri(str: string): boolean {\n // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required \".\"\n return NOT_URI_FRAGMENT.test(str) && URI.test(str)\n}\n\nconst BYTE =\n /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm\n\nfunction byte(str: string): boolean {\n BYTE.lastIndex = 0\n return BYTE.test(str)\n}\n\nconst MIN_INT32 = -(2 ** 31)\nconst MAX_INT32 = 2 ** 31 - 1\n\nfunction validateInt32(value: number): boolean {\n return Number.isInteger(value) && value <= MAX_INT32 && value >= MIN_INT32\n}\n\nfunction validateInt64(value: number): boolean {\n // JSON and javascript max Int is 2**53, so any int that passes isInteger is valid for Int64\n return Number.isInteger(value)\n}\n\nfunction validateNumber(): boolean {\n return true\n}\n\nconst Z_ANCHOR = /[^\\\\]\\\\Z/\nfunction regex(str: string): boolean {\n if (Z_ANCHOR.test(str)) return false\n try {\n new RegExp(str)\n return true\n } catch (e) {\n return false\n }\n}\n"],"names":["FormatRegistry","register","name","format","Object","entries","fullFormats","Set","value","test","date","time","getTime","getDateTime","duration","uri","url","email","hostname","ipv4","ipv6","regex","uuid","byte","int32","validateInt32","int64","validateInt64","float","validateNumber","double","password","binary","isLeapYear","year","DATE","DAYS","str","matches","exec","month","day","TIME","strictTimeZone","hr","min","sec","tz","tzSign","tzH","tzM","utcMin","utcHr","DATE_TIME_SEPARATOR","date_time","dateTime","split","length","NOT_URI_FRAGMENT","URI","BYTE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M,KAAK,KAAK/C,KAAK6C,QAAQ,CAAC,EAAE,KAAK5C,KAAK4C,QAAQ,CAAC,EAAE;IACvE;AACF;AAEA,MAAMG,mBAAmB;AACzB,MAAMC,MACJ;AAEF,SAAS5C,IAAIsB,GAAW;IAEtB,OAAOqB,iBAAiBjD,IAAI,CAAC4B,QAAQsB,IAAIlD,IAAI,CAAC4B;AAChD;AAEA,MAAMuB,OACJ;AAEF,SAASrC,KAAKc,GAAW;IACvBuB,KAAKC,SAAS,GAAG;IACjB,OAAOD,KAAKnD,IAAI,CAAC4B;AACnB;AAEA,MAAMyB,YAAY,CAAE,CAAA,KAAK,EAAC;AAC1B,MAAMC,YAAY,KAAK,KAAK;AAE5B,SAAStC,cAAcjB,KAAa;IAClC,OAAOwD,OAAOC,SAAS,CAACzD,UAAUA,SAASuD,aAAavD,SAASsD;AACnE;AAEA,SAASnC,cAAcnB,KAAa;IAElC,OAAOwD,OAAOC,SAAS,CAACzD;AAC1B;AAEA,SAASqB;IACP,OAAO;AACT;AAEA,MAAMqC,WAAW;AACjB,SAAS7C,MAAMgB,GAAW;IACxB,IAAI6B,SAASzD,IAAI,CAAC4B,MAAM,OAAO;IAC/B,IAAI;QACF,IAAI8B,OAAO9B;QACX,OAAO;IACT,EAAE,OAAO+B,GAAG;QACV,OAAO;IACT;AACF"}
package/dist/inference.js DELETED
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/inference.ts"],"sourcesContent":["import type * as Types from '@sinclair/typebox'\nimport type { TProperties, TSchema } from '@sinclair/typebox'\nimport type { TDefault } from './schemas/default.ts'\n\nexport type StaticInputEncode<Type extends TSchema> =\n Type extends Types.TOptional<TSchema>\n ? Types.StaticEncode<Type> | undefined\n : Types.StaticEncode<Type>\n\nexport type StaticInputDecode<Type extends TSchema> =\n Type extends Types.TOptional<TSchema>\n ? Types.StaticDecode<Type> | undefined\n : Types.StaticDecode<Type>\n\nexport type StaticOutputEncode<Type extends TSchema> = Types.StaticEncode<\n TMap<Type, StaticOutputMapping>\n>\n\nexport type StaticOutputDecode<Type extends TSchema> = Types.StaticDecode<\n TMap<Type, StaticOutputMapping>\n>\n\ninterface StaticOutputMapping extends TMapping {\n output: this['input']\n}\n\ninterface TMapping {\n input: unknown\n output: unknown\n}\n\ntype TApply<\n Type extends TSchema,\n Mapping extends TMapping,\n Mapped = (Mapping & { input: Type })['output'],\n Result = Mapped extends TSchema ? Mapped : never,\n> = Result\n\ntype TFromProperties<\n Properties extends TProperties,\n Mapping extends TMapping,\n Result extends TProperties = {\n [Key in keyof Properties]: TMap<Properties[Key], Mapping>\n },\n> = Result\n\ntype TFromRest<\n Types extends TSchema[],\n Mapping extends TMapping,\n Result extends TSchema[] = [],\n> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]]\n ? TFromRest<Right, Mapping, [...Result, TMap<Left, Mapping>]>\n : Result\n\ntype TFromType<\n Type extends TSchema,\n Mapping extends TMapping,\n Result extends TSchema = TApply<Type, Mapping>,\n> = Result\n\ntype UnwrapDefault<T extends TSchema> = T extends TDefault<infer U>\n ? U extends Types.TOptional<infer V>\n ? V\n : U\n : T\n\ntype TMap<\n Type extends TSchema,\n Mapping extends TMapping,\n // Maps the Exterior Type\n Exterior extends TSchema = TFromType<Type, Mapping>,\n // Maps the Interior Parameterized Types\n Interior extends TSchema = Exterior extends Types.TConstructor<\n infer Parameters extends TSchema[],\n infer ReturnType extends TSchema\n >\n ? Types.TConstructor<\n TFromRest<Parameters, Mapping>,\n TFromType<ReturnType, Mapping>\n >\n : Exterior extends Types.TFunction<\n infer Parameters extends TSchema[],\n infer ReturnType extends TSchema\n >\n ? Types.TFunction<\n TFromRest<Parameters, Mapping>,\n TFromType<ReturnType, Mapping>\n >\n : Exterior extends Types.TIntersect<infer Types extends TSchema[]>\n ? Types.TIntersect<TFromRest<Types, Mapping>>\n : Exterior extends Types.TUnion<infer Types extends TSchema[]>\n ? Types.TUnion<TFromRest<Types, Mapping>>\n : Exterior extends Types.TTuple<infer Types extends TSchema[]>\n ? Types.TTuple<TFromRest<Types, Mapping>>\n : Exterior extends Types.TArray<infer Type extends TSchema>\n ? Types.TArray<TFromType<Type, Mapping>>\n : Exterior extends Types.TAsyncIterator<\n infer Type extends TSchema\n >\n ? Types.TAsyncIterator<TFromType<Type, Mapping>>\n : Exterior extends Types.TIterator<infer Type extends TSchema>\n ? Types.TIterator<TFromType<Type, Mapping>>\n : Exterior extends Types.TPromise<infer Type extends TSchema>\n ? Types.TPromise<TFromType<Type, Mapping>>\n : Exterior extends Types.TObject<\n infer Properties extends TProperties\n >\n ? Types.TObject<TFromProperties<Properties, Mapping>>\n : Exterior extends Types.TRecord<\n infer Key extends TSchema,\n infer Value extends TSchema\n >\n ? Types.TRecordOrObject<\n TFromType<Key, Mapping>,\n TFromType<Value, Mapping>\n >\n : Exterior,\n // Modifiers Derived from Exterior Type Mapping\n IsOptional extends number = Exterior extends Types.TOptional<TSchema> ? 1 : 0,\n IsReadonly extends number = Exterior extends Types.TReadonly<TSchema> ? 1 : 0,\n Result extends TSchema = [IsReadonly, IsOptional] extends [1, 1]\n ? Types.TReadonly<UnwrapDefault<Interior>>\n : [IsReadonly, IsOptional] extends [0, 1]\n ? UnwrapDefault<Interior>\n : [IsReadonly, IsOptional] extends [1, 0]\n ? Types.TReadonly<UnwrapDefault<Interior>>\n : UnwrapDefault<Interior>,\n> = Result\n"],"names":[],"mappings":"AAkBA,WAEC"}