@distilled.cloud/core 1.0.0-rc.15 → 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
package/src/schema.ts CHANGED
@@ -5,32 +5,39 @@
5
5
  * provider package via `@distilled.cloud/core/schema`. Do not copy it into
6
6
  * individual packages.
7
7
  *
8
- * Every real TYPE (`Schema`, `Codec`, `Top`, …) is re-exported untouched, so
8
+ * Every real TYPE (`Schema`, `Codec`, `Top`, ...) is re-exported untouched, so
9
9
  * the `Schema.Schema<Foo>` annotations on generated consts (and the public
10
10
  * `.d.ts`) stay precise. The schema *construction surface* (`Struct`,
11
- * `optional`, `suspend`, …) and the leaf scalar schemas are retyped to `any`,
11
+ * `optional`, `suspend`, ...) and the leaf scalar schemas are retyped to `any`,
12
12
  * so the compiler instantiates none of the heavy Schema generics while
13
- * building a service file — the explicit annotations carry the real types.
13
+ * building a service file -- the explicit annotations carry the real types.
14
14
  *
15
15
  * Overriding a *value* export never affects the same-named *type* export (they
16
16
  * live in separate namespaces and continue to flow through `export *`), so
17
17
  * `Schema.Literal<"x">`-style type usages remain precise.
18
18
  *
19
- * Runtime behaviour is identical — every override aliases the exact same
20
- * runtime value from `effect/Schema`.
19
+ * Runtime behaviour is identical. Every override aliases the exact same
20
+ * runtime value from `effect/Schema`, except `suspend`, `Array` and
21
+ * `Record`, which build the same schema lazily (see "Lazy schemas").
21
22
  */
22
- export * from "effect/Schema";
23
+ // Types only: a value `export *` costs one binding per Effect Schema export
24
+ // (345 of them, ~70 KB) in every process that imports an SDK. The values
25
+ // generated and hand-written code use are re-exported explicitly below.
26
+ export type * from "effect/Schema";
27
+ export { declare, Duration, instanceOf, Redacted } from "effect/Schema";
23
28
 
29
+ import { pipeArguments } from "effect/Pipeable";
24
30
  import * as S from "effect/Schema";
25
31
 
26
32
  export type AnyFn = (...args: any[]) => any;
27
33
 
28
- // Construction surface — collapse to `any` so generics are never instantiated.
34
+ // Construction surface -- collapse to `any` so generics are never instantiated.
29
35
  export const optional: AnyFn = S.optional as AnyFn;
30
36
  export const Struct: AnyFn = S.Struct as AnyFn;
31
- export const suspend: AnyFn = S.suspend as AnyFn;
32
- export const Array: AnyFn = S.Array as AnyFn;
33
- export const Record: AnyFn = S.Record as AnyFn;
37
+ export const StructWithRest: AnyFn = S.StructWithRest as AnyFn;
38
+ export const suspend: AnyFn = (f: () => S.Top) => lazySuspend(f);
39
+ export const Array: AnyFn = (item: S.Top) => lazyArray(item);
40
+ export const Record: AnyFn = (key: S.Top, value: S.Top) => lazyRecord(key, value);
34
41
  export const Union: AnyFn = S.Union as AnyFn;
35
42
  export const Literal: AnyFn = S.Literal as AnyFn;
36
43
  export const Literals: AnyFn = S.Literals as AnyFn;
@@ -38,7 +45,7 @@ export const NullOr: AnyFn = S.NullOr as AnyFn;
38
45
  export const Tuple: AnyFn = S.Tuple as AnyFn;
39
46
  export const encodeKeys: AnyFn = S.encodeKeys as AnyFn;
40
47
 
41
- // Leaf schemas — collapse to `any` so `.pipe(...)` on them is free.
48
+ // Leaf schemas -- collapse to `any` so `.pipe(...)` on them is free.
42
49
  export const String: any = S.String;
43
50
  export const Number: any = S.Number;
44
51
  export const Boolean: any = S.Boolean;
@@ -48,6 +55,243 @@ export const Null: any = S.Null;
48
55
  export const Void: any = S.Void;
49
56
  export const Any: any = S.Any;
50
57
 
