lifecycleion 0.0.19 → 0.0.21
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/README.md +39 -36
- package/dist/lib/event-emitter.cjs +195 -9
- package/dist/lib/event-emitter.cjs.map +1 -1
- package/dist/lib/event-emitter.js +195 -9
- package/dist/lib/event-emitter.js.map +1 -1
- package/dist/lib/global-event-target.cjs +217 -0
- package/dist/lib/global-event-target.cjs.map +1 -0
- package/dist/lib/global-event-target.d.cts +70 -0
- package/dist/lib/global-event-target.d.ts +70 -0
- package/dist/lib/global-event-target.js +189 -0
- package/dist/lib/global-event-target.js.map +1 -0
- package/dist/lib/http-client/index.cjs +554 -193
- package/dist/lib/http-client/index.cjs.map +1 -1
- package/dist/lib/http-client/index.d.cts +9 -3
- package/dist/lib/http-client/index.d.ts +9 -3
- package/dist/lib/http-client/index.js +554 -193
- package/dist/lib/http-client/index.js.map +1 -1
- package/dist/lib/http-client-mock/index.cjs +71 -24
- package/dist/lib/http-client-mock/index.cjs.map +1 -1
- package/dist/lib/http-client-mock/index.d.cts +50 -2
- package/dist/lib/http-client-mock/index.d.ts +50 -2
- package/dist/lib/http-client-mock/index.js +71 -24
- package/dist/lib/http-client-mock/index.js.map +1 -1
- package/dist/lib/http-client-node/index.cjs +135 -33
- package/dist/lib/http-client-node/index.cjs.map +1 -1
- package/dist/lib/http-client-node/index.d.cts +33 -2
- package/dist/lib/http-client-node/index.d.ts +33 -2
- package/dist/lib/http-client-node/index.js +135 -33
- package/dist/lib/http-client-node/index.js.map +1 -1
- package/dist/lib/http-client-xhr/index.cjs +0 -14
- package/dist/lib/http-client-xhr/index.cjs.map +1 -1
- package/dist/lib/http-client-xhr/index.d.cts +3 -2
- package/dist/lib/http-client-xhr/index.d.ts +3 -2
- package/dist/lib/http-client-xhr/index.js +0 -14
- package/dist/lib/http-client-xhr/index.js.map +1 -1
- package/dist/lib/lifecycle-manager/index.cjs +199 -13
- package/dist/lib/lifecycle-manager/index.cjs.map +1 -1
- package/dist/lib/lifecycle-manager/index.js +199 -13
- package/dist/lib/lifecycle-manager/index.js.map +1 -1
- package/dist/lib/logger/index.cjs +203 -21
- package/dist/lib/logger/index.cjs.map +1 -1
- package/dist/lib/logger/index.d.cts +5 -1
- package/dist/lib/logger/index.d.ts +5 -1
- package/dist/lib/logger/index.js +203 -21
- package/dist/lib/logger/index.js.map +1 -1
- package/dist/lib/lru-cache/index.cjs +195 -9
- package/dist/lib/lru-cache/index.cjs.map +1 -1
- package/dist/lib/lru-cache/index.js +195 -9
- package/dist/lib/lru-cache/index.js.map +1 -1
- package/dist/lib/process-signal-manager.cjs +199 -13
- package/dist/lib/process-signal-manager.cjs.map +1 -1
- package/dist/lib/process-signal-manager.js +199 -13
- package/dist/lib/process-signal-manager.js.map +1 -1
- package/dist/lib/promise-protected-resolver.cjs +195 -9
- package/dist/lib/promise-protected-resolver.cjs.map +1 -1
- package/dist/lib/promise-protected-resolver.js +195 -9
- package/dist/lib/promise-protected-resolver.js.map +1 -1
- package/dist/lib/retry-utils/index.cjs +195 -9
- package/dist/lib/retry-utils/index.cjs.map +1 -1
- package/dist/lib/retry-utils/index.js +195 -9
- package/dist/lib/retry-utils/index.js.map +1 -1
- package/dist/lib/safe-handle-callback.cjs +196 -18
- package/dist/lib/safe-handle-callback.cjs.map +1 -1
- package/dist/lib/safe-handle-callback.d.cts +14 -4
- package/dist/lib/safe-handle-callback.d.ts +14 -4
- package/dist/lib/safe-handle-callback.js +196 -18
- package/dist/lib/safe-handle-callback.js.map +1 -1
- package/dist/lib/single-event-observer.cjs +195 -9
- package/dist/lib/single-event-observer.cjs.map +1 -1
- package/dist/lib/single-event-observer.js +195 -9
- package/dist/lib/single-event-observer.js.map +1 -1
- package/dist/{types-CWw885iO.d.cts → types-BFvpJPMt.d.cts} +72 -11
- package/dist/{types-Mso0dYOS.d.ts → types-BONtIhQ5.d.ts} +72 -11
- package/package.json +31 -12
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { H as HTTPAdapter, Q as QueryObject, C as ContentType, A as AdapterType, a as AdapterRequest, b as AdapterResponse } from '../../types-
|
|
1
|
+
import { H as HTTPAdapter, Q as QueryObject, C as ContentType, A as AdapterType, a as AdapterRequest, b as AdapterResponse } from '../../types-BONtIhQ5.js';
|
|
2
|
+
export { c as AdapterProgressEvent, d as HTTPMethod } from '../../types-BONtIhQ5.js';
|
|
2
3
|
import '../../types-BW0vnSzd.js';
|
|
3
4
|
|
|
4
5
|
interface MockFormData {
|
|
@@ -73,6 +74,53 @@ interface MockResponse {
|
|
|
73
74
|
* the same identity (name + path + domain) and typically `maxAge: 0`
|
|
74
75
|
*/
|
|
75
76
|
cookies?: Record<string, string | MockCookieOptions | null>;
|
|
77
|
+
/**
|
|
78
|
+
* Simulate a response-body failure that happens **after** headers arrive, so
|
|
79
|
+
* consumers can test the `isStreamError` branch without a real socket.
|
|
80
|
+
*
|
|
81
|
+
* `status`, `headers` and cookies are reported as given, but `body` resolves as
|
|
82
|
+
* `null` whatever the handler set and the response carries
|
|
83
|
+
* `isStreamError: true`, which `HTTPClient` treats as terminal.
|
|
84
|
+
*
|
|
85
|
+
* Pass `true` for the default `'stream_response_error'`, or name the code.
|
|
86
|
+
*/
|
|
87
|
+
streamError?: boolean | 'stream_write_error' | 'stream_response_error';
|
|
88
|
+
/**
|
|
89
|
+
* Simulate a failure that produced **no response at all** — a refused
|
|
90
|
+
* connection, a name that did not resolve, a socket dropped before headers.
|
|
91
|
+
*
|
|
92
|
+
* Nothing from the handler's response is delivered: no body, headers, cookies,
|
|
93
|
+
* or terminal progress. The response carries `isTransportError: true`.
|
|
94
|
+
*
|
|
95
|
+
* Pass `true` for a plain `status: 0` failure, or an object to exercise the
|
|
96
|
+
* replay signals a real adapter would attach:
|
|
97
|
+
*
|
|
98
|
+
* ```ts
|
|
99
|
+
* // Proven undelivered — a POST may be replayed
|
|
100
|
+
* { status: 200, transportError: { wasDefinitelyNotSent: true } }
|
|
101
|
+
*
|
|
102
|
+
* // Delivery unknown — a POST is not replayed
|
|
103
|
+
* { status: 200, transportError: true }
|
|
104
|
+
*
|
|
105
|
+
* // Nothing should retry this, whatever the method (a TLS failure)
|
|
106
|
+
* { status: 200, transportError: { status: 495, isRetryable: false } }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
transportError?: boolean | MockTransportErrorOptions;
|
|
110
|
+
}
|
|
111
|
+
/** Shape of a simulated transport failure. See {@link MockResponse.transportError}. */
|
|
112
|
+
interface MockTransportErrorOptions {
|
|
113
|
+
/**
|
|
114
|
+
* Diagnostic status to preserve, as adapters do for TLS failures (`495`).
|
|
115
|
+
* Defaults to `0`, the ordinary "no response" status.
|
|
116
|
+
*/
|
|
117
|
+
status?: number;
|
|
118
|
+
/** Proof no request bytes reached the server. Authorizes replaying a write. */
|
|
119
|
+
wasDefinitelyNotSent?: boolean;
|
|
120
|
+
/** Set `false` for a failure no method should retry. */
|
|
121
|
+
isRetryable?: boolean;
|
|
122
|
+
/** Message for the generated `errorCause`. */
|
|
123
|
+
message?: string;
|
|
76
124
|
}
|
|
77
125
|
type MockRouteHandler = (request: MockRequest) => MockResponse | Promise<MockResponse>;
|
|
78
126
|
interface MockAdapterConfig {
|
|
@@ -126,4 +174,4 @@ declare class MockAdapter implements HTTPAdapter {
|
|
|
126
174
|
send(request: AdapterRequest): Promise<AdapterResponse>;
|
|
127
175
|
}
|
|
128
176
|
|
|
129
|
-
export { MockAdapter, type MockAdapterConfig, type MockAdapterRoutes, type MockCookieOptions, type MockFormData, type MockRequest, type MockResponse, type MockRouteHandler };
|
|
177
|
+
export { AdapterRequest, AdapterResponse, AdapterType, HTTPAdapter, MockAdapter, type MockAdapterConfig, type MockAdapterRoutes, type MockCookieOptions, type MockFormData, type MockRequest, type MockResponse, type MockRouteHandler, type MockTransportErrorOptions };
|
|
@@ -27,20 +27,6 @@ var REDIRECT_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
|
27
27
|
|
|
28
28
|
// src/lib/http-client/utils.ts
|
|
29
29
|
import qs from "qs";
|
|
30
|
-
|
|
31
|
-
// src/lib/domain-utils/domain-utils.ts
|
|
32
|
-
import { getDomain, getSubdomain, getPublicSuffix } from "tldts";
|
|
33
|
-
|
|
34
|
-
// src/lib/domain-utils/helpers.ts
|
|
35
|
-
import { toASCII } from "tr46";
|
|
36
|
-
var INTERNAL_PSEUDO_TLDS = Object.freeze(
|
|
37
|
-
/* @__PURE__ */ new Set(["localhost", "local", "test", "internal"])
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
// src/lib/domain-utils/domain-utils.ts
|
|
41
|
-
import { getDomain as getDomain2, getSubdomain as getSubdomain2 } from "tldts";
|
|
42
|
-
|
|
43
|
-
// src/lib/http-client/utils.ts
|
|
44
30
|
function resolveAbsoluteURL(url, baseURL) {
|
|
45
31
|
if (!url) {
|
|
46
32
|
return url;
|
|
@@ -226,13 +212,33 @@ var MockAdapter = class {
|
|
|
226
212
|
if (request.signal?.aborted) {
|
|
227
213
|
throwAbortError();
|
|
228
214
|
}
|
|
229
|
-
|
|
215
|
+
if (mockResponse.transportError) {
|
|
216
|
+
const options = mockResponse.transportError === true ? {} : mockResponse.transportError;
|
|
217
|
+
return {
|
|
218
|
+
status: options.status ?? 0,
|
|
219
|
+
isTransportError: true,
|
|
220
|
+
...options.isRetryable !== void 0 ? { isRetryable: options.isRetryable } : {},
|
|
221
|
+
...options.wasDefinitelyNotSent !== void 0 ? { wasDefinitelyNotSent: options.wasDefinitelyNotSent } : {},
|
|
222
|
+
headers: {},
|
|
223
|
+
body: null,
|
|
224
|
+
errorCause: new Error(
|
|
225
|
+
options.message ?? "Mock transport error (MockResponse.transportError)"
|
|
226
|
+
)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const streamErrorCode = resolveMockStreamErrorCode(
|
|
230
|
+
mockResponse.streamError
|
|
231
|
+
);
|
|
232
|
+
const intendedBody = shouldOmitResponseBody(method, mockResponse.status) ? null : serializeResponseBody(mockResponse);
|
|
233
|
+
const responseBody = streamErrorCode !== void 0 ? null : intendedBody;
|
|
230
234
|
request.onUploadProgress?.({ loaded: 1, total: 1, progress: 1 });
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
235
|
+
if (streamErrorCode === void 0) {
|
|
236
|
+
request.onDownloadProgress?.({
|
|
237
|
+
loaded: responseBody?.length ?? 0,
|
|
238
|
+
total: responseBody?.length ?? 0,
|
|
239
|
+
progress: 1
|
|
240
|
+
});
|
|
241
|
+
}
|
|
236
242
|
const responseHeaders = {
|
|
237
243
|
...mockResponse.headers ?? {}
|
|
238
244
|
};
|
|
@@ -244,7 +250,7 @@ var MockAdapter = class {
|
|
|
244
250
|
responseHeaders["set-cookie"] = [...existingArr, ...setCookieEntries];
|
|
245
251
|
}
|
|
246
252
|
}
|
|
247
|
-
if (!hasHeader(responseHeaders, "content-type") &&
|
|
253
|
+
if (!hasHeader(responseHeaders, "content-type") && intendedBody !== null) {
|
|
248
254
|
const ct = mockResponse.contentType ?? inferContentType(mockResponse.body);
|
|
249
255
|
if (ct === "json") {
|
|
250
256
|
responseHeaders["content-type"] = "application/json";
|
|
@@ -263,10 +269,23 @@ var MockAdapter = class {
|
|
|
263
269
|
wasRedirectDetected: REDIRECT_STATUS_CODES.has(mockResponse.status),
|
|
264
270
|
...detectedRedirectURL ? { detectedRedirectURL } : {},
|
|
265
271
|
headers: normalizedResponseHeaders,
|
|
266
|
-
body: responseBody
|
|
272
|
+
body: responseBody,
|
|
273
|
+
...streamErrorCode !== void 0 ? {
|
|
274
|
+
isStreamError: true,
|
|
275
|
+
streamErrorCode,
|
|
276
|
+
errorCause: new Error(
|
|
277
|
+
"Mock response stream error (MockResponse.streamError)"
|
|
278
|
+
)
|
|
279
|
+
} : {}
|
|
267
280
|
};
|
|
268
281
|
}
|
|
269
282
|
};
|
|
283
|
+
function resolveMockStreamErrorCode(streamError) {
|
|
284
|
+
if (streamError === void 0 || streamError === false) {
|
|
285
|
+
return void 0;
|
|
286
|
+
}
|
|
287
|
+
return streamError === true ? "stream_response_error" : streamError;
|
|
288
|
+
}
|
|
270
289
|
function buildRoutes(router) {
|
|
271
290
|
function on(method, path, handler) {
|
|
272
291
|
try {
|
|
@@ -289,7 +308,8 @@ function buildRoutes(router) {
|
|
|
289
308
|
};
|
|
290
309
|
}
|
|
291
310
|
function isDuplicateRouteRegistrationError(error) {
|
|
292
|
-
|
|
311
|
+
const message = readObjectMember(error, "message");
|
|
312
|
+
return isErrorValue(error) && typeof message === "string" && message.includes("already declared for route");
|
|
293
313
|
}
|
|
294
314
|
function duplicateRouteRegistrationError(method, path, cause) {
|
|
295
315
|
return new Error(
|
|
@@ -461,11 +481,38 @@ function awaitAbortable(value, signal) {
|
|
|
461
481
|
},
|
|
462
482
|
(error) => {
|
|
463
483
|
signal.removeEventListener("abort", onAbort);
|
|
464
|
-
reject(
|
|
484
|
+
reject(normalizeError(error));
|
|
465
485
|
}
|
|
466
486
|
);
|
|
467
487
|
});
|
|
468
488
|
}
|
|
489
|
+
function readObjectMember(source, key) {
|
|
490
|
+
if (source === null || typeof source !== "object" && typeof source !== "function") {
|
|
491
|
+
return void 0;
|
|
492
|
+
}
|
|
493
|
+
try {
|
|
494
|
+
return source[key];
|
|
495
|
+
} catch {
|
|
496
|
+
return void 0;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
function isErrorValue(value) {
|
|
500
|
+
try {
|
|
501
|
+
return value instanceof Error;
|
|
502
|
+
} catch {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function normalizeError(value) {
|
|
507
|
+
if (isErrorValue(value)) {
|
|
508
|
+
return value;
|
|
509
|
+
}
|
|
510
|
+
try {
|
|
511
|
+
return new Error(String(value));
|
|
512
|
+
} catch {
|
|
513
|
+
return new Error("Unknown error");
|
|
514
|
+
}
|
|
515
|
+
}
|
|
469
516
|
function sleepAbortable(ms, signal) {
|
|
470
517
|
if (signal.aborted) {
|
|
471
518
|
throw new InternalMockAbortError();
|