@nmtjs/type 0.2.0 → 0.3.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 (55) hide show
  1. package/dist/compiler.js +2 -2
  2. package/dist/compiler.js.map +1 -1
  3. package/dist/constants.js +2 -0
  4. package/dist/constants.js.map +1 -0
  5. package/dist/index.js +2 -3
  6. package/dist/index.js.map +1 -1
  7. package/dist/temporal.js +3 -1
  8. package/dist/temporal.js.map +1 -1
  9. package/dist/types/any.js +37 -5
  10. package/dist/types/any.js.map +1 -1
  11. package/dist/types/array.js +55 -24
  12. package/dist/types/array.js.map +1 -1
  13. package/dist/types/base.js +31 -62
  14. package/dist/types/base.js.map +1 -1
  15. package/dist/types/boolean.js +37 -5
  16. package/dist/types/boolean.js.map +1 -1
  17. package/dist/types/custom.js +37 -8
  18. package/dist/types/custom.js.map +1 -1
  19. package/dist/types/datetime.js +41 -22
  20. package/dist/types/datetime.js.map +1 -1
  21. package/dist/types/enum.js +74 -16
  22. package/dist/types/enum.js.map +1 -1
  23. package/dist/types/literal.js +35 -8
  24. package/dist/types/literal.js.map +1 -1
  25. package/dist/types/never.js +17 -2
  26. package/dist/types/never.js.map +1 -1
  27. package/dist/types/number.js +116 -62
  28. package/dist/types/number.js.map +1 -1
  29. package/dist/types/object.js +58 -17
  30. package/dist/types/object.js.map +1 -1
  31. package/dist/types/string.js +57 -21
  32. package/dist/types/string.js.map +1 -1
  33. package/dist/types/temporal.js +292 -74
  34. package/dist/types/temporal.js.map +1 -1
  35. package/dist/types/union.js +75 -17
  36. package/dist/types/union.js.map +1 -1
  37. package/package.json +3 -3
  38. package/src/compiler.ts +2 -2
  39. package/src/constants.ts +5 -0
  40. package/src/index.ts +5 -6
  41. package/src/temporal.ts +4 -2
  42. package/src/types/any.ts +32 -9
  43. package/src/types/array.ts +59 -28
  44. package/src/types/base.ts +59 -112
  45. package/src/types/boolean.ts +31 -9
  46. package/src/types/custom.ts +61 -24
  47. package/src/types/datetime.ts +40 -35
  48. package/src/types/enum.ts +78 -21
  49. package/src/types/literal.ts +42 -12
  50. package/src/types/never.ts +24 -11
  51. package/src/types/number.ts +103 -67
  52. package/src/types/object.ts +87 -32
  53. package/src/types/string.ts +38 -30
  54. package/src/types/temporal.ts +378 -118
  55. package/src/types/union.ts +103 -31
@@ -1,47 +1,88 @@
1
1
  import { Type } from '@sinclair/typebox';
2
- import { BaseType, typeFinalSchema } from "./base.js";
2
+ import { BaseType, getTypeSchema } from "./base.js";
3
3
  import { EnumType } from "./enum.js";
