@distilled.cloud/core 1.0.0-rc.14 → 1.0.0-rc.16

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 (312) hide show
  1. package/lib/api.d.ts +118 -13
  2. package/lib/api.d.ts.map +1 -1
  3. package/lib/api.js +755 -147
  4. package/lib/api.js.map +1 -1
  5. package/lib/category.d.ts.map +1 -1
  6. package/lib/category.js +146 -146
  7. package/lib/category.js.map +1 -1
  8. package/lib/chunks.d.ts +3 -0
  9. package/lib/chunks.d.ts.map +1 -0
  10. package/lib/chunks.js +11 -0
  11. package/lib/chunks.js.map +1 -0
  12. package/lib/codegen/boolean-string-enums.js +36 -36
  13. package/lib/codegen/chunk.d.ts +7 -0
  14. package/lib/codegen/chunk.d.ts.map +1 -0
  15. package/lib/codegen/chunk.js +139 -0
  16. package/lib/codegen/chunk.js.map +1 -0
  17. package/lib/codegen/cli.d.ts.map +1 -1
  18. package/lib/codegen/cli.js +28 -14
  19. package/lib/codegen/cli.js.map +1 -1
  20. package/lib/codegen/datafy.d.ts +14 -0
  21. package/lib/codegen/datafy.d.ts.map +1 -0
  22. package/lib/codegen/datafy.js +853 -0
  23. package/lib/codegen/datafy.js.map +1 -0
  24. package/lib/codegen/dedupe.d.ts +5 -0
  25. package/lib/codegen/dedupe.d.ts.map +1 -0
  26. package/lib/codegen/dedupe.js +153 -0
  27. package/lib/codegen/dedupe.js.map +1 -0
  28. package/lib/codegen/emit.js +56 -56
  29. package/lib/codegen/format.js +18 -18
  30. package/lib/codegen/generated-at.js +29 -29
  31. package/lib/codegen/generator.d.ts.map +1 -1
  32. package/lib/codegen/generator.js +92 -84
  33. package/lib/codegen/generator.js.map +1 -1
  34. package/lib/codegen/graph.js +36 -36
  35. package/lib/codegen/graphql-client.d.ts +2 -0
  36. package/lib/codegen/graphql-client.d.ts.map +1 -1
  37. package/lib/codegen/graphql-client.js +55 -26
  38. package/lib/codegen/graphql-client.js.map +1 -1
  39. package/lib/codegen/graphql.js +113 -113
  40. package/lib/codegen/latin1.d.ts +3 -0
  41. package/lib/codegen/latin1.d.ts.map +1 -0
  42. package/lib/codegen/latin1.js +126 -0
  43. package/lib/codegen/latin1.js.map +1 -0
  44. package/lib/codegen/members.d.ts +7 -0
  45. package/lib/codegen/members.d.ts.map +1 -1
  46. package/lib/codegen/members.js +26 -19
  47. package/lib/codegen/members.js.map +1 -1
  48. package/lib/codegen/model-diff.js +6 -6
  49. package/lib/codegen/naming.js +19 -19
  50. package/lib/codegen/openapi-cli.js +15 -15
  51. package/lib/codegen/openapi.d.ts +17 -0
  52. package/lib/codegen/openapi.d.ts.map +1 -1
  53. package/lib/codegen/openapi.js +323 -169
  54. package/lib/codegen/openapi.js.map +1 -1
  55. package/lib/codegen/operations.js +14 -14
  56. package/lib/codegen/pagination.js +11 -11
  57. package/lib/codegen/patch-audit.js +57 -57
  58. package/lib/codegen/patches.js +79 -79
  59. package/lib/codegen/prelude.js +19 -19
  60. package/lib/codegen/privatize.d.ts +21 -0
  61. package/lib/codegen/privatize.d.ts.map +1 -0
  62. package/lib/codegen/privatize.js +176 -0
  63. package/lib/codegen/privatize.js.map +1 -0
  64. package/lib/codegen/proto.js +25 -25
  65. package/lib/codegen/pure.d.ts +6 -0
  66. package/lib/codegen/pure.d.ts.map +1 -0
  67. package/lib/codegen/pure.js +91 -0
  68. package/lib/codegen/pure.js.map +1 -0
  69. package/lib/codegen/rewrite-operation-ids.js +108 -108
  70. package/lib/codegen/spec-path.js +57 -57
  71. package/lib/codegen/table.d.ts +5 -0
  72. package/lib/codegen/table.d.ts.map +1 -0
  73. package/lib/codegen/table.js +249 -0
  74. package/lib/codegen/table.js.map +1 -0
  75. package/lib/config.d.ts +27 -0
  76. package/lib/config.d.ts.map +1 -0
  77. package/lib/config.js +161 -0
  78. package/lib/config.js.map +1 -0
  79. package/lib/crypto.d.ts +76 -0
  80. package/lib/crypto.d.ts.map +1 -0
  81. package/lib/crypto.js +130 -0
  82. package/lib/crypto.js.map +1 -0
  83. package/lib/debug.d.ts +2 -0
  84. package/lib/debug.d.ts.map +1 -0
  85. package/lib/debug.js +8 -0
  86. package/lib/debug.js.map +1 -0
  87. package/lib/error-category.d.ts +1 -1
  88. package/lib/error-category.d.ts.map +1 -1
  89. package/lib/error-category.js +7 -6
  90. package/lib/error-category.js.map +1 -1
  91. package/lib/errors.d.ts +62 -62
  92. package/lib/errors.d.ts.map +1 -1
  93. package/lib/errors.js +117 -114
  94. package/lib/errors.js.map +1 -1
  95. package/lib/graphql.d.ts +31 -20
  96. package/lib/graphql.d.ts.map +1 -1
  97. package/lib/graphql.js +150 -119
  98. package/lib/graphql.js.map +1 -1
  99. package/lib/graphql.types.js +4 -3
  100. package/lib/graphql.types.js.map +1 -1
  101. package/lib/index.d.ts +3 -2
  102. package/lib/index.d.ts.map +1 -1
  103. package/lib/index.js +15 -14
  104. package/lib/index.js.map +1 -1
  105. package/lib/json-patch.d.ts +2 -2
  106. package/lib/json-patch.js +28 -28
  107. package/lib/pagination.d.ts +9 -25
  108. package/lib/pagination.d.ts.map +1 -1
  109. package/lib/pagination.js +95 -90
  110. package/lib/pagination.js.map +1 -1
  111. package/lib/plain-values.d.ts +10 -0
  112. package/lib/plain-values.d.ts.map +1 -0
  113. package/lib/plain-values.js +40 -0
  114. package/lib/plain-values.js.map +1 -0
  115. package/lib/protocol-http.d.ts +50 -14
  116. package/lib/protocol-http.d.ts.map +1 -1
  117. package/lib/protocol-http.js +351 -178
  118. package/lib/protocol-http.js.map +1 -1
  119. package/lib/protocol-rest.d.ts +38 -25
  120. package/lib/protocol-rest.d.ts.map +1 -1
  121. package/lib/protocol-rest.js +238 -130
  122. package/lib/protocol-rest.js.map +1 -1
  123. package/lib/query.js +16 -16
  124. package/lib/response-validation-strict.d.ts +48 -0
  125. package/lib/response-validation-strict.d.ts.map +1 -0
  126. package/lib/response-validation-strict.js +284 -0
  127. package/lib/response-validation-strict.js.map +1 -0
  128. package/lib/response-validation.d.ts +43 -25
  129. package/lib/response-validation.d.ts.map +1 -1
  130. package/lib/response-validation.js +112 -70
  131. package/lib/response-validation.js.map +1 -1
  132. package/lib/retry-after.d.ts +3 -3
  133. package/lib/retry-after.js +49 -49
  134. package/lib/retry.d.ts +48 -29
  135. package/lib/retry.d.ts.map +1 -1
  136. package/lib/retry.js +142 -154
  137. package/lib/retry.js.map +1 -1
  138. package/lib/schema-lite-impl.d.ts +158 -0
  139. package/lib/schema-lite-impl.d.ts.map +1 -0
  140. package/lib/schema-lite-impl.js +341 -0
  141. package/lib/schema-lite-impl.js.map +1 -0
  142. package/lib/schema-lite-typed.d.ts +41 -0
  143. package/lib/schema-lite-typed.d.ts.map +1 -0
  144. package/lib/schema-lite-typed.js +27 -0
  145. package/lib/schema-lite-typed.js.map +1 -0
  146. package/lib/schema-lite.d.ts +40 -0
  147. package/lib/schema-lite.d.ts.map +1 -0
  148. package/lib/schema-lite.js +31 -0
  149. package/lib/schema-lite.js.map +1 -0
  150. package/lib/schema.d.ts +20 -6
  151. package/lib/schema.d.ts.map +1 -1
  152. package/lib/schema.js +202 -30
  153. package/lib/schema.js.map +1 -1
  154. package/lib/testing.d.ts +3 -2
  155. package/lib/testing.d.ts.map +1 -1
  156. package/lib/testing.js +22 -21
  157. package/lib/testing.js.map +1 -1
  158. package/lib/trait.d.ts +13 -13
  159. package/lib/trait.d.ts.map +1 -1
  160. package/lib/trait.js +80 -80
  161. package/lib/trait.js.map +1 -1
  162. package/lib/xml.d.ts +1 -1
  163. package/lib/xml.d.ts.map +1 -1
  164. package/lib/xml.js +38 -26
  165. package/lib/xml.js.map +1 -1
  166. package/package.json +9 -7
  167. package/src/api.ts +1079 -180
  168. package/src/category.ts +33 -33
  169. package/src/chunks.ts +30 -0
  170. package/src/codegen/chunk.ts +147 -0
  171. package/src/codegen/cli.ts +27 -1
  172. package/src/codegen/datafy.ts +874 -0
  173. package/src/codegen/dedupe.ts +173 -0
  174. package/src/codegen/generator.ts +10 -3
  175. package/src/codegen/graphql-client.ts +49 -15
  176. package/src/codegen/latin1.ts +131 -0
  177. package/src/codegen/members.ts +8 -0
  178. package/src/codegen/openapi.ts +194 -3
  179. package/src/codegen/privatize.ts +200 -0
  180. package/src/codegen/pure.ts +94 -0
  181. package/src/codegen/table.ts +254 -0
  182. package/src/config.ts +216 -0
  183. package/src/crypto.ts +202 -0
  184. package/src/debug.ts +8 -0
  185. package/src/error-category.ts +2 -1
  186. package/src/errors.ts +65 -56
  187. package/src/graphql.ts +109 -62
  188. package/src/graphql.types.ts +9 -7
  189. package/src/index.ts +3 -2
  190. package/src/json-patch.ts +2 -2
  191. package/src/pagination.ts +37 -18
  192. package/src/plain-values.ts +41 -0
  193. package/src/protocol-http.ts +378 -145
  194. package/src/protocol-rest.ts +337 -169
  195. package/src/response-validation-strict.ts +327 -0
  196. package/src/response-validation.ts +101 -50
  197. package/src/retry-after.ts +3 -3
  198. package/src/retry.ts +94 -93
  199. package/src/schema-lite-impl.ts +550 -0
  200. package/src/schema-lite-typed.ts +44 -0
  201. package/src/schema-lite.ts +44 -0
  202. package/src/schema.ts +258 -14
  203. package/src/testing.ts +4 -2
  204. package/src/trait.ts +36 -28
  205. package/src/xml.ts +31 -17
  206. package/lib/codegen/boolean-string-enums.test.d.ts +0 -2
  207. package/lib/codegen/boolean-string-enums.test.d.ts.map +0 -1
  208. package/lib/codegen/boolean-string-enums.test.js +0 -275
  209. package/lib/codegen/boolean-string-enums.test.js.map +0 -1
  210. package/lib/codegen/defer-naming.test.d.ts +0 -2
  211. package/lib/codegen/defer-naming.test.d.ts.map +0 -1
  212. package/lib/codegen/defer-naming.test.js +0 -105
  213. package/lib/codegen/defer-naming.test.js.map +0 -1
  214. package/lib/codegen/generated-at.test.d.ts +0 -2
  215. package/lib/codegen/generated-at.test.d.ts.map +0 -1
  216. package/lib/codegen/generated-at.test.js +0 -81
  217. package/lib/codegen/generated-at.test.js.map +0 -1
  218. package/lib/codegen/generator.test.d.ts +0 -2
  219. package/lib/codegen/generator.test.d.ts.map +0 -1
  220. package/lib/codegen/generator.test.js +0 -121
  221. package/lib/codegen/generator.test.js.map +0 -1
  222. package/lib/codegen/graphql-client.test.d.ts +0 -2
  223. package/lib/codegen/graphql-client.test.d.ts.map +0 -1
  224. package/lib/codegen/graphql-client.test.js +0 -171
  225. package/lib/codegen/graphql-client.test.js.map +0 -1
  226. package/lib/codegen/openapi-binary.test.d.ts +0 -2
  227. package/lib/codegen/openapi-binary.test.d.ts.map +0 -1
  228. package/lib/codegen/openapi-binary.test.js +0 -67
  229. package/lib/codegen/openapi-binary.test.js.map +0 -1
  230. package/lib/codegen/patch-audit.test.d.ts +0 -2
  231. package/lib/codegen/patch-audit.test.d.ts.map +0 -1
  232. package/lib/codegen/patch-audit.test.js +0 -141
  233. package/lib/codegen/patch-audit.test.js.map +0 -1
  234. package/lib/codegen/patches.test.d.ts +0 -2
  235. package/lib/codegen/patches.test.d.ts.map +0 -1
  236. package/lib/codegen/patches.test.js +0 -155
  237. package/lib/codegen/patches.test.js.map +0 -1
  238. package/lib/codegen/protocol-imports.test.d.ts +0 -2
  239. package/lib/codegen/protocol-imports.test.d.ts.map +0 -1
  240. package/lib/codegen/protocol-imports.test.js +0 -36
  241. package/lib/codegen/protocol-imports.test.js.map +0 -1
  242. package/lib/codegen/rewrite-operation-ids.test.d.ts +0 -2
  243. package/lib/codegen/rewrite-operation-ids.test.d.ts.map +0 -1
  244. package/lib/codegen/rewrite-operation-ids.test.js +0 -451
  245. package/lib/codegen/rewrite-operation-ids.test.js.map +0 -1
  246. package/lib/codegen/untagged-unions.test.d.ts +0 -2
  247. package/lib/codegen/untagged-unions.test.d.ts.map +0 -1
  248. package/lib/codegen/untagged-unions.test.js +0 -80
  249. package/lib/codegen/untagged-unions.test.js.map +0 -1
  250. package/lib/fixtures/xml/upstream-validator.json +0 -397
  251. package/lib/graphql.test.d.ts +0 -2
  252. package/lib/graphql.test.d.ts.map +0 -1
  253. package/lib/graphql.test.js +0 -151
  254. package/lib/graphql.test.js.map +0 -1
  255. package/lib/json-patch.test.d.ts +0 -2
  256. package/lib/json-patch.test.d.ts.map +0 -1
  257. package/lib/json-patch.test.js +0 -65
  258. package/lib/json-patch.test.js.map +0 -1
  259. package/lib/pagination.test.d.ts +0 -2
  260. package/lib/pagination.test.d.ts.map +0 -1
  261. package/lib/pagination.test.js +0 -131
  262. package/lib/pagination.test.js.map +0 -1
  263. package/lib/protocol-http.test.d.ts +0 -2
  264. package/lib/protocol-http.test.d.ts.map +0 -1
  265. package/lib/protocol-http.test.js +0 -228
  266. package/lib/protocol-http.test.js.map +0 -1
  267. package/lib/protocol-rest.test.d.ts +0 -2
  268. package/lib/protocol-rest.test.d.ts.map +0 -1
  269. package/lib/protocol-rest.test.js +0 -498
  270. package/lib/protocol-rest.test.js.map +0 -1
  271. package/lib/response-validation.test.d.ts +0 -2
  272. package/lib/response-validation.test.d.ts.map +0 -1
  273. package/lib/response-validation.test.js +0 -72
  274. package/lib/response-validation.test.js.map +0 -1
  275. package/lib/retry-after.test.d.ts +0 -2
  276. package/lib/retry-after.test.d.ts.map +0 -1
  277. package/lib/retry-after.test.js +0 -204
  278. package/lib/retry-after.test.js.map +0 -1
  279. package/lib/retry.test.d.ts +0 -2
  280. package/lib/retry.test.d.ts.map +0 -1
  281. package/lib/retry.test.js +0 -407
  282. package/lib/retry.test.js.map +0 -1
  283. package/lib/sdks.test.d.ts +0 -2
  284. package/lib/sdks.test.d.ts.map +0 -1
  285. package/lib/sdks.test.js +0 -76
  286. package/lib/sdks.test.js.map +0 -1
  287. package/lib/xml.test.d.ts +0 -2
  288. package/lib/xml.test.d.ts.map +0 -1
  289. package/lib/xml.test.js +0 -210
  290. package/lib/xml.test.js.map +0 -1
  291. package/src/codegen/boolean-string-enums.test.ts +0 -299
  292. package/src/codegen/defer-naming.test.ts +0 -113
  293. package/src/codegen/generated-at.test.ts +0 -89
  294. package/src/codegen/generator.test.ts +0 -137
  295. package/src/codegen/graphql-client.test.ts +0 -189
  296. package/src/codegen/openapi-binary.test.ts +0 -91
  297. package/src/codegen/patch-audit.test.ts +0 -160
  298. package/src/codegen/patches.test.ts +0 -188
  299. package/src/codegen/protocol-imports.test.ts +0 -39
  300. package/src/codegen/rewrite-operation-ids.test.ts +0 -472
  301. package/src/codegen/untagged-unions.test.ts +0 -85
  302. package/src/fixtures/xml/upstream-validator.json +0 -397
  303. package/src/graphql.test.ts +0 -198
  304. package/src/json-patch.test.ts +0 -77
  305. package/src/pagination.test.ts +0 -169
  306. package/src/protocol-http.test.ts +0 -276
  307. package/src/protocol-rest.test.ts +0 -703
  308. package/src/response-validation.test.ts +0 -89
  309. package/src/retry-after.test.ts +0 -267
  310. package/src/retry.test.ts +0 -566
  311. package/src/sdks.test.ts +0 -87
  312. package/src/xml.test.ts +0 -251
