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

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 (306) 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/annotations.d.ts +15 -0
  12. package/lib/annotations.d.ts.map +1 -0
  13. package/lib/annotations.js +2 -0
  14. package/lib/annotations.js.map +1 -0
  15. package/lib/api.d.ts +15 -0
  16. package/lib/api.d.ts.map +1 -1
  17. package/lib/api.js +1 -796
  18. package/lib/category.d.ts.map +1 -1
  19. package/lib/category.js +1 -278
  20. package/lib/chunks.js +1 -11
  21. package/lib/config.d.ts +54 -13
  22. package/lib/config.d.ts.map +1 -1
  23. package/lib/config.js +1 -161
  24. package/lib/crypto.js +1 -130
  25. package/lib/debug.d.ts.map +1 -1
  26. package/lib/debug.js +1 -8
  27. package/lib/error-category.d.ts.map +1 -1
  28. package/lib/error-category.js +1 -47
  29. package/lib/errors.d.ts +2 -13
  30. package/lib/errors.d.ts.map +1 -1
  31. package/lib/errors.js +1 -198
  32. package/lib/graphql.d.ts +14 -0
  33. package/lib/graphql.d.ts.map +1 -1
  34. package/lib/graphql.js +1 -1058
  35. package/lib/graphql.types.js +1 -6
  36. package/lib/index.d.ts +3 -2
  37. package/lib/index.d.ts.map +1 -1
  38. package/lib/index.js +1 -15
  39. package/lib/pagination.d.ts +34 -2
  40. package/lib/pagination.d.ts.map +1 -1
  41. package/lib/pagination.js +1 -271
  42. package/lib/plain-values.js +1 -39
  43. package/lib/plain-values.js.map +1 -1
  44. package/lib/protocol-http.d.ts +30 -6
  45. package/lib/protocol-http.d.ts.map +1 -1
  46. package/lib/protocol-http.js +1 -812
  47. package/lib/protocol-rest.d.ts +53 -39
  48. package/lib/protocol-rest.d.ts.map +1 -1
  49. package/lib/protocol-rest.js +1 -375
  50. package/lib/query.js +1 -27
  51. package/lib/response-validation-strict.js +1 -284
  52. package/lib/response-validation.d.ts +4 -3
  53. package/lib/response-validation.d.ts.map +1 -1
  54. package/lib/response-validation.js +1 -118
  55. package/lib/retry-after.js +1 -112
  56. package/lib/retry.js +1 -197
  57. package/lib/schema-lite-impl.js +1 -341
  58. package/lib/schema-lite-typed.js +1 -27
  59. package/lib/schema-lite.js +1 -31
  60. package/lib/schema.js +1 -220
  61. package/lib/telemetry-debug.d.ts +14 -0
  62. package/lib/telemetry-debug.d.ts.map +1 -0
  63. package/lib/telemetry-debug.js +2 -0
  64. package/lib/telemetry-debug.js.map +1 -0
  65. package/lib/telemetry-hooks.d.ts +32 -0
  66. package/lib/telemetry-hooks.d.ts.map +1 -0
  67. package/lib/telemetry-hooks.js +2 -0
  68. package/lib/telemetry-hooks.js.map +1 -0
  69. package/lib/telemetry-host-rules.d.ts +23 -0
  70. package/lib/telemetry-host-rules.d.ts.map +1 -0
  71. package/lib/telemetry-host-rules.js +2 -0
  72. package/lib/telemetry-host-rules.js.map +1 -0
  73. package/lib/telemetry-lambda-context.d.ts +17 -0
  74. package/lib/telemetry-lambda-context.d.ts.map +1 -0
  75. package/lib/telemetry-lambda-context.js +2 -0
  76. package/lib/telemetry-lambda-context.js.map +1 -0
  77. package/lib/telemetry-message-context.d.ts +52 -0
  78. package/lib/telemetry-message-context.d.ts.map +1 -0
  79. package/lib/telemetry-message-context.js +2 -0
  80. package/lib/telemetry-message-context.js.map +1 -0
  81. package/lib/telemetry-metrics.d.ts +6 -0
  82. package/lib/telemetry-metrics.d.ts.map +1 -0
  83. package/lib/telemetry-metrics.js +2 -0
  84. package/lib/telemetry-metrics.js.map +1 -0
  85. package/lib/telemetry-name-template.d.ts +13 -0
  86. package/lib/telemetry-name-template.d.ts.map +1 -0
  87. package/lib/telemetry-name-template.js +2 -0
  88. package/lib/telemetry-name-template.js.map +1 -0
  89. package/lib/telemetry-stream.d.ts +9 -0
  90. package/lib/telemetry-stream.d.ts.map +1 -0
  91. package/lib/telemetry-stream.js +2 -0
  92. package/lib/telemetry-stream.js.map +1 -0
  93. package/lib/telemetry-xray.d.ts +28 -0
  94. package/lib/telemetry-xray.d.ts.map +1 -0
  95. package/lib/telemetry-xray.js +2 -0
  96. package/lib/telemetry-xray.js.map +1 -0
  97. package/lib/telemetry.d.ts +269 -0
  98. package/lib/telemetry.d.ts.map +1 -0
  99. package/lib/telemetry.js +3 -0
  100. package/lib/telemetry.js.map +1 -0
  101. package/lib/trait.js +1 -131
  102. package/lib/xml.js +1 -323
  103. package/package.json +1 -3
  104. package/src/annotations.ts +37 -0
  105. package/src/api.ts +130 -30
  106. package/src/category.ts +21 -22
  107. package/src/config.ts +58 -29
  108. package/src/debug.ts +9 -6
  109. package/src/error-category.ts +12 -14
  110. package/src/errors.ts +7 -7
  111. package/src/graphql.ts +123 -18
  112. package/src/index.ts +3 -2
  113. package/src/pagination.ts +119 -6
  114. package/src/protocol-http.ts +63 -43
  115. package/src/protocol-rest.ts +201 -140
  116. package/src/response-validation.ts +4 -3
  117. package/src/telemetry-debug.ts +135 -0
  118. package/src/telemetry-hooks.ts +33 -0
  119. package/src/telemetry-host-rules.ts +39 -0
  120. package/src/telemetry-lambda-context.ts +46 -0
  121. package/src/telemetry-message-context.ts +170 -0
  122. package/src/telemetry-metrics.ts +69 -0
  123. package/src/telemetry-name-template.ts +26 -0
  124. package/src/telemetry-stream.ts +91 -0
  125. package/src/telemetry-xray.ts +66 -0
  126. package/src/telemetry.ts +768 -0
  127. package/lib/api.js.map +0 -1
  128. package/lib/category.js.map +0 -1
  129. package/lib/chunks.js.map +0 -1
  130. package/lib/codegen/boolean-string-enums.d.ts +0 -36
  131. package/lib/codegen/boolean-string-enums.d.ts.map +0 -1
  132. package/lib/codegen/boolean-string-enums.js +0 -147
  133. package/lib/codegen/boolean-string-enums.js.map +0 -1
  134. package/lib/codegen/chunk.d.ts +0 -7
  135. package/lib/codegen/chunk.d.ts.map +0 -1
  136. package/lib/codegen/chunk.js +0 -139
  137. package/lib/codegen/chunk.js.map +0 -1
  138. package/lib/codegen/cli.d.ts +0 -80
  139. package/lib/codegen/cli.d.ts.map +0 -1
  140. package/lib/codegen/cli.js +0 -166
  141. package/lib/codegen/cli.js.map +0 -1
  142. package/lib/codegen/datafy.d.ts +0 -14
  143. package/lib/codegen/datafy.d.ts.map +0 -1
  144. package/lib/codegen/datafy.js +0 -853
  145. package/lib/codegen/datafy.js.map +0 -1
  146. package/lib/codegen/dedupe.d.ts +0 -5
  147. package/lib/codegen/dedupe.d.ts.map +0 -1
  148. package/lib/codegen/dedupe.js +0 -153
  149. package/lib/codegen/dedupe.js.map +0 -1
  150. package/lib/codegen/emit.d.ts +0 -125
  151. package/lib/codegen/emit.d.ts.map +0 -1
  152. package/lib/codegen/emit.js +0 -99
  153. package/lib/codegen/emit.js.map +0 -1
  154. package/lib/codegen/format.d.ts +0 -11
  155. package/lib/codegen/format.d.ts.map +0 -1
  156. package/lib/codegen/format.js +0 -32
  157. package/lib/codegen/format.js.map +0 -1
  158. package/lib/codegen/generated-at.d.ts +0 -29
  159. package/lib/codegen/generated-at.d.ts.map +0 -1
  160. package/lib/codegen/generated-at.js +0 -78
  161. package/lib/codegen/generated-at.js.map +0 -1
  162. package/lib/codegen/generator.d.ts +0 -353
  163. package/lib/codegen/generator.d.ts.map +0 -1
  164. package/lib/codegen/generator.js +0 -810
  165. package/lib/codegen/generator.js.map +0 -1
  166. package/lib/codegen/graph.d.ts +0 -36
  167. package/lib/codegen/graph.d.ts.map +0 -1
  168. package/lib/codegen/graph.js +0 -136
  169. package/lib/codegen/graph.js.map +0 -1
  170. package/lib/codegen/graphql-client.d.ts +0 -70
  171. package/lib/codegen/graphql-client.d.ts.map +0 -1
  172. package/lib/codegen/graphql-client.js +0 -439
  173. package/lib/codegen/graphql-client.js.map +0 -1
  174. package/lib/codegen/graphql.d.ts +0 -207
  175. package/lib/codegen/graphql.d.ts.map +0 -1
  176. package/lib/codegen/graphql.js +0 -786
  177. package/lib/codegen/graphql.js.map +0 -1
  178. package/lib/codegen/latin1.d.ts +0 -3
  179. package/lib/codegen/latin1.d.ts.map +0 -1
  180. package/lib/codegen/latin1.js +0 -126
  181. package/lib/codegen/latin1.js.map +0 -1
  182. package/lib/codegen/members.d.ts +0 -32
  183. package/lib/codegen/members.d.ts.map +0 -1
  184. package/lib/codegen/members.js +0 -62
  185. package/lib/codegen/members.js.map +0 -1
  186. package/lib/codegen/model-diff.d.ts +0 -10
  187. package/lib/codegen/model-diff.d.ts.map +0 -1
  188. package/lib/codegen/model-diff.js +0 -67
  189. package/lib/codegen/model-diff.js.map +0 -1
  190. package/lib/codegen/naming.d.ts +0 -29
  191. package/lib/codegen/naming.d.ts.map +0 -1
  192. package/lib/codegen/naming.js +0 -74
  193. package/lib/codegen/naming.js.map +0 -1
  194. package/lib/codegen/openapi-cli.d.ts +0 -52
  195. package/lib/codegen/openapi-cli.d.ts.map +0 -1
  196. package/lib/codegen/openapi-cli.js +0 -84
  197. package/lib/codegen/openapi-cli.js.map +0 -1
  198. package/lib/codegen/openapi.d.ts +0 -209
  199. package/lib/codegen/openapi.d.ts.map +0 -1
  200. package/lib/codegen/openapi.js +0 -1548
  201. package/lib/codegen/openapi.js.map +0 -1
  202. package/lib/codegen/operations.d.ts +0 -24
  203. package/lib/codegen/operations.d.ts.map +0 -1
  204. package/lib/codegen/operations.js +0 -56
  205. package/lib/codegen/operations.js.map +0 -1
  206. package/lib/codegen/pagination.d.ts +0 -39
  207. package/lib/codegen/pagination.d.ts.map +0 -1
  208. package/lib/codegen/pagination.js +0 -31
  209. package/lib/codegen/pagination.js.map +0 -1
  210. package/lib/codegen/patch-audit.d.ts +0 -84
  211. package/lib/codegen/patch-audit.d.ts.map +0 -1
  212. package/lib/codegen/patch-audit.js +0 -366
  213. package/lib/codegen/patch-audit.js.map +0 -1
  214. package/lib/codegen/patches.d.ts +0 -129
  215. package/lib/codegen/patches.d.ts.map +0 -1
  216. package/lib/codegen/patches.js +0 -472
  217. package/lib/codegen/patches.js.map +0 -1
  218. package/lib/codegen/prelude.d.ts +0 -15
  219. package/lib/codegen/prelude.d.ts.map +0 -1
  220. package/lib/codegen/prelude.js +0 -60
  221. package/lib/codegen/prelude.js.map +0 -1
  222. package/lib/codegen/privatize.d.ts +0 -21
  223. package/lib/codegen/privatize.d.ts.map +0 -1
  224. package/lib/codegen/privatize.js +0 -176
  225. package/lib/codegen/privatize.js.map +0 -1
  226. package/lib/codegen/proto.d.ts +0 -121
  227. package/lib/codegen/proto.d.ts.map +0 -1
  228. package/lib/codegen/proto.js +0 -960
  229. package/lib/codegen/proto.js.map +0 -1
  230. package/lib/codegen/pure.d.ts +0 -6
  231. package/lib/codegen/pure.d.ts.map +0 -1
  232. package/lib/codegen/pure.js +0 -91
  233. package/lib/codegen/pure.js.map +0 -1
  234. package/lib/codegen/rewrite-operation-ids.d.ts +0 -154
  235. package/lib/codegen/rewrite-operation-ids.d.ts.map +0 -1
  236. package/lib/codegen/rewrite-operation-ids.js +0 -1117
  237. package/lib/codegen/rewrite-operation-ids.js.map +0 -1
  238. package/lib/codegen/spec-path.d.ts +0 -16
  239. package/lib/codegen/spec-path.d.ts.map +0 -1
  240. package/lib/codegen/spec-path.js +0 -101
  241. package/lib/codegen/spec-path.js.map +0 -1
  242. package/lib/codegen/table.d.ts +0 -5
  243. package/lib/codegen/table.d.ts.map +0 -1
  244. package/lib/codegen/table.js +0 -249
  245. package/lib/codegen/table.js.map +0 -1
  246. package/lib/config.js.map +0 -1
  247. package/lib/crypto.js.map +0 -1
  248. package/lib/debug.js.map +0 -1
  249. package/lib/error-category.js.map +0 -1
  250. package/lib/errors.js.map +0 -1
  251. package/lib/graphql.js.map +0 -1
  252. package/lib/graphql.types.js.map +0 -1
  253. package/lib/index.js.map +0 -1
  254. package/lib/json-patch.d.ts +0 -58
  255. package/lib/json-patch.d.ts.map +0 -1
  256. package/lib/json-patch.js +0 -227
  257. package/lib/json-patch.js.map +0 -1
  258. package/lib/pagination.js.map +0 -1
  259. package/lib/protocol-http.js.map +0 -1
  260. package/lib/protocol-rest.js.map +0 -1
  261. package/lib/query.js.map +0 -1
  262. package/lib/response-validation-strict.js.map +0 -1
  263. package/lib/response-validation.js.map +0 -1
  264. package/lib/retry-after.js.map +0 -1
  265. package/lib/retry.js.map +0 -1
  266. package/lib/schema-lite-impl.js.map +0 -1
  267. package/lib/schema-lite-typed.js.map +0 -1
  268. package/lib/schema-lite.js.map +0 -1
  269. package/lib/schema.js.map +0 -1
  270. package/lib/testing.d.ts +0 -40
  271. package/lib/testing.d.ts.map +0 -1
  272. package/lib/testing.js +0 -42
  273. package/lib/testing.js.map +0 -1
  274. package/lib/trait.js.map +0 -1
  275. package/lib/xml.js.map +0 -1
  276. package/src/codegen/boolean-string-enums.ts +0 -155
  277. package/src/codegen/chunk.ts +0 -147
  278. package/src/codegen/cli.ts +0 -293
  279. package/src/codegen/datafy.ts +0 -874
  280. package/src/codegen/dedupe.ts +0 -173
  281. package/src/codegen/emit.ts +0 -200
  282. package/src/codegen/format.ts +0 -49
  283. package/src/codegen/generated-at.ts +0 -88
  284. package/src/codegen/generator.ts +0 -1229
  285. package/src/codegen/graph.ts +0 -151
  286. package/src/codegen/graphql-client.ts +0 -545
  287. package/src/codegen/graphql.ts +0 -1145
  288. package/src/codegen/latin1.ts +0 -131
  289. package/src/codegen/members.ts +0 -79
  290. package/src/codegen/model-diff.ts +0 -67
  291. package/src/codegen/naming.ts +0 -85
  292. package/src/codegen/openapi-cli.ts +0 -141
  293. package/src/codegen/openapi.ts +0 -1845
  294. package/src/codegen/operations.ts +0 -73
  295. package/src/codegen/pagination.ts +0 -64
  296. package/src/codegen/patch-audit.ts +0 -480
  297. package/src/codegen/patches.ts +0 -581
  298. package/src/codegen/prelude.ts +0 -70
  299. package/src/codegen/privatize.ts +0 -200
  300. package/src/codegen/proto.ts +0 -1092
  301. package/src/codegen/pure.ts +0 -94
  302. package/src/codegen/rewrite-operation-ids.ts +0 -1219
  303. package/src/codegen/spec-path.ts +0 -112
  304. package/src/codegen/table.ts +0 -254
  305. package/src/json-patch.ts +0 -273
  306. package/src/testing.ts +0 -74