4
4
  export class ObjectType extends BaseType {
5
5
  properties;
6
- constructor(properties = {}, nullable = false, optional = false){
7
- const schemaProperties = Object.fromEntries(Object.entries(properties).map(([key, value])=>[
8
- key,
9
- value[typeFinalSchema]
10
- ]));
11
- super(Type.Object(schemaProperties), nullable, optional);
6
+ constructor(properties = {}, options = {}, isNullable = false, isOptional = false, hasDefault = false){
7
+ super(options, isNullable, isOptional, hasDefault, properties);
12
8
  this.properties = properties;
13
9
  }
10
+ _constructSchema(options, properties) {
11
+ const schemaProperties = {};
12
+ for (const [key, value] of Object.entries(properties)){
13
+ schemaProperties[key] = getTypeSchema(value);
14
+ }
15
+ return Type.Object(schemaProperties, options);
16
+ }
14
17
  nullable() {
15
- const [_, ...args] = this._nullable();
16
- return new ObjectType(this.properties, ...args);
18
+ return new ObjectType(this.properties, ...this._with({
19
+ isNullable: true
20
+ }));
17
21
  }
18
22
  optional() {
19
- const [_, ...args] = this._optional();
20
- return new ObjectType(this.properties, ...args);
23
+ return new ObjectType(this.properties, ...this._with({
24
+ isOptional: true
25
+ }));
21
26
  }
22
27
  nullish() {
23
- const [_, ...args] = this._nullish();
24
- return new ObjectType(this.properties, ...args);
28
+ return new ObjectType(this.properties, ...this._with({
29
+ isNullable: true,
30
+ isOptional: true
31
+ }));
32
+ }
33
+ default(value) {
34
+ return new ObjectType(this.properties, ...this._with({
35
+ options: {
36
+ default: value
37
+ },
38
+ hasDefault: true
39
+ }));
40
+ }
41
+ description(description) {
42
+ return new ObjectType(this.properties, ...this._with({
43
+ options: {
44
+ description
45
+ }
46
+ }));
47
+ }
48
+ examples(...examples) {
49
+ return new ObjectType(this.properties, ...this._with({
50
+ options: {
51
+ examples
52
+ }
53
+ }));
25
54
  }
26
55
  pick(pick) {
27
56
  const properties = Object.fromEntries(Object.entries(this.properties).filter(([key])=>pick[key]));
28
- return new ObjectType(properties, ...this._isNullableOptional);
57
+ const [_, ...args] = this._with();
58
+ return new ObjectType(properties, {}, ...args);
29
59
  }
30
60
  omit(omit) {
31
61
  const properties = Object.fromEntries(Object.entries(this.properties).filter(([key])=>!omit[key]));
32
- return new ObjectType(properties, ...this._isNullableOptional);
62
+ const [_, ...args] = this._with();
63
+ return new ObjectType(properties, {}, ...args);
33
64
  }
34
65
  extend(properties) {
66
+ const [_, ...args] = this._with();
35
67
  return new ObjectType({
36
68
  ...this.properties,
37
69
  ...properties
38
- }, ...this._isNullableOptional);
70
+ }, {}, ...args);
39
71
  }
40
72
  merge(object) {
73
+ const [_, ...args] = this._with();
41
74
  return new ObjectType({
42
75
  ...this.properties,
43
76
  ...object.properties
44
- }, ...this._isNullableOptional);
77
+ }, {}, ...args);
78
+ }
79
+ partial() {
80
+ const properties = {};
81
+ for (const [key, value] of Object.entries(this.properties)){
82
+ properties[key] = value.optional();
83
+ }
84
+ const [_, ...args] = this._with();
85
+ return new ObjectType(properties, {}, ...args);
45
86
  }
