@cullet/erp-core 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -24
- package/dist/gate-engine-registry.js.map +1 -1
- package/dist/gate-v1-payload.schema.js +5 -0
- package/dist/gate-v1-payload.schema.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/outcome.js.map +1 -1
- package/dist/policies/engines/v1/gate/index.d.ts +1 -0
- package/dist/policies/engines/v1/gate/index.js.map +1 -1
- package/dist/policy-service.js.map +1 -1
- package/dist/validation-code.js.map +1 -1
- package/dist/validation-error.js.map +1 -1
- package/dist/validation-field.js.map +1 -1
- package/meta.json +67 -67
- package/package.json +56 -56
- package/src/core/application/commands/command.ts +3 -3
- package/src/core/application/commands/requested-by.ts +60 -60
- package/src/core/application/index.ts +21 -21
- package/src/core/application/policy-error-mapper.ts +54 -54
- package/src/core/application/ports/index.ts +6 -6
- package/src/core/application/ports/logger.port.ts +4 -4
- package/src/core/application/ports/metrics.port.ts +3 -3
- package/src/core/application/ports/policy-port.ts +7 -7
- package/src/core/application/ports/repository.port.ts +3 -3
- package/src/core/application/ports/temporal-repository.port.ts +4 -4
- package/src/core/application/ports/tracer.port.ts +7 -7
- package/src/core/application/queries/query.ts +13 -13
- package/src/core/application/temporal/index.ts +7 -7
- package/src/core/application/temporal/temporal-context.ts +20 -20
- package/src/core/application/temporal/temporal-use-case.ts +22 -22
- package/src/core/application/use-case.ts +10 -10
- package/src/core/config/core-config.instance.ts +1 -1
- package/src/core/config/core-config.ts +59 -59
- package/src/core/config/index.ts +6 -6
- package/src/core/config/policy-reporter.ts +31 -31
- package/src/core/config/silent-policy-reporter.ts +1 -1
- package/src/core/domain/entity.ts +44 -44
- package/src/core/domain/rulesets/entity-ruleset.contracts.ts +6 -6
- package/src/core/domain/rulesets/ruleset-registry.ts +49 -49
- package/src/core/domain/rulesets/ruleset.contracts.ts +6 -6
- package/src/core/domain/rulesets/value-object-ruleset.contracts.ts +5 -5
- package/src/core/domain/temporal/index.ts +11 -11
- package/src/core/domain/temporal/temporal-range.ts +16 -16
- package/src/core/domain/temporal/temporal-snapshot.ts +24 -24
- package/src/core/domain/temporal/transaction-time.ts +30 -30
- package/src/core/domain/temporal/valid-time.ts +29 -29
- package/src/core/domain/value-object.ts +16 -16
- package/src/core/errors/app-error.ts +64 -64
- package/src/core/errors/authentication-error.ts +134 -134
- package/src/core/errors/authorization-error.ts +154 -154
- package/src/core/errors/business-rule-violation-error.ts +15 -15
- package/src/core/errors/conflict-error.ts +202 -201
- package/src/core/errors/error-codes.ts +48 -48
- package/src/core/errors/idempotency-error.ts +324 -320
- package/src/core/errors/index.ts +50 -50
- package/src/core/errors/integration-error.ts +120 -120
- package/src/core/errors/legacy-incompatible-error.ts +13 -13
- package/src/core/errors/not-found-error.ts +14 -14
- package/src/core/errors/serialization-error.ts +167 -167
- package/src/core/errors/temporal-error.ts +109 -107
- package/src/core/errors/types.ts +35 -35
- package/src/core/errors/unexpected-error.ts +10 -10
- package/src/core/errors/utils/index.ts +2 -2
- package/src/core/errors/utils/json-safe.ts +53 -53
- package/src/core/errors/validation-error.ts +18 -18
- package/src/core/exceptions/business-rule-violation-exception.ts +6 -6
- package/src/core/exceptions/domain-exception.ts +5 -5
- package/src/core/exceptions/entity-not-found-exception.ts +6 -6
- package/src/core/exceptions/invalid-state-transition-exception.ts +8 -8
- package/src/core/exceptions/invariant-violation-exception.ts +3 -3
- package/src/core/exceptions/validation-code.ts +35 -29
- package/src/core/exceptions/validation-exception.ts +19 -19
- package/src/core/exceptions/validation-field.ts +20 -19
- package/src/core/index.ts +7 -7
- package/src/core/policies/asof/asof.ts +47 -47
- package/src/core/policies/catalog/catalog.instance.ts +8 -6
- package/src/core/policies/catalog/index.ts +4 -4
- package/src/core/policies/catalog/policy-catalog-entry.ts +199 -197
- package/src/core/policies/catalog/policy-catalog.ts +101 -101
- package/src/core/policies/catalog/policy-key.ts +51 -51
- package/src/core/policies/context/context-builder.ts +335 -313
- package/src/core/policies/context/context-registry.instance.ts +9 -9
- package/src/core/policies/context/context-registry.ts +61 -61
- package/src/core/policies/context/context-resolver.ts +12 -12
- package/src/core/policies/context/context-seed.ts +19 -15
- package/src/core/policies/context/index.ts +9 -9
- package/src/core/policies/context/path.ts +135 -128
- package/src/core/policies/defs/in-memory-policy-definition-repo.ts +56 -55
- package/src/core/policies/defs/index.ts +10 -10
- package/src/core/policies/defs/policy-definition-repository.ts +3 -3
- package/src/core/policies/defs/policy-definition.ts +143 -142
- package/src/core/policies/defs/policy-scope.ts +21 -19
- package/src/core/policies/defs/policy-semver.ts +51 -51
- package/src/core/policies/engines/compute-engine-registry.ts +43 -43
- package/src/core/policies/engines/compute-evaluator-registry.ts +20 -20
- package/src/core/policies/engines/compute-registry.ts +45 -45
- package/src/core/policies/engines/compute-types.ts +15 -15
- package/src/core/policies/engines/condition-evaluator-reporter.ts +17 -17
- package/src/core/policies/engines/gate-engine-registry.ts +27 -25
- package/src/core/policies/engines/gate-types.ts +28 -28
- package/src/core/policies/engines/index.ts +28 -28
- package/src/core/policies/engines/parse-compute-payload.ts +51 -45
- package/src/core/policies/engines/parse-gate-payload.ts +42 -42
- package/src/core/policies/engines/v1/compute/compute-engine-v1.ts +39 -37
- package/src/core/policies/engines/v1/compute/compute-payload.schema.ts +43 -41
- package/src/core/policies/engines/v1/compute/index.ts +6 -6
- package/src/core/policies/engines/v1/compute/resolve-decision-table-v1.ts +41 -39
- package/src/core/policies/engines/v1/condition-evaluator.ts +557 -504
- package/src/core/policies/engines/v1/condition-schema.ts +35 -35
- package/src/core/policies/engines/v1/condition-types.ts +21 -21
- package/src/core/policies/engines/v1/gate/gate-engine-v1.ts +134 -130
- package/src/core/policies/engines/v1/gate/gate-types-v1.ts +5 -5
- package/src/core/policies/engines/v1/gate/gate-v1-payload.schema.ts +32 -30
- package/src/core/policies/engines/v1/gate/index.ts +4 -4
- package/src/core/policies/engines/v1/index.ts +8 -8
- package/src/core/policies/index.ts +72 -72
- package/src/core/policies/package/policy-package.ts +3 -3
- package/src/core/policies/policy-ids.ts +25 -25
- package/src/core/policies/resolver/policy-resolver.ts +34 -34
- package/src/core/policies/service/index.ts +6 -6
- package/src/core/policies/service/policy-evaluation-error.ts +141 -133
- package/src/core/policies/service/policy-service.ts +432 -419
- package/src/core/policies/utils/date.ts +3 -3
- package/src/core/policies/utils/hash.ts +61 -61
- package/src/core/result/outcome.ts +131 -126
- package/src/core/result/result.ts +130 -127
- package/src/core/shared/aggregate-version.ts +5 -5
- package/src/core/shared/hashing.ts +18 -18
- package/src/core/shared/immutable.ts +29 -29
- package/src/core/shared/temporal-guards.ts +9 -9
- package/src/core/versioning/domain-event-contracts.ts +40 -40
- package/src/core/versioning/version.ts +19 -19
- package/src/examples/rulesets/entity/order-creation-rules-v1.ts +18 -18
- package/src/examples/rulesets/entity/order-invariants-v1.ts +31 -29
- package/src/examples/rulesets/entity/order-invariants-v2.ts +12 -12
- package/src/examples/rulesets/entity/order.ts +127 -127
- package/src/examples/rulesets/value-object/cpf-rules-v1.ts +41 -39
- package/src/examples/rulesets/value-object/cpf-rules-v2.ts +14 -12
- package/src/examples/rulesets/value-object/cpf.ts +24 -24
- package/src/examples/rulesets/value-object/customer.ts +42 -39
- package/src/examples/rulesets/value-object/person-name-rules-v1.ts +27 -27
- package/src/examples/rulesets/value-object/person-name-rules-v2.ts +13 -13
- package/src/examples/rulesets/value-object/person-name.ts +29 -26
- package/src/index.ts +2 -2
- package/src/version.ts +1 -1
|
@@ -1,67 +1,70 @@
|
|
|
1
1
|
import { CPF } from "./cpf";
|
|
2
2
|
import { PersonName } from "./person-name";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type RulesetId,
|
|
5
|
+
type ValueObjectRuleset,
|
|
6
6
|
} from "../../../core/domain/rulesets/value-object-ruleset.contracts";
|
|
7
7
|
|
|
8
8
|
interface CustomerCreateData {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
readonly cpf: string;
|
|
10
|
+
readonly name: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
interface CustomerCreateRulesets {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
readonly cpf: ValueObjectRuleset<string>;
|
|
15
|
+
readonly name: ValueObjectRuleset<string>;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
interface CustomerSnapshot {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
readonly cpf_value: string;
|
|
20
|
+
readonly cpf_ruleset: RulesetId;
|
|
21
|
+
readonly name_value: string;
|
|
22
|
+
readonly name_ruleset: RulesetId;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
interface CustomerStatic {
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
create(
|
|
27
|
+
data: CustomerCreateData,
|
|
28
|
+
rulesets: CustomerCreateRulesets,
|
|
29
|
+
): Customer;
|
|
30
|
+
reconstitute(snapshot: CustomerSnapshot): Customer;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
class Customer {
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
readonly cpf: CPF;
|
|
35
|
+
readonly name: PersonName;
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
private constructor(cpf: CPF, name: PersonName) {
|
|
38
|
+
this.cpf = cpf;
|
|
39
|
+
this.name = name;
|
|
40
|
+
}
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
static create(
|
|
43
|
+
data: CustomerCreateData,
|
|
44
|
+
rulesets: CustomerCreateRulesets,
|
|
45
|
+
): Customer {
|
|
46
|
+
const cpf = CPF.create(data.cpf, rulesets.cpf);
|
|
47
|
+
const name = PersonName.create(data.name, rulesets.name);
|
|
48
|
+
return new Customer(cpf, name);
|
|
49
|
+
}
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
static reconstitute(snapshot: CustomerSnapshot): Customer {
|
|
52
|
+
const cpf = CPF.reconstitute(snapshot.cpf_value, snapshot.cpf_ruleset);
|
|
53
|
+
const name = PersonName.reconstitute(
|
|
54
|
+
snapshot.name_value,
|
|
55
|
+
snapshot.name_ruleset,
|
|
56
|
+
);
|
|
57
|
+
return new Customer(cpf, name);
|
|
58
|
+
}
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
const _typeCheck: CustomerStatic = Customer;
|
|
59
62
|
void _typeCheck;
|
|
60
63
|
|
|
61
64
|
export {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
Customer,
|
|
66
|
+
type CustomerCreateData,
|
|
67
|
+
type CustomerCreateRulesets,
|
|
68
|
+
type CustomerSnapshot,
|
|
69
|
+
type CustomerStatic,
|
|
67
70
|
};
|
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
DomainException,
|
|
3
|
+
type ValueObjectRuleset,
|
|
4
4
|
} from "../../../core/domain/rulesets/value-object-ruleset.contracts";
|
|
5
5
|
|
|
6
6
|
class PersonNameValidationError extends DomainException {}
|
|
7
7
|
|
|
8
8
|
class PersonNameRulesV1 implements ValueObjectRuleset<string> {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
9
|
+
readonly id = "person-name-rules@1.0" as const;
|
|
10
|
+
readonly description = "Name validation requiring at least two words";
|
|
11
|
+
|
|
12
|
+
validate(value: string): void {
|
|
13
|
+
const trimmed = value.trim();
|
|
14
|
+
|
|
15
|
+
if (trimmed.length === 0) {
|
|
16
|
+
throw new PersonNameValidationError("Name cannot be empty.");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const words = trimmed.split(/\s+/);
|
|
20
|
+
|
|
21
|
+
if (words.length < 2) {
|
|
22
|
+
throw new PersonNameValidationError(
|
|
23
|
+
`Name must have at least two words. Received: "${value}".`,
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
for (const word of words) {
|
|
28
|
+
if (word.length < 2) {
|
|
29
|
+
throw new PersonNameValidationError(
|
|
30
|
+
`Each word of the name must be at least two characters long. Invalid word: "${word}".`,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
33
34
|
}
|
|
34
|
-
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export { PersonNameRulesV1 };
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
DomainException,
|
|
3
|
+
type ValueObjectRuleset,
|
|
4
4
|
} from "../../../core/domain/rulesets/value-object-ruleset.contracts";
|
|
5
5
|
import { PersonNameRulesV1 } from "./person-name-rules-v1";
|
|
6
6
|
|
|
7
7
|
class PersonNameCharacterError extends DomainException {}
|
|
8
8
|
|
|
9
9
|
class PersonNameRulesV2 implements ValueObjectRuleset<string> {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
readonly id = "person-name-rules@2.0" as const;
|
|
11
|
+
readonly description =
|
|
12
|
+
"Name validation with restriction on special characters";
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
private readonly v1 = new PersonNameRulesV1();
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
validate(value: string): void {
|
|
17
|
+
this.v1.validate(value);
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
if (/[^a-zA-ZÀ-ÿ\s'-]/.test(value)) {
|
|
20
|
+
throw new PersonNameCharacterError(
|
|
21
|
+
`Name contains invalid characters: "${value}". Only letters, hyphens, and apostrophes are allowed.`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
23
24
|
}
|
|
24
|
-
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export { PersonNameRulesV2 };
|
|
@@ -1,36 +1,39 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type RulesetId,
|
|
3
|
+
type ValueObjectRuleset,
|
|
4
4
|
} from "../../../core/domain/rulesets/value-object-ruleset.contracts";
|
|
5
5
|
|
|
6
6
|
interface PersonNameStatic {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
create(raw: string, ruleset: ValueObjectRuleset<string>): PersonName;
|
|
8
|
+
reconstitute(value: string, rulesetId: RulesetId): PersonName;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
class PersonName {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
12
|
+
readonly value: string;
|
|
13
|
+
readonly appliedRulesetId: RulesetId;
|
|
14
|
+
|
|
15
|
+
private constructor(value: string, appliedRulesetId: RulesetId) {
|
|
16
|
+
this.value = value;
|
|
17
|
+
this.appliedRulesetId = appliedRulesetId;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
equals(other: PersonName): boolean {
|
|
21
|
+
const normalize = (v: string) =>
|
|
22
|
+
v.trim().replace(/\s+/g, " ").toLowerCase();
|
|
23
|
+
return normalize(this.value) === normalize(other.value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static create(
|
|
27
|
+
raw: string,
|
|
28
|
+
ruleset: ValueObjectRuleset<string>,
|
|
29
|
+
): PersonName {
|
|
30
|
+
ruleset.validate(raw);
|
|
31
|
+
return new PersonName(raw, ruleset.id);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static reconstitute(value: string, rulesetId: RulesetId): PersonName {
|
|
35
|
+
return new PersonName(value, rulesetId);
|
|
36
|
+
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
const _typeCheck: PersonNameStatic = PersonName;
|
package/src/index.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
// Mantemos a versao aqui, dentro de src/, para que a copia full-control seja
|
|
5
5
|
// auto-contida: ao copiar so o conteudo de src/, o entry nao depende de um
|
|
6
6
|
// `../package.json` que deixaria de existir no projeto consumidor.
|
|
7
|
-
export const version = "1.0.
|
|
7
|
+
export const version = "1.0.4";
|