@cullet/erp-core 1.0.1 → 1.0.3

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 (144) hide show
  1. package/README.md +24 -24
  2. package/dist/gate-engine-registry.js.map +1 -1
  3. package/dist/gate-v1-payload.schema.js.map +1 -1
  4. package/dist/index.d.ts +2 -2
  5. package/dist/index.js +1 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/outcome.js.map +1 -1
  8. package/dist/policies/engines/v1/gate/index.js.map +1 -1
  9. package/dist/policy-service.js.map +1 -1
  10. package/dist/validation-code.js.map +1 -1
  11. package/dist/validation-error.js.map +1 -1
  12. package/dist/validation-field.js.map +1 -1
  13. package/meta.json +67 -62
  14. package/package.json +56 -56
  15. package/src/core/application/commands/command.ts +3 -3
  16. package/src/core/application/commands/requested-by.ts +60 -60
  17. package/src/core/application/index.ts +21 -21
  18. package/src/core/application/policy-error-mapper.ts +54 -54
  19. package/src/core/application/ports/index.ts +6 -6
  20. package/src/core/application/ports/logger.port.ts +4 -4
  21. package/src/core/application/ports/metrics.port.ts +3 -3
  22. package/src/core/application/ports/policy-port.ts +7 -7
  23. package/src/core/application/ports/repository.port.ts +3 -3
  24. package/src/core/application/ports/temporal-repository.port.ts +4 -4
  25. package/src/core/application/ports/tracer.port.ts +7 -7
  26. package/src/core/application/queries/query.ts +13 -13
  27. package/src/core/application/temporal/index.ts +7 -7
  28. package/src/core/application/temporal/temporal-context.ts +20 -20
  29. package/src/core/application/temporal/temporal-use-case.ts +22 -22
  30. package/src/core/application/use-case.ts +10 -10
  31. package/src/core/config/core-config.instance.ts +1 -1
  32. package/src/core/config/core-config.ts +59 -59
  33. package/src/core/config/index.ts +6 -6
  34. package/src/core/config/policy-reporter.ts +31 -31
  35. package/src/core/config/silent-policy-reporter.ts +1 -1
  36. package/src/core/domain/entity.ts +44 -44
  37. package/src/core/domain/rulesets/entity-ruleset.contracts.ts +6 -6
  38. package/src/core/domain/rulesets/ruleset-registry.ts +49 -49
  39. package/src/core/domain/rulesets/ruleset.contracts.ts +6 -6
  40. package/src/core/domain/rulesets/value-object-ruleset.contracts.ts +5 -5
  41. package/src/core/domain/temporal/index.ts +11 -11
  42. package/src/core/domain/temporal/temporal-range.ts +16 -16
  43. package/src/core/domain/temporal/temporal-snapshot.ts +24 -24
  44. package/src/core/domain/temporal/transaction-time.ts +30 -30
  45. package/src/core/domain/temporal/valid-time.ts +29 -29
  46. package/src/core/domain/value-object.ts +16 -16
  47. package/src/core/errors/app-error.ts +64 -64
  48. package/src/core/errors/authentication-error.ts +134 -134
  49. package/src/core/errors/authorization-error.ts +154 -154
  50. package/src/core/errors/business-rule-violation-error.ts +15 -15
  51. package/src/core/errors/conflict-error.ts +202 -201
  52. package/src/core/errors/error-codes.ts +48 -48
  53. package/src/core/errors/idempotency-error.ts +324 -320
  54. package/src/core/errors/index.ts +50 -50
  55. package/src/core/errors/integration-error.ts +120 -120
  56. package/src/core/errors/legacy-incompatible-error.ts +13 -13
  57. package/src/core/errors/not-found-error.ts +14 -14
  58. package/src/core/errors/serialization-error.ts +167 -167
  59. package/src/core/errors/temporal-error.ts +109 -107
  60. package/src/core/errors/types.ts +35 -35
  61. package/src/core/errors/unexpected-error.ts +10 -10
  62. package/src/core/errors/utils/index.ts +2 -2
  63. package/src/core/errors/utils/json-safe.ts +53 -53
  64. package/src/core/errors/validation-error.ts +18 -18
  65. package/src/core/exceptions/business-rule-violation-exception.ts +6 -6
  66. package/src/core/exceptions/domain-exception.ts +5 -5
  67. package/src/core/exceptions/entity-not-found-exception.ts +6 -6
  68. package/src/core/exceptions/invalid-state-transition-exception.ts +8 -8
  69. package/src/core/exceptions/invariant-violation-exception.ts +3 -3
  70. package/src/core/exceptions/validation-code.ts +35 -29
  71. package/src/core/exceptions/validation-exception.ts +19 -19
  72. package/src/core/exceptions/validation-field.ts +20 -19
  73. package/src/core/index.ts +7 -7
  74. package/src/core/policies/asof/asof.ts +47 -47
  75. package/src/core/policies/catalog/catalog.instance.ts +8 -6
  76. package/src/core/policies/catalog/index.ts +4 -4
  77. package/src/core/policies/catalog/policy-catalog-entry.ts +199 -197
  78. package/src/core/policies/catalog/policy-catalog.ts +101 -101
  79. package/src/core/policies/catalog/policy-key.ts +51 -51
  80. package/src/core/policies/context/context-builder.ts +335 -313
  81. package/src/core/policies/context/context-registry.instance.ts +9 -9
  82. package/src/core/policies/context/context-registry.ts +61 -61
  83. package/src/core/policies/context/context-resolver.ts +12 -12
  84. package/src/core/policies/context/context-seed.ts +19 -15
  85. package/src/core/policies/context/index.ts +9 -9
  86. package/src/core/policies/context/path.ts +135 -128
  87. package/src/core/policies/defs/in-memory-policy-definition-repo.ts +56 -55
  88. package/src/core/policies/defs/index.ts +10 -10
  89. package/src/core/policies/defs/policy-definition-repository.ts +3 -3
  90. package/src/core/policies/defs/policy-definition.ts +143 -142
  91. package/src/core/policies/defs/policy-scope.ts +21 -19
  92. package/src/core/policies/defs/policy-semver.ts +51 -51
  93. package/src/core/policies/engines/compute-engine-registry.ts +43 -43
  94. package/src/core/policies/engines/compute-evaluator-registry.ts +20 -20
  95. package/src/core/policies/engines/compute-registry.ts +45 -45
  96. package/src/core/policies/engines/compute-types.ts +15 -15
  97. package/src/core/policies/engines/condition-evaluator-reporter.ts +17 -17
  98. package/src/core/policies/engines/gate-engine-registry.ts +27 -25
  99. package/src/core/policies/engines/gate-types.ts +28 -28
  100. package/src/core/policies/engines/index.ts +28 -28
  101. package/src/core/policies/engines/parse-compute-payload.ts +51 -45
  102. package/src/core/policies/engines/parse-gate-payload.ts +42 -42
  103. package/src/core/policies/engines/v1/compute/compute-engine-v1.ts +39 -37
  104. package/src/core/policies/engines/v1/compute/compute-payload.schema.ts +43 -41
  105. package/src/core/policies/engines/v1/compute/index.ts +6 -6
  106. package/src/core/policies/engines/v1/compute/resolve-decision-table-v1.ts +41 -39
  107. package/src/core/policies/engines/v1/condition-evaluator.ts +547 -505
  108. package/src/core/policies/engines/v1/condition-schema.ts +35 -35
  109. package/src/core/policies/engines/v1/condition-types.ts +21 -21
  110. package/src/core/policies/engines/v1/gate/gate-engine-v1.ts +134 -130
  111. package/src/core/policies/engines/v1/gate/gate-types-v1.ts +5 -5
  112. package/src/core/policies/engines/v1/gate/gate-v1-payload.schema.ts +32 -30
  113. package/src/core/policies/engines/v1/gate/index.ts +4 -4
  114. package/src/core/policies/engines/v1/index.ts +8 -8
  115. package/src/core/policies/index.ts +72 -72
  116. package/src/core/policies/package/policy-package.ts +3 -3
  117. package/src/core/policies/policy-ids.ts +25 -25
  118. package/src/core/policies/resolver/policy-resolver.ts +34 -34
  119. package/src/core/policies/service/index.ts +6 -6
  120. package/src/core/policies/service/policy-evaluation-error.ts +141 -133
  121. package/src/core/policies/service/policy-service.ts +432 -419
  122. package/src/core/policies/utils/date.ts +3 -3
  123. package/src/core/policies/utils/hash.ts +61 -61
  124. package/src/core/result/outcome.ts +131 -126
  125. package/src/core/result/result.ts +130 -127
  126. package/src/core/shared/aggregate-version.ts +5 -5
  127. package/src/core/shared/hashing.ts +18 -18
  128. package/src/core/shared/immutable.ts +29 -29
  129. package/src/core/shared/temporal-guards.ts +9 -9
  130. package/src/core/versioning/domain-event-contracts.ts +40 -40
  131. package/src/core/versioning/version.ts +19 -19
  132. package/src/examples/rulesets/entity/order-creation-rules-v1.ts +18 -18
  133. package/src/examples/rulesets/entity/order-invariants-v1.ts +31 -29
  134. package/src/examples/rulesets/entity/order-invariants-v2.ts +12 -12
  135. package/src/examples/rulesets/entity/order.ts +127 -127
  136. package/src/examples/rulesets/value-object/cpf-rules-v1.ts +41 -39
  137. package/src/examples/rulesets/value-object/cpf-rules-v2.ts +14 -12
  138. package/src/examples/rulesets/value-object/cpf.ts +24 -24
  139. package/src/examples/rulesets/value-object/customer.ts +42 -39
  140. package/src/examples/rulesets/value-object/person-name-rules-v1.ts +27 -27
  141. package/src/examples/rulesets/value-object/person-name-rules-v2.ts +13 -13
  142. package/src/examples/rulesets/value-object/person-name.ts +29 -26
  143. package/src/index.ts +2 -2
  144. package/src/version.ts +1 -1
