@cullet/erp-core 1.0.11 → 1.2.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 +1 -0
- package/README.md +128 -1
- package/dist/app-error.d.ts +108 -0
- package/dist/application/index.d.ts +2 -0
- package/dist/application/index.js +3 -0
- package/dist/domain/index.d.ts +3 -0
- package/dist/domain/index.js +3 -0
- package/dist/domain-event-contracts.d.ts +27 -0
- package/dist/domain-event-contracts.js +22 -0
- package/dist/domain-event-contracts.js.map +1 -0
- package/dist/domain-exception.d.ts +7 -0
- package/dist/domain-exception.js +12 -0
- package/dist/domain-exception.js.map +1 -0
- package/dist/errors/index.d.ts +2 -1
- package/dist/errors/index.js +4 -2
- package/dist/exceptions/index.d.ts +5 -0
- package/dist/exceptions/index.js +7 -0
- package/dist/gate-engine-registry.d.ts +81 -0
- package/dist/gate-engine-registry.js +2 -1
- package/dist/gate-engine-registry.js.map +1 -1
- package/dist/gate-types.d.ts +3 -139
- package/dist/gate-v1-payload.schema.js +3 -143
- package/dist/gate-v1-payload.schema.js.map +1 -1
- package/dist/hashing.js +49 -0
- package/dist/hashing.js.map +1 -0
- package/dist/immutable.d.ts +6 -0
- package/dist/immutable.js +54 -0
- package/dist/immutable.js.map +1 -0
- package/dist/index.d.ts +21 -200
- package/dist/index.js +21 -251
- package/dist/index.js.map +1 -1
- package/dist/invalid-state-transition-exception.js +30 -0
- package/dist/invalid-state-transition-exception.js.map +1 -0
- package/dist/invariant-violation-exception.js +11 -0
- package/dist/invariant-violation-exception.js.map +1 -0
- package/dist/not-found-error.js +54 -0
- package/dist/not-found-error.js.map +1 -0
- package/dist/outcome.d.ts +140 -0
- package/dist/outcome.js +1 -1
- package/dist/parse-gate-payload.d.ts +4 -78
- package/dist/path.d.ts +90 -0
- package/dist/plugin.d.ts +85 -0
- package/dist/plugin.js +74 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +2 -0
- package/dist/policies/engines/index.d.ts +3 -2
- package/dist/policies/engines/v1/gate/index.d.ts +2 -1
- 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.d.ts +6 -3
- package/dist/policies/index.js +2 -1
- package/dist/policy-service.d.ts +4 -86
- package/dist/policy-service.js +8 -16
- package/dist/policy-service.js.map +1 -1
- package/dist/result/index.d.ts +2 -0
- package/dist/result/index.js +3 -0
- package/dist/result.js +118 -0
- package/dist/result.js.map +1 -0
- package/dist/ruleset-registry.js +42 -0
- package/dist/ruleset-registry.js.map +1 -0
- package/dist/rulesets/index.d.ts +2 -0
- package/dist/rulesets/index.js +2 -0
- package/dist/temporal-guards.js +15 -0
- package/dist/temporal-guards.js.map +1 -0
- package/dist/temporal-use-case.d.ts +304 -0
- package/dist/temporal-use-case.js +150 -0
- package/dist/temporal-use-case.js.map +1 -0
- package/dist/unexpected-error.js +179 -0
- package/dist/unexpected-error.js.map +1 -0
- package/dist/use-case.js +91 -0
- package/dist/use-case.js.map +1 -0
- package/dist/uuid-identifier.d.ts +230 -0
- package/dist/uuid-identifier.js +60 -0
- package/dist/uuid-identifier.js.map +1 -0
- package/dist/validation-code.d.ts +23 -0
- package/dist/validation-code.js +1 -223
- package/dist/validation-code.js.map +1 -1
- package/dist/validation-error.d.ts +3 -128
- package/dist/validation-error.js +2 -52
- package/dist/validation-error.js.map +1 -1
- package/dist/validation-exception.d.ts +50 -0
- package/dist/validation-exception.js +24 -0
- package/dist/validation-exception.js.map +1 -0
- package/dist/value-object-ruleset.contracts.d.ts +36 -0
- package/dist/value-object.js +191 -0
- package/dist/value-object.js.map +1 -0
- package/dist/version.d.ts +10 -0
- package/dist/versioning/index.d.ts +3 -0
- package/dist/versioning/index.js +3 -0
- package/meta.json +18 -3
- package/package.json +37 -4
- package/src/application/index.ts +1 -0
- package/src/core/application/commands/index.ts +1 -0
- package/src/core/application/index.ts +12 -3
- package/src/core/application/ports/index.ts +2 -2
- package/src/core/application/ports/policy-port.ts +13 -3
- package/src/core/application/ports/repository.port.ts +37 -1
- package/src/core/application/temporal/temporal-use-case.ts +14 -2
- package/src/core/application/use-case.ts +133 -2
- package/src/core/domain/rulesets/index.ts +7 -0
- package/src/core/domain/uuid-identifier.ts +72 -0
- package/src/core/domain/value-object.ts +37 -5
- package/src/core/exceptions/index.ts +13 -0
- package/src/core/index.ts +15 -12
- package/src/core/plugins/index.ts +7 -0
- package/src/core/plugins/plugin.ts +99 -0
- package/src/core/plugins/types.ts +53 -0
- package/src/core/versioning/index.ts +14 -0
- package/src/domain/index.ts +7 -0
- package/src/examples/application/cancel-order.example.ts +124 -0
- package/src/examples/application/in-memory-account-repository.example.ts +73 -0
- package/src/exceptions/index.ts +1 -0
- package/src/plugins/index.ts +1 -0
- package/src/result/index.ts +2 -0
- package/src/rulesets/index.ts +1 -0
- package/src/version.ts +1 -1
- package/src/versioning/index.ts +1 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference implementation of a {@link ResultRepository}: shows how a
|
|
3
|
+
* repository signals recoverable persistence outcomes as `Result` values
|
|
4
|
+
* instead of throwing.
|
|
5
|
+
*
|
|
6
|
+
* - `save` returns a `ConflictError` on an optimistic-concurrency version
|
|
7
|
+
* mismatch, otherwise persists and bumps the version.
|
|
8
|
+
* - `delete` returns a `NotFoundError` when the row is absent.
|
|
9
|
+
* - `findById` keeps `null` as the "not present" answer (a valid lookup
|
|
10
|
+
* result, not an error), still wrapped in a `Result` so genuine infra
|
|
11
|
+
* failures could stay in band.
|
|
12
|
+
*
|
|
13
|
+
* Consumers import `ResultRepository` from the package root
|
|
14
|
+
* (`@cullet/erp-core`); the relative paths here keep the example compilable
|
|
15
|
+
* and test-covered.
|
|
16
|
+
*/
|
|
17
|
+
import type { ResultRepository } from "../../core/application/index.js";
|
|
18
|
+
import {
|
|
19
|
+
AlreadyExistsError,
|
|
20
|
+
type ConflictError,
|
|
21
|
+
NotFoundError,
|
|
22
|
+
} from "../../core/errors/index.js";
|
|
23
|
+
import { Result } from "../../core/result/result.js";
|
|
24
|
+
|
|
25
|
+
interface Account {
|
|
26
|
+
readonly id: string;
|
|
27
|
+
readonly version: number;
|
|
28
|
+
readonly balance: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type AccountError = NotFoundError | ConflictError;
|
|
32
|
+
|
|
33
|
+
class InMemoryAccountRepository implements ResultRepository<
|
|
34
|
+
Account,
|
|
35
|
+
string,
|
|
36
|
+
AccountError
|
|
37
|
+
> {
|
|
38
|
+
private readonly store = new Map<string, Account>();
|
|
39
|
+
|
|
40
|
+
seed(account: Account): void {
|
|
41
|
+
this.store.set(account.id, account);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async findById(id: string): Promise<Result<Account | null, AccountError>> {
|
|
45
|
+
return Result.ok(this.store.get(id) ?? null);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async save(entity: Account): Promise<Result<void, AccountError>> {
|
|
49
|
+
const current = this.store.get(entity.id);
|
|
50
|
+
if (current && current.version !== entity.version) {
|
|
51
|
+
return Result.err(
|
|
52
|
+
AlreadyExistsError.detected({
|
|
53
|
+
entity: "Account",
|
|
54
|
+
operation: "update",
|
|
55
|
+
existingId: entity.id,
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
this.store.set(entity.id, { ...entity, version: entity.version + 1 });
|
|
60
|
+
return Result.ok(undefined);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async delete(id: string): Promise<Result<void, AccountError>> {
|
|
64
|
+
if (!this.store.has(id)) {
|
|
65
|
+
return Result.err(new NotFoundError("Account", { id }));
|
|
66
|
+
}
|
|
67
|
+
this.store.delete(id);
|
|
68
|
+
return Result.ok(undefined);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export { InMemoryAccountRepository };
|
|
73
|
+
export type { Account, AccountError };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../core/exceptions/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../core/plugins/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../core/domain/rulesets/index.js";
|
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.2.0";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../core/versioning/index.js";
|