@nmtjs/type 0.4.5 → 0.4.7

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.
package/dist/compiler.js CHANGED
@@ -1,11 +1,8 @@
1
1
  import { TypeCompiler } from '@sinclair/typebox/compiler';
2
2
  import { Value } from '@sinclair/typebox/value';
3
3
  import { getTypeSchema } from "./types/base.js";
4
- function _prepare(schema, value) {
5
- return Value.Default(schema, Value.Clean(schema, value));
6
- }
7
- function _convert(schema, value) {
8
- return Value.Convert(schema, value);
4
+ function _parse(schema, value) {
5
+ return Value.Convert(schema, Value.Default(schema, Value.Clean(schema, Value.Clone(value))));
9
6
  }
10
7
  function compileType(type) {
11
8
  const schema = getTypeSchema(type);
@@ -15,16 +12,13 @@ function compileType(type) {
15
12
  errors: compiled.Errors.bind(compiled),
16
13
  decode: compiled.Decode.bind(compiled),
17
14
  encode: compiled.Encode.bind(compiled),
18
- prepare: _prepare.bind(null, schema),
19
- convert: _convert.bind(null, schema)
15
+ parse: _parse.bind(null, schema)
20
16
  };
21
17
  }
22
18
  export function compile(schema) {
23
19
  const compiled = compileType(schema);
24
20
  return {
25
21
  ...compiled,
26
- decode: (val)=>compiled.decode(val),
27
- encode: (val)=>compiled.encode(val),
28
22
  decodeSafe: (val)=>{
29
23
  try {
30
24
  return {
@@ -55,14 +49,10 @@ export function compile(schema) {
55
49
  }
56
50
  export var runtime;
57
51
  (function(runtime) {
58
- function prepare(type, value) {
59
- return _prepare(getTypeSchema(type), value);
60
- }
61
- runtime.prepare = prepare;
62
- function convert(type, value) {
63
- return _convert(getTypeSchema(type), value);
52
+ function parse(type, value) {
53
+ return _parse(getTypeSchema(type), value);
64
54
  }
65
- runtime.convert = convert;
55
+ runtime.parse = parse;
66
56
  function errors(type, value) {
67
57
  return Value.Errors(getTypeSchema(type), value);
68
58
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compiler.ts"],"sourcesContent":["import type { TSchema } from '@sinclair/typebox'\nimport {\n TypeCompiler,\n type ValueErrorIterator,\n} from '@sinclair/typebox/compiler'\nimport { Value } from '@sinclair/typebox/value'\nimport type { typeStatic } from './constants.ts'\nimport { type BaseType, getTypeSchema } from './types/base.ts'\n\nexport type Compiled<T extends BaseType = BaseType> = {\n check: (val: unknown) => boolean\n errors: (val: unknown) => ValueErrorIterator\n prepare: (val: unknown) => unknown\n convert: (val: unknown) => unknown\n decode: (val: unknown) => T[typeStatic]['decoded']\n encode: (val: unknown) => T[typeStatic]['encoded']\n decodeSafe: (\n val: unknown,\n ) =>\n | { success: true; value: T[typeStatic]['decoded'] }\n | { success: false; error: any }\n encodeSafe: (\n val: unknown,\n ) =>\n | { success: true; value: T[typeStatic]['encoded'] }\n | { success: false; error: any }\n}\n\nfunction _prepare(schema: TSchema, value: any) {\n return Value.Default(schema, Value.Clean(schema, value))\n}\n\nfunction _convert(schema: TSchema, value: any) {\n return Value.Convert(schema, value)\n}\n\nfunction compileType(type: BaseType) {\n const schema = getTypeSchema(type)\n const compiled = TypeCompiler.Compile(schema)\n return {\n check: compiled.Check.bind(compiled),\n errors: compiled.Errors.bind(compiled),\n decode: compiled.Decode.bind(compiled),\n encode: compiled.Encode.bind(compiled),\n prepare: _prepare.bind(null, schema),\n convert: _convert.bind(null, schema),\n }\n}\n\nexport function compile<T extends BaseType>(schema: T): Compiled<T> {\n const compiled = compileType(schema)\n\n // TODO: custom error handling/shaping\n return {\n ...compiled,\n decode: (val) => compiled.decode(val),\n encode: (val) => compiled.encode(val),\n decodeSafe: (val) => {\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 encodeSafe: (val) => {\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}\n\nexport namespace runtime {\n export function prepare(type: BaseType, value: any) {\n return _prepare(getTypeSchema(type), value)\n }\n\n export function convert(type: BaseType, value: any) {\n return _convert(getTypeSchema(type), value)\n }\n\n export function errors(type: BaseType, value: any): ValueErrorIterator {\n return Value.Errors(getTypeSchema(type), value)\n }\n\n export function check(type: BaseType, value: any): boolean {\n return Value.Check(getTypeSchema(type), value)\n }\n\n export function decode<T extends BaseType>(\n type: BaseType,\n value: any,\n ): T[typeStatic]['decoded'] {\n return Value.Decode(getTypeSchema(type), value)\n }\n\n export function encode<T extends BaseType>(\n type: T,\n value: any,\n ): T[typeStatic]['encoded'] {\n return Value.Encode(getTypeSchema(type), value)\n }\n}\n"],"names":["TypeCompiler","Value","getTypeSchema","_prepare","schema","value","Default","Clean","_convert","Convert","compileType","type","compiled","Compile","check","Check","bind","errors","Errors","decode","Decode","encode","Encode","prepare","convert","compile","val","decodeSafe","success","error","encodeSafe","runtime"],"mappings":"AACA,SACEA,YAAY,QAEP,6BAA4B;AACnC,SAASC,KAAK,QAAQ,0BAAyB;AAE/C,SAAwBC,aAAa,QAAQ,kBAAiB;AAqB9D,SAASC,SAASC,MAAe,EAAEC,KAAU;IAC3C,OAAOJ,MAAMK,OAAO,CAACF,QAAQH,MAAMM,KAAK,CAACH,QAAQC;AACnD;AAEA,SAASG,SAASJ,MAAe,EAAEC,KAAU;IAC3C,OAAOJ,MAAMQ,OAAO,CAACL,QAAQC;AAC/B;AAEA,SAASK,YAAYC,IAAc;IACjC,MAAMP,SAASF,cAAcS;IAC7B,MAAMC,WAAWZ,aAAaa,OAAO,CAACT;IACtC,OAAO;QACLU,OAAOF,SAASG,KAAK,CAACC,IAAI,CAACJ;QAC3BK,QAAQL,SAASM,MAAM,CAACF,IAAI,CAACJ;QAC7BO,QAAQP,SAASQ,MAAM,CAACJ,IAAI,CAACJ;QAC7BS,QAAQT,SAASU,MAAM,CAACN,IAAI,CAACJ;QAC7BW,SAASpB,SAASa,IAAI,CAAC,MAAMZ;QAC7BoB,SAAShB,SAASQ,IAAI,CAAC,MAAMZ;IAC/B;AACF;AAEA,OAAO,SAASqB,QAA4BrB,MAAS;IACnD,MAAMQ,WAAWF,YAAYN;IAG7B,OAAO;QACL,GAAGQ,QAAQ;QACXO,QAAQ,CAACO,MAAQd,SAASO,MAAM,CAACO;QACjCL,QAAQ,CAACK,MAAQd,SAASS,MAAM,CAACK;QACjCC,YAAY,CAACD;YACX,IAAI;gBACF,OAAO;oBACLE,SAAS;oBACTvB,OAAOO,SAASO,MAAM,CAACO;gBACzB;YACF,EAAE,OAAOG,OAAO;gBACd,OAAO;oBAAED,SAAS;oBAAgBC;gBAAM;YAC1C;QACF;QACAC,YAAY,CAACJ;YACX,IAAI;gBACF,OAAO;oBACLE,SAAS;oBACTvB,OAAOO,SAASS,MAAM,CAACK;gBACzB;YACF,EAAE,OAAOG,OAAO;gBACd,OAAO;oBAAED,SAAS;oBAAgBC;gBAAM;YAC1C;QACF;IACF;AACF;;UAEiBE;IACR,SAASR,QAAQZ,IAAc,EAAEN,KAAU;QAChD,OAAOF,SAASD,cAAcS,OAAON;IACvC;YAFgBkB,UAAAA;IAIT,SAASC,QAAQb,IAAc,EAAEN,KAAU;QAChD,OAAOG,SAASN,cAAcS,OAAON;IACvC;YAFgBmB,UAAAA;IAIT,SAASP,OAAON,IAAc,EAAEN,KAAU;QAC/C,OAAOJ,MAAMiB,MAAM,CAAChB,cAAcS,OAAON;IAC3C;YAFgBY,SAAAA;IAIT,SAASH,MAAMH,IAAc,EAAEN,KAAU;QAC9C,OAAOJ,MAAMc,KAAK,CAACb,cAAcS,OAAON;IAC1C;YAFgBS,QAAAA;IAIT,SAASK,OACdR,IAAc,EACdN,KAAU;QAEV,OAAOJ,MAAMmB,MAAM,CAAClB,cAAcS,OAAON;IAC3C;YALgBc,SAAAA;IAOT,SAASE,OACdV,IAAO,EACPN,KAAU;QAEV,OAAOJ,MAAMqB,MAAM,CAACpB,cAAcS,OAAON;IAC3C;YALgBgB,SAAAA;AAMlB,GA9BiBU,YAAAA"}
1
+ {"version":3,"sources":["../../src/compiler.ts"],"sourcesContent":["import type { TSchema } from '@sinclair/typebox'\nimport {\n TypeCompiler,\n type ValueErrorIterator,\n} from '@sinclair/typebox/compiler'\nimport { Value } from '@sinclair/typebox/value'\nimport type { typeStatic } from './constants.ts'\nimport { type BaseType, getTypeSchema } from './types/base.ts'\n\nexport type Compiled<T extends BaseType = BaseType> = {\n check: (val: unknown) => boolean\n errors: (val: unknown) => ValueErrorIterator\n parse: (val: unknown) => unknown\n decode: (val: unknown) => T[typeStatic]['decoded']\n encode: (val: unknown) => T[typeStatic]['encoded']\n decodeSafe: (\n val: unknown,\n ) =>\n | { success: true; value: T[typeStatic]['decoded'] }\n | { success: false; error: any }\n encodeSafe: (\n val: unknown,\n ) =>\n | { success: true; value: T[typeStatic]['encoded'] }\n | { success: false; error: any }\n}\n\nfunction _parse(schema: TSchema, value: any) {\n // Clone -> Clean -> Default -> Convert\n return Value.Convert(\n schema,\n Value.Default(schema, Value.Clean(schema, Value.Clone(value))),\n )\n}\n\nfunction compileType(type: BaseType) {\n const schema = getTypeSchema(type)\n const compiled = TypeCompiler.Compile(schema)\n return {\n check: compiled.Check.bind(compiled),\n errors: compiled.Errors.bind(compiled),\n decode: compiled.Decode.bind(compiled),\n encode: compiled.Encode.bind(compiled),\n parse: _parse.bind(null, schema),\n }\n}\n\nexport function compile<T extends BaseType>(schema: T): Compiled<T> {\n const compiled = compileType(schema)\n\n return {\n ...compiled,\n decodeSafe: (val) => {\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 encodeSafe: (val) => {\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}\n\nexport namespace runtime {\n export function parse(type: BaseType, value: any) {\n return _parse(getTypeSchema(type), value)\n }\n\n export function errors(type: BaseType, value: any): ValueErrorIterator {\n return Value.Errors(getTypeSchema(type), value)\n }\n\n export function check(type: BaseType, value: any): boolean {\n return Value.Check(getTypeSchema(type), value)\n }\n\n export function decode<T extends BaseType>(\n type: BaseType,\n value: any,\n ): T[typeStatic]['decoded'] {\n return Value.Decode(getTypeSchema(type), value)\n }\n\n export function encode<T extends BaseType>(\n type: T,\n value: any,\n ): T[typeStatic]['encoded'] {\n return Value.Encode(getTypeSchema(type), value)\n }\n}\n"],"names":["TypeCompiler","Value","getTypeSchema","_parse","schema","value","Convert","Default","Clean","Clone","compileType","type","compiled","Compile","check","Check","bind","errors","Errors","decode","Decode","encode","Encode","parse","compile","decodeSafe","val","success","error","encodeSafe","runtime"],"mappings":"AACA,SACEA,YAAY,QAEP,6BAA4B;AACnC,SAASC,KAAK,QAAQ,0BAAyB;AAE/C,SAAwBC,aAAa,QAAQ,kBAAiB;AAoB9D,SAASC,OAAOC,MAAe,EAAEC,KAAU;IAEzC,OAAOJ,MAAMK,OAAO,CAClBF,QACAH,MAAMM,OAAO,CAACH,QAAQH,MAAMO,KAAK,CAACJ,QAAQH,MAAMQ,KAAK,CAACJ;AAE1D;AAEA,SAASK,YAAYC,IAAc;IACjC,MAAMP,SAASF,cAAcS;IAC7B,MAAMC,WAAWZ,aAAaa,OAAO,CAACT;IACtC,OAAO;QACLU,OAAOF,SAASG,KAAK,CAACC,IAAI,CAACJ;QAC3BK,QAAQL,SAASM,MAAM,CAACF,IAAI,CAACJ;QAC7BO,QAAQP,SAASQ,MAAM,CAACJ,IAAI,CAACJ;QAC7BS,QAAQT,SAASU,MAAM,CAACN,IAAI,CAACJ;QAC7BW,OAAOpB,OAAOa,IAAI,CAAC,MAAMZ;IAC3B;AACF;AAEA,OAAO,SAASoB,QAA4BpB,MAAS;IACnD,MAAMQ,WAAWF,YAAYN;IAE7B,OAAO;QACL,GAAGQ,QAAQ;QACXa,YAAY,CAACC;YACX,IAAI;gBACF,OAAO;oBACLC,SAAS;oBACTtB,OAAOO,SAASO,MAAM,CAACO;gBACzB;YACF,EAAE,OAAOE,OAAO;gBACd,OAAO;oBAAED,SAAS;oBAAgBC;gBAAM;YAC1C;QACF;QACAC,YAAY,CAACH;YACX,IAAI;gBACF,OAAO;oBACLC,SAAS;oBACTtB,OAAOO,SAASS,MAAM,CAACK;gBACzB;YACF,EAAE,OAAOE,OAAO;gBACd,OAAO;oBAAED,SAAS;oBAAgBC;gBAAM;YAC1C;QACF;IACF;AACF;;UAEiBE;IACR,SAASP,MAAMZ,IAAc,EAAEN,KAAU;QAC9C,OAAOF,OAAOD,cAAcS,OAAON;IACrC;YAFgBkB,QAAAA;IAIT,SAASN,OAAON,IAAc,EAAEN,KAAU;QAC/C,OAAOJ,MAAMiB,MAAM,CAAChB,cAAcS,OAAON;IAC3C;YAFgBY,SAAAA;IAIT,SAASH,MAAMH,IAAc,EAAEN,KAAU;QAC9C,OAAOJ,MAAMc,KAAK,CAACb,cAAcS,OAAON;IAC1C;YAFgBS,QAAAA;IAIT,SAASK,OACdR,IAAc,EACdN,KAAU;QAEV,OAAOJ,MAAMmB,MAAM,CAAClB,cAAcS,OAAON;IAC3C;YALgBc,SAAAA;IAOT,SAASE,OACdV,IAAO,EACPN,KAAU;QAEV,OAAOJ,MAAMqB,MAAM,CAACpB,cAAcS,OAAON;IAC3C;YALgBgB,SAAAA;AAMlB,GA1BiBS,YAAAA"}
package/dist/formats.js CHANGED
@@ -18,7 +18,7 @@ export const fullFormats = {
18
18
  'date-time': getDateTime(true),
19
19
  'iso-time': getTime(),
20
20
  'iso-date-time': getDateTime(),
21
- duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,
21
+ duration: /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?((\d+|\d\.\d+)S)?)?|(\d+W)?)$/,
22
22
  uri,
23
23
  'uri-reference': /^(?:[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]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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,
@@ -1 +1 @@
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+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","lastIndex","MIN_INT32","MAX_INT32","Number","isInteger","Z_ANCHOR","RegExp","e"],"mappings":"AAGA,SAASA,cAAc,QAAQ,yBAAwB;AAEvD,OAAO,MAAMC,WAAW;IACtB,KAAK,MAAM,CAACC,MAAMC,OAAO,IAAIC,OAAOC,OAAO,CAACC,aAAc;QACxD,IAAIH,WAAW,MAAM;YACnBH,eAAeO,GAAG,CAACL,MAAM,IAAM;YAC/B;QACF;QAEA,IAAI,OAAOC,WAAW,YAAY;YAChCH,eAAeO,GAAG,CAACL,MAAMC;YACzB;QACF;QAEAH,eAAeO,GAAG,CAACL,MAAM,CAACM,QAAUL,OAAOM,IAAI,CAACD;IAClD;AACF,EAAC;AAED,OAAO,MAAMF,cAGT;IAEFI;IAEAC,MAAMC,QAAQ;IACd,aAAaC,YAAY;IACzB,YAAYD;IACZ,iBAAiBC;IAEjBC,UACE;IACFC;IACA,iBACE;IAEF,gBAEE;IAGFC,KAAK;IACLC,OACE;IACFC,UACE;IAEFC,MAAM;IACNC,MAAM;IACNC;IAEAC,MAAM;IAGN,gBAAgB;IAChB,6BACE;IAEF,yBAAyB;IAGzBC;IAEAC,OAAOC;IAEPC,OAAOC;IAEPC,OAAOC;IAEPC,QAAQD;IAERE,UAAU;IAEVC,QAAQ;AACV,EAAC;AAED,SAASC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AO;IACT;AACF"}
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","lastIndex","MIN_INT32","MAX_INT32","Number","isInteger","Z_ANCHOR","RegExp","e"],"mappings":"AAGA,SAASA,cAAc,QAAQ,yBAAwB;AAEvD,OAAO,MAAMC,WAAW;IACtB,KAAK,MAAM,CAACC,MAAMC,OAAO,IAAIC,OAAOC,OAAO,CAACC,aAAc;QACxD,IAAIH,WAAW,MAAM;YACnBH,eAAeO,GAAG,CAACL,MAAM,IAAM;YAC/B;QACF;QAEA,IAAI,OAAOC,WAAW,YAAY;YAChCH,eAAeO,GAAG,CAACL,MAAMC;YACzB;QACF;QAEAH,eAAeO,GAAG,CAACL,MAAM,CAACM,QAAUL,OAAOM,IAAI,CAACD;IAClD;AACF,EAAC;AAED,OAAO,MAAMF,cAGT;IAEFI;IAEAC,MAAMC,QAAQ;IACd,aAAaC,YAAY;IACzB,YAAYD;IACZ,iBAAiBC;IAEjBC,UACE;IACFC;IACA,iBACE;IAEF,gBAEE;IAGFC,KAAK;IACLC,OACE;IACFC,UACE;IAEFC,MAAM;IACNC,MAAM;IACNC;IAEAC,MAAM;IAGN,gBAAgB;IAChB,6BACE;IAEF,yBAAyB;IAGzBC;IAEAC,OAAOC;IAEPC,OAAOC;IAEPC,OAAOC;IAEPC,QAAQD;IAERE,UAAU;IAEVC,QAAQ;AACV,EAAC;AAED,SAASC,WAAWC,IAAY;IAE9B,OAAOA,OAAO,MAAM,KAAMA,CAAAA,OAAO,QAAQ,KAAKA,OAAO,QAAQ,CAAA;AAC/D;AAEA,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CAAA;QACpD,OACE,AAACC,CAAAA,UAAU,MAAMA,UAAU,CAAC,CAAA,KAC3BD,CAAAA,WAAW,MAAMA,WAAW,CAAC,CAAA,KAC9BL,MAAM;IAEV;AACF;AAEA,MAAMO,sBAAsB;AAC5B,SAASxC,YAAY8B,cAAwB;IAC3C,MAAMhC,OAAOC,QAAQ+B;IAErB,OAAO,SAASW,UAAUjB,GAAW;QAEnC,MAAMkB,WAAqBlB,IAAImB,KAAK,CAACH;QACrC,OAAOE,SAASE,MAAM,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"}
@@ -57,7 +57,7 @@ export class NumberType extends BaseType {
57
57
  return new NumberType(...this._with({
58
58
  options: {
59
59
  maximum: value,
60
- ...exclusive ? {} : {
60
+ ...!exclusive ? {} : {
61
61
  exclusiveMaximum: value
62
62
  }
63
63
  }
@@ -67,7 +67,7 @@ export class NumberType extends BaseType {
67
67
  return new NumberType(...this._with({
68
68
  options: {
69
69
  minimum: value,
70
- ...exclusive ? {} : {
70
+ ...!exclusive ? {} : {
71
71
  exclusiveMinimum: value
72
72
  }
73
73
  }
@@ -129,7 +129,7 @@ export class IntegerType extends BaseType {
129
129
  return new IntegerType(...this._with({
130
130
  options: {
131
131
  maximum: value,
132
- ...exclusive ? {} : {
132
+ ...!exclusive ? {} : {
133
133
  exclusiveMaximum: value
134
134
  }
135
135
  }
@@ -139,7 +139,7 @@ export class IntegerType extends BaseType {
139
139
  return new IntegerType(...this._with({
140
140
  options: {
141
141
  minimum: value,
142
- ...exclusive ? {} : {
142
+ ...!exclusive ? {} : {
143
143
  exclusiveMinimum: value
144
144
  }
145
145
  }
@@ -213,7 +213,7 @@ export class BigIntType extends BaseType {
213
213
  return new BigIntType(...this._with({
214
214
  options: {
215
215
  maximum: this.encode(value),
216
- ...exclusive ? {} : {
216
+ ...!exclusive ? {} : {
217
217
  exclusiveMaximum: this.encode(value)
218
218
  }
219
219
  }
@@ -223,7 +223,7 @@ export class BigIntType extends BaseType {
223
223
  return new BigIntType(...this._with({
224
224
  options: {
225
225
  minimum: `${value}`,
226
- ...exclusive ? {} : {
226
+ ...!exclusive ? {} : {
227
227
  exclusiveMinimum: `${value}`
228
228
  }
229
229
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/number.ts"],"sourcesContent":["import {\n type IntegerOptions,\n type NumberOptions,\n type StringOptions,\n type TInteger,\n type TNumber,\n type TString,\n type TTransform,\n Type,\n TypeBoxError,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NumberType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TNumber, N, O, D, NumberOptions> {\n constructor(\n protected readonly options: NumberOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(options: NumberOptions): TNumber {\n return Type.Number(options)\n }\n\n nullable() {\n return new NumberType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new NumberType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new NumberType(...this._with({ isNullable: true, isOptional: true }))\n }\n\n default(value: number) {\n return new NumberType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new NumberType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [number, ...number[]]) {\n return new NumberType(...this._with({ options: { examples } }))\n }\n\n positive() {\n return this.min(0, true)\n }\n\n negative() {\n return this.max(0, true)\n }\n\n max(value: number, exclusive?: true) {\n return new NumberType(\n ...this._with({\n options: {\n maximum: value,\n ...(exclusive ? {} : { exclusiveMaximum: value }),\n },\n }),\n )\n }\n\n min(value: number, exclusive?: true) {\n return new NumberType(\n ...this._with({\n options: {\n minimum: value,\n ...(exclusive ? {} : { exclusiveMinimum: value }),\n },\n }),\n )\n }\n}\n\nexport class IntegerType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TInteger, N, O, D, IntegerOptions> {\n constructor(\n options: IntegerOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(options: IntegerOptions): TInteger {\n return Type.Integer(options)\n }\n\n nullable() {\n return new IntegerType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new IntegerType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new IntegerType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: number) {\n return new IntegerType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new IntegerType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [number, ...number[]]) {\n return new IntegerType(...this._with({ options: { examples } }))\n }\n\n positive() {\n return this.min(0, true)\n }\n\n negative() {\n return this.max(0, true)\n }\n\n max(value: number, exclusive?: true) {\n return new IntegerType(\n ...this._with({\n options: {\n maximum: value,\n ...(exclusive ? {} : { exclusiveMaximum: value }),\n },\n }),\n )\n }\n\n min(value: number, exclusive?: true) {\n return new IntegerType(\n ...this._with({\n options: {\n minimum: value,\n ...(exclusive ? {} : { exclusiveMinimum: value }),\n },\n }),\n )\n }\n}\n\nexport class BigIntType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TTransform<TString, bigint>, N, O, D, StringOptions> {\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(options: StringOptions) {\n return Type.Transform(Type.String({ ...options, pattern: '^\\\\d$' }))\n .Decode((v: string) => {\n try {\n return BigInt(v)\n } catch (error) {\n throw new TypeBoxError('Invalid bigint value')\n }\n })\n .Encode(this.encode)\n }\n\n protected encode = (value: bigint): string => {\n return value.toString()\n }\n\n nullable() {\n return new BigIntType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new BigIntType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new BigIntType(...this._with({ isNullable: true, isOptional: true }))\n }\n\n default(value: bigint) {\n return new BigIntType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new BigIntType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [bigint, ...bigint[]]) {\n return new BigIntType(\n ...this._with({ options: { examples: examples.map(this.encode) } }),\n )\n }\n\n positive() {\n return this.min(0n, true)\n }\n\n negative() {\n return this.max(0n, true)\n }\n\n max(value: bigint, exclusive?: true) {\n return new BigIntType(\n ...this._with({\n options: {\n maximum: this.encode(value),\n ...(exclusive ? {} : { exclusiveMaximum: this.encode(value) }),\n },\n }),\n )\n }\n\n min(value: bigint, exclusive?: true) {\n return new BigIntType(\n ...this._with({\n options: {\n minimum: `${value}`,\n ...(exclusive ? {} : { exclusiveMinimum: `${value}` }),\n },\n }),\n )\n }\n}\n"],"names":["Type","TypeBoxError","BaseType","NumberType","constructor","options","isNullable","isOptional","hasDefault","_constructSchema","Number","nullable","_with","optional","nullish","default","value","description","examples","positive","min","negative","max","exclusive","maximum","exclusiveMaximum","minimum","exclusiveMinimum","IntegerType","Integer","BigIntType","Transform","String","pattern","Decode","v","BigInt","error","Encode","encode","toString","map"],"mappings":"AAAA,SAQEA,IAAI,EACJC,YAAY,QACP,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAIHD;;IACRE,YACE,AAAmBC,UAAyB,CAAC,CAAC,EAC9CC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC;aALpBH,UAAAA;IAMrB;IAEUI,iBAAiBJ,OAAsB,EAAW;QAC1D,OAAOL,KAAKU,MAAM,CAACL;IACrB;IAEAM,WAAW;QACT,OAAO,IAAIR,cAAc,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;QAAK;IACzD;IAEAO,WAAW;QACT,OAAO,IAAIV,cAAc,IAAI,CAACS,KAAK,CAAC;YAAEL,YAAY;QAAK;IACzD;IAEAO,UAAU;QACR,OAAO,IAAIX,cAAc,IAAI,CAACS,KAAK,CAAC;YAAEN,YAAY;YAAMC,YAAY;QAAK;IAC3E;IAEAQ,QAAQC,KAAa,EAAE;QACrB,OAAO,IAAIb,cACN,IAAI,CAACS,KAAK,CAAC;YAAEP,SAAS;gBAAEU,SAASC;YAAM;YAAGR,YAAY;QAAK;IAElE;IAEAS,YAAYA,WAAmB,EAAE;QAC/B,OAAO,IAAId,cAAc,IAAI,CAACS,KAAK,CAAC;YAAEP,SAAS;gBAAEY;YAAY;QAAE;IACjE;IAEAC,SAAS,GAAGA,QAA+B,EAAE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,EAAE;QACnC,OAAO,IAAIO,cACN,IAAI,CAAClB,KAAK,CAAC;YACZP,SAAS;gBACPqB,SAAS,CAAC,EAAEV,MAAM,CAAC;gBACnB,GAAIO,YAAY,CAAC,IAAI;oBAAEI,kBAAkB,CAAC,EAAEX,MAAM,CAAC;gBAAC,CAAC;YACvD;QACF;IAEJ;AACF"}
1
+ {"version":3,"sources":["../../../src/types/number.ts"],"sourcesContent":["import {\n type IntegerOptions,\n type NumberOptions,\n type StringOptions,\n type TInteger,\n type TNumber,\n type TString,\n type TTransform,\n Type,\n TypeBoxError,\n} from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class NumberType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TNumber, N, O, D, NumberOptions> {\n constructor(\n protected readonly options: NumberOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(options: NumberOptions): TNumber {\n return Type.Number(options)\n }\n\n nullable() {\n return new NumberType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new NumberType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new NumberType(...this._with({ isNullable: true, isOptional: true }))\n }\n\n default(value: number) {\n return new NumberType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new NumberType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [number, ...number[]]) {\n return new NumberType(...this._with({ options: { examples } }))\n }\n\n positive() {\n return this.min(0, true)\n }\n\n negative() {\n return this.max(0, true)\n }\n\n max(value: number, exclusive?: true) {\n return new NumberType(\n ...this._with({\n options: {\n maximum: value,\n ...(!exclusive ? {} : { exclusiveMaximum: value }),\n },\n }),\n )\n }\n\n min(value: number, exclusive?: true) {\n return new NumberType(\n ...this._with({\n options: {\n minimum: value,\n ...(!exclusive ? {} : { exclusiveMinimum: value }),\n },\n }),\n )\n }\n}\n\nexport class IntegerType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TInteger, N, O, D, IntegerOptions> {\n constructor(\n options: IntegerOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(options: IntegerOptions): TInteger {\n return Type.Integer(options)\n }\n\n nullable() {\n return new IntegerType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new IntegerType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new IntegerType(\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: number) {\n return new IntegerType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new IntegerType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [number, ...number[]]) {\n return new IntegerType(...this._with({ options: { examples } }))\n }\n\n positive() {\n return this.min(0, true)\n }\n\n negative() {\n return this.max(0, true)\n }\n\n max(value: number, exclusive?: true) {\n return new IntegerType(\n ...this._with({\n options: {\n maximum: value,\n ...(!exclusive ? {} : { exclusiveMaximum: value }),\n },\n }),\n )\n }\n\n min(value: number, exclusive?: true) {\n return new IntegerType(\n ...this._with({\n options: {\n minimum: value,\n ...(!exclusive ? {} : { exclusiveMinimum: value }),\n },\n }),\n )\n }\n}\n\nexport class BigIntType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TTransform<TString, bigint>, N, O, D, StringOptions> {\n constructor(\n options: StringOptions = {},\n isNullable: N = false as N,\n isOptional: O = false as O,\n hasDefault: D = false as D,\n ) {\n super(options, isNullable, isOptional, hasDefault)\n }\n\n protected _constructSchema(options: StringOptions) {\n return Type.Transform(Type.String({ ...options, pattern: '^\\\\d$' }))\n .Decode((v: string) => {\n try {\n return BigInt(v)\n } catch (error) {\n throw new TypeBoxError('Invalid bigint value')\n }\n })\n .Encode(this.encode)\n }\n\n protected encode = (value: bigint): string => {\n return value.toString()\n }\n\n nullable() {\n return new BigIntType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new BigIntType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new BigIntType(...this._with({ isNullable: true, isOptional: true }))\n }\n\n default(value: bigint) {\n return new BigIntType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new BigIntType(...this._with({ options: { description } }))\n }\n\n examples(...examples: [bigint, ...bigint[]]) {\n return new BigIntType(\n ...this._with({ options: { examples: examples.map(this.encode) } }),\n )\n }\n\n positive() {\n return this.min(0n, true)\n }\n\n negative() {\n return this.max(0n, true)\n }\n\n max(value: bigint, exclusive?: true) {\n return new BigIntType(\n ...this._with({\n options: {\n maximum: this.encode(value),\n ...(!exclusive ? {} : { exclusiveMaximum: this.encode(value) }),\n },\n }),\n )\n }\n\n min(value: bigint, exclusive?: true) {\n return new BigIntType(\n ...this._with({\n options: {\n minimum: `${value}`,\n ...(!exclusive ? {} : { exclusiveMinimum: `${value}` }),\n },\n }),\n )\n }\n}\n"],"names":["Type","TypeBoxError","BaseType","NumberType","constructor","options","isNullable","isOptional","hasDefault","_constructSchema","Number","nullable","_with","optional","nullish","default","value","description","examples","positive","min","negative","max","exclusive","maximum","exclusiveMaximum","minimum","exclusiveMinimum","IntegerType","Integer","BigIntType","Transform","String","pattern","Decode","v","BigInt","error","Encode","encode","toString","map"],"mappings":"AAAA,SAQEA,IAAI,EACJC,YAAY,QACP,oBAAmB;AAC1B,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAIHD;;IACRE,YACE,AAAmBC,UAAyB,CAAC,CAAC,EAC9CC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,EAC1BC,aAAgB,KAAU,CAC1B;QACA,KAAK,CAACH,SAASC,YAAYC,YAAYC;aALpBH,UAAAA;IAMrB;IAEUI,iBAAiBJ,OAAsB,EAAW;QAC1D,OAAOL,KAAKU,MAAM,CAACL;IACrB;IAEAM,WAAW;QACT,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B,EAAE;QAC3C,OAAO,IAAIY,cACN,IAAI,CAAClB,KAAK,CAAC;YAAEP,SAAS;gBAAEa,UAAUA,SAASuB,GAAG,CAAC,IAAI,CAACF,MAAM;YAAE;QAAE;IAErE;IAEApB,WAAW;QACT,OAAO,IAAI,CAACC,GAAG,CAAC,EAAE,EAAE;IACtB;IAEAC,WAAW;QACT,OAAO,IAAI,CAACC,GAAG,CAAC,EAAE,EAAE;IACtB;IAEAA,IAAIN,KAAa,EAAEO,SAAgB,EAAE;QACnC,OAAO,IAAIO,cACN,IAAI,CAAClB,KAAK,CAAC;YACZP,SAAS;gBACPmB,SAAS,IAAI,CAACe,MAAM,CAACvB;gBACrB,GAAI,CAACO,YAAY,CAAC,IAAI;oBAAEE,kBAAkB,IAAI,CAACc,MAAM,CAACvB;gBAAO,CAAC;YAChE;QACF;IAEJ;IAEAI,IAAIJ,KAAa,EAAEO,SAAgB,EAAE;QACnC,OAAO,IAAIO,cACN,IAAI,CAAClB,KAAK,CAAC;YACZP,SAAS;gBACPqB,SAAS,CAAC,EAAEV,MAAM,CAAC;gBACnB,GAAI,CAACO,YAAY,CAAC,IAAI;oBAAEI,kBAAkB,CAAC,EAAEX,MAAM,CAAC;gBAAC,CAAC;YACxD;QACF;IAEJ;AACF"}
package/package.json CHANGED
@@ -19,14 +19,14 @@
19
19
  }
20
20
  },
21
21
  "peerDependencies": {
22
- "@sinclair/typebox": "^0.33.7",
22
+ "@sinclair/typebox": "^0.34.13",
23
23
  "temporal-polyfill": "^0.2.5",
24
- "@nmtjs/common": "0.4.5"
24
+ "@nmtjs/common": "0.4.7"
25
25
  },
26
26
  "devDependencies": {
27
- "@sinclair/typebox": "^0.33.7",
27
+ "@sinclair/typebox": "^0.34.13",
28
28
  "temporal-polyfill": "^0.2.5",
29
- "@nmtjs/common": "0.4.5"
29
+ "@nmtjs/common": "0.4.7"
30
30
  },
31
31
  "files": [
32
32
  "src",
@@ -35,7 +35,7 @@
35
35
  "LICENSE.md",
36
36
  "README.md"
37
37
  ],
38
- "version": "0.4.5",
38
+ "version": "0.4.7",
39
39
  "scripts": {
40
40
  "build": "neemata-build -p neutral --root=./src './**/*.ts'",
41
41
  "type-check": "tsc --noEmit"
package/src/compiler.ts CHANGED
@@ -10,8 +10,7 @@ import { type BaseType, getTypeSchema } from './types/base.ts'
10
10
  export type Compiled<T extends BaseType = BaseType> = {
11
11
  check: (val: unknown) => boolean
12
12
  errors: (val: unknown) => ValueErrorIterator
13
- prepare: (val: unknown) => unknown
14
- convert: (val: unknown) => unknown
13
+ parse: (val: unknown) => unknown
15
14
  decode: (val: unknown) => T[typeStatic]['decoded']
16
15
  encode: (val: unknown) => T[typeStatic]['encoded']
17
16
  decodeSafe: (
@@ -26,12 +25,12 @@ export type Compiled<T extends BaseType = BaseType> = {
26
25
  | { success: false; error: any }
27
26
  }
28
27
 
29
- function _prepare(schema: TSchema, value: any) {
30
- return Value.Default(schema, Value.Clean(schema, value))
31
- }
32
-
33
- function _convert(schema: TSchema, value: any) {
34
- return Value.Convert(schema, value)
28
+ function _parse(schema: TSchema, value: any) {
29
+ // Clone -> Clean -> Default -> Convert
30
+ return Value.Convert(
31
+ schema,
32
+ Value.Default(schema, Value.Clean(schema, Value.Clone(value))),
33
+ )
35
34
  }
36
35
 
37
36
  function compileType(type: BaseType) {
@@ -42,19 +41,15 @@ function compileType(type: BaseType) {
42
41
  errors: compiled.Errors.bind(compiled),
43
42
  decode: compiled.Decode.bind(compiled),
44
43
  encode: compiled.Encode.bind(compiled),
45
- prepare: _prepare.bind(null, schema),
46
- convert: _convert.bind(null, schema),
44
+ parse: _parse.bind(null, schema),
47
45
  }
48
46
  }
49
47
 
50
48
  export function compile<T extends BaseType>(schema: T): Compiled<T> {
51
49
  const compiled = compileType(schema)
52
50
 
53
- // TODO: custom error handling/shaping
54
51
  return {
55
52
  ...compiled,
56
- decode: (val) => compiled.decode(val),
57
- encode: (val) => compiled.encode(val),
58
53
  decodeSafe: (val) => {
59
54
  try {
60
55
  return {
@@ -79,12 +74,8 @@ export function compile<T extends BaseType>(schema: T): Compiled<T> {
79
74
  }
80
75
 
81
76
  export namespace runtime {
82
- export function prepare(type: BaseType, value: any) {
83
- return _prepare(getTypeSchema(type), value)
84
- }
85
-
86
- export function convert(type: BaseType, value: any) {
87
- return _convert(getTypeSchema(type), value)
77
+ export function parse(type: BaseType, value: any) {
78
+ return _parse(getTypeSchema(type), value)
88
79
  }
89
80
 
90
81
  export function errors(type: BaseType, value: any): ValueErrorIterator {
package/src/formats.ts CHANGED
@@ -32,7 +32,7 @@ export const fullFormats: Record<
32
32
  'iso-date-time': getDateTime(),
33
33
  // duration: https://tools.ietf.org/html/rfc3339#appendix-A
34
34
  duration:
35
- /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,
35
+ /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?((\d+|\d\.\d+)S)?)?|(\d+W)?)$/,
36
36
  uri,
37
37
  'uri-reference':
38
38
  /^(?:[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,
@@ -68,7 +68,7 @@ export class NumberType<
68
68
  ...this._with({
69
69
  options: {
70
70
  maximum: value,
71
- ...(exclusive ? {} : { exclusiveMaximum: value }),
71
+ ...(!exclusive ? {} : { exclusiveMaximum: value }),
72
72
  },
73
73
  }),
74
74
  )
@@ -79,7 +79,7 @@ export class NumberType<
79
79
  ...this._with({
80
80
  options: {
81
81
  minimum: value,
82
- ...(exclusive ? {} : { exclusiveMinimum: value }),
82
+ ...(!exclusive ? {} : { exclusiveMinimum: value }),
83
83
  },
84
84
  }),
85
85
  )
@@ -145,7 +145,7 @@ export class IntegerType<
145
145
  ...this._with({
146
146
  options: {
147
147
  maximum: value,
148
- ...(exclusive ? {} : { exclusiveMaximum: value }),
148
+ ...(!exclusive ? {} : { exclusiveMaximum: value }),
149
149
  },
150
150
  }),
151
151
  )
@@ -156,7 +156,7 @@ export class IntegerType<
156
156
  ...this._with({
157
157
  options: {
158
158
  minimum: value,
159
- ...(exclusive ? {} : { exclusiveMinimum: value }),
159
+ ...(!exclusive ? {} : { exclusiveMinimum: value }),
160
160
  },
161
161
  }),
162
162
  )
@@ -234,7 +234,7 @@ export class BigIntType<
234
234
  ...this._with({
235
235
  options: {
236
236
  maximum: this.encode(value),
237
- ...(exclusive ? {} : { exclusiveMaximum: this.encode(value) }),
237
+ ...(!exclusive ? {} : { exclusiveMaximum: this.encode(value) }),
238
238
  },
239
239
  }),
240
240
  )
@@ -245,7 +245,7 @@ export class BigIntType<
245
245
  ...this._with({
246
246
  options: {
247
247
  minimum: `${value}`,
248
- ...(exclusive ? {} : { exclusiveMinimum: `${value}` }),
248
+ ...(!exclusive ? {} : { exclusiveMinimum: `${value}` }),
249
249
  },
250
250
  }),
251
251
  )