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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. package/README.md +46 -40
  2. package/esm/ResponseFormat.d.ts +1 -1
  3. package/esm/ResponseFormat.d.ts.map +1 -1
  4. package/esm/ResponseFormat.js.map +1 -1
  5. package/esm/Tool.d.ts +1 -0
  6. package/esm/Tool.d.ts.map +1 -1
  7. package/esm/Tool.js +1 -0
  8. package/esm/Tool.js.map +1 -1
  9. package/esm/types/Ref.d.ts.map +1 -1
  10. package/esm/types/Ref.js +6 -3
  11. package/esm/types/Ref.js.map +1 -1
  12. package/esm/types/RootTy.d.ts +5 -5
  13. package/esm/types/RootTy.d.ts.map +1 -1
  14. package/esm/types/RootTy.js +5 -7
  15. package/esm/types/RootTy.js.map +1 -1
  16. package/esm/types/Ty.d.ts +15 -19
  17. package/esm/types/Ty.d.ts.map +1 -1
  18. package/esm/types/Ty.js +5 -9
  19. package/esm/types/Ty.js.map +1 -1
  20. package/esm/types/array.d.ts +1 -1
  21. package/esm/types/array.d.ts.map +1 -1
  22. package/esm/types/array.js +1 -2
  23. package/esm/types/array.js.map +1 -1
  24. package/esm/types/constant.d.ts.map +1 -1
  25. package/esm/types/constant.js +1 -2
  26. package/esm/types/constant.js.map +1 -1
  27. package/esm/types/constantUnion.d.ts.map +1 -1
  28. package/esm/types/constantUnion.js +16 -19
  29. package/esm/types/constantUnion.js.map +1 -1
  30. package/esm/types/mod.d.ts +3 -3
  31. package/esm/types/mod.d.ts.map +1 -1
  32. package/esm/types/mod.js +3 -3
  33. package/esm/types/mod.js.map +1 -1
  34. package/esm/types/object.d.ts +2 -2
  35. package/esm/types/object.d.ts.map +1 -1
  36. package/esm/types/object.js +1 -2
  37. package/esm/types/object.js.map +1 -1
  38. package/esm/types/{leaves.d.ts → primitives.d.ts} +1 -1
  39. package/esm/types/primitives.d.ts.map +1 -0
  40. package/esm/types/primitives.js +14 -0
  41. package/esm/types/primitives.js.map +1 -0
  42. package/esm/types/std/Option.js +1 -1
  43. package/esm/types/std/Option.js.map +1 -1
  44. package/esm/types/std/Wrapper.d.ts +0 -1
  45. package/esm/types/std/Wrapper.d.ts.map +1 -1
  46. package/esm/types/std/Wrapper.js.map +1 -1
  47. package/esm/types/taggedUnion.d.ts +2 -2
  48. package/esm/types/taggedUnion.d.ts.map +1 -1
  49. package/esm/types/taggedUnion.js +1 -2
  50. package/esm/types/taggedUnion.js.map +1 -1
  51. package/package.json +2 -2
  52. package/src/ResponseFormat.ts +1 -1
  53. package/src/Tool.ts +1 -0
  54. package/src/types/Ref.ts +7 -4
  55. package/src/types/RootTy.ts +11 -13
  56. package/src/types/Ty.ts +23 -30
  57. package/src/types/array.ts +2 -3
  58. package/src/types/constant.ts +1 -2
  59. package/src/types/constantUnion.ts +16 -19
  60. package/src/types/mod.ts +3 -3
  61. package/src/types/object.ts +4 -6
  62. package/src/types/primitives.ts +17 -0
  63. package/src/types/std/Option.ts +1 -1
  64. package/src/types/std/Wrapper.ts +0 -2
  65. package/src/types/taggedUnion.ts +3 -4
  66. package/esm/types/leaves.d.ts.map +0 -1
  67. package/esm/types/leaves.js +0 -18
  68. package/esm/types/leaves.js.map +0 -1
  69. package/src/types/leaves.ts +0 -21
package/README.md CHANGED
@@ -1,7 +1,13 @@
1
- # Structured Outputs
1
+ # Structured Outputs TypeScript
2
2
 
