structured-outputs 0.1.0-beta.22 → 0.1.0-beta.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. package/README.md +1 -1
  2. package/esm/ResponseFormat.d.ts +8 -8
  3. package/esm/ResponseFormat.d.ts.map +1 -1
  4. package/esm/ResponseFormat.js +4 -7
  5. package/esm/ResponseFormat.js.map +1 -1
  6. package/esm/Tool.d.ts +2 -3
  7. package/esm/Tool.d.ts.map +1 -1
  8. package/esm/Tool.js +2 -3
  9. package/esm/Tool.js.map +1 -1
  10. package/esm/types/Ty.d.ts +19 -12
  11. package/esm/types/Ty.d.ts.map +1 -1
  12. package/esm/types/Ty.js +28 -7
  13. package/esm/types/Ty.js.map +1 -1
  14. package/esm/types/array.d.ts +1 -1
  15. package/esm/types/array.d.ts.map +1 -1
  16. package/esm/types/array.js +1 -1
  17. package/esm/types/array.js.map +1 -1
  18. package/esm/types/constantUnion.d.ts +1 -1
  19. package/esm/types/constantUnion.d.ts.map +1 -1
  20. package/esm/types/constantUnion.js +1 -1
  21. package/esm/types/constantUnion.js.map +1 -1
  22. package/esm/types/mod.d.ts +2 -3
  23. package/esm/types/mod.d.ts.map +1 -1
  24. package/esm/types/mod.js +2 -3
  25. package/esm/types/mod.js.map +1 -1
  26. package/esm/types/object.d.ts +3 -4
  27. package/esm/types/object.d.ts.map +1 -1
  28. package/esm/types/object.js +3 -3
  29. package/esm/types/object.js.map +1 -1
  30. package/esm/types/primitives.d.ts +4 -4
  31. package/esm/types/primitives.d.ts.map +1 -1
  32. package/esm/types/primitives.js +4 -4
  33. package/esm/types/primitives.js.map +1 -1
  34. package/esm/types/std/Date.d.ts +4 -0
  35. package/esm/types/std/Date.d.ts.map +1 -0
  36. package/esm/types/std/Date.js +14 -0
  37. package/esm/types/std/Date.js.map +1 -0
  38. package/esm/types/std/Option.d.ts +3 -2
  39. package/esm/types/std/Option.d.ts.map +1 -1
  40. package/esm/types/std/Option.js +1 -1
  41. package/esm/types/std/color.d.ts +8 -0
  42. package/esm/types/std/color.d.ts.map +1 -0
  43. package/esm/types/std/color.js +13 -0
  44. package/esm/types/std/color.js.map +1 -0
  45. package/esm/types/std/mod.d.ts +2 -0
  46. package/esm/types/std/mod.d.ts.map +1 -1
  47. package/esm/types/std/mod.js +2 -0
  48. package/esm/types/std/mod.js.map +1 -1
  49. package/esm/types/taggedUnion.d.ts +1 -1
  50. package/esm/types/taggedUnion.d.ts.map +1 -1
  51. package/esm/types/taggedUnion.js +20 -14
  52. package/esm/types/taggedUnion.js.map +1 -1
  53. package/esm/types/transform.d.ts +3 -0
  54. package/esm/types/transform.d.ts.map +1 -0
  55. package/esm/types/transform.js +5 -0
  56. package/esm/types/transform.js.map +1 -0
  57. package/esm/types/tuple.d.ts +5 -0
  58. package/esm/types/tuple.d.ts.map +1 -0
  59. package/esm/types/tuple.js +11 -0
  60. package/esm/types/tuple.js.map +1 -0
  61. package/esm/util/recombine.d.ts +2 -0
  62. package/esm/util/recombine.d.ts.map +1 -0
  63. package/esm/util/recombine.js +4 -0
  64. package/esm/util/recombine.js.map +1 -0
  65. package/package.json +1 -1
  66. package/src/ResponseFormat.ts +14 -17
  67. package/src/Tool.ts +5 -6
  68. package/src/types/Ty.ts +71 -30
  69. package/src/types/array.ts +9 -5
  70. package/src/types/constantUnion.ts +2 -2
  71. package/src/types/mod.ts +2 -3
  72. package/src/types/object.ts +15 -9
  73. package/src/types/primitives.ts +8 -8
  74. package/src/types/std/Date.ts +19 -0
  75. package/src/types/std/Option.ts +2 -2
  76. package/src/types/std/color.ts +27 -0
  77. package/src/types/std/mod.ts +2 -0
  78. package/src/types/taggedUnion.ts +28 -15
  79. package/src/types/transform.ts +8 -0
  80. package/src/types/tuple.ts +17 -0
  81. package/src/util/recombine.ts +3 -0
  82. package/esm/oai.d.ts +0 -5
  83. package/esm/oai.d.ts.map +0 -1
  84. package/esm/oai.js +0 -2
  85. package/esm/oai.js.map +0 -1
  86. package/esm/types/Ref.d.ts +0 -4
  87. package/esm/types/Ref.d.ts.map +0 -1
  88. package/esm/types/Ref.js +0 -14
  89. package/esm/types/Ref.js.map +0 -1
  90. package/esm/types/RootTy.d.ts +0 -8
  91. package/esm/types/RootTy.d.ts.map +0 -1
  92. package/esm/types/RootTy.js +0 -17
  93. package/esm/types/RootTy.js.map +0 -1
  94. package/esm/types/constant.d.ts +0 -3
  95. package/esm/types/constant.d.ts.map +0 -1
  96. package/esm/types/constant.js +0 -7
  97. package/esm/types/constant.js.map +0 -1
  98. package/esm/util/phantoms.d.ts +0 -2
  99. package/esm/util/phantoms.d.ts.map +0 -1
  100. package/esm/util/phantoms.js +0 -4
  101. package/esm/util/phantoms.js.map +0 -1
  102. package/esm/util/recombineTaggedTemplateArgs.d.ts +0 -2
  103. package/esm/util/recombineTaggedTemplateArgs.d.ts.map +0 -1
  104. package/esm/util/recombineTaggedTemplateArgs.js +0 -4
  105. package/esm/util/recombineTaggedTemplateArgs.js.map +0 -1
  106. package/src/oai.ts +0 -5
  107. package/src/types/Ref.ts +0 -19
  108. package/src/types/RootTy.ts +0 -38
  109. package/src/types/constant.ts +0 -7
  110. package/src/util/phantoms.ts +0 -3
  111. package/src/util/recombineTaggedTemplateArgs.ts +0 -6
