@nmtjs/contract 0.0.3 → 0.1.0

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 (69) hide show
  1. package/dist/index.js +16 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/schemas/event.js +4 -4
  4. package/dist/schemas/event.js.map +1 -1
  5. package/dist/schemas/procedure.js +4 -5
  6. package/dist/schemas/procedure.js.map +1 -1
  7. package/dist/schemas/service.js +1 -6
  8. package/dist/schemas/service.js.map +1 -1
  9. package/dist/schemas/subscription.js +13 -14
  10. package/dist/schemas/subscription.js.map +1 -1
  11. package/dist/types/blob.js +13 -0
  12. package/dist/types/blob.js.map +1 -0
  13. package/dist/utils.js.map +1 -1
  14. package/package.json +8 -18
  15. package/src/index.ts +31 -0
  16. package/src/schemas/event.ts +7 -11
  17. package/src/schemas/procedure.ts +21 -23
  18. package/src/schemas/service.ts +41 -31
  19. package/src/schemas/subscription.ts +27 -49
  20. package/src/types/blob.ts +25 -0
  21. package/src/utils.ts +5 -6
  22. package/dist/compiler.js +0 -50
  23. package/dist/compiler.js.map +0 -1
  24. package/dist/contract.js +0 -24
  25. package/dist/contract.js.map +0 -1
  26. package/dist/formats.js +0 -127
  27. package/dist/formats.js.map +0 -1
  28. package/dist/guards/blob.js +0 -3
  29. package/dist/guards/blob.js.map +0 -1
  30. package/dist/guards/event.js +0 -3
  31. package/dist/guards/event.js.map +0 -1
  32. package/dist/guards/native-enum.js +0 -3
  33. package/dist/guards/native-enum.js.map +0 -1
  34. package/dist/guards/nullable.js +0 -2
  35. package/dist/guards/nullable.js.map +0 -1
  36. package/dist/guards/procedure.js +0 -3
  37. package/dist/guards/procedure.js.map +0 -1
  38. package/dist/guards/service.js +0 -3
  39. package/dist/guards/service.js.map +0 -1
  40. package/dist/guards/subscription.js +0 -3
  41. package/dist/guards/subscription.js.map +0 -1
  42. package/dist/guards/union-enum.js +0 -3
  43. package/dist/guards/union-enum.js.map +0 -1
  44. package/dist/guards.js +0 -20
  45. package/dist/guards.js.map +0 -1
  46. package/dist/schemas/blob.js +0 -26
  47. package/dist/schemas/blob.js.map +0 -1
  48. package/dist/schemas/native-enum.js +0 -14
  49. package/dist/schemas/native-enum.js.map +0 -1
  50. package/dist/schemas/nullable.js +0 -5
  51. package/dist/schemas/nullable.js.map +0 -1
  52. package/dist/schemas/union-enum.js +0 -13
  53. package/dist/schemas/union-enum.js.map +0 -1
  54. package/src/compiler.ts +0 -63
  55. package/src/contract.ts +0 -62
  56. package/src/formats.ts +0 -181
  57. package/src/guards/blob.ts +0 -5
  58. package/src/guards/event.ts +0 -6
  59. package/src/guards/native-enum.ts +0 -7
  60. package/src/guards/nullable.ts +0 -14
  61. package/src/guards/procedure.ts +0 -6
  62. package/src/guards/service.ts +0 -6
  63. package/src/guards/subscription.ts +0 -10
  64. package/src/guards/union-enum.ts +0 -7
  65. package/src/guards.ts +0 -21
  66. package/src/schemas/blob.ts +0 -58
  67. package/src/schemas/native-enum.ts +0 -29
  68. package/src/schemas/nullable.ts +0 -6
  69. package/src/schemas/union-enum.ts +0 -43
@@ -1,15 +1,13 @@
1
- import { Kind, type TSchema, TypeRegistry } from '@sinclair/typebox/type'
1
+ import type { BaseType } from '@nmtjs/type'
2
2
  import { type ContractSchemaOptions, createSchema } from '../utils.ts'
3
3
  import type { TEventContract } from './event.ts'
4
4
  import type { TBaseProcedureContract } from './procedure.ts'
5
5
 
6
- export const SubscriptionKind = 'NeemataSubscription'
7
-
8
- export type TSubcriptionOptions = { static: Record<string, string | number> }
6
+ export type TSubcriptionOptions = Record<string, string | number>
9
7
 
10
8
  export interface TSubscriptionContract<
11
- Input extends TSchema = TSchema,
12
- Output extends TSchema = TSchema,
9
+ Input extends BaseType = BaseType,
10
+ Output extends BaseType = BaseType,
13
11
  Options extends TSubcriptionOptions = TSubcriptionOptions,
14
12
  Events extends Record<string, TEventContract> = Record<
15
13
  string,
@@ -20,63 +18,43 @@ export interface TSubscriptionContract<
20
18
  Transports extends { [K in string]?: true } | undefined =
21
19
  | { [K in string]?: true }
22
20
  | undefined,
