@distilled.cloud/core 1.0.0-rc.2 → 1.0.0-rc.21

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 (321) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +33 -0
  3. package/lib/_bundle/aws.js +2 -0
  4. package/lib/_bundle/aws.js.map +1 -0
  5. package/lib/_bundle/base.js +5 -0
  6. package/lib/_bundle/base.js.map +1 -0
  7. package/lib/_bundle/graphql.js +3 -0
  8. package/lib/_bundle/graphql.js.map +1 -0
  9. package/lib/_bundle/grpc.js +3 -0
  10. package/lib/_bundle/grpc.js.map +1 -0
  11. package/lib/_bundle/rest.js +2 -0
  12. package/lib/_bundle/rest.js.map +1 -0
  13. package/lib/_bundle/xml.js +4 -0
  14. package/lib/_bundle/xml.js.map +1 -0
  15. package/lib/annotations.d.ts +17 -0
  16. package/lib/annotations.d.ts.map +1 -0
  17. package/lib/annotations.js +2 -0
  18. package/lib/annotations.js.map +1 -0
  19. package/lib/api.d.ts +220 -51
  20. package/lib/api.d.ts.map +1 -1
  21. package/lib/api.js +1 -178
  22. package/lib/category.d.ts +19 -16
  23. package/lib/category.d.ts.map +1 -1
  24. package/lib/category.js +1 -280
  25. package/lib/chunks.d.ts +3 -0
  26. package/lib/chunks.d.ts.map +1 -0
  27. package/lib/chunks.js +1 -0
  28. package/lib/config.d.ts +81 -0
  29. package/lib/config.d.ts.map +1 -0
  30. package/lib/config.js +1 -0
  31. package/lib/crypto.d.ts +76 -0
  32. package/lib/crypto.d.ts.map +1 -0
  33. package/lib/crypto.js +1 -0
  34. package/lib/error-category.d.ts +1 -1
  35. package/lib/error-category.d.ts.map +1 -1
  36. package/lib/error-category.js +1 -46
  37. package/lib/errors.d.ts +99 -74
  38. package/lib/errors.d.ts.map +1 -1
  39. package/lib/errors.js +1 -186
  40. package/lib/graphql.d.ts +420 -0
  41. package/lib/graphql.d.ts.map +1 -0
  42. package/lib/graphql.js +1 -0
  43. package/lib/graphql.types.d.ts +11 -0
  44. package/lib/graphql.types.d.ts.map +1 -0
  45. package/lib/graphql.types.js +1 -0
  46. package/lib/grpc-transport-cloudflare-http2.d.ts +7 -0
  47. package/lib/grpc-transport-cloudflare-http2.d.ts.map +1 -0
  48. package/lib/grpc-transport-cloudflare-http2.js +6 -0
  49. package/lib/grpc-transport-cloudflare-http2.js.map +1 -0
  50. package/lib/grpc-transport-cloudflare-sockets.d.ts +7 -0
  51. package/lib/grpc-transport-cloudflare-sockets.d.ts.map +1 -0
  52. package/lib/grpc-transport-cloudflare-sockets.js +5 -0
  53. package/lib/grpc-transport-cloudflare-sockets.js.map +1 -0
  54. package/lib/grpc-transport-node-http2.d.ts +19 -0
  55. package/lib/grpc-transport-node-http2.d.ts.map +1 -0
  56. package/lib/grpc-transport-node-http2.js +2 -0
  57. package/lib/grpc-transport-node-http2.js.map +1 -0
  58. package/lib/grpc-transport.d.ts +111 -0
  59. package/lib/grpc-transport.d.ts.map +1 -0
  60. package/lib/grpc-transport.js +1 -0
  61. package/lib/hpack.d.ts +34 -0
  62. package/lib/hpack.d.ts.map +1 -0
  63. package/lib/hpack.js +2 -0
  64. package/lib/hpack.js.map +1 -0
  65. package/lib/index.d.ts +32 -0
  66. package/lib/index.d.ts.map +1 -0
  67. package/lib/index.js +17 -0
  68. package/lib/max-message-bytes.d.ts +42 -0
  69. package/lib/max-message-bytes.d.ts.map +1 -0
  70. package/lib/max-message-bytes.js +2 -0
  71. package/lib/max-message-bytes.js.map +1 -0
  72. package/lib/ndjson.d.ts +3 -0
  73. package/lib/ndjson.d.ts.map +1 -0
  74. package/lib/ndjson.js +2 -0
  75. package/lib/ndjson.js.map +1 -0
  76. package/lib/pagination.d.ts +105 -25
  77. package/lib/pagination.d.ts.map +1 -1
  78. package/lib/pagination.js +1 -182
  79. package/lib/plain-values.d.ts +21 -0
  80. package/lib/plain-values.d.ts.map +1 -0
  81. package/lib/plain-values.js +2 -0
  82. package/lib/plain-values.js.map +1 -0
  83. package/lib/protobuf.d.ts +85 -0
  84. package/lib/protobuf.d.ts.map +1 -0
  85. package/lib/protobuf.js +1 -0
  86. package/lib/protocol-grpc.d.ts +123 -0
  87. package/lib/protocol-grpc.d.ts.map +1 -0
  88. package/lib/protocol-grpc.js +1 -0
  89. package/lib/protocol-http.d.ts +206 -25
  90. package/lib/protocol-http.d.ts.map +1 -1
  91. package/lib/protocol-http.js +1 -554
  92. package/lib/protocol-rest.d.ts +258 -64
  93. package/lib/protocol-rest.d.ts.map +1 -1
  94. package/lib/protocol-rest.js +1 -242
  95. package/lib/protocol.d.ts +113 -0
  96. package/lib/protocol.d.ts.map +1 -0
  97. package/lib/protocol.js +0 -0
  98. package/lib/query.d.ts +29 -0
  99. package/lib/query.d.ts.map +1 -0
  100. package/lib/query.js +1 -0
  101. package/lib/response-validation-strict.d.ts +48 -0
  102. package/lib/response-validation-strict.d.ts.map +1 -0
  103. package/lib/response-validation-strict.js +1 -0
  104. package/lib/response-validation.d.ts +86 -0
  105. package/lib/response-validation.d.ts.map +1 -0
  106. package/lib/response-validation.js +1 -0
  107. package/lib/retry-after.d.ts +4 -4
  108. package/lib/retry-after.d.ts.map +1 -1
  109. package/lib/retry-after.js +1 -112
  110. package/lib/retry-state.d.ts +26 -0
  111. package/lib/retry-state.d.ts.map +1 -0
  112. package/lib/retry-state.js +2 -0
  113. package/lib/retry-state.js.map +1 -0
  114. package/lib/retry.d.ts +141 -42
  115. package/lib/retry.d.ts.map +1 -1
  116. package/lib/retry.js +1 -210
  117. package/lib/schema-lite-impl.d.ts +179 -0
  118. package/lib/schema-lite-impl.d.ts.map +1 -0
  119. package/lib/schema-lite-impl.js +1 -0
  120. package/lib/schema-lite-typed.d.ts +41 -0
  121. package/lib/schema-lite-typed.d.ts.map +1 -0
  122. package/lib/schema-lite-typed.js +1 -0
  123. package/lib/schema-lite.d.ts +41 -0
  124. package/lib/schema-lite.d.ts.map +1 -0
  125. package/lib/schema-lite.js +1 -0
  126. package/lib/schema.d.ts +21 -7
  127. package/lib/schema.d.ts.map +1 -1
  128. package/lib/schema.js +1 -48
  129. package/lib/sdk-error.d.ts +31 -0
  130. package/lib/sdk-error.d.ts.map +1 -0
  131. package/lib/sdk-error.js +1 -0
  132. package/lib/send.d.ts +37 -0
  133. package/lib/send.d.ts.map +1 -0
  134. package/lib/send.js +2 -0
  135. package/lib/send.js.map +1 -0
  136. package/lib/sensitive.d.ts +28 -0
  137. package/lib/sensitive.d.ts.map +1 -0
  138. package/lib/sensitive.js +2 -0
  139. package/lib/sensitive.js.map +1 -0
  140. package/lib/telemetry-debug.d.ts +6 -0
  141. package/lib/telemetry-debug.d.ts.map +1 -0
  142. package/lib/telemetry-debug.js +2 -0
  143. package/lib/telemetry-debug.js.map +1 -0
  144. package/lib/telemetry-hooks.d.ts +32 -0
  145. package/lib/telemetry-hooks.d.ts.map +1 -0
  146. package/lib/telemetry-hooks.js +2 -0
  147. package/lib/telemetry-hooks.js.map +1 -0
  148. package/lib/telemetry-host-rules.d.ts +23 -0
  149. package/lib/telemetry-host-rules.d.ts.map +1 -0
  150. package/lib/telemetry-host-rules.js +2 -0
  151. package/lib/telemetry-host-rules.js.map +1 -0
  152. package/lib/telemetry-lambda-context.d.ts +17 -0
  153. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  154. package/lib/telemetry-lambda-context.js +2 -0
  155. package/lib/telemetry-lambda-context.js.map +1 -0
  156. package/lib/telemetry-message-context.d.ts +52 -0
  157. package/lib/telemetry-message-context.d.ts.map +1 -0
  158. package/lib/telemetry-message-context.js +2 -0
  159. package/lib/telemetry-message-context.js.map +1 -0
  160. package/lib/telemetry-metrics.d.ts +6 -0
  161. package/lib/telemetry-metrics.d.ts.map +1 -0
  162. package/lib/telemetry-metrics.js +2 -0
  163. package/lib/telemetry-metrics.js.map +1 -0
  164. package/lib/telemetry-name-template.d.ts +13 -0
  165. package/lib/telemetry-name-template.d.ts.map +1 -0
  166. package/lib/telemetry-name-template.js +2 -0
  167. package/lib/telemetry-name-template.js.map +1 -0
  168. package/lib/telemetry-stream.d.ts +11 -0
  169. package/lib/telemetry-stream.d.ts.map +1 -0
  170. package/lib/telemetry-stream.js +2 -0
  171. package/lib/telemetry-stream.js.map +1 -0
  172. package/lib/telemetry-xray.d.ts +28 -0
  173. package/lib/telemetry-xray.d.ts.map +1 -0
  174. package/lib/telemetry-xray.js +2 -0
  175. package/lib/telemetry-xray.js.map +1 -0
  176. package/lib/telemetry.d.ts +317 -0
  177. package/lib/telemetry.d.ts.map +1 -0
  178. package/lib/telemetry.js +3 -0
  179. package/lib/telemetry.js.map +1 -0
  180. package/lib/token-cache.d.ts +31 -0
  181. package/lib/token-cache.d.ts.map +1 -0
  182. package/lib/token-cache.js +2 -0
  183. package/lib/token-cache.js.map +1 -0
  184. package/lib/trait.d.ts +94 -20
  185. package/lib/trait.d.ts.map +1 -1
  186. package/lib/trait.js +1 -107
  187. package/lib/unknown-error.d.ts +18 -0
  188. package/lib/unknown-error.d.ts.map +1 -0
  189. package/lib/unknown-error.js +1 -0
  190. package/lib/xml.d.ts +44 -0
  191. package/lib/xml.d.ts.map +1 -0
  192. package/lib/xml.js +1 -0
  193. package/package.json +13 -13
  194. package/src/annotations.ts +53 -0
  195. package/src/api.ts +1597 -234
  196. package/src/category.ts +97 -134
  197. package/src/chunks.ts +30 -0
  198. package/src/config.ts +261 -0
  199. package/src/crypto.ts +202 -0
  200. package/src/error-category.ts +16 -29
  201. package/src/errors.ts +99 -77
  202. package/src/graphql.ts +1817 -0
  203. package/src/graphql.types.ts +120 -0
  204. package/src/grpc-transport-cloudflare-http2.ts +569 -0
  205. package/src/grpc-transport-cloudflare-sockets.ts +368 -0
  206. package/src/grpc-transport-node-http2.ts +307 -0
  207. package/src/grpc-transport.ts +287 -0
  208. package/src/hpack.ts +331 -0
  209. package/src/index.ts +31 -0
  210. package/src/max-message-bytes.ts +58 -0
  211. package/src/ndjson.ts +55 -0
  212. package/src/pagination.ts +379 -94
  213. package/src/plain-values.ts +70 -0
  214. package/src/protobuf.ts +1367 -0
  215. package/src/protocol-grpc.ts +811 -0
  216. package/src/protocol-http.ts +1045 -371
  217. package/src/protocol-rest.ts +908 -255
  218. package/src/protocol.ts +150 -0
  219. package/src/query.ts +39 -0
  220. package/src/response-validation-strict.ts +333 -0
  221. package/src/response-validation.ts +161 -0
  222. package/src/retry-after.ts +8 -14
  223. package/src/retry-state.ts +105 -0
  224. package/src/retry.ts +260 -145
  225. package/src/schema-lite-impl.ts +621 -0
  226. package/src/schema-lite-typed.ts +44 -0
  227. package/src/schema-lite.ts +45 -0
  228. package/src/schema.ts +259 -15
  229. package/src/sdk-error.ts +37 -0
  230. package/src/send.ts +156 -0
  231. package/src/sensitive.ts +188 -0
  232. package/src/telemetry-debug.ts +179 -0
  233. package/src/telemetry-hooks.ts +33 -0
  234. package/src/telemetry-host-rules.ts +39 -0
  235. package/src/telemetry-lambda-context.ts +46 -0
  236. package/src/telemetry-message-context.ts +170 -0
  237. package/src/telemetry-metrics.ts +69 -0
  238. package/src/telemetry-name-template.ts +26 -0
  239. package/src/telemetry-stream.ts +100 -0
  240. package/src/telemetry-xray.ts +66 -0
  241. package/src/telemetry.ts +800 -0
  242. package/src/token-cache.ts +117 -0
  243. package/src/trait.ts +139 -67
  244. package/src/unknown-error.ts +38 -0
  245. package/src/xml.ts +346 -0
  246. package/lib/api.js.map +0 -1
  247. package/lib/category.js.map +0 -1
  248. package/lib/codegen/cli.d.ts +0 -29
  249. package/lib/codegen/cli.d.ts.map +0 -1
  250. package/lib/codegen/cli.js +0 -165
  251. package/lib/codegen/cli.js.map +0 -1
  252. package/lib/codegen/emit.d.ts +0 -129
  253. package/lib/codegen/emit.d.ts.map +0 -1
  254. package/lib/codegen/emit.js +0 -105
  255. package/lib/codegen/emit.js.map +0 -1
  256. package/lib/codegen/format.d.ts +0 -23
  257. package/lib/codegen/format.d.ts.map +0 -1
  258. package/lib/codegen/format.js +0 -28
  259. package/lib/codegen/format.js.map +0 -1
  260. package/lib/codegen/generator.d.ts +0 -334
  261. package/lib/codegen/generator.d.ts.map +0 -1
  262. package/lib/codegen/generator.js +0 -691
  263. package/lib/codegen/generator.js.map +0 -1
  264. package/lib/codegen/graph.d.ts +0 -36
  265. package/lib/codegen/graph.d.ts.map +0 -1
  266. package/lib/codegen/graph.js +0 -136
  267. package/lib/codegen/graph.js.map +0 -1
  268. package/lib/codegen/members.d.ts +0 -25
  269. package/lib/codegen/members.d.ts.map +0 -1
  270. package/lib/codegen/members.js +0 -55
  271. package/lib/codegen/members.js.map +0 -1
  272. package/lib/codegen/naming.d.ts +0 -29
  273. package/lib/codegen/naming.d.ts.map +0 -1
  274. package/lib/codegen/naming.js +0 -74
  275. package/lib/codegen/naming.js.map +0 -1
  276. package/lib/codegen/openapi-cli.d.ts +0 -38
  277. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  278. package/lib/codegen/openapi-cli.js +0 -107
  279. package/lib/codegen/openapi-cli.js.map +0 -1
  280. package/lib/codegen/openapi.d.ts +0 -115
  281. package/lib/codegen/openapi.d.ts.map +0 -1
  282. package/lib/codegen/openapi.js +0 -1220
  283. package/lib/codegen/openapi.js.map +0 -1
  284. package/lib/codegen/operations.d.ts +0 -24
  285. package/lib/codegen/operations.d.ts.map +0 -1
  286. package/lib/codegen/operations.js +0 -56
  287. package/lib/codegen/operations.js.map +0 -1
  288. package/lib/codegen/pagination.d.ts +0 -39
  289. package/lib/codegen/pagination.d.ts.map +0 -1
  290. package/lib/codegen/pagination.js +0 -33
  291. package/lib/codegen/pagination.js.map +0 -1
  292. package/lib/codegen/prelude.d.ts +0 -15
  293. package/lib/codegen/prelude.d.ts.map +0 -1
  294. package/lib/codegen/prelude.js +0 -60
  295. package/lib/codegen/prelude.js.map +0 -1
  296. package/lib/error-category.js.map +0 -1
  297. package/lib/errors.js.map +0 -1
  298. package/lib/json-patch.d.ts +0 -44
  299. package/lib/json-patch.d.ts.map +0 -1
  300. package/lib/json-patch.js +0 -174
  301. package/lib/json-patch.js.map +0 -1
  302. package/lib/pagination.js.map +0 -1
  303. package/lib/protocol-http.js.map +0 -1
  304. package/lib/protocol-rest.js.map +0 -1
  305. package/lib/retry-after.js.map +0 -1
  306. package/lib/retry.js.map +0 -1
  307. package/lib/schema.js.map +0 -1
  308. package/lib/trait.js.map +0 -1
  309. package/src/codegen/cli.ts +0 -268
  310. package/src/codegen/emit.ts +0 -207
  311. package/src/codegen/format.ts +0 -47
  312. package/src/codegen/generator.ts +0 -1153
  313. package/src/codegen/graph.ts +0 -151
  314. package/src/codegen/members.ts +0 -71
  315. package/src/codegen/naming.ts +0 -86
  316. package/src/codegen/openapi-cli.ts +0 -166
  317. package/src/codegen/openapi.ts +0 -1450
  318. package/src/codegen/operations.ts +0 -76
  319. package/src/codegen/pagination.ts +0 -71
  320. package/src/codegen/prelude.ts +0 -70
  321. package/src/json-patch.ts +0 -222
