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

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 (69) 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/api.d.ts.map +1 -1
  12. package/lib/api.js +1 -796
  13. package/lib/category.js +1 -278
  14. package/lib/chunks.js +1 -11
  15. package/lib/config.js +1 -161
  16. package/lib/crypto.js +1 -130
  17. package/lib/debug.js +1 -8
  18. package/lib/error-category.js +1 -47
  19. package/lib/errors.js +1 -198
  20. package/lib/graphql.js +1 -1058
  21. package/lib/graphql.types.js +1 -6
  22. package/lib/index.js +0 -15
  23. package/lib/json-patch.js +1 -226
  24. package/lib/json-patch.js.map +1 -1
  25. package/lib/pagination.js +1 -271
  26. package/lib/plain-values.js +1 -39
  27. package/lib/plain-values.js.map +1 -1
  28. package/lib/protocol-http.js +1 -812
  29. package/lib/protocol-rest.js +1 -375
  30. package/lib/query.js +1 -27
  31. package/lib/response-validation-strict.js +1 -284
  32. package/lib/response-validation.js +1 -118
  33. package/lib/retry-after.js +1 -112
  34. package/lib/retry.js +1 -197
  35. package/lib/schema-lite-impl.js +1 -341
  36. package/lib/schema-lite-typed.js +1 -26
  37. package/lib/schema-lite-typed.js.map +1 -1
  38. package/lib/schema-lite.js +1 -31
  39. package/lib/schema.js +1 -220
  40. package/lib/testing.js +1 -41
  41. package/lib/testing.js.map +1 -1
  42. package/lib/trait.js +1 -131
  43. package/lib/xml.js +1 -323
  44. package/package.json +1 -1
  45. package/src/api.ts +7 -6
  46. package/lib/api.js.map +0 -1
  47. package/lib/category.js.map +0 -1
  48. package/lib/chunks.js.map +0 -1
  49. package/lib/config.js.map +0 -1
  50. package/lib/crypto.js.map +0 -1
  51. package/lib/debug.js.map +0 -1
  52. package/lib/error-category.js.map +0 -1
  53. package/lib/errors.js.map +0 -1
  54. package/lib/graphql.js.map +0 -1
  55. package/lib/graphql.types.js.map +0 -1
  56. package/lib/index.js.map +0 -1
  57. package/lib/pagination.js.map +0 -1
  58. package/lib/protocol-http.js.map +0 -1
  59. package/lib/protocol-rest.js.map +0 -1
  60. package/lib/query.js.map +0 -1
  61. package/lib/response-validation-strict.js.map +0 -1
  62. package/lib/response-validation.js.map +0 -1
  63. package/lib/retry-after.js.map +0 -1
  64. package/lib/retry.js.map +0 -1
  65. package/lib/schema-lite-impl.js.map +0 -1
  66. package/lib/schema-lite.js.map +0 -1
  67. package/lib/schema.js.map +0 -1
  68. package/lib/trait.js.map +0 -1
  69. package/lib/xml.js.map +0 -1