package/README.md CHANGED
@@ -64,7 +64,7 @@ const character = await openai.chat.completions
64
64
  messages: [...yourMessages],
65
65
  response_format,
66
66
  })
67
- .then(response_format.parseFirstChoice)
67
+ .then(response_format.into)
68
68
  ```
69
69
 
70
70
  ### Utilize The Typed, Unwrapped Data
@@ -1,16 +1,14 @@
1
- import type { ChatCompletion, JsonSchema } from "./oai.js";
2
- import type { RootTy } from "./types/mod.js";
1
+ import type Openai from "openai";
2
+ import type { Ty } from "./types/mod.js";
3
3
  export interface ResponseFormat<T> {
4
4
  (template: TemplateStringsArray, ...quasis: Array<string>): ResponseFormat<T>;
5
5
  type: "json_schema";
6
6
  /** The desired return type in JSON Schema. */
7
- json_schema: JsonSchema;
8
- /** Parse the content of the first choice into a typed object. */
9
- parseFirstChoice(completion: ChatCompletion): T;
10
- /** Parse all choice contents into an array of typed object. */
11
- parseChoices(completion: ChatCompletion): Array<T>;
7
+ json_schema: Openai.ResponseFormatJSONSchema["json_schema"];
8
+ /** Transform the content of the first choice into a typed object. */
9
+ into(completion: ChatCompletion): T;
12
10
  }
13
- export declare function ResponseFormat<T>(name: string, ty: RootTy<T, never>): ResponseFormat<T>;
11
+ export declare function ResponseFormat<T>(name: string, ty: Ty<T, never, true>): ResponseFormat<T>;
14
12
  export declare namespace ResponseFormat {
15
13
  function unwrapFirstChoice(completion: ChatCompletion): string;
16
14
  function unwrapChoices(completions: ChatCompletion): string[];
@@ -18,4 +16,6 @@ export declare namespace ResponseFormat {
18
16
  export declare class ResponseFormatUnwrapError extends Error {
19
17
  readonly name = "UnwrapResponseError";
20
18
  }
19
+ type ChatCompletion = Openai.Chat.ChatCompletion;
20
+ export {};
21
21
  //# sourceMappingURL=ResponseFormat.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ResponseFormat.d.ts","sourceRoot":"","sources":["../src/ResponseFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAwB,UAAU,EAAE,MAAM,UAAU,CAAA;AAChF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAG5C,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAA;IAC7E,IAAI,EAAE,aAAa,CAAA;IACnB,8CAA8C;IAC9C,WAAW,EAAE,UAAU,CAAA;IACvB,iEAAiE;IACjE,gBAAgB,CAAC,UAAU,EAAE,cAAc,GAAG,CAAC,CAAA;IAC/C,+DAA+D;IAC/D,YAAY,CAAC,UAAU,EAAE,cAAc,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;CACnD;AAED,wBAAgB,cAAc,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,E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BAAwB;CAC/C;AAED,KAAK,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,cAAc,CAAA"}
@@ -1,9 +1,9 @@
1
- import { recombineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js";
1
+ import { recombine } from "./util/recombine.js";
2
2
  export function ResponseFormat(name, ty) {
3
3
  return ResponseFormat_(name, ty);
4
4
  }
5
5
  function ResponseFormat_(name, ty, description) {
6
- return Object.assign((template, ...quasis) => ResponseFormat_(name, ty, description ? `${description} ${recombineTaggedTemplateArgs(template, quasis)}` : undefined), {
6
+ return Object.assign((template, ...quasis) => ResponseFormat_(name, ty, description ? `${description} ${recombine(template, quasis)}` : undefined), {
7
7
  type: "json_schema",
8
8
  json_schema: {
9
9
  name,
@@ -11,11 +11,8 @@ function ResponseFormat_(name, ty, description) {
11
11
  schema: ty.schema(),
12
12
  strict: true,
13
13
  },
14
- parseFirstChoice: (completion) => {
15
- return JSON.parse(ResponseFormat.unwrapFirstChoice(completion));
16
- },
17
- parseChoices: (completion) => {
18
- return ResponseFormat.unwrapChoices(completion).map((content) => JSON.parse(content));
14
+ into: (completion) => {
15
+ return ty[""].transform(JSON.parse(ResponseFormat.unwrapFirstChoice(completion)));
19
16
  },
20
17
  toJSON() {
21
18
  const { type, json_schema } = this;
@@ -1 +1 @@
1
- {"version":3,"file":"ResponseFormat.js","sourceRoot":"","sources":["../src/ResponseFormat.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAA;AAanF,MAAM,UAAU,cAAc,CAAI,IAAY,EAAE,EAAoB;IAClE,OAAO,eAAe,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AAClC,CAAC;AAED,SAAS,eAAe,CACtB,IAAY,EACZ,EAAoB,EACpB,WAAoB;IAEpB,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,QAA8B,EAAE,GAAG,MAAqB,EAAE,EAAE,CAC3D,eAAe,CACb,IAAI,EACJ,EAAE,EACF,W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jC,iDAAiD,OAAO,EAAE,CAC3D,CAAA;QACH,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,yBAAyB,CAAC,6CAA6C,CAAC,CAAA;QACpF,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC,EA/BgB,cAAc,KAAd,cAAc,QA+B9B;AAED,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAApD;;QACoB;;;;mBAAO,qBAAqB;WAAA;IAChD,CAAC;CAAA"}
package/esm/Tool.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import type { RootTy, Schema } from "./types/mod.js";
2
- /** @experimental */
3
- export declare function Tool<T>(name: string, ty: RootTy<T, never>): Tool<T>;
1
+ import type { Schema, Ty } from "./types/mod.js";
2
+ export declare function Tool<T>(name: string, ty: Ty<T, never, true>): Tool<T>;
4
3
  export interface Tool<T = any> {
5
4
  (template: TemplateStringsArray, ...quasis: Array<string>): Tool<T>;
6
5
  type: "function";
package/esm/Tool.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Tool.d.ts","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGpD,oBAAoB;AACpB,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAEnE;AAuBD,MAAM,WAAW,IAAI,CAAC,CAAC,GAAG,GAAG;IAC3B,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACnE,IAAI,EAAE,UAAU,CAAA;IAChB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
1
+ {"version":3,"file":"Tool.d.ts","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAA;AAGhD,wBAAgB,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAErE;AAuBD,MAAM,WAAW,IAAI,CAAC,CAAC,GAAG,GAAG;IAC3B,CAAC,QAAQ,EAAE,oBAAoB,EAAE,GAAG,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;IACnE,IAAI,EAAE,UAAU,CAAA;IAChB,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,mEAAmE;IACnE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB"}
package/esm/Tool.js CHANGED
@@ -1,10 +1,9 @@
1
- import { recombineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js";
2
- /** @experimental */
1
+ import { recombine } from "./util/recombine.js";
3
2
  export function Tool(name, ty) {
4
3
  return Tool_(name, ty);
5
4
  }
6
5
  function Tool_(name, ty, description) {
7
- return Object.assign((template, ...quasis) => Tool_(name, ty, description ? `${description} ${recombineTaggedTemplateArgs(template, quasis)}` : undefined), {
6
+ return Object.assign((template, ...quasis) => Tool_(name, ty, description ? `${description} ${recombine(template, quasis)}` : undefined), {
8
7
  type: "function",
9
8
  name,
10
9
  description,
package/esm/Tool.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Tool.js","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AACA,OAA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,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAC1E,EACH;QACE,IAAI,EAAE,UAAmB;QACzB,IAAI;QACJ,WAAW;QACX,UAAU,EAAE,EAAE,CAAC,MAAM,EAAE;QACvB,MAAM;YACJ,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,IAAI,CAAA;YACpD,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAA;QAChD,CAAC;KACF,CACF,CAAA;AACH,CAAC"}
package/esm/types/Ty.d.ts CHANGED
@@ -1,23 +1,30 @@
1
- import type { Ref } from "./Ref.js";
2
- import type { RootTy } from "./RootTy.js";
3
- export declare function Ty<T, P extends keyof any = never>(toSchema: ToSchema, context?: Array<Context>, applied?: Applied): Ty<T, P>;
4
- export interface Ty<T = any, P extends keyof any = keyof any> {
5
- <P2 extends Array<keyof any>>(template: TemplateStringsArray, ...placeheld: P2): Ty<T, P | P2[number]>;
1
+ export interface Ty<T = any, P extends keyof any = keyof any, R extends boolean = boolean> {
2
+ <P2 extends Array<keyof any>>(template: TemplateStringsArray, ...placeheld: P2): Ty<T, P | P2[number], R>;
3
+ /** The native TypeScript type. The runtime value is nonexistent. */
6
4
  T: T;
5
+ /** The literal types of the placeheld keys. The runtime value is nonexistent. */
7
6
  P: P;
8
7
  "": {
9
- toSchema: ToSchema;
8
+ subschema: Subschema;
9
+ root: R;
10
+ transform: (value: any) => any;
10
11
  context: Array<Context>;
11
12
  applied: Applied;
12
13
  };
13
- fill: <A extends Partial<Record<P, number | string>>>(values: A) => Ty<T, Exclude<P, keyof A>>;
14
- isRoot(): this is RootTy;
14
+ /** Inject context into that which is placeheld. */
15
+ fill: <A extends Partial<Record<P, number | string>>>(values: A) => Ty<T, Exclude<P, keyof A>, R>;
16
+ /** Get the corresponding JSON Schema. */
17
+ schema(this: Ty<T, never>): Schema;
15
18
  }
16
- export type ToSchema = (ref: Ref) => Schema;
17
- export type Schema = Record<string, unknown>;
18
- export interface Context {
19
+ export declare function Ty<T, P extends keyof any, R extends boolean, I = T>(subschema: Subschema, root: R, transform?: (value: I) => T, context?: Array<Context>, applied?: Applied): Ty<T, P, R>;
20
+ export type Subschema = (subschema: SubschemaFactory) => Schema;
21
+ export type SubschemaFactory = (ty: Ty) => Schema;
22
+ export declare function SubschemaFactory(applied: Applied): SubschemaFactory;
23
+ interface Context {
19
24
  template: TemplateStringsArray;
20
25
  placeheld: Array<keyof any>;
21
26
  }
22
- export type Applied = Record<keyof any, number | string>;
27
+ type Applied = Record<keyof any, number | string>;
28
+ export type Schema = Record<string, unknown>;
29
+ export {};
23
30
  //# sourceMappingURL=Ty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Ty.d.ts","sourceRoot":"","sources":["../../src/types/Ty.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,wBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,GAAG,KAAK,EAC/C,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE,KAAK,CAAC,OAAO,CAAM,EAC5B,OAAO,GAAE,OAAY,GACpB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAeV;AAED,MAAM,WAAW,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,GAAG,MAAM,GAAG;IAC1D,CAAC,EAAE,SAAS,KAAK,CAAC,MAAM,GAAG,CAAC,EAC1B,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,SAAS,EAAE,EAAE,GACf,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IACxB,CAAC,EAAE,CAAC,CAAA;IACJ,CAAC,EAAE,CAAC,CAAA;IACJ,E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AAG,CAAC,CAAA;CAC5B;AACD,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA;AAEjD,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA"}
package/esm/types/Ty.js CHANGED
@@ -1,13 +1,34 @@
1
- import { phantoms } from "../util/phantoms.js";
2
- export function Ty(toSchema, context = [], applied = {}) {
3
- return Object.assign((template, ...placeheld) => Ty(toSchema, [{ template, placeheld }, ...context], applied), phantoms(), {
4
- "": { toSchema, context, applied },
1
+ import { recombine } from "../util/recombine.js";
2
+ export function Ty(subschema, root, transform = (value) => value, context = [], applied = {}) {
3
+ return Object.assign((template, ...placeheld) => Ty(subschema, root, transform, [{ template, placeheld }, ...context], applied), {}, {
4
+ "": {
5
+ subschema,
6
+ root,
7
+ transform,
8
+ context,
9
+ applied,
10
+ },
5
11
  fill: (values) => {
6
- return Ty(toSchema, context, { ...applied, ...values });
12
+ return Ty(subschema, root, transform, context, {
13
+ ...applied,
14
+ ...values,
15
+ });
7
16
  },
8
- isRoot() {
9
- return false;
17
+ schema() {
18
+ return SubschemaFactory({})(this);
10
19
  },
11
20
  });
12
21
  }
22
+ export function SubschemaFactory(applied) {
23
+ return (ty) => {
24
+ applied = { ...applied, ...ty[""].applied };
25
+ const description = ty[""].context
26
+ .map(({ template, placeheld }) => recombine(template, placeheld.map((k) => applied[k])))
27
+ .join(" ");
28
+ return {
29
+ ...ty[""].subschema(SubschemaFactory(applied)),
30
+ ...description ? { description } : {},
31
+ };
32
+ };
33
+ }
13
34
  //# sourceMappingURL=Ty.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Ty.js","sourceRoot":"","sources":["../../src/types/Ty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAI9C,MAAM,UAAU,EAAE,CAChB,QAAkB,EAClB,UAA0B,EAAE,EAC5B,UAAmB,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,MAAM;aACV,CAAC,CAAA;QACJ,CAAC;QACD,MAAM;YACJ,OAAO,gBAAgB,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;QACnC,CAAC;KACF,CACF,CAAA;AACH,CAAC;AAKD,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,OAAO,CAAC,EAAE,EAAE,EAAE;QACZ,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAA;QAC3C,MAAM,WAAW,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO;aAC/B,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC;aACxF,IAAI,CAAC,GAAG,CAAC,CAAA;QACZ,OAAO;YACL,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAC9C,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE;SACtC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import { Ty } from "./Ty.js";
2
- export declare function array<E extends Ty>(element: E): Ty<Array<E["T"]>, E["P"]>;
2
+ export declare function array<E extends Ty>(element: E): Ty<Array<E["T"]>, E["P"], false>;
3
3
  //# sourceMappingURL=array.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/types/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAKzE"}
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/types/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAShF"}
@@ -3,6 +3,6 @@ export function array(element) {
3
3
  return Ty((ref) => ({
4
4
  type: "array",
5
5
  items: ref(element),
6
- }));
6
+ }), false, (value) => value.map(element[""].transform));
7
7
  }
8
8
  //# sourceMappingURL=array.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/types/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,KAAK,CAAe,OAAU;IAC5C,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAClB,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC;KACpB,CAAC,CAAC,CAAA;AACL,CAAC"}
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/types/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,KAAK,CAAe,OAAU;IAC5C,OAAO,EAAE,CACP,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACR,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC;KACpB,CAAC,EACF,KAAK,EACL,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAC5C,CAAA;AACH,CAAC"}
@@ -1,3 +1,3 @@
1
1
  import { Ty } from "./Ty.js";
2
- export declare function constantUnion<M extends Array<number | string>>(...members: M): Ty<M[number], never>;
2
+ export declare function constantUnion<M extends Array<number | string>>(...members: M): Ty<M[number], never, false>;
3
3
  //# sourceMappingURL=constantUnion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constantUnion.d.ts","sourceRoot":"","sources":["../../src/types/constantUnion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAC5D,GAAG,OAAO,EAAE,CAAC,GACZ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAkBtB"}
1
+ {"version":3,"file":"constantUnion.d.ts","sourceRoot":"","sources":["../../src/types/constantUnion.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,aAAa,CAAC,CAAC,SAAS,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,EAC5D,GAAG,OAAO,EAAE,CAAC,GACZ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAkB7B"}
@@ -17,6 +17,6 @@ export function constantUnion(...members) {
17
17
  }]
18
18
  : [],
19
19
  ],
20
- }));
20
+ }), false);
21
21
  }
22
22
  //# sourceMappingURL=constantUnion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constantUnion.js","sourceRoot":"","sources":["../../src/types/constantUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8CAA8C,CAAA;AACxE,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,aAAa,CAC3B,GAAG,OAAU;IA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AAC,EAAE,KAAK,CAAC,CAAA;AACZ,CAAC"}
@@ -1,11 +1,10 @@
1
1
  export * from "./array.js";
2
- export * from "./constant.js";
3
2
  export * from "./constantUnion.js";
4
3
  export * from "./object.js";
5
4
  export * from "./primitives.js";
6
- export * from "./Ref.js";
7
- export * from "./RootTy.js";
8
5
  export * from "./std/mod.js";
9
6
  export * from "./taggedUnion.js";
7
+ export * from "./transform.js";
8
+ export * from "./tuple.js";
10
9
  export * from "./Ty.js";
11
10
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/types/mod.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/types/mod.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
package/esm/types/mod.js CHANGED
@@ -1,11 +1,10 @@
1
1
  export * from "./array.js";
2
- export * from "./constant.js";
3
2
  export * from "./constantUnion.js";
4
3
  export * from "./object.js";
5
4
  export * from "./primitives.js";
6
- export * from "./Ref.js";
7
- export * from "./RootTy.js";
8
5
  export * from "./std/mod.js";
9
6
  export * from "./taggedUnion.js";
7
+ export * from "./transform.js";
8
+ export * from "./tuple.js";
10
9
  export * from "./Ty.js";
11
10
  //# sourceMappingURL=mod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/types/mod.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/types/mod.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA"}
@@ -1,6 +1,5 @@
1
- import { RootTy } from "./RootTy.js";
2
- import type { Ty } from "./Ty.js";
3
- export declare function object<F extends Record<string, Ty>>(fields: F): RootTy<{
1
+ import { Ty } from "./Ty.js";
2
+ export declare function object<F extends Record<string, Ty>>(fields: F): Ty<{
4
3
  [K in keyof F]: F[K]["T"];
5
- }, F[keyof F]["P"]>;
4
+ }, F[keyof F]["P"], true>;
6
5
  //# sourceMappingURL=object.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/types/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAEjC,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EACjD,MAAM,EAAE,CAAC,GACR,MAAM,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;CAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAOxD"}
1
+ {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/types/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EACjD,MAAM,EAAE,CAAC,GACR,EAAE,CAAC;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;CAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAc1D"}
@@ -1,10 +1,10 @@
1
- import { RootTy } from "./RootTy.js";
1
+ import { Ty } from "./Ty.js";
2
2
  export function object(fields) {
3
- return RootTy((ref) => ({
3
+ return Ty((ref) => ({
4
4
  type: "object",
5
5
  properties: Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, ref(v)])),
6
6
  additionalProperties: false,
7
7
  required: Object.keys(fields),
8
- }));
8
+ }), true, (v) => Object.fromEntries(Object.entries(v).map(([k, v]) => [k, fields[k][""].transform(v)])));
9
9
  }
10
10
  //# sourceMappingURL=object.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/types/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,MAAM,UAAU,MAAM,CACpB,MAAS;IAET,OAAO,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACtB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnF,oBAAoB,EAAE,KAAK;QAC3B,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;KAC9B,CAAC,CAAC,CAAA;AACL,CAAC"}
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/types/object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,MAAM,CACpB,MAAS;IAET,OAAO,EAAE,CACP,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QACR,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnF,oBAAoB,EAAE,KAAK;QAC3B,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;KAC9B,CAAC,EACF,IAAI,EACJ,CAAC,CAAC,EAAE,EAAE,CACJ,MAAM,CAAC,WAAW,CAChB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAE,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAC3D,CACb,CAAA;AACH,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Ty } from "./Ty.js";
2
- export declare const none: Ty<null, never>;
3
- export declare const boolean: Ty<boolean, never>;
4
- export declare const number: Ty<number, never>;
5
- export declare const string: Ty<string, never>;
2
+ export declare const none: Ty<null, never, false>;
3
+ export declare const boolean: Ty<boolean, never, false>;
4
+ export declare const number: Ty<number, never, false>;
5
+ export declare const string: Ty<string, never, false>;
6
6
  //# sourceMappingURL=primitives.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/types/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,CAE9B,CAAA;AAEH,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,CAEpC,CAAA;AAEH,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAElC,CAAA;AAEH,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAElC,CAAA"}
1
+ {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/types/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAE9B,CAAA;AAEV,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAEpC,CAAA;AAEV,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAElC,CAAA;AAEV,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAElC,CAAA"}
@@ -1,14 +1,14 @@
1
1
  import { Ty } from "./Ty.js";
2
2
  export const none = Ty(() => ({
3
3
  type: "null",
4
- }));
4
+ }), false);
5
5
  export const boolean = Ty(() => ({
6
6
  type: "boolean",
7
- }));
7
+ }), false);
8
8
  export const number = Ty(() => ({
9
9
  type: "number",
10
- }));
10
+ }), false);
11
11
  export const string = Ty(() => ({
12
12
  type: "string",
13
- }));
13
+ }), false);
14
14
  //# sourceMappingURL=primitives.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/types/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,CAAC,MAAM,IAAI,GAAoB,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IAC7C,IAAI,EAAE,MAAM;CACb,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,OAAO,GAAuB,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACnD,IAAI,EAAE,SAAS;CAChB,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,MAAM,GAAsB,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,IAAI,EAAE,QAAQ;CACf,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,MAAM,GAAsB,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACjD,IAAI,EAAE,QAAQ;CACf,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../src/types/primitives.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,CAAC,MAAM,IAAI,GAA2B,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACpD,IAAI,EAAE,MAAM;CACb,CAAC,EAAE,KAAK,CAAC,CAAA;AAEV,MAAM,CAAC,MAAM,OAAO,GAA8B,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IAC1D,IAAI,EAAE,SAAS;CAChB,CAAC,EAAE,KAAK,CAAC,CAAA;AAEV,MAAM,CAAC,MAAM,MAAM,GAA6B,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACxD,IAAI,EAAE,QAAQ;CACf,CAAC,EAAE,KAAK,CAAC,CAAA;AAEV,MAAM,CAAC,MAAM,MAAM,GAA6B,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;IACxD,IAAI,EAAE,QAAQ;CACf,CAAC,EAAE,KAAK,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import type { Ty } from "../Ty.js";
2
+ export { Date_ as Date };
3
+ declare const Date_: Ty<Date, never, true>;
4
+ //# sourceMappingURL=Date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Date.d.ts","sourceRoot":"","sources":["../../../src/types/std/Date.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAElC,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAA;AACxB,QAAA,MAAM,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAYhC,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { object } from "../object.js";
2
+ import { number } from "../primitives.js";
3
+ import { transform } from "../transform.js";
4
+ export { Date_ as Date };
5
+ const Date_ = transform(object({
6
+ year: number,
7
+ month: number `Zero-based (0 for January, 11 for December).`,
8
+ day: number `Day of the month (1-31). Ensure within available range for the specified month.`,
9
+ hour: number `Zero-based (0-23)`,
10
+ minute: number `Zero-based (0-59)`,
11
+ second: number `Zero-based (0-59)`,
12
+ millisecond: number `Zero-based (0-999)`,
13
+ }), ({ year, month, day, hour, minute, second, millisecond }) => new Date(year, month, day, hour, minute, second, millisecond));
14
+ //# sourceMappingURL=Date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Date.js","sourceRoot":"","sources":["../../../src/types/std/Date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG3C,OAAO,EAAE,KAAK,IAAI,IAAI,EAAE,CAAA;AACxB,MAAM,KAAK,GAA0B,SAAS,CAC5C,MAAM,CAAC;IACL,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,MAAM,CAAA,8CAA8C;IAC3D,GAAG,EAAE,MAAM,CAAA,iFAAiF;IAC5F,IAAI,EAAE,MAAM,CAAA,mBAAmB;IAC/B,MAAM,EAAE,MAAM,CAAA,mBAAmB;IACjC,MAAM,EAAE,MAAM,CAAA,mBAAmB;IACjC,WAAW,EAAE,MAAM,CAAA,oBAAoB;CACxC,CAAC,EACF,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,EAAE,CAC1D,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAChE,CAAA"}
@@ -1,7 +1,8 @@
1
+ import { none } from "../primitives.js";
1
2
  import { taggedUnion } from "../taggedUnion.js";
2
3
  import type { Ty } from "../Ty.js";
3
- export declare function option<S extends Ty>(Some: S): ReturnType<typeof taggedUnion<{
4
+ export declare function Option<S extends Ty>(Some: S): ReturnType<typeof taggedUnion<{
4
5
  Some: S;
5
- None: Ty<null, never>;
6
+ None: typeof none;
6
7
  }>>;
7
8
  //# sourceMappingURL=Option.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../../src/types/std/Option.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAElC,wBAAgB,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,UAAU,CACvD,OAAO,WAAW,CAAC;IACjB,IAAI,EAAE,CAAC,CAAA;IACP,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;CACtB,CAAC,CACH,CAKA"}
1
+ {"version":3,"file":"Option.d.ts","sourceRoot":"","sources":["../../../src/types/std/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAElC,wBAAgB,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,GAAG,UAAU,CACvD,OAAO,WAAW,CAAC;IACjB,IAAI,EAAE,CAAC,CAAA;IACP,IAAI,EAAE,OAAO,IAAI,CAAA;CAClB,CAAC,CACH,CAKA"}
@@ -1,6 +1,6 @@
1
1
  import { none } from "../primitives.js";
2
2
  import { taggedUnion } from "../taggedUnion.js";
3
- export function option(Some) {
3
+ export function Option(Some) {
4
4
  return taggedUnion({
5
5
  Some,
6
6
  None: none,
@@ -0,0 +1,8 @@
1
+ import type { Ty } from "../Ty.js";
2
+ export declare const Rgb: Ty<{
3
+ r: number;
4
+ g: number;
5
+ b: number;
6
+ }, never, true>;
7
+ export declare const Hex: Ty<string, never, true>;
8
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../src/types/std/color.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAA;AAElC,eAAO,MAAM,GAAG,EAAE,EAAE,CAClB;IACE,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;IACT,CAAC,EAAE,MAAM,CAAA;CACV,EACD,KAAK,EACL,IAAI,CAKJ,CAAA;AAEF,eAAO,MAAM,GAAG,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,CAGvC,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { object } from "../object.js";
2
+ import { number } from "../primitives.js";
3
+ import { transform } from "../transform.js";
4
+ export const Rgb = object({
5
+ r: number `Between 0 and 255`,
6
+ g: number `Between 0 and 255`,
7
+ b: number `Between 0 and 255`,
8
+ });
9
+ export const Hex = transform(Rgb, ({ r, g, b }) => `${toHex(r)}${toHex(g)}${toHex(b)}"`);
10
+ function toHex(value) {
11
+ return value.toString(16).padStart(2, "0");
12
+ }
13
+ //# sourceMappingURL=color.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.js","sourceRoot":"","sources":["../../../src/types/std/color.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAG3C,MAAM,CAAC,MAAM,GAAG,GAQZ,MAAM,CAAC;IACT,CAAC,EAAE,MAAM,CAAA,mBAAmB;IAC5B,CAAC,EAAE,MAAM,CAAA,mBAAmB;IAC5B,CAAC,EAAE,MAAM,CAAA,mBAAmB;CAC7B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,GAAG,GAA4B,SAAS,CACnD,GAAG,EACH,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CACtD,CAAA;AAED,SAAS,KAAK,CAAC,KAAa;IAC1B,OAAO,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;AAC5C,CAAC"}
@@ -1,3 +1,5 @@
1
+ export * from "./color.js";
2
+ export * from "./Date.js";
1
3
  export * from "./Option.js";
