@cullet/erp-core 1.2.0 → 1.3.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.
Files changed (101) hide show
  1. package/dist/app-error.d.cts +108 -0
  2. package/dist/application/index.cjs +26 -0
  3. package/dist/application/index.d.cts +2 -0
  4. package/dist/domain/index.cjs +16 -0
  5. package/dist/domain/index.d.cts +3 -0
  6. package/dist/domain-event-contracts.cjs +33 -0
  7. package/dist/domain-event-contracts.cjs.map +1 -0
  8. package/dist/domain-event-contracts.d.cts +27 -0
  9. package/dist/domain-exception.cjs +17 -0
  10. package/dist/domain-exception.cjs.map +1 -0
  11. package/dist/domain-exception.d.cts +7 -0
  12. package/dist/errors/index.cjs +41 -0
  13. package/dist/errors/index.d.cts +3 -0
  14. package/dist/exceptions/index.cjs +17 -0
  15. package/dist/exceptions/index.d.cts +5 -0
  16. package/dist/exceptions/validation-field.cjs +3 -0
  17. package/dist/exceptions/validation-field.d.cts +2 -0
  18. package/dist/gate-engine-registry.cjs +308 -0
  19. package/dist/gate-engine-registry.cjs.map +1 -0
  20. package/dist/gate-engine-registry.d.cts +81 -0
  21. package/dist/gate-types.d.cts +171 -0
  22. package/dist/gate-v1-payload.schema.cjs +638 -0
  23. package/dist/gate-v1-payload.schema.cjs.map +1 -0
  24. package/dist/hashing.cjs +66 -0
  25. package/dist/hashing.cjs.map +1 -0
  26. package/dist/immutable.cjs +77 -0
  27. package/dist/immutable.cjs.map +1 -0
  28. package/dist/immutable.d.cts +6 -0
  29. package/dist/index.cjs +163 -0
  30. package/dist/index.cjs.map +1 -0
  31. package/dist/index.d.cts +30 -0
  32. package/dist/index.d.ts +2 -2
  33. package/dist/index.js +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/invalid-state-transition-exception.cjs +47 -0
  36. package/dist/invalid-state-transition-exception.cjs.map +1 -0
  37. package/dist/invariant-violation-exception.cjs +16 -0
  38. package/dist/invariant-violation-exception.cjs.map +1 -0
  39. package/dist/not-found-error.cjs +65 -0
  40. package/dist/not-found-error.cjs.map +1 -0
  41. package/dist/outcome.cjs +97 -0
  42. package/dist/outcome.cjs.map +1 -0
  43. package/dist/outcome.d.cts +140 -0
  44. package/dist/parse-gate-payload.d.cts +62 -0
  45. package/dist/path.d.cts +90 -0
  46. package/dist/plugin.cjs +79 -0
  47. package/dist/plugin.cjs.map +1 -0
  48. package/dist/plugin.d.cts +85 -0
  49. package/dist/plugins/index.cjs +3 -0
  50. package/dist/plugins/index.d.cts +2 -0
  51. package/dist/policies/engines/index.cjs +10 -0
  52. package/dist/policies/engines/index.d.cts +4 -0
  53. package/dist/policies/engines/v1/gate/index.cjs +91 -0
  54. package/dist/policies/engines/v1/gate/index.cjs.map +1 -0
  55. package/dist/policies/engines/v1/gate/index.d.cts +121 -0
  56. package/dist/policies/index.cjs +41 -0
  57. package/dist/policies/index.d.cts +7 -0
  58. package/dist/policy-service.cjs +1190 -0
  59. package/dist/policy-service.cjs.map +1 -0
  60. package/dist/policy-service.d.cts +559 -0
  61. package/dist/result/index.cjs +7 -0
  62. package/dist/result/index.d.cts +2 -0
  63. package/dist/result.cjs +135 -0
  64. package/dist/result.cjs.map +1 -0
  65. package/dist/ruleset-registry.cjs +47 -0
  66. package/dist/ruleset-registry.cjs.map +1 -0
  67. package/dist/rulesets/index.cjs +3 -0
  68. package/dist/rulesets/index.d.cts +2 -0
  69. package/dist/temporal-guards.cjs +32 -0
  70. package/dist/temporal-guards.cjs.map +1 -0
  71. package/dist/temporal-use-case.cjs +191 -0
  72. package/dist/temporal-use-case.cjs.map +1 -0
  73. package/dist/temporal-use-case.d.cts +304 -0
  74. package/dist/unexpected-error.cjs +208 -0
  75. package/dist/unexpected-error.cjs.map +1 -0
  76. package/dist/use-case.cjs +96 -0
  77. package/dist/use-case.cjs.map +1 -0
  78. package/dist/uuid-identifier.cjs +65 -0
  79. package/dist/uuid-identifier.cjs.map +1 -0
  80. package/dist/uuid-identifier.d.cts +230 -0
  81. package/dist/validation-code.cjs +60 -0
  82. package/dist/validation-code.cjs.map +1 -0
  83. package/dist/validation-code.d.cts +23 -0
  84. package/dist/validation-error.cjs +1020 -0
  85. package/dist/validation-error.cjs.map +1 -0
  86. package/dist/validation-error.d.cts +777 -0
  87. package/dist/validation-exception.cjs +41 -0
  88. package/dist/validation-exception.cjs.map +1 -0
  89. package/dist/validation-exception.d.cts +50 -0
  90. package/dist/validation-field.cjs +28 -0
  91. package/dist/validation-field.cjs.map +1 -0
  92. package/dist/validation-field.d.cts +12 -0
  93. package/dist/value-object-ruleset.contracts.d.cts +36 -0
  94. package/dist/value-object.cjs +208 -0
  95. package/dist/value-object.cjs.map +1 -0
  96. package/dist/version.d.cts +10 -0
  97. package/dist/versioning/index.cjs +7 -0
  98. package/dist/versioning/index.d.cts +3 -0
  99. package/meta.json +3 -2
  100. package/package.json +147 -28
  101. package/src/version.ts +1 -1
