@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
package/lib/retry.js CHANGED
@@ -1,197 +1 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
- import * as Context from "effect/Context";
11
- import * as Duration from "effect/Duration";
12
- import * as Effect from "effect/Effect";
13
- import { pipe } from "effect/Function";
14
- import * as Layer from "effect/Layer";
15
- import * as Option from "effect/Option";
16
- import * as Ref from "effect/Ref";
17
- import * as Schedule from "effect/Schedule";
18
- import { isThrottling, isTransientError } from "./category.js";
19
- // ============================================================================
20
- // Retry Service Factory
21
- // ============================================================================
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
- export const makeRetryService = (name) => Context.Service()(name);
35
- // ============================================================================
36
- // Retry Schedule Utilities
37
- // ============================================================================
38
-
39
-
40
-
41
-
42
- export const jittered = /*@__PURE__*/ Schedule.addDelay(() => Effect.succeed(Duration.millis(Math.random() * 50)));
43
-
44
-
45
-
46
- export const capped = (max) => Schedule.modifyDelay(({ duration }) => Effect.succeed(Duration.isGreaterThan(duration, max) ? max : duration));
47
- // ============================================================================
48
- // Server Hint Helpers
49
- // ============================================================================
50
-
51
-
52
-
53
-
54
-
55
- export const DEFAULT_SERVER_RETRY_HINT_CAP_MS = 60_000;
56
- const ENV_SERVER_RETRY_HINT_CAP_MS = "DISTILLED_SERVER_RETRY_HINT_CAP_MS";
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
- export const ServerRetryHintCapMs = /*@__PURE__*/ Context.Service("@distilled.cloud/core/ServerRetryHintCapMs");
70
-
71
-
72
-
73
- export const serverRetryHintCapLayer = (capMs) => Layer.succeed(ServerRetryHintCapMs, capMs);
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
- export const readServerRetryHintCapMsFromEnv = () => parseCapMs(globalThis.process?.env?.[ENV_SERVER_RETRY_HINT_CAP_MS]);
85
- const parseCapMs = (raw) => {
86
- if (raw === undefined || raw === "")
87
- return DEFAULT_SERVER_RETRY_HINT_CAP_MS;
88
- const n = Number(raw);
89
- return Number.isFinite(n) && n >= 0 ? Math.trunc(n) : DEFAULT_SERVER_RETRY_HINT_CAP_MS;
90
- };
91
-
92
-
93
-
94
-
95
-
96
-
97
- const CONFIG_PROVIDER_KEY = "effect/ConfigProvider";
98
- export const resolveServerRetryHintCapMs = () => Effect.gen(function* () {
99
- const fromLayer = yield* Effect.serviceOption(ServerRetryHintCapMs);
100
- if (Option.isSome(fromLayer)) {
101
- const n = fromLayer.value;
102
- if (Number.isFinite(n) && n >= 0)
103
- return Math.trunc(n);
104
- }
105
- const provider = (yield* Effect.context()).mapUnsafe.get(CONFIG_PROVIDER_KEY);
106
- if (!provider)
107
- return readServerRetryHintCapMsFromEnv();
108
- const node = yield* provider
109
- .load([ENV_SERVER_RETRY_HINT_CAP_MS])
110
- .pipe(Effect.orElseSucceed(() => undefined));
111
- return parseCapMs(node?._tag === "Value" ? node.value : undefined);
112
- });
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
- export const serverHintMillis = (error, capMs) => {
121
- const hint = error?.retryAfter;
122
- if (!Duration.isDuration(hint))
123
- return undefined;
124
- return Math.min(Duration.toMillis(hint), capMs);
125
- };
126
-
127
-
128
-
129
-
130
-
131
-
132
- const honorServerHint = (lastError, baseline) => Schedule.modifyDelay(Effect.fnUntraced(function* ({ duration }) {
133
- const capMs = yield* resolveServerRetryHintCapMs();
134
- const error = yield* Ref.get(lastError);
135
- const hint = serverHintMillis(error, capMs);
136
- if (hint !== undefined)
137
- return hint;
138
- const adjusted = baseline ? baseline(duration, error) : duration;
139
- return Duration.toMillis(adjusted);
140
- }));
141
- // ============================================================================
142
- // Default Retry Policies
143
- // ============================================================================
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
- export const defaultOptions = {
165
- while: (error) => isTransientError(error),
166
- backoff: {
167
- baseMs: 250,
168
- factor: 2,
169
- capMs: 5000,
170
- maxRetries: 8,
171
- jitterMs: 50,
172
- minThrottleMs: 500,
173
- serverHint: true,
174
- },
175
- };
176
- export const makeDefault = () => defaultOptions;
177
- const slowBackoff = {
178
- baseMs: 1000,
179
- factor: 2,
180
- capMs: 5000,
181
- jitterMs: 50,
182
- serverHint: true,
183
- };
184
- const slowBackoffNoHint = { baseMs: 1000, factor: 2, capMs: 5000, jitterMs: 50 };
185
- export const throttlingFactory = () => throttlingFactoryOptions;
186
- const throttlingFactoryOptions = {
187
- while: (error) => isThrottling(error),
188
- backoff: slowBackoff,
189
- };
190
- export const throttlingOptions = {
191
- while: (error) => isThrottling(error),
192
- backoff: slowBackoffNoHint,
193
- };
194
- export const transientFactory = () => transientFactoryOptions;
195
- const transientFactoryOptions = { while: isTransientError, backoff: slowBackoff };
196
- export const transientOptions = { while: isTransientError, backoff: slowBackoffNoHint };
197
- //# sourceMappingURL=retry.js.map
1
+ export { retry$DEFAULT_SERVER_RETRY_HINT_CAP_MS as DEFAULT_SERVER_RETRY_HINT_CAP_MS, retry$ServerRetryHintCapMs as ServerRetryHintCapMs, retry$capped as capped, retry$defaultOptions as defaultOptions, retry$jittered as jittered, retry$makeDefault as makeDefault, retry$makeRetryService as makeRetryService, retry$readServerRetryHintCapMsFromEnv as readServerRetryHintCapMsFromEnv, retry$resolveServerRetryHintCapMs as resolveServerRetryHintCapMs, retry$serverHintMillis as serverHintMillis, retry$serverRetryHintCapLayer as serverRetryHintCapLayer, retry$throttlingFactory as throttlingFactory, retry$throttlingOptions as throttlingOptions, retry$transientFactory as transientFactory, retry$transientOptions as transientOptions } from "./_bundle/base.js";
@@ -1,341 +1 @@
1
- import * as Data from "effect/Data";
2
- import { pipeArguments } from "effect/Pipeable";
3
-
4
- export const liteKey = "~lite";
5
- const node = (n) => Object.assign(n, { [liteKey]: true });
6
- const Proto = {
7
- "~lite": true,
8
- pipe() {
9
- return pipeArguments(this, arguments);
10
- },
11
- annotate(annotations) {
12
- return make({ ...this.ast, annotations: { ...this.ast.annotations, ...annotations } }, this);
13
- },
14
- };
15
- const make = (ast, from) => {
16
- const self = Object.create(Proto);
17
- self.ast = ast;
18
- // Struct `.fields` and record `.key`/`.value` travel with annotate.
19
- if (from)
20
- for (const k of ["fields", "key", "value"])
21
- if (k in from)
22
- self[k] = from[k];
23
- return self;
24
- };
25
-
26
- export const fromNode = (n) => make(node(n));
27
- export const isLite = (u) => (typeof u === "object" || typeof u === "function") && u !== null && u["~lite"] === true;
28
- const astOf = (s) => s.ast;
29
- //#region primitives
30
- export const String = /*@__PURE__*/ make(node({ _tag: "String" }));
31
- export const Number = /*@__PURE__*/ make(node({ _tag: "Number" }));
32
- export const Boolean = /*@__PURE__*/ make(node({ _tag: "Boolean" }));
33
- export const Unknown = /*@__PURE__*/ make(node({ _tag: "Unknown" }));
34
- export const Any = /*@__PURE__*/ make(node({ _tag: "Any" }));
35
- export const Null = /*@__PURE__*/ make(node({ _tag: "Null" }));
36
- export const Void = /*@__PURE__*/ make(node({ _tag: "Void" }));
37
- export const Undefined = /*@__PURE__*/ make(node({ _tag: "Undefined" }));
38
- //#endregion
39
- //#region combinators
40
- export const Literal = (value) => make(node({ _tag: "Literal", literal: value }));
41
- export const Literals = (values) => make(node({ _tag: "Union", types: values.map((v) => node({ _tag: "Literal", literal: v })) }));
42
- export const optional = (s) => {
43
- const inner = astOf(s);
44
- return make(node({
45
- _tag: "Union",
46
- types: [inner, node({ _tag: "Undefined" })],
47
- context: { isOptional: true },
48
- }));
49
- };
50
- export const NullOr = (s) => make(node({ _tag: "Union", types: [astOf(s), node({ _tag: "Null" })] }));
51
- export const Union = (members) => make(node({ _tag: "Union", types: members.map(astOf) }));
52
- export const Array = (item) => make(node({ _tag: "Arrays", elements: [], rest: [astOf(item)] }));
53
- export const Tuple = (elements) => make(node({ _tag: "Arrays", elements: elements.map(astOf), rest: [] }));
54
- export const Record = (key, value) => {
55
- const s = make(node({
56
- _tag: "Objects",
57
- propertySignatures: [],
58
- indexSignatures: [{ parameter: astOf(key), type: astOf(value) }],
59
- }));
60
- s.key = key;
61
- s.value = value;
62
- return s;
63
- };
64
- export const Struct = (fields) => {
65
- const s = make(node({
66
- _tag: "Objects",
67
- propertySignatures: Object.keys(fields).map((name) => {
68
- const type = astOf(fields[name]);
69
- return { name, type };
70
- }),
71
- indexSignatures: [],
72
- }));
73
- s.fields = fields;
74
- return s;
75
- };
76
-
77
-
78
-
79
-
80
-
81
-
82
- export const StructWithRest = (struct, records) => {
83
- const base = resolveObjects(astOf(struct));
84
- const s = make(node({
85
- _tag: "Objects",
86
- propertySignatures: base.propertySignatures ?? [],
87
- indexSignatures: [
88
- ...(base.indexSignatures ?? []),
89
- ...records.flatMap((r) => resolveObjects(astOf(r)).indexSignatures ?? []),
90
- ],
91
- }));
92
- s.fields = struct.fields;
93
- return s;
94
- };
95
- const resolveObjects = (n) => (n._tag === "Suspend" ? resolveObjects(n.thunk()) : n);
96
-
97
- export const suspend = (f) => {
98
- let resolved;
99
- return make(node({ _tag: "Suspend", thunk: () => (resolved ??= astOf(f())) }));
100
- };
101
-
102
- export const encodeKeys = (mapping) => (s) => s.annotate({ [encodeKeysKey]: mapping });
103
- export const encodeKeysKey = "@distilled.cloud/core/schema-lite/encodeKeys";
104
- //#endregion
105
- //#region declarations and errors
106
- const declaration = (identifier) => make(node({ _tag: "Declaration", typeParameters: [], annotations: { identifier } }));
107
- export const Date = /*@__PURE__*/ declaration("Date");
108
- export const Duration = /*@__PURE__*/ declaration("Duration");
109
- export const Redacted = (value) => make(node({
110
- _tag: "Declaration",
111
- typeParameters: [astOf(value)],
112
- annotations: { identifier: "Redacted" },
113
- }));
114
- export const instanceOf = (cls, annotations) => make(node({
115
- _tag: "Declaration",
116
- typeParameters: [],
117
- annotations: { identifier: cls.name, ...annotations },
118
- }));
119
- export const declare = (_is, annotations) => make(node({ _tag: "Declaration", typeParameters: [], annotations: { ...annotations } }));
120
-
121
-
122
-
123
-
124
-
125
-
126
- const tagKey = "~distilled/tag";
127
- const keysKey = "~distilled/keys";
128
- const astKey = "~distilled/ast";
129
- const annotationsKey = "~distilled/annotations";
130
- const annotationMetaKey = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/annotation-meta");
131
-
132
-
133
-
134
-
135
- const ownAnnotations = (from) => {
136
- const out = {};
137
- for (const k of Reflect.ownKeys(from))
138
- if (k !== annotationMetaKey && Object.prototype.propertyIsEnumerable.call(from, k))
139
- out[k] = from[k];
140
- return out;
141
- };
142
-
143
-
144
-
145
-
146
-
147
-
148
- let liteErrorBase;
149
- const LiteErrorBase = () => (liteErrorBase ??= class LiteError extends Data.Error {
150
- constructor(props) {
151
- const keys = new.target[keysKey];
152
- const picked = {};
153
- if (props)
154
- for (const k of keys)
155
- if (props[k] !== undefined)
156
- picked[k] = props[k];
157
- super(picked);
158
- this._tag = new.target[tagKey];
159
- }
160
-
161
- static get ast() {
162
- const C = this;
163
- if (Object.hasOwn(C, astKey))
164
- return C[astKey];
165
- const fields = C.fields;
166
- return (C[astKey] = node({
167
- _tag: "Objects",
168
- propertySignatures: Object.keys(fields).map((name) => ({
169
- name,
170
- type: astOf(fields[name]),
171
- })),
172
- indexSignatures: [],
173
- annotations: { identifier: C[tagKey], ...C[annotationsKey] },
174
- }));
175
- }
176
- static pipe() {
177
- return pipeArguments(this, arguments);
178
- }
179
-
180
- static make(props) {
181
- return new this(props);
182
- }
183
-
184
-
185
-
186
-
187
- static is(u) {
188
- return typeof u === "object" && u !== null && u._tag === this[tagKey];
189
- }
190
- });
191
-
192
-
193
-
194
-
195
-
196
- export const TaggedError = (_identifier) => (tag, fields = {}, annotations) => {
197
- const C = class extends LiteErrorBase() {
198
- };
199
- C[tagKey] = tag;
200
- C[keysKey] = Object.keys(fields);
201
- if (annotations)
202
- C[annotationsKey] = ownAnnotations(annotations);
203
- C.fields = fields;
204
- C.identifier = tag;
205
- C.prototype.name = tag;
206
- return C;
207
- };
208
-
209
-
210
-
211
-
212
-
213
- export const at = (build, j) => {
214
- const self = Object.create(AtProto);
215
- self.b = build;
216
- self.j = j;
217
- return self;
218
- };
219
- const resolveAt = (self) => (self.s ??= self.b(self.j));
220
- const AtProto = /*@__PURE__*/ Object.create(Proto, {
221
- ast: {
222
- get() {
223
- return resolveAt(this).ast;
224
- },
225
- },
226
- fields: {
227
- get() {
228
- return resolveAt(this).fields;
229
- },
230
- },
231
- key: {
232
- get() {
233
- return resolveAt(this).key;
234
- },
235
- },
236
- value: {
237
- get() {
238
- return resolveAt(this).value;
239
- },
240
- },
241
- });
242
- export const toEffect = (S, ast) => {
243
- const memo = new Map();
244
- // Whether a lite node sits anywhere under `n` (cycles count as no).
245
- const liteBelow = new Map();
246
- const hasLite = (n) => {
247
- const known = liteBelow.get(n);
248
- if (known !== undefined)
249
- return known;
250
- liteBelow.set(n, false);
251
- const kids = [
252
- ...(n.types ?? []),
253
- ...(n.elements ?? []),
254
- ...(n.rest ?? []),
255
- ...(n.typeParameters ?? []),
256
- ...(n.propertySignatures ?? []).map((p) => p.type),
257
- ...(n.indexSignatures ?? []).flatMap((i) => [i.parameter, i.type]),
258
- ...(n.encoding ?? []).map((l) => l.to),
259
- ...(n._tag === "Suspend" && n.thunk ? [n.thunk()] : []),
260
- ];
261
- const r = !!n[liteKey] || kids.some(hasLite);
262
- liteBelow.set(n, r);
263
- return r;
264
- };
265
- const build = (n) => {
266
- const hit = memo.get(n);
267
- if (hit)
268
- return hit;
269
- // A real Effect subtree with nothing lite below keeps its exact schema.
270
- if (!n[liteKey] && !hasLite(n)) {
271
- const real = S.make(n);
272
- memo.set(n, real);
273
- return real;
274
- }
275
- let out;
276
- switch (n._tag) {
277
- case "String":
278
- out = S.String;
279
- break;
280
- case "Number":
281
- out = S.Number;
282
- break;
283
- case "Boolean":
284
- out = S.Boolean;
285
- break;
286
- case "Null":
287
- out = S.Null;
288
- break;
289
- case "Undefined":
290
- out = S.Undefined;
291
- break;
292
- case "Void":
293
- out = S.Void;
294
- break;
295
- case "Any":
296
- out = S.Any;
297
- break;
298
- case "Literal":
299
- out = S.Literal(n.literal);
300
- break;
301
- case "Union":
302
- out = n.context?.isOptional
303
- ? S.optional(build(n.types[0]))
304
- : S.Union(n.types.map(build));
305
- break;
306
- case "Arrays":
307
- out = n.rest.length ? S.Array(build(n.rest[0])) : S.Tuple(n.elements.map(build));
308
- break;
309
- case "Objects": {
310
- const props = n.propertySignatures ?? [];
311
- const records = (n.indexSignatures ?? []).map((i) => S.Record(build(i.parameter), build(i.type)));
312
- if (props.length === 0 && records.length === 1) {
313
- out = records[0];
314
- break;
315
- }
316
- const struct = S.Struct(Object.fromEntries(props.map((p) => [p.name, build(p.type)])));
317
- out = records.length ? S.StructWithRest(struct, records) : struct;
318
- break;
319
- }
320
- case "Suspend": {
321
- const thunk = n.thunk;
322
- out = S.suspend(() => build(thunk()));
323
- break;
324
- }
325
- case "Declaration":
326
- out = n.check ? S.declare(n.check) : S.Unknown;
327
- break;
328
- case "Unknown":
329
- out = S.Unknown;
330
- break;
331
- default:
332
- // A lite tag with no case maps to Unknown; a real node keeps its schema.
333
- out = n[liteKey] ? S.Unknown : S.make(n);
334
- }
335
- memo.set(n, out);
336
- return out;
337
- };
338
- return build(ast);
339
- };
340
- //#endregion
341
- //# sourceMappingURL=schema-lite-impl.js.map
1
+ export { schema_lite_impl$Any as Any, schema_lite_impl$Array as Array, schema_lite_impl$Boolean as Boolean, schema_lite_impl$Date as Date, schema_lite_impl$Duration as Duration, schema_lite_impl$Literal as Literal, schema_lite_impl$Literals as Literals, schema_lite_impl$Null as Null, schema_lite_impl$NullOr as NullOr, schema_lite_impl$Number as Number, schema_lite_impl$Record as Record, schema_lite_impl$Redacted as Redacted, schema_lite_impl$String as String, schema_lite_impl$Struct as Struct, schema_lite_impl$StructWithRest as StructWithRest, schema_lite_impl$TaggedError as TaggedError, schema_lite_impl$Tuple as Tuple, schema_lite_impl$Undefined as Undefined, schema_lite_impl$Union as Union, schema_lite_impl$Unknown as Unknown, schema_lite_impl$Void as Void, schema_lite_impl$at as at, schema_lite_impl$declare as declare, schema_lite_impl$encodeKeys as encodeKeys, schema_lite_impl$encodeKeysKey as encodeKeysKey, schema_lite_impl$fromNode as fromNode, schema_lite_impl$instanceOf as instanceOf, schema_lite_impl$isLite as isLite, schema_lite_impl$liteKey as liteKey, schema_lite_impl$optional as optional, schema_lite_impl$suspend as suspend, schema_lite_impl$toEffect as toEffect } from "./_bundle/base.js";
@@ -1,27 +1 @@
1
- import * as L from "./schema-lite-impl.js";
2
- export const optional = L.optional;
3
- export const Struct = L.Struct;
4
- export const StructWithRest = L.StructWithRest;
5
- export const suspend = L.suspend;
6
- export const Array = L.Array;
7
- export const Record = L.Record;
8
- export const Union = L.Union;
9
- export const Literal = L.Literal;
10
- export const Literals = L.Literals;
11
- export const NullOr = L.NullOr;
12
- export const Tuple = L.Tuple;
13
- export const declare = L.declare;
14
- export const instanceOf = L.instanceOf;
15
- export const Redacted = L.Redacted;
16
- export const String = L.String;
17
- export const Number = L.Number;
18
- export const Int = L.Number;
19
- export const Boolean = L.Boolean;
20
- export const Date = L.Date;
21
- export const Duration = L.Duration;
22
- export const Unknown = L.Unknown;
23
- export const Null = L.Null;
24
- export const Void = L.Void;
25
- export const Any = L.Any;
26
- export const TaggedError = L.TaggedError;
27
- //# sourceMappingURL=schema-lite-typed.js.map
1
+ export { schema_lite_typed$Any as Any, schema_lite_typed$Array as Array, schema_lite_typed$Boolean as Boolean, schema_lite_typed$Date as Date, schema_lite_typed$Duration as Duration, schema_lite_typed$Int as Int, schema_lite_typed$Literal as Literal, schema_lite_typed$Literals as Literals, schema_lite_typed$Null as Null, schema_lite_typed$NullOr as NullOr, schema_lite_typed$Number as Number, schema_lite_typed$Record as Record, schema_lite_typed$Redacted as Redacted, schema_lite_typed$String as String, schema_lite_typed$Struct as Struct, schema_lite_typed$StructWithRest as StructWithRest, schema_lite_typed$TaggedError as TaggedError, schema_lite_typed$Tuple as Tuple, schema_lite_typed$Union as Union, schema_lite_typed$Unknown as Unknown, schema_lite_typed$Void as Void, schema_lite_typed$declare as declare, schema_lite_typed$instanceOf as instanceOf, schema_lite_typed$optional as optional, schema_lite_typed$suspend as suspend } from "./_bundle/base.js";
@@ -1,31 +1 @@
1
- import * as L from "./schema-lite-impl.js";
2
- export const optional = L.optional;
3
- export const Struct = L.Struct;
4
- export const StructWithRest = L.StructWithRest;
5
- export const suspend = L.suspend;
6
- export const Array = L.Array;
7
- export const Record = L.Record;
8
- export const Union = L.Union;
9
- export const Literal = L.Literal;
10
- export const Literals = L.Literals;
11
- export const NullOr = L.NullOr;
12
- export const Tuple = L.Tuple;
13
- export const encodeKeys = L.encodeKeys;
14
- export const declare = L.declare;
15
- export const instanceOf = L.instanceOf;
16
- export const Redacted = L.Redacted;
17
- export const String = L.String;
18
- export const Number = L.Number;
19
- export const Int = L.Number;
20
- export const Boolean = L.Boolean;
21
- export const Date = L.Date;
22
- export const Duration = L.Duration;
23
- export const Unknown = L.Unknown;
24
- export const Null = L.Null;
25
- export const Void = L.Void;
26
- export const Any = L.Any;
27
- export const TaggedError = L.TaggedError;
28
-
29
- export const at = L.at;
30
- export { liteKey, toEffect } from "./schema-lite-impl.js";
31
- //# sourceMappingURL=schema-lite.js.map
1
+ export { schema_lite$Any as Any, schema_lite$Array as Array, schema_lite$Boolean as Boolean, schema_lite$Date as Date, schema_lite$Duration as Duration, schema_lite$Int as Int, schema_lite$Literal as Literal, schema_lite$Literals as Literals, schema_lite$Null as Null, schema_lite$NullOr as NullOr, schema_lite$Number as Number, schema_lite$Record as Record, schema_lite$Redacted as Redacted, schema_lite$String as String, schema_lite$Struct as Struct, schema_lite$StructWithRest as StructWithRest, schema_lite$TaggedError as TaggedError, schema_lite$Tuple as Tuple, schema_lite$Union as Union, schema_lite$Unknown as Unknown, schema_lite$Void as Void, schema_lite$at as at, schema_lite$declare as declare, schema_lite$encodeKeys as encodeKeys, schema_lite$instanceOf as instanceOf, schema_lite$liteKey as liteKey, schema_lite$optional as optional, schema_lite$suspend as suspend, schema_lite$toEffect as toEffect } from "./_bundle/rest.js";