@@ -6,63 +6,63 @@ import { isValidDate } from "../../shared/temporal-guards";
6
6
  const DEFAULT_MAX_AS_OF_FUTURE_YEARS = 10;
7
7
 
8
8
  export interface DeriveAsOfOptions {
9
- readonly maxFutureYears?: number;
9
+ readonly maxFutureYears?: number;
10
10
  }
11
11
 
12
12
  export class PolicyAsOfResolver {
13
- private static resolveMaxFutureYears(
14
- options: DeriveAsOfOptions,
15
- ): Result<number, string> {
16
- const maxFutureYears =
17
- options.maxFutureYears ?? DEFAULT_MAX_AS_OF_FUTURE_YEARS;
13
+ private static resolveMaxFutureYears(
14
+ options: DeriveAsOfOptions,
15
+ ): Result<number, string> {
16
+ const maxFutureYears =
17
+ options.maxFutureYears ?? DEFAULT_MAX_AS_OF_FUTURE_YEARS;
18
18
 
19
- if (!Number.isInteger(maxFutureYears) || maxFutureYears < 0) {
20
- return Result.err(
21
- `deriveAsOf maxFutureYears must be a non-negative integer. Received: ${maxFutureYears}`,
22
- );
23
- }
24
-
25
- return Result.ok(maxFutureYears);
26
- }
19
+ if (!Number.isInteger(maxFutureYears) || maxFutureYears < 0) {
20
+ return Result.err(
21
+ `deriveAsOf maxFutureYears must be a non-negative integer. Received: ${maxFutureYears}`,
22
+ );
23
+ }
27
24
 
28
- static derive(
29
- source: AsOfSource,
30
- seed: ContextSeed,
31
- now: Date,
32
- options: DeriveAsOfOptions = {},
33
- ): Result<Date, string> {
34
- const maxFutureYearsResult =
35
- PolicyAsOfResolver.resolveMaxFutureYears(options);
36
- if (maxFutureYearsResult.isErr()) {
37
- return Result.err(maxFutureYearsResult.errorOrNull()!);
25
+ return Result.ok(maxFutureYears);
38
26
  }
39
- const maxFutureYears = maxFutureYearsResult.getOrNull()!;
40
-
41
- switch (source) {
42
- case "NOW":
43
- return Result.ok(now);
44
27
 
45
- case "CALLER_PROVIDED": {
46
- const asOf = seed.fields["asOf"];
47
- if (!isValidDate(asOf)) {
48
- return Result.err(
49
- 'asOfSource "CALLER_PROVIDED" requires seed.fields.asOf to be a Date',
50
- );
28
+ static derive(
29
+ source: AsOfSource,
30
+ seed: ContextSeed,
31
+ now: Date,
32
+ options: DeriveAsOfOptions = {},
33
+ ): Result<Date, string> {
34
+ const maxFutureYearsResult =
35
+ PolicyAsOfResolver.resolveMaxFutureYears(options);
36
+ if (maxFutureYearsResult.isErr()) {
37
+ return Result.err(maxFutureYearsResult.errorOrNull()!);
51
38
  }
39
+ const maxFutureYears = maxFutureYearsResult.getOrNull()!;
52
40
 
53
- const maxFuture = new Date(now);
54
- maxFuture.setFullYear(maxFuture.getFullYear() + maxFutureYears);
55
- if (asOf > maxFuture) {
56
- return Result.err(
57
- `asOf date is more than ${maxFutureYears} years in the future (received ${asOf.toISOString()})`,
58
- );
59
- }
41
+ switch (source) {
42
+ case "NOW":
43
+ return Result.ok(now);
44
+
45
+ case "CALLER_PROVIDED": {
46
+ const asOf = seed.fields["asOf"];
47
+ if (!isValidDate(asOf)) {
48
+ return Result.err(
49
+ 'asOfSource "CALLER_PROVIDED" requires seed.fields.asOf to be a Date',
50
+ );
51
+ }
60
52
 
61
- return Result.ok(asOf);
62
- }
53
+ const maxFuture = new Date(now);
54
+ maxFuture.setFullYear(maxFuture.getFullYear() + maxFutureYears);
55
+ if (asOf > maxFuture) {
56
+ return Result.err(
57
+ `asOf date is more than ${maxFutureYears} years in the future (received ${asOf.toISOString()})`,
58
+ );
59
+ }
63
60
 
64
- default:
65
- return Result.err(`Unknown asOfSource: "${source}"`);
61
+ return Result.ok(asOf);
62
+ }
63
+
64
+ default:
65
+ return Result.err(`Unknown asOfSource: "${source}"`);
66
+ }
66
67
  }
67
- }
68
68
  }
@@ -11,11 +11,13 @@ import { PolicyCatalogEntry } from "./policy-catalog-entry";
11
11
  * are responsible for passing all relevant packages at composition time.
12
12
  */
13
13
  export class PolicyCatalogFactory {
14
- static build(packages: readonly PolicyPackage[]): PolicyCatalog {
15
- const entries = packages.flatMap((policyPackage) =>
16
- Array.from(policyPackage.catalogEntries).map(PolicyCatalogEntry.from),
17
- );
14
+ static build(packages: readonly PolicyPackage[]): PolicyCatalog {
15
+ const entries = packages.flatMap((policyPackage) =>
16
+ Array.from(policyPackage.catalogEntries).map(
17
+ PolicyCatalogEntry.from,
18
+ ),
19
+ );
18
20
 
19
- return new PolicyCatalog(entries);
20
- }
21
+ return new PolicyCatalog(entries);
22
+ }
21
23
  }
@@ -1,8 +1,8 @@
1
1
  export type {
2
- AsOfSource,
3
- PolicyKind,
4
- PolicyOwner,
5
- PolicyScopeLevel,
2
+ AsOfSource,
3
+ PolicyKind,
4
+ PolicyOwner,
5
+ PolicyScopeLevel,
6
6
  } from "./catalog-types";
7
7
  export type { PolicyCatalogEntryProps } from "./policy-catalog-entry";
8
8
  export { PolicyCatalogEntry } from "./policy-catalog-entry";
@@ -1,10 +1,10 @@
1
1
  import { UnexpectedError } from "../../errors";
2
2
 
3
3
  import type {
4
- AsOfSource,
5
- PolicyKind,
6
- PolicyOwner,
7
- PolicyScopeLevel,
4
+ AsOfSource,
5
+ PolicyKind,
6
+ PolicyOwner,
7
+ PolicyScopeLevel,
8
8
  } from "./catalog-types";
9
9
  import type { PolicyKey } from "./policy-key";
10
10
 
@@ -12,18 +12,18 @@ import type { PolicyKey } from "./policy-key";
12
12
  * Properties for creating a PolicyCatalogEntry.
13
13
  */
14
14
  export interface PolicyCatalogEntryProps {
15
- readonly key: PolicyKey;
16
- readonly kind: PolicyKind;
17
- readonly gateEngineVersion?: number;
18
- readonly computeEngineVersion?: number;
19
- readonly payloadSchemaVersion?: number;
20
- readonly owner: PolicyOwner;
21
- readonly allowedScopes: readonly PolicyScopeLevel[];
22
- readonly asOfSource: AsOfSource;
23
- /** Paths the context must contain for this policy to be evaluable. */
24
- readonly contextRequirements: readonly string[];
25
- readonly tags?: readonly string[];
26
- readonly description: string;
15
+ readonly key: PolicyKey;
16
+ readonly kind: PolicyKind;
17
+ readonly gateEngineVersion?: number;
18
+ readonly computeEngineVersion?: number;
19
+ readonly payloadSchemaVersion?: number;
20
+ readonly owner: PolicyOwner;
21
+ readonly allowedScopes: readonly PolicyScopeLevel[];
22
+ readonly asOfSource: AsOfSource;
23
+ /** Paths the context must contain for this policy to be evaluable. */
24
+ readonly contextRequirements: readonly string[];
25
+ readonly tags?: readonly string[];
26
+ readonly description: string;
27
27
  }
28
28
 
29
29
  /**
@@ -31,190 +31,192 @@ export interface PolicyCatalogEntryProps {
31
31
  * Encapsulates metadata and validation logic for a policy.
32
32
  */
33
33
  export class PolicyCatalogEntry {
34
- public readonly key: PolicyKey;
35
- public readonly kind: PolicyKind;
36
-
37
- public readonly gateEngineVersion?: number;
38
- public readonly computeEngineVersion?: number;
39
- public readonly payloadSchemaVersion?: number;
40
-
41
- public readonly owner: PolicyOwner;
42
- public readonly allowedScopes: readonly PolicyScopeLevel[];
43
- public readonly asOfSource: AsOfSource;
44
- public readonly contextRequirements: readonly string[];
45
- public readonly tags: readonly string[];
46
- public readonly description: string;
47
-
48
- constructor(props: PolicyCatalogEntryProps) {
49
- this.key = props.key;
50
- this.kind = props.kind;
51
- this.gateEngineVersion = props.gateEngineVersion;
52
- this.computeEngineVersion = props.computeEngineVersion;
53
- this.payloadSchemaVersion = props.payloadSchemaVersion;
54
- this.owner = props.owner;
55
- this.allowedScopes = [...props.allowedScopes];
56
- this.asOfSource = props.asOfSource;
57
- this.contextRequirements = [...props.contextRequirements];
58
- this.tags = [...(props.tags ?? [])];
59
- this.description = props.description;
60
- }
61
-
62
- static assertFamilyConsistency(entries: readonly PolicyCatalogEntry[]): void {
63
- if (entries.length === 0) {
64
- throw new UnexpectedError(
65
- "Cannot validate an empty PolicyCatalogEntry family",
66
- );
67
- }
68
-
69
- const [first, ...rest] = entries;
70
- for (const entry of rest) {
71
- if (!first.key.equals(entry.key)) {
72
- throw new UnexpectedError(
73
- "Cannot merge PolicyCatalog entries with different keys",
74
- );
75
- }
34
+ public readonly key: PolicyKey;
35
+ public readonly kind: PolicyKind;
36
+
37
+ public readonly gateEngineVersion?: number;
38
+ public readonly computeEngineVersion?: number;
39
+ public readonly payloadSchemaVersion?: number;
40
+
41
+ public readonly owner: PolicyOwner;
42
+ public readonly allowedScopes: readonly PolicyScopeLevel[];
43
+ public readonly asOfSource: AsOfSource;
44
+ public readonly contextRequirements: readonly string[];
45
+ public readonly tags: readonly string[];
46
+ public readonly description: string;
47
+
48
+ constructor(props: PolicyCatalogEntryProps) {
49
+ this.key = props.key;
50
+ this.kind = props.kind;
51
+ this.gateEngineVersion = props.gateEngineVersion;
52
+ this.computeEngineVersion = props.computeEngineVersion;
53
+ this.payloadSchemaVersion = props.payloadSchemaVersion;
54
+ this.owner = props.owner;
55
+ this.allowedScopes = [...props.allowedScopes];
56
+ this.asOfSource = props.asOfSource;
57
+ this.contextRequirements = [...props.contextRequirements];
58
+ this.tags = [...(props.tags ?? [])];
59
+ this.description = props.description;
60
+ }
76
61
 
77
- if (first.kind !== entry.kind) {
78
- throw new UnexpectedError(
79
- `PolicyCatalog entries for key "${first.key.toString()}" must share the same kind`,
80
- );
81
- }
62
+ static assertFamilyConsistency(
63
+ entries: readonly PolicyCatalogEntry[],
64
+ ): void {
65
+ if (entries.length === 0) {
66
+ throw new UnexpectedError(
67
+ "Cannot validate an empty PolicyCatalogEntry family",
68
+ );
69
+ }
70
+
71
+ const [first, ...rest] = entries;
72
+ for (const entry of rest) {
73
+ if (!first.key.equals(entry.key)) {
74
+ throw new UnexpectedError(
75
+ "Cannot merge PolicyCatalog entries with different keys",
76
+ );
77
+ }
78
+
79
+ if (first.kind !== entry.kind) {
80
+ throw new UnexpectedError(
81
+ `PolicyCatalog entries for key "${first.key.toString()}" must share the same kind`,
82
+ );
83
+ }
84
+
85
+ if (first.owner !== entry.owner) {
86
+ throw new UnexpectedError(
87
+ `PolicyCatalog entries for key "${first.key.toString()}" must share the same owner`,
88
+ );
89
+ }
90
+
91
+ if (first.asOfSource !== entry.asOfSource) {
92
+ throw new UnexpectedError(
93
+ `PolicyCatalog entries for key "${first.key.toString()}" must share the same asOfSource`,
94
+ );
95
+ }
96
+
97
+ if (first.description !== entry.description) {
98
+ throw new UnexpectedError(
99
+ `PolicyCatalog entries for key "${first.key.toString()}" must share the same description`,
100
+ );
101
+ }
102
+ }
103
+ }
82
104
 
83
- if (first.owner !== entry.owner) {
84
- throw new UnexpectedError(
85
- `PolicyCatalog entries for key "${first.key.toString()}" must share the same owner`,
86
- );
87
- }
105
+ static from(
106
+ entry: PolicyCatalogEntry | PolicyCatalogEntryProps,
107
+ ): PolicyCatalogEntry {
108
+ return entry instanceof PolicyCatalogEntry
109
+ ? entry
110
+ : new PolicyCatalogEntry(entry);
111
+ }
88
112
 
89
- if (first.asOfSource !== entry.asOfSource) {
90
- throw new UnexpectedError(
91
- `PolicyCatalog entries for key "${first.key.toString()}" must share the same asOfSource`,
92
- );
93
- }
113
+ isGate(): boolean {
114
+ return this.kind === "GATE";
115
+ }
116
+
117
+ isCompute(): boolean {
118
+ return this.kind === "COMPUTE";
119
+ }
120
+
121
+ allowsScope(scope: PolicyScopeLevel): boolean {
122
+ return this.allowedScopes.includes(scope);
123
+ }
94
124
 
95
- if (first.description !== entry.description) {
96
- throw new UnexpectedError(
97
- `PolicyCatalog entries for key "${first.key.toString()}" must share the same description`,
125
+ hasExplicitVersionSelector(): boolean {
126
+ return (
127
+ this.gateEngineVersion !== undefined ||
128
+ this.computeEngineVersion !== undefined ||
129
+ this.payloadSchemaVersion !== undefined
98
130
  );
99
- }
100
- }
101
- }
102
-
103
- static from(
104
- entry: PolicyCatalogEntry | PolicyCatalogEntryProps,
105
- ): PolicyCatalogEntry {
106
- return entry instanceof PolicyCatalogEntry
107
- ? entry
108
- : new PolicyCatalogEntry(entry);
109
- }
110
-
111
- isGate(): boolean {
112
- return this.kind === "GATE";
113
- }
114
-
115
- isCompute(): boolean {
116
- return this.kind === "COMPUTE";
117
- }
118
-
119
- allowsScope(scope: PolicyScopeLevel): boolean {
120
- return this.allowedScopes.includes(scope);
121
- }
122
-
123
- hasExplicitVersionSelector(): boolean {
124
- return (
125
- this.gateEngineVersion !== undefined ||
126
- this.computeEngineVersion !== undefined ||
127
- this.payloadSchemaVersion !== undefined
128
- );
129
- }
130
-
131
- matchesVersion(params: {
132
- readonly kind: PolicyKind;
133
- readonly gateEngineVersion?: number;
134
- readonly computeEngineVersion?: number;
135
- readonly payloadSchemaVersion?: number;
136
- }): boolean {
137
- if (this.kind !== params.kind) {
138
- return false;
139
- }
140
-
141
- if (
142
- this.gateEngineVersion !== undefined &&
143
- this.gateEngineVersion !== params.gateEngineVersion
144
- ) {
145
- return false;
146
- }
147
-
148
- if (
149
- this.computeEngineVersion !== undefined &&
150
- this.computeEngineVersion !== params.computeEngineVersion
151
- ) {
152
- return false;
153
- }
154
-
155
- if (
156
- this.payloadSchemaVersion !== undefined &&
157
- this.payloadSchemaVersion !== params.payloadSchemaVersion
158
- ) {
159
- return false;
160
- }
161
-
162
- return true;
163
- }
164
-
165
- toVariantKey(): string {
166
- return [
167
- this.key.toString(),
168
- this.kind,
169
- this.gateEngineVersion ?? "gate:any",
170
- this.computeEngineVersion ?? "compute:any",
171
- this.payloadSchemaVersion ?? "schema:any",
172
- ].join("::");
173
- }
174
-
175
- usesNowAsOf(): boolean {
176
- return this.asOfSource === "NOW";
177
- }
178
-
179
- usesCallerProvidedAsOf(): boolean {
180
- return this.asOfSource === "CALLER_PROVIDED";
181
- }
182
-
183
- requiresContext(path: string): boolean {
184
- return this.contextRequirements.includes(path);
185
- }
186
-
187
- requiresAllContexts(paths: readonly string[]): boolean {
188
- return paths.every((path) => this.requiresContext(path));
189
- }
190
-
191
- hasTag(tag: string): boolean {
192
- return this.tags.includes(tag);
193
- }
194
-
195
- equals(other: PolicyCatalogEntry): boolean {
196
- return this.key.equals(other.key);
197
- }
198
-
199
- toJSON(): PolicyCatalogEntryProps {
200
- return {
201
- key: this.key,
202
- kind: this.kind,
203
- ...(this.gateEngineVersion !== undefined
204
- ? { gateEngineVersion: this.gateEngineVersion }
205
- : {}),
206
- ...(this.computeEngineVersion !== undefined
207
- ? { computeEngineVersion: this.computeEngineVersion }
208
- : {}),
209
- ...(this.payloadSchemaVersion !== undefined
210
- ? { payloadSchemaVersion: this.payloadSchemaVersion }
211
- : {}),
212
- owner: this.owner,
213
- allowedScopes: [...this.allowedScopes],
214
- asOfSource: this.asOfSource,
215
- contextRequirements: [...this.contextRequirements],
216
- tags: this.tags.length > 0 ? [...this.tags] : undefined,
217
- description: this.description,
218
- };
219
- }
131
+ }
132
+
133
+ matchesVersion(params: {
134
+ readonly kind: PolicyKind;
135
+ readonly gateEngineVersion?: number;
136
+ readonly computeEngineVersion?: number;
137
+ readonly payloadSchemaVersion?: number;
138
+ }): boolean {
139
+ if (this.kind !== params.kind) {
140
+ return false;
141
+ }
142
+
143
+ if (
144
+ this.gateEngineVersion !== undefined &&
145
+ this.gateEngineVersion !== params.gateEngineVersion
146
+ ) {
147
+ return false;
148
+ }
149
+
150
+ if (
151
+ this.computeEngineVersion !== undefined &&
152
+ this.computeEngineVersion !== params.computeEngineVersion
153
+ ) {
154
+ return false;
155
+ }
156
+
157
+ if (
158
+ this.payloadSchemaVersion !== undefined &&
159
+ this.payloadSchemaVersion !== params.payloadSchemaVersion
160
+ ) {
161
+ return false;
162
+ }
163
+
164
+ return true;
165
+ }
166
+
167
+ toVariantKey(): string {
168
+ return [
169
+ this.key.toString(),
170
+ this.kind,
171
+ this.gateEngineVersion ?? "gate:any",
172
+ this.computeEngineVersion ?? "compute:any",
173
+ this.payloadSchemaVersion ?? "schema:any",
174
+ ].join("::");
175
+ }
176
+
177
+ usesNowAsOf(): boolean {
178
+ return this.asOfSource === "NOW";
179
+ }
180
+
181
+ usesCallerProvidedAsOf(): boolean {
182
+ return this.asOfSource === "CALLER_PROVIDED";
183
+ }
184
+
185
+ requiresContext(path: string): boolean {
186
+ return this.contextRequirements.includes(path);
187
+ }
188
+
189
+ requiresAllContexts(paths: readonly string[]): boolean {
190
+ return paths.every((path) => this.requiresContext(path));
191
+ }
192
+
193
+ hasTag(tag: string): boolean {
194
+ return this.tags.includes(tag);
195
+ }
196
+
197
+ equals(other: PolicyCatalogEntry): boolean {
198
+ return this.key.equals(other.key);
199
+ }
200
+
201
+ toJSON(): PolicyCatalogEntryProps {
202
+ return {
203
+ key: this.key,
204
+ kind: this.kind,
205
+ ...(this.gateEngineVersion !== undefined
206
+ ? { gateEngineVersion: this.gateEngineVersion }
207
+ : {}),
208
+ ...(this.computeEngineVersion !== undefined
209
+ ? { computeEngineVersion: this.computeEngineVersion }
210
+ : {}),
211
+ ...(this.payloadSchemaVersion !== undefined
212
+ ? { payloadSchemaVersion: this.payloadSchemaVersion }
213
+ : {}),
214
+ owner: this.owner,
215
+ allowedScopes: [...this.allowedScopes],
216
+ asOfSource: this.asOfSource,
217
+ contextRequirements: [...this.contextRequirements],
218
+ tags: this.tags.length > 0 ? [...this.tags] : undefined,
219
+ description: this.description,
220
+ };
221
+ }
220
222
  }