46
87
  keyof() {
47
88
  return new EnumType(Object.keys(this.properties));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/object.ts"],"sourcesContent":["import { type TObject, Type } from '@sinclair/typebox'\nimport type { UnionToTupleString } from '../utils.ts'\nimport { BaseType, typeFinalSchema } from './base.ts'\nimport { EnumType } from './enum.ts'\n\nexport class ObjectType<\n T extends Record<string, BaseType> = Record<string, BaseType>,\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TObject<{ [K in keyof T]: T[K][typeFinalSchema] }>, N, O> {\n constructor(\n readonly properties: T = {} as T,\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n const schemaProperties = Object.fromEntries(\n Object.entries(properties).map(([key, value]) => [\n key,\n value[typeFinalSchema],\n ]),\n )\n super(\n Type.Object(\n schemaProperties as { [K in keyof T]: T[K][typeFinalSchema] },\n ),\n nullable,\n optional,\n )\n }\n\n nullable() {\n const [_, ...args] = this._nullable()\n return new ObjectType(this.properties, ...args)\n }\n\n optional() {\n const [_, ...args] = this._optional()\n return new ObjectType(this.properties, ...args)\n }\n\n nullish() {\n const [_, ...args] = this._nullish()\n return new ObjectType(this.properties, ...args)\n }\n\n pick<P extends { [K in keyof T]?: true }>(pick: P) {\n const properties = Object.fromEntries(\n Object.entries(this.properties).filter(([key]) => pick[key]),\n )\n return new ObjectType(\n properties as Pick<T, Extract<keyof P, keyof T>>,\n ...this._isNullableOptional,\n )\n }\n\n omit<P extends { [K in keyof T]?: true }>(omit: P) {\n const properties = Object.fromEntries(\n Object.entries(this.properties).filter(([key]) => !omit[key]),\n )\n return new ObjectType(\n properties as Omit<T, Extract<keyof P, keyof T>>,\n ...this._isNullableOptional,\n )\n }\n\n extend<P extends Record<string, BaseType>>(properties: P) {\n return new ObjectType(\n { ...this.properties, ...properties },\n ...this._isNullableOptional,\n )\n }\n\n merge<T extends ObjectType>(object: T) {\n return new ObjectType(\n { ...this.properties, ...object.properties },\n ...this._isNullableOptional,\n )\n }\n\n keyof(): EnumType<UnionToTupleString<keyof T>> {\n return new EnumType(Object.keys(this.properties) as any)\n }\n}\n"],"names":["Type","BaseType","typeFinalSchema","EnumType","ObjectType","constructor","properties","nullable","optional","schemaProperties","Object","fromEntries","entries","map","key","value","_","args","_nullable","_optional","nullish","_nullish","pick","filter","_isNullableOptional","omit","extend","merge","object","keyof","keys"],"mappings":"AAAA,SAAuBA,IAAI,QAAQ,oBAAmB;AAEtD,SAASC,QAAQ,EAAEC,eAAe,QAAQ,YAAW;AACrD,SAASC,QAAQ,QAAQ,YAAW;AAE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xD,OAAO,IAAIF,WACT;YAAE,GAAG,IAAI,CAACE,UAAU;YAAE,GAAGA,UAAU;QAAC,MACjC,IAAI,CAACkB,mBAAmB;IAE/B;IAEAG,MAA4BC,MAAS,EAAE;QACrC,OAAO,IAAIxB,WACT;YAAE,GAAG,IAAI,CAACE,UAAU;YAAE,GAAGsB,OAAOtB,UAAU;QAAC,MACxC,IAAI,CAACkB,mBAAmB;IAE/B;IAEAK,QAA+C;QAC7C,OAAO,IAAI1B,SAASO,OAAOoB,IAAI,CAAC,IAAI,CAACxB,UAAU;IACjD;AACF"}
1
+ {"version":3,"sources":["../../../src/types/object.ts"],"sourcesContent":["import {\n type ObjectOptions,\n type StaticEncode,\n type TObject,\n Type,\n} from '@sinclair/typebox'\nimport type { typeStatic } from '../constants.ts'\nimport type { UnionToTupleString } from '../utils.ts'\nimport { BaseType, getTypeSchema } from './base.ts'\nimport { EnumType } from './enum.ts'\n\nexport class ObjectType<\n T extends Record<string, BaseType> = Record<string, BaseType>,\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<\n TObject<{ [K in keyof T]: T[K][typeStatic]['schema'] }>,\n N,\n O,\n D\n> {\n constructor(\n protected readonly properties: T = {} as T,\n options: ObjectOptions = {},\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, properties)\n }\n\n protected _constructSchema(\n options: ObjectOptions,\n properties: T,\n ): TObject<{ [K in keyof T]: T[K][typeStatic]['schema'] }> {\n const schemaProperties = {} as {\n [K in keyof T]: T[K][typeStatic]['schema']\n }\n\n for (const [key, value] of Object.entries(properties)) {\n // @ts-expect-error\n schemaProperties[key] = getTypeSchema(value)\n }\n return Type.Object(schemaProperties, options)\n }\n\n nullable() {\n return new ObjectType(this.properties, ...this._with({ isNullable: true }))\n }\n\n optional() {\n return new ObjectType(this.properties, ...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new ObjectType(\n this.properties,\n ...this._with({ isNullable: true, isOptional: true }),\n )\n }\n\n default(value: this[typeStatic]['encoded']) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { description } }),\n )\n }\n\n examples(\n ...examples: [this[typeStatic]['encoded'], ...this[typeStatic]['encoded'][]]\n ) {\n return new ObjectType(\n this.properties,\n ...this._with({ options: { examples } }),\n )\n }\n\n pick<P extends { [K in keyof T]?: true }>(pick: P) {\n const properties = Object.fromEntries(\n Object.entries(this.properties).filter(([key]) => pick[key]),\n )\n const [_, ...args] = this._with()\n return new ObjectType(\n properties as Pick<T, Extract<keyof P, keyof T>>,\n {},\n ...args,\n )\n }\n\n omit<P extends { [K in keyof T]?: true }>(omit: P) {\n const properties = Object.fromEntries(\n Object.entries(this.properties).filter(([key]) => !omit[key]),\n )\n const [_, ...args] = this._with()\n return new ObjectType(\n properties as Omit<T, Extract<keyof P, keyof T>>,\n {},\n ...args,\n )\n }\n\n extend<P extends Record<string, BaseType>>(properties: P) {\n const [_, ...args] = this._with()\n return new ObjectType({ ...this.properties, ...properties }, {}, ...args)\n }\n\n merge<T extends ObjectType>(object: T) {\n const [_, ...args] = this._with()\n return new ObjectType(\n { ...this.properties, ...object.properties },\n {},\n ...args,\n )\n }\n\n partial() {\n const properties: { [K in keyof T]: ReturnType<T[K]['optional']> } =\n {} as any\n for (const [key, value] of Object.entries(this.properties)) {\n // @ts-expect-error\n properties[key] = value.optional()\n }\n const [_, ...args] = this._with()\n return new ObjectType(properties, {}, ...args)\n }\n\n keyof(): EnumType<UnionToTupleString<keyof T>> {\n return new EnumType(Object.keys(this.properties) as any)\n }\n}\n"],"names":["Type","BaseType","getTypeSchema","EnumType","ObjectType","constructor","properties","options","isNullable","isOptional","hasDefault","_constructSchema","schemaProperties","key","value","Object","entries","nullable","_with","optional","nullish","default","description","examples","pick","fromEntries","filter","_","args","omit","extend","merge","object","partial","keyof","keys"],"m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C,IAAI,CAACV,UAAU,EAAG;YAE1DA,UAAU,CAACO,IAAI,GAAGC,MAAMK,QAAQ;QAClC;QACA,MAAM,CAACQ,GAAG,GAAGC,KAAK,GAAG,IAAI,CAACV,KAAK;QAC/B,OAAO,IAAId,WAAWE,YAAY,CAAC,MAAMsB;IAC3C;IAEAM,QAA+C;QAC7C,OAAO,IAAI/B,SAASY,OAAOoB,IAAI,CAAC,IAAI,CAAC7B,UAAU;IACjD;AACF"}
@@ -1,41 +1,77 @@
1
1
  import { Type } from '@sinclair/typebox';
2
2
  import { BaseType } from "./base.js";
3
3
  export class StringType extends BaseType {
4
- constructor(schema = Type.String(), nullable = false, optional = false){
5
- super(schema, nullable, optional);
4
+ constructor(options = {}, isNullable = false, isOptional = false, hasDefault = false){
5
+ super(options, isNullable, isOptional, hasDefault);
6
+ }
7
+ _constructSchema(options) {
8
+ return Type.String(options);
6
9
  }
7
10
  nullable() {
8
- return new StringType(...this._nullable());
11
+ return new StringType(...this._with({
12
+ isNullable: true
13
+ }));
9
14
  }
10
15
  optional() {
11
- return new StringType(...this._optional());
16
+ return new StringType(...this._with({
17
+ isOptional: true
18
+ }));
12
19
  }
13
20
  nullish() {
14
- return new StringType(...this._nullish());
21
+ return new StringType(...this._with({
22
+ isNullable: true,
23
+ isOptional: true
24
+ }));
25
+ }
26
+ default(value) {
27
+ return new StringType(...this._with({
28
+ options: {
29
+ default: value
30
+ },
31
+ hasDefault: true
32
+ }));
33
+ }
34
+ description(description) {
35
+ return new StringType(...this._with({
36
+ options: {
37
+ description
38
+ }
39
+ }));
40
+ }
41
+ examples(...examples) {
42
+ return new StringType(...this._with({
43
+ options: {
44
+ examples
45
+ }
46
+ }));
15
47
  }
16
48
  format(format) {
17
- return new StringType({
18
- ...this._schema,
19
- format
20
- }, ...this._isNullableOptional);
49
+ return new StringType(...this._with({
50
+ options: {
51
+ format
52
+ }
53
+ }));
21
54
  }
22
55
  max(value) {
23
- return new StringType({
24
- ...this._schema,
25
- maxLength: value
26
- }, ...this._isNullableOptional);
56
+ return new StringType(...this._with({
57
+ options: {
58
+ maxLength: value
59
+ }
60
+ }));
27
61
  }
28
62
  min(value) {
29
- return new StringType({
30
- ...this._schema,
31
- minLength: value
32
- }, ...this._isNullableOptional);
63
+ return new StringType(...this._with({
64
+ options: {
65
+ minLength: value
66
+ }
67
+ }));
33
68
  }
34
69
  pattern(pattern) {
35
- return new StringType({
36
- ...this._schema,
37
- pattern
38
- }, ...this._isNullableOptional);
70
+ return new StringType(...this._with({
71
+ options: {
72
+ pattern
73
+ }
74
+ }));
39
75
  }
40
76
  email() {
41
77
  return this.format('email');
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/types/string.ts"],"sourcesContent":["import { type TString, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class StringType<\n N extends boolean = false,\n O extends boolean = false,\n> extends BaseType<TString, N, O> {\n constructor(\n schema = Type.String(),\n nullable: N = false as N,\n optional: O = false as O,\n ) {\n super(schema, nullable, optional)\n }\n\n nullable() {\n return new StringType(...this._nullable())\n }\n\n optional() {\n return new StringType(...this._optional())\n }\n\n nullish() {\n return new StringType(...this._nullish())\n }\n\n format(format: TString['format']) {\n return new StringType(\n {\n ...this._schema,\n format,\n },\n ...this._isNullableOptional,\n )\n }\n\n max(value: number) {\n return new StringType(\n {\n ...this._schema,\n maxLength: value,\n },\n ...this._isNullableOptional,\n )\n }\n\n min(value: number) {\n return new StringType(\n {\n ...this._schema,\n minLength: value,\n },\n ...this._isNullableOptional,\n )\n }\n\n pattern(pattern: string) {\n return new StringType(\n {\n ...this._schema,\n pattern,\n },\n ...this._isNullableOptional,\n )\n }\n\n email() {\n return this.format('email')\n }\n\n url() {\n return this.format('uri')\n }\n\n ipv4() {\n return this.format('ipv4')\n }\n\n ipv6() {\n return this.format('ipv6')\n }\n\n uuid() {\n return this.format('uuid')\n }\n}\n"],"names":["Type","BaseType","StringType","constructor","schema","String","nullable","optional","_nullable","_optional","nullish","_nullish","format","_schema","_isNullableOptional","max","value","maxLength","min","minLength","pattern","email","url","ipv4","ipv6","uuid"],"mappings":"AAAA,SAAuBA,IAAI,QAAQ,oBAAmB;AACtD,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MAAMC,mBAGHD;IACRE,YACEC,SAASJ,KAAKK,MAAM,EAAE,EACtBC,WAAc,KAAU,EACxBC,WAAc,KAAU,CACxB;QACA,KAAK,CAACH,QAAQE,UAAUC;IAC1B;IAEAD,WAAW;QACT,OAAO,IAAIJ,cAAc,IAAI,CAACM,SAAS;IACzC;IAEAD,WAAW;QACT,OAAO,IAAIL,cAAc,IAAI,CAACO,SAAS;IACzC;IAEAC,UAAU;QACR,OAAO,IAAIR,cAAc,IAAI,CAACS,QAAQ;IACxC;IAEAC,OAAOA,MAAyB,EAAE;QAChC,OAAO,IAAIV,WACT;YACE,GAAG,IAAI,CAACW,OAAO;YACfD;QACF,MACG,IAAI,CAACE,mBAAmB;IAE/B;IAEAC,IAAIC,KAAa,EAAE;QACjB,OAAO,IAAId,WACT;YACE,GAAG,IAAI,CAACW,OAAO;YACfI,WAAWD;QACb,MACG,IAAI,CAACF,mBAAmB;IAE/B;IAEAI,IAAIF,KAAa,EAAE;QACjB,OAAO,IAAId,WACT;YACE,GAAG,IAAI,CAACW,OAAO;YACfM,WAAWH;QACb,MACG,IAAI,CAACF,mBAAmB;IAE/B;IAEAM,QAAQA,OAAe,EAAE;QACvB,OAAO,IAAIlB,WACT;YACE,GAAG,IAAI,CAACW,OAAO;YACfO;QACF,MACG,IAAI,CAACN,mBAAmB;IAE/B;IAEAO,QAAQ;QACN,OAAO,IAAI,CAACT,MAAM,CAAC;IACrB;IAEAU,MAAM;QACJ,OAAO,IAAI,CAACV,MAAM,CAAC;IACrB;IAEAW,OAAO;QACL,OAAO,IAAI,CAACX,MAAM,CAAC;IACrB;IAEAY,OAAO;QACL,OAAO,IAAI,CAACZ,MAAM,CAAC;IACrB;IAEAa,OAAO;QACL,OAAO,IAAI,CAACb,MAAM,CAAC;IACrB;AACF"}
1
+ {"version":3,"sources":["../../../src/types/string.ts"],"sourcesContent":["import { type StringOptions, type TString, Type } from '@sinclair/typebox'\nimport { BaseType } from './base.ts'\n\nexport class StringType<\n N extends boolean = false,\n O extends boolean = false,\n D extends boolean = false,\n> extends BaseType<TString, 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): TString {\n return Type.String(options)\n }\n\n nullable() {\n return new StringType(...this._with({ isNullable: true }))\n }\n\n optional() {\n return new StringType(...this._with({ isOptional: true }))\n }\n\n nullish() {\n return new StringType(...this._with({ isNullable: true, isOptional: true }))\n }\n\n default(value: string) {\n return new StringType(\n ...this._with({ options: { default: value }, hasDefault: true }),\n )\n }\n\n description(description: string) {\n return new StringType(...this._with({ options: { description } }))\n }\n\n examples(...examples: string[]) {\n return new StringType(...this._with({ options: { examples } }))\n }\n\n format(format: TString['format']) {\n return new StringType(...this._with({ options: { format } }))\n }\n\n max(value: number) {\n return new StringType(\n ...this._with({\n options: { maxLength: value },\n }),\n )\n }\n\n min(value: number) {\n return new StringType(\n ...this._with({\n options: { minLength: value },\n }),\n )\n }\n\n pattern(pattern: string) {\n return new StringType(\n ...this._with({\n options: { pattern },\n }),\n )\n }\n\n email() {\n return this.format('email')\n }\n\n url() {\n return this.format('uri')\n }\n\n ipv4() {\n return this.format('ipv4')\n }\n\n ipv6() {\n return this.format('ipv6')\n }\n\n uuid() {\n return this.format('uuid')\n }\n}\n"],"names":["Type","BaseType","StringType","constructor","options","isNullable","isOptional","hasDefault","_constructSchema","String","nullable","_with","optional","nullish","default","value","description","examples","format","max","maxLength","min","minLength","pattern","email","url","ipv4","ipv6","uuid"],"mappings":"AAAA,SAA2CA,IAAI,QAAQ,oBAAmB;AAC1E,SAASC,QAAQ,QAAQ,YAAW;AAEpC,OAAO,MA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