@distilled.cloud/core 1.0.0-rc.15 → 1.0.0-rc.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (318) hide show
  1. package/lib/_bundle/aws.js +2 -0
  2. package/lib/_bundle/aws.js.map +1 -0
  3. package/lib/_bundle/base.js +5 -0
  4. package/lib/_bundle/base.js.map +1 -0
  5. package/lib/_bundle/graphql.js +3 -0
  6. package/lib/_bundle/graphql.js.map +1 -0
  7. package/lib/_bundle/rest.js +2 -0
  8. package/lib/_bundle/rest.js.map +1 -0
  9. package/lib/_bundle/xml.js +4 -0
  10. package/lib/_bundle/xml.js.map +1 -0
  11. package/lib/api.d.ts +118 -13
  12. package/lib/api.d.ts.map +1 -1
  13. package/lib/api.js +1 -188
  14. package/lib/category.d.ts.map +1 -1
  15. package/lib/category.js +1 -278
  16. package/lib/chunks.d.ts +3 -0
  17. package/lib/chunks.d.ts.map +1 -0
  18. package/lib/chunks.js +1 -0
  19. package/lib/codegen/boolean-string-enums.js +36 -36
  20. package/lib/codegen/chunk.d.ts +7 -0
  21. package/lib/codegen/chunk.d.ts.map +1 -0
  22. package/lib/codegen/chunk.js +139 -0
  23. package/lib/codegen/chunk.js.map +1 -0
  24. package/lib/codegen/cli.d.ts.map +1 -1
  25. package/lib/codegen/cli.js +28 -14
  26. package/lib/codegen/cli.js.map +1 -1
  27. package/lib/codegen/datafy.d.ts +14 -0
  28. package/lib/codegen/datafy.d.ts.map +1 -0
  29. package/lib/codegen/datafy.js +853 -0
  30. package/lib/codegen/datafy.js.map +1 -0
  31. package/lib/codegen/dedupe.d.ts +5 -0
  32. package/lib/codegen/dedupe.d.ts.map +1 -0
  33. package/lib/codegen/dedupe.js +153 -0
  34. package/lib/codegen/dedupe.js.map +1 -0
  35. package/lib/codegen/emit.js +56 -56
  36. package/lib/codegen/format.js +18 -18
  37. package/lib/codegen/generated-at.js +29 -29
  38. package/lib/codegen/generator.d.ts.map +1 -1
  39. package/lib/codegen/generator.js +92 -84
  40. package/lib/codegen/generator.js.map +1 -1
  41. package/lib/codegen/graph.js +36 -36
  42. package/lib/codegen/graphql-client.d.ts +2 -0
  43. package/lib/codegen/graphql-client.d.ts.map +1 -1
  44. package/lib/codegen/graphql-client.js +55 -26
  45. package/lib/codegen/graphql-client.js.map +1 -1
  46. package/lib/codegen/graphql.js +113 -113
  47. package/lib/codegen/latin1.d.ts +3 -0
  48. package/lib/codegen/latin1.d.ts.map +1 -0
  49. package/lib/codegen/latin1.js +126 -0
  50. package/lib/codegen/latin1.js.map +1 -0
  51. package/lib/codegen/members.d.ts +7 -0
  52. package/lib/codegen/members.d.ts.map +1 -1
  53. package/lib/codegen/members.js +26 -19
  54. package/lib/codegen/members.js.map +1 -1
  55. package/lib/codegen/model-diff.js +6 -6
  56. package/lib/codegen/naming.js +19 -19
  57. package/lib/codegen/openapi-cli.js +15 -15
  58. package/lib/codegen/openapi.d.ts +17 -0
  59. package/lib/codegen/openapi.d.ts.map +1 -1
  60. package/lib/codegen/openapi.js +323 -169
  61. package/lib/codegen/openapi.js.map +1 -1
  62. package/lib/codegen/operations.js +14 -14
  63. package/lib/codegen/pagination.js +11 -11
  64. package/lib/codegen/patch-audit.js +57 -57
  65. package/lib/codegen/patches.js +79 -79
  66. package/lib/codegen/prelude.js +19 -19
  67. package/lib/codegen/privatize.d.ts +21 -0
  68. package/lib/codegen/privatize.d.ts.map +1 -0
  69. package/lib/codegen/privatize.js +176 -0
  70. package/lib/codegen/privatize.js.map +1 -0
  71. package/lib/codegen/proto.js +25 -25
  72. package/lib/codegen/pure.d.ts +6 -0
  73. package/lib/codegen/pure.d.ts.map +1 -0
  74. package/lib/codegen/pure.js +91 -0
  75. package/lib/codegen/pure.js.map +1 -0
  76. package/lib/codegen/rewrite-operation-ids.js +108 -108
  77. package/lib/codegen/spec-path.js +57 -57
  78. package/lib/codegen/table.d.ts +5 -0
  79. package/lib/codegen/table.d.ts.map +1 -0
  80. package/lib/codegen/table.js +249 -0
  81. package/lib/codegen/table.js.map +1 -0
  82. package/lib/config.d.ts +27 -0
  83. package/lib/config.d.ts.map +1 -0
  84. package/lib/config.js +1 -0
  85. package/lib/crypto.d.ts +76 -0
  86. package/lib/crypto.d.ts.map +1 -0
  87. package/lib/crypto.js +1 -0
  88. package/lib/debug.d.ts +2 -0
  89. package/lib/debug.d.ts.map +1 -0
  90. package/lib/debug.js +1 -0
  91. package/lib/error-category.d.ts +1 -1
  92. package/lib/error-category.d.ts.map +1 -1
  93. package/lib/error-category.js +1 -46
  94. package/lib/errors.d.ts +62 -62
  95. package/lib/errors.d.ts.map +1 -1
  96. package/lib/errors.js +1 -195
  97. package/lib/graphql.d.ts +31 -20
  98. package/lib/graphql.d.ts.map +1 -1
  99. package/lib/graphql.js +1 -1027
  100. package/lib/graphql.types.js +1 -5
  101. package/lib/index.d.ts +3 -2
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +1 -15
  104. package/lib/json-patch.d.ts +2 -2
  105. package/lib/json-patch.js +1 -226
  106. package/lib/json-patch.js.map +1 -1
  107. package/lib/pagination.d.ts +9 -25
  108. package/lib/pagination.d.ts.map +1 -1
  109. package/lib/pagination.js +1 -266
  110. package/lib/plain-values.d.ts +10 -0
  111. package/lib/plain-values.d.ts.map +1 -0
  112. package/lib/plain-values.js +2 -0
  113. package/lib/plain-values.js.map +1 -0
  114. package/lib/protocol-http.d.ts +50 -14
  115. package/lib/protocol-http.d.ts.map +1 -1
  116. package/lib/protocol-http.js +1 -639
  117. package/lib/protocol-rest.d.ts +38 -25
  118. package/lib/protocol-rest.d.ts.map +1 -1
  119. package/lib/protocol-rest.js +1 -267
  120. package/lib/query.js +1 -27
  121. package/lib/response-validation-strict.d.ts +48 -0
  122. package/lib/response-validation-strict.d.ts.map +1 -0
  123. package/lib/response-validation-strict.js +1 -0
  124. package/lib/response-validation.d.ts +43 -25
  125. package/lib/response-validation.d.ts.map +1 -1
  126. package/lib/response-validation.js +1 -76
  127. package/lib/retry-after.d.ts +3 -3
  128. package/lib/retry-after.js +1 -112
  129. package/lib/retry.d.ts +48 -29
  130. package/lib/retry.d.ts.map +1 -1
  131. package/lib/retry.js +1 -209
  132. package/lib/schema-lite-impl.d.ts +158 -0
  133. package/lib/schema-lite-impl.d.ts.map +1 -0
  134. package/lib/schema-lite-impl.js +1 -0
  135. package/lib/schema-lite-typed.d.ts +41 -0
  136. package/lib/schema-lite-typed.d.ts.map +1 -0
  137. package/lib/schema-lite-typed.js +2 -0
  138. package/lib/schema-lite-typed.js.map +1 -0
  139. package/lib/schema-lite.d.ts +40 -0
  140. package/lib/schema-lite.d.ts.map +1 -0
  141. package/lib/schema-lite.js +1 -0
  142. package/lib/schema.d.ts +20 -6
  143. package/lib/schema.d.ts.map +1 -1
  144. package/lib/schema.js +1 -48
  145. package/lib/testing.d.ts +3 -2
  146. package/lib/testing.d.ts.map +1 -1
  147. package/lib/testing.js +1 -40
  148. package/lib/testing.js.map +1 -1
  149. package/lib/trait.d.ts +13 -13
  150. package/lib/trait.d.ts.map +1 -1
  151. package/lib/trait.js +1 -131
  152. package/lib/xml.d.ts +1 -1
  153. package/lib/xml.d.ts.map +1 -1
  154. package/lib/xml.js +1 -311
  155. package/package.json +9 -7
  156. package/src/api.ts +1080 -180
  157. package/src/category.ts +33 -33
  158. package/src/chunks.ts +30 -0
  159. package/src/codegen/chunk.ts +147 -0
  160. package/src/codegen/cli.ts +27 -1
  161. package/src/codegen/datafy.ts +874 -0
  162. package/src/codegen/dedupe.ts +173 -0
  163. package/src/codegen/generator.ts +10 -3
  164. package/src/codegen/graphql-client.ts +49 -15
  165. package/src/codegen/latin1.ts +131 -0
  166. package/src/codegen/members.ts +8 -0
  167. package/src/codegen/openapi.ts +194 -3
  168. package/src/codegen/privatize.ts +200 -0
  169. package/src/codegen/pure.ts +94 -0
  170. package/src/codegen/table.ts +254 -0
  171. package/src/config.ts +216 -0
  172. package/src/crypto.ts +202 -0
  173. package/src/debug.ts +8 -0
  174. package/src/error-category.ts +2 -1
  175. package/src/errors.ts +65 -56
  176. package/src/graphql.ts +109 -62
  177. package/src/graphql.types.ts +9 -7
  178. package/src/index.ts +3 -2
  179. package/src/json-patch.ts +2 -2
  180. package/src/pagination.ts +37 -18
  181. package/src/plain-values.ts +41 -0
  182. package/src/protocol-http.ts +378 -145
  183. package/src/protocol-rest.ts +337 -169
  184. package/src/response-validation-strict.ts +327 -0
  185. package/src/response-validation.ts +101 -50
  186. package/src/retry-after.ts +3 -3
  187. package/src/retry.ts +94 -93
  188. package/src/schema-lite-impl.ts +550 -0
  189. package/src/schema-lite-typed.ts +44 -0
  190. package/src/schema-lite.ts +44 -0
  191. package/src/schema.ts +258 -14
  192. package/src/testing.ts +4 -2
  193. package/src/trait.ts +36 -28
  194. package/src/xml.ts +31 -17
  195. package/lib/api.js.map +0 -1
  196. package/lib/category.js.map +0 -1
  197. package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
  198. package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
  199. package/lib/codegen/boolean-string-enums.test.js +0 -275
  200. package/lib/codegen/boolean-string-enums.test.js.map +0 -1
  201. package/lib/codegen/defer-naming.test.d.ts +0 -2
  202. package/lib/codegen/defer-naming.test.d.ts.map +0 -1
  203. package/lib/codegen/defer-naming.test.js +0 -105
  204. package/lib/codegen/defer-naming.test.js.map +0 -1
  205. package/lib/codegen/generated-at.test.d.ts +0 -2
  206. package/lib/codegen/generated-at.test.d.ts.map +0 -1
  207. package/lib/codegen/generated-at.test.js +0 -81
  208. package/lib/codegen/generated-at.test.js.map +0 -1
  209. package/lib/codegen/generator.test.d.ts +0 -2
  210. package/lib/codegen/generator.test.d.ts.map +0 -1
  211. package/lib/codegen/generator.test.js +0 -121
  212. package/lib/codegen/generator.test.js.map +0 -1
  213. package/lib/codegen/graphql-client.test.d.ts +0 -2
  214. package/lib/codegen/graphql-client.test.d.ts.map +0 -1
  215. package/lib/codegen/graphql-client.test.js +0 -171
  216. package/lib/codegen/graphql-client.test.js.map +0 -1
  217. package/lib/codegen/openapi-binary.test.d.ts +0 -2
  218. package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
  219. package/lib/codegen/openapi-binary.test.js +0 -67
  220. package/lib/codegen/openapi-binary.test.js.map +0 -1
  221. package/lib/codegen/patch-audit.test.d.ts +0 -2
  222. package/lib/codegen/patch-audit.test.d.ts.map +0 -1
  223. package/lib/codegen/patch-audit.test.js +0 -141
  224. package/lib/codegen/patch-audit.test.js.map +0 -1
  225. package/lib/codegen/patches.test.d.ts +0 -2
  226. package/lib/codegen/patches.test.d.ts.map +0 -1
  227. package/lib/codegen/patches.test.js +0 -155
  228. package/lib/codegen/patches.test.js.map +0 -1
  229. package/lib/codegen/protocol-imports.test.d.ts +0 -2
  230. package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
  231. package/lib/codegen/protocol-imports.test.js +0 -36
  232. package/lib/codegen/protocol-imports.test.js.map +0 -1
  233. package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
  234. package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
  235. package/lib/codegen/rewrite-operation-ids.test.js +0 -451
  236. package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
  237. package/lib/codegen/untagged-unions.test.d.ts +0 -2
  238. package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
  239. package/lib/codegen/untagged-unions.test.js +0 -80
  240. package/lib/codegen/untagged-unions.test.js.map +0 -1
  241. package/lib/error-category.js.map +0 -1
  242. package/lib/errors.js.map +0 -1
  243. package/lib/fixtures/xml/upstream-validator.json +0 -397
  244. package/lib/graphql.js.map +0 -1
  245. package/lib/graphql.test.d.ts +0 -2
  246. package/lib/graphql.test.d.ts.map +0 -1
  247. package/lib/graphql.test.js +0 -151
  248. package/lib/graphql.test.js.map +0 -1
  249. package/lib/graphql.types.js.map +0 -1
  250. package/lib/index.js.map +0 -1
  251. package/lib/json-patch.test.d.ts +0 -2
  252. package/lib/json-patch.test.d.ts.map +0 -1
  253. package/lib/json-patch.test.js +0 -65
  254. package/lib/json-patch.test.js.map +0 -1
  255. package/lib/pagination.js.map +0 -1
  256. package/lib/pagination.test.d.ts +0 -2
  257. package/lib/pagination.test.d.ts.map +0 -1
  258. package/lib/pagination.test.js +0 -131
  259. package/lib/pagination.test.js.map +0 -1
  260. package/lib/protocol-http.js.map +0 -1
  261. package/lib/protocol-http.test.d.ts +0 -2
  262. package/lib/protocol-http.test.d.ts.map +0 -1
  263. package/lib/protocol-http.test.js +0 -228
  264. package/lib/protocol-http.test.js.map +0 -1
  265. package/lib/protocol-rest.js.map +0 -1
  266. package/lib/protocol-rest.test.d.ts +0 -2
  267. package/lib/protocol-rest.test.d.ts.map +0 -1
  268. package/lib/protocol-rest.test.js +0 -498
  269. package/lib/protocol-rest.test.js.map +0 -1
  270. package/lib/query.js.map +0 -1
  271. package/lib/response-validation.js.map +0 -1
  272. package/lib/response-validation.test.d.ts +0 -2
  273. package/lib/response-validation.test.d.ts.map +0 -1
  274. package/lib/response-validation.test.js +0 -72
  275. package/lib/response-validation.test.js.map +0 -1
  276. package/lib/retry-after.js.map +0 -1
  277. package/lib/retry-after.test.d.ts +0 -2
  278. package/lib/retry-after.test.d.ts.map +0 -1
  279. package/lib/retry-after.test.js +0 -204
  280. package/lib/retry-after.test.js.map +0 -1
  281. package/lib/retry.js.map +0 -1
  282. package/lib/retry.test.d.ts +0 -2
  283. package/lib/retry.test.d.ts.map +0 -1
  284. package/lib/retry.test.js +0 -407
  285. package/lib/retry.test.js.map +0 -1
  286. package/lib/schema.js.map +0 -1
  287. package/lib/sdks.test.d.ts +0 -2
  288. package/lib/sdks.test.d.ts.map +0 -1
  289. package/lib/sdks.test.js +0 -76
  290. package/lib/sdks.test.js.map +0 -1
  291. package/lib/trait.js.map +0 -1
  292. package/lib/xml.js.map +0 -1
  293. package/lib/xml.test.d.ts +0 -2
  294. package/lib/xml.test.d.ts.map +0 -1
  295. package/lib/xml.test.js +0 -210
  296. package/lib/xml.test.js.map +0 -1
  297. package/src/codegen/boolean-string-enums.test.ts +0 -299
  298. package/src/codegen/defer-naming.test.ts +0 -113
  299. package/src/codegen/generated-at.test.ts +0 -89
  300. package/src/codegen/generator.test.ts +0 -137
  301. package/src/codegen/graphql-client.test.ts +0 -189
  302. package/src/codegen/openapi-binary.test.ts +0 -91
  303. package/src/codegen/patch-audit.test.ts +0 -160
  304. package/src/codegen/patches.test.ts +0 -188
  305. package/src/codegen/protocol-imports.test.ts +0 -39
  306. package/src/codegen/rewrite-operation-ids.test.ts +0 -472
  307. package/src/codegen/untagged-unions.test.ts +0 -85
  308. package/src/fixtures/xml/upstream-validator.json +0 -397
  309. package/src/graphql.test.ts +0 -198
  310. package/src/json-patch.test.ts +0 -77
  311. package/src/pagination.test.ts +0 -169
  312. package/src/protocol-http.test.ts +0 -276
  313. package/src/protocol-rest.test.ts +0 -703
  314. package/src/response-validation.test.ts +0 -89
  315. package/src/retry-after.test.ts +0 -267
  316. package/src/retry.test.ts +0 -566
  317. package/src/sdks.test.ts +0 -87
  318. package/src/xml.test.ts +0 -251
