@shirudo/ddd-kit 2.0.0 → 3.0.0-rc.10
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 +191 -53
- package/dist/chunks/kit-errors.d.ts +1081 -0
- package/dist/chunks/kit-errors.js +1165 -0
- package/dist/chunks/kit-errors.js.map +1 -0
- package/dist/chunks/ports.js +1815 -0
- package/dist/chunks/ports.js.map +1 -0
- package/dist/chunks/snapshot-store.d.ts +2397 -0
- package/dist/http.d.ts +64 -52
- package/dist/http.js +54 -20
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +4011 -2367
- package/dist/index.js +7091 -2370
- package/dist/index.js.map +1 -1
- package/dist/money.d.ts +376 -0
- package/dist/money.js +578 -0
- package/dist/money.js.map +1 -0
- package/dist/public-errors.d.ts +102 -0
- package/dist/public-errors.js +215 -0
- package/dist/public-errors.js.map +1 -0
- package/dist/testing.d.ts +631 -252
- package/dist/testing.js +2983 -782
- package/dist/testing.js.map +1 -1
- package/package.json +46 -29
- package/dist/aggregate-CePTINEt.d.ts +0 -722
- package/dist/presentation.d.ts +0 -54
- package/dist/presentation.js +0 -45
- package/dist/presentation.js.map +0 -1
- package/dist/utils.d.ts +0 -105
- package/dist/utils.js +0 -389
- package/dist/utils.js.map +0 -1
package/dist/http.d.ts
CHANGED
|
@@ -1,69 +1,81 @@
|
|
|
1
|
-
import { ValidationError } from
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
|
|
1
|
+
import { PublicIssue, ValidationError } from "@shirudo/base-error";
|
|
2
|
+
import { ProblemDetailsResult, ToProblemContext } from "@shirudo/base-error/public-error";
|
|
3
|
+
//#region src/presentation/http/problem-details.d.ts
|
|
4
|
+
/** Details member carried by a {@link toProblemDetails} body. */
|
|
5
|
+
interface ValidationProblemDetails {
|
|
6
|
+
/** The whitelisted field issues, straight from `publicIssues()`. */
|
|
7
|
+
readonly issues: readonly PublicIssue[];
|
|
8
|
+
}
|
|
6
9
|
/**
|
|
7
|
-
* Options for {@link toProblemDetails}: the
|
|
8
|
-
*
|
|
9
|
-
* and {@link extensions} for extra public members merged alongside them.
|
|
10
|
+
* Options for {@link toProblemDetails}: the transport members the boundary
|
|
11
|
+
* may set, plus {@link extensions} for extra public body members.
|
|
10
12
|
*/
|
|
11
|
-
interface ValidationProblemOptions {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* by contract (RFC 9457 bodies must serialize); a trace id, for example,
|
|
31
|
-
* is passed here, not as a recognized top-level field.
|
|
32
|
-
*/
|
|
33
|
-
extensions?: ProblemDetailsExtensions;
|
|
13
|
+
interface ValidationProblemOptions<TExtensions extends object = Record<never, never>> {
|
|
14
|
+
/** URI reference identifying the problem type. Defaults to `"about:blank"`. */
|
|
15
|
+
type?: string;
|
|
16
|
+
/** Short, human-readable summary. Default `"Validation Failed"`. */
|
|
17
|
+
title?: string;
|
|
18
|
+
/** HTTP status code. Default `422`. */
|
|
19
|
+
status?: number;
|
|
20
|
+
/** Human-readable explanation specific to this occurrence. */
|
|
21
|
+
detail?: string;
|
|
22
|
+
/** URI reference identifying this specific occurrence. */
|
|
23
|
+
instance?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Extra public extension members merged alongside the documented body
|
|
26
|
+
* members. Constrained by base-error's `toProblem` contract: JSON-safe,
|
|
27
|
+
* string-keyed, and free of the reserved member names, checked at
|
|
28
|
+
* compile time and re-validated at runtime (a colliding or
|
|
29
|
+
* non-JSON-safe set is dropped and recorded in `outcome.omitted`).
|
|
30
|
+
*/
|
|
31
|
+
extensions?: ToProblemContext<TExtensions>["extensions"];
|
|
34
32
|
}
|
|
35
33
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* issues
|
|
34
|
+
* The kit-named result of {@link toProblemDetails}: base-error's
|
|
35
|
+
* `ProblemDetailsResult` specialized to the validation shortcut. Exists so
|
|
36
|
+
* consumers can annotate boundaries from the kit entry alone; importing
|
|
37
|
+
* base-error stays an opt-in, never a prerequisite.
|
|
38
|
+
*/
|
|
39
|
+
type ValidationProblemResult<TExtensions extends object = Record<never, never>> = ProblemDetailsResult<ValidationProblemDetails, string, TExtensions>;
|
|
40
|
+
/**
|
|
41
|
+
* Projects a base-error {@link ValidationError} to an RFC 9457 Problem
|
|
42
|
+
* Details result by delegating to base-error's `toProblem` transport stage:
|
|
43
|
+
* one pipeline, one wire profile, one hardening implementation. The body
|
|
44
|
+
* carries the error's public `code`, and the whitelisted issues ride under
|
|
45
|
+
* `details.issues` (`{ message, path, code?, pointer? }`, never raw
|
|
46
|
+
* validator extras), the same shape `toPublicErrorView` uses.
|
|
48
47
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
48
|
+
* All of `toProblem`'s wire-safety guarantees apply: the body is deeply
|
|
49
|
+
* frozen with a null prototype (cannot carry or receive prototype
|
|
50
|
+
* pollution), every member is JSON-safe (a non-serializable value drops
|
|
51
|
+
* that member and records it in `result.outcome.omitted` instead of
|
|
52
|
+
* corrupting the wire), and extensions cannot collide with the reserved
|
|
53
|
+
* members. The result also carries the HTTP `status` and ready-made
|
|
54
|
+
* `headers`, so the boundary does not restate them.
|
|
52
55
|
*
|
|
53
56
|
* This is a presentation/transport concern and ships from the opt-in
|
|
54
57
|
* `@shirudo/ddd-kit/http` entry point: the core kit stays transport-free.
|
|
58
|
+
* For catalog-driven mapping across ALL your public errors use
|
|
59
|
+
* base-error's `definePublicErrors` + `project` + `toProblem` directly;
|
|
60
|
+
* this helper is the narrow validation shortcut.
|
|
55
61
|
*
|
|
56
62
|
* @example
|
|
57
63
|
* ```ts
|
|
58
64
|
* import { toProblemDetails } from "@shirudo/ddd-kit/http";
|
|
59
65
|
*
|
|
60
66
|
* if (result.isErr()) {
|
|
61
|
-
*
|
|
67
|
+
* const problem = toProblemDetails(result.error);
|
|
68
|
+
* return Response.json(problem.body, {
|
|
69
|
+
* status: problem.status,
|
|
70
|
+
* headers: problem.headers,
|
|
71
|
+
* });
|
|
62
72
|
* }
|
|
63
|
-
* // → { type: "about:blank", title: "Validation Failed", status: 422,
|
|
64
|
-
* //
|
|
73
|
+
* // body → { type: "about:blank", title: "Validation Failed", status: 422,
|
|
74
|
+
* // code: "VALIDATION_FAILED",
|
|
75
|
+
* // details: { issues: [{ message: "must be a valid email", ... }] } }
|
|
65
76
|
* ```
|
|
66
77
|
*/
|
|
67
|
-
declare function toProblemDetails(error: ValidationError, options?: ValidationProblemOptions):
|
|
68
|
-
|
|
69
|
-
export {
|
|
78
|
+
declare function toProblemDetails<TExtensions extends object = Record<never, never>>(error: ValidationError, options?: ValidationProblemOptions<TExtensions>): ValidationProblemResult<TExtensions>;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { ValidationProblemDetails, ValidationProblemOptions, ValidationProblemResult, toProblemDetails };
|
|
81
|
+
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.js
CHANGED
|
@@ -1,26 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
1
|
+
import { toProblem } from "@shirudo/base-error/public-error";
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
//#region src/presentation/http/problem-details.ts
|
|
4
|
+
/**
|
|
5
|
+
* Projects a base-error {@link ValidationError} to an RFC 9457 Problem
|
|
6
|
+
* Details result by delegating to base-error's `toProblem` transport stage:
|
|
7
|
+
* one pipeline, one wire profile, one hardening implementation. The body
|
|
8
|
+
* carries the error's public `code`, and the whitelisted issues ride under
|
|
9
|
+
* `details.issues` (`{ message, path, code?, pointer? }`, never raw
|
|
10
|
+
* validator extras), the same shape `toPublicErrorView` uses.
|
|
11
|
+
*
|
|
12
|
+
* All of `toProblem`'s wire-safety guarantees apply: the body is deeply
|
|
13
|
+
* frozen with a null prototype (cannot carry or receive prototype
|
|
14
|
+
* pollution), every member is JSON-safe (a non-serializable value drops
|
|
15
|
+
* that member and records it in `result.outcome.omitted` instead of
|
|
16
|
+
* corrupting the wire), and extensions cannot collide with the reserved
|
|
17
|
+
* members. The result also carries the HTTP `status` and ready-made
|
|
18
|
+
* `headers`, so the boundary does not restate them.
|
|
19
|
+
*
|
|
20
|
+
* This is a presentation/transport concern and ships from the opt-in
|
|
21
|
+
* `@shirudo/ddd-kit/http` entry point: the core kit stays transport-free.
|
|
22
|
+
* For catalog-driven mapping across ALL your public errors use
|
|
23
|
+
* base-error's `definePublicErrors` + `project` + `toProblem` directly;
|
|
24
|
+
* this helper is the narrow validation shortcut.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { toProblemDetails } from "@shirudo/ddd-kit/http";
|
|
29
|
+
*
|
|
30
|
+
* if (result.isErr()) {
|
|
31
|
+
* const problem = toProblemDetails(result.error);
|
|
32
|
+
* return Response.json(problem.body, {
|
|
33
|
+
* status: problem.status,
|
|
34
|
+
* headers: problem.headers,
|
|
35
|
+
* });
|
|
36
|
+
* }
|
|
37
|
+
* // body → { type: "about:blank", title: "Validation Failed", status: 422,
|
|
38
|
+
* // code: "VALIDATION_FAILED",
|
|
39
|
+
* // details: { issues: [{ message: "must be a valid email", ... }] } }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
5
42
|
function toProblemDetails(error, options = {}) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
problem[member] = error.publicIssues();
|
|
20
|
-
return problem;
|
|
43
|
+
const { type = "about:blank", title = "Validation Failed", status = 422, detail, instance, extensions } = options;
|
|
44
|
+
return toProblem({
|
|
45
|
+
status,
|
|
46
|
+
type,
|
|
47
|
+
title
|
|
48
|
+
}, {
|
|
49
|
+
code: error.code,
|
|
50
|
+
details: { issues: error.publicIssues() }
|
|
51
|
+
}, {
|
|
52
|
+
detail,
|
|
53
|
+
instance,
|
|
54
|
+
extensions
|
|
55
|
+
});
|
|
21
56
|
}
|
|
22
|
-
__name(toProblemDetails, "toProblemDetails");
|
|
23
57
|
|
|
58
|
+
//#endregion
|
|
24
59
|
export { toProblemDetails };
|
|
25
|
-
//# sourceMappingURL=http.js.map
|
|
26
60
|
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"http.js","names":[],"sources":["../src/presentation/http/problem-details.ts"],"sourcesContent":["// HTTP / transport presenters. Opt-in entry point (`@shirudo/ddd-kit/http`)\n// so the core kit stays free of transport concerns. Import only when you map\n// domain results to HTTP responses.\nimport type { PublicIssue, ValidationError } from \"@shirudo/base-error\";\nimport {\n\ttype ProblemDetailsResult,\n\ttype ToProblemContext,\n\ttoProblem,\n} from \"@shirudo/base-error/public-error\";\n\n/** Details member carried by a {@link toProblemDetails} body. */\nexport interface ValidationProblemDetails {\n\t/** The whitelisted field issues, straight from `publicIssues()`. */\n\treadonly issues: readonly PublicIssue[];\n}\n\n/**\n * Options for {@link toProblemDetails}: the transport members the boundary\n * may set, plus {@link extensions} for extra public body members.\n */\nexport interface ValidationProblemOptions<\n\tTExtensions extends object = Record<never, never>,\n> {\n\t/** URI reference identifying the problem type. Defaults to `\"about:blank\"`. */\n\ttype?: string;\n\t/** Short, human-readable summary. Default `\"Validation Failed\"`. */\n\ttitle?: string;\n\t/** HTTP status code. Default `422`. */\n\tstatus?: number;\n\t/** Human-readable explanation specific to this occurrence. */\n\tdetail?: string;\n\t/** URI reference identifying this specific occurrence. */\n\tinstance?: string;\n\t/**\n\t * Extra public extension members merged alongside the documented body\n\t * members. Constrained by base-error's `toProblem` contract: JSON-safe,\n\t * string-keyed, and free of the reserved member names, checked at\n\t * compile time and re-validated at runtime (a colliding or\n\t * non-JSON-safe set is dropped and recorded in `outcome.omitted`).\n\t */\n\textensions?: ToProblemContext<TExtensions>[\"extensions\"];\n}\n\n/**\n * The kit-named result of {@link toProblemDetails}: base-error's\n * `ProblemDetailsResult` specialized to the validation shortcut. Exists so\n * consumers can annotate boundaries from the kit entry alone; importing\n * base-error stays an opt-in, never a prerequisite.\n */\nexport type ValidationProblemResult<\n\tTExtensions extends object = Record<never, never>,\n> = ProblemDetailsResult<ValidationProblemDetails, string, TExtensions>;\n\n/**\n * Projects a base-error {@link ValidationError} to an RFC 9457 Problem\n * Details result by delegating to base-error's `toProblem` transport stage:\n * one pipeline, one wire profile, one hardening implementation. The body\n * carries the error's public `code`, and the whitelisted issues ride under\n * `details.issues` (`{ message, path, code?, pointer? }`, never raw\n * validator extras), the same shape `toPublicErrorView` uses.\n *\n * All of `toProblem`'s wire-safety guarantees apply: the body is deeply\n * frozen with a null prototype (cannot carry or receive prototype\n * pollution), every member is JSON-safe (a non-serializable value drops\n * that member and records it in `result.outcome.omitted` instead of\n * corrupting the wire), and extensions cannot collide with the reserved\n * members. The result also carries the HTTP `status` and ready-made\n * `headers`, so the boundary does not restate them.\n *\n * This is a presentation/transport concern and ships from the opt-in\n * `@shirudo/ddd-kit/http` entry point: the core kit stays transport-free.\n * For catalog-driven mapping across ALL your public errors use\n * base-error's `definePublicErrors` + `project` + `toProblem` directly;\n * this helper is the narrow validation shortcut.\n *\n * @example\n * ```ts\n * import { toProblemDetails } from \"@shirudo/ddd-kit/http\";\n *\n * if (result.isErr()) {\n * const problem = toProblemDetails(result.error);\n * return Response.json(problem.body, {\n * status: problem.status,\n * headers: problem.headers,\n * });\n * }\n * // body → { type: \"about:blank\", title: \"Validation Failed\", status: 422,\n * // code: \"VALIDATION_FAILED\",\n * // details: { issues: [{ message: \"must be a valid email\", ... }] } }\n * ```\n */\nexport function toProblemDetails<\n\tTExtensions extends object = Record<never, never>,\n>(\n\terror: ValidationError,\n\toptions: ValidationProblemOptions<TExtensions> = {},\n): ValidationProblemResult<TExtensions> {\n\tconst {\n\t\ttype = \"about:blank\",\n\t\ttitle = \"Validation Failed\",\n\t\tstatus = 422,\n\t\tdetail,\n\t\tinstance,\n\t\textensions,\n\t} = options;\n\n\treturn toProblem<ValidationProblemDetails, string, TExtensions>(\n\t\t{ status, type, title },\n\t\t{ code: error.code, details: { issues: error.publicIssues() } },\n\t\t{ detail, instance, extensions },\n\t);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2FA,SAAgB,iBAGf,OACA,UAAiD,CAAC,GACX;CACvC,MAAM,EACL,OAAO,eACP,QAAQ,qBACR,SAAS,KACT,QACA,UACA,eACG;CAEJ,OAAO,UACN;EAAE;EAAQ;EAAM;CAAM,GACtB;EAAE,MAAM,MAAM;EAAM,SAAS,EAAE,QAAQ,MAAM,aAAa,EAAE;CAAE,GAC9D;EAAE;EAAQ;EAAU;CAAW,CAChC;AACD"}
|