@cullet/erp-core 1.3.0 → 1.4.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/KIT_CONTEXT.md +5 -3
- package/README.md +160 -0
- package/dist/abac/index.cjs +7 -0
- package/dist/abac/index.d.cts +2 -0
- package/dist/abac/index.d.ts +2 -0
- package/dist/abac/index.js +2 -0
- package/dist/app-error.cjs +193 -0
- package/dist/app-error.cjs.map +1 -0
- package/dist/app-error.js +170 -0
- package/dist/app-error.js.map +1 -0
- package/dist/application/index.cjs +2 -1
- package/dist/application/index.d.cts +2 -1
- package/dist/application/index.d.ts +2 -1
- package/dist/application/index.js +2 -1
- package/dist/authorization-error.cjs +157 -0
- package/dist/authorization-error.cjs.map +1 -0
- package/dist/authorization-error.d.cts +113 -0
- package/dist/authorization-error.d.ts +113 -0
- package/dist/authorization-error.js +152 -0
- package/dist/authorization-error.js.map +1 -0
- package/dist/authorizer.port.d.cts +130 -0
- package/dist/authorizer.port.d.ts +130 -0
- package/dist/composite-authorizer.d.cts +216 -0
- package/dist/composite-authorizer.d.ts +216 -0
- package/dist/condition-evaluator.cjs +565 -0
- package/dist/condition-evaluator.cjs.map +1 -0
- package/dist/condition-evaluator.js +536 -0
- package/dist/condition-evaluator.js.map +1 -0
- package/dist/{gate-types.d.ts → core-config.d.cts} +78 -77
- package/dist/{gate-types.d.cts → core-config.d.ts} +78 -77
- package/dist/domain/index.cjs +2 -1
- package/dist/domain/index.d.cts +2 -1
- package/dist/domain/index.d.ts +2 -1
- package/dist/domain/index.js +2 -1
- package/dist/domain-event-contracts.cjs +3 -2
- package/dist/domain-event-contracts.cjs.map +1 -1
- package/dist/domain-event-contracts.js +2 -1
- package/dist/domain-event-contracts.js.map +1 -1
- package/dist/entity.cjs +126 -0
- package/dist/entity.cjs.map +1 -0
- package/dist/entity.js +115 -0
- package/dist/entity.js.map +1 -0
- package/dist/errors/index.cjs +8 -6
- package/dist/errors/index.d.cts +2 -1
- package/dist/errors/index.d.ts +2 -1
- package/dist/errors/index.js +4 -2
- package/dist/gate-engine-registry.cjs +5 -4
- package/dist/gate-engine-registry.cjs.map +1 -1
- package/dist/gate-engine-registry.d.cts +3 -2
- package/dist/gate-engine-registry.d.ts +3 -2
- package/dist/gate-engine-registry.js +2 -1
- package/dist/gate-engine-registry.js.map +1 -1
- package/dist/gate-v1-payload.schema.cjs +0 -562
- package/dist/gate-v1-payload.schema.cjs.map +1 -1
- package/dist/gate-v1-payload.schema.js +1 -533
- package/dist/gate-v1-payload.schema.js.map +1 -1
- package/dist/index.cjs +34 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -12
- package/dist/index.d.ts +19 -12
- package/dist/index.js +15 -9
- package/dist/index.js.map +1 -1
- package/dist/not-found-error.cjs +5 -5
- package/dist/not-found-error.cjs.map +1 -1
- package/dist/not-found-error.js +1 -1
- package/dist/outcome.d.cts +1 -83
- package/dist/outcome.d.ts +1 -83
- package/dist/parse-gate-payload.d.cts +2 -2
- package/dist/parse-gate-payload.d.ts +2 -2
- package/dist/path.d.cts +2 -2
- package/dist/path.d.ts +2 -2
- package/dist/policies/engines/index.d.cts +1 -1
- package/dist/policies/engines/index.d.ts +1 -1
- package/dist/policies/engines/v1/gate/index.cjs +5 -4
- package/dist/policies/engines/v1/gate/index.cjs.map +1 -1
- package/dist/policies/engines/v1/gate/index.d.cts +2 -2
- package/dist/policies/engines/v1/gate/index.d.ts +2 -2
- package/dist/policies/engines/v1/gate/index.js +2 -1
- package/dist/policies/engines/v1/gate/index.js.map +1 -1
- package/dist/policies/index.cjs +5 -5
- package/dist/policies/index.d.cts +3 -2
- package/dist/policies/index.d.ts +3 -2
- package/dist/policies/index.js +2 -2
- package/dist/policy-bridge.cjs +437 -0
- package/dist/policy-bridge.cjs.map +1 -0
- package/dist/policy-bridge.d.cts +185 -0
- package/dist/policy-bridge.d.ts +185 -0
- package/dist/policy-bridge.js +396 -0
- package/dist/policy-bridge.js.map +1 -0
- package/dist/policy-service.cjs +239 -239
- package/dist/policy-service.cjs.map +1 -1
- package/dist/policy-service.d.cts +2 -2
- package/dist/policy-service.d.ts +2 -2
- package/dist/policy-service.js +239 -239
- package/dist/policy-service.js.map +1 -1
- package/dist/rbac/index.cjs +9 -0
- package/dist/rbac/index.d.cts +3 -0
- package/dist/rbac/index.d.ts +3 -0
- package/dist/rbac/index.js +2 -0
- package/dist/requested-by.cjs +54 -0
- package/dist/requested-by.cjs.map +1 -0
- package/dist/requested-by.d.cts +25 -0
- package/dist/requested-by.d.ts +25 -0
- package/dist/requested-by.js +49 -0
- package/dist/requested-by.js.map +1 -0
- package/dist/result/index.d.cts +2 -1
- package/dist/result/index.d.ts +2 -1
- package/dist/result.d.cts +84 -0
- package/dist/result.d.ts +84 -0
- package/dist/rule.cjs +327 -0
- package/dist/rule.cjs.map +1 -0
- package/dist/rule.js +298 -0
- package/dist/rule.js.map +1 -0
- package/dist/temporal-use-case.cjs +1 -53
- package/dist/temporal-use-case.cjs.map +1 -1
- package/dist/temporal-use-case.d.cts +5 -27
- package/dist/temporal-use-case.d.ts +5 -27
- package/dist/temporal-use-case.js +2 -48
- package/dist/temporal-use-case.js.map +1 -1
- package/dist/unexpected-error.cjs +3 -192
- package/dist/unexpected-error.cjs.map +1 -1
- package/dist/unexpected-error.js +2 -167
- package/dist/unexpected-error.js.map +1 -1
- package/dist/uuid-identifier.d.cts +2 -85
- package/dist/uuid-identifier.d.ts +2 -85
- package/dist/validation-error.cjs +33 -166
- package/dist/validation-error.cjs.map +1 -1
- package/dist/validation-error.d.cts +2 -98
- package/dist/validation-error.d.ts +2 -98
- package/dist/validation-error.js +7 -134
- package/dist/validation-error.js.map +1 -1
- package/dist/value-object.cjs +0 -123
- package/dist/value-object.cjs.map +1 -1
- package/dist/value-object.d.cts +89 -0
- package/dist/value-object.d.ts +89 -0
- package/dist/value-object.js +1 -112
- package/dist/value-object.js.map +1 -1
- package/meta.json +18 -4
- package/package.json +27 -1
- package/src/abac/index.ts +1 -0
- package/src/core/abac/abac-request.ts +29 -0
- package/src/core/abac/attributes.ts +39 -0
- package/src/core/abac/authorizer.ts +108 -0
- package/src/core/abac/combining.ts +63 -0
- package/src/core/abac/composite-authorizer.ts +45 -0
- package/src/core/abac/domain/policy-set.ts +52 -0
- package/src/core/abac/domain/rule.ts +197 -0
- package/src/core/abac/index.ts +21 -0
- package/src/core/application/ports/abac-authorizer.port.ts +20 -0
- package/src/core/application/ports/authorizer.port.ts +22 -0
- package/src/core/errors/authorization-error.ts +26 -0
- package/src/core/errors/error-codes.ts +1 -0
- package/src/core/index.ts +7 -0
- package/src/core/rbac/access-request.ts +32 -0
- package/src/core/rbac/authorizer.ts +91 -0
- package/src/core/rbac/domain/grant.ts +96 -0
- package/src/core/rbac/domain/permission-set.ts +67 -0
- package/src/core/rbac/domain/permission.ts +119 -0
- package/src/core/rbac/domain/role.ts +101 -0
- package/src/core/rbac/domain/scope.ts +84 -0
- package/src/core/rbac/index.ts +15 -0
- package/src/core/rbac/policy-bridge.ts +44 -0
- package/src/examples/application/authorize-cancel-order-abac.example.ts +107 -0
- package/src/examples/application/authorize-cancel-order.example.ts +101 -0
- package/src/rbac/index.ts +1 -0
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unexpected-error.cjs","names":[],"sources":["../src/core/errors/error-codes.ts","../src/core/errors/utils/json-safe.ts","../src/core/errors/app-error.ts","../src/core/errors/unexpected-error.ts"],"sourcesContent":["const ErrorCodes = {\n authentication: {\n missingToken: \"sec.authn.missing_token\",\n invalidToken: \"sec.authn.invalid_token\",\n expiredToken: \"sec.authn.expired_token\",\n invalidCredentials: \"sec.authn.invalid_credentials\",\n },\n authorization: {\n forbidden: \"sec.authz.forbidden\",\n policyDenied: \"sec.authz.policy_denied\",\n missingCapability: \"sec.authz.missing_capability\",\n outOfScope: \"sec.authz.out_of_scope\",\n },\n businessRuleViolation: \"business_rule_violation\",\n conflict: {\n alreadyExists: \"conf.already_exists\",\n duplicate: \"conf.duplicate\",\n uniqueViolation: \"conf.unique_violation\",\n },\n idempotency: {\n keyMissing: \"idemp.key_missing\",\n inProgress: \"idemp.in_progress\",\n payloadMismatch: \"idemp.payload_mismatch\",\n replayNotSupported: \"idemp.replay_not_supported\",\n },\n integration: {\n timeout: \"int.timeout\",\n unreachable: \"int.unreachable\",\n badResponse: \"int.bad_response\",\n },\n legacyIncompatible: \"legacy_incompatible\",\n notFound: \"not_found\",\n serialization: {\n deserializePrefix: \"ser.des\",\n serializePrefix: \"ser.ser\",\n },\n temporal: {\n expired: \"tmp.expired\",\n notYetValid: \"tmp.not_yet_valid\",\n },\n unexpected: \"unexpected\",\n validation: \"validation_error\",\n} as const;\n\ntype SerializationCodeDirection = \"deserialize\" | \"serialize\";\n\nfunction serializationErrorCode(\n direction: SerializationCodeDirection,\n category: string,\n): string {\n const prefix =\n direction === \"deserialize\"\n ? ErrorCodes.serialization.deserializePrefix\n : ErrorCodes.serialization.serializePrefix;\n\n return `${prefix}.${category}`;\n}\n\nexport { ErrorCodes, serializationErrorCode };\nexport type { SerializationCodeDirection };\n","// Utilities for ensuring metadata is JSON-serializable.\n\nimport type { JsonSafeRecord, JsonSafeValue } from \"../types.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Constants\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst NON_SERIALIZABLE_PLACEHOLDER = \"[NonSerializable]\";\nconst CIRCULAR_REFERENCE_PLACEHOLDER = \"[Circular]\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Internal helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n// `seen` tracks the ancestors on the current traversal branch (a DFS path), not\n// every object visited. This collapses true circular references to a placeholder\n// while still serializing the same object referenced more than once across\n// sibling branches (a DAG) — matching `JSON.stringify`, which only rejects\n// cycles, not shared references.\nfunction sanitizeValue(value: unknown, seen: WeakSet<object>): JsonSafeValue {\n // Null passthrough\n if (value === null) return null;\n\n const type = typeof value;\n\n // Primitives\n if (type === \"string\" || type === \"number\" || type === \"boolean\") {\n return value as JsonSafeValue;\n }\n\n // Non-serializable primitives\n if (\n type === \"bigint\" ||\n type === \"function\" ||\n type === \"symbol\" ||\n value === undefined\n ) {\n return NON_SERIALIZABLE_PLACEHOLDER;\n }\n\n // Arrays (recursive)\n if (Array.isArray(value)) {\n if (seen.has(value)) return CIRCULAR_REFERENCE_PLACEHOLDER;\n seen.add(value);\n const sanitized = value.map((item) => sanitizeValue(item, seen));\n seen.delete(value);\n return sanitized;\n }\n\n // Date → placeholder (could also use .toISOString() if preferred)\n if (value instanceof Date) {\n return NON_SERIALIZABLE_PLACEHOLDER;\n }\n\n // Class instances and non-plain objects → placeholder\n if (!isPlainObject(value)) {\n return NON_SERIALIZABLE_PLACEHOLDER;\n }\n\n // Plain object (recursive)\n if (seen.has(value)) return CIRCULAR_REFERENCE_PLACEHOLDER;\n seen.add(value);\n const result: Record<string, JsonSafeValue> = {};\n for (const [key, val] of Object.entries(value)) {\n result[key] = sanitizeValue(val, seen);\n }\n seen.delete(value);\n return result;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Public API\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Ensures metadata is JSON-serializable.\n *\n * **Allowed:** string, number, boolean, null, arrays, and plain objects.\n *\n * **Converted to placeholder:** Date, BigInt, class instances, functions,\n * symbols, undefined, and circular references (which would otherwise make\n * `JSON.stringify` throw).\n *\n * @throws {TypeError} If `input` is not a plain object at the root level.\n */\nfunction assertJsonSafeMetadata(input: unknown): JsonSafeRecord {\n if (input === undefined) {\n return {};\n }\n\n if (!isPlainObject(input)) {\n throw new TypeError(\n \"metadata must be a plain object (Record<string, unknown>).\",\n );\n }\n\n return sanitizeValue(input, new WeakSet<object>()) as JsonSafeRecord;\n}\n\nexport {\n assertJsonSafeMetadata,\n CIRCULAR_REFERENCE_PLACEHOLDER,\n NON_SERIALIZABLE_PLACEHOLDER,\n};\n","// Base application error for the domain/application layer.\n// Encapsulates a code, optional cause, and JSON-safe metadata.\n\nimport type {\n AppErrorOptions,\n ErrorSeverity,\n JsonSafeRecord,\n} from \"./types.js\";\nimport { assertJsonSafeMetadata } from \"./utils/index.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// AppError (abstract base class)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Root of the application/domain error hierarchy. Every error the system raises\n * on purpose extends `AppError`, which gives callers a single `instanceof` to\n * catch and a uniform, serializable shape to log and transport.\n *\n * Beyond the native `Error` message it carries a stable `code` (the contract the\n * outside world matches on), an optional non-leaking `publicMessage`, a\n * severity, JSON-safe `metadata`, and the correlation/request/command ids that\n * stitch an error back to the request that produced it. The metadata is\n * validated as JSON-safe on construction, so a logger can serialize any\n * `AppError` without hitting a circular reference or a non-serializable value.\n *\n * Abstract on purpose: callers should throw a specific subclass (e.g.\n * {@link ValidationError}, {@link NotFoundError}) so the `code` and shape are\n * meaningful, never a bare `AppError`.\n */\nabstract class AppError extends Error {\n public readonly code: string;\n public readonly cause?: unknown;\n public readonly metadata?: JsonSafeRecord;\n public readonly type?: string;\n public readonly severity?: ErrorSeverity;\n public readonly createdAtIso: string;\n public readonly publicMessage?: string;\n /**\n * Identifies a single execution \"story\" in the system. All operations\n * related to the same logical flow must share the same correlationId.\n */\n public readonly correlationId?: string;\n /**\n * Identifies a specific technical request attempt (each retry may produce\n * a new requestId), even when the correlationId stays the same.\n */\n public readonly requestId?: string;\n /**\n * Marks the business intent / idempotency key; stays the same across\n * technical retries and multiple requests that represent the same intent.\n */\n public readonly commandId?: string;\n\n /**\n * Builds the common error envelope shared by every subclass.\n *\n * `name` is taken from `new.target` so the thrown instance reports its\n * concrete subclass name (not `\"AppError\"`), and the prototype is re-pinned\n * via `setPrototypeOf` so `instanceof` keeps working after transpilation to\n * older targets where extending built-ins breaks the chain. `createdAtIso`\n * defaults to now, and `metadata` is validated as JSON-safe so the error is\n * always serializable.\n *\n * Declared `protected`: instantiate a concrete subclass, never `AppError`.\n *\n * @param message - The internal, developer-facing message.\n * @param code - The stable machine-readable code callers match on.\n * @param options - Optional cause, metadata, severity, and correlation ids.\n * @throws When `options.metadata` contains a value that is not JSON-safe.\n */\n protected constructor(\n message: string,\n code: string,\n options?: AppErrorOptions,\n ) {\n super(message);\n\n this.name = new.target.name;\n this.code = code;\n this.cause = options?.cause;\n this.type = options?.type;\n this.severity = options?.severity;\n this.correlationId = options?.correlationId;\n this.requestId = options?.requestId;\n this.commandId = options?.commandId;\n this.createdAtIso = options?.createdAtIso ?? new Date().toISOString();\n this.publicMessage = options?.publicMessage;\n\n this.metadata = options?.metadata\n ? assertJsonSafeMetadata(options.metadata)\n : undefined;\n\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n /**\n * Returns a JSON-safe representation of the error.\n * Does NOT include `cause` by default (to avoid leaking internal details).\n */\n public toJSON(): Record<string, unknown> {\n const payload: Record<string, unknown> = {\n name: this.name,\n code: this.code,\n message: this.message,\n createdAtIso: this.createdAtIso,\n };\n\n // Optional fields are emitted only when defined, so the serialized\n // shape never carries `undefined`-valued keys (consistent with how the\n // correlation/request/command ids are handled).\n if (this.type !== undefined) payload.type = this.type;\n if (this.severity !== undefined) payload.severity = this.severity;\n if (this.publicMessage !== undefined)\n payload.publicMessage = this.publicMessage;\n if (this.metadata !== undefined) payload.metadata = this.metadata;\n if (this.correlationId !== undefined)\n payload.correlationId = this.correlationId;\n if (this.requestId !== undefined) payload.requestId = this.requestId;\n if (this.commandId !== undefined) payload.commandId = this.commandId;\n\n return payload;\n }\n}\n\nexport { AppError };\n","import { AppError } from \"./app-error.js\";\nimport { ErrorCodes } from \"./error-codes.js\";\nimport type { AppErrorOptions } from \"./types.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// UnexpectedError\n// ─────────────────────────────────────────────────────────────────────────────\n\nclass UnexpectedError extends AppError {\n constructor(\n message = \"Unexpected error\",\n cause?: unknown,\n options?: Omit<AppErrorOptions, \"cause\">,\n ) {\n super(message, ErrorCodes.unexpected, {\n cause,\n ...options,\n });\n }\n}\n\nexport { UnexpectedError };\n"],"mappings":";AAAA,MAAM,aAAa;CACf,gBAAgB;EACZ,cAAc;EACd,cAAc;EACd,cAAc;EACd,oBAAoB;CACxB;CACA,eAAe;EACX,WAAW;EACX,cAAc;EACd,mBAAmB;EACnB,YAAY;CAChB;CACA,uBAAuB;CACvB,UAAU;EACN,eAAe;EACf,WAAW;EACX,iBAAiB;CACrB;CACA,aAAa;EACT,YAAY;EACZ,YAAY;EACZ,iBAAiB;EACjB,oBAAoB;CACxB;CACA,aAAa;EACT,SAAS;EACT,aAAa;EACb,aAAa;CACjB;CACA,oBAAoB;CACpB,UAAU;CACV,eAAe;EACX,mBAAmB;EACnB,iBAAiB;CACrB;CACA,UAAU;EACN,SAAS;EACT,aAAa;CACjB;CACA,YAAY;CACZ,YAAY;AAChB;AAIA,SAAS,uBACL,WACA,UACM;CAMN,OAAO,GAJH,cAAc,gBACR,WAAW,cAAc,oBACzB,WAAW,cAAc,gBAElB,GAAG;AACxB;;;AChDA,MAAM,+BAA+B;AACrC,MAAM,iCAAiC;AAMvC,SAAS,cAAc,OAAkD;CACrE,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU,OAAO;CACxD,MAAM,QAAQ,OAAO,eAAe,KAAK;CACzC,OAAO,UAAU,OAAO,aAAa,UAAU;AACnD;AAOA,SAAS,cAAc,OAAgB,MAAsC;CAEzE,IAAI,UAAU,MAAM,OAAO;CAE3B,MAAM,OAAO,OAAO;CAGpB,IAAI,SAAS,YAAY,SAAS,YAAY,SAAS,WACnD,OAAO;CAIX,IACI,SAAS,YACT,SAAS,cACT,SAAS,YACT,UAAU,KAAA,GAEV,OAAO;CAIX,IAAI,MAAM,QAAQ,KAAK,GAAG;EACtB,IAAI,KAAK,IAAI,KAAK,GAAG,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AK;GACd,cAAc,KAAK;EACvB;EAKA,IAAI,KAAK,SAAS,KAAA,GAAW,QAAQ,OAAO,KAAK;EACjD,IAAI,KAAK,aAAa,KAAA,GAAW,QAAQ,WAAW,KAAK;EACzD,IAAI,KAAK,kBAAkB,KAAA,GACvB,QAAQ,gBAAgB,KAAK;EACjC,IAAI,KAAK,aAAa,KAAA,GAAW,QAAQ,WAAW,KAAK;EACzD,IAAI,KAAK,kBAAkB,KAAA,GACvB,QAAQ,gBAAgB,KAAK;EACjC,IAAI,KAAK,cAAc,KAAA,GAAW,QAAQ,YAAY,KAAK;EAC3D,IAAI,KAAK,cAAc,KAAA,GAAW,QAAQ,YAAY,KAAK;EAE3D,OAAO;CACX;AACJ;;;ACnHA,IAAM,kBAAN,cAA8B,SAAS;CACnC,YACI,UAAU,oBACV,OACA,SACF;EACE,MAAM,SAAS,WAAW,YAAY;GAClC;GACA,GAAG;EACP,CAAC;CACL;AACJ"}
|
|
1
|
+
{"version":3,"file":"unexpected-error.cjs","names":["AppError","ErrorCodes"],"sources":["../src/core/errors/unexpected-error.ts"],"sourcesContent":["import { AppError } from \"./app-error.js\";\nimport { ErrorCodes } from \"./error-codes.js\";\nimport type { AppErrorOptions } from \"./types.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// UnexpectedError\n// ─────────────────────────────────────────────────────────────────────────────\n\nclass UnexpectedError extends AppError {\n constructor(\n message = \"Unexpected error\",\n cause?: unknown,\n options?: Omit<AppErrorOptions, \"cause\">,\n ) {\n super(message, ErrorCodes.unexpected, {\n cause,\n ...options,\n });\n }\n}\n\nexport { UnexpectedError };\n"],"mappings":";;AAQA,IAAM,kBAAN,cAA8BA,kBAAAA,SAAS;CACnC,YACI,UAAU,oBACV,OACA,SACF;EACE,MAAM,SAASC,kBAAAA,WAAW,YAAY;GAClC;GACA,GAAG;EACP,CAAC;CACL;AACJ"}
|
package/dist/unexpected-error.js
CHANGED
|
@@ -1,169 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const ErrorCodes = {
|
|
3
|
-
authentication: {
|
|
4
|
-
missingToken: "sec.authn.missing_token",
|
|
5
|
-
invalidToken: "sec.authn.invalid_token",
|
|
6
|
-
expiredToken: "sec.authn.expired_token",
|
|
7
|
-
invalidCredentials: "sec.authn.invalid_credentials"
|
|
8
|
-
},
|
|
9
|
-
authorization: {
|
|
10
|
-
forbidden: "sec.authz.forbidden",
|
|
11
|
-
policyDenied: "sec.authz.policy_denied",
|
|
12
|
-
missingCapability: "sec.authz.missing_capability",
|
|
13
|
-
outOfScope: "sec.authz.out_of_scope"
|
|
14
|
-
},
|
|
15
|
-
businessRuleViolation: "business_rule_violation",
|
|
16
|
-
conflict: {
|
|
17
|
-
alreadyExists: "conf.already_exists",
|
|
18
|
-
duplicate: "conf.duplicate",
|
|
19
|
-
uniqueViolation: "conf.unique_violation"
|
|
20
|
-
},
|
|
21
|
-
idempotency: {
|
|
22
|
-
keyMissing: "idemp.key_missing",
|
|
23
|
-
inProgress: "idemp.in_progress",
|
|
24
|
-
payloadMismatch: "idemp.payload_mismatch",
|
|
25
|
-
replayNotSupported: "idemp.replay_not_supported"
|
|
26
|
-
},
|
|
27
|
-
integration: {
|
|
28
|
-
timeout: "int.timeout",
|
|
29
|
-
unreachable: "int.unreachable",
|
|
30
|
-
badResponse: "int.bad_response"
|
|
31
|
-
},
|
|
32
|
-
legacyIncompatible: "legacy_incompatible",
|
|
33
|
-
notFound: "not_found",
|
|
34
|
-
serialization: {
|
|
35
|
-
deserializePrefix: "ser.des",
|
|
36
|
-
serializePrefix: "ser.ser"
|
|
37
|
-
},
|
|
38
|
-
temporal: {
|
|
39
|
-
expired: "tmp.expired",
|
|
40
|
-
notYetValid: "tmp.not_yet_valid"
|
|
41
|
-
},
|
|
42
|
-
unexpected: "unexpected",
|
|
43
|
-
validation: "validation_error"
|
|
44
|
-
};
|
|
45
|
-
function serializationErrorCode(direction, category) {
|
|
46
|
-
return `${direction === "deserialize" ? ErrorCodes.serialization.deserializePrefix : ErrorCodes.serialization.serializePrefix}.${category}`;
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region src/core/errors/utils/json-safe.ts
|
|
50
|
-
const NON_SERIALIZABLE_PLACEHOLDER = "[NonSerializable]";
|
|
51
|
-
const CIRCULAR_REFERENCE_PLACEHOLDER = "[Circular]";
|
|
52
|
-
function isPlainObject(value) {
|
|
53
|
-
if (value === null || typeof value !== "object") return false;
|
|
54
|
-
const proto = Object.getPrototypeOf(value);
|
|
55
|
-
return proto === Object.prototype || proto === null;
|
|
56
|
-
}
|
|
57
|
-
function sanitizeValue(value, seen) {
|
|
58
|
-
if (value === null) return null;
|
|
59
|
-
const type = typeof value;
|
|
60
|
-
if (type === "string" || type === "number" || type === "boolean") return value;
|
|
61
|
-
if (type === "bigint" || type === "function" || type === "symbol" || value === void 0) return NON_SERIALIZABLE_PLACEHOLDER;
|
|
62
|
-
if (Array.isArray(value)) {
|
|
63
|
-
if (seen.has(value)) return CIRCULAR_REFERENCE_PLACEHOLDER;
|
|
64
|
-
seen.add(value);
|
|
65
|
-
const sanitized = value.map((item) => sanitizeValue(item, seen));
|
|
66
|
-
seen.delete(value);
|
|
67
|
-
return sanitized;
|
|
68
|
-
}
|
|
69
|
-
if (value instanceof Date) return NON_SERIALIZABLE_PLACEHOLDER;
|
|
70
|
-
if (!isPlainObject(value)) return NON_SERIALIZABLE_PLACEHOLDER;
|
|
71
|
-
if (seen.has(value)) return CIRCULAR_REFERENCE_PLACEHOLDER;
|
|
72
|
-
seen.add(value);
|
|
73
|
-
const result = {};
|
|
74
|
-
for (const [key, val] of Object.entries(value)) result[key] = sanitizeValue(val, seen);
|
|
75
|
-
seen.delete(value);
|
|
76
|
-
return result;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Ensures metadata is JSON-serializable.
|
|
80
|
-
*
|
|
81
|
-
* **Allowed:** string, number, boolean, null, arrays, and plain objects.
|
|
82
|
-
*
|
|
83
|
-
* **Converted to placeholder:** Date, BigInt, class instances, functions,
|
|
84
|
-
* symbols, undefined, and circular references (which would otherwise make
|
|
85
|
-
* `JSON.stringify` throw).
|
|
86
|
-
*
|
|
87
|
-
* @throws {TypeError} If `input` is not a plain object at the root level.
|
|
88
|
-
*/
|
|
89
|
-
function assertJsonSafeMetadata(input) {
|
|
90
|
-
if (input === void 0) return {};
|
|
91
|
-
if (!isPlainObject(input)) throw new TypeError("metadata must be a plain object (Record<string, unknown>).");
|
|
92
|
-
return sanitizeValue(input, /* @__PURE__ */ new WeakSet());
|
|
93
|
-
}
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/core/errors/app-error.ts
|
|
96
|
-
/**
|
|
97
|
-
* Root of the application/domain error hierarchy. Every error the system raises
|
|
98
|
-
* on purpose extends `AppError`, which gives callers a single `instanceof` to
|
|
99
|
-
* catch and a uniform, serializable shape to log and transport.
|
|
100
|
-
*
|
|
101
|
-
* Beyond the native `Error` message it carries a stable `code` (the contract the
|
|
102
|
-
* outside world matches on), an optional non-leaking `publicMessage`, a
|
|
103
|
-
* severity, JSON-safe `metadata`, and the correlation/request/command ids that
|
|
104
|
-
* stitch an error back to the request that produced it. The metadata is
|
|
105
|
-
* validated as JSON-safe on construction, so a logger can serialize any
|
|
106
|
-
* `AppError` without hitting a circular reference or a non-serializable value.
|
|
107
|
-
*
|
|
108
|
-
* Abstract on purpose: callers should throw a specific subclass (e.g.
|
|
109
|
-
* {@link ValidationError}, {@link NotFoundError}) so the `code` and shape are
|
|
110
|
-
* meaningful, never a bare `AppError`.
|
|
111
|
-
*/
|
|
112
|
-
var AppError = class extends Error {
|
|
113
|
-
/**
|
|
114
|
-
* Builds the common error envelope shared by every subclass.
|
|
115
|
-
*
|
|
116
|
-
* `name` is taken from `new.target` so the thrown instance reports its
|
|
117
|
-
* concrete subclass name (not `"AppError"`), and the prototype is re-pinned
|
|
118
|
-
* via `setPrototypeOf` so `instanceof` keeps working after transpilation to
|
|
119
|
-
* older targets where extending built-ins breaks the chain. `createdAtIso`
|
|
120
|
-
* defaults to now, and `metadata` is validated as JSON-safe so the error is
|
|
121
|
-
* always serializable.
|
|
122
|
-
*
|
|
123
|
-
* Declared `protected`: instantiate a concrete subclass, never `AppError`.
|
|
124
|
-
*
|
|
125
|
-
* @param message - The internal, developer-facing message.
|
|
126
|
-
* @param code - The stable machine-readable code callers match on.
|
|
127
|
-
* @param options - Optional cause, metadata, severity, and correlation ids.
|
|
128
|
-
* @throws When `options.metadata` contains a value that is not JSON-safe.
|
|
129
|
-
*/
|
|
130
|
-
constructor(message, code, options) {
|
|
131
|
-
super(message);
|
|
132
|
-
this.name = new.target.name;
|
|
133
|
-
this.code = code;
|
|
134
|
-
this.cause = options?.cause;
|
|
135
|
-
this.type = options?.type;
|
|
136
|
-
this.severity = options?.severity;
|
|
137
|
-
this.correlationId = options?.correlationId;
|
|
138
|
-
this.requestId = options?.requestId;
|
|
139
|
-
this.commandId = options?.commandId;
|
|
140
|
-
this.createdAtIso = options?.createdAtIso ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
141
|
-
this.publicMessage = options?.publicMessage;
|
|
142
|
-
this.metadata = options?.metadata ? assertJsonSafeMetadata(options.metadata) : void 0;
|
|
143
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Returns a JSON-safe representation of the error.
|
|
147
|
-
* Does NOT include `cause` by default (to avoid leaking internal details).
|
|
148
|
-
*/
|
|
149
|
-
toJSON() {
|
|
150
|
-
const payload = {
|
|
151
|
-
name: this.name,
|
|
152
|
-
code: this.code,
|
|
153
|
-
message: this.message,
|
|
154
|
-
createdAtIso: this.createdAtIso
|
|
155
|
-
};
|
|
156
|
-
if (this.type !== void 0) payload.type = this.type;
|
|
157
|
-
if (this.severity !== void 0) payload.severity = this.severity;
|
|
158
|
-
if (this.publicMessage !== void 0) payload.publicMessage = this.publicMessage;
|
|
159
|
-
if (this.metadata !== void 0) payload.metadata = this.metadata;
|
|
160
|
-
if (this.correlationId !== void 0) payload.correlationId = this.correlationId;
|
|
161
|
-
if (this.requestId !== void 0) payload.requestId = this.requestId;
|
|
162
|
-
if (this.commandId !== void 0) payload.commandId = this.commandId;
|
|
163
|
-
return payload;
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
//#endregion
|
|
1
|
+
import { r as ErrorCodes, t as AppError } from "./app-error.js";
|
|
167
2
|
//#region src/core/errors/unexpected-error.ts
|
|
168
3
|
var UnexpectedError = class extends AppError {
|
|
169
4
|
constructor(message = "Unexpected error", cause, options) {
|
|
@@ -174,6 +9,6 @@ var UnexpectedError = class extends AppError {
|
|
|
174
9
|
}
|
|
175
10
|
};
|
|
176
11
|
//#endregion
|
|
177
|
-
export {
|
|
12
|
+
export { UnexpectedError as t };
|
|
178
13
|
|
|
179
14
|
//# sourceMappingURL=unexpected-error.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unexpected-error.js","names":[],"sources":["../src/core/errors/error-codes.ts","../src/core/errors/utils/json-safe.ts","../src/core/errors/app-error.ts","../src/core/errors/unexpected-error.ts"],"sourcesContent":["const ErrorCodes = {\n authentication: {\n missingToken: \"sec.authn.missing_token\",\n invalidToken: \"sec.authn.invalid_token\",\n expiredToken: \"sec.authn.expired_token\",\n invalidCredentials: \"sec.authn.invalid_credentials\",\n },\n authorization: {\n forbidden: \"sec.authz.forbidden\",\n policyDenied: \"sec.authz.policy_denied\",\n missingCapability: \"sec.authz.missing_capability\",\n outOfScope: \"sec.authz.out_of_scope\",\n },\n businessRuleViolation: \"business_rule_violation\",\n conflict: {\n alreadyExists: \"conf.already_exists\",\n duplicate: \"conf.duplicate\",\n uniqueViolation: \"conf.unique_violation\",\n },\n idempotency: {\n keyMissing: \"idemp.key_missing\",\n inProgress: \"idemp.in_progress\",\n payloadMismatch: \"idemp.payload_mismatch\",\n replayNotSupported: \"idemp.replay_not_supported\",\n },\n integration: {\n timeout: \"int.timeout\",\n unreachable: \"int.unreachable\",\n badResponse: \"int.bad_response\",\n },\n legacyIncompatible: \"legacy_incompatible\",\n notFound: \"not_found\",\n serialization: {\n deserializePrefix: \"ser.des\",\n serializePrefix: \"ser.ser\",\n },\n temporal: {\n expired: \"tmp.expired\",\n notYetValid: \"tmp.not_yet_valid\",\n },\n unexpected: \"unexpected\",\n validation: \"validation_error\",\n} as const;\n\ntype SerializationCodeDirection = \"deserialize\" | \"serialize\";\n\nfunction serializationErrorCode(\n direction: SerializationCodeDirection,\n category: string,\n): string {\n const prefix =\n direction === \"deserialize\"\n ? ErrorCodes.serialization.deserializePrefix\n : ErrorCodes.serialization.serializePrefix;\n\n return `${prefix}.${category}`;\n}\n\nexport { ErrorCodes, serializationErrorCode };\nexport type { SerializationCodeDirection };\n","// Utilities for ensuring metadata is JSON-serializable.\n\nimport type { JsonSafeRecord, JsonSafeValue } from \"../types.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Constants\n// ─────────────────────────────────────────────────────────────────────────────\n\nconst NON_SERIALIZABLE_PLACEHOLDER = \"[NonSerializable]\";\nconst CIRCULAR_REFERENCE_PLACEHOLDER = \"[Circular]\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Internal helpers\n// ─────────────────────────────────────────────────────────────────────────────\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n if (value === null || typeof value !== \"object\") return false;\n const proto = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n\n// `seen` tracks the ancestors on the current traversal branch (a DFS path), not\n// every object visited. This collapses true circular references to a placeholder\n// while still serializing the same object referenced more than once across\n// sibling branches (a DAG) — matching `JSON.stringify`, which only rejects\n// cycles, not shared references.\nfunction sanitizeValue(value: unknown, seen: WeakSet<object>): JsonSafeValue {\n // Null passthrough\n if (value === null) return null;\n\n const type = typeof value;\n\n // Primitives\n if (type === \"string\" || type === \"number\" || type === \"boolean\") {\n return value as JsonSafeValue;\n }\n\n // Non-serializable primitives\n if (\n type === \"bigint\" ||\n type === \"function\" ||\n type === \"symbol\" ||\n value === undefined\n ) {\n return NON_SERIALIZABLE_PLACEHOLDER;\n }\n\n // Arrays (recursive)\n if (Array.isArray(value)) {\n if (seen.has(value)) return CIRCULAR_REFERENCE_PLACEHOLDER;\n seen.add(value);\n const sanitized = value.map((item) => sanitizeValue(item, seen));\n seen.delete(value);\n return sanitized;\n }\n\n // Date → placeholder (could also use .toISOString() if preferred)\n if (value instanceof Date) {\n return NON_SERIALIZABLE_PLACEHOLDER;\n }\n\n // Class instances and non-plain objects → placeholder\n if (!isPlainObject(value)) {\n return NON_SERIALIZABLE_PLACEHOLDER;\n }\n\n // Plain object (recursive)\n if (seen.has(value)) return CIRCULAR_REFERENCE_PLACEHOLDER;\n seen.add(value);\n const result: Record<string, JsonSafeValue> = {};\n for (const [key, val] of Object.entries(value)) {\n result[key] = sanitizeValue(val, seen);\n }\n seen.delete(value);\n return result;\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// Public API\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Ensures metadata is JSON-serializable.\n *\n * **Allowed:** string, number, boolean, null, arrays, and plain objects.\n *\n * **Converted to placeholder:** Date, BigInt, class instances, functions,\n * symbols, undefined, and circular references (which would otherwise make\n * `JSON.stringify` throw).\n *\n * @throws {TypeError} If `input` is not a plain object at the root level.\n */\nfunction assertJsonSafeMetadata(input: unknown): JsonSafeRecord {\n if (input === undefined) {\n return {};\n }\n\n if (!isPlainObject(input)) {\n throw new TypeError(\n \"metadata must be a plain object (Record<string, unknown>).\",\n );\n }\n\n return sanitizeValue(input, new WeakSet<object>()) as JsonSafeRecord;\n}\n\nexport {\n assertJsonSafeMetadata,\n CIRCULAR_REFERENCE_PLACEHOLDER,\n NON_SERIALIZABLE_PLACEHOLDER,\n};\n","// Base application error for the domain/application layer.\n// Encapsulates a code, optional cause, and JSON-safe metadata.\n\nimport type {\n AppErrorOptions,\n ErrorSeverity,\n JsonSafeRecord,\n} from \"./types.js\";\nimport { assertJsonSafeMetadata } from \"./utils/index.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// AppError (abstract base class)\n// ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * Root of the application/domain error hierarchy. Every error the system raises\n * on purpose extends `AppError`, which gives callers a single `instanceof` to\n * catch and a uniform, serializable shape to log and transport.\n *\n * Beyond the native `Error` message it carries a stable `code` (the contract the\n * outside world matches on), an optional non-leaking `publicMessage`, a\n * severity, JSON-safe `metadata`, and the correlation/request/command ids that\n * stitch an error back to the request that produced it. The metadata is\n * validated as JSON-safe on construction, so a logger can serialize any\n * `AppError` without hitting a circular reference or a non-serializable value.\n *\n * Abstract on purpose: callers should throw a specific subclass (e.g.\n * {@link ValidationError}, {@link NotFoundError}) so the `code` and shape are\n * meaningful, never a bare `AppError`.\n */\nabstract class AppError extends Error {\n public readonly code: string;\n public readonly cause?: unknown;\n public readonly metadata?: JsonSafeRecord;\n public readonly type?: string;\n public readonly severity?: ErrorSeverity;\n public readonly createdAtIso: string;\n public readonly publicMessage?: string;\n /**\n * Identifies a single execution \"story\" in the system. All operations\n * related to the same logical flow must share the same correlationId.\n */\n public readonly correlationId?: string;\n /**\n * Identifies a specific technical request attempt (each retry may produce\n * a new requestId), even when the correlationId stays the same.\n */\n public readonly requestId?: string;\n /**\n * Marks the business intent / idempotency key; stays the same across\n * technical retries and multiple requests that represent the same intent.\n */\n public readonly commandId?: string;\n\n /**\n * Builds the common error envelope shared by every subclass.\n *\n * `name` is taken from `new.target` so the thrown instance reports its\n * concrete subclass name (not `\"AppError\"`), and the prototype is re-pinned\n * via `setPrototypeOf` so `instanceof` keeps working after transpilation to\n * older targets where extending built-ins breaks the chain. `createdAtIso`\n * defaults to now, and `metadata` is validated as JSON-safe so the error is\n * always serializable.\n *\n * Declared `protected`: instantiate a concrete subclass, never `AppError`.\n *\n * @param message - The internal, developer-facing message.\n * @param code - The stable machine-readable code callers match on.\n * @param options - Optional cause, metadata, severity, and correlation ids.\n * @throws When `options.metadata` contains a value that is not JSON-safe.\n */\n protected constructor(\n message: string,\n code: string,\n options?: AppErrorOptions,\n ) {\n super(message);\n\n this.name = new.target.name;\n this.code = code;\n this.cause = options?.cause;\n this.type = options?.type;\n this.severity = options?.severity;\n this.correlationId = options?.correlationId;\n this.requestId = options?.requestId;\n this.commandId = options?.commandId;\n this.createdAtIso = options?.createdAtIso ?? new Date().toISOString();\n this.publicMessage = options?.publicMessage;\n\n this.metadata = options?.metadata\n ? assertJsonSafeMetadata(options.metadata)\n : undefined;\n\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n /**\n * Returns a JSON-safe representation of the error.\n * Does NOT include `cause` by default (to avoid leaking internal details).\n */\n public toJSON(): Record<string, unknown> {\n const payload: Record<string, unknown> = {\n name: this.name,\n code: this.code,\n message: this.message,\n createdAtIso: this.createdAtIso,\n };\n\n // Optional fields are emitted only when defined, so the serialized\n // shape never carries `undefined`-valued keys (consistent with how the\n // correlation/request/command ids are handled).\n if (this.type !== undefined) payload.type = this.type;\n if (this.severity !== undefined) payload.severity = this.severity;\n if (this.publicMessage !== undefined)\n payload.publicMessage = this.publicMessage;\n if (this.metadata !== undefined) payload.metadata = this.metadata;\n if (this.correlationId !== undefined)\n payload.correlationId = this.correlationId;\n if (this.requestId !== undefined) payload.requestId = this.requestId;\n if (this.commandId !== undefined) payload.commandId = this.commandId;\n\n return payload;\n }\n}\n\nexport { AppError };\n","import { AppError } from \"./app-error.js\";\nimport { ErrorCodes } from \"./error-codes.js\";\nimport type { AppErrorOptions } from \"./types.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// UnexpectedError\n// ─────────────────────────────────────────────────────────────────────────────\n\nclass UnexpectedError extends AppError {\n constructor(\n message = \"Unexpected error\",\n cause?: unknown,\n options?: Omit<AppErrorOptions, \"cause\">,\n ) {\n super(message, ErrorCodes.unexpected, {\n cause,\n ...options,\n });\n }\n}\n\nexport { UnexpectedError };\n"],"mappings":";AAAA,MAAM,aAAa;CACf,gBAAgB;EACZ,cAAc;EACd,cAAc;EACd,c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W,QAAQ,WAAW,KAAK;EACzD,IAAI,KAAK,kBAAkB,KAAA,GACvB,QAAQ,gBAAgB,KAAK;EACjC,IAAI,KAAK,cAAc,KAAA,GAAW,QAAQ,YAAY,KAAK;EAC3D,IAAI,KAAK,cAAc,KAAA,GAAW,QAAQ,YAAY,KAAK;EAE3D,OAAO;CACX;AACJ;;;ACnHA,IAAM,kBAAN,cAA8B,SAAS;CACnC,YACI,UAAU,oBACV,OACA,SACF;EACE,MAAM,SAAS,WAAW,YAAY;GAClC;GACA,GAAG;EACP,CAAC;CACL;AACJ"}
|
|
1
|
+
{"version":3,"file":"unexpected-error.js","names":[],"sources":["../src/core/errors/unexpected-error.ts"],"sourcesContent":["import { AppError } from \"./app-error.js\";\nimport { ErrorCodes } from \"./error-codes.js\";\nimport type { AppErrorOptions } from \"./types.js\";\n\n// ─────────────────────────────────────────────────────────────────────────────\n// UnexpectedError\n// ─────────────────────────────────────────────────────────────────────────────\n\nclass UnexpectedError extends AppError {\n constructor(\n message = \"Unexpected error\",\n cause?: unknown,\n options?: Omit<AppErrorOptions, \"cause\">,\n ) {\n super(message, ErrorCodes.unexpected, {\n cause,\n ...options,\n });\n }\n}\n\nexport { UnexpectedError };\n"],"mappings":";;AAQA,IAAM,kBAAN,cAA8B,SAAS;CACnC,YACI,UAAU,oBACV,OACA,SACF;EACE,MAAM,SAAS,WAAW,YAAY;GAClC;GACA,GAAG;EACP,CAAC;CACL;AACJ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { n as ContractVersion } from "./version.cjs";
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as PluginManager } from "./plugin.cjs";
|
|
2
|
+
import { t as ValueObject } from "./value-object.cjs";
|
|
4
3
|
|
|
5
4
|
//#region src/core/domain/entity.d.ts
|
|
6
5
|
|
|
@@ -96,88 +95,6 @@ declare abstract class Entity<TIdentifier> {
|
|
|
96
95
|
protected markAsModified(updatedAt?: Date): number;
|
|
97
96
|
}
|
|
98
97
|
//#endregion
|
|
99
|
-
//#region src/core/domain/value-object.d.ts
|
|
100
|
-
/**
|
|
101
|
-
* Extension point for value-object equality. A plugin implementing this
|
|
102
|
-
* contract overrides how any two value objects are compared, letting the host
|
|
103
|
-
* application swap in a structural comparator (e.g. `lodash.isEqual` over the
|
|
104
|
-
* wrapped `value`) without every value object having to implement `equals` by
|
|
105
|
-
* hand.
|
|
106
|
-
*/
|
|
107
|
-
type ValueObjectPluginContract = {
|
|
108
|
-
equals: (a: ValueObject<unknown, unknown>, b: ValueObject<unknown, unknown>) => boolean;
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Base class for value objects — domain concepts defined entirely by their
|
|
112
|
-
* contents, with no identity of their own. Two value objects are
|
|
113
|
-
* interchangeable when they hold equal data, which is the opposite of an
|
|
114
|
-
* {@link Entity} (compared by id). Money, a CPF, a date range: replacing one
|
|
115
|
-
* instance with an equal one changes nothing about the model.
|
|
116
|
-
*
|
|
117
|
-
* Immutability is the defining guarantee here. The wrapped `value` is
|
|
118
|
-
* deep-frozen on construction, so a value object can be shared freely without
|
|
119
|
-
* any risk of a consumer mutating shared state. Subclasses seal the instance
|
|
120
|
-
* itself with {@link finalize} once their own fields are set.
|
|
121
|
-
*
|
|
122
|
-
* @typeParam T - The shape of the wrapped data.
|
|
123
|
-
* @typeParam P - The primitive form produced by {@link toPrimitive} / {@link toJSON}.
|
|
124
|
-
*/
|
|
125
|
-
declare abstract class ValueObject<T, P> {
|
|
126
|
-
static readonly CONTRACT_VERSION: ContractVersion;
|
|
127
|
-
/**
|
|
128
|
-
* Registry of equality plugins shared by every value object. Empty by
|
|
129
|
-
* default — when nothing is registered, {@link equals} falls back to a
|
|
130
|
-
* structural comparison of the wrapped `value`. Hosts register a plugin
|
|
131
|
-
* (e.g. `lodash.isEqual`) once at startup to customise equality globally.
|
|
132
|
-
*/
|
|
133
|
-
static readonly plugins: PluginManager<ValueObjectPluginContract>;
|
|
134
|
-
/** The wrapped data, deep-frozen so it can never be mutated after construction. */
|
|
135
|
-
readonly value: DeepReadonly<T>;
|
|
136
|
-
/**
|
|
137
|
-
* Wraps `value`, deep-freezing it so the value object is immutable from the
|
|
138
|
-
* moment it exists. Declared `protected` because value objects are built
|
|
139
|
-
* through a validating subclass factory, never instantiated directly.
|
|
140
|
-
*/
|
|
141
|
-
protected constructor(value: T);
|
|
142
|
-
/**
|
|
143
|
-
* The schema/contract version stamped on this value-object type by the
|
|
144
|
-
* `@version` decorator — used to detect state persisted under an older shape.
|
|
145
|
-
*/
|
|
146
|
-
get contractVersion(): ContractVersion;
|
|
147
|
-
/**
|
|
148
|
-
* Freezes the instance shell, blocking reassignment of any own field.
|
|
149
|
-
*
|
|
150
|
-
* `value` is already deep-frozen by the constructor, so the wrapped data is
|
|
151
|
-
* immutable regardless. The instance itself is NOT frozen automatically
|
|
152
|
-
* because a subclass may still need to assign its own fields after
|
|
153
|
-
* `super(value)` runs. Call `finalize()` at the very end of the subclass
|
|
154
|
-
* constructor (after all fields are set) to make the whole value object
|
|
155
|
-
* immutable.
|
|
156
|
-
*/
|
|
157
|
-
protected finalize(): void;
|
|
158
|
-
/**
|
|
159
|
-
* Hook for `JSON.stringify`. Delegates to {@link toPrimitive} so a value
|
|
160
|
-
* object serializes to its primitive form rather than exposing the internal
|
|
161
|
-
* `value` wrapper.
|
|
162
|
-
*/
|
|
163
|
-
toJSON(): P;
|
|
164
|
-
/**
|
|
165
|
-
* Compares this value object with another by content. Because value objects
|
|
166
|
-
* carry no identity, two independently constructed instances holding the
|
|
167
|
-
* same data are considered equal.
|
|
168
|
-
*
|
|
169
|
-
* Delegates to the registered equality {@link plugins}; with no plugin
|
|
170
|
-
* registered it falls back to comparing the serialized wrapped `value`.
|
|
171
|
-
* Subclasses may still override for a faster or domain-specific comparison.
|
|
172
|
-
*/
|
|
173
|
-
equals(other: this): boolean;
|
|
174
|
-
/**
|
|
175
|
-
* Projects the value object down to a plain, serializable primitive form —
|
|
176
|
-
* the representation suitable for persistence, transport, or comparison.
|
|
177
|
-
*/
|
|
178
|
-
abstract toPrimitive(): P;
|
|
179
|
-
}
|
|
180
|
-
//#endregion
|
|
181
98
|
//#region src/core/domain/uuid-identifier.d.ts
|
|
182
99
|
/**
|
|
183
100
|
* Base class for UUID-backed identity value objects.
|
|
@@ -226,5 +143,5 @@ declare abstract class UuidIdentifier<TBrand extends string = string> extends Va
|
|
|
226
143
|
static isValid(candidate: string): boolean;
|
|
227
144
|
}
|
|
228
145
|
//#endregion
|
|
229
|
-
export {
|
|
146
|
+
export { Entity as n, EntityState as r, UuidIdentifier as t };
|
|
230
147
|
//# sourceMappingURL=uuid-identifier.d.cts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { n as ContractVersion } from "./version.js";
|
|
2
|
-
import { t as
|
|
3
|
-
import { t as PluginManager } from "./plugin.js";
|
|
2
|
+
import { t as ValueObject } from "./value-object.js";
|
|
4
3
|
|
|
5
4
|
//#region src/core/domain/entity.d.ts
|
|
6
5
|
|
|
@@ -96,88 +95,6 @@ declare abstract class Entity<TIdentifier> {
|
|
|
96
95
|
protected markAsModified(updatedAt?: Date): number;
|
|
97
96
|
}
|
|
98
97
|
//#endregion
|
|
99
|
-
//#region src/core/domain/value-object.d.ts
|
|
100
|
-
/**
|
|
101
|
-
* Extension point for value-object equality. A plugin implementing this
|
|
102
|
-
* contract overrides how any two value objects are compared, letting the host
|
|
103
|
-
* application swap in a structural comparator (e.g. `lodash.isEqual` over the
|
|
104
|
-
* wrapped `value`) without every value object having to implement `equals` by
|
|
105
|
-
* hand.
|
|
106
|
-
*/
|
|
107
|
-
type ValueObjectPluginContract = {
|
|
108
|
-
equals: (a: ValueObject<unknown, unknown>, b: ValueObject<unknown, unknown>) => boolean;
|
|
109
|
-
};
|
|
110
|
-
/**
|
|
111
|
-
* Base class for value objects — domain concepts defined entirely by their
|
|
112
|
-
* contents, with no identity of their own. Two value objects are
|
|
113
|
-
* interchangeable when they hold equal data, which is the opposite of an
|
|
114
|
-
* {@link Entity} (compared by id). Money, a CPF, a date range: replacing one
|
|
115
|
-
* instance with an equal one changes nothing about the model.
|
|
116
|
-
*
|
|
117
|
-
* Immutability is the defining guarantee here. The wrapped `value` is
|
|
118
|
-
* deep-frozen on construction, so a value object can be shared freely without
|
|
119
|
-
* any risk of a consumer mutating shared state. Subclasses seal the instance
|
|
120
|
-
* itself with {@link finalize} once their own fields are set.
|
|
121
|
-
*
|
|
122
|
-
* @typeParam T - The shape of the wrapped data.
|
|
123
|
-
* @typeParam P - The primitive form produced by {@link toPrimitive} / {@link toJSON}.
|
|
124
|
-
*/
|
|
125
|
-
declare abstract class ValueObject<T, P> {
|
|
126
|
-
static readonly CONTRACT_VERSION: ContractVersion;
|
|
127
|
-
/**
|
|
128
|
-
* Registry of equality plugins shared by every value object. Empty by
|
|
129
|
-
* default — when nothing is registered, {@link equals} falls back to a
|
|
130
|
-
* structural comparison of the wrapped `value`. Hosts register a plugin
|
|
131
|
-
* (e.g. `lodash.isEqual`) once at startup to customise equality globally.
|
|
132
|
-
*/
|
|
133
|
-
static readonly plugins: PluginManager<ValueObjectPluginContract>;
|
|
134
|
-
/** The wrapped data, deep-frozen so it can never be mutated after construction. */
|
|
135
|
-
readonly value: DeepReadonly<T>;
|
|
136
|
-
/**
|
|
137
|
-
* Wraps `value`, deep-freezing it so the value object is immutable from the
|
|
138
|
-
* moment it exists. Declared `protected` because value objects are built
|
|
139
|
-
* through a validating subclass factory, never instantiated directly.
|
|
140
|
-
*/
|
|
141
|
-
protected constructor(value: T);
|
|
142
|
-
/**
|
|
143
|
-
* The schema/contract version stamped on this value-object type by the
|
|
144
|
-
* `@version` decorator — used to detect state persisted under an older shape.
|
|
145
|
-
*/
|
|
146
|
-
get contractVersion(): ContractVersion;
|
|
147
|
-
/**
|
|
148
|
-
* Freezes the instance shell, blocking reassignment of any own field.
|
|
149
|
-
*
|
|
150
|
-
* `value` is already deep-frozen by the constructor, so the wrapped data is
|
|
151
|
-
* immutable regardless. The instance itself is NOT frozen automatically
|
|
152
|
-
* because a subclass may still need to assign its own fields after
|
|
153
|
-
* `super(value)` runs. Call `finalize()` at the very end of the subclass
|
|
154
|
-
* constructor (after all fields are set) to make the whole value object
|
|
155
|
-
* immutable.
|
|
156
|
-
*/
|
|
157
|
-
protected finalize(): void;
|
|
158
|
-
/**
|
|
159
|
-
* Hook for `JSON.stringify`. Delegates to {@link toPrimitive} so a value
|
|
160
|
-
* object serializes to its primitive form rather than exposing the internal
|
|
161
|
-
* `value` wrapper.
|
|
162
|
-
*/
|
|
163
|
-
toJSON(): P;
|
|
164
|
-
/**
|
|
165
|
-
* Compares this value object with another by content. Because value objects
|
|
166
|
-
* carry no identity, two independently constructed instances holding the
|
|
167
|
-
* same data are considered equal.
|
|
168
|
-
*
|
|
169
|
-
* Delegates to the registered equality {@link plugins}; with no plugin
|
|
170
|
-
* registered it falls back to comparing the serialized wrapped `value`.
|
|
171
|
-
* Subclasses may still override for a faster or domain-specific comparison.
|
|
172
|
-
*/
|
|
173
|
-
equals(other: this): boolean;
|
|
174
|
-
/**
|
|
175
|
-
* Projects the value object down to a plain, serializable primitive form —
|
|
176
|
-
* the representation suitable for persistence, transport, or comparison.
|
|
177
|
-
*/
|
|
178
|
-
abstract toPrimitive(): P;
|
|
179
|
-
}
|
|
180
|
-
//#endregion
|
|
181
98
|
//#region src/core/domain/uuid-identifier.d.ts
|
|
182
99
|
/**
|
|
183
100
|
* Base class for UUID-backed identity value objects.
|
|
@@ -226,5 +143,5 @@ declare abstract class UuidIdentifier<TBrand extends string = string> extends Va
|
|
|
226
143
|
static isValid(candidate: string): boolean;
|
|
227
144
|
}
|
|
228
145
|
//#endregion
|
|
229
|
-
export {
|
|
146
|
+
export { Entity as n, EntityState as r, UuidIdentifier as t };
|
|
230
147
|
//# sourceMappingURL=uuid-identifier.d.ts.map
|