@zudojs/constants 0.1.0 → 1.0.1
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/LICENSE +21 -0
- 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 +25 -13
- 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,27 +3,42 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Lifecycle states, phases, valid transitions, and defaults.
|
|
5
5
|
*/
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Lifecycle states — a strongly-typed state machine.
|
|
8
|
+
*
|
|
9
|
+
* Declared as a frozen `as const` object (not a TS `enum`) to match the rest
|
|
10
|
+
* of the package; `LifecycleState` is also exported as the union type of its
|
|
11
|
+
* values, so it can be used in both value and type positions.
|
|
12
|
+
*/
|
|
13
|
+
export declare const LifecycleState: Readonly<{
|
|
14
|
+
readonly IDLE: "idle";
|
|
15
|
+
readonly INITIALIZING: "initializing";
|
|
16
|
+
readonly INITIALIZED: "initialized";
|
|
17
|
+
readonly STARTING: "starting";
|
|
18
|
+
readonly STARTED: "started";
|
|
19
|
+
readonly READY: "ready";
|
|
20
|
+
readonly STOPPING: "stopping";
|
|
21
|
+
readonly STOPPED: "stopped";
|
|
22
|
+
readonly FAILED: "failed";
|
|
23
|
+
readonly DISPOSED: "disposed";
|
|
24
|
+
}>;
|
|
25
|
+
/** Type-safe lifecycle state — the union of all {@link LifecycleState} values. */
|
|
26
|
+
export type LifecycleState = (typeof LifecycleState)[keyof typeof LifecycleState];
|
|
27
|
+
/**
|
|
28
|
+
* Lifecycle phases — the discrete hooks a component can implement.
|
|
29
|
+
*
|
|
30
|
+
* Declared as a frozen `as const` object; `LifecyclePhase` is also the union
|
|
31
|
+
* type of its values.
|
|
32
|
+
*/
|
|
33
|
+
export declare const LifecyclePhase: Readonly<{
|
|
34
|
+
readonly INITIALIZE: "initialize";
|
|
35
|
+
readonly START: "start";
|
|
36
|
+
readonly READY: "ready";
|
|
37
|
+
readonly STOP: "stop";
|
|
38
|
+
readonly DISPOSE: "dispose";
|
|
39
|
+
}>;
|
|
40
|
+
/** Type-safe lifecycle phase — the union of all {@link LifecyclePhase} values. */
|
|
41
|
+
export type LifecyclePhase = (typeof LifecyclePhase)[keyof typeof LifecyclePhase];
|
|
27
42
|
/** Valid state transitions for the lifecycle state machine. */
|
|
28
43
|
export declare const LIFECYCLE_VALID_TRANSITIONS: Readonly<Record<LifecycleState, readonly LifecycleState[]>>;
|
|
29
44
|
/** Default timeout for lifecycle operations (ms). */
|
|
@@ -34,10 +49,13 @@ export declare const LIFECYCLE_DEFAULT_START_TIMEOUT = 30000;
|
|
|
34
49
|
export declare const LIFECYCLE_DEFAULT_STOP_TIMEOUT = 10000;
|
|
35
50
|
/** Default global shutdown deadline (ms). */
|
|
36
51
|
export declare const LIFECYCLE_DEFAULT_SHUTDOWN_TIMEOUT = 30000;
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Default concurrency limit for parallel component operations
|
|
54
|
+
* (canonical: {@link Limits.MAX_CONCURRENCY}).
|
|
55
|
+
*/
|
|
56
|
+
export declare const LIFECYCLE_DEFAULT_CONCURRENCY: 10;
|
|
57
|
+
/** Default retry attempts (canonical: {@link DefaultRetry.MAX_ATTEMPTS}). */
|
|
58
|
+
export declare const LIFECYCLE_DEFAULT_RETRY_ATTEMPTS: 3;
|
|
41
59
|
/** Default retry delay (ms). */
|
|
42
60
|
export declare const LIFECYCLE_DEFAULT_RETRY_DELAY = 500;
|
|
43
61
|
/** Maximum retry delay (ms). */
|
|
@@ -3,29 +3,40 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Lifecycle states, phases, valid transitions, and defaults.
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
import { DefaultRetry } from "../time/time.constant.js";
|
|
7
|
+
import { Limits } from "./common.constant.js";
|
|
8
|
+
/**
|
|
9
|
+
* Lifecycle states — a strongly-typed state machine.
|
|
10
|
+
*
|
|
11
|
+
* Declared as a frozen `as const` object (not a TS `enum`) to match the rest
|
|
12
|
+
* of the package; `LifecycleState` is also exported as the union type of its
|
|
13
|
+
* values, so it can be used in both value and type positions.
|
|
14
|
+
*/
|
|
15
|
+
export const LifecycleState = Object.freeze({
|
|
16
|
+
IDLE: "idle",
|
|
17
|
+
INITIALIZING: "initializing",
|
|
18
|
+
INITIALIZED: "initialized",
|
|
19
|
+
STARTING: "starting",
|
|
20
|
+
STARTED: "started",
|
|
21
|
+
READY: "ready",
|
|
22
|
+
STOPPING: "stopping",
|
|
23
|
+
STOPPED: "stopped",
|
|
24
|
+
FAILED: "failed",
|
|
25
|
+
DISPOSED: "disposed",
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Lifecycle phases — the discrete hooks a component can implement.
|
|
29
|
+
*
|
|
30
|
+
* Declared as a frozen `as const` object; `LifecyclePhase` is also the union
|
|
31
|
+
* type of its values.
|
|
32
|
+
*/
|
|
33
|
+
export const LifecyclePhase = Object.freeze({
|
|
34
|
+
INITIALIZE: "initialize",
|
|
35
|
+
START: "start",
|
|
36
|
+
READY: "ready",
|
|
37
|
+
STOP: "stop",
|
|
38
|
+
DISPOSE: "dispose",
|
|
39
|
+
});
|
|
29
40
|
/** Valid state transitions for the lifecycle state machine. */
|
|
30
41
|
export const LIFECYCLE_VALID_TRANSITIONS = Object.freeze({
|
|
31
42
|
[LifecycleState.IDLE]: Object.freeze([
|
|
@@ -73,10 +84,13 @@ export const LIFECYCLE_DEFAULT_START_TIMEOUT = 30_000;
|
|
|
73
84
|
export const LIFECYCLE_DEFAULT_STOP_TIMEOUT = 10_000;
|
|
74
85
|
/** Default global shutdown deadline (ms). */
|
|
75
86
|
export const LIFECYCLE_DEFAULT_SHUTDOWN_TIMEOUT = 30_000;
|
|
76
|
-
/**
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Default concurrency limit for parallel component operations
|
|
89
|
+
* (canonical: {@link Limits.MAX_CONCURRENCY}).
|
|
90
|
+
*/
|
|
91
|
+
export const LIFECYCLE_DEFAULT_CONCURRENCY = Limits.MAX_CONCURRENCY;
|
|
92
|
+
/** Default retry attempts (canonical: {@link DefaultRetry.MAX_ATTEMPTS}). */
|
|
93
|
+
export const LIFECYCLE_DEFAULT_RETRY_ATTEMPTS = DefaultRetry.MAX_ATTEMPTS;
|
|
80
94
|
/** Default retry delay (ms). */
|
|
81
95
|
export const LIFECYCLE_DEFAULT_RETRY_DELAY = 500;
|
|
82
96
|
/** Maximum retry delay (ms). */
|
|
@@ -3,46 +3,75 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Schema-related constants, issue codes, and default limits.
|
|
5
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
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Schema issue codes — machine-readable, stable identifiers.
|
|
8
|
+
*
|
|
9
|
+
* Declared as a frozen `as const` object (not a TS `enum`) to match the rest
|
|
10
|
+
* of the package; `SchemaIssueCode` is also exported as the union type of its
|
|
11
|
+
* values, so it can be used in both value and type positions.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SchemaIssueCode: Readonly<{
|
|
14
|
+
readonly INVALID_TYPE: "invalid_type";
|
|
15
|
+
readonly REQUIRED: "required";
|
|
16
|
+
readonly INVALID_LITERAL: "invalid_literal";
|
|
17
|
+
readonly INVALID_ENUM: "invalid_enum";
|
|
18
|
+
readonly INVALID_UNION: "invalid_union";
|
|
19
|
+
readonly INVALID_STRING: "invalid_string";
|
|
20
|
+
readonly INVALID_FORMAT: "invalid_format";
|
|
21
|
+
readonly INVALID_NUMBER: "invalid_number";
|
|
22
|
+
readonly TOO_SMALL: "too_small";
|
|
23
|
+
readonly TOO_LARGE: "too_large";
|
|
24
|
+
readonly INVALID_LENGTH: "invalid_length";
|
|
25
|
+
readonly INVALID_KEY: "invalid_key";
|
|
26
|
+
readonly INVALID_ELEMENT: "invalid_element";
|
|
27
|
+
readonly UNKNOWN_KEYS: "unknown_keys";
|
|
28
|
+
readonly CIRCULAR_REFERENCE: "circular_reference";
|
|
29
|
+
readonly MAX_DEPTH_EXCEEDED: "max_depth_exceeded";
|
|
30
|
+
readonly CUSTOM: "custom";
|
|
31
|
+
readonly PREPROCESS_FAILED: "preprocess_failed";
|
|
32
|
+
readonly TRANSFORM_FAILED: "transform_failed";
|
|
33
|
+
readonly REFINE_FAILED: "refine_failed";
|
|
34
|
+
readonly COERCION_FAILED: "coercion_failed";
|
|
35
|
+
}>;
|
|
36
|
+
/** Type-safe schema issue code — the union of all {@link SchemaIssueCode} values. */
|
|
37
|
+
export type SchemaIssueCode = (typeof SchemaIssueCode)[keyof typeof SchemaIssueCode];
|
|
38
|
+
/**
|
|
39
|
+
* Default maximum depth for schema validation (recursion guard).
|
|
40
|
+
*
|
|
41
|
+
* Intentionally distinct from `Limits.MAX_NESTING_DEPTH` (10 — bound on
|
|
42
|
+
* acceptable user data shape) and `SerializationLimits.MAX_DEPTH` (128 —
|
|
43
|
+
* serializer recursion guard).
|
|
44
|
+
*/
|
|
31
45
|
export declare const SCHEMA_DEFAULT_MAX_DEPTH = 100;
|
|
32
|
-
/**
|
|
33
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Default maximum string length
|
|
48
|
+
* (canonical: {@link Limits.MAX_DISPLAY_LENGTH}).
|
|
49
|
+
*/
|
|
50
|
+
export declare const SCHEMA_DEFAULT_MAX_STRING_LENGTH: 255;
|
|
34
51
|
/** Default maximum array length. */
|
|
35
52
|
export declare const SCHEMA_DEFAULT_MAX_ARRAY_LENGTH = 1000;
|
|
36
53
|
/** Default maximum object key count. */
|
|
37
54
|
export declare const SCHEMA_DEFAULT_MAX_OBJECT_KEYS = 100;
|
|
38
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Object keys that are forbidden for prototype pollution protection.
|
|
57
|
+
*
|
|
58
|
+
* Backed by an immutable Set: `add`/`delete`/`clear` throw at runtime, so
|
|
59
|
+
* this security guard cannot be weakened by accident (or on purpose).
|
|
60
|
+
*/
|
|
39
61
|
export declare const SCHEMA_FORBIDDEN_KEYS: ReadonlySet<string>;
|
|
40
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Common string format regex patterns.
|
|
64
|
+
*
|
|
65
|
+
* These reference {@link ValidationPattern} — the single source of truth for
|
|
66
|
+
* validation regexes — rather than redefining them.
|
|
67
|
+
*/
|
|
41
68
|
export declare const SCHEMA_STRING_FORMATS: Readonly<{
|
|
42
69
|
readonly EMAIL: RegExp;
|
|
43
70
|
readonly URL: RegExp;
|
|
71
|
+
/** UUID — any version (use UUID_V4 for strict v4). */
|
|
44
72
|
readonly UUID: RegExp;
|
|
45
73
|
readonly UUID_V4: RegExp;
|
|
74
|
+
/** ISO 8601 date-time with optional fraction and Z/±hh:mm offset. */
|
|
46
75
|
readonly DATETIME: RegExp;
|
|
47
76
|
readonly DATE: RegExp;
|
|
48
77
|
readonly TIME: RegExp;
|
|
@@ -3,53 +3,86 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Schema-related constants, issue codes, and default limits.
|
|
5
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
|
-
|
|
6
|
+
import { ImmutableSet } from "../internal/immutableSet.js";
|
|
7
|
+
import { ValidationPattern } from "../validation/validation.pattern.type.js";
|
|
8
|
+
import { Limits } from "./common.constant.js";
|
|
9
|
+
/**
|
|
10
|
+
* Schema issue codes — machine-readable, stable identifiers.
|
|
11
|
+
*
|
|
12
|
+
* Declared as a frozen `as const` object (not a TS `enum`) to match the rest
|
|
13
|
+
* of the package; `SchemaIssueCode` is also exported as the union type of its
|
|
14
|
+
* values, so it can be used in both value and type positions.
|
|
15
|
+
*/
|
|
16
|
+
export const SchemaIssueCode = Object.freeze({
|
|
17
|
+
INVALID_TYPE: "invalid_type",
|
|
18
|
+
REQUIRED: "required",
|
|
19
|
+
INVALID_LITERAL: "invalid_literal",
|
|
20
|
+
INVALID_ENUM: "invalid_enum",
|
|
21
|
+
INVALID_UNION: "invalid_union",
|
|
22
|
+
INVALID_STRING: "invalid_string",
|
|
23
|
+
INVALID_FORMAT: "invalid_format",
|
|
24
|
+
INVALID_NUMBER: "invalid_number",
|
|
25
|
+
TOO_SMALL: "too_small",
|
|
26
|
+
TOO_LARGE: "too_large",
|
|
27
|
+
INVALID_LENGTH: "invalid_length",
|
|
28
|
+
INVALID_KEY: "invalid_key",
|
|
29
|
+
INVALID_ELEMENT: "invalid_element",
|
|
30
|
+
UNKNOWN_KEYS: "unknown_keys",
|
|
31
|
+
CIRCULAR_REFERENCE: "circular_reference",
|
|
32
|
+
MAX_DEPTH_EXCEEDED: "max_depth_exceeded",
|
|
33
|
+
CUSTOM: "custom",
|
|
34
|
+
PREPROCESS_FAILED: "preprocess_failed",
|
|
35
|
+
TRANSFORM_FAILED: "transform_failed",
|
|
36
|
+
REFINE_FAILED: "refine_failed",
|
|
37
|
+
COERCION_FAILED: "coercion_failed",
|
|
38
|
+
});
|
|
39
|
+
/**
|
|
40
|
+
* Default maximum depth for schema validation (recursion guard).
|
|
41
|
+
*
|
|
42
|
+
* Intentionally distinct from `Limits.MAX_NESTING_DEPTH` (10 — bound on
|
|
43
|
+
* acceptable user data shape) and `SerializationLimits.MAX_DEPTH` (128 —
|
|
44
|
+
* serializer recursion guard).
|
|
45
|
+
*/
|
|
32
46
|
export const SCHEMA_DEFAULT_MAX_DEPTH = 100;
|
|
33
|
-
/**
|
|
34
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Default maximum string length
|
|
49
|
+
* (canonical: {@link Limits.MAX_DISPLAY_LENGTH}).
|
|
50
|
+
*/
|
|
51
|
+
export const SCHEMA_DEFAULT_MAX_STRING_LENGTH = Limits.MAX_DISPLAY_LENGTH;
|
|
35
52
|
/** Default maximum array length. */
|
|
36
53
|
export const SCHEMA_DEFAULT_MAX_ARRAY_LENGTH = 1000;
|
|
37
54
|
/** Default maximum object key count. */
|
|
38
55
|
export const SCHEMA_DEFAULT_MAX_OBJECT_KEYS = 100;
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Object keys that are forbidden for prototype pollution protection.
|
|
58
|
+
*
|
|
59
|
+
* Backed by an immutable Set: `add`/`delete`/`clear` throw at runtime, so
|
|
60
|
+
* this security guard cannot be weakened by accident (or on purpose).
|
|
61
|
+
*/
|
|
62
|
+
export const SCHEMA_FORBIDDEN_KEYS = new ImmutableSet([
|
|
63
|
+
"__proto__",
|
|
64
|
+
"constructor",
|
|
65
|
+
"prototype",
|
|
66
|
+
]);
|
|
67
|
+
/**
|
|
68
|
+
* Common string format regex patterns.
|
|
69
|
+
*
|
|
70
|
+
* These reference {@link ValidationPattern} — the single source of truth for
|
|
71
|
+
* validation regexes — rather than redefining them.
|
|
72
|
+
*/
|
|
42
73
|
export const SCHEMA_STRING_FORMATS = Object.freeze({
|
|
43
|
-
EMAIL:
|
|
44
|
-
URL:
|
|
45
|
-
UUID
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
74
|
+
EMAIL: ValidationPattern.EMAIL,
|
|
75
|
+
URL: ValidationPattern.URL,
|
|
76
|
+
/** UUID — any version (use UUID_V4 for strict v4). */
|
|
77
|
+
UUID: ValidationPattern.UUID,
|
|
78
|
+
UUID_V4: ValidationPattern.UUID_V4,
|
|
79
|
+
/** ISO 8601 date-time with optional fraction and Z/±hh:mm offset. */
|
|
80
|
+
DATETIME: ValidationPattern.ISO_DATE_TIME,
|
|
81
|
+
DATE: ValidationPattern.ISO_DATE,
|
|
49
82
|
TIME: /^\d{2}:\d{2}(:\d{2})?$/,
|
|
50
|
-
IPV4:
|
|
51
|
-
IPV6:
|
|
52
|
-
HEX_COLOR:
|
|
53
|
-
PHONE:
|
|
83
|
+
IPV4: ValidationPattern.IPV4,
|
|
84
|
+
IPV6: ValidationPattern.IPV6,
|
|
85
|
+
HEX_COLOR: ValidationPattern.HEX_COLOR,
|
|
86
|
+
PHONE: ValidationPattern.PHONE,
|
|
54
87
|
});
|
|
55
88
|
//# sourceMappingURL=common.schema.js.map
|
|
@@ -10,18 +10,31 @@ export declare const SerializationFormat: Readonly<{
|
|
|
10
10
|
readonly BINARY: "binary";
|
|
11
11
|
readonly MESSAGEPACK: "messagepack";
|
|
12
12
|
}>;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* MIME content types for serialized data
|
|
15
|
+
* (canonical values: {@link ContentTypes}).
|
|
16
|
+
*/
|
|
14
17
|
export declare const SerializationContentType: Readonly<{
|
|
15
18
|
readonly JSON: "application/json";
|
|
16
19
|
readonly TEXT: "text/plain";
|
|
17
20
|
readonly OCTET: "application/octet-stream";
|
|
18
|
-
|
|
21
|
+
/** De facto standard MessagePack MIME type. */
|
|
22
|
+
readonly MSGPACK: "application/x-msgpack";
|
|
19
23
|
}>;
|
|
20
24
|
/** Default limits for serialization operations. */
|
|
21
25
|
export declare const SerializationLimits: Readonly<{
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Default maximum serialized payload size (10 MB;
|
|
28
|
+
* canonical: {@link Limits.MAX_FILE_SIZE}).
|
|
29
|
+
*/
|
|
30
|
+
readonly MAX_SIZE: 10485760;
|
|
31
|
+
/**
|
|
32
|
+
* Default maximum object nesting depth (serializer recursion guard).
|
|
33
|
+
*
|
|
34
|
+
* Intentionally distinct from `Limits.MAX_NESTING_DEPTH` (10 — bound on
|
|
35
|
+
* acceptable user data shape) and `SCHEMA_DEFAULT_MAX_DEPTH` (100 — schema
|
|
36
|
+
* validation recursion guard).
|
|
37
|
+
*/
|
|
25
38
|
readonly MAX_DEPTH: 128;
|
|
26
39
|
/** Maximum number of registered type transformers. */
|
|
27
40
|
readonly MAX_TRANSFORMERS: 256;
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module common/common.serialization
|
|
5
5
|
*/
|
|
6
|
+
import { ContentTypes } from "../http/httpContentType.type.js";
|
|
7
|
+
import { Limits } from "./common.constant.js";
|
|
6
8
|
/** Canonical serialization format names. */
|
|
7
9
|
export const SerializationFormat = Object.freeze({
|
|
8
10
|
JSON: "json",
|
|
@@ -10,18 +12,31 @@ export const SerializationFormat = Object.freeze({
|
|
|
10
12
|
BINARY: "binary",
|
|
11
13
|
MESSAGEPACK: "messagepack",
|
|
12
14
|
});
|
|
13
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* MIME content types for serialized data
|
|
17
|
+
* (canonical values: {@link ContentTypes}).
|
|
18
|
+
*/
|
|
14
19
|
export const SerializationContentType = Object.freeze({
|
|
15
|
-
JSON:
|
|
16
|
-
TEXT:
|
|
17
|
-
OCTET:
|
|
18
|
-
|
|
20
|
+
JSON: ContentTypes.JSON,
|
|
21
|
+
TEXT: ContentTypes.TEXT_PLAIN,
|
|
22
|
+
OCTET: ContentTypes.OCTET_STREAM,
|
|
23
|
+
/** De facto standard MessagePack MIME type. */
|
|
24
|
+
MSGPACK: "application/x-msgpack",
|
|
19
25
|
});
|
|
20
26
|
/** Default limits for serialization operations. */
|
|
21
27
|
export const SerializationLimits = Object.freeze({
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Default maximum serialized payload size (10 MB;
|
|
30
|
+
* canonical: {@link Limits.MAX_FILE_SIZE}).
|
|
31
|
+
*/
|
|
32
|
+
MAX_SIZE: Limits.MAX_FILE_SIZE,
|
|
33
|
+
/**
|
|
34
|
+
* Default maximum object nesting depth (serializer recursion guard).
|
|
35
|
+
*
|
|
36
|
+
* Intentionally distinct from `Limits.MAX_NESTING_DEPTH` (10 — bound on
|
|
37
|
+
* acceptable user data shape) and `SCHEMA_DEFAULT_MAX_DEPTH` (100 — schema
|
|
38
|
+
* validation recursion guard).
|
|
39
|
+
*/
|
|
25
40
|
MAX_DEPTH: 128,
|
|
26
41
|
/** Maximum number of registered type transformers. */
|
|
27
42
|
MAX_TRANSFORMERS: 256,
|
package/dist/common/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module common
|
|
5
5
|
*/
|
|
6
6
|
export { type Brand, type EntityId, type UserId, type EventId, type RequestId, type CorrelationId, type SessionId, type TenantId, type MessageId, type MessageCausationId, type TokenId, type Timestamp, type Url, type EmailAddress, type HexString, type Base64String, type JsonString, } from "./common.type.js";
|
|
7
|
-
export { NONE, UNINITIALIZED, EMPTY, Limits, Defaults, Sentinel, createUserId, createEventId, createRequestId, createCorrelationId, createTimestamp, } from "./common.constant.js";
|
|
7
|
+
export { NONE, UNINITIALIZED, EMPTY, Limits, Defaults, Sentinel, createUserId, createEventId, createRequestId, createCorrelationId, createSessionId, createTenantId, createMessageId, createMessageCausationId, createTokenId, createTimestamp, createUrl, createEmailAddress, createHexString, createBase64String, createJsonString, } from "./common.constant.js";
|
|
8
8
|
export { SerializationFormat, SerializationContentType, SerializationLimits, SerializationTags, SERIALIZATION_SCHEMA_VERSION, } from "./common.serialization.js";
|
|
9
9
|
export { SchemaIssueCode, SCHEMA_DEFAULT_MAX_DEPTH, SCHEMA_DEFAULT_MAX_STRING_LENGTH, SCHEMA_DEFAULT_MAX_ARRAY_LENGTH, SCHEMA_DEFAULT_MAX_OBJECT_KEYS, SCHEMA_FORBIDDEN_KEYS, SCHEMA_STRING_FORMATS, } from "./common.schema.js";
|
|
10
10
|
export { LifecycleState, LifecyclePhase, LIFECYCLE_VALID_TRANSITIONS, LIFECYCLE_DEFAULT_TIMEOUT, LIFECYCLE_DEFAULT_START_TIMEOUT, LIFECYCLE_DEFAULT_STOP_TIMEOUT, LIFECYCLE_DEFAULT_SHUTDOWN_TIMEOUT, LIFECYCLE_DEFAULT_CONCURRENCY, LIFECYCLE_DEFAULT_RETRY_ATTEMPTS, LIFECYCLE_DEFAULT_RETRY_DELAY, LIFECYCLE_DEFAULT_RETRY_MAX_DELAY, } from "./common.lifecycle.js";
|
package/dist/common/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @module common
|
|
5
5
|
*/
|
|
6
6
|
export {} from "./common.type.js";
|
|
7
|
-
export { NONE, UNINITIALIZED, EMPTY, Limits, Defaults, Sentinel, createUserId, createEventId, createRequestId, createCorrelationId, createTimestamp, } from "./common.constant.js";
|
|
7
|
+
export { NONE, UNINITIALIZED, EMPTY, Limits, Defaults, Sentinel, createUserId, createEventId, createRequestId, createCorrelationId, createSessionId, createTenantId, createMessageId, createMessageCausationId, createTokenId, createTimestamp, createUrl, createEmailAddress, createHexString, createBase64String, createJsonString, } from "./common.constant.js";
|
|
8
8
|
export { SerializationFormat, SerializationContentType, SerializationLimits, SerializationTags, SERIALIZATION_SCHEMA_VERSION, } from "./common.serialization.js";
|
|
9
9
|
export { SchemaIssueCode, SCHEMA_DEFAULT_MAX_DEPTH, SCHEMA_DEFAULT_MAX_STRING_LENGTH, SCHEMA_DEFAULT_MAX_ARRAY_LENGTH, SCHEMA_DEFAULT_MAX_OBJECT_KEYS, SCHEMA_FORBIDDEN_KEYS, SCHEMA_STRING_FORMATS, } from "./common.schema.js";
|
|
10
10
|
export { LifecycleState, LifecyclePhase, LIFECYCLE_VALID_TRANSITIONS, LIFECYCLE_DEFAULT_TIMEOUT, LIFECYCLE_DEFAULT_START_TIMEOUT, LIFECYCLE_DEFAULT_STOP_TIMEOUT, LIFECYCLE_DEFAULT_SHUTDOWN_TIMEOUT, LIFECYCLE_DEFAULT_CONCURRENCY, LIFECYCLE_DEFAULT_RETRY_ATTEMPTS, LIFECYCLE_DEFAULT_RETRY_DELAY, LIFECYCLE_DEFAULT_RETRY_MAX_DELAY, } from "./common.lifecycle.js";
|
|
@@ -6,15 +6,39 @@
|
|
|
6
6
|
import { type Environment } from "./environment.type.js";
|
|
7
7
|
/** Node environment variable name for detecting the current environment. */
|
|
8
8
|
export declare const NODE_ENV_KEY: "NODE_ENV";
|
|
9
|
+
/**
|
|
10
|
+
* Options for {@link resolveEnvironment}.
|
|
11
|
+
*/
|
|
12
|
+
export interface ResolveEnvironmentOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Throw an {@link InvalidConstantError} instead of warning and falling back
|
|
15
|
+
* to `"development"` when NODE_ENV holds an unrecognized value.
|
|
16
|
+
*/
|
|
17
|
+
readonly strict?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Suppress the one-time `console.warn` emitted for unrecognized NODE_ENV
|
|
20
|
+
* values (ignored in strict mode, which throws instead).
|
|
21
|
+
*/
|
|
22
|
+
readonly silent?: boolean;
|
|
23
|
+
}
|
|
9
24
|
/**
|
|
10
25
|
* Read the current environment from process.env.
|
|
11
26
|
*
|
|
12
|
-
*
|
|
27
|
+
* - Unset/empty NODE_ENV resolves to `"development"` silently.
|
|
28
|
+
* - An unrecognized value (e.g. a typo such as `"prodution"`) resolves to
|
|
29
|
+
* `"development"` but emits a `console.warn` once per distinct value per
|
|
30
|
+
* process, so a misconfigured production deployment does not silently run
|
|
31
|
+
* with development behaviour. Pass `{ silent: true }` to suppress the
|
|
32
|
+
* warning, or `{ strict: true }` to throw an {@link InvalidConstantError}
|
|
33
|
+
* instead.
|
|
13
34
|
*
|
|
14
35
|
* @param envOverride - Optional env map override (useful for testing)
|
|
36
|
+
* @param options - `strict`: throw on unrecognized values; `silent`: do not warn
|
|
15
37
|
* @returns The resolved Environment value
|
|
38
|
+
* @throws {InvalidConstantError} in strict mode, when NODE_ENV is set to an
|
|
39
|
+
* unrecognized value
|
|
16
40
|
*/
|
|
17
|
-
export declare function resolveEnvironment(envOverride?: Record<string, string | undefined
|
|
41
|
+
export declare function resolveEnvironment(envOverride?: Record<string, string | undefined>, options?: ResolveEnvironmentOptions): Environment;
|
|
18
42
|
/**
|
|
19
43
|
* Check whether the current environment is production.
|
|
20
44
|
*/
|
|
@@ -3,18 +3,33 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module environment/environment
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import {} from "./environment.type.js";
|
|
7
|
+
import { InvalidConstantError } from "../constantsErrors/constantsError.base.js";
|
|
7
8
|
/** Node environment variable name for detecting the current environment. */
|
|
8
9
|
export const NODE_ENV_KEY = "NODE_ENV";
|
|
10
|
+
/**
|
|
11
|
+
* Unrecognized NODE_ENV values that have already been warned about, so each
|
|
12
|
+
* distinct typo is reported once per process rather than on every call.
|
|
13
|
+
*/
|
|
14
|
+
const warnedUnrecognizedValues = new Set();
|
|
9
15
|
/**
|
|
10
16
|
* Read the current environment from process.env.
|
|
11
17
|
*
|
|
12
|
-
*
|
|
18
|
+
* - Unset/empty NODE_ENV resolves to `"development"` silently.
|
|
19
|
+
* - An unrecognized value (e.g. a typo such as `"prodution"`) resolves to
|
|
20
|
+
* `"development"` but emits a `console.warn` once per distinct value per
|
|
21
|
+
* process, so a misconfigured production deployment does not silently run
|
|
22
|
+
* with development behaviour. Pass `{ silent: true }` to suppress the
|
|
23
|
+
* warning, or `{ strict: true }` to throw an {@link InvalidConstantError}
|
|
24
|
+
* instead.
|
|
13
25
|
*
|
|
14
26
|
* @param envOverride - Optional env map override (useful for testing)
|
|
27
|
+
* @param options - `strict`: throw on unrecognized values; `silent`: do not warn
|
|
15
28
|
* @returns The resolved Environment value
|
|
29
|
+
* @throws {InvalidConstantError} in strict mode, when NODE_ENV is set to an
|
|
30
|
+
* unrecognized value
|
|
16
31
|
*/
|
|
17
|
-
export function resolveEnvironment(envOverride) {
|
|
32
|
+
export function resolveEnvironment(envOverride, options) {
|
|
18
33
|
const raw = (envOverride ?? process.env)[NODE_ENV_KEY];
|
|
19
34
|
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
20
35
|
const normalised = raw.trim().toLowerCase();
|
|
@@ -26,6 +41,15 @@ export function resolveEnvironment(envOverride) {
|
|
|
26
41
|
return "test";
|
|
27
42
|
if (normalised === "staging")
|
|
28
43
|
return "staging";
|
|
44
|
+
if (options?.strict === true) {
|
|
45
|
+
throw new InvalidConstantError(`Unrecognized ${NODE_ENV_KEY} value: ${JSON.stringify(raw)}`, { metadata: { value: raw } });
|
|
46
|
+
}
|
|
47
|
+
if (options?.silent !== true && !warnedUnrecognizedValues.has(raw)) {
|
|
48
|
+
warnedUnrecognizedValues.add(raw);
|
|
49
|
+
console.warn(`[@zudojs/constants] Unrecognized ${NODE_ENV_KEY} value ${JSON.stringify(raw)}; ` +
|
|
50
|
+
`falling back to "development". Expected one of: development, test, staging, production ` +
|
|
51
|
+
`(or the aliases dev, prod).`);
|
|
52
|
+
}
|
|
29
53
|
}
|
|
30
54
|
return "development";
|
|
31
55
|
}
|
|
@@ -14,7 +14,7 @@ export declare const Environments: Readonly<{
|
|
|
14
14
|
readonly STAGING: "staging";
|
|
15
15
|
readonly PRODUCTION: "production";
|
|
16
16
|
}>;
|
|
17
|
-
/** Set of all valid environments for quick membership checks. */
|
|
17
|
+
/** Set of all valid environments for quick membership checks (immutable at runtime). */
|
|
18
18
|
export declare const ENVIRONMENTS: ReadonlySet<Environment>;
|
|
19
19
|
/**
|
|
20
20
|
* Check whether a string is a valid Environment value.
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module environment/environment
|
|
5
5
|
*/
|
|
6
|
+
import { ImmutableSet } from "../internal/immutableSet.js";
|
|
6
7
|
/**
|
|
7
8
|
* All supported environments as an object map.
|
|
8
9
|
*/
|
|
@@ -12,8 +13,8 @@ export const Environments = Object.freeze({
|
|
|
12
13
|
STAGING: "staging",
|
|
13
14
|
PRODUCTION: "production",
|
|
14
15
|
});
|
|
15
|
-
/** Set of all valid environments for quick membership checks. */
|
|
16
|
-
export const ENVIRONMENTS = new
|
|
16
|
+
/** Set of all valid environments for quick membership checks (immutable at runtime). */
|
|
17
|
+
export const ENVIRONMENTS = new ImmutableSet(Object.values(Environments));
|
|
17
18
|
/**
|
|
18
19
|
* Check whether a string is a valid Environment value.
|
|
19
20
|
*/
|