@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.
Files changed (118) hide show
  1. package/KIT_CONTEXT.md +1 -0
  2. package/README.md +128 -1
  3. package/dist/app-error.d.ts +108 -0
  4. package/dist/application/index.d.ts +2 -0
  5. package/dist/application/index.js +3 -0
  6. package/dist/domain/index.d.ts +3 -0
  7. package/dist/domain/index.js +3 -0
  8. package/dist/domain-event-contracts.d.ts +27 -0
  9. package/dist/domain-event-contracts.js +22 -0
  10. package/dist/domain-event-contracts.js.map +1 -0
  11. package/dist/domain-exception.d.ts +7 -0
  12. package/dist/domain-exception.js +12 -0
  13. package/dist/domain-exception.js.map +1 -0
  14. package/dist/errors/index.d.ts +2 -1
  15. package/dist/errors/index.js +4 -2
  16. package/dist/exceptions/index.d.ts +5 -0
  17. package/dist/exceptions/index.js +7 -0
  18. package/dist/gate-engine-registry.d.ts +81 -0
  19. package/dist/gate-engine-registry.js +2 -1
  20. package/dist/gate-engine-registry.js.map +1 -1
  21. package/dist/gate-types.d.ts +3 -139
  22. package/dist/gate-v1-payload.schema.js +3 -143
  23. package/dist/gate-v1-payload.schema.js.map +1 -1
  24. package/dist/hashing.js +49 -0
  25. package/dist/hashing.js.map +1 -0
  26. package/dist/immutable.d.ts +6 -0
  27. package/dist/immutable.js +54 -0
  28. package/dist/immutable.js.map +1 -0
  29. package/dist/index.d.ts +21 -200
  30. package/dist/index.js +21 -251
  31. package/dist/index.js.map +1 -1
  32. package/dist/invalid-state-transition-exception.js +30 -0
  33. package/dist/invalid-state-transition-exception.js.map +1 -0
  34. package/dist/invariant-violation-exception.js +11 -0
  35. package/dist/invariant-violation-exception.js.map +1 -0
  36. package/dist/not-found-error.js +54 -0
  37. package/dist/not-found-error.js.map +1 -0
  38. package/dist/outcome.d.ts +140 -0
  39. package/dist/outcome.js +1 -1
  40. package/dist/parse-gate-payload.d.ts +4 -78
  41. package/dist/path.d.ts +90 -0
  42. package/dist/plugin.d.ts +85 -0
  43. package/dist/plugin.js +74 -0
  44. package/dist/plugin.js.map +1 -0
  45. package/dist/plugins/index.d.ts +2 -0
  46. package/dist/plugins/index.js +2 -0
  47. package/dist/policies/engines/index.d.ts +3 -2
  48. package/dist/policies/engines/v1/gate/index.d.ts +2 -1
  49. package/dist/policies/engines/v1/gate/index.js +2 -1
  50. package/dist/policies/engines/v1/gate/index.js.map +1 -1
  51. package/dist/policies/index.d.ts +6 -3
  52. package/dist/policies/index.js +2 -1
  53. package/dist/policy-service.d.ts +4 -86
  54. package/dist/policy-service.js +8 -16
  55. package/dist/policy-service.js.map +1 -1
  56. package/dist/result/index.d.ts +2 -0
  57. package/dist/result/index.js +3 -0
  58. package/dist/result.js +118 -0
  59. package/dist/result.js.map +1 -0
  60. package/dist/ruleset-registry.js +42 -0
  61. package/dist/ruleset-registry.js.map +1 -0
  62. package/dist/rulesets/index.d.ts +2 -0
  63. package/dist/rulesets/index.js +2 -0
  64. package/dist/temporal-guards.js +15 -0
  65. package/dist/temporal-guards.js.map +1 -0
  66. package/dist/temporal-use-case.d.ts +304 -0
  67. package/dist/temporal-use-case.js +150 -0
  68. package/dist/temporal-use-case.js.map +1 -0
  69. package/dist/unexpected-error.js +179 -0
  70. package/dist/unexpected-error.js.map +1 -0
  71. package/dist/use-case.js +91 -0
  72. package/dist/use-case.js.map +1 -0
  73. package/dist/uuid-identifier.d.ts +230 -0
  74. package/dist/uuid-identifier.js +60 -0
  75. package/dist/uuid-identifier.js.map +1 -0
  76. package/dist/validation-code.d.ts +23 -0
  77. package/dist/validation-code.js +1 -223
  78. package/dist/validation-code.js.map +1 -1
  79. package/dist/validation-error.d.ts +3 -128
  80. package/dist/validation-error.js +2 -52
  81. package/dist/validation-error.js.map +1 -1
  82. package/dist/validation-exception.d.ts +50 -0
  83. package/dist/validation-exception.js +24 -0
  84. package/dist/validation-exception.js.map +1 -0
  85. package/dist/value-object-ruleset.contracts.d.ts +36 -0
  86. package/dist/value-object.js +191 -0
  87. package/dist/value-object.js.map +1 -0
  88. package/dist/version.d.ts +10 -0
  89. package/dist/versioning/index.d.ts +3 -0
  90. package/dist/versioning/index.js +3 -0
  91. package/meta.json +18 -3
  92. package/package.json +37 -4
  93. package/src/application/index.ts +1 -0
  94. package/src/core/application/commands/index.ts +1 -0
  95. package/src/core/application/index.ts +12 -3
  96. package/src/core/application/ports/index.ts +2 -2
  97. package/src/core/application/ports/policy-port.ts +13 -3
  98. package/src/core/application/ports/repository.port.ts +37 -1
  99. package/src/core/application/temporal/temporal-use-case.ts +14 -2
  100. package/src/core/application/use-case.ts +133 -2
  101. package/src/core/domain/rulesets/index.ts +7 -0
  102. package/src/core/domain/uuid-identifier.ts +72 -0
  103. package/src/core/domain/value-object.ts +37 -5
  104. package/src/core/exceptions/index.ts +13 -0
  105. package/src/core/index.ts +15 -12
  106. package/src/core/plugins/index.ts +7 -0
  107. package/src/core/plugins/plugin.ts +99 -0
  108. package/src/core/plugins/types.ts +53 -0
  109. package/src/core/versioning/index.ts +14 -0
  110. package/src/domain/index.ts +7 -0
  111. package/src/examples/application/cancel-order.example.ts +124 -0
  112. package/src/examples/application/in-memory-account-repository.example.ts +73 -0
  113. package/src/exceptions/index.ts +1 -0
  114. package/src/plugins/index.ts +1 -0
  115. package/src/result/index.ts +2 -0
  116. package/src/rulesets/index.ts +1 -0
  117. package/src/version.ts +1 -1
  118. 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,2 @@
1
+ export { type CommonOutcomeStatus, Outcome } from "../core/result/outcome.js";
2
+ export { Err, Ok, Result } from "../core/result/result.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.11";
7
+ export const version = "1.2.0";
@@ -0,0 +1 @@
1
+ export * from "../core/versioning/index.js";