23
- > extends TBaseProcedureContract<Input, Output, Name, ServiceName, Transports> {
24
- [Kind]: typeof SubscriptionKind
25
- type: 'neemata:subscription'
26
- static: {
27
- input: Input['static']
28
- output: Output['static']
29
- options: Options['static']
30
- events: {
31
- [K in keyof Events]: Events[K]['static']
32
- }
33
- }
21
+ > extends TBaseProcedureContract<
22
+ 'neemata:subscription',
23
+ Input,
24
+ Output,
25
+ Name,
26
+ ServiceName,
27
+ Transports
28
+ > {
34
29
  options: Options
35
30
  events: Events
36
31
  }
37
32
 
38
33
  export const SubscriptionContract = <
39
- Input extends TSchema = TSchema,
40
- Output extends TSchema = TSchema,
41
- Options extends TSubcriptionOptions = TSubcriptionOptions,
34
+ Input extends BaseType = BaseType,
35
+ Output extends BaseType = BaseType,
42
36
  Events extends Record<string, TEventContract> = Record<
43
37
  string,
44
38
  TEventContract
45
39
  >,
46
- Name extends string | undefined = string | undefined,
47
- ServiceName extends string | undefined = string | undefined,
48
- Transports extends { [K in string]?: true } | undefined =
49
- | { [K in string]?: true }
50
- | undefined,
51
40
  >(
52
41
  input: Input,
53
42
  output: Output,
54
- options: Options,
55
43
  events: Events,
56
44
  timeout?: number,
57
45
  schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,
58
46
  ) => {
59
- if (!TypeRegistry.Has(SubscriptionKind))
60
- TypeRegistry.Set(SubscriptionKind, () => true)
61
-
62
- return createSchema<
63
- TSubscriptionContract<
64
- Input,
65
- Output,
66
- Options,
67
- Events,
68
- Name,
69
- ServiceName,
70
- Transports
71
- >
72
- >({
73
- ...schemaOptions,
74
- [Kind]: SubscriptionKind,
75
- type: 'neemata:subscription',
76
- input,
77
- output,
78
- events,
79
- options,
80
- timeout,
81
- })
47
+ return <Options extends TSubcriptionOptions>() =>
48
+ createSchema<TSubscriptionContract<Input, Output, Options, Events>>({
49
+ ...schemaOptions,
50
+ type: 'neemata:subscription',
51
+ input,
52
+ output,
53
+ events,
54
+ timeout,
55
+ options: undefined as unknown as Options,
56
+ name: undefined,
57
+ serviceName: undefined,
58
+ transports: undefined,
59
+ })
82
60
  }
@@ -0,0 +1,25 @@
1
+ import type { ApiBlobInterface } from '@nmtjs/common'
2
+ import { t } from '@nmtjs/type'
3
+
4
+ export const BlobKind = 'ApiBlob'
5
+
6
+ export interface BlobOptions {
7
+ maxSize?: number
8
+ contentType?: string
9
+ }
10
+
11
+ export const blob = (options: BlobOptions = {}) =>
12
+ t.custom<ApiBlobInterface>(
13
+ (value) => {
14
+ if ('metadata' in value) {
15
+ if (options.maxSize) {
16
+ const size = (value as ApiBlobInterface).metadata.size
17
+ if (size === -1 || size > options.maxSize) {
18
+ throw new Error('Blob size unknown or exceeds maximum allowed size')
19
+ }
20
+ }
21
+ }
22
+ return value
23
+ },
24
+ (value) => value,
25
+ )
package/src/utils.ts CHANGED
@@ -1,6 +1,7 @@
1
- import type { SchemaOptions, TSchema } from '@sinclair/typebox'
2
-
3
- export type ContractSchemaOptions = Pick<SchemaOptions, 'title' | 'description'>
1
+ export type ContractSchemaOptions = {
2
+ title?: string
3
+ description?: string
4
+ }
4
5
 
5
6
  export const applyNames = <T extends Record<string, { serviceName?: string }>>(
6
7
  params: T,
@@ -11,6 +12,4 @@ export const applyNames = <T extends Record<string, { serviceName?: string }>>(
11
12
  )
12
13
  }
13
14
 
14
- export const createSchema = <T extends TSchema>(
15
- schema: Omit<T, 'static' | 'params'>,
16
- ) => schema as T
15
+ export const createSchema = <T>(schema: T) => schema as T
package/dist/compiler.js DELETED
@@ -1,50 +0,0 @@
1
- import { TypeCompiler } from '@sinclair/typebox/compiler';
2
- import { Value } from '@sinclair/typebox/value';
3
- const compileSchema = (schema)=>{
4
- const compiled = TypeCompiler.Compile(schema);
5
- const Prepare = (value)=>{
6
- for (const fn of [
7
- Value.Clean,
8
- Value.Default
9
- ]){
10
- value = fn(schema, value);
11
- }
12
- return value;
13
- };
14
- return Object.assign(compiled, {
15
- Prepare
16
- });
17
- };
18
- export const compile = (schema)=>{
19
- const compiled = compileSchema(schema);
20
- return {
21
- check: compiled.Check.bind(compiled),
22
- errors: compiled.Errors.bind(compiled),
23
- decode: (val)=>{
24
- try {
25
- return {
26
- success: true,
27
- value: compiled.Decode(compiled.Prepare(val))
28
- };
29
- } catch (error) {
30
- return {
31
- success: false,
32
- error
33
- };
34
- }
35
- },
36
- encode: (val)=>{
37
- try {
38
- return {
39
- success: true,
40
- value: compiled.Encode(compiled.Prepare(val))
41
- };
42
- } catch (error) {
43
- return {
44
- success: false,
45
- error
46
- };
47
- }
48
- }
49
- };
50
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/compiler.ts"],"sourcesContent":["import {\n type TypeCheck,\n TypeCompiler,\n type ValueErrorIterator,\n} from '@sinclair/typebox/compiler'\nimport type { TSchema } from '@sinclair/typebox/type'\nimport { Value } from '@sinclair/typebox/value'\n\nexport type Compiled = {\n check: (val: unknown) => boolean\n errors: (val: unknown) => ValueErrorIterator\n decode: (\n val: unknown,\n ) => { success: true; value: unknown } | { success: false; error: any }\n encode: (\n val: unknown,\n ) => { success: true; value: unknown } | { success: false; error: any }\n}\n\nconst compileSchema = (\n schema: TSchema,\n): TypeCheck<TSchema> & {\n Prepare: (value: any) => unknown\n} => {\n const compiled = TypeCompiler.Compile(schema)\n const Prepare = (value: any) => {\n for (const fn of [Value.Clean, Value.Default]) {\n value = fn(schema, value)\n }\n return value\n }\n return Object.assign(compiled, { Prepare })\n}\n\nexport const compile = (schema: TSchema): Compiled => {\n const compiled = compileSchema(schema)\n\n // TODO: custom error handling/shaping\n return {\n check: compiled.Check.bind(compiled),\n errors: compiled.Errors.bind(compiled),\n decode: (val) => {\n try {\n return {\n success: true as const,\n value: compiled.Decode(compiled.Prepare(val)),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n },\n encode: (val) => {\n try {\n return {\n success: true as const,\n value: compiled.Encode(compiled.Prepare(val)),\n }\n } catch (error) {\n return { success: false as const, error }\n }\n },\n }\n}\n"],"names":["TypeCompiler","Value","compileSchema","schema","compiled","Compile","Prepare","value","fn","Clean","Default","Object","assign","compile","check","Check","bind","errors","Errors","decode","val","success","Decode","error","encode","Encode"],"mappings":"AAAA,SAEEA,YAAY,QAEP,6BAA4B;AAEnC,SAASC,KAAK,QAAQ,0BAAyB;AAa/C,MAAMC,gBAAgB,CACpBC;IAIA,MAAMC,WAAWJ,aAAaK,OAAO,CAACF;IACtC,MAAMG,UAAU,CAACC;QACf,KAAK,MAAMC,MAAM;YAACP,MAAMQ,KAAK;YAAER,MAAMS,OAAO;SAAC,CAAE;YAC7CH,QAAQC,GAAGL,QAAQI;QACrB;QACA,OAAOA;IACT;IACA,OAAOI,OAAOC,MAAM,CAACR,UAAU;QAAEE;IAAQ;AAC3C;AAEA,OAAO,MAAMO,UAAU,CAACV;IACtB,MAAMC,WAAWF,cAAcC;IAG/B,OAAO;QACLW,OAAOV,SAASW,KAAK,CAACC,IAAI,CAACZ;QAC3Ba,QAAQb,SAASc,MAAM,CAACF,IAAI,CAACZ;QAC7Be,QAAQ,CAACC;YACP,IAAI;gBACF,OAAO;oBACLC,SAAS;oBACTd,OAAOH,SAASkB,MAAM,CAAClB,SAASE,OAAO,CAACc;gBAC1C;YACF,EAAE,OAAOG,OAAO;gBACd,OAAO;oBAAEF,SAAS;oBAAgBE;gBAAM;YAC1C;QACF;QACAC,QAAQ,CAACJ;YACP,IAAI;gBACF,OAAO;oBACLC,SAAS;oBACTd,OAAOH,SAASqB,MAAM,CAACrB,SAASE,OAAO,CAACc;gBAC1C;YACF,EAAE,OAAOG,OAAO;gBACd,OAAO;oBAAEF,SAAS;oBAAgBE;gBAAM;YAC1C;QACF;IACF;AACF,EAAC"}
package/dist/contract.js DELETED
@@ -1,24 +0,0 @@
1
- import { JsonTypeBuilder, Kind } from '@sinclair/typebox/type';
2
- import { register } from "./formats.js";
3
- import { BlobType } from "./schemas/blob.js";
4
- import { EventContract } from "./schemas/event.js";
5
- import { NativeEnum } from "./schemas/native-enum.js";
6
- import { Nullable } from "./schemas/nullable.js";
7
- import { ProcedureContract } from "./schemas/procedure.js";
8
- import { ServiceContract } from "./schemas/service.js";
9
- import { SubscriptionContract } from "./schemas/subscription.js";
10
- import { UnionEnum } from "./schemas/union-enum.js";
11
- register();
12
- const Contract = Object.freeze({
13
- Procedure: ProcedureContract,
14
- Event: EventContract,
15
- Subscription: SubscriptionContract,
16
- Service: ServiceContract
17
- });
18
- const Type = Object.freeze(Object.assign(new JsonTypeBuilder(), {
19
- UnionEnum,
20
- NativeEnum,
21
- Nullable,
22
- Blob: BlobType
23
- }));
24
- export { Contract, Kind, Type, };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/contract.ts"],"sourcesContent":["import {\n JsonTypeBuilder,\n Kind,\n type StaticDecode,\n type StaticEncode,\n type TSchema,\n} from '@sinclair/typebox/type'\nimport { register } from './formats.ts' // register ajv formats\n\nimport { BlobType, type TBlob } from './schemas/blob.ts'\nimport { EventContract, type TEventContract } from './schemas/event.ts'\nimport { NativeEnum, type TNativeEnum } from './schemas/native-enum.ts'\nimport { Nullable } from './schemas/nullable.ts'\nimport {\n ProcedureContract,\n type TBaseProcedureContract,\n type TProcedureContract,\n} from './schemas/procedure.ts'\nimport { ServiceContract, type TServiceContract } from './schemas/service.ts'\nimport {\n SubscriptionContract,\n type TSubscriptionContract,\n} from './schemas/subscription.ts'\nimport { type TUnionEnum, UnionEnum } from './schemas/union-enum.ts'\n\nregister()\n\nconst Contract = Object.freeze({\n Procedure: ProcedureContract,\n Event: EventContract,\n Subscription: SubscriptionContract,\n Service: ServiceContract,\n})\n\nconst Type = Object.freeze(\n Object.assign(new JsonTypeBuilder(), {\n UnionEnum,\n NativeEnum,\n Nullable,\n Blob: BlobType,\n }),\n)\n\ntype Encoded<T extends TSchema> = StaticEncode<T>\ntype Decoded<T extends TSchema> = StaticDecode<T>\n\nexport {\n Contract,\n Kind,\n Type,\n type Decoded,\n type Encoded,\n type TBlob,\n type TEventContract,\n type TProcedureContract,\n type TBaseProcedureContract,\n type TSchema,\n type TServiceContract,\n type TSubscriptionContract,\n type TUnionEnum,\n type TNativeEnum,\n}\n"],"names":["JsonTypeBuilder","Kind","register","BlobType","EventContract","NativeEnum","Nullable","ProcedureContract","ServiceContract","SubscriptionContract","UnionEnum","Contract","Object","freeze","Procedure","Event","Subscription","Service","Type","assign","Blob"],"mappings":"AAAA,SACEA,eAAe,EACfC,IAAI,QAIC,yBAAwB;AAC/B,SAASC,QAAQ,QAAQ,eAAc;AAEvC,SAASC,QAAQ,QAAoB,oBAAmB;AACxD,SAASC,aAAa,QAA6B,qBAAoB;AACvE,SAASC,UAAU,QAA0B,2BAA0B;AACvE,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SACEC,iBAAiB,QAGZ,yBAAwB;AAC/B,SAASC,eAAe,QAA+B,uBAAsB;AAC7E,SACEC,oBAAoB,QAEf,4BAA2B;AAClC,SAA0BC,SAAS,QAAQ,0BAAyB;AAEpER;AAEA,MAAMS,WAAWC,OAAOC,MAAM,CAAC;IAC7BC,WAAWP;IACXQ,OAAOX;IACPY,cAAcP;IACdQ,SAAST;AACX;AAEA,MAAMU,OAAON,OAAOC,MAAM,CACxBD,OAAOO,MAAM,CAAC,IAAInB,mBAAmB;IACnCU;IACAL;IACAC;IACAc,MAAMjB;AACR;AAMF,SACEQ,QAAQ,EACRV,IAAI,EACJiB,IAAI,KAYL"}
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)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/,
22
- uri,
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]{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,
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":["import { FormatRegistry } from '@sinclair/typebox/type'\n\n// TODO: review all of this\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":"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"}
@@ -1,3 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- import { BlobKind } from "../schemas/blob.js";
3
- export const IsBlob = (schema)=>KindGuard.IsKindOf(schema, BlobKind);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/guards/blob.ts"],"sourcesContent":["import { KindGuard, type TSchema } from '@sinclair/typebox'\nimport { BlobKind, type TBlob } from '../schemas/blob.ts'\n\nexport const IsBlob = (schema: TSchema): schema is TBlob =>\n KindGuard.IsKindOf(schema, BlobKind)\n"],"names":["KindGuard","BlobKind","IsBlob","schema","IsKindOf"],"mappings":"AAAA,SAASA,SAAS,QAAsB,oBAAmB;AAC3D,SAASC,QAAQ,QAAoB,qBAAoB;AAEzD,OAAO,MAAMC,SAAS,CAACC,SACrBH,UAAUI,QAAQ,CAACD,QAAQF,UAAS"}
@@ -1,3 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- import { EventKind } from "../schemas/event.js";
3
- export const IsEvent = (schema)=>KindGuard.IsKindOf(schema, EventKind);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/guards/event.ts"],"sourcesContent":["import { KindGuard, type TSchema } from '@sinclair/typebox'\n\nimport { EventKind, type TEventContract } from '../schemas/event.ts'\n\nexport const IsEvent = (schema: TSchema): schema is TEventContract =>\n KindGuard.IsKindOf(schema, EventKind)\n"],"names":["KindGuard","EventKind","IsEvent","schema","IsKindOf"],"mappings":"AAAA,SAASA,SAAS,QAAsB,oBAAmB;AAE3D,SAASC,SAAS,QAA6B,sBAAqB;AAEpE,OAAO,MAAMC,UAAU,CAACC,SACtBH,UAAUI,QAAQ,CAACD,QAAQF,WAAU"}
@@ -1,3 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- import { NativeEnumKind } from "../schemas/native-enum.js";
3
- export const IsNativeEnum = (schema)=>KindGuard.IsKindOf(schema, NativeEnumKind);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/guards/native-enum.ts"],"sourcesContent":["import { KindGuard, type TSchema } from '@sinclair/typebox'\nimport { NativeEnumKind, type TNativeEnum } from '../schemas/native-enum.ts'\n\nexport const IsNativeEnum = (\n schema: TSchema,\n): schema is TNativeEnum<Record<string, string>> =>\n KindGuard.IsKindOf(schema, NativeEnumKind)\n"],"names":["KindGuard","NativeEnumKind","IsNativeEnum","schema","IsKindOf"],"mappings":"AAAA,SAASA,SAAS,QAAsB,oBAAmB;AAC3D,SAASC,cAAc,QAA0B,4BAA2B;AAE5E,OAAO,MAAMC,eAAe,CAC1BC,SAEAH,UAAUI,QAAQ,CAACD,QAAQF,gBAAe"}
@@ -1,2 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- export const IsNullable = (schema)=>KindGuard.IsUnion(schema) && schema.anyOf.length === 2 && KindGuard.IsNull(schema.anyOf[1]) && KindGuard.IsSchema(schema.anyOf[0]);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/guards/nullable.ts"],"sourcesContent":["import {\n KindGuard,\n type TNull,\n type TSchema,\n type TUnion,\n} from '@sinclair/typebox'\n\nexport const IsNullable = (\n schema: TSchema,\n): schema is TUnion<[TSchema, TNull]> =>\n KindGuard.IsUnion(schema) &&\n schema.anyOf.length === 2 &&\n KindGuard.IsNull(schema.anyOf[1]) &&\n KindGuard.IsSchema(schema.anyOf[0])\n"],"names":["KindGuard","IsNullable","schema","IsUnion","anyOf","length","IsNull","IsSchema"],"mappings":"AAAA,SACEA,SAAS,QAIJ,oBAAmB;AAE1B,OAAO,MAAMC,aAAa,CACxBC,SAEAF,UAAUG,OAAO,CAACD,WAClBA,OAAOE,KAAK,CAACC,MAAM,KAAK,KACxBL,UAAUM,MAAM,CAACJ,OAAOE,KAAK,CAAC,EAAE,KAChCJ,UAAUO,QAAQ,CAACL,OAAOE,KAAK,CAAC,EAAE,EAAC"}
@@ -1,3 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- import { ProcedureKind } from "../schemas/procedure.js";
3
- export const IsProcedure = (schema)=>KindGuard.IsKindOf(schema, ProcedureKind);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/guards/procedure.ts"],"sourcesContent":["import { KindGuard, type TSchema } from '@sinclair/typebox'\n\nimport { ProcedureKind, type TProcedureContract } from '../schemas/procedure.ts'\n\nexport const IsProcedure = (schema: TSchema): schema is TProcedureContract =>\n KindGuard.IsKindOf(schema, ProcedureKind)\n"],"names":["KindGuard","ProcedureKind","IsProcedure","schema","IsKindOf"],"mappings":"AAAA,SAASA,SAAS,QAAsB,oBAAmB;AAE3D,SAASC,aAAa,QAAiC,0BAAyB;AAEhF,OAAO,MAAMC,cAAc,CAACC,SAC1BH,UAAUI,QAAQ,CAACD,QAAQF,eAAc"}
@@ -1,3 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- import { ServiceKind } from "../schemas/service.js";
3
- export const IsService = (schema)=>KindGuard.IsKindOf(schema, ServiceKind);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/guards/service.ts"],"sourcesContent":["import { KindGuard, type TSchema } from '@sinclair/typebox'\n\nimport { ServiceKind, type TServiceContract } from '../schemas/service.ts'\n\nexport const IsService = (schema: TSchema): schema is TServiceContract =>\n KindGuard.IsKindOf(schema, ServiceKind)\n"],"names":["KindGuard","ServiceKind","IsService","schema","IsKindOf"],"mappings":"AAAA,SAASA,SAAS,QAAsB,oBAAmB;AAE3D,SAASC,WAAW,QAA+B,wBAAuB;AAE1E,OAAO,MAAMC,YAAY,CAACC,SACxBH,UAAUI,QAAQ,CAACD,QAAQF,aAAY"}
@@ -1,3 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- import { SubscriptionKind } from "../schemas/subscription.js";
3
- export const IsSubscription = (schema)=>KindGuard.IsKindOf(schema, SubscriptionKind);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/guards/subscription.ts"],"sourcesContent":["import { KindGuard, type TSchema } from '@sinclair/typebox'\nimport {\n SubscriptionKind,\n type TSubscriptionContract,\n} from '../schemas/subscription.ts'\n\nexport const IsSubscription = (\n schema: TSchema,\n): schema is TSubscriptionContract =>\n KindGuard.IsKindOf(schema, SubscriptionKind)\n"],"names":["KindGuard","SubscriptionKind","IsSubscription","schema","IsKindOf"],"mappings":"AAAA,SAASA,SAAS,QAAsB,oBAAmB;AAC3D,SACEC,gBAAgB,QAEX,6BAA4B;AAEnC,OAAO,MAAMC,iBAAiB,CAC5BC,SAEAH,UAAUI,QAAQ,CAACD,QAAQF,kBAAiB"}
@@ -1,3 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- import { UnionEnumKind } from "../schemas/union-enum.js";
3
- export const IsUnionEnum = (schema)=>KindGuard.IsKindOf(schema, UnionEnumKind);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/guards/union-enum.ts"],"sourcesContent":["import { KindGuard, type TSchema } from '@sinclair/typebox'\nimport { type TUnionEnum, UnionEnumKind } from '../schemas/union-enum.ts'\n\nexport const IsUnionEnum = (\n schema: TSchema,\n): schema is TUnionEnum<(string | number)[]> =>\n KindGuard.IsKindOf(schema, UnionEnumKind)\n"],"names":["KindGuard","UnionEnumKind","IsUnionEnum","schema","IsKindOf"],"mappings":"AAAA,SAASA,SAAS,QAAsB,oBAAmB;AAC3D,SAA0BC,aAAa,QAAQ,2BAA0B;AAEzE,OAAO,MAAMC,cAAc,CACzBC,SAEAH,UAAUI,QAAQ,CAACD,QAAQF,eAAc"}
package/dist/guards.js DELETED
@@ -1,20 +0,0 @@
1
- import { KindGuard } from '@sinclair/typebox';
2
- import { IsBlob } from "./guards/blob.js";
3
- import { IsEvent } from "./guards/event.js";
4
- import { IsNativeEnum } from "./guards/native-enum.js";
5
- import { IsNullable } from "./guards/nullable.js";
6
- import { IsProcedure } from "./guards/procedure.js";
7
- import { IsService } from "./guards/service.js";
8
- import { IsSubscription } from "./guards/subscription.js";
9
- import { IsUnionEnum } from "./guards/union-enum.js";
10
- export const ContractGuard = {
11
- ...KindGuard,
12
- IsEvent,
13
- IsSubscription,
14
- IsProcedure,
15
- IsService,
16
- IsBlob,
17
- IsNullable,
18
- IsUnionEnum,
19
- IsNativeEnum
20
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/guards.ts"],"sourcesContent":["import { KindGuard } from '@sinclair/typebox'\nimport { IsBlob } from './guards/blob.ts'\nimport { IsEvent } from './guards/event.ts'\nimport { IsNativeEnum } from './guards/native-enum.ts'\nimport { IsNullable } from './guards/nullable.ts'\nimport { IsProcedure } from './guards/procedure.ts'\nimport { IsService } from './guards/service.ts'\nimport { IsSubscription } from './guards/subscription.ts'\nimport { IsUnionEnum } from './guards/union-enum.ts'\n\nexport const ContractGuard = {\n ...KindGuard,\n IsEvent,\n IsSubscription,\n IsProcedure,\n IsService,\n IsBlob,\n IsNullable,\n IsUnionEnum,\n IsNativeEnum,\n}\n"],"names":["KindGuard","IsBlob","IsEvent","IsNativeEnum","IsNullable","IsProcedure","IsService","IsSubscription","IsUnionEnum","ContractGuard"],"mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAC7C,SAASC,MAAM,QAAQ,mBAAkB;AACzC,SAASC,OAAO,QAAQ,oBAAmB;AAC3C,SAASC,YAAY,QAAQ,0BAAyB;AACtD,SAASC,UAAU,QAAQ,uBAAsB;AACjD,SAASC,WAAW,QAAQ,wBAAuB;AACnD,SAASC,SAAS,QAAQ,sBAAqB;AAC/C,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,WAAW,QAAQ,yBAAwB;AAEpD,OAAO,MAAMC,gBAAgB;IAC3B,GAAGT,SAAS;IACZE;IACAK;IACAF;IACAC;IACAL;IACAG;IACAI;IACAL;AACF,EAAC"}
@@ -1,26 +0,0 @@
1
- import { Kind, Type, TypeBoxError, TypeRegistry } from '@sinclair/typebox/type';
2
- import { createSchema } from "../utils.js";
3
- export const BlobKind = 'ApiBlob';
4
- export const BlobType = (options = {}, schemaOptions = {})=>{
5
- if (!TypeRegistry.Has(BlobKind)) {
6
- TypeRegistry.Set(BlobKind, (schema, value)=>{
7
- return 'metadata' in value;
8
- });
9
- }
10
- return Type.Transform(createSchema({
11
- ...schemaOptions,
12
- [Kind]: BlobKind,
13
- type: 'neemata:blob',
14
- ...options
15
- })).Decode((value)=>{
16
- if ('metadata' in value) {
17
- if (options.maxSize) {
18
- const size = value.metadata.size;
19
- if (size === -1 || size > options.maxSize) {
20
- throw new TypeBoxError('Blob size unknown or exceeds maximum allowed size');
21
- }
22
- }
23
- }
24
- return value;
25
- }).Encode((value)=>value);
26
- };
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/schemas/blob.ts"],"sourcesContent":["import { ApiBlob, type ApiBlobInterface } from '@nmtjs/common'\nimport {\n Kind,\n type TSchema,\n Type,\n TypeBoxError,\n TypeRegistry,\n} from '@sinclair/typebox/type'\nimport { type ContractSchemaOptions, createSchema } from '../utils.ts'\n\nexport const BlobKind = 'ApiBlob'\n\nexport type BlobOptions = {\n maxSize?: number\n contentType?: string\n}\n\nexport interface TBlob extends TSchema {\n [Kind]: typeof BlobKind\n type: 'neemata:blob'\n static: ApiBlobInterface\n maxSize?: BlobOptions['maxSize']\n contentType?: BlobOptions['contentType']\n}\n\nexport const BlobType = (\n options: BlobOptions = {},\n schemaOptions: ContractSchemaOptions = {} as ContractSchemaOptions,\n) => {\n if (!TypeRegistry.Has(BlobKind)) {\n TypeRegistry.Set(BlobKind, (schema: TBlob, value) => {\n return 'metadata' in (value as any)\n })\n }\n\n return Type.Transform(\n createSchema<TBlob>({\n ...schemaOptions,\n [Kind]: BlobKind,\n type: 'neemata:blob',\n ...options,\n }),\n )\n .Decode((value) => {\n if ('metadata' in value) {\n if (options.maxSize) {\n const size = (value as ApiBlobInterface).metadata.size\n if (size === -1 || size > options.maxSize) {\n throw new TypeBoxError(\n 'Blob size unknown or exceeds maximum allowed size',\n )\n }\n }\n }\n return value\n })\n .Encode((value) => value) as unknown as TBlob\n}\n"],"names":["Kind","Type","TypeBoxError","TypeRegistry","createSchema","BlobKind","BlobType","options","schemaOptions","Has","Set","schema","value","Transform","type","Decode","maxSize","size","metadata","Encode"],"mappings":"AACA,SACEA,IAAI,EAEJC,IAAI,EACJC,YAAY,EACZC,YAAY,QACP,yBAAwB;AAC/B,SAAqCC,YAAY,QAAQ,cAAa;AAEtE,OAAO,MAAMC,WAAW,UAAS;AAejC,OAAO,MAAMC,WAAW,CACtBC,UAAuB,CAAC,CAAC,EACzBC,gBAAuC,CAAC,CAA0B;IAElE,IAAI,CAACL,aAAaM,GAAG,CAACJ,WAAW;QAC/BF,aAAaO,GAAG,CAACL,UAAU,CAACM,QAAeC;YACzC,OAAO,cAAeA;QACxB;IACF;IAEA,OAAOX,KAAKY,SAAS,CACnBT,aAAoB;QAClB,GAAGI,aAAa;QAChB,CAACR,KAAK,EAAEK;QACRS,MAAM;QACN,GAAGP,OAAO;IACZ,IAECQ,MAAM,CAAC,CAACH;QACP,IAAI,cAAcA,OAAO;YACvB,IAAIL,QAAQS,OAAO,EAAE;gBACnB,MAAMC,OAAO,AAACL,MAA2BM,QAAQ,CAACD,IAAI;gBACtD,IAAIA,SAAS,CAAC,KAAKA,OAAOV,QAAQS,OAAO,EAAE;oBACzC,MAAM,IAAId,aACR;gBAEJ;YACF;QACF;QACA,OAAOU;IACT,GACCO,MAAM,CAAC,CAACP,QAAUA;AACvB,EAAC"}
@@ -1,14 +0,0 @@
1
- import { Kind, TypeRegistry } from '@sinclair/typebox/type';
2
- export const NativeEnumKind = 'NativeEnum';
3
- export function NativeEnum(value, options = {}) {
4
- const values = Object.values(value);
5
- function NativeEnumCheck(schema, value) {
6
- return typeof value === 'string' && schema.enum.includes(value);
7
- }
8
- if (!TypeRegistry.Has(NativeEnumKind)) TypeRegistry.Set(NativeEnumKind, NativeEnumCheck);
9
- return {
10
- ...options,
11
- [Kind]: NativeEnumKind,
12
- enum: values
13
- };
14
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/schemas/native-enum.ts"],"sourcesContent":["import {\n Kind,\n type SchemaOptions,\n type TSchema,\n TypeRegistry,\n} from '@sinclair/typebox/type'\n\nexport const NativeEnumKind = 'NativeEnum'\nexport interface TNativeEnum<T extends Record<string, string>> extends TSchema {\n [Kind]: typeof NativeEnumKind\n static: T[keyof T][]\n enum: T[keyof T][]\n}\n\nexport function NativeEnum<T extends Record<string, string>>(\n value: T,\n options: SchemaOptions = {},\n) {\n const values = Object.values(value)\n\n function NativeEnumCheck(schema: TNativeEnum<T>, value: unknown) {\n return typeof value === 'string' && schema.enum.includes(value as any)\n }\n\n if (!TypeRegistry.Has(NativeEnumKind))\n TypeRegistry.Set(NativeEnumKind, NativeEnumCheck)\n\n return { ...options, [Kind]: NativeEnumKind, enum: values } as TNativeEnum<T>\n}\n"],"names":["Kind","TypeRegistry","NativeEnumKind","NativeEnum","value","options","values","Object","NativeEnumCheck","schema","enum","includes","Has","Set"],"mappings":"AAAA,SACEA,IAAI,EAGJC,YAAY,QACP,yBAAwB;AAE/B,OAAO,MAAMC,iBAAiB,aAAY;AAO1C,OAAO,SAASC,WACdC,KAAQ,EACRC,UAAyB,CAAC,CAAC;IAE3B,MAAMC,SAASC,OAAOD,MAAM,CAACF;IAE7B,SAASI,gBAAgBC,MAAsB,EAAEL,KAAc;QAC7D,OAAO,OAAOA,UAAU,YAAYK,OAAOC,IAAI,CAACC,QAAQ,CAACP;IAC3D;IAEA,IAAI,CAACH,aAAaW,GAAG,CAACV,iBACpBD,aAAaY,GAAG,CAACX,gBAAgBM;IAEnC,OAAO;QAAE,GAAGH,OAAO;QAAE,CAACL,KAAK,EAAEE;QAAgBQ,MAAMJ;IAAO;AAC5D"}
@@ -1,5 +0,0 @@
1
- import { Type } from '@sinclair/typebox/type';
2
- export const Nullable = (schema, options = {})=>Type.Union([
3
- schema,
4
- Type.Null()
5
- ], options);
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/schemas/nullable.ts"],"sourcesContent":["import { type SchemaOptions, type TSchema, Type } from '@sinclair/typebox/type'\n\nexport const Nullable = <T extends TSchema>(\n schema: T,\n options: SchemaOptions = {},\n) => Type.Union([schema, Type.Null()], options)\n"],"names":["Type","Nullable","schema","options","Union","Null"],"mappings":"AAAA,SAA2CA,IAAI,QAAQ,yBAAwB;AAE/E,OAAO,MAAMC,WAAW,CACtBC,QACAC,UAAyB,CAAC,CAAC,GACxBH,KAAKI,KAAK,CAAC;QAACF;QAAQF,KAAKK,IAAI;KAAG,EAAEF,SAAQ"}
@@ -1,13 +0,0 @@
1
- import { Kind, TypeRegistry } from '@sinclair/typebox/type';
2
- export const UnionEnumKind = 'UnionEnum';
3
- export function UnionEnum(values, options = {}) {
4
- function UnionEnumCheck(schema, value) {
5
- return (typeof value === 'string' || typeof value === 'number') && schema.enum.includes(value);
6
- }
7
- if (!TypeRegistry.Has(UnionEnumKind)) TypeRegistry.Set(UnionEnumKind, UnionEnumCheck);
8
- return {
9
- ...options,
10
- [Kind]: UnionEnumKind,
11
- enum: values
12
- };
13
- }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/schemas/union-enum.ts"],"sourcesContent":["import {\n Kind,\n type SchemaOptions,\n type TSchema,\n TypeRegistry,\n} from '@sinclair/typebox/type'\n\nexport const UnionEnumKind = 'UnionEnum'\n\n// Ref: https://github.com/sinclairzx81/typebox/blob/master/example/prototypes/union-enum.ts\n\n// -------------------------------------------------------------------------------------\n// TUnionEnum\n// -------------------------------------------------------------------------------------\nexport interface TUnionEnum<T extends (string | number)[]> extends TSchema {\n [Kind]: typeof UnionEnumKind\n static: T[number]\n enum: T\n}\n\n// -------------------------------------------------------------------------------------\n// UnionEnum\n// -------------------------------------------------------------------------------------\n/** `[Experimental]` Creates a Union type with a `enum` schema representation */\nexport function UnionEnum<T extends (string | number)[]>(\n values: [...T],\n options: SchemaOptions = {},\n) {\n function UnionEnumCheck(\n schema: TUnionEnum<(string | number)[]>,\n value: unknown,\n ) {\n return (\n (typeof value === 'string' || typeof value === 'number') &&\n schema.enum.includes(value)\n )\n }\n\n if (!TypeRegistry.Has(UnionEnumKind))\n TypeRegistry.Set(UnionEnumKind, UnionEnumCheck)\n\n return { ...options, [Kind]: UnionEnumKind, enum: values } as TUnionEnum<T>\n}\n"],"names":["Kind","TypeRegistry","UnionEnumKind","UnionEnum","values","options","UnionEnumCheck","schema","value","enum","includes","Has","Set"],"mappings":"AAAA,SACEA,IAAI,EAGJC,YAAY,QACP,yBAAwB;AAE/B,OAAO,MAAMC,gBAAgB,YAAW;AAiBxC,OAAO,SAASC,UACdC,MAAc,EACdC,UAAyB,CAAC,CAAC;IAE3B,SAASC,eACPC,MAAuC,EACvCC,KAAc;QAEd,OACE,AAAC,CAAA,OAAOA,UAAU,YAAY,OAAOA,UAAU,QAAO,KACtDD,OAAOE,IAAI,CAACC,QAAQ,CAACF;IAEzB;IAEA,IAAI,CAACP,aAAaU,GAAG,CAACT,gBACpBD,aAAaW,GAAG,CAACV,eAAeI;IAElC,OAAO;QAAE,GAAGD,OAAO;QAAE,CAACL,KAAK,EAAEE;QAAeO,MAAML;IAAO;AAC3D"}