3
- A TypeScript library for composing
4
- [OpenAI structured output schemas](https://platform.openai.com/docs/guides/structured-outputs).
3
+ > A library for working with OpenAI's structured outputs.
4
+
5
+ - [Documentation &rarr;](https://structured-outputs.dev)<br />Expanded introduction and usage
6
+ instructions.
7
+ - [OpenAI Guide &rarr;](https://platform.openai.com/docs/guides/structured-outputs)<br />The OpenAI
8
+ platform's guide on Structured Outputs
9
+ - [Pattern Libraries &rarr;](https://structured-outputs.dev/patterns)<br />Pattern libraries
10
+ modeling common schemas using Structured Outputs TypeScript.
5
11
 
6
12
  ## Installation
7
13
 
@@ -14,66 +20,66 @@ npm i structured-outputs
14
20
  ### Deno
15
21
 
16
22
  ```ts
17
- deno add jsr:@crosshatch/structured-outputs
23
+ deno add jsr:@crosshatch/structured-outputs@0.1.0-beta.X
18
24
  ```
19
25
 
20
- ## Usage
26
+ > Note: replace "X" with the latest beta version number. Version specificity will be unnecessary
27
+ > upon the first stable release of `structured-outputs`.
28
+
29
+ ## Example Usage
21
30
 
22
- ### Basic Usage
31
+ ### Declare a Type
23
32
 
24
33
  ```ts
25
- import { ResponseFormat, T } from "structured-outputs"
34
+ import { T } from "structured-outputs"
26
35
 
27
- // 1. Define the shape of the desired response.
28
36
  const Character = T.object({
29
37
  name: T.string,
30
38
  age: T.number`Ensure between 1 and 110.`,
39
+ home: T.string`The name of a fictional realm of magic and wonder.`,
40
+ disposition: T.constantUnion("Optimistic", "Reserved", "Inquisitive"),
31
41
  })
42
+ ```
32
43
 
33
- // 2. Create the response format object.
34
- const response_format = ResponseFormat("create_character", Character)
44
+ ### Create a `ResponseFormat`
35
45
 
36
- // 3. Utilize the response format to create a chat completion.
37
- const response = await openai.chat.completions.create({
38
- model: MODEL,
39
- messages: [{ role: "system", content: [] }],
40
- response_format,
41
- })
46
+ ```ts
47
+ // ...
48
+
49
+ import { ResponseFormat } from "structured-outputs"
42
50
 
43
- // 4. Use `response_format.parseFirstOrThrow` to unwrap the inner data with correct types.
44
- const { name, age } = response_format.parseFirstOrThrow(response)
51
+ const response_format = ResponseFormat("create_character", Character)`
52
+ Create a character to be the protagonist of a children's story.
53
+ `
45
54
  ```
46
55
 
47
- For more concise usage, chain off the completions promise.
56
+ ### Create Chat Completions
48
57
 
49
58
  ```ts
50
- const { name, age } = await openai.chat.completions
59
+ // ...
60
+
61
+ const character = await openai.chat.completions
51
62
  .create({
52
- model: MODEL,
53
- messages: [{ role: "system", content: [] }],
63
+ model: "gpt-4o-mini",
64
+ messages: [...yourMessages],
54
65
  response_format,
55
66
  })
56
- .then(response_format.parseFirstOrThrow)
67
+ .then(response_format.parseFirstChoice)
57
68
  ```
58
69
 
59
- We can also attach a description to the response format.
70
+ ### Utilize The Typed, Unwrapped Data
60
71
 
61
- ```diff
62
- - ResponseFormat("create_character", Character)
63
- + ResponseFormat("create_character", Character)`
64
- + Create a new character to be the protagonist of a children's story.
65
- + `
72
+ ```ts
73
+ // ...
74
+
75
+ character satisfies {
76
+ name: string
77
+ age: number
78
+ home: string
79
+ disposition: "Optimistic" | "Reserved" | "Inquisitive"
80
+ }
66
81
  ```
67
82
 
68
- ### Dependency Injection
83
+ ## License
69
84
 
70
- ```ts
71
- const Character = T.object({
72
- name: T.string`Preferably names common to those who are {"national identity"}.`,
73
- age: T.number`Ensure between 1 and 110.`,
74
- })
75
-
76
- const AmericanCharacter = Character.apply({
77
- "national identity": "american",
78
- })
79
- ```
85
+ Structured Outputs TypeScript is [Apache licensed](LICENSE).
@@ -1,5 +1,5 @@
1
- import type { RootTy } from "./types/mod.js";
2
1
  import type { ChatCompletion, JsonSchema } from "./oai.js";
2
+ import type { RootTy } from "./types/mod.js";
3
3
  export interface ResponseFormat<T> {
4
4
  (template: TemplateStringsArray, ...quasis: Array<string>): ResponseFormat<T>;
5
5
  type: "json_schema";
@@ -1 +1 @@
1
- {"version":3,"file":"ResponseFormat.d.ts","sourceRoot":"","sources":["../src/ResponseFormat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAwB,UAAU,EAAE,MAAM,UAAU,CAAA;AAEhF,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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** @experimental */
2
3
  export declare function Tool<T>(name: string, ty: RootTy<T, never>): Tool<T>;
3
4
  export interface Tool<T = any> {
4
5
  (template: TemplateStringsArray, ...quasis: Array<string>): Tool<T>;
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,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,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"}
package/esm/Tool.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { recombineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js";
2
+ /** @experimental */
2
3
  export function Tool(name, ty) {
3
4
  return Tool_(name, ty);
4
5
  }
package/esm/Tool.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Tool.js","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAA;AAEnF,MAAM,UAAU,IAAI,CAAI,IAAY,EAAE,EAAoB;IACxD,OAAO,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACxB,CAAC;AAED,SAAS,KAAK,CAAI,IAAY,EAAE,EAAoB,EAAE,WAAoB;IACxE,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,QAA8B,EAAE,GAAG,MAAqB,EAAE,EAAE,CAC3D,KAAK,CACH,IAAI,EACJ,EAAE,EACF,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,2BAA2B,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAC5F,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"}
1
+ {"version":3,"file":"Tool.js","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAA;AAEnF,oBAAoB;AACpB,MAAM,UAAU,IAAI,CAAI,IAAY,EAAE,EAAoB;IACxD,OAAO,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACxB,CAAC;AAED,SAAS,KAAK,CAAI,IAAY,EAAE,EAAoB,EAAE,WAAoB;IACxE,OAAO,MAAM,CAAC,MAAM,CAClB,CAAC,QAA8B,EAAE,GAAG,MAAqB,EAAE,EAAE,CAC3D,KAAK,CACH,IAAI,EACJ,EAAE,EACF,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,IAAI,2BAA2B,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAC5F,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../src/types/Ref.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAGlD,MAAM,MAAM,GAAG,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,MAAM,CAAA;AAEpC,wBAAgB,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,GAAG,CAUzC"}
1
+ {"version":3,"file":"Ref.d.ts","sourceRoot":"","sources":["../../src/types/Ref.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAElD,MAAM,MAAM,GAAG,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,MAAM,CAAA;AAEpC,wBAAgB,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,GAAG,CAazC"}
package/esm/types/Ref.js CHANGED
@@ -1,11 +1,14 @@
1
1
  import { recombineTaggedTemplateArgs } from "../util/recombineTaggedTemplateArgs.js";
2
2
  export function Ref(applied) {
3
3
  return (ty) => {
4
- applied = { ...applied, ...ty.applied };
5
- const description = ty.descriptions
4
+ applied = { ...applied, ...ty[""].applied };
5
+ const description = ty[""].context
6
6
  .map(({ template, placeheld }) => recombineTaggedTemplateArgs(template, placeheld.map((k) => applied[k])))
7
7
  .join(" ");
8
- return ty.toSchema(description, Ref(applied));
8
+ return {
9
+ ...ty[""].toSchema(Ref(applied)),
10
+ ...description ? { description } : {},
11
+ };
9
12
  };
10
13
  }
11
14
  //# sourceMappingURL=Ref.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Ref.js","sourceRoot":"","sources":["../../src/types/Ref.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAA;AAIpF,MAAM,UAAU,GAAG,CAAC,OAAgB;IAClC,OAAO,CAAC,EAAE,EAAE,EAAE;QACZ,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAA;QACvC,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY;aAChC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,CAC/B,2BAA2B,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CACzE;aACA,IAAI,CAAC,GAAG,CAAC,CAAA;QACZ,OAAO,EAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAA;IAC/C,CAAC,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"Ref.js","sourceRoot":"","sources":["../../src/types/Ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2BAA2B,EAAE,MAAM,wCAAwC,CAAA;AAKpF,MAAM,UAAU,GAAG,CAAC,OAAgB;IAClC,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,CAC/B,2BAA2B,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CACzE;aACA,IAAI,CAAC,GAAG,CAAC,CAAA;QACZ,OAAO;YACL,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAChC,GAAG,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE;SACtC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -1,8 +1,8 @@
1
- import type { Applied, Description, Schema, ToSchema, Ty } from "./Ty.js";
2
- export declare function RootTy<T, P extends string = never>(toSchema: ToSchema, descriptions?: Array<Description>, applied?: Applied): RootTy<T, P>;
3
- export interface RootTy<T = any, P extends string = string> extends Ty<T, P> {
4
- <P2 extends Array<string>>(template: TemplateStringsArray, ...placeheld: P2): RootTy<T, P | P2[number]>;
5
- apply: <A extends Partial<Record<P, number | string>>>(values: A) => RootTy<T, Exclude<P, keyof A>>;
1
+ import type { Applied, Context, Schema, ToSchema, Ty } from "./Ty.js";
2
+ export declare function RootTy<T, P extends keyof any = never>(toSchema: ToSchema, context?: Array<Context>, applied?: Applied): RootTy<T, P>;
3
+ export interface RootTy<T = any, P extends keyof any = keyof any> extends Ty<T, P> {
4
+ <P2 extends Array<keyof any>>(template: TemplateStringsArray, ...placeheld: P2): RootTy<T, P | P2[number]>;
5
+ fill: <A extends Partial<Record<P, number | string>>>(values: A) => RootTy<T, Exclude<P, keyof A>>;
6
6
  schema(this: RootTy<T, never>): Schema;
7
7
  }
8
8
  //# sourceMappingURL=RootTy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RootTy.d.ts","sourceRoot":"","sources":["../../src/types/RootTy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAEzE,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,KAAK,EAChD,QAAQ,EAAE,QAAQ,EAClB,YAAY,GAAE,KAAK,CAAC,WAAW,CAAM,EACrC,OAAO,GAAE,OAAY,GACpB,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAoBd;AAED,MAAM,WAAW,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1E,CAAC,EAAE,SAAS,KAAK,CAAC,MAAM,CAAC,EACvB,QAAQ,EAAE,oBAAoB,EAC9B,GAAG,SAAS,EAAE,EAAE,GACf,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5B,KAAK,EAAE,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EACnD,MAAM,EAAE,CAA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
1
1
  import { phantoms } from "../util/phantoms.js";
2
2
  import { Ref } from "./Ref.js";
3
- export function RootTy(toSchema, descriptions = [], applied = {}) {
4
- return Object.assign((template, ...placeheld) => RootTy(toSchema, [{ template, placeheld }, ...descriptions], applied), phantoms(), {
5
- toSchema,
6
- descriptions,
7
- applied,
8
- apply: (values) => {
9
- return RootTy(toSchema, descriptions, { ...applied, ...values });
3
+ export function RootTy(toSchema, context = [], applied = {}) {
4
+ return Object.assign((template, ...placeheld) => RootTy(toSchema, [{ template, placeheld }, ...context], applied), phantoms(), {
5
+ "": { toSchema, context, applied },
6
+ fill: (values) => {
7
+ return RootTy(toSchema, context, { ...applied, ...values });
10
8
  },
11
9
  schema() {
12
10
  return Ref({})(this);
@@ -1 +1 @@
1
- {"version":3,"file":"RootTy.js","sourceRoot":"","sources":["../../src/types/RootTy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAG9B,MAAM,UAAU,MAAM,CACpB,QAAkB,EAClB,eAAmC,EAAE,EACrC,UAAmB,EAAE;IAErB,OAAO,MAAM,CAAC,MAAM,CAClB,CAA2B,QAA8B,EAAE,GAAG,SAAa,EAAE,EAAE,CAC7E,MAAM,CAAoB,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,YAAY,CAAC,EAAE,OAAO,CAAC,EAC1F,QAAQ,EAA4B,EACpC;QACE,QAAQ;QACR,YAAY;QACZ,OAAO;QACP,KAAK,EAAE,CAAgD,MAAS,EAAE,EAAE;YAClE,OAAO,MAAM,CAAyB,QAAQ,EAAE,YAAY,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;QAC1F,CAAC;QACD,MAAM;YACJ,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;QACtB,CAAC;QACD,MAAM;YACJ,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CACF,CAAA;AACH,CAAC"}
1
+ {"version":3,"file":"RootTy.js","sourceRoot":"","sources":["../../src/types/RootTy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAG9B,MAAM,UAAU,MAAM,CACpB,QAAkB,EAClB,UAA0B,EAAE,EAC5B,UAAmB,EAAE;IAErB,OAAO,MAAM,CAAC,MAAM,CAClB,CAA2B,QAA8B,EAAE,GAAG,SAAa,EAAE,EAAE,CAC7E,MAAM,CAAoB,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,OAAO,CAAC,EACrF,QAAQ,EAAkB,EAC1B;QACE,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE;QAClC,IAAI,EAAE,CAAgD,MAAS,EAAE,EAAE;YACjE,OAAO,MAAM,CAAyB,QAAQ,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;QACrF,CAAC;QACD,MAAM;YACJ,OAAO,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;QACtB,CAAC;QACD,MAAM;YACJ,OAAO,IAAI,CAAA;QACb,CAAC;KACF,CACF,CAAA;AACH,CAAC"}
package/esm/types/Ty.d.ts CHANGED
@@ -1,27 +1,23 @@
1
1
  import type { Ref } from "./Ref.js";
2
2
  import type { RootTy } from "./RootTy.js";
3
- export declare function Ty<T, P extends string = never>(toSchema: ToSchema, descriptions?: Array<Description>, applied?: Applied): Ty<T, P>;
4
- export interface Ty<T = any, P extends string = string> {
5
- <P2 extends Array<string>>(template: TemplateStringsArray, ...placeheld: P2): Ty<T, P | P2[number]>;
6
- [Ty.T]: T;
7
- [Ty.P]: P;
8
- toSchema: ToSchema;
9
- descriptions: Array<Description>;
10
- applied: Applied;
11
- apply: <A extends Partial<Record<P, number | string>>>(values: A) => Ty<T, Exclude<P, keyof A>>;
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]>;
6
+ T: T;
7
+ P: P;
8
+ "": {
9
+ toSchema: ToSchema;
10
+ context: Array<Context>;
11
+ applied: Applied;
12
+ };
13
+ fill: <A extends Partial<Record<P, number | string>>>(values: A) => Ty<T, Exclude<P, keyof A>>;
12
14
  isRoot(): this is RootTy;
13
15
  }
14
- export declare namespace Ty {
15
- type T = typeof T;
16
- const T: unique symbol;
17
- type P = typeof P;
18
- const P: unique symbol;
19
- }
20
- export type ToSchema = (description: string | undefined, ref: Ref) => Schema;
16
+ export type ToSchema = (ref: Ref) => Schema;
21
17
  export type Schema = Record<string, unknown>;
22
- export interface Description {
18
+ export interface Context {
23
19
  template: TemplateStringsArray;
24
- placeheld: Array<string>;
20
+ placeheld: Array<keyof any>;
25
21
  }
26
- export type Applied = Record<string, number | string>;
22
+ export type Applied = Record<keyof any, number | string>;
27
23
  //# sourceMappingURL=Ty.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Ty.d.ts","sourceRoot":"","sources":["../../src/types/Ty.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAEnC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,wBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,KAAK,EAC5C,QAAQ,EAAE,QAAQ,EAClB,YAAY,GAAE,KAAK,CAAC,WAAW,CAAM,EACrC,OAAO,GAAE,OAAY,GACpB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAiBV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CACzB;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAAA;AAC3C,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE5C,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,oBAAoB,CAAA;IAC9B,SAAS,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAA;CAC5B;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,CAAA"}
package/esm/types/Ty.js CHANGED
@@ -1,17 +1,13 @@
1
1
  import { phantoms } from "../util/phantoms.js";
2
- export function Ty(toSchema, descriptions = [], applied = {}) {
3
- return Object.assign((template, ...placeheld) => Ty(toSchema, [{ template, placeheld }, ...descriptions], applied), phantoms(), {
4
- toSchema,
5
- descriptions,
6
- applied,
7
- apply: (values) => {
8
- return Ty(toSchema, descriptions, { ...applied, ...values });
2
+ export function Ty(toSchema, context = [], applied = {}) {
3
+ return Object.assign((template, ...placeheld) => Ty(toSchema, [{ template, placeheld }, ...context], applied), phantoms(), {
4
+ "": { toSchema, context, applied },
5
+ fill: (values) => {
6
+ return Ty(toSchema, context, { ...applied, ...values });
9
7
  },
10
8
  isRoot() {
11
9
  return false;
12
10
  },
13
11
  });
14
12
  }
15
- (function (Ty) {
16
- })(Ty || (Ty = {}));
17
13
  //# sourceMappingURL=Ty.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Ty.js","sourceRoot":"","sources":["../../src/types/Ty.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAG9C,MAAM,UAAU,EAAE,CAChB,QAAkB,EAClB,eAAmC,EAAE,EACrC,UAAmB,EAAE;IAErB,OAAO,MAAM,CAAC,MAAM,CAClB,CAA2B,QAA8B,EAAE,GAAG,SAAa,EAAE,EAAE,CAC7E,EAAE,CAAoB,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,YAAY,CAAC,EAAE,OAAO,CAAC,EACtF,QAAQ,EAA4B,EACpC;QACE,QAAQ;QACR,YAAY;QACZ,OAAO;QACP,KAAK,EAAE,CAAgD,MAAS,EAAE,EAAE;YAClE,OAAO,EAAE,CAAyB,QAAQ,EAAE,YAAY,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;QACtF,CAAC;QACD,MAAM;YACJ,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CACF,CAAA;AACH,CAAC;AAgBD,WAAiB,EAAE;AAKnB,CAAC,EALgB,EAAE,KAAF,EAAE,QAKlB"}
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,EAAE;IAErB,OAAO,MAAM,CAAC,MAAM,CAClB,CAA8B,QAA8B,EAAE,GAAG,SAAa,EAAE,EAAE,CAChF,EAAE,CAAoB,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,GAAG,OAAO,CAAC,EAAE,OAAO,CAAC,EACjF,QAAQ,EAAkB,EAC1B;QACE,EAAE,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE;QAClC,IAAI,EAAE,CAAgD,MAAS,EAAE,EAAE;YACjE,OAAO,EAAE,CAAyB,QAAQ,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,CAAA;QACjF,CAAC;QACD,MAAM;YACJ,OAAO,KAAK,CAAA;QACd,CAAC;KACF,CACF,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[Ty.T]>, E[Ty.P]>;
2
+ export declare function array<E extends Ty>(element: E): Ty<Array<E["T"]>, E["P"]>;
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,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAM3E"}
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,8 +1,7 @@
1
1
  import { Ty } from "./Ty.js";
2
2
  export function array(element) {
3
- return Ty((description, ref) => ({
3
+ return Ty((ref) => ({
4
4
  type: "array",
5
- description,
6
5
  items: ref(element),
7
6
  }));
8
7
  }
@@ -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,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/B,IAAI,EAAE,OAAO;QACb,WAAW;QACX,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,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 +1 @@
1
- {"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../src/types/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAK1E"}
1
+ {"version":3,"file":"constant.d.ts","sourceRoot":"","sources":["../../src/types/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,wBAAgB,QAAQ,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,CAI1E"}
@@ -1,8 +1,7 @@
1
1
  import { Ty } from "./Ty.js";
2
2
  export function constant(value) {
3
- return Ty((description) => ({
3
+ return Ty(() => ({
4
4
  const: value,
5
- description,
6
5
  }));
7
6
  }
8
7
  //# sourceMappingURL=constant.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/types/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,QAAQ,CAA4B,KAAQ;IAC1D,OAAO,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QAC1B,KAAK,EAAE,KAAK;QACZ,WAAW;KACZ,CAAC,CAAC,CAAA;AACL,CAAC"}
1
+ {"version":3,"file":"constant.js","sourceRoot":"","sources":["../../src/types/constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,UAAU,QAAQ,CAA4B,KAAQ;IAC1D,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QACf,KAAK,EAAE,KAAK;KACb,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -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,CAqBtB"}
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"}
@@ -2,24 +2,21 @@ import { partition } from "../deps/jsr.io/@std/collections/1.0.9/mod.js";
2
2
  import { Ty } from "./Ty.js";
3
3
  export function constantUnion(...members) {
4
4
  const [strings, numbers] = partition(members, (v) => typeof v === "string");
5
- return Ty((description) => {
6
- return {
7
- anyOf: [
8
- ...strings.length
9
- ? [{
10
- type: "string",
11
- enum: strings,
12
- }]
13
- : [],
14
- ...numbers.length
15
- ? [{
16
- type: "number",
17
- enum: numbers,
18
- }]
19
- : [],
20
- ],
21
- description,
22
- };
23
- });
5
+ return Ty(() => ({
6
+ anyOf: [
7
+ ...strings.length
8
+ ? [{
9
+ type: "string",
10
+ enum: strings,
11
+ }]
12
+ : [],
13
+ ...numbers.length
14
+ ? [{
15
+ type: "number",
16
+ enum: numbers,
17
+ }]
18
+ : [],
19
+ ],
20
+ }));
24
21
  }
25
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;IAEb,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAA;IAC3E,OAAO,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE;QACxB,OAAO;YACL,KAAK,EAAE;gBACL,GAAG,OAAO,CAAC,MAAM;oBACf,CAAC,CAAC,CAAC;4BACD,IAAI,EAAE,QAAQ;4BACd,IAAI,EAAE,OAAO;yBACd,CAAC;oBACF,CAAC,CAAC,EAAE;gBACN,GAAG,OAAO,CAAC,MAAM;oBACf,CAAC,CAAC,CAAC;4BACD,IAAI,EAAE,QAAQ;4BACd,IAAI,EAAE,OAAO;yBACd,CAAC;oBACF,CAAC,CAAC,EAAE;aACP;YACD,WAAW;SACZ,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
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;IAEb,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAA;IAC3E,OAAO,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QACf,KAAK,EAAE;YACL,GAAG,OAAO,CAAC,MAAM;gBACf,CAAC,CAAC,CAAC;wBACD,IAAI,EAAE,QAAQ;wBACd,IAAI,EAAE,OAAO;qBACd,CAAC;gBACF,CAAC,CAAC,EAAE;YACN,GAAG,OAAO,CAAC,MAAM;gBACf,CAAC,CAAC,CAAC;wBACD,IAAI,EAAE,QAAQ;wBACd,IAAI,EAAE,OAAO;qBACd,CAAC;gBACF,CAAC,CAAC,EAAE;SACP;KACF,CAAC,CAAC,CAAA;AACL,CAAC"}
@@ -1,11 +1,11 @@
1
1
  export * from "./array.js";
2
- export * from "./leaves.js";
3
2
  export * from "./constant.js";
4
3
  export * from "./constantUnion.js";
5
- export * from "./std/mod.js";
6
4
  export * from "./object.js";
5
+ export * from "./primitives.js";
7
6
  export * from "./Ref.js";
7
+ export * from "./RootTy.js";
8
+ export * from "./std/mod.js";
8
9
  export * from "./taggedUnion.js";
9
10
  export * from "./Ty.js";
10
- export * from "./RootTy.js";
11
11
  //# 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,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA"}
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"}
package/esm/types/mod.js CHANGED
@@ -1,11 +1,11 @@
1
1
  export * from "./array.js";
2
- export * from "./leaves.js";
3
2
  export * from "./constant.js";
4
3
  export * from "./constantUnion.js";
5
- export * from "./std/mod.js";
6
4
  export * from "./object.js";
5
+ export * from "./primitives.js";
7
6
  export * from "./Ref.js";
7
+ export * from "./RootTy.js";
8
+ export * from "./std/mod.js";
8
9
  export * from "./taggedUnion.js";
9
10
  export * from "./Ty.js";
10
- export * from "./RootTy.js";
11
11
  //# 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,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,aAAa,CAAA"}
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,6 +1,6 @@
1
1
  import { RootTy } from "./RootTy.js";
2
2
  import type { Ty } from "./Ty.js";
3
3
  export declare function object<F extends Record<string, Ty>>(fields: F): RootTy<{
4
- [K in keyof F]: F[K][Ty.T];
5
- }, F[keyof F][Ty.P]>;
4
+ [K in keyof F]: F[K]["T"];
5
+ }, F[keyof F]["P"]>;
6
6
  //# 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,EAAE,MAAM,EAAE,CAAC,GAAG,MAAM,CACrE;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;CAAE,EAC9B,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACjB,CAQA"}
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,8 +1,7 @@
1
1
  import { RootTy } from "./RootTy.js";
2
2
  export function object(fields) {
3
- return RootTy((description, ref) => ({
3
+ return RootTy((ref) => ({
4
4
  type: "object",
5
- description,
6
5
  properties: Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, ref(v)])),
7
6
  additionalProperties: false,
8
7
  required: Object.keys(fields),
@@ -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,CAA+B,MAAS;IAI5D,OAAO,MAAM,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QACnC,IAAI,EAAE,QAAQ;QACd,WAAW;QACX,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,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"}
@@ -3,4 +3,4 @@ export declare const none: Ty<null, never>;
3
3
  export declare const boolean: Ty<boolean, never>;
4
4
  export declare const number: Ty<number, never>;
5
5
  export declare const string: Ty<string, never>;
6
- //# sourceMappingURL=leaves.d.ts.map
6
+ //# sourceMappingURL=primitives.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,14 @@
1
+ import { Ty } from "./Ty.js";
2
+ export const none = Ty(() => ({
3
+ type: "null",
4
+ }));
5
+ export const boolean = Ty(() => ({
6
+ type: "boolean",
7
+ }));
8
+ export const number = Ty(() => ({
9
+ type: "number",
10
+ }));
11
+ export const string = Ty(() => ({
12
+ type: "string",
13
+ }));
14
+ //# sourceMappingURL=primitives.js.map
@@ -0,0 +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,4 +1,4 @@
1
- import { none } from "../leaves.js";
1
+ import { none } from "../primitives.js";
2
2
  import { taggedUnion } from "../taggedUnion.js";
3
3
  export function option(Some) {
4
4
  return taggedUnion({
@@ -1 +1 @@
1
- {"version":3,"file":"Option.js","sourceRoot":"","sources":["../../../src/types/std/Option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAG/C,MAAM,UAAU,MAAM,CAAe,IAAO;IAM1C,OAAO,WAAW,CAAC;QACjB,IAAI;QACJ,IAAI,EAAE,IAAI;KACX,CAAC,CAAA,uCAAuC,CAAA;AAC3C,CAAC"}
1
+ {"version":3,"file":"Option.js","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;AAG/C,MAAM,UAAU,MAAM,CAAe,IAAO;IAM1C,OAAO,WAAW,CAAC;QACjB,IAAI;QACJ,IAAI,EAAE,IAAI;KACX,CAAC,CAAA,uCAAuC,CAAA;AAC3C,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import type { Ty } from "../mod.js";
2
2
  import { object } from "../object.js";
3
- export type Wrapper<X extends Ty = Ty> = ReturnType<typeof Wrapper<X>>;
4
3
  export declare function Wrapper<X extends Ty>(value: X): ReturnType<typeof object<{
5
4
  value: X;
6
5
  }>>;
@@ -1 +1 @@
1
- {"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../../src/types/std/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,MAAM,OAAO,CAAC,CAAC,SAAS,EAAE,GAAG,EAAE,IAAI,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAEtE,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC,CAEvF"}
1
+ {"version":3,"file":"Wrapper.d.ts","sourceRoot":"","sources":["../../../src/types/std/Wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,wBAAgB,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,KAAK,EAAE,CAAC,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC,CAEvF"}
@@ -1 +1 @@
1
- {"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../../src/types/std/Wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAIrC,MAAM,UAAU,OAAO,CAAe,KAAQ;IAC5C,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC1B,CAAC"}
1
+ {"version":3,"file":"Wrapper.js","sourceRoot":"","sources":["../../../src/types/std/Wrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,MAAM,UAAU,OAAO,CAAe,KAAQ;IAC5C,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAC1B,CAAC"}
@@ -2,7 +2,7 @@ import { Ty } from "./Ty.js";
2
2
  export declare function taggedUnion<M extends Record<string, Ty>>(members: M): Ty<{
3
3
  [K in keyof M]: {
4
4
  type: K;
5
- value: M[K][Ty.T];
5
+ value: M[K]["T"];
6
6
  };
7
- }[keyof M], M[keyof M][Ty.P]>;
7
+ }[keyof M], M[keyof M]["P"]>;
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,EAAE,CAAC,CAAC,CAAC,CAAA;KAClB;CACF,CAAC,MAAM,CAAC,CAAC,EACV,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACjB,CAiBA"}
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,7 +1,6 @@
1
1
  import { Ty } from "./Ty.js";
2
2
  export function taggedUnion(members) {
3
- return Ty((description, ref) => ({
4
- description,
3
+ return Ty((ref) => ({
5
4
  discriminator: "type",
6
5
  anyOf: Object.entries(members).map(([k, v]) => ({
7
6
  type: "object",
@@ -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,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;QAC/B,WAAW;QACX,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;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"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "structured-outputs",
3
- "version": "0.1.0-beta.21",
4
- "description": "Compose OpenAI structured output schemas.",
3
+ "version": "0.1.0-beta.22",
4
+ "description": "A library for working with OpenAI's structured outputs.",
5
5
  "repository": "github:harrysolovay/structured-outputs.git",
6
6
  "license": "Apache-2.0",
7
7
  "main": "./esm/mod.js",
@@ -1,6 +1,6 @@
1
+ import type { ChatCompletion, ChatCompletionChoice, JsonSchema } from "./oai.js"
1
2
  import type { RootTy } from "./types/mod.js"
2
3
  import { recombineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js"
3
- import type { ChatCompletion, ChatCompletionChoice, JsonSchema } from "./oai.js"
4
4
 
5
5
  export interface ResponseFormat<T> {
6
6
  (template: TemplateStringsArray, ...quasis: Array<string>): ResponseFormat<T>
package/src/Tool.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { RootTy, Schema } from "./types/mod.js"
2
2
  import { recombineTaggedTemplateArgs } from "./util/recombineTaggedTemplateArgs.js"
3
3
 
4
+ /** @experimental */
4
5
  export function Tool<T>(name: string, ty: RootTy<T, never>): Tool<T> {
5
6
  return Tool_(name, ty)
6
7
  }
package/src/types/Ref.ts CHANGED
@@ -1,16 +1,19 @@
1
- import type { Applied, Schema, Ty } from "./Ty.js"
2
1
  import { recombineTaggedTemplateArgs } from "../util/recombineTaggedTemplateArgs.js"
2
+ import type { Applied, Schema, Ty } from "./Ty.js"
3
3
 
4
4
  export type Ref = (ty: Ty) => Schema
5
5
 
6
6
  export function Ref(applied: Applied): Ref {
7
7
  return (ty) => {
8
- applied = { ...applied, ...ty.applied }
9
- const description = ty.descriptions
8
+ applied = { ...applied, ...ty[""].applied }
9
+ const description = ty[""].context
10
10
  .map(({ template, placeheld }) =>
11
11
  recombineTaggedTemplateArgs(template, placeheld.map((k) => applied[k]!))
12
12
  )
13
13
  .join(" ")
14
- return ty.toSchema(description, Ref(applied))
14
+ return {
15
+ ...ty[""].toSchema(Ref(applied)),
16
+ ...description ? { description } : {},
17
+ }
15
18
  }
16
19
  }
@@ -1,22 +1,20 @@
1
1
  import { phantoms } from "../util/phantoms.js"
2
2
  import { Ref } from "./Ref.js"
3
- import type { Applied, Description, Schema, ToSchema, Ty } from "./Ty.js"
3
+ import type { Applied, Context, Schema, ToSchema, Ty } from "./Ty.js"
4
4
 
5
- export function RootTy<T, P extends string = never>(
5
+ export function RootTy<T, P extends keyof any = never>(
6
6
  toSchema: ToSchema,
7
- descriptions: Array<Description> = [],
7
+ context: Array<Context> = [],
8
8
  applied: Applied = {},
9
9
  ): RootTy<T, P> {
10
10
  return Object.assign(
11
11
  <P2 extends Array<string>>(template: TemplateStringsArray, ...placeheld: P2) =>
12
- RootTy<T, P | P2[number]>(toSchema, [{ template, placeheld }, ...descriptions], applied),
13
- phantoms<{ [Ty.T]: T; [Ty.P]: P }>(),
12
+ RootTy<T, P | P2[number]>(toSchema, [{ template, placeheld }, ...context], applied),
13
+ phantoms<{ T: T; P: P }>(),
14
14
  {
15
- toSchema,
16
- descriptions,
17
- applied,
18
- apply: <A extends Partial<Record<P, string | number>>>(values: A) => {
19
- return RootTy<T, Exclude<P, keyof A>>(toSchema, descriptions, { ...applied, ...values })
15
+ "": { toSchema, context, applied },
16
+ fill: <A extends Partial<Record<P, string | number>>>(values: A) => {
17
+ return RootTy<T, Exclude<P, keyof A>>(toSchema, context, { ...applied, ...values })
20
18
  },
21
19
  schema(this: RootTy<T, never>) {
22
20
  return Ref({})(this)
@@ -28,12 +26,12 @@ export function RootTy<T, P extends string = never>(
28
26
  )
29
27
  }
30
28
 
31
- export interface RootTy<T = any, P extends string = string> extends Ty<T, P> {
32
- <P2 extends Array<string>>(
29
+ export interface RootTy<T = any, P extends keyof any = keyof any> extends Ty<T, P> {
30
+ <P2 extends Array<keyof any>>(
33
31
  template: TemplateStringsArray,
34
32
  ...placeheld: P2
35
33
  ): RootTy<T, P | P2[number]>
36
- apply: <A extends Partial<Record<P, number | string>>>(
34
+ fill: <A extends Partial<Record<P, number | string>>>(
37
35
  values: A,
38
36
  ) => RootTy<T, Exclude<P, keyof A>>
39
37
  schema(this: RootTy<T, never>): Schema
package/src/types/Ty.ts CHANGED
@@ -1,22 +1,20 @@
1
- import type { Ref } from "./Ref.js"
2
1
  import { phantoms } from "../util/phantoms.js"
2
+ import type { Ref } from "./Ref.js"
3
3
  import type { RootTy } from "./RootTy.js"
4
4
 
5
- export function Ty<T, P extends string = never>(
5
+ export function Ty<T, P extends keyof any = never>(
6
6
  toSchema: ToSchema,
7
- descriptions: Array<Description> = [],
7
+ context: Array<Context> = [],
8
8
  applied: Applied = {},
9
9
  ): Ty<T, P> {
10
10
  return Object.assign(
11
- <P2 extends Array<string>>(template: TemplateStringsArray, ...placeheld: P2) =>
12
- Ty<T, P | P2[number]>(toSchema, [{ template, placeheld }, ...descriptions], applied),
13
- phantoms<{ [Ty.T]: T; [Ty.P]: P }>(),
11
+ <P2 extends Array<keyof any>>(template: TemplateStringsArray, ...placeheld: P2) =>
12
+ Ty<T, P | P2[number]>(toSchema, [{ template, placeheld }, ...context], applied),
13
+ phantoms<{ T: T; P: P }>(),
14
14
  {
15
- toSchema,
16
- descriptions,
17
- applied,
18
- apply: <A extends Partial<Record<P, string | number>>>(values: A) => {
19
- return Ty<T, Exclude<P, keyof A>>(toSchema, descriptions, { ...applied, ...values })
15
+ "": { toSchema, context, applied },
16
+ fill: <A extends Partial<Record<P, string | number>>>(values: A) => {
17
+ return Ty<T, Exclude<P, keyof A>>(toSchema, context, { ...applied, ...values })
20
18
  },
21
19
  isRoot(): this is RootTy {
22
20
  return false
@@ -25,33 +23,28 @@ export function Ty<T, P extends string = never>(
25
23
  )
26
24
  }
27
25
 
28
- export interface Ty<T = any, P extends string = string> {
29
- <P2 extends Array<string>>(
26
+ export interface Ty<T = any, P extends keyof any = keyof any> {
27
+ <P2 extends Array<keyof any>>(
30
28
  template: TemplateStringsArray,
31
29
  ...placeheld: P2
32
30
  ): Ty<T, P | P2[number]>
33
- [Ty.T]: T
34
- [Ty.P]: P
35
- toSchema: ToSchema
36
- descriptions: Array<Description>
37
- applied: Applied
38
- apply: <A extends Partial<Record<P, number | string>>>(values: A) => Ty<T, Exclude<P, keyof A>>
31
+ T: T
32
+ P: P
33
+ "": {
34
+ toSchema: ToSchema
35
+ context: Array<Context>
36
+ applied: Applied
37
+ }
38
+ fill: <A extends Partial<Record<P, number | string>>>(values: A) => Ty<T, Exclude<P, keyof A>>
39
39
  isRoot(): this is RootTy
40
40
  }
41
41
 
42
- export namespace Ty {
43
- export type T = typeof T
44
- export declare const T: unique symbol
45
- export type P = typeof P
46
- export declare const P: unique symbol
47
- }
48
-
49
- export type ToSchema = (description: string | undefined, ref: Ref) => Schema
42
+ export type ToSchema = (ref: Ref) => Schema
50
43
  export type Schema = Record<string, unknown>
51
44
 
52
- export interface Description {
45
+ export interface Context {
53
46
  template: TemplateStringsArray
54
- placeheld: Array<string>
47
+ placeheld: Array<keyof any>
55
48
  }
56
49
 
57
- export type Applied = Record<string, number | string>
50
+ export type Applied = Record<keyof any, number | string>
@@ -1,9 +1,8 @@
1
1
  import { Ty } from "./Ty.js"
2
2
 
3
- export function array<E extends Ty>(element: E): Ty<Array<E[Ty.T]>, E[Ty.P]> {
4
- return Ty((description, ref) => ({
3
+ export function array<E extends Ty>(element: E): Ty<Array<E["T"]>, E["P"]> {
4
+ return Ty((ref) => ({
5
5
  type: "array",
6
- description,
7
6
  items: ref(element),
8
7
  }))
9
8
  }
@@ -1,8 +1,7 @@
1
1
  import { Ty } from "./Ty.js"
2
2
 
3
3
  export function constant<V extends number | string>(value: V): Ty<V, never> {
4
- return Ty((description) => ({
4
+ return Ty(() => ({
5
5
  const: value,
6
- description,
7
6
  }))
8
7
  }
@@ -5,23 +5,20 @@ export function constantUnion<M extends Array<number | string>>(
5
5
  ...members: M
6
6
  ): Ty<M[number], never> {
7
7
  const [strings, numbers] = partition(members, (v) => typeof v === "string")
8
- return Ty((description) => {
9
- return {
10
- anyOf: [
11
- ...strings.length
12
- ? [{
13
- type: "string",
14
- enum: strings,
15
- }]
16
- : [],
17
- ...numbers.length
18
- ? [{
19
- type: "number",
20
- enum: numbers,
21
- }]
22
- : [],
23
- ],
24
- description,
25
- }
26
- })
8
+ return Ty(() => ({
9
+ anyOf: [
10
+ ...strings.length
11
+ ? [{
12
+ type: "string",
13
+ enum: strings,
14
+ }]
15
+ : [],
16
+ ...numbers.length
17
+ ? [{
18
+ type: "number",
19
+ enum: numbers,
20
+ }]
21
+ : [],
22
+ ],
23
+ }))
27
24
  }
package/src/types/mod.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  export * from "./array.js"
2
- export * from "./leaves.js"
3
2
  export * from "./constant.js"
4
3
  export * from "./constantUnion.js"
5
- export * from "./std/mod.js"
6
4
  export * from "./object.js"
5
+ export * from "./primitives.js"
7
6
  export * from "./Ref.js"
7
+ export * from "./RootTy.js"
8
+ export * from "./std/mod.js"
8
9
  export * from "./taggedUnion.js"
9
10
  export * from "./Ty.js"
10
- export * from "./RootTy.js"
@@ -1,13 +1,11 @@
1
1
  import { RootTy } from "./RootTy.js"
2
2
  import type { Ty } from "./Ty.js"
3
3
 
4
- export function object<F extends Record<string, Ty>>(fields: F): RootTy<
5
- { [K in keyof F]: F[K][Ty.T] },
6
- F[keyof F][Ty.P]
7
- > {
8
- return RootTy((description, ref) => ({
4
+ export function object<F extends Record<string, Ty>>(
5
+ fields: F,
6
+ ): RootTy<{ [K in keyof F]: F[K]["T"] }, F[keyof F]["P"]> {
7
+ return RootTy((ref) => ({
9
8
  type: "object",
10
- description,
11
9
  properties: Object.fromEntries(Object.entries(fields).map(([k, v]) => [k, ref(v)])),
12
10
  additionalProperties: false,
13
11
  required: Object.keys(fields),
@@ -0,0 +1,17 @@
1
+ import { Ty } from "./Ty.js"
2
+
3
+ export const none: Ty<null, never> = Ty(() => ({
4
+ type: "null",
5
+ }))
6
+
7
+ export const boolean: Ty<boolean, never> = Ty(() => ({
8
+ type: "boolean",
9
+ }))
10
+
11
+ export const number: Ty<number, never> = Ty(() => ({
12
+ type: "number",
13
+ }))
14
+
15
+ export const string: Ty<string, never> = Ty(() => ({
16
+ type: "string",
17
+ }))
@@ -1,4 +1,4 @@
1
- import { none } from "../leaves.js"
1
+ import { none } from "../primitives.js"
2
2
  import { taggedUnion } from "../taggedUnion.js"
3
3
  import type { Ty } from "../Ty.js"
4
4
 
@@ -1,8 +1,6 @@
1
1
  import type { Ty } from "../mod.js"
2
2
  import { object } from "../object.js"
3
3
 
4
- export type Wrapper<X extends Ty = Ty> = ReturnType<typeof Wrapper<X>>
5
-
6
4
  export function Wrapper<X extends Ty>(value: X): ReturnType<typeof object<{ value: X }>> {
7
5
  return object({ value })
8
6
  }
@@ -4,13 +4,12 @@ export function taggedUnion<M extends Record<string, Ty>>(members: M): Ty<
4
4
  {
5
5
  [K in keyof M]: {
6
6
  type: K
7
- value: M[K][Ty.T]
7
+ value: M[K]["T"]
8
8
  }
9
9
  }[keyof M],
10
- M[keyof M][Ty.P]
10
+ M[keyof M]["P"]
11
11
  > {
12
- return Ty((description, ref) => ({
13
- description,
12
+ return Ty((ref) => ({
14
13
  discriminator: "type",
15
14
  anyOf: Object.entries(members).map(([k, v]) => ({
16
15
  type: "object",
@@ -1 +0,0 @@
1
- {"version":3,"file":"leaves.d.ts","sourceRoot":"","sources":["../../src/types/leaves.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,eAAO,MAAM,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,CAG9B,CAAA;AAEH,eAAO,MAAM,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,CAGpC,CAAA;AAEH,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAGlC,CAAA;AAEH,eAAO,MAAM,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,KAAK,CAGlC,CAAA"}
@@ -1,18 +0,0 @@
1
- import { Ty } from "./Ty.js";
2
- export const none = Ty((description) => ({
3
- type: "null",
4
- description,
5
- }));
6
- export const boolean = Ty((description) => ({
7
- type: "boolean",
8
- description,
9
- }));
10
- export const number = Ty((description) => ({
11
- type: "number",
12
- description,
13
- }));
14
- export const string = Ty((description) => ({
15
- type: "string",
16
- description,
17
- }));
18
- //# sourceMappingURL=leaves.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"leaves.js","sourceRoot":"","sources":["../../src/types/leaves.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,MAAM,CAAC,MAAM,IAAI,GAAoB,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IACxD,IAAI,EAAE,MAAM;IACZ,WAAW;CACZ,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,OAAO,GAAuB,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC9D,IAAI,EAAE,SAAS;IACf,WAAW;CACZ,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,MAAM,GAAsB,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,EAAE,QAAQ;IACd,WAAW;CACZ,CAAC,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,MAAM,GAAsB,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC5D,IAAI,EAAE,QAAQ;IACd,WAAW;CACZ,CAAC,CAAC,CAAA"}
@@ -1,21 +0,0 @@
1
- import { Ty } from "./Ty.js"
2
-
3
- export const none: Ty<null, never> = Ty((description) => ({
4
- type: "null",
5
- description,
6
- }))
7
-
8
- export const boolean: Ty<boolean, never> = Ty((description) => ({
9
- type: "boolean",
10
- description,
11
- }))
12
-
13
- export const number: Ty<number, never> = Ty((description) => ({
14
- type: "number",
15
- description,
16
- }))
17
-
18
- export const string: Ty<string, never> = Ty((description) => ({
19
- type: "string",
20
- description,
21
- }))