package/lib/category.js CHANGED
@@ -1,278 +1 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
- import * as Effect from "effect/Effect";
22
- import * as HttpClientError from "effect/http/HttpClientError";
23
- import * as Predicate from "effect/Predicate";
24
- // ============================================================================
25
- // Error Category Constants
26
- // ============================================================================
27
- export const AuthError = "AuthError";
28
- export const BadRequestError = "BadRequestError";
29
- export const ConflictError = "ConflictError";
30
- export const NotFoundError = "NotFoundError";
31
- export const QuotaError = "QuotaError";
32
- export const ServerError = "ServerError";
33
- export const ThrottlingError = "ThrottlingError";
34
- export const NetworkError = "NetworkError";
35
- export const ParseError = "ParseError";
36
- export const ConfigurationError = "ConfigurationError";
37
- export const TimeoutError = "TimeoutError";
38
- export const RetryableError = "RetryableError";
39
- export const LockedError = "LockedError";
40
- export const AbortedError = "AbortedError";
41
- export const AlreadyExistsError = "AlreadyExistsError";
42
- export const DependencyViolationError = "DependencyViolationError";
43
- // ============================================================================
44
- // Category Storage Key
45
- // ============================================================================
46
-
47
-
48
-
49
-
50
- export const categoriesKey = "@distilled.cloud/error/categories";
51
-
52
-
53
-
54
-
55
- export const retryableKey = "@distilled.cloud/error/retryable";
56
- // ============================================================================
57
- // Category Decorator
58
- // ============================================================================
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
- export const withCategory = (...categories) => (C) => {
72
- for (const category of categories) {
73
- if (!(categoriesKey in C.prototype)) {
74
- C.prototype[categoriesKey] = {};
75
- }
76
- C.prototype[categoriesKey][category] = true;
77
- }
78
- return C;
79
- };
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
- export const withRetryable = (info = {}) => (C) => {
100
- C.prototype[retryableKey] = info;
101
- return C;
102
- };
103
- // ============================================================================
104
- // Category Decorators (convenience functions for common categories)
105
- // ============================================================================
106
- export const withAuthError = /*@__PURE__*/ withCategory(AuthError);
107
- export const withBadRequestError = /*@__PURE__*/ withCategory(BadRequestError);
108
- export const withConflictError = /*@__PURE__*/ withCategory(ConflictError);
109
- export const withNotFoundError = /*@__PURE__*/ withCategory(NotFoundError);
110
- export const withQuotaError = /*@__PURE__*/ withCategory(QuotaError);
111
- export const withServerError = /*@__PURE__*/ withCategory(ServerError);
112
- export const withThrottlingError = /*@__PURE__*/ withCategory(ThrottlingError);
113
- export const withNetworkError = /*@__PURE__*/ withCategory(NetworkError);
114
- export const withParseError = /*@__PURE__*/ withCategory(ParseError);
115
- export const withConfigurationError = /*@__PURE__*/ withCategory(ConfigurationError);
116
- export const withTimeoutError = /*@__PURE__*/ withCategory(TimeoutError);
117
- export const withRetryableError = /*@__PURE__*/ withCategory(RetryableError);
118
- export const withLockedError = /*@__PURE__*/ withCategory(LockedError);
119
- export const withAbortedError = /*@__PURE__*/ withCategory(AbortedError);
120
- export const withAlreadyExistsError = /*@__PURE__*/ withCategory(AlreadyExistsError);
121
- export const withDependencyViolationError = /*@__PURE__*/ withCategory(DependencyViolationError);
122
- // ============================================================================
123
- // Category Predicates
124
- // ============================================================================
125
-
126
-
127
-
128
- export const hasCategory = (error, category) => {
129
- if (Predicate.isObject(error) && Predicate.hasProperty(categoriesKey)(error)) {
130
- // @ts-expect-error - dynamic property access
131
- return category in error[categoriesKey];
132
- }
133
- return false;
134
- };
135
- export const isAuthError = (error) => hasCategory(error, AuthError);
136
- export const isBadRequestError = (error) => hasCategory(error, BadRequestError);
137
- export const isConflictError = (error) => hasCategory(error, ConflictError);
138
- export const isNotFoundError = (error) => hasCategory(error, NotFoundError);
139
- export const isQuotaError = (error) => hasCategory(error, QuotaError);
140
- export const isServerError = (error) => hasCategory(error, ServerError);
141
- export const isThrottlingError = (error) => hasCategory(error, ThrottlingError);
142
- export const isNetworkError = (error) => hasCategory(error, NetworkError);
143
- export const isParseError = (error) => hasCategory(error, ParseError);
144
- export const isConfigurationError = (error) => hasCategory(error, ConfigurationError);
145
- export const isTimeoutError = (error) => hasCategory(error, TimeoutError);
146
- export const isRetryableError = (error) => hasCategory(error, RetryableError);
147
- export const isLockedError = (error) => hasCategory(error, LockedError);
148
- export const isAbortedError = (error) => hasCategory(error, AbortedError);
149
- export const isAlreadyExistsError = (error) => hasCategory(error, AlreadyExistsError);
150
- export const isDependencyViolationError = (error) => hasCategory(error, DependencyViolationError);
151
- // ============================================================================
152
- // Transient Error Detection (for retry logic)
153
- // ============================================================================
154
-
155
-
156
-
157
- export const isRetryable = (error) => {
158
- if (Predicate.isObject(error) && Predicate.hasProperty(retryableKey)(error)) {
159
- return true;
160
- }
161
- return false;
162
- };
163
-
164
-
165
-
166
-
167
- export const isThrottling = (error) => {
168
- if (Predicate.isObject(error) && Predicate.hasProperty(retryableKey)(error)) {
169
- // @ts-expect-error - dynamic property access
170
- return error[retryableKey]?.throttling === true;
171
- }
172
- return hasCategory(error, ThrottlingError);
173
- };
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
- const isHttpTransportError = (error) => HttpClientError.isHttpClientError(error) && error.reason._tag === "TransportError";
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
- export const isTransientError = (error) => {
199
- // Check for retryable trait first
200
- if (isRetryable(error)) {
201
- return true;
202
- }
203
- // Fall back to category-based checking
204
- return (hasCategory(error, RetryableError) ||
205
- hasCategory(error, ThrottlingError) ||
206
- hasCategory(error, ServerError) ||
207
- hasCategory(error, NetworkError) ||
208
- hasCategory(error, TimeoutError) ||
209
- hasCategory(error, LockedError) ||
210
- isHttpTransportError(error));
211
- };
212
- // ============================================================================
213
- // Category Catchers
214
- // ============================================================================
215
- const makeCatcher = (category) => (f) => (effect) => Effect.catchIf(effect, (e) => hasCategory(e, category), f);
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
- export const catchErrors = (...args) => (effect) => {
229
- const handler = args.pop();
230
- const categories = args;
231
- return Effect.catchIf(effect, (e) => categories.some((cat) => hasCategory(e, cat)), handler);
232
- };
233
- // Alias for convenience
234
- export { catchErrors as catch };
235
- export const catchAuthError = /*@__PURE__*/ makeCatcher(AuthError);
236
- export const catchBadRequestError = /*@__PURE__*/ makeCatcher(BadRequestError);
237
- export const catchConflictError = /*@__PURE__*/ makeCatcher(ConflictError);
238
- export const catchNotFoundError = /*@__PURE__*/ makeCatcher(NotFoundError);
239
- export const catchQuotaError = /*@__PURE__*/ makeCatcher(QuotaError);
240
- export const catchServerError = /*@__PURE__*/ makeCatcher(ServerError);
241
- export const catchThrottlingError = /*@__PURE__*/ makeCatcher(ThrottlingError);
242
- export const catchNetworkError = /*@__PURE__*/ makeCatcher(NetworkError);
243
- export const catchParseError = /*@__PURE__*/ makeCatcher(ParseError);
244
- export const catchConfigurationError = /*@__PURE__*/ makeCatcher(ConfigurationError);
245
- export const catchTimeoutError = /*@__PURE__*/ makeCatcher(TimeoutError);
246
- export const catchRetryableError = /*@__PURE__*/ makeCatcher(RetryableError);
247
- export const catchLockedError = /*@__PURE__*/ makeCatcher(LockedError);
248
- export const catchAbortedError = /*@__PURE__*/ makeCatcher(AbortedError);
249
- export const catchAlreadyExistsError = /*@__PURE__*/ makeCatcher(AlreadyExistsError);
250
- export const catchDependencyViolationError = /*@__PURE__*/ makeCatcher(DependencyViolationError);
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
- export const catchCategory = (...args) => (effect) => {
262
- const f = args.pop();
263
- const categories = args;
264
- return Effect.catchIf(effect, (e) => {
265
- if (Predicate.isObject(e) && Predicate.hasProperty(categoriesKey)(e)) {
266
- for (const cat of categories) {
267
- // @ts-expect-error - dynamic property access
268
- if (cat in e[categoriesKey]) {
269
- return true;
270
- }
271
- }
272
- }
273
- return false;
274
- },
275
- // @ts-expect-error - type narrowing limitation
276
- (e) => f(e));
277
- };
278
- //# sourceMappingURL=category.js.map
1
+ export { category$AbortedError as AbortedError, category$AlreadyExistsError as AlreadyExistsError, category$AuthError as AuthError, category$BadRequestError as BadRequestError, category$ConfigurationError as ConfigurationError, category$ConflictError as ConflictError, category$DependencyViolationError as DependencyViolationError, category$LockedError as LockedError, category$NetworkError as NetworkError, category$NotFoundError as NotFoundError, category$ParseError as ParseError, category$QuotaError as QuotaError, category$RetryableError as RetryableError, category$ServerError as ServerError, category$ThrottlingError as ThrottlingError, category$TimeoutError as TimeoutError, category$catch as catch, category$catchAbortedError as catchAbortedError, category$catchAlreadyExistsError as catchAlreadyExistsError, category$catchAuthError as catchAuthError, category$catchBadRequestError as catchBadRequestError, category$catchCategory as catchCategory, category$catchConfigurationError as catchConfigurationError, category$catchConflictError as catchConflictError, category$catchDependencyViolationError as catchDependencyViolationError, category$catchErrors as catchErrors, category$catchLockedError as catchLockedError, category$catchNetworkError as catchNetworkError, category$catchNotFoundError as catchNotFoundError, category$catchParseError as catchParseError, category$catchQuotaError as catchQuotaError, category$catchRetryableError as catchRetryableError, category$catchServerError as catchServerError, category$catchThrottlingError as catchThrottlingError, category$catchTimeoutError as catchTimeoutError, category$categoriesKey as categoriesKey, category$hasCategory as hasCategory, category$isAbortedError as isAbortedError, category$isAlreadyExistsError as isAlreadyExistsError, category$isAuthError as isAuthError, category$isBadRequestError as isBadRequestError, category$isConfigurationError as isConfigurationError, category$isConflictError as isConflictError, category$isDependencyViolationError as isDependencyViolationError, category$isLockedError as isLockedError, category$isNetworkError as isNetworkError, category$isNotFoundError as isNotFoundError, category$isParseError as isParseError, category$isQuotaError as isQuotaError, category$isRetryable as isRetryable, category$isRetryableError as isRetryableError, category$isServerError as isServerError, category$isThrottling as isThrottling, category$isThrottlingError as isThrottlingError, category$isTimeoutError as isTimeoutError, category$isTransientError as isTransientError, category$retryableKey as retryableKey, category$withAbortedError as withAbortedError, category$withAlreadyExistsError as withAlreadyExistsError, category$withAuthError as withAuthError, category$withBadRequestError as withBadRequestError, category$withCategory as withCategory, category$withConfigurationError as withConfigurationError, category$withConflictError as withConflictError, category$withDependencyViolationError as withDependencyViolationError, category$withLockedError as withLockedError, category$withNetworkError as withNetworkError, category$withNotFoundError as withNotFoundError, category$withParseError as withParseError, category$withQuotaError as withQuotaError, category$withRetryable as withRetryable, category$withRetryableError as withRetryableError, category$withServerError as withServerError, category$withThrottlingError as withThrottlingError, category$withTimeoutError as withTimeoutError } from "./_bundle/base.js";
package/lib/chunks.js CHANGED
@@ -1,11 +1 @@
1
- import { lazyFrom } from "./schema.js";
2
- const builders = /*@__PURE__*/ new WeakMap();
3
-
4
- // `any`: each const keeps the type it declares or casts to.
5
- export const at = (build, j) => {
6
- let builder = builders.get(build);
7
- if (!builder)
8
- builders.set(build, (builder = { build: (data) => build(data) }));
9
- return lazyFrom(builder, j);
10
- };
11
- //# sourceMappingURL=chunks.js.map
1
+ export { chunks$at as at } from "./_bundle/aws.js";
package/lib/config.js CHANGED
@@ -1,161 +1 @@
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
- import * as Context from "effect/Context";
27
- import * as Data from "effect/Data";
28
- import * as Effect from "effect/Effect";
29
- import * as Option from "effect/Option";
30
- import * as Redact from "effect/Redacted";
31
-
32
- export class ConfigMissing extends /*@__PURE__*/ /*@__PURE__*/ Data.TaggedError("ConfigError") {
33
- }
34
- const CONFIG_PROVIDER_KEY = "effect/ConfigProvider";
35
- const fromEnv = (name) => globalThis.process?.env?.[name];
36
-
37
- class Missing {
38
- name;
39
- constructor(name) {
40
- this.name = name;
41
- }
42
- }
43
-
44
-
45
-
46
-
47
- const DEFER = /*@__PURE__*/ Symbol("defer");
48
- const readSymbol = /*@__PURE__*/ Symbol.for("@distilled.cloud/core/config/read");
49
- const readerOf = (self) => self[readSymbol];
50
- // Looked up by its string key so `effect/ConfigProvider` stays out of bundles.
51
- const providerKey = { key: CONFIG_PROVIDER_KEY };
52
- const hasProvider = (context) => Context.getOrUndefined(context, providerKey) !== undefined;
53
- const missingError = (m) => new ConfigMissing({ name: m.name, message: `Expected ${m.name} to be set` });
54
- const fromReader = (reader) => {
55
- const effect = Effect.withFiber((fiber) => {
56
- if (hasProvider(fiber.context))
57
- return reader.viaEffect();
58
- const value = reader.read();
59
- if (value === DEFER)
60
- return reader.viaEffect();
61
- return value instanceof Missing ? Effect.fail(missingError(value)) : Effect.succeed(value);
62
- });
63
- effect[readSymbol] = reader;
64
- return effect;
65
- };
66
-
67
- const lookup = (name) => Effect.flatMap(Effect.context(), (context) => {
68
- const provider = context.mapUnsafe.get(CONFIG_PROVIDER_KEY);
69
- if (!provider)
70
- return Effect.succeed(fromEnv(name));
71
- return provider.load([name]).pipe(Effect.map((node) => (node?._tag === "Value" ? node.value : undefined)), Effect.orElseSucceed(() => undefined));
72
- });
73
- const required = (name) => fromReader({
74
- read: () => fromEnv(name) ?? new Missing(name),
75
- viaEffect: () => Effect.flatMap(lookup(name), (value) => value === undefined ? Effect.fail(missingError(new Missing(name))) : Effect.succeed(value)),
76
- });
77
-
78
- export const String = (name) => required(name);
79
-
80
- export const Redacted = (name) => map((value) => Redact.make(value))(required(name));
81
-
82
- export const option = (self) => {
83
- const viaEffect = () => Effect.catch(Effect.map(self, Option.some), () => Effect.succeed(Option.none()));
84
- const reader = readerOf(self);
85
- if (!reader)
86
- return viaEffect();
87
- return fromReader({
88
- read: () => {
89
- const value = reader.read();
90
- if (value === DEFER)
91
- return DEFER;
92
- return value instanceof Missing ? Option.none() : Option.some(value);
93
- },
94
- viaEffect,
95
- });
96
- };
97
-
98
- export const withDefault = (value) => (self) => {
99
- const viaEffect = () => Effect.catch(self, () => Effect.succeed(value));
100
- const reader = readerOf(self);
101
- if (!reader)
102
- return viaEffect();
103
- return fromReader({
104
- read: () => {
105
- const v = reader.read();
106
- return v instanceof Missing ? value : v;
107
- },
108
- viaEffect,
109
- });
110
- };
111
-
112
- export const orElse = (that) => (self) => {
113
- const viaEffect = () => Effect.catch(self, () => that());
114
- const reader = readerOf(self);
115
- if (!reader)
116
- return viaEffect();
117
- return fromReader({
118
- read: () => {
119
- const v = reader.read();
120
- if (!(v instanceof Missing))
121
- return v;
122
- const fallback = readerOf(that());
123
- return fallback ? fallback.read() : DEFER;
124
- },
125
- viaEffect,
126
- });
127
- };
128
- export const map = (f) => (self) => {
129
- const reader = readerOf(self);
130
- if (!reader)
131
- return Effect.map(self, f);
132
- return fromReader({
133
- read: () => {
134
- const v = reader.read();
135
- return v === DEFER || v instanceof Missing ? v : f(v);
136
- },
137
- viaEffect: () => Effect.map(reader.viaEffect(), f),
138
- });
139
- };
140
-
141
- export const all = (readers) => {
142
- const viaEffect = () => Effect.all(readers);
143
- const keys = Object.keys(readers);
144
- const parts = keys.map((k) => readerOf(readers[k]));
145
- if (parts.some((r) => r === undefined))
146
- return viaEffect();
147
- return fromReader({
148
- read: () => {
149
- const out = {};
150
- for (let i = 0; i < keys.length; i++) {
151
- const v = parts[i].read();
152
- if (v === DEFER || v instanceof Missing)
153
- return v;
154
- out[keys[i]] = v;
155
- }
156
- return out;
157
- },
158
- viaEffect: viaEffect,
159
- });
160
- };
161
- //# sourceMappingURL=config.js.map
1
+ export { config$ConfigMissing as ConfigMissing, config$Redacted as Redacted, config$String as String, config$all as all, config$map as map, config$option as option, config$orElse as orElse, config$withDefault as withDefault } from "./_bundle/base.js";
package/lib/crypto.js CHANGED
@@ -1,130 +1 @@
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
- import * as Context from "effect/Context";
24
- import * as Data from "effect/Data";
25
- import * as Effect from "effect/Effect";
26
- import * as Layer from "effect/Layer";
27
-
28
- export class CryptoError extends /*@__PURE__*/ /*@__PURE__*/ Data.TaggedError("CryptoError") {
29
- }
30
-
31
- const nodeModule = () => {
32
- try {
33
- const p = globalThis.process;
34
- return p?.getBuiltinModule?.("node:crypto");
35
- }
36
- catch {
37
- return undefined;
38
- }
39
- };
40
- const encoder = /*@__PURE__*/ new TextEncoder();
41
- const toBytes = (data) => typeof data === "string" ? encoder.encode(data) : data;
42
-
43
- export const makeNodeCrypto = () => {
44
- const c = nodeModule();
45
- if (!c)
46
- return undefined;
47
- return {
48
- name: "node:crypto",
49
- sync: {
50
- sha256: (data) => c.createHash("sha256").update(data).digest(),
51
- importHmacKey: (key) => c.createSecretKey(toBytes(key)),
52
- hmacSha256: (key, data) => c
53
- .createHmac("sha256", key)
54
- .update(data)
55
- .digest(),
56
- sha256Hex: c.hash
57
- ? (data) => c.hash("sha256", data, "hex")
58
- : (data) => c.createHash("sha256").update(data).digest("hex"),
59
- hmacSha256Hex: (key, data) => c
60
- .createHmac("sha256", key)
61
- .update(data)
62
- .digest("hex"),
63
- },
64
- sha256: (data) => Effect.try({
65
- try: () => c.createHash("sha256").update(data).digest(),
66
- catch: (cause) => new CryptoError({ operation: "sha256", cause }),
67
- }),
68
- importHmacKey: (key) => Effect.try({
69
- try: () => c.createSecretKey(toBytes(key)),
70
- catch: (cause) => new CryptoError({ operation: "importKey", cause }),
71
- }),
72
- hmacSha256: (key, data) => Effect.try({
73
- try: () => c
74
- .createHmac("sha256", key)
75
- .update(data)
76
- .digest(),
77
- catch: (cause) => new CryptoError({ operation: "hmac", cause }),
78
- }),
79
- };
80
- };
81
- //#endregion
82
- //#region WebCrypto
83
- const buffer = (data) => {
84
- const b = toBytes(data);
85
- return b.buffer instanceof ArrayBuffer ? b : new Uint8Array(b);
86
- };
87
-
88
- export const makeWebCrypto = () => ({
89
- name: "webcrypto",
90
- sha256: (data) => Effect.tryPromise({
91
- try: async () => new Uint8Array(await crypto.subtle.digest("SHA-256", buffer(data))),
92
- catch: (cause) => new CryptoError({ operation: "sha256", cause }),
93
- }),
94
- importHmacKey: (key) => Effect.tryPromise({
95
- try: () => crypto.subtle.importKey("raw", buffer(key), { name: "HMAC", hash: "SHA-256" }, false, [
96
- "sign",
97
- ]),
98
- catch: (cause) => new CryptoError({ operation: "importKey", cause }),
99
- }),
100
- hmacSha256: (key, data) => Effect.tryPromise({
101
- try: async () => new Uint8Array(await crypto.subtle.sign("HMAC", key, buffer(data))),
102
- catch: (cause) => new CryptoError({ operation: "hmac", cause }),
103
- }),
104
- });
105
- //#endregion
106
-
107
- export const Crypto = /*@__PURE__*/ Context.Reference("@distilled.cloud/core/Crypto", {
108
- defaultValue: () => makeNodeCrypto() ?? makeWebCrypto(),
109
- });
110
-
111
- export const layer = (impl) => Layer.succeed(Crypto, impl);
112
-
113
- export const webCrypto = /*@__PURE__*/ Layer.sync(Crypto, makeWebCrypto);
114
-
115
- export const nodeCrypto = /*@__PURE__*/ Layer.effect(Crypto,
116
- /*@__PURE__*/ Effect.suspend(() => {
117
- const impl = makeNodeCrypto();
118
- return impl
119
- ? Effect.succeed(impl)
120
- : Effect.fail(new CryptoError({ operation: "importKey", cause: "node:crypto is not available" }));
121
- }));
122
- const HEX = /*@__PURE__*/ Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, "0"));
123
-
124
- export const hex = (bytes) => {
125
- let out = "";
126
- for (let i = 0; i < bytes.length; i++)
127
- out += HEX[bytes[i]];
128
- return out;
129
- };
130
- //# sourceMappingURL=crypto.js.map
1
+ export { crypto$Crypto as Crypto, crypto$CryptoError as CryptoError, crypto$hex as hex, crypto$layer as layer, crypto$makeNodeCrypto as makeNodeCrypto, crypto$makeWebCrypto as makeWebCrypto, crypto$nodeCrypto as nodeCrypto, crypto$webCrypto as webCrypto } from "./_bundle/aws.js";
package/lib/debug.js CHANGED
@@ -1,8 +1 @@
1
-
2
-
3
-
4
-
5
- let flag;
6
- export const debugHttp = () => (flag ??= !!globalThis.process
7
- ?.env?.DISTILLED_DEBUG_HTTP);
8
- //# sourceMappingURL=debug.js.map
1
+ export { debug$debugHttp as debugHttp } from "./_bundle/rest.js";
@@ -1,47 +1 @@
1
- import * as Effect from "effect/Effect";
2
- import * as Predicate from "effect/Predicate";
3
- export const categoriesKey = "@distilled/meta/error-categories";
4
- export const withCategory = (...categories) => (C) => {
5
- // @ts-expect-error
6
- const Mixed = class extends C {
7
- };
8
- for (const category of categories) {
9
- if (!(categoriesKey in Mixed.prototype)) {
10
- // @ts-expect-error
11
- Mixed.prototype[categoriesKey] = {};
12
- }
13
- // @ts-expect-error
14
- Mixed.prototype[categoriesKey][category] = true;
15
- }
16
- return Mixed;
17
- };
18
-
19
-
20
-
21
-
22
- export const hasCategory = (category) => (value) => {
23
- if (!Predicate.isObject(value))
24
- return false;
25
- if (!Predicate.hasProperty(categoriesKey)(value))
26
- return false;
27
- return category in value[categoriesKey];
28
- };
29
-
30
- export const hasAnyCategory = (...categories) => (value) => {
31
- if (!Predicate.isObject(value))
32
- return false;
33
- if (!Predicate.hasProperty(categoriesKey)(value))
34
- return false;
35
- const cats = value[categoriesKey];
36
- for (const c of categories)
37
- if (c in cats)
38
- return true;
39
- return false;
40
- };
41
- export const catchCategory = (...args) => (effect) => {
42
- const f = args.pop();
43
- const categories = args;
44
- const matches = hasAnyCategory(...categories);
45
- return Effect.catchIf(effect, matches, (e) => f(e));
46
- };
47
- //# sourceMappingURL=error-category.js.map
1
+ export { error_category$catchCategory as catchCategory, error_category$categoriesKey as categoriesKey, error_category$hasAnyCategory as hasAnyCategory, error_category$hasCategory as hasCategory, error_category$withCategory as withCategory } from "./_bundle/rest.js";