51
- // NOTE: `Schema` / `Codec` (types) and `TaggedError` are intentionally NOT
52
- // overridden — they flow through `export *` with real types so cast targets and
53
- // typed error classes stay precise.
58
+ // NOTE: `Schema` / `Codec` (types) are intentionally NOT overridden -- they
59
+ // flow through `export *` with real types so cast targets stay precise.
60
+ // `TaggedError` is overridden with the same type (see "Lazy error classes").
61
+
62
+ //#region Lazy schemas
63
+
64
+ /**
65
+ * Schemas whose real Effect schema is built on first use instead of at
66
+ * import.
67
+ *
68
+ * A service module declares every schema as a top-level const, and
69
+ * importing it constructs all of them: EC2 has 2,575 `S.suspend(...)` and
70
+ * 784 `S.Array(...)` consts, Elasticsearch 3,272 and 2,265. An Effect schema
71
+ * is a function object plus an AST node (a `suspend` also a wrapper
72
+ * closure), and `.annotate` copies both: about 550 bytes per suspend, more
73
+ * for an array whose item it forces. A lazy schema is one small object
74
+ * holding how to build the real one and any annotations added before then:
75
+ * about 180 bytes.
76
+ *
77
+ * It inherits Effect's own schema prototype, so `pipe`, `annotate`, `make`,
78
+ * `isSchema` and every combinator see a schema. On first use of `.ast` (or
79
+ * of an own member such as an array's `value`) it builds the real schema --
80
+ * `build().annotate(annotations)`, exactly what eager code would have made --
81
+ * and copies the real schema's own properties onto itself, so from then on
82
+ * it IS that schema: same AST (memoized, stable identity), same rebuild
83
+ * options for later `.annotate` / `.check` calls.
84
+ */
85
+ const SchemaProto: object = /*@__PURE__*/ Object.getPrototypeOf(S.String);
86
+ const buildKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/build");
87
+ const annotationsKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/annotations");
88
+
89
+ type Annotations = Record<string, unknown>;
90
+
91
+ /**
92
+ * How a lazy schema builds itself: a closure, or a shared builder plus data
93
+ * stored on the schema object (no closure per schema; see packed.ts).
94
+ */
95
+ export interface LazyBuilder {
96
+ readonly build: (data: unknown) => S.Top;
97
+ }
98
+ const dataKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/data");
99
+
100
+ interface LazySchema {
101
+ [buildKey]?: (() => S.Top) | LazyBuilder;
102
+ [dataKey]?: unknown;
103
+ [annotationsKey]?: Annotations;
104
+ }
105
+
106
+ /** Build the real schema and become it. */
107
+ const force = (self: LazySchema): void => {
108
+ const build = self[buildKey];
109
+ if (!build) return;
110
+ const annotations = self[annotationsKey];
111
+ const built = typeof build === "function" ? build() : build.build(self[dataKey]);
112
+ const real = annotations ? built.annotate(annotations) : built;
113
+ delete self[buildKey];
114
+ delete self[dataKey];
115
+ delete self[annotationsKey];
116
+ Object.defineProperties(self, Object.getOwnPropertyDescriptors(real));
117
+ };
118
+
119
+ /** Members a built schema carries as own properties (array item, record key/value). */
120
+ const forwarded = (name: string): PropertyDescriptor => ({
121
+ configurable: true,
122
+ get(this: LazySchema & Record<string, unknown>) {
123
+ if (!this[buildKey]) return undefined;
124
+ force(this);
125
+ return this[name];
126
+ },
127
+ });
128
+
129
+ const LazyProto: object = /*@__PURE__*/ Object.create(SchemaProto, {
130
+ ast: /*@__PURE__*/ forwarded("ast"),
131
+ value: /*@__PURE__*/ forwarded("value"),
132
+ key: /*@__PURE__*/ forwarded("key"),
133
+ annotate: {
134
+ configurable: true,
135
+ writable: true,
136
+ value(this: LazySchema, annotations: Annotations) {
137
+ const build = this[buildKey];
138
+ // Once built, annotate like any schema (a rebuilt copy).
139
+ if (!build) return (SchemaProto as { annotate: Function }).annotate.call(this, annotations);
140
+ const previous = this[annotationsKey];
141
+ return lazy(build, previous ? { ...previous, ...annotations } : annotations, this[dataKey]);
142
+ },
143
+ },
144
+ });
145
+
146
+ // Effect detects schemas by this key on the prototype; if a future Effect
147
+ // moves it, build eagerly.
148
+ const supported = (SchemaProto as Record<string, unknown>)["~effect/Schema/Schema"] !== undefined;
149
+
150
+ const lazy = (
151
+ build: (() => S.Top) | LazyBuilder,
152
+ annotations?: Annotations,
153
+ data?: unknown,
154
+ ): S.Top => {
155
+ if (!supported) {
156
+ const built = typeof build === "function" ? build() : build.build(data);
157
+ return annotations ? built.annotate(annotations) : built;
158
+ }
159
+ const self = Object.create(LazyProto);
160
+ self[buildKey] = build;
161
+ if (data !== undefined) self[dataKey] = data;
162
+ if (annotations) self[annotationsKey] = annotations;
163
+ return self;
164
+ };
165
+
166
+ /** A schema built on first use by `builder.build(data)`. */
167
+ export const lazyFrom = (builder: LazyBuilder, data: unknown): S.Top =>
168
+ lazy(builder, undefined, data);
169
+
170
+ const lazySuspend = (f: () => S.Top): S.Top => lazy(() => S.suspend(f));
171
+ const lazyArray = (item: S.Top): S.Top => lazy(() => S.Array(item));
172
+ const lazyRecord = (key: S.Top, value: S.Top): S.Top => lazy(() => S.Record(key as any, value));
173
+
174
+ //#endregion
175
+
176
+ //#region Lazy error classes
177
+
178
+ /**
179
+ * `S.TaggedError` whose Effect class is built on first use instead of at
180
+ * import.
181
+ *
182
+ * Every error class Effect builds carries its own copies of about fifteen
183
+ * static methods plus a tagged struct schema: about 4.6 KB per class, and
184
+ * AWS EC2 alone declares 248 of them. This returns a small constructor that
185
+ * stands in for the class until something needs it -- constructing an
186
+ * instance, or a schema static such as `ast` / `fields` / `make`. Then it
187
+ * builds the real class with `S.TaggedError` and puts it underneath: the
188
+ * lazy class's prototype starts inheriting from the real prototype, and
189
+ * statics forward to the real class with `this` bound to the lazy class, so
190
+ * decoding produces instances of the lazy class (and of its subclasses).
191
+ *
192
+ * `pipe` (used to attach error categories), `identifier` and the schema
193
+ * marker answer without building. Instances behave as before: same
194
+ * `_tag`, fields, validation, `instanceof`, stack and `Effect.catchTag`.
195
+ */
196
+ const lazyErrorKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/schema/lazyError");
197
+
198
+ interface LazyErrorState {
199
+ readonly identifier: string | undefined;
200
+ readonly args: ReadonlyArray<unknown>;
201
+ readonly lazy: Function;
202
+ real?: Function;
203
+ }
204
+
205
+ const SchemaTypeId = "~effect/Schema/Schema";
206
+
207
+ // The base every Effect error class extends (`core.Error`, a yieldable
208
+ // Error). Found on first use, so bundles without error classes do not keep
209
+ // Effect's class machinery.
210
+ let errorBase: Function | undefined;
211
+ const ErrorBase = (): Function =>
212
+ (errorBase ??= Object.getPrototypeOf(S.TaggedError()("Probe", {})) as Function);
213
+
214
+ const realErrorClass = (cls: Function): Function => {
215
+ const state = (cls as unknown as Record<symbol, LazyErrorState>)[lazyErrorKey];
216
+ if (!state.real) {
217
+ const real = (S.TaggedError as Function)(state.identifier)(...state.args) as Function;
218
+ state.real = real;
219
+ Object.setPrototypeOf(state.lazy.prototype, real.prototype);
220
+ }
221
+ return state.real;
222
+ };
223
+
224
+ /** Effect's class statics that need the real class. */
225
+ const FORWARDED_STATICS = [
226
+ "ast",
227
+ "fields",
228
+ "make",
229
+ "makeOption",
230
+ "makeEffect",
231
+ "annotate",
232
+ "annotateKey",
233
+ "check",
234
+ "rebuild",
235
+ "extend",
236
+ "mapFields",
237
+ ];
238
+
239
+ let lazyErrorStatics: object | undefined;
240
+ const LazyErrorStatics = (): object =>
241
+ (lazyErrorStatics ??= Object.create(ErrorBase(), {
242
+ [SchemaTypeId]: { value: SchemaTypeId, configurable: true },
243
+ identifier: {
244
+ configurable: true,
245
+ get(this: Record<symbol, LazyErrorState>) {
246
+ const state = this[lazyErrorKey];
247
+ return state.identifier ?? state.args[0];
248
+ },
249
+ },
250
+ pipe: {
251
+ configurable: true,
252
+ writable: true,
253
+ value(this: unknown) {
254
+ return pipeArguments(this, arguments);
255
+ },
256
+ },
257
+ ...Object.fromEntries(
258
+ FORWARDED_STATICS.map((name) => [
259
+ name,
260
+ {
261
+ configurable: true,
262
+ get(this: Function) {
263
+ let owner: object | null = realErrorClass(this);
264
+ let descriptor: PropertyDescriptor | undefined;
265
+ while (owner && !(descriptor = Object.getOwnPropertyDescriptor(owner, name))) {
266
+ owner = Object.getPrototypeOf(owner);
267
+ }
268
+ if (!descriptor) return undefined;
269
+ if (descriptor.get) return descriptor.get.call(this);
270
+ return typeof descriptor.value === "function"
271
+ ? descriptor.value.bind(this)
272
+ : descriptor.value;
273
+ },
274
+ },
275
+ ]),
276
+ ),
277
+ }));
278
+
279
+ const lazyTaggedError =
280
+ (identifier?: string) =>
281
+ (...args: ReadonlyArray<unknown>): Function => {
282
+ function LazyTaggedError(this: unknown, input?: unknown, options?: unknown) {
283
+ if (!new.target) throw new TypeError("Class constructor cannot be invoked without 'new'");
284
+ return Reflect.construct(realErrorClass(new.target), [input, options], new.target);
285
+ }
286
+ Object.setPrototypeOf(LazyTaggedError, LazyErrorStatics());
287
+ LazyTaggedError.prototype = Object.create(ErrorBase().prototype, {
288
+ constructor: { value: LazyTaggedError, writable: true, configurable: true },
289
+ });
290
+ const state: LazyErrorState = { identifier, args, lazy: LazyTaggedError };
291
+ Object.defineProperty(LazyTaggedError, lazyErrorKey, { value: state });
292
+ return LazyTaggedError;
293
+ };
294
+
295
+ export const TaggedError: typeof S.TaggedError = lazyTaggedError as typeof S.TaggedError;
296
+
297
+ //#endregion
package/src/testing.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Test helpers for SDK packages: a canned-response `HttpClient` and a runner
3
- * that executes one operation under both response-validation modes.
3
+ * that executes one operation under every response-validation mode.
4
4
  *