@@ -1,76 +0,0 @@
1
- /**
2
- * Operation-level smithy helpers for the SDK generators (dev-time only).
3
- */
4
- import { local } from "./naming.ts";
5
- import type { ShapeMap } from "./graph.ts";
6
-
7
- export interface OpEntry {
8
- id: string;
9
- def: any;
10
- }
11
-
12
- /** All operation shapes, sorted by local name. */
13
- export const collectOperations = (shapes: ShapeMap): OpEntry[] => {
14
- const operations: OpEntry[] = [];
15
- for (const [id, def] of Object.entries(shapes)) {
16
- if (def.type === "operation") operations.push({ id, def });
17
- }
18
- operations.sort((a, b) => local(a.id).localeCompare(local(b.id)));
19
- return operations;
20
- };
21
-
22
- /** The model's shape namespace (from the first operation, else any shape). */
23
- export const modelNamespace = (
24
- operations: readonly OpEntry[],
25
- shapes: ShapeMap,
26
- fallback: string,
27
- ): string =>
28
- operations.length
29
- ? operations[0].id.split("#")[0]
30
- : (Object.keys(shapes)[0]?.split("#")[0] ?? fallback);
31
-
32
- /**
33
- * Resolve an operation's input/output targets, synthesizing an empty named
34
- * structure for `smithy.api#Unit` so every operation has a shape that can
35
- * carry operation-level traits (mutates `shapes`).
36
- */
37
- export const ensureNamedIo = (
38
- shapes: ShapeMap,
39
- op: OpEntry,
40
- ns: string,
41
- ): { input: string; output: string } => {
42
- const opName = local(op.id);
43
- let input = op.def.input?.target ?? "smithy.api#Unit";
44
- let output = op.def.output?.target ?? "smithy.api#Unit";
45
- if (input === "smithy.api#Unit") {
46
- input = `${ns}#${opName}Request`;
47
- shapes[input] = { type: "structure", members: {} };
48
- }
49
- if (output === "smithy.api#Unit") {
50
- output = `${ns}#${opName}Response`;
51
- shapes[output] = { type: "structure", members: {} };
52
- }
53
- return { input, output };
54
- };
55
-
56
- /**
57
- * Every error shape id referenced by the operations' `errors` lists —
58
- * deduplicated, existing in the model, sorted by local name.
59
- */
60
- export const collectOpErrorIds = (
61
- operations: readonly OpEntry[],
62
- shapes: ShapeMap,
63
- ): string[] => {
64
- const errorIds: string[] = [];
65
- const seen = new Set<string>();
66
- for (const op of operations) {
67
- for (const e of op.def.errors ?? []) {
68
- if (!seen.has(e.target) && shapes[e.target]) {
69
- seen.add(e.target);
70
- errorIds.push(e.target);
71
- }
72
- }
73
- }
74
- errorIds.sort((a, b) => local(a).localeCompare(local(b)));
75
- return errorIds;
76
- };
@@ -1,71 +0,0 @@
1
- /**
2
- * Shared pagination-trait handling for the SDK generators (dev-time only).
3
- *
4
- * Both SDKs source `smithy.api#paginated`; AWS merges operation-level
5
- * config over service-level defaults, cloudflare validates the trait
6
- * against the operation's actual members (degrading to a plain op when it
7
- * can't work). Both behaviors live here.
8
- */
9
- import type { PaginatedTrait } from "../pagination.ts";
10
-
11
- /**
12
- * Merge an operation-level paginated trait over service-level defaults
13
- * (Smithy semantics: operations may specify partial pagination and inherit
14
- * the rest from the service).
15
- */
16
- export const mergePaginated = (
17
- op: Partial<PaginatedTrait> | undefined,
18
- service: Partial<PaginatedTrait> | undefined,
19
- ): PaginatedTrait | undefined => {
20
- if (!op) return undefined;
21
- const merged = {
22
- mode: op.mode ?? service?.mode,
23
- inputToken: op.inputToken ?? service?.inputToken,
24
- outputToken: op.outputToken ?? service?.outputToken,
25
- items: op.items ?? service?.items,
26
- pageSize: op.pageSize ?? service?.pageSize,
27
- };
28
- return Object.fromEntries(
29
- Object.entries(merged).filter(([, v]) => v !== undefined),
30
- ) as PaginatedTrait;
31
- };
32
-
33
- export interface ValidatePaginatedOptions {
34
- readonly trait: Partial<PaginatedTrait>;
35
- /** TS-facing member names of the operation input shape. */
36
- readonly inputNames: ReadonlySet<string>;
37
- /** TS-facing member names of the operation output shape. */
38
- readonly outputNames: ReadonlySet<string>;
39
- /** Items path fallback when the trait omits `items` (e.g. `"result"`). */
40
- readonly itemsFallback?: string;
41
- /** Output names accepted even when not modeled (e.g. `"resultInfo"`). */
42
- readonly syntheticOutputs?: ReadonlySet<string>;
43
- }
44
-
45
- export interface ValidatedPagination {
46
- readonly ok: boolean;
47
- /** Root member of the items path (`"result.items"` → `"result"`). */
48
- readonly itemsRoot: string;
49
- }
50
-
51
- /**
52
- * A paginated op must actually carry its page/cursor token on the input
53
- * and its items member on the output — otherwise `.pages()` would loop or
54
- * yield nothing. Returns the items-path root for emitters that promote it
55
- * to required.
56
- */
57
- export const validatePaginated = (
58
- o: ValidatePaginatedOptions,
59
- ): ValidatedPagination => {
60
- const itemsRoot = String(o.trait.items ?? o.itemsFallback ?? "").split(
61
- ".",
62
- )[0];
63
- const tokenOk =
64
- o.trait.mode === "single" ||
65
- (typeof o.trait.inputToken === "string" &&
66
- o.inputNames.has(o.trait.inputToken));
67
- const itemsOk =
68
- o.outputNames.has(itemsRoot) ||
69
- (o.syntheticOutputs?.has(itemsRoot) ?? false);
70
- return { ok: tokenOk && itemsOk, itemsRoot };
71
- };
@@ -1,70 +0,0 @@
1
- /**
2
- * Smithy prelude scalar baselines + reference resolvers for the SDK
3
- * generators (dev-time only).
4
- *
5
- * The JSON flavor maps timestamps/blobs to plain strings — the baseline for
6
- * SDKs whose wire format is JSON-over-docs (cloudflare). Generators with
7
- * richer models (AWS) emit real timestamp/blob schemas themselves and only
8
- * fall back here for untyped scalars.
9
- */
10
- import { isPrelude, local } from "./naming.ts";
11
- import { isForwardRef } from "./graph.ts";
12
-
13
- /** Prelude shape → schema expression (JSON-wire flavor). */
14
- export const JSON_PRELUDE: Record<string, string> = {
15
- String: "S.String",
16
- Boolean: "S.Boolean",
17
- Double: "S.Number",
18
- Float: "S.Number",
19
- Integer: "S.Number",
20
- Long: "S.Number",
21
- BigInteger: "S.Number",
22
- BigDecimal: "S.Number",
23
- Timestamp: "S.String",
24
- Blob: "S.String",
25
- Document: "S.Unknown",
26
- Unit: "S.Struct({})",
27
- };
28
-
29
- /** TypeScript type for each prelude shape, mirroring {@link JSON_PRELUDE}. */
30
- export const TS_JSON_PRELUDE: Record<string, string> = {
31
- String: "string",
32
- Boolean: "boolean",
33
- Double: "number",
34
- Float: "number",
35
- Integer: "number",
36
- Long: "number",
37
- BigInteger: "number",
38
- BigDecimal: "number",
39
- Timestamp: "string",
40
- Blob: "string",
41
- Document: "unknown",
42
- Unit: "{}",
43
- };
44
-
45
- /**
46
- * Schema reference resolver: prelude shapes map through the prelude table,
47
- * forward references (including into cycles) wrap in `S.suspend`.
48
- */
49
- export const makeSchemaRef =
50
- (
51
- prelude: Record<string, string>,
52
- indexOf: ReadonlyMap<string, number>,
53
- ): ((target: string, selfIdx: number) => string) =>
54
- (target, selfIdx) => {
55
- if (isPrelude(target)) return prelude[local(target)] ?? "S.Unknown";
56
- const name = local(target);
57
- if (isForwardRef(indexOf, target, selfIdx)) {
58
- return `S.suspend(() => ${name})`;
59
- }
60
- return name;
61
- };
62
-
63
- /**
64
- * TypeScript type reference resolver. Named shapes all get an emitted
65
- * interface / type alias, so forward references are always fine.
66
- */
67
- export const makeTsRef =
68
- (tsPrelude: Record<string, string>): ((target: string) => string) =>
69
- (target) =>
70
- isPrelude(target) ? (tsPrelude[local(target)] ?? "unknown") : local(target);
package/src/json-patch.ts DELETED
@@ -1,222 +0,0 @@
1
- /**
2
- * JSON Patch (RFC 6902) Implementation
3
- *
4
- * Provides a unified spec patching system for all SDKs. Patches are applied to
5
- * generated intermediary specs (Smithy models, OpenAPI docs, …) before code
6
- * generation to add typed error shapes, rename operations, mark nullable
7
- * fields, etc. Ported from the distilled repo's `core/json-patch`.
8
- *
9
- * Pure functions only — callers load patch files themselves (the generators
10
- * use Effect's FileSystem) and hand the parsed operations to `applyPatch`.
11
- */
12
-
13
- // ============================================================================
14
- // Types
15
- // ============================================================================
16
-
17
- export interface JsonPatchOperation {
18
- op: "add" | "remove" | "replace" | "move" | "copy" | "test";
19
- path: string;
20
- value?: unknown;
21
- from?: string;
22
- }
23
-
24
- export type JsonPatch = JsonPatchOperation[];
25
-
26
- export interface PatchFile {
27
- description?: string;
28
- patches: JsonPatch;
29
- }
30
-
31
- // ============================================================================
32
- // JSON Pointer (RFC 6901)
33
- // ============================================================================
34
-
35
- /** Parse a JSON Pointer (RFC 6901) path into segments. */
36
- export function parseJsonPointer(pointer: string): string[] {
37
- if (pointer === "") return [];
38
- if (!pointer.startsWith("/")) {
39
- throw new Error(`Invalid JSON Pointer: ${pointer}`);
40
- }
41
- return pointer
42
- .slice(1)
43
- .split("/")
44
- .map((segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~"));
45
- }
46
-
47
- /** Get a value at a JSON Pointer path. */
48
- export function getValueAtPath(obj: unknown, pointer: string): unknown {
49
- const segments = parseJsonPointer(pointer);
50
- let current: unknown = obj;
51
-
52
- for (const segment of segments) {
53
- if (current === null || typeof current !== "object") {
54
- throw new Error(`Cannot traverse path ${pointer}: not an object`);
55
- }
56
- if (Array.isArray(current)) {
57
- const index = segment === "-" ? current.length : parseInt(segment, 10);
58
- current = current[index];
59
- } else {
60
- current = (current as Record<string, unknown>)[segment];
61
- }
62
- }
63
-
64
- return current;
65
- }
66
-
67
- /** Set a value at a JSON Pointer path. */
68
- export function setValueAtPath(
69
- obj: unknown,
70
- pointer: string,
71
- value: unknown,
72
- ): void {
73
- const segments = parseJsonPointer(pointer);
74
- if (segments.length === 0) {
75
- throw new Error("Cannot set value at root path");
76
- }
77
-
78
- let current: unknown = obj;
79
-
80
- for (let i = 0; i < segments.length - 1; i++) {
81
- const segment = segments[i]!;
82
- if (current === null || typeof current !== "object") {
83
- throw new Error(`Cannot traverse path ${pointer}: not an object`);
84
- }
85
- if (Array.isArray(current)) {
86
- current = current[parseInt(segment, 10)];
87
- } else {
88
- current = (current as Record<string, unknown>)[segment];
89
- }
90
- }
91
-
92
- const lastSegment = segments[segments.length - 1]!;
93
- if (current === null || typeof current !== "object") {
94
- throw new Error(
95
- `Cannot set value at path ${pointer}: parent is not an object`,
96
- );
97
- }
98
-
99
- if (Array.isArray(current)) {
100
- if (lastSegment === "-") {
101
- current.push(value);
102
- } else {
103
- current[parseInt(lastSegment, 10)] = value;
104
- }
105
- } else {
106
- (current as Record<string, unknown>)[lastSegment] = value;
107
- }
108
- }
109
-
110
- /** Remove a value at a JSON Pointer path. */
111
- export function removeValueAtPath(obj: unknown, pointer: string): void {
112
- const segments = parseJsonPointer(pointer);
113
- if (segments.length === 0) {
114
- throw new Error("Cannot remove root");
115
- }
116
-
117
- let current: unknown = obj;
118
-
119
- for (let i = 0; i < segments.length - 1; i++) {
120
- const segment = segments[i]!;
121
- if (current === null || typeof current !== "object") {
122
- throw new Error(`Cannot traverse path ${pointer}: not an object`);
123
- }
124
- if (Array.isArray(current)) {
125
- current = current[parseInt(segment, 10)];
126
- } else {
127
- current = (current as Record<string, unknown>)[segment];
128
- }
129
- }
130
-
131
- const lastSegment = segments[segments.length - 1]!;
132
- if (current === null || typeof current !== "object") {
133
- throw new Error(
134
- `Cannot remove at path ${pointer}: parent is not an object`,
135
- );
136
- }
137
-
138
- if (Array.isArray(current)) {
139
- current.splice(parseInt(lastSegment, 10), 1);
140
- } else {
141
- delete (current as Record<string, unknown>)[lastSegment];
142
- }
143
- }
144
-
145
- // ============================================================================
146
- // Patch Operations
147
- // ============================================================================
148
-
149
- /** Apply a single JSON Patch operation (mutates `obj` in place). */
150
- export function applyOperation(
151
- obj: unknown,
152
- operation: JsonPatchOperation,
153
- ): void {
154
- switch (operation.op) {
155
- case "add":
156
- setValueAtPath(obj, operation.path, operation.value);
157
- break;
158
- case "remove":
159
- removeValueAtPath(obj, operation.path);
160
- break;
161
- case "replace":
162
- // For replace, the path must exist
163
- getValueAtPath(obj, operation.path); // throws if doesn't exist
164
- setValueAtPath(obj, operation.path, operation.value);
165
- break;
166
- case "move": {
167
- if (!operation.from) throw new Error("move operation requires 'from'");
168
- const moveValue = getValueAtPath(obj, operation.from);
169
- if (moveValue === undefined) {
170
- throw new Error(
171
- `Cannot move from path ${operation.from}: not an object`,
172
- );
173
- }
174
- removeValueAtPath(obj, operation.from);
175
- setValueAtPath(obj, operation.path, moveValue);
176
- break;
177
- }
178
- case "copy": {
179
- if (!operation.from) throw new Error("copy operation requires 'from'");
180
- const copyValue = getValueAtPath(obj, operation.from);
181
- setValueAtPath(
182
- obj,
183
- operation.path,
184
- JSON.parse(JSON.stringify(copyValue)),
185
- );
186
- break;
187
- }
188
- case "test": {
189
- const testValue = getValueAtPath(obj, operation.path);
190
- if (JSON.stringify(testValue) !== JSON.stringify(operation.value)) {
191
- throw new Error(
192
- `Test operation failed at ${operation.path}: expected ${JSON.stringify(operation.value)}, got ${JSON.stringify(testValue)}`,
193
- );
194
- }
195
- break;
196
- }
197
- default:
198
- throw new Error(`Unknown operation: ${(operation as { op: string }).op}`);
199
- }
200
- }
201
-
202
- /** Apply a JSON Patch to an object (mutates in place). */
203
- export function applyPatch(obj: unknown, patch: JsonPatch): void {
204
- for (const operation of patch) {
205
- applyOperation(obj, operation);
206
- }
207
- }
208
-
209
- /**
210
- * Whether a per-operation failure is caused by the target location being
211
- * absent from the spec (i.e. spec drift — the operation/shape the patch
212
- * targets was renamed or removed upstream) as opposed to a malformed patch.
213
- * Stale targets should be skipped with a warning rather than aborting the
214
- * whole generate; a patch that only adds an error to an operation that no
215
- * longer exists is harmless to drop.
216
- */
217
- export function isStaleTargetError(message: string): boolean {
218
- return (
219
- message.includes("not an object") ||
220
- message.includes("parent is not an object")
221
- );
222
- }