@zudojs/constants 0.0.1 → 1.0.0
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 +123 -15
- package/dist/cache/cacheControl.type.d.ts +16 -7
- package/dist/cache/cacheControl.type.js +38 -6
- package/dist/common/common.constant.d.ts +80 -11
- package/dist/common/common.constant.js +126 -12
- package/dist/common/common.lifecycle.d.ts +43 -25
- package/dist/common/common.lifecycle.js +41 -27
- package/dist/common/common.schema.d.ts +58 -29
- package/dist/common/common.schema.js +74 -41
- package/dist/common/common.serialization.d.ts +18 -5
- package/dist/common/common.serialization.js +23 -8
- package/dist/common/index.d.ts +1 -1
- package/dist/common/index.js +1 -1
- package/dist/environment/environment.constant.d.ts +26 -2
- package/dist/environment/environment.constant.js +27 -3
- package/dist/environment/environment.type.d.ts +1 -1
- package/dist/environment/environment.type.js +3 -2
- package/dist/environment/index.d.ts +1 -1
- package/dist/http/httpContentType.type.d.ts +18 -4
- package/dist/http/httpContentType.type.js +22 -2
- package/dist/http/httpHeader.type.d.ts +7 -2
- package/dist/http/httpMethod.type.d.ts +3 -3
- package/dist/http/httpMethod.type.js +7 -6
- package/dist/http/httpStatus.type.d.ts +42 -2
- package/dist/http/httpStatus.type.js +36 -0
- package/dist/http/index.d.ts +3 -3
- package/dist/http/index.js +1 -1
- package/dist/internal/immutableSet.d.ts +26 -0
- package/dist/internal/immutableSet.js +40 -0
- package/dist/runtime/clock.d.ts +22 -2
- package/dist/runtime/clock.js +10 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/random.d.ts +10 -1
- package/dist/runtime/random.js +32 -17
- package/dist/time/time.constant.d.ts +7 -1
- package/dist/time/time.constant.js +11 -5
- package/dist/validation/validation.constant.d.ts +12 -5
- package/dist/validation/validation.constant.js +16 -8
- package/dist/validation/validation.pattern.type.d.ts +37 -8
- package/dist/validation/validation.pattern.type.js +44 -15
- package/package.json +15 -7
- package/dist/.tsbuildinfo +0 -1
- package/dist/cache/cacheControl.type.d.ts.map +0 -1
- package/dist/cache/cacheControl.type.js.map +0 -1
- package/dist/cache/cacheStrategy.type.d.ts.map +0 -1
- package/dist/cache/cacheStrategy.type.js.map +0 -1
- package/dist/cache/index.d.ts.map +0 -1
- package/dist/cache/index.js.map +0 -1
- package/dist/common/common.constant.d.ts.map +0 -1
- package/dist/common/common.constant.js.map +0 -1
- package/dist/common/common.lifecycle.d.ts.map +0 -1
- package/dist/common/common.lifecycle.js.map +0 -1
- package/dist/common/common.schema.d.ts.map +0 -1
- package/dist/common/common.schema.js.map +0 -1
- package/dist/common/common.serialization.d.ts.map +0 -1
- package/dist/common/common.serialization.js.map +0 -1
- package/dist/common/common.type.d.ts.map +0 -1
- package/dist/common/common.type.js.map +0 -1
- package/dist/common/index.d.ts.map +0 -1
- package/dist/common/index.js.map +0 -1
- package/dist/constantsErrors/constantsError.base.d.ts.map +0 -1
- package/dist/constantsErrors/constantsError.base.js.map +0 -1
- package/dist/constantsErrors/index.d.ts.map +0 -1
- package/dist/constantsErrors/index.js.map +0 -1
- package/dist/environment/environment.constant.d.ts.map +0 -1
- package/dist/environment/environment.constant.js.map +0 -1
- package/dist/environment/environment.type.d.ts.map +0 -1
- package/dist/environment/environment.type.js.map +0 -1
- package/dist/environment/index.d.ts.map +0 -1
- package/dist/environment/index.js.map +0 -1
- package/dist/http/httpContentType.type.d.ts.map +0 -1
- package/dist/http/httpContentType.type.js.map +0 -1
- package/dist/http/httpHeader.type.d.ts.map +0 -1
- package/dist/http/httpHeader.type.js.map +0 -1
- package/dist/http/httpMethod.type.d.ts.map +0 -1
- package/dist/http/httpMethod.type.js.map +0 -1
- package/dist/http/httpStatus.type.d.ts.map +0 -1
- package/dist/http/httpStatus.type.js.map +0 -1
- package/dist/http/index.d.ts.map +0 -1
- package/dist/http/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/priority/index.d.ts.map +0 -1
- package/dist/priority/index.js.map +0 -1
- package/dist/priority/priority.type.d.ts.map +0 -1
- package/dist/priority/priority.type.js.map +0 -1
- package/dist/runtime/clock.d.ts.map +0 -1
- package/dist/runtime/clock.js.map +0 -1
- package/dist/runtime/index.d.ts.map +0 -1
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/random.d.ts.map +0 -1
- package/dist/runtime/random.js.map +0 -1
- package/dist/time/index.d.ts.map +0 -1
- package/dist/time/index.js.map +0 -1
- package/dist/time/time.constant.d.ts.map +0 -1
- package/dist/time/time.constant.js.map +0 -1
- package/dist/time/time.unit.type.d.ts.map +0 -1
- package/dist/time/time.unit.type.js.map +0 -1
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/validation.constant.d.ts.map +0 -1
- package/dist/validation/validation.constant.js.map +0 -1
- package/dist/validation/validation.pattern.type.d.ts.map +0 -1
- package/dist/validation/validation.pattern.type.js.map +0 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module http/httpContentType
|
|
5
5
|
*/
|
|
6
|
+
import { InvalidConstantError } from "../constantsErrors/constantsError.base.js";
|
|
6
7
|
/**
|
|
7
8
|
* Common MIME content types.
|
|
8
9
|
*/
|
|
@@ -31,21 +32,40 @@ export const ContentTypes = Object.freeze({
|
|
|
31
32
|
});
|
|
32
33
|
/**
|
|
33
34
|
* Common charset values.
|
|
35
|
+
*
|
|
36
|
+
* These are IANA/MIME charset labels for use in `Content-Type` headers
|
|
37
|
+
* (e.g. `charset=us-ascii`) — they are NOT Node.js `Buffer` encoding names
|
|
38
|
+
* (Node uses `"ascii"`, `"utf16le"`, `"latin1"`, etc.).
|
|
34
39
|
*/
|
|
35
40
|
export const Charset = Object.freeze({
|
|
36
41
|
UTF_8: "utf-8",
|
|
37
|
-
ASCII: "ascii",
|
|
42
|
+
ASCII: "us-ascii",
|
|
38
43
|
ISO_8859_1: "iso-8859-1",
|
|
39
44
|
UTF_16: "utf-16",
|
|
40
45
|
});
|
|
41
46
|
/**
|
|
42
47
|
* Build a Content-Type header value with optional charset.
|
|
43
48
|
*
|
|
49
|
+
* The charset is omitted for `multipart/*` types, where a charset parameter
|
|
50
|
+
* is not meaningful (multipart types take a `boundary` parameter instead).
|
|
51
|
+
*
|
|
44
52
|
* @param mimeType - The MIME type (e.g. ContentTypes.JSON)
|
|
45
53
|
* @param charset - Optional charset (e.g. Charset.UTF_8)
|
|
46
54
|
* @returns Full Content-Type string (e.g. "application/json; charset=utf-8")
|
|
55
|
+
* @throws {InvalidConstantError} if `mimeType` is empty, or `charset` is
|
|
56
|
+
* provided but empty/blank.
|
|
47
57
|
*/
|
|
48
58
|
export function buildContentType(mimeType, charset) {
|
|
49
|
-
|
|
59
|
+
if (mimeType.trim().length === 0) {
|
|
60
|
+
throw new InvalidConstantError("buildContentType: mimeType must not be empty");
|
|
61
|
+
}
|
|
62
|
+
if (charset !== undefined && charset.trim().length === 0) {
|
|
63
|
+
throw new InvalidConstantError("buildContentType: charset must not be empty");
|
|
64
|
+
}
|
|
65
|
+
if (charset === undefined ||
|
|
66
|
+
mimeType.toLowerCase().startsWith("multipart/")) {
|
|
67
|
+
return mimeType;
|
|
68
|
+
}
|
|
69
|
+
return `${mimeType}; charset=${charset}`;
|
|
50
70
|
}
|
|
51
71
|
//# sourceMappingURL=httpContentType.type.js.map
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module http/httpHeader
|
|
5
5
|
*/
|
|
6
|
-
/** Type-safe HTTP header name string. */
|
|
7
|
-
export type HttpHeaderName = string;
|
|
8
6
|
/**
|
|
9
7
|
* Common HTTP header names.
|
|
10
8
|
*/
|
|
@@ -39,4 +37,11 @@ export declare const HttpHeader: Readonly<{
|
|
|
39
37
|
readonly X_API_KEY: "X-Api-Key";
|
|
40
38
|
readonly X_CORRELATION_ID: "X-Correlation-Id";
|
|
41
39
|
}>;
|
|
40
|
+
/** Type-safe HTTP header name — the union of all {@link HttpHeader} values. */
|
|
41
|
+
export type HttpHeaderName = (typeof HttpHeader)[keyof typeof HttpHeader];
|
|
42
|
+
/**
|
|
43
|
+
* Any HTTP header name — use when handling headers outside the
|
|
44
|
+
* {@link HttpHeader} catalogue (still autocompletes the known names).
|
|
45
|
+
*/
|
|
46
|
+
export type AnyHttpHeaderName = HttpHeaderName | (string & {});
|
|
42
47
|
//# sourceMappingURL=httpHeader.type.d.ts.map
|
|
@@ -19,10 +19,10 @@ export declare const HttpMethods: Readonly<{
|
|
|
19
19
|
readonly TRACE: "TRACE";
|
|
20
20
|
readonly CONNECT: "CONNECT";
|
|
21
21
|
}>;
|
|
22
|
-
/** Set of all HTTP methods for quick membership checks. */
|
|
22
|
+
/** Set of all HTTP methods for quick membership checks (immutable at runtime). */
|
|
23
23
|
export declare const HTTP_METHODS: ReadonlySet<HttpMethod>;
|
|
24
|
-
/** HTTP methods that are safe (no side effects). */
|
|
24
|
+
/** HTTP methods that are safe (no side effects). Immutable at runtime. */
|
|
25
25
|
export declare const SAFE_HTTP_METHODS: ReadonlySet<HttpMethod>;
|
|
26
|
-
/** HTTP methods that are idempotent. */
|
|
26
|
+
/** HTTP methods that are idempotent. Immutable at runtime. */
|
|
27
27
|
export declare const IDEMPOTENT_HTTP_METHODS: ReadonlySet<HttpMethod>;
|
|
28
28
|
//# sourceMappingURL=httpMethod.type.d.ts.map
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module http/httpMethod
|
|
5
5
|
*/
|
|
6
|
+
import { ImmutableSet } from "../internal/immutableSet.js";
|
|
6
7
|
/**
|
|
7
8
|
* All supported HTTP methods as an object map for runtime use.
|
|
8
9
|
*/
|
|
@@ -17,16 +18,16 @@ export const HttpMethods = Object.freeze({
|
|
|
17
18
|
TRACE: "TRACE",
|
|
18
19
|
CONNECT: "CONNECT",
|
|
19
20
|
});
|
|
20
|
-
/** Set of all HTTP methods for quick membership checks. */
|
|
21
|
-
export const HTTP_METHODS = new
|
|
22
|
-
/** HTTP methods that are safe (no side effects). */
|
|
23
|
-
export const SAFE_HTTP_METHODS = new
|
|
21
|
+
/** Set of all HTTP methods for quick membership checks (immutable at runtime). */
|
|
22
|
+
export const HTTP_METHODS = new ImmutableSet(Object.values(HttpMethods));
|
|
23
|
+
/** HTTP methods that are safe (no side effects). Immutable at runtime. */
|
|
24
|
+
export const SAFE_HTTP_METHODS = new ImmutableSet([
|
|
24
25
|
HttpMethods.GET,
|
|
25
26
|
HttpMethods.HEAD,
|
|
26
27
|
HttpMethods.OPTIONS,
|
|
27
28
|
]);
|
|
28
|
-
/** HTTP methods that are idempotent. */
|
|
29
|
-
export const IDEMPOTENT_HTTP_METHODS = new
|
|
29
|
+
/** HTTP methods that are idempotent. Immutable at runtime. */
|
|
30
|
+
export const IDEMPOTENT_HTTP_METHODS = new ImmutableSet([
|
|
30
31
|
HttpMethods.GET,
|
|
31
32
|
HttpMethods.HEAD,
|
|
32
33
|
HttpMethods.PUT,
|
|
@@ -3,39 +3,79 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module http/httpStatus
|
|
5
5
|
*/
|
|
6
|
-
/** Type-safe HTTP status code number. */
|
|
7
|
-
export type HttpStatusCode = number;
|
|
8
6
|
/**
|
|
9
7
|
* Standard HTTP status codes organized by category.
|
|
10
8
|
*/
|
|
11
9
|
export declare const HttpStatus: Readonly<{
|
|
10
|
+
readonly CONTINUE: 100;
|
|
11
|
+
readonly SWITCHING_PROTOCOLS: 101;
|
|
12
|
+
readonly PROCESSING: 102;
|
|
13
|
+
readonly EARLY_HINTS: 103;
|
|
12
14
|
readonly OK: 200;
|
|
13
15
|
readonly CREATED: 201;
|
|
14
16
|
readonly ACCEPTED: 202;
|
|
17
|
+
readonly NON_AUTHORITATIVE_INFORMATION: 203;
|
|
15
18
|
readonly NO_CONTENT: 204;
|
|
16
19
|
readonly RESET_CONTENT: 205;
|
|
17
20
|
readonly PARTIAL_CONTENT: 206;
|
|
21
|
+
readonly MULTI_STATUS: 207;
|
|
22
|
+
readonly ALREADY_REPORTED: 208;
|
|
23
|
+
readonly IM_USED: 226;
|
|
24
|
+
readonly MULTIPLE_CHOICES: 300;
|
|
18
25
|
readonly MOVED_PERMANENTLY: 301;
|
|
19
26
|
readonly FOUND: 302;
|
|
27
|
+
readonly SEE_OTHER: 303;
|
|
20
28
|
readonly NOT_MODIFIED: 304;
|
|
21
29
|
readonly TEMPORARY_REDIRECT: 307;
|
|
22
30
|
readonly PERMANENT_REDIRECT: 308;
|
|
23
31
|
readonly BAD_REQUEST: 400;
|
|
24
32
|
readonly UNAUTHORIZED: 401;
|
|
33
|
+
readonly PAYMENT_REQUIRED: 402;
|
|
25
34
|
readonly FORBIDDEN: 403;
|
|
26
35
|
readonly NOT_FOUND: 404;
|
|
27
36
|
readonly METHOD_NOT_ALLOWED: 405;
|
|
28
37
|
readonly NOT_ACCEPTABLE: 406;
|
|
38
|
+
readonly PROXY_AUTHENTICATION_REQUIRED: 407;
|
|
39
|
+
readonly REQUEST_TIMEOUT: 408;
|
|
29
40
|
readonly CONFLICT: 409;
|
|
30
41
|
readonly GONE: 410;
|
|
42
|
+
readonly LENGTH_REQUIRED: 411;
|
|
43
|
+
readonly PRECONDITION_FAILED: 412;
|
|
44
|
+
readonly PAYLOAD_TOO_LARGE: 413;
|
|
45
|
+
readonly URI_TOO_LONG: 414;
|
|
46
|
+
readonly UNSUPPORTED_MEDIA_TYPE: 415;
|
|
47
|
+
readonly RANGE_NOT_SATISFIABLE: 416;
|
|
48
|
+
readonly EXPECTATION_FAILED: 417;
|
|
49
|
+
readonly IM_A_TEAPOT: 418;
|
|
50
|
+
readonly MISDIRECTED_REQUEST: 421;
|
|
31
51
|
readonly UNPROCESSABLE_ENTITY: 422;
|
|
52
|
+
readonly LOCKED: 423;
|
|
53
|
+
readonly FAILED_DEPENDENCY: 424;
|
|
54
|
+
readonly TOO_EARLY: 425;
|
|
55
|
+
readonly UPGRADE_REQUIRED: 426;
|
|
56
|
+
readonly PRECONDITION_REQUIRED: 428;
|
|
32
57
|
readonly TOO_MANY_REQUESTS: 429;
|
|
58
|
+
readonly REQUEST_HEADER_FIELDS_TOO_LARGE: 431;
|
|
59
|
+
readonly UNAVAILABLE_FOR_LEGAL_REASONS: 451;
|
|
33
60
|
readonly INTERNAL_SERVER_ERROR: 500;
|
|
34
61
|
readonly NOT_IMPLEMENTED: 501;
|
|
35
62
|
readonly BAD_GATEWAY: 502;
|
|
36
63
|
readonly SERVICE_UNAVAILABLE: 503;
|
|
37
64
|
readonly GATEWAY_TIMEOUT: 504;
|
|
65
|
+
readonly HTTP_VERSION_NOT_SUPPORTED: 505;
|
|
66
|
+
readonly VARIANT_ALSO_NEGOTIATES: 506;
|
|
67
|
+
readonly INSUFFICIENT_STORAGE: 507;
|
|
68
|
+
readonly LOOP_DETECTED: 508;
|
|
69
|
+
readonly NOT_EXTENDED: 510;
|
|
70
|
+
readonly NETWORK_AUTHENTICATION_REQUIRED: 511;
|
|
38
71
|
}>;
|
|
72
|
+
/** Type-safe HTTP status code — the union of all {@link HttpStatus} values. */
|
|
73
|
+
export type HttpStatusCode = (typeof HttpStatus)[keyof typeof HttpStatus];
|
|
74
|
+
/**
|
|
75
|
+
* Any HTTP status code number — use when handling status codes outside the
|
|
76
|
+
* {@link HttpStatus} catalogue (e.g. from third-party servers).
|
|
77
|
+
*/
|
|
78
|
+
export type AnyHttpStatusCode = number;
|
|
39
79
|
/**
|
|
40
80
|
* Check whether a status code is in the 2xx success range.
|
|
41
81
|
*/
|
|
@@ -7,36 +7,72 @@
|
|
|
7
7
|
* Standard HTTP status codes organized by category.
|
|
8
8
|
*/
|
|
9
9
|
export const HttpStatus = Object.freeze({
|
|
10
|
+
// 1xx Informational
|
|
11
|
+
CONTINUE: 100,
|
|
12
|
+
SWITCHING_PROTOCOLS: 101,
|
|
13
|
+
PROCESSING: 102,
|
|
14
|
+
EARLY_HINTS: 103,
|
|
10
15
|
// 2xx Success
|
|
11
16
|
OK: 200,
|
|
12
17
|
CREATED: 201,
|
|
13
18
|
ACCEPTED: 202,
|
|
19
|
+
NON_AUTHORITATIVE_INFORMATION: 203,
|
|
14
20
|
NO_CONTENT: 204,
|
|
15
21
|
RESET_CONTENT: 205,
|
|
16
22
|
PARTIAL_CONTENT: 206,
|
|
23
|
+
MULTI_STATUS: 207,
|
|
24
|
+
ALREADY_REPORTED: 208,
|
|
25
|
+
IM_USED: 226,
|
|
17
26
|
// 3xx Redirection
|
|
27
|
+
MULTIPLE_CHOICES: 300,
|
|
18
28
|
MOVED_PERMANENTLY: 301,
|
|
19
29
|
FOUND: 302,
|
|
30
|
+
SEE_OTHER: 303,
|
|
20
31
|
NOT_MODIFIED: 304,
|
|
21
32
|
TEMPORARY_REDIRECT: 307,
|
|
22
33
|
PERMANENT_REDIRECT: 308,
|
|
23
34
|
// 4xx Client Error
|
|
24
35
|
BAD_REQUEST: 400,
|
|
25
36
|
UNAUTHORIZED: 401,
|
|
37
|
+
PAYMENT_REQUIRED: 402,
|
|
26
38
|
FORBIDDEN: 403,
|
|
27
39
|
NOT_FOUND: 404,
|
|
28
40
|
METHOD_NOT_ALLOWED: 405,
|
|
29
41
|
NOT_ACCEPTABLE: 406,
|
|
42
|
+
PROXY_AUTHENTICATION_REQUIRED: 407,
|
|
43
|
+
REQUEST_TIMEOUT: 408,
|
|
30
44
|
CONFLICT: 409,
|
|
31
45
|
GONE: 410,
|
|
46
|
+
LENGTH_REQUIRED: 411,
|
|
47
|
+
PRECONDITION_FAILED: 412,
|
|
48
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
49
|
+
URI_TOO_LONG: 414,
|
|
50
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
51
|
+
RANGE_NOT_SATISFIABLE: 416,
|
|
52
|
+
EXPECTATION_FAILED: 417,
|
|
53
|
+
IM_A_TEAPOT: 418,
|
|
54
|
+
MISDIRECTED_REQUEST: 421,
|
|
32
55
|
UNPROCESSABLE_ENTITY: 422,
|
|
56
|
+
LOCKED: 423,
|
|
57
|
+
FAILED_DEPENDENCY: 424,
|
|
58
|
+
TOO_EARLY: 425,
|
|
59
|
+
UPGRADE_REQUIRED: 426,
|
|
60
|
+
PRECONDITION_REQUIRED: 428,
|
|
33
61
|
TOO_MANY_REQUESTS: 429,
|
|
62
|
+
REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
|
|
63
|
+
UNAVAILABLE_FOR_LEGAL_REASONS: 451,
|
|
34
64
|
// 5xx Server Error
|
|
35
65
|
INTERNAL_SERVER_ERROR: 500,
|
|
36
66
|
NOT_IMPLEMENTED: 501,
|
|
37
67
|
BAD_GATEWAY: 502,
|
|
38
68
|
SERVICE_UNAVAILABLE: 503,
|
|
39
69
|
GATEWAY_TIMEOUT: 504,
|
|
70
|
+
HTTP_VERSION_NOT_SUPPORTED: 505,
|
|
71
|
+
VARIANT_ALSO_NEGOTIATES: 506,
|
|
72
|
+
INSUFFICIENT_STORAGE: 507,
|
|
73
|
+
LOOP_DETECTED: 508,
|
|
74
|
+
NOT_EXTENDED: 510,
|
|
75
|
+
NETWORK_AUTHENTICATION_REQUIRED: 511,
|
|
40
76
|
});
|
|
41
77
|
/**
|
|
42
78
|
* Check whether a status code is in the 2xx success range.
|
package/dist/http/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module http
|
|
5
5
|
*/
|
|
6
6
|
export { type HttpMethod, HttpMethods, HTTP_METHODS, SAFE_HTTP_METHODS, IDEMPOTENT_HTTP_METHODS, } from "./httpMethod.type.js";
|
|
7
|
-
export { type HttpStatusCode, HttpStatus, isSuccessStatus, isRedirectStatus, isClientError, isServerError, isErrorStatus, } from "./httpStatus.type.js";
|
|
8
|
-
export { type HttpHeaderName, HttpHeader } from "./httpHeader.type.js";
|
|
9
|
-
export { type ContentType, ContentTypes, Charset, buildContentType, } from "./httpContentType.type.js";
|
|
7
|
+
export { type HttpStatusCode, type AnyHttpStatusCode, HttpStatus, isSuccessStatus, isRedirectStatus, isClientError, isServerError, isErrorStatus, } from "./httpStatus.type.js";
|
|
8
|
+
export { type HttpHeaderName, type AnyHttpHeaderName, HttpHeader, } from "./httpHeader.type.js";
|
|
9
|
+
export { type ContentType, type AnyContentType, ContentTypes, Charset, buildContentType, } from "./httpContentType.type.js";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/http/index.js
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { HttpMethods, HTTP_METHODS, SAFE_HTTP_METHODS, IDEMPOTENT_HTTP_METHODS, } from "./httpMethod.type.js";
|
|
7
7
|
export { HttpStatus, isSuccessStatus, isRedirectStatus, isClientError, isServerError, isErrorStatus, } from "./httpStatus.type.js";
|
|
8
|
-
export { HttpHeader } from "./httpHeader.type.js";
|
|
8
|
+
export { HttpHeader, } from "./httpHeader.type.js";
|
|
9
9
|
export { ContentTypes, Charset, buildContentType, } from "./httpContentType.type.js";
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal immutable Set implementation.
|
|
3
|
+
*
|
|
4
|
+
* `Object.freeze` does not protect the internal slots of a `Set`, so a
|
|
5
|
+
* "frozen" Set still allows `.add()`, `.delete()`, and `.clear()` at runtime.
|
|
6
|
+
* This subclass hard-disables all mutators, making it safe to expose
|
|
7
|
+
* security-sensitive sets (e.g. forbidden schema keys) as `ReadonlySet`.
|
|
8
|
+
*
|
|
9
|
+
* @module internal/immutableSet
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A `Set` whose mutating methods (`add`, `delete`, `clear`) always throw.
|
|
13
|
+
*
|
|
14
|
+
* Values are inserted via `super.add` during construction only; afterwards
|
|
15
|
+
* the collection is permanently immutable.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ImmutableSet<T> extends Set<T> {
|
|
18
|
+
constructor(values?: Iterable<T>);
|
|
19
|
+
/** @throws {TypeError} always — this set is immutable. */
|
|
20
|
+
add(_value: T): this;
|
|
21
|
+
/** @throws {TypeError} always — this set is immutable. */
|
|
22
|
+
delete(_value: T): boolean;
|
|
23
|
+
/** @throws {TypeError} always — this set is immutable. */
|
|
24
|
+
clear(): void;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=immutableSet.d.ts.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal immutable Set implementation.
|
|
3
|
+
*
|
|
4
|
+
* `Object.freeze` does not protect the internal slots of a `Set`, so a
|
|
5
|
+
* "frozen" Set still allows `.add()`, `.delete()`, and `.clear()` at runtime.
|
|
6
|
+
* This subclass hard-disables all mutators, making it safe to expose
|
|
7
|
+
* security-sensitive sets (e.g. forbidden schema keys) as `ReadonlySet`.
|
|
8
|
+
*
|
|
9
|
+
* @module internal/immutableSet
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* A `Set` whose mutating methods (`add`, `delete`, `clear`) always throw.
|
|
13
|
+
*
|
|
14
|
+
* Values are inserted via `super.add` during construction only; afterwards
|
|
15
|
+
* the collection is permanently immutable.
|
|
16
|
+
*/
|
|
17
|
+
export class ImmutableSet extends Set {
|
|
18
|
+
constructor(values) {
|
|
19
|
+
super();
|
|
20
|
+
if (values !== undefined) {
|
|
21
|
+
for (const value of values) {
|
|
22
|
+
super.add(value);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
Object.freeze(this);
|
|
26
|
+
}
|
|
27
|
+
/** @throws {TypeError} always — this set is immutable. */
|
|
28
|
+
add(_value) {
|
|
29
|
+
throw new TypeError("Cannot add to an immutable Set");
|
|
30
|
+
}
|
|
31
|
+
/** @throws {TypeError} always — this set is immutable. */
|
|
32
|
+
delete(_value) {
|
|
33
|
+
throw new TypeError("Cannot delete from an immutable Set");
|
|
34
|
+
}
|
|
35
|
+
/** @throws {TypeError} always — this set is immutable. */
|
|
36
|
+
clear() {
|
|
37
|
+
throw new TypeError("Cannot clear an immutable Set");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=immutableSet.js.map
|
package/dist/runtime/clock.d.ts
CHANGED
|
@@ -13,15 +13,35 @@ export interface Clock {
|
|
|
13
13
|
now(): number;
|
|
14
14
|
/**
|
|
15
15
|
* Returns current Date.
|
|
16
|
+
*
|
|
17
|
+
* Note: the capitalised method name is kept for backwards compatibility
|
|
18
|
+
* (it mirrors the global `Date` constructor it wraps).
|
|
16
19
|
*/
|
|
17
20
|
Date(): Date;
|
|
18
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* A mock {@link Clock} whose time can be advanced or set explicitly.
|
|
24
|
+
*/
|
|
25
|
+
export interface MockClock extends Clock {
|
|
26
|
+
/**
|
|
27
|
+
* Advance the mock time by the given number of milliseconds.
|
|
28
|
+
*/
|
|
29
|
+
advance(ms: number): void;
|
|
30
|
+
/**
|
|
31
|
+
* Set the mock time to an absolute point in time — either a timestamp in
|
|
32
|
+
* milliseconds or a `Date`.
|
|
33
|
+
*/
|
|
34
|
+
set(time: number | Date): void;
|
|
35
|
+
}
|
|
19
36
|
/**
|
|
20
37
|
* Default clock using real system time.
|
|
21
38
|
*/
|
|
22
39
|
export declare const systemClock: Clock;
|
|
23
40
|
/**
|
|
24
|
-
* Creates a mock clock with a
|
|
41
|
+
* Creates a mock clock with a controllable time.
|
|
42
|
+
*
|
|
43
|
+
* The clock starts at `fixedTime` and stays there until `advance(ms)` or
|
|
44
|
+
* `set(time)` is called.
|
|
25
45
|
*/
|
|
26
|
-
export declare function createMockClock(fixedTime?: number):
|
|
46
|
+
export declare function createMockClock(fixedTime?: number): MockClock;
|
|
27
47
|
//# sourceMappingURL=clock.d.ts.map
|
package/dist/runtime/clock.js
CHANGED
|
@@ -11,13 +11,22 @@ export const systemClock = {
|
|
|
11
11
|
Date: () => new Date(),
|
|
12
12
|
};
|
|
13
13
|
/**
|
|
14
|
-
* Creates a mock clock with a
|
|
14
|
+
* Creates a mock clock with a controllable time.
|
|
15
|
+
*
|
|
16
|
+
* The clock starts at `fixedTime` and stays there until `advance(ms)` or
|
|
17
|
+
* `set(time)` is called.
|
|
15
18
|
*/
|
|
16
19
|
export function createMockClock(fixedTime = 0) {
|
|
17
20
|
let time = fixedTime;
|
|
18
21
|
return {
|
|
19
22
|
now: () => time,
|
|
20
23
|
Date: () => new Date(time),
|
|
24
|
+
advance: (ms) => {
|
|
25
|
+
time += ms;
|
|
26
|
+
},
|
|
27
|
+
set: (newTime) => {
|
|
28
|
+
time = typeof newTime === "number" ? newTime : newTime.getTime();
|
|
29
|
+
},
|
|
21
30
|
};
|
|
22
31
|
}
|
|
23
32
|
//# sourceMappingURL=clock.js.map
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module runtime
|
|
5
5
|
*/
|
|
6
6
|
export { systemClock, createMockClock } from "./clock.js";
|
|
7
|
-
export type { Clock } from "./clock.js";
|
|
7
|
+
export type { Clock, MockClock } from "./clock.js";
|
|
8
8
|
export { systemRandom, createMockRandom } from "./random.js";
|
|
9
9
|
export type { Random } from "./random.js";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/runtime/random.d.ts
CHANGED
|
@@ -25,11 +25,20 @@ export interface Random {
|
|
|
25
25
|
randomBytes(length: number): Uint8Array;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Default random
|
|
28
|
+
* Default random backed by `node:crypto` (CSPRNG).
|
|
29
|
+
*
|
|
30
|
+
* Every method — including `random()` — draws from the platform CSPRNG, so
|
|
31
|
+
* this singleton is safe to use for tokens, session IDs, salts, and other
|
|
32
|
+
* security-sensitive values. `random()` builds a 53-bit float in `[0, 1)`
|
|
33
|
+
* from 64 bits of `crypto.getRandomValues` output.
|
|
29
34
|
*/
|
|
30
35
|
export declare const systemRandom: Random;
|
|
31
36
|
/**
|
|
32
37
|
* Creates a mock random with a seeded sequence for deterministic testing.
|
|
38
|
+
*
|
|
39
|
+
* Uses a 32-bit linear congruential generator (Numerical Recipes constants)
|
|
40
|
+
* with `Math.imul` for exact 32-bit arithmetic. Outputs are always in
|
|
41
|
+
* `[0, 1)`. Not cryptographically secure — tests only.
|
|
33
42
|
*/
|
|
34
43
|
export declare function createMockRandom(seed?: number): Random;
|
|
35
44
|
//# sourceMappingURL=random.d.ts.map
|
package/dist/runtime/random.js
CHANGED
|
@@ -3,45 +3,60 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module runtime/random
|
|
5
5
|
*/
|
|
6
|
+
import { getRandomValues, randomBytes as cryptoRandomBytes, randomInt as cryptoRandomInt, } from "node:crypto";
|
|
7
|
+
/** Alphanumeric alphabet used by `randomString`. */
|
|
8
|
+
const RANDOM_STRING_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
9
|
+
/** Scratch buffer for `systemRandom.random()` (two 32-bit words = 64 bits). */
|
|
10
|
+
const RANDOM_FLOAT_WORDS = new Uint32Array(2);
|
|
6
11
|
/**
|
|
7
|
-
* Default random
|
|
12
|
+
* Default random backed by `node:crypto` (CSPRNG).
|
|
13
|
+
*
|
|
14
|
+
* Every method — including `random()` — draws from the platform CSPRNG, so
|
|
15
|
+
* this singleton is safe to use for tokens, session IDs, salts, and other
|
|
16
|
+
* security-sensitive values. `random()` builds a 53-bit float in `[0, 1)`
|
|
17
|
+
* from 64 bits of `crypto.getRandomValues` output.
|
|
8
18
|
*/
|
|
9
19
|
export const systemRandom = {
|
|
10
|
-
random: () =>
|
|
11
|
-
|
|
20
|
+
random: () => {
|
|
21
|
+
getRandomValues(RANDOM_FLOAT_WORDS);
|
|
22
|
+
// 21 high bits from word 0 and all 32 bits of word 1 = 53 bits of
|
|
23
|
+
// precision, mapped onto [0, 1) exactly like a double mantissa.
|
|
24
|
+
const high = RANDOM_FLOAT_WORDS[0] >>> 11;
|
|
25
|
+
const low = RANDOM_FLOAT_WORDS[1];
|
|
26
|
+
return (high * 0x100000000 + low) / 0x20000000000000;
|
|
27
|
+
},
|
|
28
|
+
randomInt: (min, max) => cryptoRandomInt(min, max + 1),
|
|
12
29
|
randomString: (length) => {
|
|
13
|
-
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
14
30
|
let result = "";
|
|
15
31
|
for (let i = 0; i < length; i++) {
|
|
16
|
-
result +=
|
|
32
|
+
result +=
|
|
33
|
+
RANDOM_STRING_CHARS[cryptoRandomInt(0, RANDOM_STRING_CHARS.length)];
|
|
17
34
|
}
|
|
18
35
|
return result;
|
|
19
36
|
},
|
|
20
|
-
randomBytes: (length) =>
|
|
21
|
-
const bytes = new Uint8Array(length);
|
|
22
|
-
for (let i = 0; i < length; i++) {
|
|
23
|
-
bytes[i] = Math.floor(Math.random() * 256);
|
|
24
|
-
}
|
|
25
|
-
return bytes;
|
|
26
|
-
},
|
|
37
|
+
randomBytes: (length) => new Uint8Array(cryptoRandomBytes(length)),
|
|
27
38
|
};
|
|
28
39
|
/**
|
|
29
40
|
* Creates a mock random with a seeded sequence for deterministic testing.
|
|
41
|
+
*
|
|
42
|
+
* Uses a 32-bit linear congruential generator (Numerical Recipes constants)
|
|
43
|
+
* with `Math.imul` for exact 32-bit arithmetic. Outputs are always in
|
|
44
|
+
* `[0, 1)`. Not cryptographically secure — tests only.
|
|
30
45
|
*/
|
|
31
46
|
export function createMockRandom(seed = 1) {
|
|
32
|
-
let state = seed;
|
|
47
|
+
let state = seed >>> 0;
|
|
33
48
|
function next() {
|
|
34
|
-
state = (state
|
|
35
|
-
return
|
|
49
|
+
state = (Math.imul(state, 1664525) + 1013904223) >>> 0;
|
|
50
|
+
return state / 0x100000000;
|
|
36
51
|
}
|
|
37
52
|
return {
|
|
38
53
|
random: next,
|
|
39
54
|
randomInt: (min, max) => Math.floor(next() * (max - min + 1)) + min,
|
|
40
55
|
randomString: (length) => {
|
|
41
|
-
const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
42
56
|
let result = "";
|
|
43
57
|
for (let i = 0; i < length; i++) {
|
|
44
|
-
result +=
|
|
58
|
+
result +=
|
|
59
|
+
RANDOM_STRING_CHARS[Math.floor(next() * RANDOM_STRING_CHARS.length)];
|
|
45
60
|
}
|
|
46
61
|
return result;
|
|
47
62
|
},
|
|
@@ -47,7 +47,13 @@ export declare const DefaultTimeout: Readonly<{
|
|
|
47
47
|
* Default retry configuration values.
|
|
48
48
|
*/
|
|
49
49
|
export declare const DefaultRetry: Readonly<{
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Default number of retry attempts used when nothing is configured.
|
|
52
|
+
*
|
|
53
|
+
* Distinct from `Limits.MAX_RETRY_ATTEMPTS` (10; also surfaced as
|
|
54
|
+
* `ValidationRange.MAX_RETRIES`), which is the upper bound on what a caller
|
|
55
|
+
* may configure — this is merely the out-of-the-box default.
|
|
56
|
+
*/
|
|
51
57
|
readonly MAX_ATTEMPTS: 3;
|
|
52
58
|
/** Base delay between retries in ms */
|
|
53
59
|
readonly BASE_DELAY_MS: 1000;
|
|
@@ -47,7 +47,13 @@ export const DefaultTimeout = Object.freeze({
|
|
|
47
47
|
* Default retry configuration values.
|
|
48
48
|
*/
|
|
49
49
|
export const DefaultRetry = Object.freeze({
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Default number of retry attempts used when nothing is configured.
|
|
52
|
+
*
|
|
53
|
+
* Distinct from `Limits.MAX_RETRY_ATTEMPTS` (10; also surfaced as
|
|
54
|
+
* `ValidationRange.MAX_RETRIES`), which is the upper bound on what a caller
|
|
55
|
+
* may configure — this is merely the out-of-the-box default.
|
|
56
|
+
*/
|
|
51
57
|
MAX_ATTEMPTS: 3,
|
|
52
58
|
/** Base delay between retries in ms */
|
|
53
59
|
BASE_DELAY_MS: 1_000,
|
|
@@ -87,11 +93,11 @@ export function formatDuration(ms) {
|
|
|
87
93
|
if (ms < TimeMs.SECOND)
|
|
88
94
|
return `${ms}ms`;
|
|
89
95
|
if (ms < TimeMs.MINUTE)
|
|
90
|
-
return `${Math.
|
|
96
|
+
return `${Math.floor(ms / TimeMs.SECOND)}s`;
|
|
91
97
|
if (ms < TimeMs.HOUR) {
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
return
|
|
98
|
+
const m = Math.floor(ms / TimeMs.MINUTE);
|
|
99
|
+
const s = Math.floor((ms % TimeMs.MINUTE) / TimeMs.SECOND);
|
|
100
|
+
return s > 0 ? `${m}m ${s}s` : `${m}m`;
|
|
95
101
|
}
|
|
96
102
|
if (ms < TimeMs.DAY) {
|
|
97
103
|
const h = Math.floor(ms / TimeMs.HOUR);
|
|
@@ -11,9 +11,9 @@ export declare const ValidationLength: Readonly<{
|
|
|
11
11
|
readonly SHORT: 64;
|
|
12
12
|
/** Standard name field */
|
|
13
13
|
readonly NAME: 128;
|
|
14
|
-
/** Email address */
|
|
15
|
-
readonly EMAIL:
|
|
16
|
-
/** Display name or title */
|
|
14
|
+
/** Email address (RFC 5321 maximum total length) */
|
|
15
|
+
readonly EMAIL: 254;
|
|
16
|
+
/** Display name or title (canonical: {@link Limits.MAX_DISPLAY_LENGTH}) */
|
|
17
17
|
readonly DISPLAY: 255;
|
|
18
18
|
/** Short description */
|
|
19
19
|
readonly DESCRIPTION_SHORT: 500;
|
|
@@ -40,7 +40,7 @@ export declare const ValidationRange: Readonly<{
|
|
|
40
40
|
readonly MAX_PERCENTAGE: 100;
|
|
41
41
|
/** Minimum page number (1-based) */
|
|
42
42
|
readonly MIN_PAGE: 1;
|
|
43
|
-
/** Maximum page size */
|
|
43
|
+
/** Maximum page size (canonical: {@link Limits.MAX_PAGE_SIZE}) */
|
|
44
44
|
readonly MAX_PAGE_SIZE: 100;
|
|
45
45
|
/** Minimum pagination offset */
|
|
46
46
|
readonly MIN_OFFSET: 0;
|
|
@@ -48,7 +48,14 @@ export declare const ValidationRange: Readonly<{
|
|
|
48
48
|
readonly MAX_TIMEOUT_SECONDS: 3600;
|
|
49
49
|
/** Minimum retry count */
|
|
50
50
|
readonly MIN_RETRIES: 0;
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Maximum retry count a caller may configure (upper validation bound;
|
|
53
|
+
* canonical: {@link Limits.MAX_RETRY_ATTEMPTS}).
|
|
54
|
+
*
|
|
55
|
+
* Note: this is intentionally larger than `DefaultRetry.MAX_ATTEMPTS` (3),
|
|
56
|
+
* which is the out-of-the-box default — this constant caps what users may
|
|
57
|
+
* request, the other is what they get if they configure nothing.
|
|
58
|
+
*/
|
|
52
59
|
readonly MAX_RETRIES: 10;
|
|
53
60
|
}>;
|
|
54
61
|
//# sourceMappingURL=validation.constant.d.ts.map
|