5
5
  * ```ts
6
6
  * const { lenient, strict } = await runValidationModes(
@@ -52,13 +52,14 @@ export const mockHttpClient = (
52
52
 
53
53
  /**
54
54
  * Run `effect` against `mockHttpClient(response)` once in lenient mode and
55
- * once in strict mode.
55
+ * once in each validating mode (`additionalProperties`, `strict`).
56
56
  */
57
57
  export const runValidationModes = <A, E>(
58
58
  effect: Effect.Effect<A, E, HttpClient.HttpClient>,
59
59
  response: Parameters<typeof mockHttpClient>[0],
60
60
  ): Promise<{
61
61
  readonly lenient: Result.Result<A, E>;
62
+ readonly additionalProperties: Result.Result<A, E>;
62
63
  readonly strict: Result.Result<A, E>;
63
64
  }> => {
64
65
  const run = (mode: Layer.Layer<never>) =>
@@ -66,6 +67,7 @@ export const runValidationModes = <A, E>(
66
67
  return Effect.runPromise(
67
68
  Effect.all({
68
69
  lenient: run(ResponseValidation.lenient),
70
+ additionalProperties: run(ResponseValidation.additionalProperties),
69
71
  strict: run(ResponseValidation.strict),
70
72
  }),
71
73
  );
package/src/trait.ts CHANGED
@@ -1,4 +1,6 @@
1
- export const annotationMetaSymbol = Symbol.for("@distilled.cloud/core/annotation-meta");
1
+ export const annotationMetaSymbol = /*@__PURE__*/ Symbol.for(
2
+ "@distilled.cloud/core/annotation-meta",
3
+ );
2
4
 
3
5
  export type Annotatable = {
4
6
  annotate(annotations: any): Annotatable;
@@ -18,7 +20,7 @@ export interface Annotation {
18
20
  * Build a pipeable schema annotation carrying `value` under `sym`. Exported
19
21
  * so SDK packages can define their own protocol traits (e.g. cloudflare's
20
22
  * envelope traits, aws's smithy traits) with the same mechanics as the
21
- * generic ones here. Keys may be symbols or plain strings — effect Schema
23
+ * generic ones here. Keys may be symbols or plain strings -- effect Schema
22
24
  * annotation dictionaries accept both.
23
25
  */
24
26
  export function makeAnnotation<T>(sym: symbol | string, value: T): Annotation {
@@ -29,7 +31,7 @@ export function makeAnnotation<T>(sym: symbol | string, value: T): Annotation {
29
31
  }
30
32
 
31
33
  /**
32
- * Combine several annotations into one — needed where only a single
34
+ * Combine several annotations into one -- needed where only a single
33
35
  * annotations object can be supplied (e.g. the second argument of
34
36
  * `S.Class`).
35
37
  */
@@ -63,7 +65,7 @@ export interface HttpTrait {
63
65
  readonly code?: number;
64
66
  /**
65
67
  * Request body encoding. Default is JSON; `"multipart"` sends
66
- * multipart/form-data — body members become form parts (objects
68
+ * multipart/form-data -- body members become form parts (objects
67
69
  * JSON-encoded) and members marked `FormDataFile()` append their files.
68
70
  * `"form-urlencoded"` sends application/x-www-form-urlencoded with
69
71
  * Stripe-style bracket notation for nested objects and arrays (see
@@ -80,13 +82,13 @@ export interface HttpTrait {
80
82
  /**
81
83
  * Explicit `Accept` for the operation, when the API serves more than one
82
84
  * response media type. Atlas pins an API version this way (e.g.
83
- * `application/vnd.atlas.2024-05-30+json` — `application/json` alone is a
85
+ * `application/vnd.atlas.2024-05-30+json` -- `application/json` alone is a
84
86
  * 406). Protocols that don't read it fall back to their own default.
85
87
  */
86
88
  readonly accept?: string;
87
89
  }
88
90
 
89
- export const httpSymbol = Symbol.for("@distilled.cloud/core/http");
91
+ export const httpSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http");
90
92
  /**
91
93
  * Operation-level HTTP binding: the request method + URI template. Stamped on
92
94
  * the input schema so the protocol can build the request line. URI `{labels}`
@@ -94,11 +96,13 @@ export const httpSymbol = Symbol.for("@distilled.cloud/core/http");
94
96
  */
95
97
  export const Http = (trait: HttpTrait) => makeAnnotation(httpSymbol, trait);
96
98
 
97
- export const labelSymbol = Symbol.for("@distilled.cloud/core/http/label");
99
+ export const labelSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/label");
98
100
  /** Bind a member to a `{name}` placeholder in the operation's URI template. */
99
101
  export const Label = (name?: string) => makeAnnotation(labelSymbol, name ?? true);
100
102
 
101
- export const labelEncodingSymbol = Symbol.for("@distilled.cloud/core/http/label-encoding");
103
+ export const labelEncodingSymbol = /*@__PURE__*/ Symbol.for(
104
+ "@distilled.cloud/core/http/label-encoding",
105
+ );
102
106
  /** Preserve selected RFC 3986 pchar delimiters inside a single URI label. */
103
107
  export const LabelEncoding = (options: { readonly preserve: string }) => {
104
108
  if (!/^[!$&'()*+,;=:@]*$/.test(options.preserve)) {
@@ -107,41 +111,45 @@ export const LabelEncoding = (options: { readonly preserve: string }) => {
107
111
  return makeAnnotation(labelEncodingSymbol, options.preserve);
108
112
  };
109
113
 
110
- export const responseCodeSymbol = Symbol.for("@distilled.cloud/core/http/response-code");
114
+ export const responseCodeSymbol = /*@__PURE__*/ Symbol.for(
115
+ "@distilled.cloud/core/http/response-code",
116
+ );
111
117
  export const ResponseCode = () => makeAnnotation(responseCodeSymbol, true);
112
118
 
113
- export const headerSymbol = Symbol.for("@distilled.cloud/core/http/header");
119
+ export const headerSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/header");
114
120
  export const Header = (name?: string) => makeAnnotation(headerSymbol, name ?? true);
115
121
 
116
- export const bodySymbol = Symbol.for("@distilled.cloud/core/http/body");
122
+ export const bodySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/body");
117
123
  export const Body = (name?: string) => makeAnnotation(bodySymbol, name ?? true);
118
124
 
119
- export const querySymbol = Symbol.for("@distilled.cloud/core/http/query");
125
+ export const querySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/query");
120
126
  export const Query = (name?: string) => makeAnnotation(querySymbol, name ?? true);
121
127
 
122
- export const deepQuerySymbol = Symbol.for("@distilled.cloud/core/http/deep-query");
128
+ export const deepQuerySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http/deep-query");
123
129
  /**
124
130
  * Binds a struct-valued input member to a family of DOTTED query parameters:
125
131
  * `{ account: { id, name } }` with `DeepQuery("account")` serializes as
126
- * `?account.id=…&account.name=…` (null/undefined entries skipped). This is
132
+ * `?account.id=...&account.name=...` (null/undefined entries skipped). This is
127
133
  * how several list endpoints model their filters on the wire (e.g.
128
134
  * Cloudflare zones list `account.id` / `account.name`) while the TS surface
129
135
  * keeps the nested-object shape (v0 parity).
130
136
  */
131
137
  export const DeepQuery = (name?: string) => makeAnnotation(deepQuerySymbol, name ?? true);
132
138
 
133
- export const httpBodySymbol = Symbol.for("@distilled.cloud/core/http-body");
139
+ export const httpBodySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/http-body");
134
140
  /**
135
141
  * Marks the input member whose value IS the entire request body (raw arrays/
136
- * scalars — e.g. endpoints that POST a bare JSON array). Mirrors
142
+ * scalars -- e.g. endpoints that POST a bare JSON array). Mirrors
137
143
  * `smithy.api#httpPayload`.