2
4
  export * from "./Wrapper.js";
3
5
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/types/std/mod.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/types/std/mod.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
@@ -1,3 +1,5 @@
1
+ export * from "./color.js";
2
+ export * from "./Date.js";
1
3
  export * from "./Option.js";
2
4
  export * from "./Wrapper.js";
3
5
  //# sourceMappingURL=mod.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../src/types/std/mod.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"mod.js","sourceRoot":"","sources":["../../../src/types/std/mod.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA"}
@@ -4,5 +4,5 @@ export declare function taggedUnion<M extends Record<string, Ty>>(members: M): T
4
4
  type: K;
5
5
  value: M[K]["T"];
6
6
  };
7
- }[keyof M], M[keyof M]["P"]>;
7
+ }[keyof M], M[keyof M]["P"], false>;
8
8
  //# sourceMappingURL=taggedUnion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"taggedUnion.d.ts","sourceRoot":"","sources":["../../src/types/taggedUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,CACvE;KACG,CAAC,IAAI,MAAM,CAAC,GAAG;QACd,IAAI,EAAE,CAAC,CAAA;QACP,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;KACjB;CACF,CAAC,MAAM,CAAC,CAAC,EACV,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAChB,CAgBA"}
1
+ {"version":3,"file":"taggedUnion.d.ts","sourceRoot":"","sources":["../../src/types/taggedUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAA;AAEzC,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,EAAE,CACvE;KACG,CAAC,IAAI,MAAM,CAAC,GAAG;QACd,IAAI,EAAE,CAAC,CAAA;QACP,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;KACjB;CACF,CAAC,MAAM,CAAC,CAAC,EACV,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,EACf,KAAK,CACN,CAaA"}
@@ -1,19 +1,25 @@
1
1
  import { Ty } from "./Ty.js";
2
2
  export function taggedUnion(members) {
3
- return Ty((ref) => ({
4
- discriminator: "type",
5
- anyOf: Object.entries(members).map(([k, v]) => ({
6
- type: "object",
7
- properties: {
8
- type: {
9
- type: "string",
10
- const: k,
11
- },
12
- value: ref(v),
3
+ const entries = Object.entries(members);
4
+ return Ty((subschema) => entries.length === 1
5
+ ? variant(entries[0][0], subschema(entries[0][1]))
6
+ : {
7
+ discriminator: "type",
8
+ anyOf: entries.map(([k, v]) => variant(k, subschema(v))),
9
+ }, false, (v) => members[v.type][""].transform(v));
10
+ }
11
+ function variant(type, value) {
12
+ return {
13
+ type: "object",
14
+ properties: {
15
+ type: {
16
+ type: "string",
17
+ const: type,
13
18
  },
14
- required: ["type", "value"],
15
- additionalProperties: false,
16
- })),
17
- }));
19
+ value,
20
+ },
21
+ required: ["type", "value"],
22
+ additionalProperties: false,
23
+ };
18
24
  }
19
25
  //# sourceMappingURL=taggedUnion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"taggedUnion.js","sourceRoot":"","sources":["../../src/types/taggedUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,WAAW,CAA+B,OAAU;IASlE,OAAO,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAClB,aAAa,EAAE,MAAM;QACrB,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9C,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,CAAC;iBACT;gBACD,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;aACd;YACD,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC;YAC3B,oBAAoB,EAAE,KAAK;SAC5B,CAAC,CAAC;KACJ,CAAC,CAAC,CAAA;AACL,CAAC"}
1
+ {"version":3,"file":"taggedUnion.js","sourceRoot":"","sources":["../../src/types/taggedUnion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAA;AAEzC,MAAM,UAAU,WAAW,CAA+B,OAAU;IAUlE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO,EAAE,CACP,CAAC,SAAS,EAAE,EAAE,CACZ,OAAO,CAAC,MAAM,KAAK,CAAC;QAClB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC,C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