@@ -0,0 +1,108 @@
1
+ //#region src/core/errors/types.d.ts
2
+ type ErrorSeverity = "low" | "medium" | "high" | "critical";
3
+ type JsonSafePrimitive = string | number | boolean | null;
4
+ type JsonSafeValue = JsonSafePrimitive | JsonSafeValue[] | {
5
+ [key: string]: JsonSafeValue;
6
+ };
7
+ type JsonSafeRecord = Record<string, JsonSafeValue>;
8
+ /**
9
+ * Options accepted by the AppError constructor.
10
+ * Subclasses can extend or pick from this type.
11
+ */
12
+ type AppErrorOptions = {
13
+ /** Original error or exception that caused this error. */
14
+ cause?: unknown;
15
+ /** Arbitrary key-value metadata (will be sanitized to JSON-safe values). */
16
+ metadata?: Record<string, unknown>;
17
+ /** Error category/type for grouping (e.g., "authentication", "validation"). */
18
+ type?: string;
19
+ /** severity level for alerting/logging prioritization. */
20
+ severity?: ErrorSeverity;
21
+ /**
22
+ * Identifies a single execution "story" in the system. All operations
23
+ * related to the same logical flow must share the same correlationId.
24
+ */
25
+ correlationId?: string;
26
+ /**
27
+ * Identifies a specific technical request attempt (each retry may produce
28
+ * a new requestId), even when the correlationId stays the same.
29
+ */
30
+ requestId?: string;
31
+ /**
32
+ * Identifies a unique business intent (idempotency key); stays the same
33
+ * across technical retries and multiple requests that represent the same intent.
34
+ */
35
+ commandId?: string;
36
+ /** ISO timestamp of when the error was created (defaults to now). */
37
+ createdAtIso?: string;
38
+ /** Safe message that can be exposed to end users (no internal details). */
39
+ publicMessage?: string;
40
+ };
41
+ //#endregion
42
+ //#region src/core/errors/app-error.d.ts
43
+ /**
44
+ * Root of the application/domain error hierarchy. Every error the system raises
45
+ * on purpose extends `AppError`, which gives callers a single `instanceof` to
46
+ * catch and a uniform, serializable shape to log and transport.
47
+ *
48
+ * Beyond the native `Error` message it carries a stable `code` (the contract the
49
+ * outside world matches on), an optional non-leaking `publicMessage`, a
50
+ * severity, JSON-safe `metadata`, and the correlation/request/command ids that
51
+ * stitch an error back to the request that produced it. The metadata is
52
+ * validated as JSON-safe on construction, so a logger can serialize any
53
+ * `AppError` without hitting a circular reference or a non-serializable value.
54
+ *
55
+ * Abstract on purpose: callers should throw a specific subclass (e.g.
56
+ * {@link ValidationError}, {@link NotFoundError}) so the `code` and shape are
57
+ * meaningful, never a bare `AppError`.
58
+ */
59
+ declare abstract class AppError extends Error {
60
+ readonly code: string;
61
+ readonly cause?: unknown;
62
+ readonly metadata?: JsonSafeRecord;
63
+ readonly type?: string;
64
+ readonly severity?: ErrorSeverity;
65
+ readonly createdAtIso: string;
66
+ readonly publicMessage?: string;
67
+ /**
68
+ * Identifies a single execution "story" in the system. All operations
69
+ * related to the same logical flow must share the same correlationId.
70
+ */
71
+ readonly correlationId?: string;
72
+ /**
73
+ * Identifies a specific technical request attempt (each retry may produce
74
+ * a new requestId), even when the correlationId stays the same.
75
+ */
76
+ readonly requestId?: string;
77
+ /**
78
+ * Marks the business intent / idempotency key; stays the same across
79
+ * technical retries and multiple requests that represent the same intent.
80
+ */
81
+ readonly commandId?: string;
82
+ /**
83
+ * Builds the common error envelope shared by every subclass.
84
+ *
85
+ * `name` is taken from `new.target` so the thrown instance reports its
86
+ * concrete subclass name (not `"AppError"`), and the prototype is re-pinned
87
+ * via `setPrototypeOf` so `instanceof` keeps working after transpilation to
88
+ * older targets where extending built-ins breaks the chain. `createdAtIso`
89
+ * defaults to now, and `metadata` is validated as JSON-safe so the error is
90
+ * always serializable.
91
+ *
92
+ * Declared `protected`: instantiate a concrete subclass, never `AppError`.
93
+ *
94
+ * @param message - The internal, developer-facing message.
95
+ * @param code - The stable machine-readable code callers match on.
96
+ * @param options - Optional cause, metadata, severity, and correlation ids.
97
+ * @throws When `options.metadata` contains a value that is not JSON-safe.
98
+ */
99
+ protected constructor(message: string, code: string, options?: AppErrorOptions);
100
+ /**
101
+ * Returns a JSON-safe representation of the error.
102
+ * Does NOT include `cause` by default (to avoid leaking internal details).
103
+ */
104
+ toJSON(): Record<string, unknown>;
105
+ }
106
+ //#endregion
107
+ export { JsonSafeRecord as a, JsonSafePrimitive as i, AppErrorOptions as n, JsonSafeValue as o, ErrorSeverity as r, AppError as t };
108
+ //# sourceMappingURL=app-error.d.cts.map
@@ -0,0 +1,26 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_use_case = require("../use-case.cjs");
3
+ const require_temporal_use_case = require("../temporal-use-case.cjs");
4
+ Object.defineProperty(exports, "Command", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return require_temporal_use_case.Command;
8
+ }
9
+ });
10
+ Object.defineProperty(exports, "Query", {
11
+ enumerable: true,
12
+ get: function() {
13
+ return require_temporal_use_case.Query;
14
+ }
15
+ });
16
+ exports.RequestedBy = require_temporal_use_case.RequestedBy;
17
+ exports.TemporalUseCase = require_temporal_use_case.TemporalUseCase;
18
+ Object.defineProperty(exports, "UseCase", {
19
+ enumerable: true,
20
+ get: function() {
21
+ return require_use_case.UseCase;
22
+ }
23
+ });
24
+ exports.assertTemporalContext = require_temporal_use_case.assertTemporalContext;
25
+ exports.createTemporalContext = require_temporal_use_case.createTemporalContext;
26
+ exports.mapPolicyEvaluationError = require_temporal_use_case.mapPolicyEvaluationError;
@@ -0,0 +1,2 @@
1
+ import { A as MetricLabels, C as RequestedByKind, D as TraceAttributeValue, E as UseCaseObservability, M as LogPayload, N as LoggerPort, O as TraceSpan, S as RequestedBy, T as UseCase, _ as PolicyEvaluationOutput, a as TemporalContext, b as Command, c as CacheStrategy, d as mapPolicyEvaluationError, f as TemporalHistory, g as PolicyEvaluationInput, h as ResultRepository, i as CreateTemporalContextInput, j as MetricsPort, k as TracerPort, l as Page, m as Repository, n as TemporalUseCaseInput, o as assertTemporalContext, p as TemporalRepository, r as TemporalizedContextSeed, s as createTemporalContext, t as TemporalUseCase, u as Query, v as PolicyPort, w as MaybePromise, x as CommandInput, y as PolicyPortError } from "../temporal-use-case.cjs";
2
+ export { CacheStrategy, Command, CommandInput, CreateTemporalContextInput, LogPayload, LoggerPort, MaybePromise, MetricLabels, MetricsPort, Page, PolicyEvaluationInput, PolicyEvaluationOutput, PolicyPort, PolicyPortError, Query, Repository, RequestedBy, RequestedByKind, ResultRepository, TemporalContext, TemporalHistory, TemporalRepository, TemporalUseCase, TemporalUseCaseInput, TemporalizedContextSeed, TraceAttributeValue, TraceSpan, TracerPort, UseCase, UseCaseObservability, assertTemporalContext, createTemporalContext, mapPolicyEvaluationError };
@@ -0,0 +1,16 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_value_object = require("../value-object.cjs");
3
+ const require_uuid_identifier = require("../uuid-identifier.cjs");
4
+ Object.defineProperty(exports, "Entity", {
5
+ enumerable: true,
6
+ get: function() {
7
+ return require_value_object.Entity;
8
+ }
9
+ });
10
+ exports.UuidIdentifier = require_uuid_identifier.UuidIdentifier;
11
+ Object.defineProperty(exports, "ValueObject", {
12
+ enumerable: true,
13
+ get: function() {
14
+ return require_value_object.ValueObject;
15
+ }
16
+ });
@@ -0,0 +1,3 @@
1
+ import { t as DeepReadonly } from "../immutable.cjs";
2
+ import { a as EntityState, i as Entity, n as ValueObject, r as ValueObjectPluginContract, t as UuidIdentifier } from "../uuid-identifier.cjs";
3
+ export { type DeepReadonly, Entity, type EntityState, UuidIdentifier, ValueObject, type ValueObjectPluginContract };
@@ -0,0 +1,33 @@
1
+ const require_use_case = require("./use-case.cjs");
2
+ const require_value_object = require("./value-object.cjs");
3
+ //#region src/core/versioning/domain-event-contracts.ts
4
+ function buildDomainEventContractVersions(selection) {
5
+ const contractVersions = {};
6
+ if (selection.entity) contractVersions.entity_contract = require_value_object.Entity.CONTRACT_VERSION;
7
+ if (selection.valueObject) contractVersions.value_object_contract = require_value_object.ValueObject.CONTRACT_VERSION;
8
+ if (selection.useCase) contractVersions.use_case_contract = require_use_case.UseCase.CONTRACT_VERSION;
9
+ return Object.freeze(contractVersions);
10
+ }
11
+ function createDomainEventEnvelope(input) {
12
+ require_value_object.assertValidAggregateVersion(input.aggregateVersion);
13
+ return Object.freeze({
14
+ aggregate_version: input.aggregateVersion,
15
+ payload: input.payload,
16
+ ...buildDomainEventContractVersions(input.contracts)
17
+ });
18
+ }
19
+ //#endregion
20
+ Object.defineProperty(exports, "buildDomainEventContractVersions", {
21
+ enumerable: true,
22
+ get: function() {
23
+ return buildDomainEventContractVersions;
24
+ }
25
+ });
26
+ Object.defineProperty(exports, "createDomainEventEnvelope", {
27
+ enumerable: true,
28
+ get: function() {
29
+ return createDomainEventEnvelope;
30
+ }
31
+ });
32
+
33
+ //# sourceMappingURL=domain-event-contracts.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-event-contracts.cjs","names":["Entity","ValueObject","UseCase"],"sources":["../src/core/versioning/domain-event-contracts.ts"],"sourcesContent":["import { UseCase } from \"../application/use-case.js\";\nimport { Entity } from \"../domain/entity.js\";\nimport { ValueObject } from \"../domain/value-object.js\";\nimport { assertValidAggregateVersion } from \"../shared/aggregate-version.js\";\nimport { type ContractVersion } from \"./version.js\";\n\ninterface DomainEventContractSelection {\n readonly entity?: boolean;\n readonly valueObject?: boolean;\n readonly useCase?: boolean;\n}\n\ninterface DomainEventContractVersions {\n readonly entity_contract?: ContractVersion;\n readonly value_object_contract?: ContractVersion;\n readonly use_case_contract?: ContractVersion;\n}\n\ninterface CreateDomainEventEnvelopeInput<TPayload> {\n readonly aggregateVersion: number;\n readonly payload: TPayload;\n readonly contracts: DomainEventContractSelection;\n}\n\ninterface DomainEventEnvelope<TPayload> extends DomainEventContractVersions {\n readonly aggregate_version: number;\n readonly payload: TPayload;\n}\n\nfunction buildDomainEventContractVersions(\n selection: DomainEventContractSelection,\n): DomainEventContractVersions {\n const contractVersions: {\n entity_contract?: ContractVersion;\n value_object_contract?: ContractVersion;\n use_case_contract?: ContractVersion;\n } = {};\n\n if (selection.entity) {\n contractVersions.entity_contract = Entity.CONTRACT_VERSION;\n }\n\n if (selection.valueObject) {\n contractVersions.value_object_contract = ValueObject.CONTRACT_VERSION;\n }\n\n if (selection.useCase) {\n contractVersions.use_case_contract = UseCase.CONTRACT_VERSION;\n }\n\n return Object.freeze(contractVersions);\n}\n\nfunction createDomainEventEnvelope<TPayload>(\n input: CreateDomainEventEnvelopeInput<TPayload>,\n): DomainEventEnvelope<TPayload> {\n assertValidAggregateVersion(input.aggregateVersion);\n\n return Object.freeze({\n aggregate_version: input.aggregateVersion,\n payload: input.payload,\n ...buildDomainEventContractVersions(input.contracts),\n });\n}\n\nexport {\n buildDomainEventContractVersions,\n createDomainEventEnvelope,\n type CreateDomainEventEnvelopeInput,\n type DomainEventContractSelection,\n type DomainEventContractVersions,\n type DomainEventEnvelope,\n};\n"],"mappings":";;;AA6BA,SAAS,iCACL,WAC2B;CAC3B,MAAM,mBAIF,CAAC;CAEL,IAAI,UAAU,QACV,iBAAiB,kBAAkBA,qBAAAA,OAAO;CAG9C,IAAI,UAAU,aACV,iBAAiB,wBAAwBC,qBAAAA,YAAY;CAGzD,IAAI,UAAU,SACV,iBAAiB,oBAAoBC,iBAAAA,QAAQ;CAGjD,OAAO,OAAO,OAAO,gBAAgB;AACzC;AAEA,SAAS,0BACL,OAC6B;CAC7B,qBAAA,4BAA4B,MAAM,gBAAgB;CAElD,OAAO,OAAO,OAAO;EACjB,mBAAmB,MAAM;EACzB,SAAS,MAAM;EACf,GAAG,iCAAiC,MAAM,SAAS;CACvD,CAAC;AACL"}
@@ -0,0 +1,27 @@
1
+ import { n as ContractVersion } from "./version.cjs";
2
+
3
+ //#region src/core/versioning/domain-event-contracts.d.ts
4
+ interface DomainEventContractSelection {
5
+ readonly entity?: boolean;
6
+ readonly valueObject?: boolean;
7
+ readonly useCase?: boolean;
8
+ }
9
+ interface DomainEventContractVersions {
10
+ readonly entity_contract?: ContractVersion;
11
+ readonly value_object_contract?: ContractVersion;
12
+ readonly use_case_contract?: ContractVersion;
13
+ }
14
+ interface CreateDomainEventEnvelopeInput<TPayload> {
15
+ readonly aggregateVersion: number;
16
+ readonly payload: TPayload;
17
+ readonly contracts: DomainEventContractSelection;
18
+ }
19
+ interface DomainEventEnvelope<TPayload> extends DomainEventContractVersions {
20
+ readonly aggregate_version: number;
21
+ readonly payload: TPayload;
22
+ }
23
+ declare function buildDomainEventContractVersions(selection: DomainEventContractSelection): DomainEventContractVersions;
24
+ declare function createDomainEventEnvelope<TPayload>(input: CreateDomainEventEnvelopeInput<TPayload>): DomainEventEnvelope<TPayload>;
25
+ //#endregion
26
+ export { buildDomainEventContractVersions as a, DomainEventEnvelope as i, DomainEventContractSelection as n, createDomainEventEnvelope as o, DomainEventContractVersions as r, CreateDomainEventEnvelopeInput as t };
27
+ //# sourceMappingURL=domain-event-contracts.d.cts.map
@@ -0,0 +1,17 @@
1
+ //#region src/core/exceptions/domain-exception.ts
2
+ var DomainException = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ Object.setPrototypeOf(this, new.target.prototype);
6
+ this.name = new.target.name;
7
+ }
8
+ };
9
+ //#endregion
10
+ Object.defineProperty(exports, "DomainException", {
11
+ enumerable: true,
12
+ get: function() {
13
+ return DomainException;
14
+ }
15
+ });
16
+
17
+ //# sourceMappingURL=domain-exception.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain-exception.cjs","names":[],"sources":["../src/core/exceptions/domain-exception.ts"],"sourcesContent":["abstract class DomainException extends Error {\n constructor(message: string) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n this.name = new.target.name;\n }\n}\n\nexport { DomainException };\n"],"mappings":";AAAA,IAAe,kBAAf,cAAuC,MAAM;CACzC,YAAY,SAAiB;EACzB,MAAM,OAAO;EACb,OAAO,eAAe,MAAM,IAAI,OAAO,SAAS;EAChD,KAAK,OAAO,IAAI,OAAO;CAC3B;AACJ"}
@@ -0,0 +1,7 @@
1
+ //#region src/core/exceptions/domain-exception.d.ts
2
+ declare abstract class DomainException extends Error {
3
+ constructor(message: string);
4
+ }
5
+ //#endregion
6
+ export { DomainException as t };
7
+ //# sourceMappingURL=domain-exception.d.cts.map
@@ -0,0 +1,41 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_unexpected_error = require("../unexpected-error.cjs");
3
+ const require_validation_error = require("../validation-error.cjs");
4
+ const require_not_found_error = require("../not-found-error.cjs");
5
+ const require_hashing = require("../hashing.cjs");
6
+ exports.AlreadyExistsError = require_validation_error.AlreadyExistsError;
7
+ exports.AppError = require_unexpected_error.AppError;
8
+ exports.AuthenticationError = require_validation_error.AuthenticationError;
9
+ exports.AuthorizationError = require_validation_error.AuthorizationError;
10
+ exports.BusinessRuleViolationError = require_not_found_error.BusinessRuleViolationError;
11
+ exports.ConflictError = require_validation_error.ConflictError;
12
+ exports.DeserializationError = require_validation_error.SerializationInError;
13
+ exports.DuplicateError = require_validation_error.DuplicateError;
14
+ exports.ErrorCodes = require_unexpected_error.ErrorCodes;
15
+ exports.ExpiredError = require_validation_error.ExpiredError;
16
+ exports.IdempotencyError = require_validation_error.IdempotencyError;
17
+ exports.IdempotencyInProgressError = require_validation_error.IdempotencyInProgressError;
18
+ exports.IdempotencyKeyMissingError = require_validation_error.IdempotencyKeyMissingError;
19
+ exports.IdempotencyPayloadMismatchError = require_validation_error.IdempotencyPayloadMismatchError;
20
+ exports.IdempotencyReplayNotSupportedError = require_validation_error.IdempotencyReplayNotSupportedError;
21
+ exports.IntegrationError = require_validation_error.IntegrationError;
22
+ exports.LegacyIncompatibleError = require_validation_error.LegacyIncompatibleError;
23
+ exports.NotFoundError = require_not_found_error.NotFoundError;
24
+ exports.NotYetValidError = require_validation_error.NotYetValidError;
25
+ exports.SerializationCodes = require_validation_error.SerializationCodes;
26
+ exports.SerializationError = require_validation_error.SerializationError;
27
+ exports.SerializationInError = require_validation_error.SerializationInError;
28
+ exports.SerializationMessages = require_validation_error.SerializationMessages;
29
+ exports.SerializationOutError = require_validation_error.SerializationOutError;
30
+ exports.TemporalError = require_validation_error.TemporalError;
31
+ exports.UnexpectedError = require_unexpected_error.UnexpectedError;
32
+ exports.UniqueConstraintViolationError = require_validation_error.UniqueConstraintViolationError;
33
+ exports.ValidationError = require_validation_error.ValidationError;
34
+ exports.assertJsonSafeMetadata = require_unexpected_error.assertJsonSafeMetadata;
35
+ exports.evaluateTemporalWindow = require_validation_error.evaluateTemporalWindow;
36
+ exports.payloadHash = require_hashing.payloadHash;
37
+ exports.safePreview = require_validation_error.safePreview;
38
+ exports.serializationErrorCode = require_unexpected_error.serializationErrorCode;
39
+ exports.sha256Hex = require_hashing.sha256Hex;
40
+ exports.stableStringify = require_hashing.stableStringify;
41
+ exports.translateUniqueViolationToDuplicate = require_validation_error.translateUniqueViolationToDuplicate;
@@ -0,0 +1,3 @@
1
+ import { a as JsonSafeRecord, i as JsonSafePrimitive, n as AppErrorOptions, o as JsonSafeValue, r as ErrorSeverity, t as AppError } from "../app-error.cjs";
2
+ import { $ as serializationErrorCode, A as IdempotencyPayloadMismatchError, B as UniqueConstraintViolation, C as IntegrationErrorMetadata, D as IdempotencyFailureKind, E as IdempotencyErrorMetadata, F as AlreadyExistsError, G as AuthorizationErrorMetadata, H as translateUniqueViolationToDuplicate, I as ConflictError, J as AuthenticationError, K as AuthorizationErrorReason, L as ConflictErrorMetadata, M as payloadHash, N as sha256Hex, O as IdempotencyInProgressError, P as stableStringify, Q as ErrorCodes, R as ConflictKind, S as IntegrationError, T as IdempotencyError, U as BusinessRuleViolationError, V as UniqueConstraintViolationError, W as AuthorizationError, X as AuthenticationErrorReason, Y as AuthenticationErrorMetadata, Z as assertJsonSafeMetadata, _ as SerializationMessages, a as TemporalError, b as NotFoundError, c as TemporalPrecision, d as SerializationCodes, f as SerializationDirection, g as SerializationInError, h as SerializationFailureCategory, i as NotYetValidError, j as IdempotencyReplayNotSupportedError, k as IdempotencyKeyMissingError, l as evaluateTemporalWindow, m as SerializationErrorMetadata, n as UnexpectedError, o as TemporalErrorMetadata, p as SerializationError, q as AuthorizationRequirement, r as ExpiredError, s as TemporalKind, t as ValidationError, u as SerializationBoundary, v as SerializationOutError, w as IntegrationErrorReason, x as LegacyIncompatibleError, y as safePreview, z as DuplicateError } from "../validation-error.cjs";
3
+ export { AlreadyExistsError, AppError, AppErrorOptions, AuthenticationError, AuthenticationErrorMetadata, AuthenticationErrorReason, AuthorizationError, AuthorizationErrorMetadata, AuthorizationErrorReason, AuthorizationRequirement, BusinessRuleViolationError, ConflictError, ConflictErrorMetadata, ConflictKind, SerializationInError as DeserializationError, SerializationInError, DuplicateError, ErrorCodes, ErrorSeverity, ExpiredError, TemporalErrorMetadata as ExpiredErrorMetadata, TemporalErrorMetadata, TemporalPrecision as ExpiredErrorPrecision, TemporalPrecision, IdempotencyError, IdempotencyErrorMetadata, IdempotencyFailureKind, IdempotencyInProgressError, IdempotencyKeyMissingError, IdempotencyPayloadMismatchError, IdempotencyReplayNotSupportedError, IntegrationError, IntegrationErrorMetadata, IntegrationErrorReason, JsonSafePrimitive, JsonSafeRecord, JsonSafeValue, LegacyIncompatibleError, NotFoundError, NotYetValidError, SerializationBoundary, SerializationCodes, SerializationDirection, SerializationError, SerializationErrorMetadata, SerializationFailureCategory, SerializationMessages, SerializationOutError, TemporalError, TemporalKind, UnexpectedError, UniqueConstraintViolation, UniqueConstraintViolationError, ValidationError, assertJsonSafeMetadata, evaluateTemporalWindow, payloadHash, safePreview, serializationErrorCode, sha256Hex, stableStringify, translateUniqueViolationToDuplicate };
@@ -0,0 +1,17 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_validation_code = require("../validation-code.cjs");
3
+ const require_validation_field = require("../validation-field.cjs");
4
+ const require_domain_exception = require("../domain-exception.cjs");
5
+ const require_invalid_state_transition_exception = require("../invalid-state-transition-exception.cjs");
6
+ const require_invariant_violation_exception = require("../invariant-violation-exception.cjs");
7
+ const require_validation_exception = require("../validation-exception.cjs");
8
+ exports.BusinessRuleViolationException = require_invalid_state_transition_exception.BusinessRuleViolationException;
9
+ exports.DomainException = require_domain_exception.DomainException;
10
+ exports.EntityNotFoundException = require_invalid_state_transition_exception.EntityNotFoundException;
11
+ exports.InvalidStateTransitionException = require_invalid_state_transition_exception.InvalidStateTransitionException;
12
+ exports.InvalidValueException = require_validation_exception.InvalidValueException;
13
+ exports.InvariantViolationException = require_invariant_violation_exception.InvariantViolationException;
14
+ exports.MultipleValidationException = require_validation_exception.MultipleValidationException;
15
+ exports.ValidationCode = require_validation_code.ValidationCode;
16
+ exports.ValidationException = require_validation_exception.ValidationException;
17
+ exports.ValidationField = require_validation_field.ValidationField;
@@ -0,0 +1,5 @@
1
+ import { t as ValidationCode } from "../validation-code.cjs";
2
+ import { t as ValidationField } from "../validation-field.cjs";
3
+ import { t as DomainException } from "../domain-exception.cjs";
4
+ import { a as InvariantViolationException, c as BusinessRuleViolationException, i as ValidationViolation, n as MultipleValidationException, o as InvalidStateTransitionException, r as ValidationException, s as EntityNotFoundException, t as InvalidValueException } from "../validation-exception.cjs";
5
+ export { BusinessRuleViolationException, DomainException, EntityNotFoundException, InvalidStateTransitionException, InvalidValueException, InvariantViolationException, MultipleValidationException, ValidationCode, ValidationException, ValidationField, ValidationViolation };
@@ -0,0 +1,3 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_validation_field = require("../validation-field.cjs");
3
+ exports.ValidationField = require_validation_field.ValidationField;
@@ -0,0 +1,2 @@
1
+ import { t as ValidationField } from "../validation-field.cjs";
2
+ export { ValidationField };
@@ -0,0 +1,308 @@
1
+ const require_gate_v1_payload_schema = require("./gate-v1-payload.schema.cjs");
2
+ const require_result = require("./result.cjs");
3
+ let zod = require("zod");
4
+ //#region src/core/policies/engines/v1/compute/compute-payload.schema.ts
5
+ const computeDecisionTableRuleSchema = zod.z.object({
6
+ conditions: require_gate_v1_payload_schema.conditionNodeSchema,
7
+ result: zod.z.unknown()
8
+ });
9
+ var ComputePayloadSchemaV1 = class ComputePayloadSchemaV1 {
10
+ static {
11
+ this.schema = zod.z.union([zod.z.object({
12
+ type: zod.z.literal("decision-table"),
13
+ rules: zod.z.array(computeDecisionTableRuleSchema).min(1),
14
+ default: zod.z.unknown()
15
+ }).strict(), zod.z.object({
16
+ type: zod.z.literal("params"),
17
+ data: zod.z.record(zod.z.string(), zod.z.unknown())
18
+ }).strict()]);
19
+ }
20
+ static parse(payload) {
21
+ const parsed = ComputePayloadSchemaV1.schema.safeParse(payload);
22
+ if (!parsed.success) {
23
+ const details = parsed.error.issues.map((issue) => {
24
+ const path = issue.path.join(".");
25
+ return path.length > 0 ? `${path}: ${issue.message}` : issue.message;
26
+ }).join("; ");
27
+ return require_result.Result.err(`Invalid compute payload: ${details}`);
28
+ }
29
+ return require_result.Result.ok(parsed.data);
30
+ }
31
+ };
32
+ ComputePayloadSchemaV1.schema;
33
+ //#endregion
34
+ //#region src/core/policies/engines/parse-compute-payload.ts
35
+ var ComputePayloadParserRegistry = class {
36
+ constructor() {
37
+ this.parsers = /* @__PURE__ */ new Map();
38
+ }
39
+ register(payloadSchemaVersion, parser) {
40
+ this.parsers.set(payloadSchemaVersion, parser);
41
+ }
42
+ get(payloadSchemaVersion) {
43
+ return this.parsers.get(payloadSchemaVersion);
44
+ }
45
+ parse(payloadSchemaVersion, payload) {
46
+ const parser = this.parsers.get(payloadSchemaVersion);
47
+ if (parser === void 0) return require_result.Result.err(`No compute payload parser registered for schema version "${payloadSchemaVersion}"`);
48
+ return parser(payload);
49
+ }
50
+ };
51
+ var ComputePayloadParsers = class ComputePayloadParsers {
52
+ static {
53
+ this.registry = new ComputePayloadParserRegistry();
54
+ }
55
+ static {
56
+ this.defaultsRegistered = false;
57
+ }
58
+ static ensureDefaults() {
59
+ if (ComputePayloadParsers.defaultsRegistered) return;
60
+ ComputePayloadParsers.defaultsRegistered = true;
61
+ ComputePayloadParsers.registry.register(1, ComputePayloadSchemaV1.parse);
62
+ }
63
+ static register(payloadSchemaVersion, parser) {
64
+ ComputePayloadParsers.ensureDefaults();
65
+ ComputePayloadParsers.registry.register(payloadSchemaVersion, parser);
66
+ }
67
+ static get(payloadSchemaVersion) {
68
+ ComputePayloadParsers.ensureDefaults();
69
+ return ComputePayloadParsers.registry.get(payloadSchemaVersion);
70
+ }
71
+ static parse(payloadSchemaVersion, payload) {
72
+ ComputePayloadParsers.ensureDefaults();
73
+ return ComputePayloadParsers.registry.parse(payloadSchemaVersion, payload);
74
+ }
75
+ };
76
+ //#endregion
77
+ //#region src/core/policies/engines/compute-engine-registry.ts
78
+ var ComputeEngineRegistry = class {
79
+ constructor() {
80
+ this.engines = /* @__PURE__ */ new Map();
81
+ }
82
+ register(engine) {
83
+ this.engines.set(engine.version, engine);
84
+ }
85
+ get(version) {
86
+ return this.engines.get(version);
87
+ }
88
+ evaluate(version, params) {
89
+ const engine = this.get(version);
90
+ if (engine === void 0) return require_result.Result.err(`No compute engine registered for version "${version}"`);
91
+ const evaluator = params.evaluators.get(params.policyKey, version);
92
+ if (evaluator === void 0) return require_result.Result.err(`No compute evaluator registered for policy key "${params.policyKey}" and version "${version}"`);
93
+ const parsedPayloadResult = ComputePayloadParsers.parse(params.payloadSchemaVersion, params.payload);
94
+ if (parsedPayloadResult.isErr()) return require_result.Result.err(parsedPayloadResult.errorOrNull());
95
+ return engine.evaluate(parsedPayloadResult.getOrNull(), params.context, evaluator);
96
+ }
97
+ };
98
+ //#endregion
99
+ //#region src/core/policies/engines/compute-evaluator-registry.ts
100
+ var ComputeEvaluatorRegistry = class ComputeEvaluatorRegistry {
101
+ constructor() {
102
+ this.evaluators = /* @__PURE__ */ new Map();
103
+ }
104
+ static toRegistryKey(policyKey, version) {
105
+ return `${policyKey}::${version}`;
106
+ }
107
+ register(registration) {
108
+ this.evaluators.set(ComputeEvaluatorRegistry.toRegistryKey(registration.policyKey, registration.version), registration.evaluator);
109
+ }
110
+ get(policyKey, version) {
111
+ return this.evaluators.get(ComputeEvaluatorRegistry.toRegistryKey(policyKey, version));
112
+ }
113
+ };
114
+ //#endregion
115
+ //#region src/core/policies/engines/v1/compute/resolve-decision-table-v1.ts
116
+ const COMPUTE_CONDITION_EVAL_FAILED_TAG = "COMPUTE_CONDITION_EVAL_FAILED";
117
+ var DecisionTableResolverV1 = class DecisionTableResolverV1 {
118
+ constructor(payload, context, conditionEvaluationOptions) {
119
+ this.payload = payload;
120
+ this.context = context;
121
+ this.conditionEvaluationOptions = conditionEvaluationOptions;
122
+ }
123
+ wrapConditionEvaluationError(error) {
124
+ return require_result.Result.err(`${COMPUTE_CONDITION_EVAL_FAILED_TAG}: ${error}`);
125
+ }
126
+ resolve() {
127
+ const evaluator = new require_gate_v1_payload_schema.ConditionEvaluatorV1(this.context, this.conditionEvaluationOptions);
128
+ for (const rule of this.payload.rules) {
129
+ const conditionResult = evaluator.evaluate(rule.conditions);
130
+ if (conditionResult.isErr()) return this.wrapConditionEvaluationError(conditionResult.errorOrNull());
131
+ if (conditionResult.getOrNull()) return require_result.Result.ok(rule.result);
132
+ }
133
+ return require_result.Result.ok(this.payload.default);
134
+ }
135
+ static resolve(payload, context, conditionEvaluationOptions) {
136
+ return new DecisionTableResolverV1(payload, context, conditionEvaluationOptions).resolve();
137
+ }
138
+ };
139
+ //#endregion
140
+ //#region src/core/policies/engines/v1/compute/compute-engine-v1.ts
141
+ const COMPUTE_ENGINE_VERSION = 1;
142
+ var ComputeEngineV1 = class {
143
+ constructor(params = {}) {
144
+ this.version = COMPUTE_ENGINE_VERSION;
145
+ this.coreConfig = params.coreConfig ?? require_gate_v1_payload_schema.coreConfig;
146
+ }
147
+ /**
148
+ * Evaluates an already-parsed ComputePayload against a context.
149
+ * Pure function — no side effects.
150
+ *
151
+ * For `params`: forwards `payload.data` directly to the evaluator.
152
+ * For `decision-table`: evaluates the rules in order and passes the `result`
153
+ * of the first one that satisfies its conditions, or `default` if none match.
154
+ *
155
+ * The evaluator is responsible for validating and transforming the final value.
156
+ */
157
+ evaluate(payload, context, evaluator) {
158
+ if (payload.type === "params") return evaluator.evaluate(payload.data, context);
159
+ const resolvedResult = DecisionTableResolverV1.resolve(payload, context, this.coreConfig.getConditionEvaluationOptions(COMPUTE_ENGINE_VERSION));
160
+ if (resolvedResult.isErr()) return require_result.Result.err(resolvedResult.errorOrNull());
161
+ return evaluator.evaluate(resolvedResult.getOrNull(), context);
162
+ }
163
+ };
164
+ //#endregion
165
+ //#region src/core/policies/engines/compute-registry.ts
166
+ var ComputeRegistry = class {
167
+ constructor(params = {}) {
168
+ this.engines = new ComputeEngineRegistry();
169
+ this.evaluators = new ComputeEvaluatorRegistry();
170
+ const resolvedCoreConfig = params.coreConfig ?? require_gate_v1_payload_schema.coreConfig;
171
+ this.engines.register(new ComputeEngineV1({ coreConfig: resolvedCoreConfig }));
172
+ }
173
+ register(registration) {
174
+ this.evaluators.register(registration);
175
+ }
176
+ registerEngine(engine) {
177
+ this.engines.register(engine);
178
+ }
179
+ getEngine(version) {
180
+ return this.engines.get(version);
181
+ }
182
+ getEvaluator(policyKey, version) {
183
+ return this.evaluators.get(policyKey, version);
184
+ }
185
+ evaluate(policyKey, computeEngineVersion, payloadSchemaVersion, payload, context) {
186
+ return this.engines.evaluate(computeEngineVersion, {
187
+ policyKey,
188
+ payloadSchemaVersion,
189
+ payload,
190
+ context,
191
+ evaluators: this.evaluators
192
+ });
193
+ }
194
+ };
195
+ //#endregion
196
+ //#region src/core/policies/engines/parse-gate-payload.ts
197
+ var GatePayloadParserRegistry = class {
198
+ constructor() {
199
+ this.parsers = /* @__PURE__ */ new Map();
200
+ }
201
+ register(engineVersion, parser) {
202
+ this.parsers.set(engineVersion, parser);
203
+ }
204
+ get(engineVersion) {
205
+ return this.parsers.get(engineVersion);
206
+ }
207
+ parse(engineVersion, payload) {
208
+ const parser = this.parsers.get(engineVersion);
209
+ if (parser === void 0) return require_result.Result.err(`No gate payload parser registered for engine version "${engineVersion}"`);
210
+ return parser(payload);
211
+ }
212
+ };
213
+ var GatePayloadParsers = class GatePayloadParsers {
214
+ static {
215
+ this.registry = new GatePayloadParserRegistry();
216
+ }
217
+ static {
218
+ this.defaultsRegistered = false;
219
+ }
220
+ static ensureDefaults() {
221
+ if (GatePayloadParsers.defaultsRegistered) return;
222
+ GatePayloadParsers.defaultsRegistered = true;
223
+ GatePayloadParsers.registry.register(1, require_gate_v1_payload_schema.GatePayloadSchemaV1.parse);
224
+ }
225
+ static register(engineVersion, parser) {
226
+ GatePayloadParsers.ensureDefaults();
227
+ GatePayloadParsers.registry.register(engineVersion, parser);
228
+ }
229
+ static get(engineVersion) {
230
+ GatePayloadParsers.ensureDefaults();
231
+ return GatePayloadParsers.registry.get(engineVersion);
232
+ }
233
+ static parse(engineVersion, payload) {
234
+ GatePayloadParsers.ensureDefaults();
235
+ return GatePayloadParsers.registry.parse(engineVersion, payload);
236
+ }
237
+ };
238
+ //#endregion
239
+ //#region src/core/policies/engines/gate-engine-registry.ts
240
+ var GateEngineRegistry = class {
241
+ constructor() {
242
+ this.engines = /* @__PURE__ */ new Map();
243
+ }
244
+ register(engine) {
245
+ this.engines.set(engine.version, engine);
246
+ }
247
+ get(version) {
248
+ return this.engines.get(version);
249
+ }
250
+ evaluate(version, payload, context) {
251
+ const engine = this.engines.get(version);
252
+ if (!engine) return require_result.Result.err(`No gate engine registered for version "${version}"`);
253
+ const parsedPayload = GatePayloadParsers.parse(version, payload);
254
+ if (parsedPayload.isErr()) return require_result.Result.err(parsedPayload.errorOrNull());
255
+ return engine.evaluate(parsedPayload.getOrNull(), context);
256
+ }
257
+ };
258
+ //#endregion
259
+ Object.defineProperty(exports, "ComputeEngineRegistry", {
260
+ enumerable: true,
261
+ get: function() {
262
+ return ComputeEngineRegistry;
263
+ }
264
+ });
265
+ Object.defineProperty(exports, "ComputeEvaluatorRegistry", {
266
+ enumerable: true,
267
+ get: function() {
268
+ return ComputeEvaluatorRegistry;
269
+ }
270
+ });
271
+ Object.defineProperty(exports, "ComputePayloadParserRegistry", {
272
+ enumerable: true,
273
+ get: function() {
274
+ return ComputePayloadParserRegistry;
275
+ }
276
+ });
277
+ Object.defineProperty(exports, "ComputePayloadParsers", {
278
+ enumerable: true,
279
+ get: function() {
280
+ return ComputePayloadParsers;
281
+ }
282
+ });
283
+ Object.defineProperty(exports, "ComputeRegistry", {
284
+ enumerable: true,
285
+ get: function() {
286
+ return ComputeRegistry;
287
+ }
288
+ });
289
+ Object.defineProperty(exports, "GateEngineRegistry", {
290
+ enumerable: true,
291
+ get: function() {
292
+ return GateEngineRegistry;
293
+ }
294
+ });
295
+ Object.defineProperty(exports, "GatePayloadParserRegistry", {
296
+ enumerable: true,
297
+ get: function() {
298
+ return GatePayloadParserRegistry;
299
+ }
300
+ });
301
+ Object.defineProperty(exports, "GatePayloadParsers", {
302
+ enumerable: true,
303
+ get: function() {
304
+ return GatePayloadParsers;
305
+ }
306
+ });
307
+
308
+ //# sourceMappingURL=gate-engine-registry.cjs.map