@@ -0,0 +1,550 @@
1
+ /**
2
+ * Minimal schemas for generated SDK code: plain objects shaped like Effect
3
+ * Schema ASTs (`_tag`, `annotations`, `propertySignatures`, `types`,
4
+ * `thunk`, `encoding`), without Effect Schema's parser, issue and
5
+ * transformation machinery.
6
+ *
7
+ * Request encoding and lenient response decoding only walk the AST: they
8
+ * read wire names, HTTP bindings and the shape of the value. Importing
9
+ * `effect/Schema` to build those ASTs put about 37 KB gzip of decode
10
+ * machinery into every bundle that never decodes. These nodes carry the
11
+ * same fields protocol code reads, so it runs unchanged.
12
+ *
13
+ * When a caller asks for real validation (`ResponseValidation.strict` or
14
+ * `additionalProperties`), {@link toEffect} rebuilds the equivalent Effect
15
+ * schema from a lite node, loading `effect/Schema` only then.
16
+ *
17
+ * Every value here has the members generated code uses on schemas: `.ast`,
18
+ * `.pipe(...)`, `.annotate(...)`, `.fields` (structs) and `.key`/`.value`
19
+ * (records).
20
+ */
21
+ import type * as Cause from "effect/Cause";
22
+ import * as Data from "effect/Data";
23
+ import { pipeArguments, type Pipeable } from "effect/Pipeable";
24
+ import type * as EffectSchema from "effect/Schema";
25
+
26
+ export type Annotations = Record<string | symbol, unknown>;
27
+
28
+ /** A lite AST node. Field names match Effect's SchemaAST where protocols read them. */
29
+ export interface Node {
30
+ readonly _tag: string;
31
+ readonly annotations?: Annotations;
32
+ /**
33
+ * The wire-side node, for nodes whose value changes on the wire (AWS
34
+ * timestamps, blobs, sensitive values). Same shape as Effect's encoding
35
+ * chain, so code that follows `encoding[0].to` reads the wire type.
36
+ */
37
+ readonly encoding?: ReadonlyArray<{ readonly to: Node }>;
38
+ /** Declaration: the type guard strict validation applies (Unknown without one). */
39
+ readonly check?: (u: unknown) => boolean;
40
+ readonly context?: { readonly isOptional: boolean };
41
+ /** Objects */
42
+ readonly propertySignatures?: ReadonlyArray<PropertySignature>;
43
+ readonly indexSignatures?: ReadonlyArray<{ readonly parameter: Node; readonly type: Node }>;
44
+ /** Union */
45
+ readonly types?: ReadonlyArray<Node>;
46
+ /** Arrays */
47
+ readonly elements?: ReadonlyArray<Node>;
48
+ readonly rest?: ReadonlyArray<Node>;
49
+ /** Suspend */
50
+ readonly thunk?: () => Node;
51
+ /** Literal */
52
+ readonly literal?: unknown;
53
+ /** Declaration */
54
+ readonly typeParameters?: ReadonlyArray<Node>;
55
+ }
56
+
57
+ export interface PropertySignature {
58
+ readonly name: PropertyKey;
59
+ readonly type: Node;
60
+ }
61
+
62
+ /** A lite schema value: what generated code holds and passes around. */
63
+ export interface Lite {
64
+ readonly ast: Node;
65
+ readonly "~lite": true;
66
+ pipe(...fns: ReadonlyArray<(s: any) => any>): any;
67
+ annotate(annotations: Annotations): Lite;
68
+ }
69
+
70
+ /** Marks lite nodes so strict validation knows to convert them. */
71
+ export const liteKey = "~lite";
72
+ const node = <N extends Node>(n: N): N => Object.assign(n, { [liteKey]: true });
73
+
74
+ const Proto = {
75
+ "~lite": true,
76
+ pipe(this: Lite) {
77
+ return pipeArguments(this, arguments);
78
+ },
79
+ annotate(this: Lite, annotations: Annotations): Lite {
80
+ return make(
81
+ { ...this.ast, annotations: { ...this.ast.annotations, ...annotations } } as Node,
82
+ this,
83
+ );
84
+ },
85
+ };
86
+
87
+ const make = (ast: Node, from?: object): Lite => {
88
+ const self = Object.create(Proto) as { ast: Node };
89
+ self.ast = ast;
90
+ // Struct `.fields` and record `.key`/`.value` travel with annotate.
91
+ if (from)
92
+ for (const k of ["fields", "key", "value"]) if (k in from) (self as any)[k] = (from as any)[k];
93
+ return self as unknown as Lite;
94
+ };
95
+
96
+ /** A lite schema for a hand-built node (SDK-specific declarations). */
97
+ export const fromNode = (n: Node): Lite => make(node(n));
98
+
99
+ export const isLite = (u: unknown): u is Lite =>
100
+ (typeof u === "object" || typeof u === "function") && u !== null && (u as Lite)["~lite"] === true;
101
+
102
+ const astOf = (s: Lite | { readonly ast: Node }): Node => s.ast;
103
+
104
+ //#region primitives
105
+
106
+ export const String: Lite = /*@__PURE__*/ make(node({ _tag: "String" }));
107
+ export const Number: Lite = /*@__PURE__*/ make(node({ _tag: "Number" }));
108
+ export const Boolean: Lite = /*@__PURE__*/ make(node({ _tag: "Boolean" }));
109
+ export const Unknown: Lite = /*@__PURE__*/ make(node({ _tag: "Unknown" }));
110
+ export const Any: Lite = /*@__PURE__*/ make(node({ _tag: "Any" }));
111
+ export const Null: Lite = /*@__PURE__*/ make(node({ _tag: "Null" }));
112
+ export const Void: Lite = /*@__PURE__*/ make(node({ _tag: "Void" }));
113
+ export const Undefined: Lite = /*@__PURE__*/ make(node({ _tag: "Undefined" }));
114
+
115
+ //#endregion
116
+
117
+ //#region combinators
118
+
119
+ export const Literal = (value: unknown): Lite => make(node({ _tag: "Literal", literal: value }));
120
+
121
+ export const Literals = (values: ReadonlyArray<unknown>): Lite =>
122
+ make(node({ _tag: "Union", types: values.map((v) => node({ _tag: "Literal", literal: v })) }));
123
+
124
+ export const optional = (s: Lite): Lite => {
125
+ const inner = astOf(s);
126
+ return make(
127
+ node({
128
+ _tag: "Union",
129
+ types: [inner, node({ _tag: "Undefined" })],
130
+ context: { isOptional: true },
131
+ }),
132
+ );
133
+ };
134
+
135
+ export const NullOr = (s: Lite): Lite =>
136
+ make(node({ _tag: "Union", types: [astOf(s), node({ _tag: "Null" })] }));
137
+
138
+ export const Union = (members: ReadonlyArray<Lite>): Lite =>
139
+ make(node({ _tag: "Union", types: members.map(astOf) }));
140
+
141
+ export const Array = (item: Lite): Lite =>
142
+ make(node({ _tag: "Arrays", elements: [], rest: [astOf(item)] }));
143
+
144
+ export const Tuple = (elements: ReadonlyArray<Lite>): Lite =>
145
+ make(node({ _tag: "Arrays", elements: elements.map(astOf), rest: [] }));
146
+
147
+ export const Record = (key: Lite, value: Lite): Lite => {
148
+ const s = make(
149
+ node({
150
+ _tag: "Objects",
151
+ propertySignatures: [],
152
+ indexSignatures: [{ parameter: astOf(key), type: astOf(value) }],
153
+ }),
154
+ );
155
+ (s as any).key = key;
156
+ (s as any).value = value;
157
+ return s;
158
+ };
159
+
160
+ export const Struct = (fields: Readonly<Record<string, Lite>>): Lite => {
161
+ const s = make(
162
+ node({
163
+ _tag: "Objects",
164
+ propertySignatures: Object.keys(fields).map((name) => {
165
+ const type = astOf(fields[name]!);
166
+ return { name, type };
167
+ }),
168
+ indexSignatures: [],
169
+ }),
170
+ );
171
+ (s as any).fields = fields;
172
+ return s;
173
+ };
174
+
175
+ /**
176
+ * A struct that also allows keys it does not declare (OpenAPI
177
+ * `additionalProperties` next to `properties`): the struct's property
178
+ * signatures plus each record's index signature, as Effect's
179
+ * `StructWithRest` builds them.
180
+ */
181
+ export const StructWithRest = (struct: Lite, records: ReadonlyArray<Lite>): Lite => {
182
+ const base = resolveObjects(astOf(struct));
183
+ const s = make(
184
+ node({
185
+ _tag: "Objects",
186
+ propertySignatures: base.propertySignatures ?? [],
187
+ indexSignatures: [
188
+ ...(base.indexSignatures ?? []),
189
+ ...records.flatMap((r) => resolveObjects(astOf(r)).indexSignatures ?? []),
190
+ ],
191
+ }),
192
+ );
193
+ (s as any).fields = (struct as any).fields;
194
+ return s;
195
+ };
196
+
197
+ const resolveObjects = (n: Node): Node => (n._tag === "Suspend" ? resolveObjects(n.thunk!()) : n);
198
+
199
+ /** A lazily resolved schema; `.ast` is a Suspend node whose thunk resolves the target. */
200
+ export const suspend = (f: () => Lite): Lite => {
201
+ let resolved: Node | undefined;
202
+ return make(node({ _tag: "Suspend", thunk: () => (resolved ??= astOf(f())) }));
203
+ };
204
+
205
+ /** Rename struct keys on the wire: `{ typeKey: "wire_key" }`. */
206
+ export const encodeKeys =
207
+ (mapping: Readonly<Record<string, string>>) =>
208
+ (s: Lite): Lite =>
209
+ s.annotate({ [encodeKeysKey]: mapping });
210
+ export const encodeKeysKey = "@distilled.cloud/core/schema-lite/encodeKeys";
211
+
212
+ //#endregion
213
+
214
+ //#region declarations and errors
215
+
216
+ const declaration = (identifier: string): Lite =>
217
+ make(node({ _tag: "Declaration", typeParameters: [], annotations: { identifier } }));
218
+
219
+ export const Date: Lite = /*@__PURE__*/ declaration("Date");
220
+ export const Duration: Lite = /*@__PURE__*/ declaration("Duration");
221
+ export const Redacted = (value: Lite): Lite =>
222
+ make(
223
+ node({
224
+ _tag: "Declaration",
225
+ typeParameters: [astOf(value)],
226
+ annotations: { identifier: "Redacted" },
227
+ }),
228
+ );
229
+ export const instanceOf = (cls: Function, annotations?: Annotations): Lite =>
230
+ make(
231
+ node({
232
+ _tag: "Declaration",
233
+ typeParameters: [],
234
+ annotations: { identifier: cls.name, ...annotations },
235
+ }),
236
+ );
237
+ export const declare = (_is: (u: unknown) => boolean, annotations?: Annotations): Lite =>
238
+ make(node({ _tag: "Declaration", typeParameters: [], annotations: { ...annotations } }));
239
+
240
+ /**
241
+ * A tagged error class without Effect Schema: a yieldable `Data.TaggedError`
242
+ * that keeps only its declared fields (as the schema class did) and carries
243
+ * `.fields`, `.ast` and a static `.pipe` for category decorators. It does not
244
+ * validate on construction.
245
+ */
246
+ const tagKey = "~distilled/tag";
247
+ const keysKey = "~distilled/keys";
248
+ const astKey = "~distilled/ast";
249
+ const annotationsKey = "~distilled/annotations";
250
+ const annotationMetaKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/annotation-meta");
251
+
252
+ /**
253
+ * The annotations an error class declares: a plain object, or a pipeable
254
+ * trait (`T.all(...)`), whose own enumerable keys are its annotations.
255
+ */
256
+ const ownAnnotations = (from: object): Annotations => {
257
+ const out: Annotations = {};
258
+ for (const k of Reflect.ownKeys(from))
259
+ if (k !== annotationMetaKey && Object.prototype.propertyIsEnumerable.call(from, k))
260
+ out[k] = (from as any)[k];
261
+ return out;
262
+ };
263
+
264
+ /**
265
+ * Shared base of every lite error class: a yieldable `Data.Error` that keeps
266
+ * only the declared fields and sets `_tag` and `name` like
267
+ * `Data.TaggedError`. One class per error costs ~0.6 KB; building a
268
+ * `Data.TaggedError` base for each cost ~2.3 KB.
269
+ */
270
+ let liteErrorBase: any;
271
+ const LiteErrorBase = (): any =>
272
+ (liteErrorBase ??= class LiteError extends (Data.Error as any) {
273
+ constructor(props?: Record<string, unknown>) {
274
+ const keys: ReadonlyArray<string> = (new.target as any)[keysKey];
275
+ const picked: Record<string, unknown> = {};
276
+ if (props) for (const k of keys) if (props[k] !== undefined) picked[k] = props[k];
277
+ super(picked);
278
+ (this as any)._tag = (new.target as any)[tagKey];
279
+ }
280
+ /** The fields as a struct node carrying the tag (`identifier`) and class annotations. */
281
+ static get ast(): Node {
282
+ const C = this as any;
283
+ if (Object.hasOwn(C, astKey)) return C[astKey];
284
+ const fields: Record<string, Lite> = C.fields;
285
+ return (C[astKey] = node({
286
+ _tag: "Objects",
287
+ propertySignatures: Object.keys(fields).map((name) => ({
288
+ name,
289
+ type: astOf(fields[name]!),
290
+ })),
291
+ indexSignatures: [],
292
+ annotations: { identifier: C[tagKey], ...C[annotationsKey] },
293
+ }));
294
+ }
295
+ static pipe(this: unknown) {
296
+ return pipeArguments(this, arguments);
297
+ }
298
+ /** `new this(props)`, like Effect Schema's `TaggedError.make`. */
299
+ static make(
300
+ this: new (props?: Record<string, unknown>) => unknown,
301
+ props?: Record<string, unknown>,
302
+ ) {
303
+ return new this(props);
304
+ }
305
+ /**
306
+ * Whether `u` is an error of this class, by `_tag`. Matching the tag
307
+ * (not `instanceof`) holds across duplicate copies of a package.
308
+ */
309
+ static is(this: unknown, u: unknown): boolean {
310
+ return typeof u === "object" && u !== null && (u as any)._tag === (this as any)[tagKey];
311
+ }
312
+ });
313
+
314
+ /**
315
+ * The type of a lite tagged error class: what the class really has. It is
316
+ * not an Effect Schema, so `Schema.is(E)`, `Schema.decode(E)` and friends do
317
+ * not compile against it -- at runtime they would fail on the lite `.ast`.
318
+ * Match errors with `_tag` (`Effect.catchTag`) or `instanceof`.
319
+ */
320
+ export interface TaggedErrorClass<
321
+ Tag extends string,
322
+ Fields extends EffectSchema.Struct.Fields,
323
+ > extends Pipeable {
324
+ new (
325
+ ...args: {} extends EffectSchema.Struct.MakeIn<Fields>
326
+ ? [props?: EffectSchema.Struct.MakeIn<Fields>]
327
+ : [props: EffectSchema.Struct.MakeIn<Fields>]
328
+ ): Cause.YieldableError & { readonly _tag: Tag } & EffectSchema.Struct.Type<Fields>;
329
+ /** `new this(props)`. */
330
+ make<C extends abstract new (...args: any) => any>(
331
+ this: C,
332
+ ...args: ConstructorParameters<C>
333
+ ): InstanceType<C>;
334
+ /**
335
+ * Whether `u` is an error of this class, by `_tag`, so it holds across
336
+ * duplicate copies of a package (`instanceof` does not). Errors of another
337
+ * service with the same tag also match.
338
+ */
339
+ is<C extends abstract new (...args: any) => any>(this: C, u: unknown): u is InstanceType<C>;
340
+ readonly fields: Fields;
341
+ readonly identifier: Tag;
342
+ /** The lite struct node (not an Effect Schema AST). */
343
+ readonly ast: Node;
344
+ }
345
+
346
+ /**
347
+ * `TaggedError<Self>()(tag, fields)`, typed by the field schemas. `Self` is
348
+ * accepted for source compatibility with `Schema.TaggedError` and unused.
349
+ */
350
+ export type TaggedErrorFactory = <_Self = never>(
351
+ identifier?: string,
352
+ ) => <Tag extends string, const Fields extends EffectSchema.Struct.Fields = {}>(
353
+ tag: Tag,
354
+ fields?: Fields,
355
+ annotations?: object,
356
+ ) => TaggedErrorClass<Tag, Fields>;
357
+
358
+ /**
359
+ * A tagged error class without Effect Schema. It does not validate on
360
+ * construction. Carries `.fields` and `.identifier`, and a static `.pipe`
361
+ * for category decorators.
362
+ */
363
+ export const TaggedError =
364
+ (_identifier?: string) =>
365
+ (tag: string, fields: Readonly<Record<string, Lite>> = {}, annotations?: object): any => {
366
+ const C = class extends LiteErrorBase() {} as any;
367
+ C[tagKey] = tag;
368
+ C[keysKey] = Object.keys(fields);
369
+ if (annotations) C[annotationsKey] = ownAnnotations(annotations);
370
+ C.fields = fields;
371
+ C.identifier = tag;
372
+ C.prototype.name = tag;
373
+ return C;
374
+ };
375
+
376
+ /**
377
+ * Schema `j` of builder `build`, made on first use (the lite `chunks.at`).
378
+ * Its `.ast` is the built schema's own node, not a Suspend around it, so
379
+ * protocol code sees the same node shapes as with eager schemas.
380
+ */
381
+ export const at = (build: (j: number) => unknown, j: number): any => {
382
+ const self = Object.create(AtProto);
383
+ self.b = build;
384
+ self.j = j;
385
+ return self;
386
+ };
387
+
388
+ interface At {
389
+ readonly b: (j: number) => unknown;
390
+ readonly j: number;
391
+ s?: any;
392
+ }
393
+ const resolveAt = (self: At): any => (self.s ??= self.b(self.j));
394
+
395
+ const AtProto: object = /*@__PURE__*/ Object.create(Proto, {
396
+ ast: {
397
+ get(this: At) {
398
+ return resolveAt(this).ast;
399
+ },
400
+ },
401
+ fields: {
402
+ get(this: At) {
403
+ return resolveAt(this).fields;
404
+ },
405
+ },
406
+ key: {
407
+ get(this: At) {
408
+ return resolveAt(this).key;
409
+ },
410
+ },
411
+ value: {
412
+ get(this: At) {
413
+ return resolveAt(this).value;
414
+ },
415
+ },
416
+ });
417
+
418
+ //#endregion
419
+
420
+ //#region Effect Schema bridge (strict validation only)
421
+
422
+ /**
423
+ * The Effect schema equivalent to a lite node, for strict decoding. Loaded
424
+ * on demand so `effect/Schema` is only bundled/imported by callers that
425
+ * validate.
426
+ */
427
+ /** The Effect Schema functions the bridge uses (passed in, so callers import only these). */
428
+ export type EffectSchemaApi = Pick<
429
+ typeof import("effect/Schema"),
430
+ | "Any"
431
+ | "Array"
432
+ | "Boolean"
433
+ | "Literal"
434
+ | "Null"
435
+ | "Number"
436
+ | "Record"
437
+ | "String"
438
+ | "Struct"
439
+ | "StructWithRest"
440
+ | "Tuple"
441
+ | "Undefined"
442
+ | "Union"
443
+ | "Unknown"
444
+ | "Void"
445
+ | "declare"
446
+ | "make"
447
+ | "optional"
448
+ | "suspend"
449
+ >;
450
+
451
+ export const toEffect = (S: EffectSchemaApi, ast: Node): unknown => {
452
+ const memo = new Map<Node, any>();
453
+ // Whether a lite node sits anywhere under `n` (cycles count as no).
454
+ const liteBelow = new Map<Node, boolean>();
455
+ const hasLite = (n: Node): boolean => {
456
+ const known = liteBelow.get(n);
457
+ if (known !== undefined) return known;
458
+ liteBelow.set(n, false);
459
+ const kids: Node[] = [
460
+ ...(n.types ?? []),
461
+ ...(n.elements ?? []),
462
+ ...(n.rest ?? []),
463
+ ...(n.typeParameters ?? []),
464
+ ...(n.propertySignatures ?? []).map((p) => p.type),
465
+ ...(n.indexSignatures ?? []).flatMap((i) => [i.parameter, i.type]),
466
+ ...(((n as any).encoding ?? []) as Array<{ to: Node }>).map((l) => l.to),
467
+ ...(n._tag === "Suspend" && n.thunk ? [n.thunk()] : []),
468
+ ];
469
+ const r = !!(n as any)[liteKey] || kids.some(hasLite);
470
+ liteBelow.set(n, r);
471
+ return r;
472
+ };
473
+ const build = (n: Node): any => {
474
+ const hit = memo.get(n);
475
+ if (hit) return hit;
476
+ // A real Effect subtree with nothing lite below keeps its exact schema.
477
+ if (!(n as any)[liteKey] && !hasLite(n)) {
478
+ const real = S.make(n as any);
479
+ memo.set(n, real);
480
+ return real;
481
+ }
482
+ let out: any;
483
+ switch (n._tag) {
484
+ case "String":
485
+ out = S.String;
486
+ break;
487
+ case "Number":
488
+ out = S.Number;
489
+ break;
490
+ case "Boolean":
491
+ out = S.Boolean;
492
+ break;
493
+ case "Null":
494
+ out = S.Null;
495
+ break;
496
+ case "Undefined":
497
+ out = S.Undefined;
498
+ break;
499
+ case "Void":
500
+ out = S.Void;
501
+ break;
502
+ case "Any":
503
+ out = S.Any;
504
+ break;
505
+ case "Literal":
506
+ out = S.Literal(n.literal as any);
507
+ break;
508
+ case "Union":
509
+ out = n.context?.isOptional
510
+ ? S.optional(build(n.types![0]!))
511
+ : S.Union(n.types!.map(build));
512
+ break;
513
+ case "Arrays":
514
+ out = n.rest!.length ? S.Array(build(n.rest![0]!)) : S.Tuple(n.elements!.map(build));
515
+ break;
516
+ case "Objects": {
517
+ const props = n.propertySignatures ?? [];
518
+ const records = (n.indexSignatures ?? []).map((i) =>
519
+ S.Record(build(i.parameter), build(i.type)),
520
+ );
521
+ if (props.length === 0 && records.length === 1) {
522
+ out = records[0];
523
+ break;
524
+ }
525
+ const struct = S.Struct(Object.fromEntries(props.map((p) => [p.name, build(p.type)])));
526
+ out = records.length ? S.StructWithRest(struct, records as any) : struct;
527
+ break;
528
+ }
529
+ case "Suspend": {
530
+ const thunk = n.thunk!;
531
+ out = S.suspend(() => build(thunk()));
532
+ break;
533
+ }
534
+ case "Declaration":
535
+ out = n.check ? S.declare(n.check as (u: unknown) => u is unknown) : S.Unknown;
536
+ break;
537
+ case "Unknown":
538
+ out = S.Unknown;
539
+ break;
540
+ default:
541
+ // A lite tag with no case maps to Unknown; a real node keeps its schema.
542
+ out = (n as any)[liteKey] ? S.Unknown : S.make(n as any);
543
+ }
544
+ memo.set(n, out);
545
+ return out;
546
+ };
547
+ return build(ast);
548
+ };
549
+
550
+ //#endregion
@@ -0,0 +1,44 @@
1
+ /**
2
+ * `schema-lite` with Effect Schema's types, for hand-written modules.
3
+ *
4
+ * Generated services import `schema-lite`, whose builders are typed `any`
5
+ * because every generated schema is cast to its declared interface. Hand-
6
+ * written error classes have no such cast: built from untyped builders,
7
+ * their fields declare as `any` (`ValidationError.message: any`), which
8
+ * erases the field types for every consumer. This module exposes the same
9
+ * lite runtime values with the Effect Schema types, so `S.TaggedError` field
10
+ * types infer as they did with Effect Schema.
11
+ */
12
+ import type * as S from "effect/Schema";
13
+ import * as L from "./schema-lite-impl.ts";
14
+
15
+ export type * from "effect/Schema";
16
+
17
+ export const optional = L.optional as unknown as typeof S.optional;
18
+ export const Struct = L.Struct as unknown as typeof S.Struct;
19
+ export const StructWithRest = L.StructWithRest as unknown as typeof S.StructWithRest;
20
+ export const suspend = L.suspend as unknown as typeof S.suspend;
21
+ export const Array = L.Array as unknown as typeof S.Array;
22
+ export const Record = L.Record as unknown as typeof S.Record;
23
+ export const Union = L.Union as unknown as typeof S.Union;
24
+ export const Literal = L.Literal as unknown as typeof S.Literal;
25
+ export const Literals = L.Literals as unknown as typeof S.Literals;
26
+ export const NullOr = L.NullOr as unknown as typeof S.NullOr;
27
+ export const Tuple = L.Tuple as unknown as typeof S.Tuple;
28
+ export const declare = L.declare as unknown as typeof S.declare;
29
+ export const instanceOf = L.instanceOf as unknown as typeof S.instanceOf;
30
+ export const Redacted = L.Redacted as unknown as typeof S.Redacted;
31
+
32
+ export const String = L.String as unknown as typeof S.String;
33
+ export const Number = L.Number as unknown as typeof S.Number;
34
+ export const Int = L.Number as unknown as typeof S.Int;
35
+ export const Boolean = L.Boolean as unknown as typeof S.Boolean;
36
+ export const Date = L.Date as unknown as typeof S.Date;
37
+ export const Duration = L.Duration as unknown as typeof S.Duration;
38
+ export const Unknown = L.Unknown as unknown as typeof S.Unknown;
39
+ export const Null = L.Null as unknown as typeof S.Null;
40
+ export const Void = L.Void as unknown as typeof S.Void;
41
+ export const Any = L.Any as unknown as typeof S.Any;
42
+
43
+ export const TaggedError = L.TaggedError as unknown as L.TaggedErrorFactory;
44
+ export type { TaggedErrorClass, TaggedErrorFactory } from "./schema-lite-impl.ts";
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Effect Schema's API surface for generated code, backed by lite schemas
3
+ * (see `schema-lite-impl.ts`): the same names and types as
4
+ * `@distilled.cloud/core/schema`, without importing Effect Schema at runtime.
5
+ */
6
+ import type * as S from "effect/Schema";
7
+ import * as L from "./schema-lite-impl.ts";
8
+
9
+ export type * from "effect/Schema";
10
+ export type AnyFn = (...args: any[]) => any;
11
+
12
+ export const optional: AnyFn = L.optional;
13
+ export const Struct: AnyFn = L.Struct;
14
+ export const StructWithRest: AnyFn = L.StructWithRest;
15
+ export const suspend: AnyFn = L.suspend;
16
+ export const Array: AnyFn = L.Array;
17
+ export const Record: AnyFn = L.Record;
18
+ export const Union: AnyFn = L.Union;
19
+ export const Literal: AnyFn = L.Literal;
20
+ export const Literals: AnyFn = L.Literals;
21
+ export const NullOr: AnyFn = L.NullOr;
22
+ export const Tuple: AnyFn = L.Tuple;
23
+ export const encodeKeys: AnyFn = L.encodeKeys;
24
+ export const declare: typeof S.declare = L.declare as unknown as typeof S.declare;
25
+ export const instanceOf: AnyFn = L.instanceOf;
26
+ export const Redacted: AnyFn = L.Redacted;
27
+
28
+ export const String: any = L.String;
29
+ export const Number: any = L.Number;
30
+ export const Int: any = L.Number;
31
+ export const Boolean: any = L.Boolean;
32
+ export const Date: any = L.Date;
33
+ export const Duration: any = L.Duration;
34
+ export const Unknown: any = L.Unknown;
35
+ export const Null: any = L.Null;
36
+ export const Void: any = L.Void;
37
+ export const Any: any = L.Any;
38
+
39
+ export const TaggedError = L.TaggedError as unknown as L.TaggedErrorFactory;
40
+ export type { TaggedErrorClass, TaggedErrorFactory } from "./schema-lite-impl.ts";
41
+
42
+ /** Lite `chunks.at`: generated services name this module `__L`. */
43
+ export const at = L.at;
44
+ export { liteKey, toEffect } from "./schema-lite-impl.ts";