@@ -1,853 +0,0 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
- import { parseAst } from "rolldown/parseAst";
44
- const isNode = (v) => v !== null && typeof v === "object" && typeof v.type === "string";
45
- const strip = (n) => {
46
- while (n.type === "TSAsExpression" ||
47
- n.type === "TSSatisfiesExpression" ||
48
- n.type === "TSNonNullExpression" ||
49
- n.type === "ParenthesizedExpression")
50
- n = n.expression;
51
- return n;
52
- };
53
-
54
- const tableRef = (n) => {
55
- if (n.type !== "CallExpression")
56
- return undefined;
57
- const c = n.callee;
58
- const table = c.type === "Identifier" && c.name === "__S";
59
- const at = c.type === "MemberExpression" && c.object.name === "__L" && c.property.name === "at";
60
- if (!table && !at)
61
- return undefined;
62
- const [f, j] = n.arguments.slice(table ? 1 : 0);
63
- const m = /^__c(\d+)$/.exec(f.name ?? "");
64
- if (!m || j.type !== "Literal")
65
- throw new Error("datafy: unexpected __S call");
66
- return `${m[1]}:${j.value}`;
67
- };
68
- const walk = (n, visit) => {
69
- if (Array.isArray(n)) {
70
- for (const c of n)
71
- walk(c, visit);
72
- return;
73
- }
74
- if (!isNode(n) || !visit(n))
75
- return;
76
- for (const [key, v] of Object.entries(n))
77
- if (key !== "type" && v !== null && typeof v === "object")
78
- walk(v, visit);
79
- };
80
- const IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
81
-
82
- const encodable = (n) => {
83
- n = strip(n);
84
- if (tableRef(n))
85
- return true;
86
- switch (n.type) {
87
- case "Literal": {
88
- const v = n.value;
89
- return (typeof v === "string" ||
90
- typeof v === "boolean" ||
91
- (typeof v === "number" && Number.isFinite(v)) ||
92
- (v === null && !n.regex && !n.bigint));
93
- }
94
- case "TemplateLiteral":
95
- return !n.expressions.length;
96
- case "UnaryExpression":
97
- return (n.operator === "void" ||
98
- (n.operator === "-" &&
99
- n.argument.type === "Literal" &&
100
- typeof n.argument.value === "number"));
101
- case "Identifier":
102
- return true;
103
- case "MemberExpression":
104
- return !n.computed && encodable(n.object);
105
- case "CallExpression":
106
- return (encodable(n.callee) &&
107
- n.arguments.every((a) => a.type !== "SpreadElement" && encodable(a)));
108
- case "ObjectExpression":
109
- return n.properties.every((p) => p.type === "Property" &&
110
- p.kind === "init" &&
111
- !p.method &&
112
- ((!p.computed && p.key.type === "Identifier") || p.key.type === "Literal") &&
113
- encodable(p.value));
114
- case "ArrayExpression":
115
- return n.elements.every((e) => !!e && e.type !== "SpreadElement" && encodable(e));
116
- case "ArrowFunctionExpression":
117
- return !n.params.length && n.body.type !== "BlockStatement" && encodable(n.body);
118
- default:
119
- return false;
120
- }
121
- };
122
-
123
-
124
-
125
-
126
- const quote = (s) => JSON.stringify(s).replace(/[^\x00-\x24\x26-\x3a\x3c-\x7f]/g, (c) => `\\u${c.charCodeAt(0).toString(16).padStart(4, "0")}`);
127
-
128
- const VOCAB = /^(?:S|T|__L)\.[A-Za-z_$][\w$]*$/;
129
-
130
- class Holder {
131
- entries = [];
132
- refs = ["__0"];
133
- refIndex = new Map([["__0", 0]]);
134
-
135
- local = new Map();
136
- name;
137
-
138
- stem;
139
- constructor(name) {
140
- this.name = name;
141
- }
142
- ref(text) {
143
- let i = this.refIndex.get(text);
144
- if (i === undefined) {
145
- i = this.refs.length;
146
- this.refs.push(text);
147
- this.refIndex.set(text, i);
148
- }
149
- return i;
150
- }
151
- }
152
-
153
- const identifierOf = (n) => {
154
- const callee = strip(n.callee);
155
- const [arg] = n.arguments;
156
- const props = arg?.type === "ObjectExpression" ? arg.properties : [];
157
- const p = props[0];
158
- return callee.property.name === "annotate" &&
159
- n.arguments.length === 1 &&
160
- props.length === 1 &&
161
- p.type === "Property" &&
162
- !p.computed &&
163
- p.key.name === "identifier" &&
164
- p.value.type === "Literal" &&
165
- typeof p.value.value === "string"
166
- ? p.value.value
167
- : undefined;
168
- };
169
-
170
-
171
-
172
-
173
-
174
-
175
- const canon = (n, isNamespace, onNode, up) => {
176
- n = strip(n);
177
- const go = (x) => canon(x, isNamespace, onNode, n);
178
- const all = (xs) => {
179
- const parts = xs.map(go);
180
- return parts.every((p) => p) ? parts : undefined;
181
- };
182
- const join = (ps) => ps.map((p) => p[0]).join(",");
183
- const width = (ps) => ps.reduce((a, p) => a + p[1] + 1, 0);
184
- let out;
185
- if (tableRef(n))
186
- out = undefined;
187
- else
188
- switch (n.type) {
189
- case "Literal":
190
- case "TemplateLiteral":
191
- case "UnaryExpression": {
192
- const v = n.type === "TemplateLiteral"
193
- ? n.expressions.length
194
- ? undefined
195
- : quote(n.quasis[0].value.cooked)
196
- : n.type === "UnaryExpression"
197
- ? n.operator === "void"
198
- ? "u"
199
- : `-${n.argument.value}`
200
- : typeof n.value === "string"
201
- ? quote(n.value)
202
- : String(n.value);
203
- out = v === undefined ? undefined : [v, v.length];
204
- break;
205
- }
206
- case "Identifier":
207
- out = n.name === "undefined" ? ["u", 1] : [`$${n.name}`, 3];
208
- break;
209
- case "MemberExpression": {
210
- const obj = strip(n.object);
211
- if (isNamespace(obj))
212
- out = [`$${obj.name}.${n.property.name}`, 3];
213
- else {
214
- const o = go(obj);
215
- out = o && [`${o[0]}.${n.property.name}`, o[1] + 1 + n.property.name.length];
216
- }
217
- break;
218
- }
219
- case "CallExpression": {
220
- const callee = strip(n.callee);
221
- if (callee.type === "MemberExpression" && !isNamespace(strip(callee.object))) {
222
- const o = go(callee.object);
223
- const name = callee.property.name;
224
- const id = identifierOf(n);
225
- if (id !== undefined)
226
- out = o && [`${o[0]}@${quote(id)}`, o[1] + 3 + id.length];
227
- else {
228
- const args = all(n.arguments);
229
- out = o &&
230
- args && [`${o[0]}.${name}(${join(args)})`, o[1] + name.length + 2 + width(args)];
231
- }
232
- }
233
- else {
234
- const args = all(n.arguments);
235
- const c = go(callee);
236
- out = c && args && [`${c[0]}(${join(args)})`, c[1] + 1 + width(args)];
237
- }
238
- break;
239
- }
240
- case "ObjectExpression": {
241
- const props = n.properties;
242
- const vals = all(props.map((p) => p.value));
243
- out = vals && [
244
- `{${props.map((p, i) => `${quote(String(p.key.name ?? p.key.value))}:${vals[i][0]}`).join(",")}}`,
245
- props.reduce((a, p, i) => a + String(p.key.name ?? p.key.value).length + 2 + vals[i][1], 1),
246
- ];
247
- break;
248
- }
249
- case "ArrayExpression": {
250
- const els = all(n.elements);
251
- out = els && [`[${join(els)}]`, width(els) + 1];
252
- break;
253
- }
254
- case "ArrowFunctionExpression":
255
- go(n.body);
256
- out = undefined;
257
- break;
258
- default:
259
- out = undefined;
260
- }
261
- onNode?.(n, up, out?.[0], out?.[1] ?? 0);
262
- return out;
263
- };
264
-
265
- const configOf = (o) => {
266
- if (!o.strategy)
267
- return o.config;
268
- const c = strip(o.config);
269
- if (c.type !== "ObjectExpression")
270
- throw new Error(`datafy: ${o.name} config is not an object`);
271
- const key = { type: "Identifier", start: 0, end: 0, name: "strategy" };
272
- const member = {
273
- type: "Property",
274
- start: 0,
275
- end: 0,
276
- kind: "init",
277
- method: false,
278
- computed: false,
279
- key,
280
- value: o.strategy,
281
- };
282
- return { ...c, properties: [...c.properties, member] };
283
- };
284
-
285
- const MAX_MOVED_FUNCTION = 4000;
286
-
287
- const MIN_LEN = 16;
288
-
289
- const MIN_SAVING = 64;
290
-
291
-
292
-
293
-
294
- const NEW_HOLDER_COST = 3000;
295
-
296
-
297
-
298
-
299
-
300
-
301
-
302
- const hoistConstants = (roots, isNamespace, holderOf, rootsOf, pinned) => {
303
- const pinnedUses = new Map();
304
- const parent = new Map();
305
- const container = new Map();
306
- const byKey = new Map();
307
- for (const [root, h] of roots) {
308
- container.set(strip(root), h);
309
- canon(root, isNamespace, (n, up, key, len) => {
310
- if (up)
311
- parent.set(n, up);
312
- if (n.type === "Identifier" && pinned.has(n.name)) {
313
- let uses = pinnedUses.get(n.name);
314
- if (!uses)
315
- pinnedUses.set(n.name, (uses = []));
316
- uses.push(n);
317
- }
318
- if (key === undefined)
319
- return;
320
- const candidate = (len >= MIN_LEN && n.type === "CallExpression" && n.arguments.length > 0) ||
321
- ((n.type === "Literal" || n.type === "TemplateLiteral") && len >= MIN_LEN);
322
- if (!candidate)
323
- return;
324
- let c = byKey.get(key);
325
- if (!c)
326
- byKey.set(key, (c = { len, nodes: [] }));
327
- c.nodes.push(n);
328
- });
329
- }
330
- const valueOf = new Map();
331
- const liveIn = (n) => {
332
- for (let x = n;;) {
333
- const p = parent.get(x);
334
- if (!p)
335
- return container.get(x);
336
- const v = valueOf.get(p);
337
- if (v)
338
- return v.nodes[0] === p ? v.holder : undefined;
339
- x = p;
340
- }
341
- };
342
- const keyOf = (holders) => {
343
- const rs = new Set();
344
- for (const h of holders)
345
- for (const r of rootsOf.get(h).split(","))
346
- rs.add(+r);
347
- return [...rs].sort((a, b) => a - b).join(",");
348
- };
349
- // Each moved constant was at least one object at import; the holder it moves to may be new.
350
- let newHolders = Math.max(0, pinned.size - 1);
351
- const values = [];
352
- const candidates = [...byKey.values()]
353
- .filter((c) => c.nodes.length > 1)
354
- .sort((a, b) => (b.nodes.length - 1) * b.len - (a.nodes.length - 1) * a.len);
355
- for (const c of candidates) {
356
- const live = [];
357
- for (const n of c.nodes) {
358
- const h = liveIn(n);
359
- if (h)
360
- live.push([n, h]);
361
- }
362
- if (live.length < 2)
363
- continue;
364
- const key = keyOf(live.map(([, h]) => h));
365
- const existing = holderOf(key, false);
366
- // A new holder is one more function at import: only as many as moved constants free.
367
- if (!existing && !newHolders)
368
- continue;
369
- let cost = c.len + (existing ? 0 : NEW_HOLDER_COST);
370
- const users = new Set();
371
- for (const [, h] of live) {
372
- cost += h === existing ? 3 : 6;
373
- users.add(h);
374
- }
375
- cost += 6 * [...users].filter((h) => h !== existing).length;
376
- if (live.length * c.len - cost < MIN_SAVING)
377
- continue;
378
- if (!existing)
379
- newHolders--;
380
- const holder = existing ?? holderOf(key, true);
381
- rootsOf.set(holder, key);
382
- const v = { nodes: live.map(([n]) => n), holder, j: -1 };
383
- for (const n of v.nodes)
384
- valueOf.set(n, v);
385
- values.push(v);
386
- }
387
- for (const [name, code] of pinned) {
388
- const live = [];
389
- for (const n of pinnedUses.get(name) ?? []) {
390
- const h = liveIn(n);
391
- if (h)
392
- live.push([n, h]);
393
- }
394
- if (!live.length)
395
- throw new Error(`datafy: constant ${name} has no live reader`);
396
- const key = keyOf(live.map(([, h]) => h));
397
- const holder = holderOf(key, true);
398
- rootsOf.set(holder, key);
399
- values.push({ nodes: live.map(([n]) => n), holder, j: -1, code });
400
- }
401
- return values;
402
- };
403
- const STRING = /"(?:[^"\\]|\\.)*"/g;
404
- const STEM = /^[\w.-]{4,}$/;
405
-
406
-
407
-
408
-
409
-
410
- const stemOf = (h) => {
411
- const strings = h.entries.flatMap((e) => e.match(STRING) ?? []).map((t) => t.slice(1, -1));
412
- let best = 0;
413
- for (const c of new Set(strings)) {
414
- if (!STEM.test(c))
415
- continue;
416
- let uses = 0;
417
- for (const t of strings)
418
- uses += t.split(c).length - 1;
419
- const saving = uses * (c.length - 1) - (c.length + 4);
420
- if (saving > best)
421
- [best, h.stem] = [saving, c];
422
- }
423
- const stem = h.stem;
424
- if (stem)
425
- for (let j = 0; j < h.entries.length; j++)
426
- h.entries[j] = h.entries[j].replace(STRING, (t) => t.split(stem).join("%"));
427
- };
428
- export const datafyOperations = (code, filename = "generated.ts",
429
-
430
-
431
-
432
-
433
- { aliases: aliased = true } = {}) => {
434
- if (!/\bfunction __S\(/.test(code))
435
- return { code, operations: 0, holders: 0, errors: 0 };
436
- const program = parseAst(code, { sourceType: "module", lang: "ts" }, filename);
437
- const body = program.body;
438
- const text = (n) => code.slice(n.start, n.end);
439
- // `import * as X`: `X.y` is a plain value; any other receiver keeps `this` in calls.
440
- const namespaces = new Set();
441
- for (const st of body)
442
- if (st.type === "ImportDeclaration" && st.importKind !== "type")
443
- for (const sp of st.specifiers)
444
- if (sp.type === "ImportNamespaceSpecifier")
445
- namespaces.add(sp.local.name);
446
- const isNamespace = (n) => n.type === "Identifier" && namespaces.has(n.name);
447
- // Emitted JS (lib/) gets no type annotations.
448
- const ts = !filename.endsWith(".js");
449
- const any = ts ? ": any" : "";
450
- // Graph nodes: schemas (`K:j`, from the builders).
451
- const nodes = new Map();
452
- const removals = [];
453
- const ops = [];
454
- const errors = [];
455
- const rest = [];
456
- for (const st of body) {
457
- const cls = st.type === "ExportNamedDeclaration" ? st.declaration : st;
458
- if (cls?.type === "ClassDeclaration" &&
459
- cls.id &&
460
- cls.superClass &&
461
- !cls.body.body.length &&
462
- !cls.decorators?.length &&
463
- encodable(cls.superClass)) {
464
- errors.push({
465
- name: cls.id.name,
466
- init: st,
467
- paginated: false,
468
- config: cls.superClass,
469
- error: { exported: st !== cls },
470
- });
471
- continue;
472
- }
473
- if (st.type === "FunctionDeclaration" && /^__c\d+$/.test(st.id?.name ?? "")) {
474
- const k = st.id.name.slice(3);
475
- const sw = st.body.body[0];
476
- if (sw?.type !== "SwitchStatement")
477
- throw new Error(`datafy: ${st.id.name} is not a switch`);
478
- for (const c of sw.cases) {
479
- const ret = c.consequent[0];
480
- if (ret?.type !== "ReturnStatement")
481
- throw new Error("datafy: case without return");
482
- nodes.set(`${k}:${c.test.value}`, ret.argument);
483
- }
484
- removals.push(st);
485
- continue;
486
- }
487
- if (st.type === "FunctionDeclaration" && st.id?.name === "__S") {
488
- removals.push(st);
489
- continue;
490
- }
491
- if (st.type === "VariableDeclaration" && st.declarations.length === 1) {
492
- const d = st.declarations[0];
493
- if (d.id.name === "__s") {
494
- removals.push(st);
495
- continue;
496
- }
497
- }
498
- const decl = st.type === "ExportNamedDeclaration" ? st.declaration : st;
499
- if (decl?.type === "VariableDeclaration" && decl.declarations.length === 1) {
500
- const d = decl.declarations[0];
501
- const init = d.init ? strip(d.init) : undefined;
502
- if (init?.type === "CallExpression" &&
503
- init.callee.type === "MemberExpression" &&
504
- init.callee.object.name === "API" &&
505
- (init.callee.property.name === "make" || init.callee.property.name === "makePaginated")) {
506
- const [fn, strategy] = init.arguments;
507
- if (fn?.type !== "ArrowFunctionExpression" ||
508
- fn.params.length ||
509
- fn.body.type === "BlockStatement")
510
- throw new Error(`datafy: unexpected operation form in ${d.id.name}`);
511
- ops.push({
512
- name: d.id.name,
513
- init: d.init,
514
- paginated: init.callee.property.name === "makePaginated",
515
- config: strip(fn.body),
516
- strategy,
517
- });
518
- continue;
519
- }
520
- }
521
- if (st.type !== "ImportDeclaration")
522
- rest.push(st);
523
- }
524
- if (!ops.length && !errors.length)
525
- return { code, operations: 0, holders: 0, errors: 0 };
526
- const operations = ops.length;
527
- // From here on an error class is a root like an operation; its entry 0 is its base class.
528
- ops.push(...errors);
529
- // Module constants only data reads (service traits, endpoint rules, ...)
530
- // move, as written, into the holder of the roots that reach them.
531
- const reads = (n, name) => {
532
- let count = 0;
533
- walk(n, (x) => {
534
- if (x.type === "Identifier" && x.name === name)
535
- count++;
536
- return true;
537
- });
538
- return count;
539
- };
540
- const dataRoots = [[...nodes.values()], ops.map((o) => [o.config, o.strategy])];
541
- const pinnable = new Map();
542
- for (const st of rest) {
543
- if (st.type !== "VariableDeclaration" || st.kind !== "const" || st.declarations.length !== 1)
544
- continue;
545
- const d = st.declarations[0];
546
- if (d.id.type !== "Identifier" || !d.init || strip(d.init).type !== "CallExpression")
547
- continue;
548
- if (!/\/\*[@#]__PURE__\*\/\s*$/.test(code.slice(Math.max(0, d.init.start - 20), d.init.start)))
549
- continue;
550
- let internal = false;
551
- walk(d.init, (x) => {
552
- if (tableRef(x) || (x.type === "Identifier" && /^__[cSs]\d*$/.test(x.name)))
553
- internal = true;
554
- // A first call would parse a big function twice (holder, then itself): it stays.
555
- if (/Function/.test(x.type) && x.end - x.start > MAX_MOVED_FUNCTION)
556
- internal = true;
557
- return true;
558
- });
559
- if (!internal)
560
- pinnable.set(d.id.name, { st, init: d.init });
561
- }
562
- for (let changed = true; changed;) {
563
- changed = false;
564
- for (const [name, c] of pinnable) {
565
- const outside = rest.some((st) => st !== c.st && reads(st, name) > 0);
566
- const chained = [...pinnable.keys()].some((other) => reads(c.init, other) > 0);
567
- if (outside || chained || reads(c.init, name) || !reads(dataRoots, name)) {
568
- pinnable.delete(name);
569
- changed = true;
570
- }
571
- }
572
- }
573
- const pinned = new Map();
574
- for (const [name, c] of pinnable) {
575
- pinned.set(name, text(c.init));
576
- removals.push(c.st);
577
- }
578
- const roots = rest.filter((st) => !removals.includes(st));
579
-
580
- const refsOf = (n) => {
581
- const out = new Set();
582
- walk(n, (x) => {
583
- const k = tableRef(x);
584
- if (k)
585
- out.add(k);
586
- return !k;
587
- });
588
- return out;
589
- };
590
- // Reachability: which roots reach each node.
591
- const edges = new Map();
592
- for (const [k, n] of nodes)
593
- edges.set(k, refsOf(n));
594
- const otherRoots = roots.filter((st) => refsOf(st).size);
595
- const rootRefs = [...ops.map((o) => refsOf(o.config)), ...otherRoots.map((st) => refsOf(st))];
596
- const reachedBy = new Map();
597
- rootRefs.forEach((start, r) => {
598
- const seen = new Set();
599
- const stack = [...start];
600
- while (stack.length) {
601
- const k = stack.pop();
602
- if (seen.has(k))
603
- continue;
604
- seen.add(k);
605
- if (!nodes.has(k))
606
- throw new Error(`datafy: missing schema ${k}`);
607
- let list = reachedBy.get(k);
608
- if (!list)
609
- reachedBy.set(k, (list = []));
610
- list.push(r);
611
- for (const x of edges.get(k))
612
- stack.push(x);
613
- }
614
- });
615
- // Placement: an operation's own holder, or a shared holder per root set.
616
- const opHolders = ops.map((o) => new Holder(o.name));
617
- const shared = new Map();
618
- const home = new Map();
619
- for (const k of nodes.keys()) {
620
- const rs = reachedBy.get(k);
621
- if (!rs)
622
- continue; // unreachable: dropped
623
- let h;
624
- if (rs.length === 1 && rs[0] < ops.length)
625
- h = opHolders[rs[0]];
626
- else {
627
- const key = rs.join(",");
628
- h = shared.get(key) ?? new Holder(`__d${shared.size}`);
629
- shared.set(key, h);
630
- }
631
- home.set(k, h);
632
- }
633
- // Entry indexes: operation config first, then nodes in source order.
634
- for (const h of opHolders)
635
- h.entries.push("");
636
- for (const [k, h] of home) {
637
- h.local.set(k, h.entries.length);
638
- h.entries.push("");
639
- }
640
- // Aliases: `__0` is `at`; other namespace members are numbered on first use.
641
- const aliases = new Map([["__L.at", "__0"]]);
642
- const alias = (t) => {
643
- let a = aliases.get(t);
644
- if (!a)
645
- aliases.set(t, (a = `__${aliases.size}`));
646
- return a;
647
- };
648
- const nodeRef = (k, h) => {
649
- const target = home.get(k);
650
- const j = target.local.get(k);
651
- if (target === h)
652
- return `#${j}`;
653
- return `#${h.ref(target.name)}:${j}`;
654
- };
655
- const configs = ops.map(configOf);
656
- // Repeated constant expressions become value entries (`~N`, `~R:N`).
657
- const holderOfKey = (key, create) => {
658
- const rs = key.split(",").map(Number);
659
- if (rs.length === 1 && rs[0] < ops.length)
660
- return opHolders[rs[0]];
661
- let h = shared.get(key);
662
- if (!h && create)
663
- shared.set(key, (h = new Holder(`__d${shared.size}`)));
664
- return h;
665
- };
666
- const rootsOf = new Map();
667
- opHolders.forEach((h, i) => rootsOf.set(h, String(i)));
668
- for (const [key, h] of shared)
669
- rootsOf.set(h, key);
670
- const exprRoots = [...home].map(([k, h]) => [nodes.get(k), h]);
671
- configs.forEach((c, i) => exprRoots.push([c, opHolders[i]]));
672
- const values = hoistConstants(exprRoots, isNamespace, holderOfKey, rootsOf, pinned);
673
- for (const v of values) {
674
- v.j = v.holder.entries.length;
675
- v.holder.entries.push("");
676
- }
677
- const valueOf = new Map();
678
- for (const v of values)
679
- for (const n of v.nodes)
680
- valueOf.set(n, v);
681
- const encode = (n, h, self) => {
682
- const value = (t) => `$${h.ref(aliased && VOCAB.test(t) ? alias(t) : t)}`;
683
- n = strip(n);
684
- const v = valueOf.get(n);
685
- if (v && v !== self)
686
- return v.holder === h ? `~${v.j}` : `~${h.ref(v.holder.name)}:${v.j}`;
687
- const k = tableRef(n);
688
- if (k)
689
- return nodeRef(k, h);
690
- const enc = (x) => encode(x, h);
691
- switch (n.type) {
692
- case "Literal": {
693
- const v = n.value;
694
- if (typeof v === "string")
695
- return quote(v);
696
- if (typeof v === "number" && Number.isFinite(v))
697
- return String(v);
698
- if (typeof v === "boolean")
699
- return String(v);
700
- if (v === null && !n.regex && !n.bigint)
701
- return "null";
702
- throw new Error(`datafy: unsupported literal ${text(n)}`);
703
- }
704
- case "TemplateLiteral":
705
- if (n.expressions.length)
706
- throw new Error("datafy: template with expressions");
707
- return quote(n.quasis[0].value.cooked);
708
- case "UnaryExpression":
709
- if (n.operator === "-" &&
710
- n.argument.type === "Literal" &&
711
- typeof n.argument.value === "number")
712
- return String(-n.argument.value);
713
- if (n.operator === "void")
714
- return "u";
715
- throw new Error(`datafy: unsupported unary ${text(n)}`);
716
- case "Identifier":
717
- if (n.name === "undefined")
718
- return "u";
719
- return value(n.name);
720
- case "MemberExpression": {
721
- if (n.computed)
722
- throw new Error(`datafy: computed member ${text(n)}`);
723
- const obj = strip(n.object);
724
- // `S.String`, `Retry.Retry`: one value.
725
- if (isNamespace(obj))
726
- return value(`${obj.name}.${n.property.name}`);
727
- return `${enc(obj)}.${n.property.name}`;
728
- }
729
- case "CallExpression": {
730
- const args = n.arguments.map((a) => {
731
- if (a.type === "SpreadElement")
732
- throw new Error("datafy: spread argument");
733
- return enc(a);
734
- });
735
- const callee = strip(n.callee);
736
- // `S.Struct(...)` calls the namespace member as a plain function;
737
- // `x.pipe(...)` on any other receiver is a method call.
738
- if (callee.type === "MemberExpression" &&
739
- !callee.computed &&
740
- !isNamespace(strip(callee.object))) {
741
- // `.annotate({ identifier: "X" })`, on most schemas: `@"X"`.
742
- const id = identifierOf(n);
743
- if (id !== undefined)
744
- return `${enc(callee.object)}@${quote(id)}`;
745
- return `${enc(callee.object)}.${callee.property.name}(${args.join(",")})`;
746
- }
747
- return `${enc(callee)}(${args.join(",")})`;
748
- }
749
- case "ObjectExpression":
750
- return `{${n.properties
751
- .map((p) => {
752
- if (p.type !== "Property" || p.kind !== "init" || p.method)
753
- throw new Error(`datafy: unsupported property ${text(p)}`);
754
- let key;
755
- if (!p.computed && p.key.type === "Identifier")
756
- key = p.key.name;
757
- else if (p.key.type === "Literal")
758
- key = String(p.key.value);
759
- else
760
- throw new Error(`datafy: unsupported key ${text(p)}`);
761
- return `${IDENT.test(key) ? key : quote(key)}:${enc(p.value)}`;
762
- })
763
- .join(",")}}`;
764
- case "ArrayExpression":
765
- return `[${n.elements
766
- .map((e) => {
767
- if (!e || e.type === "SpreadElement")
768
- throw new Error("datafy: array hole or spread");
769
- return enc(e);
770
- })
771
- .join(",")}]`;
772
- case "ArrowFunctionExpression":
773
- if (n.params.length || n.body.type === "BlockStatement")
774
- throw new Error(`datafy: unsupported function ${text(n).slice(0, 80)}`);
775
- {
776
- // The body becomes its own entry, so a reader never has to skip it.
777
- const j = h.entries.length;
778
- h.entries.push("");
779
- h.entries[j] = enc(n.body);
780
- return `>${j}`;
781
- }
782
- default:
783
- throw new Error(`datafy: unsupported ${n.type}: ${text(n).slice(0, 80)}`);
784
- }
785
- };
786
- for (const [k, h] of home)
787
- h.entries[h.local.get(k)] = encode(nodes.get(k), h);
788
- configs.forEach((c, i) => (opHolders[i].entries[0] = encode(c, opHolders[i])));
789
- for (const v of values)
790
- v.holder.entries[v.j] = v.code ? `$${v.holder.ref(v.code)}` : encode(v.nodes[0], v.holder, v);
791
- // Operations only: an error class's data is built on every construction.
792
- for (const h of opHolders.slice(0, operations))
793
- stemOf(h);
794
- // The data string is a single-quoted JS literal.
795
- const literal = (h) => {
796
- const data = `'${h.entries.join(";").replace(/[\\']/g, (c) => `\\${c}`)}'`;
797
- const refs = `[${(aliased ? h.refs : ["__L.at", ...h.refs.slice(1)]).join(", ")}]`;
798
- return h.stem ? `API.named(${quote(h.stem)}, ${data}, ${refs})` : `[${data}, ${refs}]`;
799
- };
800
- const edits = [];
801
- for (const st of removals) {
802
- let end = st.end;
803
- while (code[end] === "\n")
804
- end++;
805
- edits.push([st.start, end, ""]);
806
- }
807
- ops.forEach((o, i) => {
808
- if (o.error) {
809
- // A plain function, not an arrow: it is the class (`new`, `instanceof`, `extends`).
810
- edits.push([
811
- o.init.start,
812
- o.init.end,
813
- `${o.error.exported ? "export " : ""}const ${o.name}${any} = /*@__PURE__*/ API.error(function ${o.name}(i${any})${any} {\n return API.newError(i, new.target, ${literal(opHolders[i])});\n});`,
814
- ]);
815
- return;
816
- }
817
- const fn = o.paginated ? "API.opPaginated" : "API.op";
818
- const marked = /\/\*[@#]__PURE__\*\/\s*$/.test(code.slice(o.init.start - 20, o.init.start));
819
- edits.push([
820
- o.init.start,
821
- o.init.end,
822
- `${marked ? "" : "/*@__PURE__*/ "}${fn}((i${any})${any} => i === API.D ? ${literal(opHolders[i])} : API.call(${o.name}, i))`,
823
- ]);
824
- });
825
- // Module-level code that names a schema at import (error classes).
826
- for (const st of otherRoots)
827
- walk(st, (n) => {
828
- const k = tableRef(n);
829
- if (!k)
830
- return true;
831
- const target = home.get(k);
832
- edits.push([n.start, n.end, `API.schema(${target.name}, ${target.local.get(k)})`]);
833
- return false;
834
- });
835
- edits.sort((a, b) => b[0] - a[0]);
836
- let out = code;
837
- for (const [s, e, t] of edits)
838
- out = out.slice(0, s) + t + out.slice(e);
839
- out = out.replace(/\n*$/, "\n").replace(/^\/\/ Schema table, filled on first reach.*\n/m, "");
840
- if (shared.size)
841
- out +=
842
- "\n// Shared schema data (see `op` in core/api).\n" +
843
- [...shared.values()]
844
- .map((h) => `function ${h.name}()${any} {\n return ${literal(h)};\n}\n`)
845
- .join("");
846
- // Aliases go right after the imports: error classes reach schemas while the module evaluates.
847
- const lastImport = [...body].reverse().find((st) => st.type === "ImportDeclaration");
848
- const at = lastImport ? lastImport.end : 0;
849
- const decls = aliased ? [...aliases].map(([t, a]) => `const ${a} = ${t};`) : [];
850
- out = `${out.slice(0, at)}\n${decls.join("\n")}${out.slice(at)}`;
851
- return { code: out, operations, holders: shared.size, errors: errors.length };
852
- };
853
- //# sourceMappingURL=datafy.js.map