@@ -1,189 +0,0 @@
1
- import { stripTypeScriptTypes } from "node:module";
2
- import { describe, expect, test } from "vitest";
3
- import { applyOperation } from "../json-patch.ts";
4
- import {
5
- convertGraphQLClient,
6
- generateGraphQLClient,
7
- graphqlTypeString,
8
- validateGraphQLModel,
9
- } from "./graphql-client.ts";
10
-
11
- const named = (name: string, kind = "OBJECT") => ({ kind, name });
12
- const required = (ofType: object) => ({ kind: "NON_NULL", ofType });
13
- const field = (name: string, type: object, args: object[] = []) => ({
14
- name,
15
- type,
16
- args,
17
- });
18
-
19
- const fixture = {
20
- queryType: { name: "Query" },
21
- mutationType: { name: "Mutation" },
22
- types: [
23
- { kind: "SCALAR", name: "String" },
24
- { kind: "SCALAR", name: "Int" },
25
- {
26
- kind: "OBJECT",
27
- name: "Query",
28
- fields: [
29
- field("project", required(named("Project")), [
30
- { name: "id", type: required(named("String", "SCALAR")) },
31
- ]),
32
- field("me", required(named("User"))),
33
- field("projects", required(named("ProjectConnection")), [
34
- {
35
- name: "first",
36
- type: named("Int", "SCALAR"),
37
- },
38
- ]),
39
- ],
40
- },
41
- {
42
- kind: "OBJECT",
43
- name: "Mutation",
44
- fields: [
45
- field("projectCreate", named("Project"), [
46
- { name: "name", type: required(named("String", "SCALAR")) },
47
- ]),
48
- ],
49
- },
50
- {
51
- kind: "OBJECT",
52
- name: "Project",
53
- fields: [
54
- field("id", required(named("String", "SCALAR"))),
55
- field("name", required(named("String", "SCALAR"))),
56
- ],
57
- },
58
- {
59
- kind: "OBJECT",
60
- name: "User",
61
- fields: [
62
- field("email", required(named("String", "SCALAR"))),
63
- field("name", named("String", "SCALAR")),
64
- field("projects", required(named("ProjectConnection")), [
65
- { name: "first", type: named("Int", "SCALAR") },
66
- ]),
67
- ],
68
- },
69
- {
70
- kind: "OBJECT",
71
- name: "ProjectConnection",
72
- fields: [
73
- field("edges", required({ kind: "LIST", ofType: named("ProjectEdge") })),
74
- field("pageInfo", required(named("PageInfo"))),
75
- ],
76
- },
77
- {
78
- kind: "OBJECT",
79
- name: "ProjectEdge",
80
- fields: [
81
- field("cursor", required(named("String", "SCALAR"))),
82
- field("node", required(named("Project"))),
83
- ],
84
- },
85
- {
86
- kind: "OBJECT",
87
- name: "PageInfo",
88
- fields: [
89
- field("endCursor", named("String", "SCALAR")),
90
- field("hasNextPage", required(named("Boolean", "SCALAR"))),
91
- ],
92
- },
93
- { kind: "SCALAR", name: "Boolean" },
94
- ],
95
- };
96
-
97
- const options = {
98
- transportImport: "./transport.ts",
99
- requirementsImport: "./transport.ts",
100
- requirementsType: "Requirements",
101
- sdkName: "Railway",
102
- };
103
-
104
- describe("GraphQL Query SDK generator", () => {
105
- test("emits TypeMeta, interfaces, and named roots on the SDK object", () => {
106
- const model = convertGraphQLClient(fixture);
107
- const output = generateGraphQLClient(model, options);
108
- expect(output).toContain("export interface Project");
109
- expect(output).toContain("export interface User");
110
- expect(output).toContain('export const Project: TypeMeta = { name: "Project", fields: {} };');
111
- expect(output).toContain("export const Railway = {");
112
- expect(output).toContain('root("query", "me", User, undefined, undefined, globalErrors)');
113
- expect(output).toContain('root("query", "project", Project');
114
- expect(output).toContain('rootConnection("query", "projects", Project');
115
- expect(output).toContain("Query<ReadonlyArray<Project>, RailwayGlobalError>");
116
- expect(output).toContain('connectionField("projects", Project, { first: "Int" })');
117
- expect(output).toContain('root("mutation", "projectCreate", Project');
118
- // Nullable GraphQL types include null; non-null ones do not.
119
- expect(output).toContain("readonly name: string | null;");
120
- expect(output).toContain("readonly email: string;");
121
- expect(output).toContain("Query<Project | null, RailwayGlobalError>");
122
- expect(output).toContain("args?: { readonly first?: number | null }");
123
- expect(output).toContain('from "@distilled.cloud/core/graphql"');
124
- expect(() => stripTypeScriptTypes(output)).not.toThrow();
125
- });
126
-
127
- test("emits error classes and scopes them to roots", () => {
128
- const model = convertGraphQLClient(fixture);
129
- for (const operation of [
130
- {
131
- op: "add" as const,
132
- path: "/errors/RailwayNotFound",
133
- value: {
134
- description: "Missing.",
135
- category: "notFound",
136
- matchers: [{ code: "NOT_FOUND" }],
137
- },
138
- },
139
- {
140
- op: "add" as const,
141
- path: "/errors/RailwayRateLimited",
142
- value: {
143
- category: "throttling",
144
- retryable: true,
145
- matchers: [{ code: "RATE_LIMITED" }],
146
- },
147
- },
148
- {
149
- op: "add" as const,
150
- path: "/globalErrors/-",
151
- value: "RailwayRateLimited",
152
- },
153
- {
154
- op: "add" as const,
155
- path: "/types/Query/fields/project/errors/-",
156
- value: "RailwayNotFound",
157
- },
158
- ])
159
- applyOperation(model, operation);
160
- const output = generateGraphQLClient(model, options);
161
- expect(output).toContain(
162
- 'export class RailwayNotFound extends S.TaggedError<RailwayNotFound>()("RailwayNotFound", errorFields).pipe(Category.withNotFoundError) {}',
163
- );
164
- expect(output).toContain(
165
- "Category.withThrottlingError, Category.withRetryable({ throttling: true })",
166
- );
167
- expect(output).toContain(
168
- 'errorSpec(RailwayRateLimited, "RailwayRateLimited", [{"code":"RATE_LIMITED"}], { retryable: true, global: true })',
169
- );
170
- expect(output).toContain("export type RailwayGlobalError = RailwayRateLimited;");
171
- expect(output).toContain("Query<Project, RailwayNotFound | RailwayGlobalError>");
172
- expect(output).toContain("[RailwayNotFoundSpec, ...globalErrors]");
173
- expect(output).toContain("Query<User, RailwayGlobalError>");
174
- expect(() => stripTypeScriptTypes(output)).not.toThrow();
175
- });
176
-
177
- test("unknown coordinates fail validateGraphQLModel", () => {
178
- const model = convertGraphQLClient(fixture);
179
- applyOperation(model, {
180
- op: "add",
181
- path: "/types/Project/fields/id/errors/-",
182
- value: "MissingError",
183
- });
184
- expect(() => validateGraphQLModel(model)).toThrow(
185
- "Project.id: unknown GraphQL error MissingError",
186
- );
187
- expect(() => graphqlTypeString({ kind: "NON_NULL" })).toThrow("Incomplete GraphQL NON_NULL");
188
- });
189
- });
@@ -1,91 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { convertOpenApiToSmithy } from "./openapi.ts";
3
-
4
- const model = (
5
- schema: unknown,
6
- mediaType = "multipart/form-data",
7
- responseSchema: unknown = { type: "string", format: "binary" },
8
- components: Record<string, unknown> = {},
9
- options: { binaryTypes?: boolean } = { binaryTypes: true },
10
- ) =>
11
- convertOpenApiToSmithy(
12
- {
13
- openapi: "3.0.3",
14
- info: { title: "Binary", version: "1" },
15
- components,
16
- paths: {
17
- "/files": {
18
- post: {
19
- operationId: "uploadFile",
20
- requestBody: { content: { [mediaType]: { schema } } },
21
- responses: {
22
- "200": {
23
- content: {
24
- "application/octet-stream": {
25
- schema: responseSchema,
26
- },
27
- },
28
- },
29
- },
30
- },
31
- },
32
- },
33
- },
34
- { namespace: "com.example.binary", serviceName: "Binary", ...options },
35
- );
36
-
37
- describe("OpenAPI binary contracts", () => {
38
- for (const options of [{}, { binaryTypes: false }]) {
39
- test(`binary conversion preserves existing contracts with ${JSON.stringify(options)}`, () => {
40
- const result = model(
41
- {
42
- type: "object",
43
- properties: {
44
- zip: { type: "string", format: "binary" },
45
- archive: { $ref: "#/components/schemas/Archive" },
46
- },
47
- },
48
- "multipart/form-data",
49
- { $ref: "#/components/schemas/Archive" },
50
- { schemas: { Archive: { type: "string", format: "binary" } } },
51
- options,
52
- );
53
- const request = result.shapes["com.example.binary#UploadFileRequest"];
54
- expect(request.members.zip.target).toBe("smithy.api#String");
55
- expect(request.members.archive.target).toBe("smithy.api#String");
56
- expect(result.shapes["com.example.binary#UploadFile"].output.target).toBe("smithy.api#Unit");
57
- expect(result.shapes["com.example.binary#UploadFileResponse"]).toBeUndefined();
58
- });
59
- }
60
-
61
- test("component-referenced binary responses retain the original reference's nullability", () => {
62
- const result = model(
63
- { type: "object" },
64
- "application/json",
65
- { $ref: "#/components/schemas/Archive", nullable: true },
66
- { schemas: { Archive: { type: "string", format: "binary" } } },
67
- );
68
- const body = result.shapes["com.example.binary#UploadFileResponse"].members.body;
69
- expect(body.target).toBe("smithy.api#Blob");
70
- expect(body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
71
- expect(body.traits["com.distilled.openapi#nullable"]).toEqual({});
72
- });
73
-
74
- test("multipart binary fields become blobs, not text or base64", () => {
75
- const result = model({
76
- type: "object",
77
- properties: {
78
- zip: { type: "string", format: "binary" },
79
- encoded: { type: "string", format: "byte" },
80
- environment: { type: "string" },
81
- },
82
- });
83
- const request = result.shapes["com.example.binary#UploadFileRequest"];
84
- expect(request.members.zip.target).toBe("smithy.api#Blob");
85
- expect(request.members.encoded.target).toBe("smithy.api#String");
86
- expect(request.members.environment.target).toBe("smithy.api#String");
87
- const response = result.shapes["com.example.binary#UploadFileResponse"];
88
- expect(response.members.body.target).toBe("smithy.api#Blob");
89
- expect(response.members.body.traits["com.distilled.openapi#rawResponse"]).toEqual({});
90
- });
91
- });
@@ -1,160 +0,0 @@
1
- import {
2
- existsSync,
3
- mkdirSync,
4
- mkdtempSync,
5
- readdirSync,
6
- readFileSync,
7
- rmSync,
8
- writeFileSync,
9
- } from "node:fs";
10
- import { tmpdir } from "node:os";
11
- import { join } from "node:path";
12
- import { afterEach, describe, expect, test } from "vitest";
13
- import { auditPackage } from "./patch-audit.ts";
14
-
15
- const dirs: string[] = [];
16
- afterEach(() => {
17
- for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
18
- });
19
-
20
- // ---------------------------------------------------------------------------
21
-
22
- const PATCHES_TS = join(import.meta.dirname, "patches.ts");
23
-
24
- /**
25
- * A package: `spec.json` lists field names, and every field becomes a
26
- * member of `x#Thing`. `patches/spec/` edit the spec in the convert script
27
- * itself (the way Railway patches its GraphQL schema, out of
28
- * finalizeConvert's reach); `patches/svc/` are Smithy ops applied in
29
- * finalizeConvert, whose transform drops a member named `dropped`.
30
- */
31
- const convertFixture = (patches: Record<string, unknown[]>): string => {
32
- const parent = mkdtempSync(join(tmpdir(), "patch-audit-convert-"));
33
- dirs.push(parent);
34
- const root = join(parent, "pkg");
35
- mkdirSync(join(root, "scripts"), { recursive: true });
36
- writeFileSync(
37
- join(root, "package.json"),
38
- JSON.stringify({ name: "fixture", scripts: { convert: "node scripts/convert.ts" } }),
39
- );
40
- writeFileSync(join(root, "spec.json"), JSON.stringify({ fields: { a: true } }));
41
- writeFileSync(
42
- join(root, "scripts", "convert.ts"),
43
- `
44
- import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
45
- import { join } from "node:path";
46
- import { applyRfc6902Files, finalizeConvert, isSmithyPatchPath, listRfc6902PatchFiles } from ${JSON.stringify(PATCHES_TS)};
47
- const root = join(import.meta.dirname, "..");
48
- const spec = JSON.parse(readFileSync(join(root, "spec.json"), "utf8"));
49
- const files = await listRfc6902PatchFiles(join(root, "patches", "spec"));
50
- const applied = await applyRfc6902Files(spec, files, { include: (op) => !isSmithyPatchPath(op.path) });
51
- if (applied.errors.length) throw new Error(applied.errors.join("\\n"));
52
- const members = Object.fromEntries(Object.keys(spec.fields).map((k) => [k, { target: "smithy.api#String" }]));
53
- mkdirSync(join(root, ".generated-specs"), { recursive: true });
54
- writeFileSync(join(root, ".generated-specs", "svc.json"), JSON.stringify({ smithy: "2.0", shapes: { "x#Thing": { type: "structure", members } } }));
55
- await finalizeConvert({
56
- root,
57
- operationNaming: "as-is",
58
- transform: (model) => { delete model.shapes["x#Thing"].members.dropped; },
59
- });
60
- `,
61
- );
62
- for (const [key, ops] of Object.entries(patches)) {
63
- const dir = key.startsWith("spec/") ? "spec" : "svc";
64
- mkdirSync(join(root, "patches", dir), { recursive: true });
65
- const name = key.replace(/^spec\//, "");
66
- writeFileSync(join(root, "patches", dir, name), JSON.stringify({ patches: ops }));
67
- }
68
- mkdirSync(join(root, ".generated-specs"));
69
- writeFileSync(join(root, ".generated-specs", "svc.json"), "committed\n");
70
- return root;
71
- };
72
-
73
- const addField = (name: string) => ({ op: "add", path: `/fields/${name}`, value: true });
74
- const addMember = (name: string) => ({
75
- op: "add",
76
- path: `/shapes/x#Thing/members/${name}`,
77
- value: { target: "smithy.api#String" },
78
- });
79
-
80
- describe("convert-stage patch audit", () => {
81
- test("judges Smithy files in memory and the rest by convert", async () => {
82
- const root = convertFixture({
83
- "spec/1-spec.json": [addField("s")],
84
- "2-member.json": [addMember("b")],
85
- "3-noop.json": [{ op: "replace", path: "/shapes/x#Thing/type", value: "structure" }],
86
- "4-dropped.json": [addMember("dropped")],
87
- "5-uses-b.json": [{ op: "add", path: "/shapes/x#Thing/members/b/traits", value: {} }],
88
- });
89
- const result = await auditPackage(root, { jobs: 2 });
90
- if (result.kind !== "audited") throw new Error(result.reason);
91
- expect(Object.fromEntries(result.files.map((f) => [f.file.key, f.verdict]))).toEqual({
92
- "spec/1-spec.json": { kind: "needed", diff: ["+ Thing/members/s"] },
93
- "svc/2-member.json": { kind: "depended", error: expect.stringMatching(/members\/b/) },
94
- "svc/3-noop.json": { kind: "unused" },
95
- // The transform removes it again, so it changes nothing.
96
- "svc/4-dropped.json": { kind: "unused" },
97
- "svc/5-uses-b.json": { kind: "needed", diff: ["+ Thing/members/b/traits"] },
98
- });
99
- expect(result.judged).toEqual({ inMemory: 4, perFile: 1 });
100
- });
101
-
102
- test("--ops in memory finds the dead op", async () => {
103
- const root = convertFixture({
104
- "mixed.json": [
105
- addMember("b"),
106
- { op: "replace", path: "/shapes/x#Thing/type", value: "structure" },
107
- ],
108
- });
109
- const result = await auditPackage(root, { ops: true, jobs: 1 });
110
- if (result.kind !== "audited") throw new Error(result.reason);
111
- expect(result.files[0]!.deadOps).toEqual([1]);
112
- });
113
-
114
- test("a file that only orders keys is needed", async () => {
115
- const root = convertFixture({
116
- "1-member.json": [addMember("b")],
117
- "2-order.json": [
118
- {
119
- op: "move",
120
- from: "/shapes/x#Thing/members/b",
121
- path: "/shapes/x#Thing/members/b",
122
- before: "a",
123
- },
124
- ],
125
- });
126
- const result = await auditPackage(root, { jobs: 1 });
127
- if (result.kind !== "audited") throw new Error(result.reason);
128
- expect(result.files.find((f) => f.file.key === "svc/2-order.json")!.verdict).toEqual({
129
- kind: "needed",
130
- diff: ["(key order only)"],
131
- });
132
- });
133
-
134
- test("leaves the package as it was and removes its scratch copies", async () => {
135
- const root = convertFixture({
136
- "member.json": [addMember("b")],
137
- "spec/s.json": [addField("s")],
138
- });
139
- const result = await auditPackage(root, { jobs: 2 });
140
- expect(result.kind).toBe("audited");
141
- expect(readFileSync(join(root, ".generated-specs", "svc.json"), "utf8")).toBe("committed\n");
142
- expect(readdirSync(join(root, ".."))).toEqual(["pkg"]);
143
- expect(existsSync(join(root, ".audit-request.json"))).toBe(false);
144
- });
145
-
146
- test("a patch that changes nothing has no effect", async () => {
147
- const root = convertFixture({
148
- "noop.json": [{ op: "replace", path: "/shapes/x#Thing/type", value: "structure" }],
149
- });
150
- const result = await auditPackage(root, { jobs: 1 });
151
- if (result.kind !== "audited") throw new Error(result.reason);
152
- expect(result.files[0]!.verdict).toEqual({ kind: "unused" });
153
- });
154
-
155
- test("a baseline that fails to convert is skipped", async () => {
156
- const root = convertFixture({ "stale.json": [{ op: "remove", path: "/shapes/x#Gone" }] });
157
- const result = await auditPackage(root, { jobs: 1 });
158
- expect(result.kind).toBe("skipped");
159
- });
160
- });
@@ -1,188 +0,0 @@
1
- import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { afterEach, describe, expect, test } from "vitest";
5
- import {
6
- FINALIZED_KEY,
7
- SKIP_PATCHES_ENV,
8
- applyRfc6902Files,
9
- danglingTargets,
10
- finalizeConvert,
11
- listRfc6902PatchFiles,
12
- syncServiceOperations,
13
- } from "./patches.ts";
14
-
15
- const model = () => ({
16
- smithy: "2.0",
17
- shapes: {
18
- "ns#Svc": {
19
- type: "service",
20
- operations: [{ target: "ns#AppsList" }, { target: "ns#AppsGet" }],
21
- },
22
- "ns#AppsList": {
23
- type: "operation",
24
- input: { target: "ns#AppsListRequest" },
25
- output: { target: "smithy.api#Unit" },
26
- },
27
- "ns#AppsListRequest": { type: "structure", members: {} },
28
- "ns#AppsGet": {
29
- type: "operation",
30
- input: { target: "smithy.api#Unit" },
31
- output: { target: "smithy.api#Unit" },
32
- },
33
- },
34
- });
35
-
36
- const scaffold = (patches?: Record<string, unknown>) => {
37
- const root = mkdtempSync(join(tmpdir(), "finalize-"));
38
- mkdirSync(join(root, ".generated-specs"));
39
- writeFileSync(join(root, ".generated-specs", "svc.json"), JSON.stringify(model()));
40
- if (patches) {
41
- mkdirSync(join(root, "patches", "svc"), { recursive: true });
42
- writeFileSync(join(root, "patches", "svc", "a.json"), JSON.stringify(patches));
43
- }
44
- return root;
45
- };
46
-
47
- const read = (root: string) =>
48
- JSON.parse(readFileSync(join(root, ".generated-specs", "svc.json"), "utf8"));
49
-
50
- describe("finalizeConvert", () => {
51
- test("renames, syncs the service list, stamps the marker", async () => {
52
- const root = scaffold();
53
- await finalizeConvert({ root });
54
- const m = read(root);
55
- expect(Object.keys(m.shapes).sort()).toEqual(
56
- ["ns#Svc", "ns#ListApps", "ns#ListAppsRequest", "ns#GetApp"].sort(),
57
- );
58
- expect(m.shapes["ns#Svc"].operations).toEqual([
59
- { target: "ns#ListApps" },
60
- { target: "ns#GetApp" },
61
- ]);
62
- expect(m.metadata[FINALIZED_KEY]).toBe(true);
63
- });
64
-
65
- test("refuses a second pass", async () => {
66
- const root = scaffold();
67
- await finalizeConvert({ root });
68
- await expect(finalizeConvert({ root })).rejects.toThrow(/already finalized/);
69
- });
70
-
71
- test("applies Smithy patches and repairs the service list after a move", async () => {
72
- const root = scaffold({
73
- patches: [{ op: "move", from: "/shapes/ns#AppsGet", path: "/shapes/ns#FetchApp" }],
74
- });
75
- await finalizeConvert({ root });
76
- const m = read(root);
77
- expect(m.shapes["ns#FetchApp"]).toBeDefined();
78
- expect(m.shapes["ns#Svc"].operations.map((o: any) => o.target)).toEqual([
79
- "ns#ListApps",
80
- "ns#FetchApp",
81
- ]);
82
- });
83
-
84
- test("rejects a patch that edits the spec", async () => {
85
- const root = scaffold({
86
- patches: [{ op: "add", path: "/paths/~1apps/get/responses/404", value: {} }],
87
- });
88
- await expect(finalizeConvert({ root })).rejects.toThrow(/target the Smithy model/);
89
- });
90
-
91
- test("fails on a stale patch pointer by default", async () => {
92
- const root = scaffold({
93
- patches: [{ op: "remove", path: "/shapes/ns#Missing" }],
94
- });
95
- await expect(finalizeConvert({ root })).rejects.toThrow(/failed/);
96
- });
97
-
98
- test("fails on dangling targets and leaves the model unstamped", async () => {
99
- const root = scaffold({
100
- patches: [
101
- {
102
- op: "replace",
103
- path: "/shapes/ns#AppsList/output/target",
104
- value: "ns#Nope",
105
- },
106
- ],
107
- });
108
- await expect(finalizeConvert({ root })).rejects.toThrow(/do not exist/);
109
- expect(read(root).metadata?.[FINALIZED_KEY]).toBeUndefined();
110
- });
111
- });
112
-
113
- describe("danglingTargets", () => {
114
- test("ignores prelude ids", () => {
115
- expect(danglingTargets(model())).toEqual([]);
116
- });
117
- });
118
-
119
- describe("syncServiceOperations", () => {
120
- test("drops missing and appends unlisted, keeping order", () => {
121
- const m = model();
122
- delete (m.shapes as any)["ns#AppsGet"];
123
- (m.shapes as any)["ns#Zed"] = { type: "operation" };
124
- expect(syncServiceOperations(m)).toBe(1);
125
- expect((m.shapes as any)["ns#Svc"].operations).toEqual([
126
- { target: "ns#AppsList" },
127
- { target: "ns#Zed" },
128
- ]);
129
- });
130
- });
131
-
132
- describe(SKIP_PATCHES_ENV, () => {
133
- afterEach(() => {
134
- delete process.env[SKIP_PATCHES_ENV];
135
- });
136
-
137
- const patchDir = () => {
138
- const dir = mkdtempSync(join(tmpdir(), "skip-"));
139
- mkdirSync(join(dir, "svc"));
140
- writeFileSync(
141
- join(dir, "svc", "a.json"),
142
- JSON.stringify({
143
- patches: [
144
- { op: "add", path: "/x", value: 1 },
145
- { op: "add", path: "/y", value: 2 },
146
- ],
147
- }),
148
- );
149
- writeFileSync(
150
- join(dir, "svc", "b.json"),
151
- JSON.stringify({ patches: [{ op: "add", path: "/z", value: 3 }] }),
152
- );
153
- return join(dir, "svc");
154
- };
155
-
156
- test("unset applies everything", async () => {
157
- const target: Record<string, unknown> = {};
158
- const files = await listRfc6902PatchFiles(patchDir());
159
- expect(files.map((f) => f.split("/").pop())).toEqual(["a.json", "b.json"]);
160
- expect((await applyRfc6902Files(target, files)).applied).toBe(3);
161
- expect(target).toEqual({ x: 1, y: 2, z: 3 });
162
- });
163
-
164
- test("all lists no files", async () => {
165
- process.env[SKIP_PATCHES_ENV] = "all";
166
- expect(await listRfc6902PatchFiles(patchDir())).toEqual([]);
167
- });
168
-
169
- test("a basename or a path suffix drops that file", async () => {
170
- const dir = patchDir();
171
- process.env[SKIP_PATCHES_ENV] = "a.json";
172
- expect((await listRfc6902PatchFiles(dir)).map((f) => f.split("/").pop())).toEqual(["b.json"]);
173
- process.env[SKIP_PATCHES_ENV] = "svc/b.json";
174
- expect((await listRfc6902PatchFiles(dir)).map((f) => f.split("/").pop())).toEqual(["a.json"]);
175
- process.env[SKIP_PATCHES_ENV] = "other/b.json";
176
- expect((await listRfc6902PatchFiles(dir)).length).toBe(2);
177
- });
178
-
179
- test("<file>:<index> drops one op and keeps the rest of the file", async () => {
180
- const dir = patchDir();
181
- const files = await listRfc6902PatchFiles(dir);
182
- process.env[SKIP_PATCHES_ENV] = "a.json:1";
183
- const target: Record<string, unknown> = {};
184
- const result = await applyRfc6902Files(target, files);
185
- expect(result.applied).toBe(2);
186
- expect(target).toEqual({ x: 1, z: 3 });
187
- });
188
- });
@@ -1,39 +0,0 @@
1
- import { expect, test } from "vitest";
2
- import { generateService } from "./generator.ts";
3
-
4
- test("imports only the pagination protocol when every operation uses it", () => {
5
- const { code } = generateService(
6
- {
7
- smithy: "2.0",
8
- shapes: {
9
- "example#Service": {
10
- type: "service",
11
- version: "1",
12
- operations: [{ target: "example#List" }],
13
- },
14
- "example#List": {
15
- type: "operation",
16
- input: { target: "example#Request" },
17
- output: { target: "example#Response" },
18
- traits: { "smithy.api#paginated": { mode: "single", items: "items" } },
19
- },
20
- "example#Request": { type: "structure", members: {} },
21
- "example#Response": { type: "structure", members: { items: { target: "example#Items" } } },
22
- "example#Items": { type: "list", member: { target: "smithy.api#String" } },
23
- },
24
- },
25
- {
26
- operationDecl: {
27
- contextType: "OpContext",
28
- commonErrorType: "OpError",
29
- commonErrorClasses: [],
30
- protocol: "DefaultProtocol",
31
- retry: "Retry.Retry",
32
- },
33
- paginationProfiles: { default: { protocol: "PaginatedProtocol", itemsFallback: "items" } },
34
- },
35
- );
36
- expect(code).toContain("protocol: PaginatedProtocol");
37
- expect(code).toContain(" PaginatedProtocol,");
38
- expect(code).not.toContain("DefaultProtocol");
39
- });