138
144
  */
139
145
  export const HttpBody = () => makeAnnotation(httpBodySymbol, true);
140
146
 
141
- export const stringEncodedSymbol = Symbol.for("@distilled.cloud/core/http/string-encoded");
147
+ export const stringEncodedSymbol = /*@__PURE__*/ Symbol.for(
148
+ "@distilled.cloud/core/http/string-encoded",
149
+ );
142
150
  /**
143
- * Marks a member the API only accepts as the STRING spelling of its value —
144
- * `true` travels as `"true"`, `3` as `"3"` — while the TS surface keeps the
151
+ * Marks a member the API only accepts as the STRING spelling of its value --
152
+ * `true` travels as `"true"`, `3` as `"3"` -- while the TS surface keeps the
145
153
  * natural type (e.g. Cloudflare's multipart `validation_enabled`, which the
146
154
  * docs model as the enum `"true" | "false"`). The protocol stringifies body
147
155
  * members on encode, element-wise for lists; `null` is left alone. Query and
@@ -150,7 +158,7 @@ export const stringEncodedSymbol = Symbol.for("@distilled.cloud/core/http/string
150
158
  */
151
159
  export const StringEncoded = () => makeAnnotation(stringEncodedSymbol, true);
152
160
 
153
- export const formDataFileSymbol = Symbol.for("@distilled.cloud/core/form-data-file");
161
+ export const formDataFileSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/form-data-file");
154
162
  /**
155
163
  * Marks an input member holding `File`/`Blob` parts for a multipart upload
156
164
  * (`Http({ contentType: "multipart" })`). Each file is appended to the form
@@ -161,9 +169,9 @@ export const FormDataFile = () => makeAnnotation(formDataFileSymbol, true);
161
169
 
162
170
  //#region Generic JSON traits
163
171
 
164
- export const keyDictionarySymbol = Symbol.for("@distilled.cloud/core/key-dictionary");
172
+ export const keyDictionarySymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/key-dictionary");
165
173
  /**
166
- * Deep TS-name→wire-name key dictionary for members whose full structure is
174
+ * Deep TS-name->wire-name key dictionary for members whose full structure is
167
175
  * not modeled (opaque `Document` content). The protocol renames any matching
168
176
  * key at any depth on encode (and the reverse on decode); keys not in the
169
177
  * dictionary pass through verbatim.
@@ -179,10 +187,10 @@ export type KeyDictionaryEntries = Record<string, string | ReadonlyArray<string>
179
187
  export const KeyDictionary = (dict: KeyDictionaryEntries) =>
180
188
  makeAnnotation(keyDictionarySymbol, dict);
181
189
 
182
- export const unionCasesSymbol = Symbol.for("@distilled.cloud/core/union-cases");
190
+ export const unionCasesSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/union-cases");
183
191
 
184
192
  /**
185
- * The literal member every case of a union fixes to its own value — what the
193
+ * The literal member every case of a union fixes to its own value -- what the
186
194
  * docs call the resource `type` or the action `id`. `values[i]` is the value
187
195
  * case `i` carries.
188
196
  */
