@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.
- package/lib/_bundle/aws.js +2 -0
- package/lib/_bundle/aws.js.map +1 -0
- package/lib/_bundle/base.js +5 -0
- package/lib/_bundle/base.js.map +1 -0
- package/lib/_bundle/graphql.js +3 -0
- package/lib/_bundle/graphql.js.map +1 -0
- package/lib/_bundle/rest.js +2 -0
- package/lib/_bundle/rest.js.map +1 -0
- package/lib/_bundle/xml.js +4 -0
- package/lib/_bundle/xml.js.map +1 -0
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +1 -796
- package/lib/category.js +1 -278
- package/lib/chunks.js +1 -11
- package/lib/config.js +1 -161
- package/lib/crypto.js +1 -130
- package/lib/debug.js +1 -8
- package/lib/error-category.js +1 -47
- package/lib/errors.js +1 -198
- package/lib/graphql.js +1 -1058
- package/lib/graphql.types.js +1 -6
- package/lib/index.js +0 -15
- package/lib/json-patch.js +1 -226
- package/lib/json-patch.js.map +1 -1
- package/lib/pagination.js +1 -271
- package/lib/plain-values.js +1 -39
- package/lib/plain-values.js.map +1 -1
- package/lib/protocol-http.js +1 -812
- package/lib/protocol-rest.js +1 -375
- package/lib/query.js +1 -27
- package/lib/response-validation-strict.js +1 -284
- package/lib/response-validation.js +1 -118
- package/lib/retry-after.js +1 -112
- package/lib/retry.js +1 -197
- package/lib/schema-lite-impl.js +1 -341
- package/lib/schema-lite-typed.js +1 -26
- package/lib/schema-lite-typed.js.map +1 -1
- package/lib/schema-lite.js +1 -31
- package/lib/schema.js +1 -220
- package/lib/testing.js +1 -41
- package/lib/testing.js.map +1 -1
- package/lib/trait.js +1 -131
- package/lib/xml.js +1 -323
- package/package.json +1 -1
- package/src/api.ts +7 -6
- package/lib/api.js.map +0 -1
- package/lib/category.js.map +0 -1
- package/lib/chunks.js.map +0 -1
- package/lib/config.js.map +0 -1
- package/lib/crypto.js.map +0 -1
- package/lib/debug.js.map +0 -1
- package/lib/error-category.js.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/graphql.js.map +0 -1
- package/lib/graphql.types.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/pagination.js.map +0 -1
- package/lib/protocol-http.js.map +0 -1
- package/lib/protocol-rest.js.map +0 -1
- package/lib/query.js.map +0 -1
- package/lib/response-validation-strict.js.map +0 -1
- package/lib/response-validation.js.map +0 -1
- package/lib/retry-after.js.map +0 -1
- package/lib/retry.js.map +0 -1
- package/lib/schema-lite-impl.js.map +0 -1
- package/lib/schema-lite.js.map +0 -1
- package/lib/schema.js.map +0 -1
- package/lib/trait.js.map +0 -1
- package/lib/xml.js.map +0 -1
|
@@ -1,118 +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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import * as Context from "effect/Context";
|
|
40
|
-
import * as Effect from "effect/Effect";
|
|
41
|
-
import * as Layer from "effect/Layer";
|
|
42
|
-
import { decoderFor } from "./response-validation-strict.js";
|
|
43
|
-
export { SchemaMismatch, withholdActual } from "./response-validation-strict.js";
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export const ResponseValidation = /*@__PURE__*/ Context.Reference("@distilled.cloud/core/ResponseValidation", { defaultValue: () => "lenient" });
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export const StrictDecoder = /*@__PURE__*/ Context.Reference("@distilled.cloud/core/ResponseValidation/StrictDecoder", { defaultValue: () => undefined });
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const layerOfContext = (context) => {
|
|
64
|
-
const layer = Layer.succeedContext(context);
|
|
65
|
-
const both = Object.create(context);
|
|
66
|
-
const layerProto = Object.getPrototypeOf(layer);
|
|
67
|
-
for (const key of Reflect.ownKeys(layerProto)) {
|
|
68
|
-
if (key !== "pipe")
|
|
69
|
-
both[key] = layerProto[key];
|
|
70
|
-
}
|
|
71
|
-
both.build = layer.build;
|
|
72
|
-
return both;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
export const strict = /*@__PURE__*/ layerOfContext(
|
|
79
|
-
/*@__PURE__*/ Context.add(
|
|
80
|
-
/*@__PURE__*/ Context.make(ResponseValidation, "strict"), StrictDecoder, decoderFor));
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
export const additionalProperties = /*@__PURE__*/ layerOfContext(
|
|
86
|
-
/*@__PURE__*/ Context.add(
|
|
87
|
-
/*@__PURE__*/ Context.make(ResponseValidation, "additionalProperties"), StrictDecoder, decoderFor));
|
|
88
|
-
|
|
89
|
-
export const lenient = /*@__PURE__*/ layerOfContext(
|
|
90
|
-
/*@__PURE__*/ Context.make(ResponseValidation, "lenient"));
|
|
91
|
-
|
|
92
|
-
export const isValidating = /*@__PURE__*/ Effect.map(ResponseValidation, (mode) => mode !== "lenient");
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
export const failUnlessLenient = (error, asRead) => Effect.flatMap(ResponseValidation, (mode) => mode === "lenient" ? Effect.succeed(asRead) : Effect.fail(error));
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
export const checkResponse = (context, outputAst, value) => {
|
|
105
|
-
const mode = Context.get(context, ResponseValidation);
|
|
106
|
-
if (mode === "lenient")
|
|
107
|
-
return undefined;
|
|
108
|
-
const decoderOf = Context.get(context, StrictDecoder);
|
|
109
|
-
if (!decoderOf) {
|
|
110
|
-
throw new Error(`${mode} response validation needs the ResponseValidation.${mode} layer`);
|
|
111
|
-
}
|
|
112
|
-
return decoderOf(outputAst, mode === "strict")(value);
|
|
113
|
-
};
|
|
114
|
-
export const validateResponse = (outputAst, value, onError) => Effect.withFiber((fiber) => {
|
|
115
|
-
const error = checkResponse(fiber.context, outputAst, value);
|
|
116
|
-
return error === undefined ? Effect.succeed(value) : Effect.fail(onError(error));
|
|
117
|
-
});
|
|
118
|
-
//# sourceMappingURL=response-validation.js.map
|
|
1
|
+
export { response_validation$ResponseValidation as ResponseValidation, response_validation$SchemaMismatch as SchemaMismatch, response_validation$StrictDecoder as StrictDecoder, response_validation$additionalProperties as additionalProperties, response_validation$checkResponse as checkResponse, response_validation$failUnlessLenient as failUnlessLenient, response_validation$isValidating as isValidating, response_validation$lenient as lenient, response_validation$strict as strict, response_validation$validateResponse as validateResponse, response_validation$withholdActual as withholdActual } from "./_bundle/base.js";
|
package/lib/retry-after.js
CHANGED
|
@@ -1,112 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import * as Duration from "effect/Duration";
|
|
18
|
-
import { RETRYABLE_HTTP_STATUSES } from "./errors.js";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export const parseRetryAfter = (headers) => {
|
|
28
|
-
const raw = headers?.["retry-after"];
|
|
29
|
-
if (!raw)
|
|
30
|
-
return undefined;
|
|
31
|
-
const trimmed = raw.trim();
|
|
32
|
-
if (trimmed.length === 0)
|
|
33
|
-
return undefined;
|
|
34
|
-
// delay-seconds: 1*DIGIT (non-negative decimal integer per RFC).
|
|
35
|
-
if (/^\d+$/.test(trimmed)) {
|
|
36
|
-
const seconds = Number(trimmed);
|
|
37
|
-
if (Number.isFinite(seconds) && seconds >= 0) {
|
|
38
|
-
return Duration.seconds(seconds);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Reject anything that *looks* numeric but isn't a valid delay-seconds.
|
|
42
|
-
// Without this, `Date.parse("-5")` happens to return 0 on some engines and
|
|
43
|
-
// would silently yield a zero-duration instead of the expected undefined.
|
|
44
|
-
if (/^[-+]?\d+(?:\.\d+)?$/.test(trimmed))
|
|
45
|
-
return undefined;
|
|
46
|
-
// HTTP-date: try Date.parse, which handles RFC 1123 / RFC 850 / asctime.
|
|
47
|
-
const ts = Date.parse(trimmed);
|
|
48
|
-
if (!Number.isNaN(ts)) {
|
|
49
|
-
const ms = Math.max(0, ts - Date.now());
|
|
50
|
-
return Duration.millis(ms);
|
|
51
|
-
}
|
|
52
|
-
return undefined;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export const parseRatelimit = (headers) => {
|
|
67
|
-
const raw = headers?.["ratelimit"];
|
|
68
|
-
if (!raw)
|
|
69
|
-
return undefined;
|
|
70
|
-
let remaining;
|
|
71
|
-
let reset;
|
|
72
|
-
// Tokenize on commas and semicolons; tolerate `key=value` and `key =value`.
|
|
73
|
-
for (const piece of raw.split(/[,;]/)) {
|
|
74
|
-
const eq = piece.indexOf("=");
|
|
75
|
-
if (eq < 0)
|
|
76
|
-
continue;
|
|
77
|
-
const key = piece.slice(0, eq).trim().toLowerCase();
|
|
78
|
-
const value = piece.slice(eq + 1).trim();
|
|
79
|
-
const num = Number(value);
|
|
80
|
-
if (!Number.isFinite(num))
|
|
81
|
-
continue;
|
|
82
|
-
if (key === "r" || key === "remaining")
|
|
83
|
-
remaining = num;
|
|
84
|
-
else if (key === "t" || key === "reset")
|
|
85
|
-
reset = num;
|
|
86
|
-
}
|
|
87
|
-
if (remaining !== 0)
|
|
88
|
-
return undefined;
|
|
89
|
-
if (reset === undefined || reset < 0)
|
|
90
|
-
return undefined;
|
|
91
|
-
return Duration.seconds(reset);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
export const parseServerRetryHint = (headers) => parseRetryAfter(headers) ?? parseRatelimit(headers);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export const parseRetryAfterForStatus = (status, headers) => {
|
|
108
|
-
if (!RETRYABLE_HTTP_STATUSES.has(status))
|
|
109
|
-
return undefined;
|
|
110
|
-
return parseServerRetryHint(headers);
|
|
111
|
-
};
|
|
112
|
-
//# sourceMappingURL=retry-after.js.map
|
|
1
|
+
export { retry_after$parseRatelimit as parseRatelimit, retry_after$parseRetryAfter as parseRetryAfter, retry_after$parseRetryAfterForStatus as parseRetryAfterForStatus, retry_after$parseServerRetryHint as parseServerRetryHint } from "./_bundle/rest.js";
|
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";
|