@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.
- package/README.md +24 -24
- package/dist/gate-engine-registry.js.map +1 -1
- 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.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 -62
- 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 +547 -505
- 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
|
@@ -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
|
-
|
|
9
|
+
readonly maxFutureYears?: number;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class PolicyAsOfResolver {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
+
return new PolicyCatalog(entries);
|
|
22
|
+
}
|
|
21
23
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
125
|
+
hasExplicitVersionSelector(): boolean {
|
|
126
|
+
return (
|
|
127
|
+
this.gateEngineVersion !== undefined ||
|
|
128
|
+
this.computeEngineVersion !== undefined ||
|
|
129
|
+
this.payloadSchemaVersion !== undefined
|
|
98
130
|
);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
}
|