@@ -198,8 +206,8 @@ export interface UnionDiscriminator {
198
206
  * sets to pick the active case and drop the others, so consumers' `"key" in
199
207
  * value` discrimination works.
200
208
  *
201
- * Key sets alone cannot tell apart cases that share them — the 41 resource
202
- * kinds of `resource_tagging`, the 34 page-rule actions — so when the union
209
+ * Key sets alone cannot tell apart cases that share them -- the 41 resource
210
+ * kinds of `resource_tagging`, the 34 page-rule actions -- so when the union
203
211
  * has a discriminator the protocol reads the case off it and only falls back
204
212
  * to key-set scoring for a value whose tag is missing or unknown.
205
213
  */
@@ -211,7 +219,7 @@ export const UnionCases = (
211
219
 
212
220
  //#region Error matcher traits
213
221
 
214
- export const errorMatchersSymbol = Symbol.for("@distilled.cloud/core/error-matchers");
222
+ export const errorMatchersSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/error-matchers");
215
223
 
216
224
  /** Exact text, or the conjunction of substring and regular-expression constraints. */
217
225
  export type ErrorTextMatcher = string | { readonly includes?: string; readonly matches?: string };
@@ -246,7 +254,7 @@ export interface ErrorMatcher {
246
254
  * Stamp wire-matching rules onto a generated error class. Protocols consult
247
255
  * these to decide which of an operation's declared error classes a failed
248
256
  * response should surface as (most specific matcher wins; ties break by
249
- * declaration order — see `matchTypedError` in `core/protocol-http`).
257
+ * declaration order -- see `matchTypedError` in `core/protocol-http`).
250
258
  */
251
259
  export const applyErrorMatchers = <C>(cls: C, matchers: ReadonlyArray<ErrorMatcher>): C => {
252
260
  (cls as any)[errorMatchersSymbol] = matchers;
package/src/xml.ts CHANGED
@@ -6,13 +6,14 @@ export interface XmlObject {
6
6
  [name: string]: XmlValue;
7
7
  }
8
8
 
9
- export class XmlParseError extends Data.TaggedError("XmlParseError")<{
10
- readonly message: string;
11
- /** UTF-16 offset in the original input; line and column are one-based. */
12
- readonly offset: number;
13
- readonly line: number;
14
- readonly column: number;
15
- }> {}
9
+ export class XmlParseError
10
+ extends /*@__PURE__*/ Data.TaggedError("XmlParseError")<{
11
+ readonly message: string;
12
+ /** UTF-16 offset in the original input; line and column are one-based. */
13
+ readonly offset: number;
14
+ readonly line: number;
15
+ readonly column: number;
16
+ }> {}
16
17
 
17
18
  export interface XmlParseOptions {
18
19
  /** Maximum open elements, including the root. Defaults to 256. */
@@ -34,10 +35,21 @@ const xmlSpace = /^[\t\n\r ]*$/;
34
35
  const declarationPattern =
35
36
  /^xml[\t\n\r ]+version[\t\n\r ]*=[\t\n\r ]*(?:"1\.0"|'1\.0')(?:[\t\n\r ]+encoding[\t\n\r ]*=[\t\n\r ]*(?:"[A-Za-z][A-Za-z0-9._-]*"|'[A-Za-z][A-Za-z0-9._-]*'))?(?:[\t\n\r ]+standalone[\t\n\r ]*=[\t\n\r ]*(?:"(?:yes|no)"|'(?:yes|no)'))?[\t\n\r ]*$/;
36
37
 
38
+ /**
39
+ * The prototype of every object the parser returns. It has no prototype
40
+ * itself, so element names such as `__proto__` or `constructor` are plain
41
+ * own keys, as with a null prototype -- but V8 keeps objects with a
42
+ * non-null prototype in fast mode, which makes parsing several times faster.
43
+ */
44
+ const nodeProto: object = /*@__PURE__*/ Object.create(null);
45
+
46
+ /** An ASCII XML name not followed by a non-ASCII (possibly name) character. */
47
+ const asciiName = /[A-Za-z_:][\w:.-]*(?![^\0-\x7f])/y;
48
+
37
49
  interface Element {
38
50
  name: string;
39
51
  object: XmlObject;
40
- text: string[];
52
+ text: string;
41
53
  hasChildren: boolean;
42
54
  hasAttributes: boolean;
43
55
  hasCdata: boolean;
@@ -58,7 +70,7 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
58
70
  const maxDepth = options.maxDepth ?? 256;
59
71
  const maxLength = options.maxLength ?? 64 * 1024 * 1024;
60
72
  const stack: Element[] = [];
61
- const document: XmlObject = Object.create(null);
73
+ const document: XmlObject = Object.create(nodeProto);
62
74
  let hasRoot = false;
63
75
 
64
76
  function fail(message: string, offset = pos): never {
@@ -92,14 +104,16 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
92
104
  }
93
105
 
94
106
  function readName(): string {
95
- namePattern.lastIndex = pos;
96
- const match = namePattern.exec(xml);
107
+ // ASCII names (most documents) match a cheaper, non-Unicode pattern first.
108
+ asciiName.lastIndex = namePattern.lastIndex = pos;
109
+ const match = asciiName.exec(xml) ?? namePattern.exec(xml);
97
110
  if (!match) fail("Expected XML name");
98
- pos = namePattern.lastIndex;
111
+ pos += match[0].length;
99
112
  return match[0];
100
113
  }
101
114
 
102
115
  function decode(raw: string, offset: number, attribute = false): string {
116
+ if (raw.indexOf("&") < 0 && !(attribute ? /[\t\r\n]/ : /\r/).test(raw)) return raw;
103
117
  const parts: string[] = [];
104
118
  let from = 0;
105
119
  while (from < raw.length) {
@@ -158,7 +172,7 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
158
172
  }
159
173
 
160
174
  function finish(element: Element): void {
161
- const text = element.text.join("");
175
+ const text = element.text;
162
176
  let value: XmlValue;
163
177
  if (!element.hasChildren && !element.hasAttributes) {
164
178
  value = text;
@@ -191,7 +205,7 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
191
205
  } else {
192
206
  const cdataEnd = raw.indexOf("]]>");
193
207
  if (cdataEnd >= 0) fail("Unexpected CDATA terminator", offset + cdataEnd);
194
- element.text.push(decode(raw, offset));
208
+ element.text += decode(raw, offset);
195
209
  }
196
210
  continue;
197
211
  }
@@ -207,7 +221,7 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
207
221
  if (!element) fail("CDATA outside root element");
208
222
  const end = xml.indexOf("]]>", pos + 9);
209
223
  if (end < 0) fail("Unterminated CDATA");
210
- element.text.push(xml.slice(pos + 9, end).replace(/\r\n?/g, "\n"));
224
+ element.text += xml.slice(pos + 9, end).replace(/\r\n?/g, "\n");
211
225
  element.hasCdata = true;
212
226
  pos = end + 3;
213
227
  } else if (xml.startsWith("<?", pos)) {
@@ -243,8 +257,8 @@ export function parseXmlSync(xml: string, options: XmlParseOptions = {}): XmlObj
243
257
  pos++;
244
258
  const element: Element = {
245
259
  name: readName(),
246
- object: Object.create(null),
247
- text: [],
260
+ object: Object.create(nodeProto),
261
+ text: "",
248
262
  hasChildren: false,
249
263
  hasAttributes: false,
250
264
  hasCdata: false,
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=boolean-string-enums.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"boolean-string-enums.test.d.ts","sourceRoot":"","sources":["../../src/codegen/boolean-string-enums.test.ts"],"names":[],"mappings":""}