@telorun/analyzer 0.62.1 → 0.64.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/dist/analysis-registry.d.ts +24 -0
- package/dist/analysis-registry.d.ts.map +1 -1
- package/dist/analysis-registry.js +41 -0
- package/dist/analyzer.d.ts +3 -37
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +396 -476
- package/dist/call-graph.d.ts.map +1 -1
- package/dist/call-graph.js +2 -7
- package/dist/cel-scope-query.d.ts +109 -0
- package/dist/cel-scope-query.d.ts.map +1 -0
- package/dist/cel-scope-query.js +270 -0
- package/dist/cel-scope.d.ts +166 -0
- package/dist/cel-scope.d.ts.map +1 -0
- package/dist/cel-scope.js +377 -0
- package/dist/definition-registry.d.ts +15 -0
- package/dist/definition-registry.d.ts.map +1 -1
- package/dist/definition-registry.js +25 -9
- package/dist/find-manifest.d.ts +10 -0
- package/dist/find-manifest.d.ts.map +1 -0
- package/dist/find-manifest.js +12 -0
- package/dist/flatten-for-analyzer.js +1 -1
- package/dist/import-resolution-diagnostics.d.ts +9 -2
- package/dist/import-resolution-diagnostics.d.ts.map +1 -1
- package/dist/import-resolution-diagnostics.js +26 -7
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -1
- package/dist/invocation-contract.d.ts +17 -1
- package/dist/invocation-contract.d.ts.map +1 -1
- package/dist/invocation-contract.js +42 -4
- package/dist/loaded-types.d.ts +12 -3
- package/dist/loaded-types.d.ts.map +1 -1
- package/dist/manifest-analysis.d.ts +73 -0
- package/dist/manifest-analysis.d.ts.map +1 -0
- package/dist/manifest-analysis.js +78 -0
- package/dist/manifest-loader.d.ts +0 -1
- package/dist/manifest-loader.d.ts.map +1 -1
- package/dist/manifest-loader.js +62 -41
- package/dist/manifest-path.d.ts +18 -0
- package/dist/manifest-path.d.ts.map +1 -0
- package/dist/manifest-path.js +37 -0
- package/dist/manifest-schemas.d.ts +699 -0
- package/dist/manifest-schemas.d.ts.map +1 -1
- package/dist/manifest-schemas.js +306 -14
- package/dist/module-compatibility.d.ts +40 -0
- package/dist/module-compatibility.d.ts.map +1 -0
- package/dist/module-compatibility.js +52 -0
- package/dist/ref-slot-reading.d.ts +30 -0
- package/dist/ref-slot-reading.d.ts.map +1 -0
- package/dist/ref-slot-reading.js +139 -0
- package/dist/referrer-rule.d.ts +67 -0
- package/dist/referrer-rule.d.ts.map +1 -0
- package/dist/referrer-rule.js +96 -0
- package/dist/release/index.d.ts +1 -1
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +1 -1
- package/dist/release/version-stamp.d.ts +16 -0
- package/dist/release/version-stamp.d.ts.map +1 -1
- package/dist/release/version-stamp.js +52 -0
- package/dist/release/workspace-config.d.ts +10 -6
- package/dist/release/workspace-config.d.ts.map +1 -1
- package/dist/release/workspace-config.js +10 -6
- package/dist/resolve-schema-ref-kinds.d.ts +4 -3
- package/dist/resolve-schema-ref-kinds.d.ts.map +1 -1
- package/dist/resolve-schema-ref-kinds.js +16 -0
- package/dist/resolve-throws-union.d.ts.map +1 -1
- package/dist/resolve-throws-union.js +4 -3
- package/dist/resolve-zone-containment.d.ts +99 -0
- package/dist/resolve-zone-containment.d.ts.map +1 -0
- package/dist/resolve-zone-containment.js +212 -0
- package/dist/resolve-zone-requirements.d.ts +5 -0
- package/dist/resolve-zone-requirements.d.ts.map +1 -1
- package/dist/resolve-zone-requirements.js +48 -7
- package/dist/resource-rule.d.ts +106 -0
- package/dist/resource-rule.d.ts.map +1 -0
- package/dist/resource-rule.js +236 -0
- package/dist/rule-condition.d.ts +50 -0
- package/dist/rule-condition.d.ts.map +1 -0
- package/dist/rule-condition.js +108 -0
- package/dist/schema-keywords.d.ts.map +1 -1
- package/dist/schema-keywords.js +20 -0
- package/dist/schema-projection.d.ts +171 -0
- package/dist/schema-projection.d.ts.map +1 -0
- package/dist/schema-projection.js +317 -0
- package/dist/schema-walk.d.ts +25 -0
- package/dist/schema-walk.d.ts.map +1 -0
- package/dist/schema-walk.js +126 -0
- package/dist/step-slot.d.ts +39 -0
- package/dist/step-slot.d.ts.map +1 -0
- package/dist/step-slot.js +49 -0
- package/dist/telo-version.d.ts +1 -1
- package/dist/telo-version.js +1 -1
- package/dist/validate-cel-context.d.ts.map +1 -1
- package/dist/validate-cel-context.js +17 -3
- package/dist/validate-durable-regions.d.ts +15 -0
- package/dist/validate-durable-regions.d.ts.map +1 -0
- package/dist/validate-durable-regions.js +336 -0
- package/dist/validate-references.d.ts.map +1 -1
- package/dist/validate-references.js +44 -2
- package/dist/validate-referrer-rules.d.ts +120 -0
- package/dist/validate-referrer-rules.d.ts.map +1 -0
- package/dist/validate-referrer-rules.js +255 -0
- package/dist/validate-resource-rules.d.ts +114 -0
- package/dist/validate-resource-rules.d.ts.map +1 -0
- package/dist/validate-resource-rules.js +283 -0
- package/dist/validate-schema-projection.d.ts +32 -0
- package/dist/validate-schema-projection.d.ts.map +1 -0
- package/dist/validate-schema-projection.js +110 -0
- package/dist/validate-step-inputs.d.ts +19 -1
- package/dist/validate-step-inputs.d.ts.map +1 -1
- package/dist/validate-step-inputs.js +102 -9
- package/dist/validate-throws-coverage.d.ts.map +1 -1
- package/dist/validate-throws-coverage.js +11 -5
- package/dist/validate-zone-slots.d.ts +2 -2
- package/dist/validate-zone-slots.d.ts.map +1 -1
- package/dist/validate-zone-slots.js +202 -6
- package/dist/validate-zone-violations.d.ts +12 -0
- package/dist/validate-zone-violations.d.ts.map +1 -0
- package/dist/validate-zone-violations.js +169 -0
- package/dist/value-type-keyword.d.ts +1 -1
- package/dist/value-type-keyword.d.ts.map +1 -1
- package/dist/value-type-keyword.js +4 -0
- package/dist/zone-slot.d.ts +61 -0
- package/dist/zone-slot.d.ts.map +1 -1
- package/dist/zone-slot.js +86 -5
- package/package.json +2 -2
- package/src/analysis-registry.ts +43 -0
- package/src/analyzer.ts +452 -595
- package/src/call-graph.ts +2 -8
- package/src/cel-scope-query.ts +337 -0
- package/src/cel-scope.ts +570 -0
- package/src/definition-registry.ts +31 -13
- package/src/find-manifest.ts +19 -0
- package/src/flatten-for-analyzer.ts +1 -1
- package/src/import-resolution-diagnostics.ts +25 -7
- package/src/index.ts +86 -0
- package/src/invocation-contract.ts +67 -2
- package/src/loaded-types.ts +12 -3
- package/src/manifest-analysis.ts +132 -0
- package/src/manifest-loader.ts +87 -55
- package/src/manifest-path.ts +34 -0
- package/src/manifest-schemas.ts +328 -14
- package/src/module-compatibility.ts +72 -0
- package/src/ref-slot-reading.ts +156 -0
- package/src/referrer-rule.ts +116 -0
- package/src/release/index.ts +1 -0
- package/src/release/version-stamp.ts +58 -0
- package/src/release/workspace-config.ts +10 -6
- package/src/resolve-schema-ref-kinds.ts +28 -4
- package/src/resolve-throws-union.ts +4 -3
- package/src/resolve-zone-containment.ts +329 -0
- package/src/resolve-zone-requirements.ts +67 -7
- package/src/resource-rule.ts +252 -0
- package/src/rule-condition.ts +126 -0
- package/src/schema-keywords.ts +24 -0
- package/src/schema-projection.ts +403 -0
- package/src/schema-walk.ts +144 -0
- package/src/step-slot.ts +64 -0
- package/src/telo-version.ts +1 -1
- package/src/validate-cel-context.ts +17 -3
- package/src/validate-durable-regions.ts +401 -0
- package/src/validate-references.ts +57 -2
- package/src/validate-referrer-rules.ts +373 -0
- package/src/validate-resource-rules.ts +401 -0
- package/src/validate-schema-projection.ts +184 -0
- package/src/validate-step-inputs.ts +148 -10
- package/src/validate-throws-coverage.ts +12 -5
- package/src/validate-zone-slots.ts +192 -8
- package/src/validate-zone-violations.ts +190 -0
- package/src/value-type-keyword.ts +4 -0
- package/src/zone-slot.ts +114 -5
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ZONE_ATTRIBUTE_VIOLATED` — a resource inside a region whose guarantee it
|
|
3
|
+
* declares it cannot honour.
|
|
4
|
+
*
|
|
5
|
+
* The third leg of the zone-attribute mechanism, and the one that makes the
|
|
6
|
+
* other two enforceable. `x-telo-provides-zone` says what a region guarantees
|
|
7
|
+
* about its contents and `x-telo-requires-zone` says what a resource needs of
|
|
8
|
+
* the region around it — but neither says *this resource breaks that
|
|
9
|
+
* guarantee*, so until now an attribute could be declared, resolved and read
|
|
10
|
+
* with nothing able to report the one thing it exists to prevent.
|
|
11
|
+
*
|
|
12
|
+
* **Generic over the whole vocabulary, and it names no kind.** The rule is one
|
|
13
|
+
* sentence — *a region declaring attribute A must not contain a resource
|
|
14
|
+
* declaring it violates A* — and it is run once per attribute in
|
|
15
|
+
* `sdk/zone-attributes/`. So `noSuspend` (a parking kind inside a lease) and any
|
|
16
|
+
* attribute added later are covered by the same traversal, and `modules/durable`
|
|
17
|
+
* stays outside the analyzer's surface exactly as the topology-driven constraint
|
|
18
|
+
* requires.
|
|
19
|
+
*
|
|
20
|
+
* **Both sentences are their authors' own.** The diagnostic prints the region's
|
|
21
|
+
* declared reason and the violating kind's declared reason side by side, because
|
|
22
|
+
* the useful message is the collision between two written claims — "this
|
|
23
|
+
* transaction holds a connection a parked run would lose" against "this waits
|
|
24
|
+
* for a delivery that may be days away" — and neither half is anything the
|
|
25
|
+
* analyzer could generate.
|
|
26
|
+
*
|
|
27
|
+
* **Enforced at runtime, warned early**, like every other containment rule: the
|
|
28
|
+
* walk under-approximates (an edge the call graph cannot see is invisible here),
|
|
29
|
+
* and the runtime check in the violating controller is the real enforcement. It
|
|
30
|
+
* is an ERROR rather than a warning nonetheless: where the walk *can* see the
|
|
31
|
+
* path, the placement is decidably wrong — the region's promise and the
|
|
32
|
+
* resource's rebuttal are both declarations, so nothing about the runtime can
|
|
33
|
+
* reconcile them.
|
|
34
|
+
*
|
|
35
|
+
* Browser-safe: no Node built-ins.
|
|
36
|
+
*/
|
|
37
|
+
import {
|
|
38
|
+
SUSPENDING_BACKOFF_MS,
|
|
39
|
+
ZONE_ATTRIBUTES,
|
|
40
|
+
retryBackoffMs,
|
|
41
|
+
type ResourceManifest,
|
|
42
|
+
} from "@telorun/sdk";
|
|
43
|
+
import type { CallGraph } from "./call-graph.js";
|
|
44
|
+
import { findZoneRegions, type DefinitionLookup } from "./resolve-zone-containment.js";
|
|
45
|
+
import { DiagnosticSeverity, type AnalysisDiagnostic } from "./types.js";
|
|
46
|
+
import { readViolatesZone } from "./zone-slot.js";
|
|
47
|
+
|
|
48
|
+
const SOURCE = "telo";
|
|
49
|
+
|
|
50
|
+
export interface ZoneViolationArgs {
|
|
51
|
+
graph: CallGraph;
|
|
52
|
+
resolveDef: DefinitionLookup;
|
|
53
|
+
/** Only report against modules the entry owns — a published dependency's
|
|
54
|
+
* placement is not the consumer's to fix. */
|
|
55
|
+
reportModules: ReadonlySet<string>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function validateZoneViolations(args: ZoneViolationArgs): AnalysisDiagnostic[] {
|
|
59
|
+
const { graph, resolveDef, reportModules } = args;
|
|
60
|
+
const diagnostics: AnalysisDiagnostic[] = [];
|
|
61
|
+
const reported = new Set<string>();
|
|
62
|
+
|
|
63
|
+
// What each kind in the graph declares it cannot honour, resolved once. A
|
|
64
|
+
// graph holds many instances of few kinds, and this is a schema read.
|
|
65
|
+
const violationsOf = new Map<string, Record<string, string>>();
|
|
66
|
+
const violations = (kind: string, module?: string): Record<string, string> => {
|
|
67
|
+
const key = `${module ?? ""}\0${kind}`;
|
|
68
|
+
let found = violationsOf.get(key);
|
|
69
|
+
if (!found) {
|
|
70
|
+
const def = resolveDef(kind, module);
|
|
71
|
+
found = readViolatesZone(def?.schema as Record<string, any> | undefined);
|
|
72
|
+
violationsOf.set(key, found);
|
|
73
|
+
}
|
|
74
|
+
return found;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
for (const attribute of ZONE_ATTRIBUTES.keys()) {
|
|
78
|
+
for (const region of findZoneRegions(graph, resolveDef, attribute)) {
|
|
79
|
+
for (const contained of region.contents.values()) {
|
|
80
|
+
// The one step-level rule, and it is separate because it is a property
|
|
81
|
+
// of the STEP rather than of its target: a retry whose backoff is long
|
|
82
|
+
// enough to park suspends the run from inside a region that promised
|
|
83
|
+
// nothing in it would. Only `noSuspend` has such a rule, because only
|
|
84
|
+
// `noSuspend` is broken by waiting.
|
|
85
|
+
if (attribute === "noSuspend" && contained.node.type === "step") {
|
|
86
|
+
const ownerNode = graph.nodes.get(contained.node.owner);
|
|
87
|
+
const owner = ownerNode?.type === "resource" ? ownerNode : undefined;
|
|
88
|
+
if (
|
|
89
|
+
owner &&
|
|
90
|
+
owned(owner.manifest, reportModules) &&
|
|
91
|
+
suspendingBackoff(contained.node.step.retry)
|
|
92
|
+
) {
|
|
93
|
+
const dedupe = `retry\0${contained.node.id}`;
|
|
94
|
+
if (!reported.has(dedupe)) {
|
|
95
|
+
reported.add(dedupe);
|
|
96
|
+
diagnostics.push({
|
|
97
|
+
severity: DiagnosticSeverity.Error,
|
|
98
|
+
code: "ZONE_ATTRIBUTE_VIOLATED",
|
|
99
|
+
source: SOURCE,
|
|
100
|
+
message:
|
|
101
|
+
`Step '${contained.node.name ?? contained.node.path}' declares a retry ` +
|
|
102
|
+
`whose last backoff reaches ${SUSPENDING_BACKOFF_MS}ms, at which point a ` +
|
|
103
|
+
`re-attempt waits by PARKING the run rather than by sleeping — but it is ` +
|
|
104
|
+
`inside a ${region.provider.kind} ` +
|
|
105
|
+
`'${region.provider.name}' region that declares 'noSuspend' ` +
|
|
106
|
+
`(${region.reason}). Shorten the backoff, or move the retry outside the ` +
|
|
107
|
+
`region so it re-attempts the region as a whole.`,
|
|
108
|
+
data: {
|
|
109
|
+
resource: { kind: owner.kind, name: owner.name },
|
|
110
|
+
filePath: (owner.manifest.metadata as { source?: string } | undefined)?.source,
|
|
111
|
+
path: contained.node.path,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// A step node is a dispatch site, not a resource — whatever it reaches
|
|
118
|
+
// is in `contents` in its own right, so judging the step too would
|
|
119
|
+
// report one placement twice.
|
|
120
|
+
if (contained.node.type !== "resource") continue;
|
|
121
|
+
const manifest = contained.node.manifest;
|
|
122
|
+
const module = (manifest.metadata as { module?: string } | undefined)?.module;
|
|
123
|
+
const rebuttal = violations(contained.node.kind, module)[attribute];
|
|
124
|
+
if (!rebuttal) continue;
|
|
125
|
+
if (!owned(manifest, reportModules)) continue;
|
|
126
|
+
|
|
127
|
+
const dedupe = `${region.provider.id}\0${region.slot}\0${contained.node.id}\0${attribute}`;
|
|
128
|
+
if (reported.has(dedupe)) continue;
|
|
129
|
+
reported.add(dedupe);
|
|
130
|
+
|
|
131
|
+
const path = [`${region.provider.name}.${region.slot}`, ...contained.via].join(" → ");
|
|
132
|
+
diagnostics.push({
|
|
133
|
+
severity: DiagnosticSeverity.Error,
|
|
134
|
+
code: "ZONE_ATTRIBUTE_VIOLATED",
|
|
135
|
+
source: SOURCE,
|
|
136
|
+
message:
|
|
137
|
+
`${contained.node.kind} '${contained.node.name}' is inside a ` +
|
|
138
|
+
`${region.provider.kind} '${region.provider.name}' region that declares ` +
|
|
139
|
+
`'${attribute}' (${region.reason}), but ${contained.node.kind} cannot honour ` +
|
|
140
|
+
`it: ${rebuttal}. Reached by ${path}. Move it outside the region, or use a ` +
|
|
141
|
+
`region that does not make that promise.`,
|
|
142
|
+
data: {
|
|
143
|
+
resource: { kind: contained.node.kind, name: contained.node.name },
|
|
144
|
+
filePath: (manifest.metadata as { source?: string } | undefined)?.source,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return diagnostics;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Does this declared retry policy back off far enough to park?
|
|
156
|
+
*
|
|
157
|
+
* EXACT, not an estimate, and it is the runtime's own arithmetic
|
|
158
|
+
* (`retryBackoffMs`) rather than a second copy of it — a static rule that
|
|
159
|
+
* re-derives what it describes drifts from the behaviour the first time either
|
|
160
|
+
* side gains a knob. It is exact for a second reason too: the runtime branches
|
|
161
|
+
* on the UN-JITTERED backoff, so there is no coin flip for this to
|
|
162
|
+
* approximate. The last attempt has the largest backoff, so it decides.
|
|
163
|
+
*
|
|
164
|
+
* Only a STATICALLY KNOWN policy is judged — the `LIVE_VALUE_RETRIED` posture,
|
|
165
|
+
* and for its reason: a CEL budget says nothing, and guessing would report a
|
|
166
|
+
* conflict against a manifest that may never wait that long. An unreadable
|
|
167
|
+
* policy is left to the runtime check, which sees the real number.
|
|
168
|
+
*/
|
|
169
|
+
function suspendingBackoff(raw: unknown): boolean {
|
|
170
|
+
if (!raw || typeof raw !== "object") return false;
|
|
171
|
+
const policy = raw as Record<string, unknown>;
|
|
172
|
+
if (!Object.values(policy).every(isStaticValue)) return false;
|
|
173
|
+
const attempts = policy.attempts;
|
|
174
|
+
if (typeof attempts !== "number" || attempts <= 0) return false;
|
|
175
|
+
return retryBackoffMs(policy as never, attempts - 1) >= SUSPENDING_BACKOFF_MS;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** A CEL leaf reaches here as a compiled value or a tagged sentinel, and either
|
|
179
|
+
* way the policy is not statically known. Refusing the whole policy rather than
|
|
180
|
+
* the one field is the conservative direction: `maxDelay` alone decides the
|
|
181
|
+
* answer, so reading around an unresolved one would report a bound the manifest
|
|
182
|
+
* may never reach. */
|
|
183
|
+
function isStaticValue(value: unknown): boolean {
|
|
184
|
+
return value === undefined || typeof value === "number" || typeof value === "string";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function owned(manifest: ResourceManifest, reportModules: ReadonlySet<string>): boolean {
|
|
188
|
+
const module = (manifest.metadata as { module?: string } | undefined)?.module;
|
|
189
|
+
return !module || reportModules.size === 0 || reportModules.has(module);
|
|
190
|
+
}
|
|
@@ -63,7 +63,11 @@ export const ANNOTATION_KEYWORDS = [
|
|
|
63
63
|
"x-telo-provides-zone",
|
|
64
64
|
"x-telo-ref",
|
|
65
65
|
"x-telo-requires-zone",
|
|
66
|
+
"x-telo-resource-rules",
|
|
66
67
|
"x-telo-schema-from",
|
|
68
|
+
"x-telo-schema-map",
|
|
69
|
+
"x-telo-schema-projection",
|
|
70
|
+
"x-telo-schema-projection-from",
|
|
67
71
|
"x-telo-scope",
|
|
68
72
|
"x-telo-step-context",
|
|
69
73
|
"x-telo-topology-role",
|
package/src/zone-slot.ts
CHANGED
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
*
|
|
11
11
|
* x-telo-provides-zone: true # uncorrelated — the zone is the kind
|
|
12
12
|
* x-telo-provides-zone: /connection # correlation-key pointer (own field)
|
|
13
|
+
* x-telo-provides-zone: # correlation key + zone attributes
|
|
14
|
+
* key: /connection
|
|
15
|
+
* atomic: a rollback erases writes a journal recorded as done
|
|
16
|
+
* noSuspend: the transaction holds a connection a parked run would lose
|
|
17
|
+
*
|
|
18
|
+
* x-telo-violates-zone: # what this kind cannot honour
|
|
19
|
+
* noSuspend: this waits for a delivery that may be days away
|
|
13
20
|
*
|
|
14
21
|
* x-telo-requires-zone: Self.Transaction # uncorrelated string form
|
|
15
22
|
* x-telo-requires-zone: # object form
|
|
@@ -18,8 +25,11 @@
|
|
|
18
25
|
* reason: the statement would execute outside any transaction
|
|
19
26
|
*/
|
|
20
27
|
|
|
28
|
+
import { ZONE_ATTRIBUTES, type ZoneAttributes } from "@telorun/sdk";
|
|
29
|
+
|
|
21
30
|
const PROVIDES = "x-telo-provides-zone";
|
|
22
31
|
const REQUIRES = "x-telo-requires-zone";
|
|
32
|
+
const VIOLATES = "x-telo-violates-zone";
|
|
23
33
|
|
|
24
34
|
/** A body slot that establishes the declaring kind's zone when dispatched
|
|
25
35
|
* through. The zone's identity is always the declaring kind — the annotation
|
|
@@ -29,6 +39,16 @@ export interface ProvidesZoneSlot {
|
|
|
29
39
|
* reference the zone carries as its correlation payload. Absent =
|
|
30
40
|
* uncorrelated (`true`). */
|
|
31
41
|
key?: string;
|
|
42
|
+
/** What this zone declares about everything executed inside it, keyed by the
|
|
43
|
+
* closed vocabulary's bare names with the author's REASON as each value (see
|
|
44
|
+
* `sdk/zone-attributes/`). Empty for the two scalar spellings, which say
|
|
45
|
+
* nothing about their contents.
|
|
46
|
+
*
|
|
47
|
+
* Read here and interpreted nowhere in this file: an attribute's meaning is
|
|
48
|
+
* entirely its consumer's — the containment walk, the step engine's collapse
|
|
49
|
+
* rule, the parking kinds — exactly as `readRefSlot` hands back `use` without
|
|
50
|
+
* acting on it. */
|
|
51
|
+
attributes: ZoneAttributes;
|
|
32
52
|
}
|
|
33
53
|
|
|
34
54
|
/** A field declaring that its resource must be reached through a zone. */
|
|
@@ -43,6 +63,22 @@ export interface RequiresZoneSlot {
|
|
|
43
63
|
key: string[];
|
|
44
64
|
/** The runtime consequence, quoted after the path in diagnostics. */
|
|
45
65
|
reason?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Zone attributes the satisfying zone must DECLARE — what it must guarantee,
|
|
68
|
+
* as opposed to which kind it is.
|
|
69
|
+
*
|
|
70
|
+
* The two are different questions and the kind test alone cannot answer the
|
|
71
|
+
* second. A kind may extend the required abstract, and so satisfy every kind
|
|
72
|
+
* check, while its body slot omits the attribute the requirer actually depends
|
|
73
|
+
* on — a durable workflow whose body does not declare `replayed` is a zone the
|
|
74
|
+
* durable checks never look inside, and a run parking there parks against
|
|
75
|
+
* nothing. Naming the attribute is what makes the requirement say what it
|
|
76
|
+
* means.
|
|
77
|
+
*
|
|
78
|
+
* Names come from the closed vocabulary (`sdk/zone-attributes/`), so the
|
|
79
|
+
* analyzer reads its own words here and no module's kind is named.
|
|
80
|
+
*/
|
|
81
|
+
attributes: string[];
|
|
46
82
|
}
|
|
47
83
|
|
|
48
84
|
/** A self-relative JSON Pointer — the only correlation-key spelling the
|
|
@@ -59,9 +95,36 @@ function isPointer(value: unknown): value is string {
|
|
|
59
95
|
* none or the value is malformed (`validate-zone-slots` reports those). */
|
|
60
96
|
export function readProvidesZone(node: Record<string, any> | undefined): ProvidesZoneSlot | undefined {
|
|
61
97
|
const raw = node?.[PROVIDES];
|
|
62
|
-
if (raw === true) return {};
|
|
63
|
-
if (isPointer(raw)) return { key: raw };
|
|
64
|
-
return undefined;
|
|
98
|
+
if (raw === true) return { attributes: {} };
|
|
99
|
+
if (isPointer(raw)) return { key: raw, attributes: {} };
|
|
100
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
101
|
+
|
|
102
|
+
const obj = raw as Record<string, unknown>;
|
|
103
|
+
// A `key` that is present but unreadable makes the object form MEAN something
|
|
104
|
+
// different to the two halves — the correlation the author wrote is dropped
|
|
105
|
+
// here while the kernel's walk still resolves a bare name — so the whole
|
|
106
|
+
// annotation is refused rather than read as uncorrelated. Absent `key` is the
|
|
107
|
+
// legitimate uncorrelated case.
|
|
108
|
+
if (obj.key !== undefined && !isPointer(obj.key)) return undefined;
|
|
109
|
+
|
|
110
|
+
const attributes: Record<string, string> = {};
|
|
111
|
+
for (const [name, value] of Object.entries(obj)) {
|
|
112
|
+
if (name === "key") continue;
|
|
113
|
+
// Unknown names and wrong-shaped values are reported by
|
|
114
|
+
// `validate-zone-slots`; skipped here so a typo degrades to an attribute
|
|
115
|
+
// this zone does not declare rather than to a consumer reading a name that
|
|
116
|
+
// means nothing to it.
|
|
117
|
+
if (!ZONE_ATTRIBUTES.has(name) || typeof value !== "string" || !value) continue;
|
|
118
|
+
attributes[name] = value;
|
|
119
|
+
}
|
|
120
|
+
return { ...(isPointer(obj.key) ? { key: obj.key } : {}), attributes: attributes as ZoneAttributes };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The attributes the zone a slot provides declares, or an empty record when the
|
|
124
|
+
* node provides no zone. The shape every containment consumer wants, so none of
|
|
125
|
+
* them repeats the `readProvidesZone(...)?.attributes ?? {}` dance. */
|
|
126
|
+
export function providedZoneAttributes(node: Record<string, any> | undefined): ZoneAttributes {
|
|
127
|
+
return readProvidesZone(node)?.attributes ?? {};
|
|
65
128
|
}
|
|
66
129
|
|
|
67
130
|
/** True when the node carries `x-telo-provides-zone` in any shape, valid or not
|
|
@@ -74,17 +137,63 @@ export function hasProvidesZone(node: Record<string, any> | undefined): boolean
|
|
|
74
137
|
* none or the value is malformed (`validate-zone-slots` reports those). */
|
|
75
138
|
export function readRequiresZone(node: Record<string, any> | undefined): RequiresZoneSlot | undefined {
|
|
76
139
|
const raw = node?.[REQUIRES];
|
|
77
|
-
if (typeof raw === "string" && raw) return { zone: raw, key: [] };
|
|
140
|
+
if (typeof raw === "string" && raw) return { zone: raw, key: [], attributes: [] };
|
|
78
141
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return undefined;
|
|
79
142
|
const obj = raw as Record<string, unknown>;
|
|
80
143
|
if (typeof obj.zone !== "string" || !obj.zone) return undefined;
|
|
81
144
|
// One filter for both spellings — see `isPointer`.
|
|
82
145
|
const key = (Array.isArray(obj.key) ? obj.key : [obj.key]).filter(isPointer);
|
|
83
|
-
|
|
146
|
+
// Unknown names are dropped here and reported by `validate-zone-slots`, the
|
|
147
|
+
// lenient-reader / strict-validator split this file has throughout: a typo
|
|
148
|
+
// degrades to a guarantee this requirement does not ask for, never to a
|
|
149
|
+
// consumer matching against a name that means nothing.
|
|
150
|
+
const attributes = (Array.isArray(obj.attributes) ? obj.attributes : []).filter(
|
|
151
|
+
(a): a is string => typeof a === "string" && ZONE_ATTRIBUTES.has(a),
|
|
152
|
+
);
|
|
153
|
+
const slot: RequiresZoneSlot = { zone: obj.zone, key, attributes };
|
|
84
154
|
if (typeof obj.reason === "string") slot.reason = obj.reason;
|
|
85
155
|
return slot;
|
|
86
156
|
}
|
|
87
157
|
|
|
158
|
+
/**
|
|
159
|
+
* What this kind CANNOT honour about a region it is placed inside.
|
|
160
|
+
*
|
|
161
|
+
* The third relation, and the one the other two cannot express. `provides`
|
|
162
|
+
* declares what a region guarantees about its contents; `requires` declares what
|
|
163
|
+
* a resource needs of the region around it. Neither says *this resource breaks
|
|
164
|
+
* that guarantee* — and without it a zone attribute has a promise and no way to
|
|
165
|
+
* name what falsifies it: `noSuspend` would be enforced only when a parking kind
|
|
166
|
+
* happened to reach its runtime check, and `Durable.Sleep` would be
|
|
167
|
+
* indistinguishable from `Durable.Value`, which needs the same journal and parks
|
|
168
|
+
* nothing.
|
|
169
|
+
*
|
|
170
|
+
* Declared at the kind's SCHEMA ROOT, because it is a property of the kind
|
|
171
|
+
* rather than of one of its slots — a kind that suspends suspends however it is
|
|
172
|
+
* configured.
|
|
173
|
+
*
|
|
174
|
+
* Values are the author's REASON, exactly as on `provides`: a diagnostic prints
|
|
175
|
+
* the region's promise and this resource's rebuttal side by side, and both are
|
|
176
|
+
* their own authors' words.
|
|
177
|
+
*/
|
|
178
|
+
export function readViolatesZone(node: Record<string, any> | undefined): ZoneAttributes {
|
|
179
|
+
const raw = node?.[VIOLATES];
|
|
180
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
181
|
+
const out: Record<string, string> = {};
|
|
182
|
+
for (const [name, value] of Object.entries(raw as Record<string, unknown>)) {
|
|
183
|
+
// Lenient, like every reader here: `validate-zone-slots` reports a typo, and
|
|
184
|
+
// dropping it degrades to a violation nobody declared rather than to a
|
|
185
|
+
// consumer matching a name that means nothing.
|
|
186
|
+
if (!ZONE_ATTRIBUTES.has(name) || typeof value !== "string" || !value) continue;
|
|
187
|
+
out[name] = value;
|
|
188
|
+
}
|
|
189
|
+
return out as ZoneAttributes;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** True when the node carries `x-telo-violates-zone` in any shape, valid or not. */
|
|
193
|
+
export function hasViolatesZone(node: Record<string, any> | undefined): boolean {
|
|
194
|
+
return node?.[VIOLATES] !== undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
88
197
|
/** True when the node carries `x-telo-requires-zone` in any shape. */
|
|
89
198
|
export function hasRequiresZone(node: Record<string, any> | undefined): boolean {
|
|
90
199
|
return node?.[REQUIRES] !== undefined;
|