@telorun/analyzer 0.72.0 → 0.73.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/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +50 -13
- package/dist/builtins.d.ts.map +1 -1
- package/dist/builtins.js +71 -97
- package/dist/cel-scope-query.d.ts.map +1 -1
- package/dist/cel-scope-query.js +32 -11
- package/dist/cel-scope.d.ts.map +1 -1
- package/dist/cel-scope.js +1 -0
- package/dist/eval-paths.d.ts +36 -5
- package/dist/eval-paths.d.ts.map +1 -1
- package/dist/eval-paths.js +47 -6
- package/dist/extends-resolution.d.ts +12 -0
- package/dist/extends-resolution.d.ts.map +1 -1
- package/dist/extends-resolution.js +23 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/nearest-name.d.ts +22 -0
- package/dist/nearest-name.d.ts.map +1 -0
- package/dist/nearest-name.js +43 -0
- package/dist/release/destinations.d.ts +59 -0
- package/dist/release/destinations.d.ts.map +1 -0
- package/dist/release/destinations.js +75 -0
- package/dist/release/index.d.ts +6 -2
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +3 -1
- package/dist/release/ledger.d.ts +20 -11
- package/dist/release/ledger.d.ts.map +1 -1
- package/dist/release/ledger.js +43 -14
- package/dist/release/release-plan.d.ts +3 -2
- package/dist/release/release-plan.d.ts.map +1 -1
- package/dist/release/release-plan.js +12 -19
- package/dist/release/workspace-config.d.ts +114 -34
- package/dist/release/workspace-config.d.ts.map +1 -1
- package/dist/release/workspace-config.js +322 -38
- package/dist/release/workspace-schema.d.ts +41 -0
- package/dist/release/workspace-schema.d.ts.map +1 -0
- package/dist/release/workspace-schema.js +77 -0
- package/dist/schema-error-report.d.ts +7 -0
- package/dist/schema-error-report.d.ts.map +1 -1
- package/dist/schema-error-report.js +9 -4
- package/dist/telo-version.d.ts +1 -1
- package/dist/telo-version.js +1 -1
- package/dist/template-body.d.ts +10 -0
- package/dist/template-body.d.ts.map +1 -1
- package/dist/template-body.js +25 -0
- package/dist/validate-cel-context.d.ts +23 -8
- package/dist/validate-cel-context.d.ts.map +1 -1
- package/dist/validate-cel-context.js +48 -16
- package/dist/validate-exports.d.ts +28 -0
- package/dist/validate-exports.d.ts.map +1 -0
- package/dist/validate-exports.js +146 -0
- package/dist/validate-extends.d.ts.map +1 -1
- package/dist/validate-extends.js +37 -1
- package/dist/validate-provider-coherence.d.ts +4 -8
- package/dist/validate-provider-coherence.d.ts.map +1 -1
- package/dist/validate-provider-coherence.js +12 -123
- package/dist/validate-references.d.ts.map +1 -1
- package/dist/validate-references.js +141 -60
- package/dist/validate-template-body.d.ts +36 -0
- package/dist/validate-template-body.d.ts.map +1 -0
- package/dist/validate-template-body.js +246 -0
- package/package.json +3 -2
- package/src/analyzer.ts +64 -11
- package/src/builtins.ts +85 -97
- package/src/cel-scope-query.ts +28 -9
- package/src/cel-scope.ts +1 -0
- package/src/eval-paths.ts +53 -6
- package/src/extends-resolution.ts +24 -0
- package/src/index.ts +1 -0
- package/src/nearest-name.ts +47 -0
- package/src/release/destinations.ts +105 -0
- package/src/release/index.ts +33 -2
- package/src/release/ledger.ts +51 -21
- package/src/release/release-plan.ts +16 -26
- package/src/release/workspace-config.ts +483 -47
- package/src/release/workspace-schema.ts +99 -0
- package/src/schema-error-report.ts +16 -4
- package/src/telo-version.ts +1 -1
- package/src/template-body.ts +25 -0
- package/src/validate-cel-context.ts +57 -16
- package/src/validate-exports.ts +185 -0
- package/src/validate-extends.ts +43 -0
- package/src/validate-provider-coherence.ts +17 -127
- package/src/validate-references.ts +141 -60
- package/src/validate-template-body.ts +274 -0
- package/dist/validate-template-dispatch.d.ts +0 -27
- package/dist/validate-template-dispatch.d.ts.map +0 -1
- package/dist/validate-template-dispatch.js +0 -95
- package/src/validate-template-dispatch.ts +0 -99
|
@@ -12,20 +12,16 @@ import { type AnalysisDiagnostic } from "./types.js";
|
|
|
12
12
|
* `capability` is not `Telo.Provider`.
|
|
13
13
|
* - PROVIDE_DISPATCHER_CONFLICT: `provide:` co-exists with `invoke:` or `run:`
|
|
14
14
|
* on the same definition.
|
|
15
|
-
* - PROVIDE_TARGET_UNKNOWN: `provide.name` does not resolve to an entry in
|
|
16
|
-
* `resources:`.
|
|
17
|
-
* - PROVIDE_TARGET_NOT_INVOCABLE: `provide.name` resolves to a resource whose
|
|
18
|
-
* kind is registered but not a `Telo.Invocable`.
|
|
19
15
|
* - PROVIDER_MISSING_IMPLEMENTATION: definition with `capability: Telo.Provider`
|
|
20
16
|
* declares neither `controllers:` (TS-backed) nor `provide:` (template-backed).
|
|
21
17
|
* - MOUNT_ON_NON_MOUNT: `mount:` declared on a definition whose `capability` is
|
|
22
18
|
* not `Telo.Mount`.
|
|
23
19
|
* - MOUNT_DISPATCHER_CONFLICT: `mount:` co-exists with another dispatch
|
|
24
20
|
* entry-point (`invoke:` / `run:` / `provide:`).
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
21
|
+
*
|
|
22
|
+
* What a dispatch slot NAMES — that it is a `!ref`, that the entry exists, that
|
|
23
|
+
* its capability carries the method — is `validate-template-body`'s, for every
|
|
24
|
+
* slot alike.
|
|
29
25
|
*/
|
|
30
26
|
export declare function validateProviderCoherence(manifests: ResourceManifest[], registry: DefinitionRegistry, aliases: AliasResolver): AnalysisDiagnostic[];
|
|
31
27
|
//# sourceMappingURL=validate-provider-coherence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-provider-coherence.d.ts","sourceRoot":"","sources":["../src/validate-provider-coherence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"validate-provider-coherence.d.ts","sourceRoot":"","sources":["../src/validate-provider-coherence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAMnE,OAAO,EAAsB,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAIzE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,aAAa,GACrB,kBAAkB,EAAE,CAiHtB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { controllerBearingAncestor } from "./extends-resolution.js";
|
|
1
|
+
import { controllerBearingAncestor, inheritedCapability, } from "./extends-resolution.js";
|
|
2
2
|
import { DiagnosticSeverity } from "./types.js";
|
|
3
3
|
const SOURCE = "telo-analyzer";
|
|
4
4
|
/**
|
|
@@ -11,20 +11,16 @@ const SOURCE = "telo-analyzer";
|
|
|
11
11
|
* `capability` is not `Telo.Provider`.
|
|
12
12
|
* - PROVIDE_DISPATCHER_CONFLICT: `provide:` co-exists with `invoke:` or `run:`
|
|
13
13
|
* on the same definition.
|
|
14
|
-
* - PROVIDE_TARGET_UNKNOWN: `provide.name` does not resolve to an entry in
|
|
15
|
-
* `resources:`.
|
|
16
|
-
* - PROVIDE_TARGET_NOT_INVOCABLE: `provide.name` resolves to a resource whose
|
|
17
|
-
* kind is registered but not a `Telo.Invocable`.
|
|
18
14
|
* - PROVIDER_MISSING_IMPLEMENTATION: definition with `capability: Telo.Provider`
|
|
19
15
|
* declares neither `controllers:` (TS-backed) nor `provide:` (template-backed).
|
|
20
16
|
* - MOUNT_ON_NON_MOUNT: `mount:` declared on a definition whose `capability` is
|
|
21
17
|
* not `Telo.Mount`.
|
|
22
18
|
* - MOUNT_DISPATCHER_CONFLICT: `mount:` co-exists with another dispatch
|
|
23
19
|
* entry-point (`invoke:` / `run:` / `provide:`).
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* What a dispatch slot NAMES — that it is a `!ref`, that the entry exists, that
|
|
22
|
+
* its capability carries the method — is `validate-template-body`'s, for every
|
|
23
|
+
* slot alike.
|
|
28
24
|
*/
|
|
29
25
|
export function validateProviderCoherence(manifests, registry, aliases) {
|
|
30
26
|
const diagnostics = [];
|
|
@@ -50,13 +46,18 @@ export function validateProviderCoherence(manifests, registry, aliases) {
|
|
|
50
46
|
const resource = { kind: m.kind, name };
|
|
51
47
|
const label = `${m.kind}/${name}`;
|
|
52
48
|
const md = m;
|
|
53
|
-
const
|
|
49
|
+
const resolveDef = (k) => registry.resolve(aliases.resolveKind(k) ?? k) ?? registry.resolve(k);
|
|
50
|
+
// The INHERITED capability, not the declared one: an `extends` child writes
|
|
51
|
+
// none of its own, so reading `md.capability` reported a child that inherits
|
|
52
|
+
// `Telo.Provider` and declares `provide:` as PROVIDE_ON_NON_PROVIDER
|
|
53
|
+
// "(found '<unset>')" — the same defect `celRuleApplies` and
|
|
54
|
+
// `validate-template-body` were fixed for, in the file next door.
|
|
55
|
+
const capability = inheritedCapability(m, resolveDef);
|
|
54
56
|
const provide = md.provide;
|
|
55
57
|
const invoke = md.invoke;
|
|
56
58
|
const run = md.run;
|
|
57
59
|
const mount = md.mount;
|
|
58
60
|
const controllers = md.controllers;
|
|
59
|
-
const resources = md.resources;
|
|
60
61
|
const hasProvide = provide !== undefined && provide !== null;
|
|
61
62
|
const hasInvoke = invoke !== undefined && invoke !== null;
|
|
62
63
|
const hasRun = run !== undefined && run !== null;
|
|
@@ -83,67 +84,6 @@ export function validateProviderCoherence(manifests, registry, aliases) {
|
|
|
83
84
|
data: { resource, filePath, path: "provide" },
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
|
-
if (hasProvide && typeof provide === "object" && !Array.isArray(provide)) {
|
|
87
|
-
const provideObj = provide;
|
|
88
|
-
const providedName = typeof provideObj.name === "string" ? provideObj.name : undefined;
|
|
89
|
-
const providedKind = typeof provideObj.kind === "string" ? provideObj.kind : undefined;
|
|
90
|
-
if (providedName && Array.isArray(resources)) {
|
|
91
|
-
const match = resources.find((r) => {
|
|
92
|
-
const meta = r?.metadata;
|
|
93
|
-
return typeof meta?.name === "string" && meta.name === providedName;
|
|
94
|
-
});
|
|
95
|
-
if (!match) {
|
|
96
|
-
diagnostics.push({
|
|
97
|
-
severity: DiagnosticSeverity.Error,
|
|
98
|
-
code: "PROVIDE_TARGET_UNKNOWN",
|
|
99
|
-
source: SOURCE,
|
|
100
|
-
message: `${label}: 'provide.name: ${providedName}' does not match any entry's ` +
|
|
101
|
-
`metadata.name in 'resources:'.`,
|
|
102
|
-
data: { resource, filePath, path: "provide.name" },
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
else if (typeof match.kind === "string") {
|
|
106
|
-
// `provide.kind` is the type contract the analyzer uses to type
|
|
107
|
-
// `result` CEL against the target's `outputType`. The runtime
|
|
108
|
-
// dispatches on `provide.name` and ignores `provide.kind`, so a
|
|
109
|
-
// mismatch silently degrades `result` typing to an open schema
|
|
110
|
-
// (and at runtime quietly invokes the actually-matched resource).
|
|
111
|
-
// Flag the divergence so result-typing never lies.
|
|
112
|
-
if (providedKind) {
|
|
113
|
-
const providedCanonical = aliases.resolveKind(providedKind) ?? providedKind;
|
|
114
|
-
const matchCanonical = aliases.resolveKind(match.kind) ?? match.kind;
|
|
115
|
-
if (providedCanonical !== matchCanonical) {
|
|
116
|
-
diagnostics.push({
|
|
117
|
-
severity: DiagnosticSeverity.Error,
|
|
118
|
-
code: "PROVIDE_KIND_MISMATCH",
|
|
119
|
-
source: SOURCE,
|
|
120
|
-
message: `${label}: 'provide.kind: ${providedKind}' disagrees with the matched ` +
|
|
121
|
-
`'resources:' entry's kind '${match.kind}' (matched by metadata.name ` +
|
|
122
|
-
`'${providedName}'). The runtime dispatches by name, so 'provide.kind' ` +
|
|
123
|
-
`is decorative — but the analyzer types 'result:' against it, and a ` +
|
|
124
|
-
`mismatch silently turns off that typing.`,
|
|
125
|
-
data: { resource, filePath, path: "provide.kind" },
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const resolvedKind = aliases.resolveKind(match.kind) ?? match.kind;
|
|
130
|
-
const targetDef = registry.resolve(resolvedKind) ?? registry.resolve(match.kind);
|
|
131
|
-
if (targetDef && targetDef.kind === "Telo.Definition") {
|
|
132
|
-
const targetCap = targetDef.capability;
|
|
133
|
-
if (typeof targetCap === "string" && targetCap !== "Telo.Invocable") {
|
|
134
|
-
diagnostics.push({
|
|
135
|
-
severity: DiagnosticSeverity.Error,
|
|
136
|
-
code: "PROVIDE_TARGET_NOT_INVOCABLE",
|
|
137
|
-
source: SOURCE,
|
|
138
|
-
message: `${label}: 'provide.name: ${providedName}' resolves to a ${match.kind} ` +
|
|
139
|
-
`(capability '${targetCap}'); 'provide:' requires a Telo.Invocable target.`,
|
|
140
|
-
data: { resource, filePath, path: "provide.name" },
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
87
|
if (hasMount && capability !== "Telo.Mount") {
|
|
148
88
|
diagnostics.push({
|
|
149
89
|
severity: DiagnosticSeverity.Error,
|
|
@@ -165,60 +105,9 @@ export function validateProviderCoherence(manifests, registry, aliases) {
|
|
|
165
105
|
data: { resource, filePath, path: "mount" },
|
|
166
106
|
});
|
|
167
107
|
}
|
|
168
|
-
if (hasMount) {
|
|
169
|
-
// Resolve the target's name from either form: the bare string (the
|
|
170
|
-
// primary, documented form — `mount: api`) or the object's `name`. A CEL
|
|
171
|
-
// target (`${{ … }}`) can only be checked at runtime, so skip those.
|
|
172
|
-
let mountedName;
|
|
173
|
-
if (typeof mount === "string") {
|
|
174
|
-
if (!mount.includes("${{"))
|
|
175
|
-
mountedName = mount;
|
|
176
|
-
}
|
|
177
|
-
else if (typeof mount === "object" && !Array.isArray(mount)) {
|
|
178
|
-
const mountObj = mount;
|
|
179
|
-
if (typeof mountObj.name === "string" && !mountObj.name.includes("${{")) {
|
|
180
|
-
mountedName = mountObj.name;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
const mountPath = typeof mount === "string" ? "mount" : "mount.name";
|
|
184
|
-
if (mountedName && Array.isArray(resources)) {
|
|
185
|
-
const match = resources.find((r) => {
|
|
186
|
-
const meta = r?.metadata;
|
|
187
|
-
return typeof meta?.name === "string" && meta.name === mountedName;
|
|
188
|
-
});
|
|
189
|
-
if (!match) {
|
|
190
|
-
diagnostics.push({
|
|
191
|
-
severity: DiagnosticSeverity.Error,
|
|
192
|
-
code: "MOUNT_TARGET_UNKNOWN",
|
|
193
|
-
source: SOURCE,
|
|
194
|
-
message: `${label}: '${mountPath}: ${mountedName}' does not match any entry's ` +
|
|
195
|
-
`metadata.name in 'resources:'.`,
|
|
196
|
-
data: { resource, filePath, path: mountPath },
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
else if (typeof match.kind === "string") {
|
|
200
|
-
const resolvedKind = aliases.resolveKind(match.kind) ?? match.kind;
|
|
201
|
-
const targetDef = registry.resolve(resolvedKind) ?? registry.resolve(match.kind);
|
|
202
|
-
if (targetDef && targetDef.kind === "Telo.Definition") {
|
|
203
|
-
const targetCap = targetDef.capability;
|
|
204
|
-
if (typeof targetCap === "string" && targetCap !== "Telo.Mount") {
|
|
205
|
-
diagnostics.push({
|
|
206
|
-
severity: DiagnosticSeverity.Error,
|
|
207
|
-
code: "MOUNT_TARGET_NOT_MOUNTABLE",
|
|
208
|
-
source: SOURCE,
|
|
209
|
-
message: `${label}: '${mountPath}: ${mountedName}' resolves to a ${match.kind} ` +
|
|
210
|
-
`(capability '${targetCap}'); 'mount:' requires a Telo.Mount target.`,
|
|
211
|
-
data: { resource, filePath, path: mountPath },
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
108
|
// A definition that inherits a controller by delegation (concrete `extends`,
|
|
219
109
|
// no own controller/template) satisfies the implementation requirement
|
|
220
110
|
// through its parent — `base:` supplies the parent's config.
|
|
221
|
-
const resolveDef = (k) => registry.resolve(aliases.resolveKind(k) ?? k) ?? registry.resolve(k);
|
|
222
111
|
const inheritsController = typeof md.extends === "string" &&
|
|
223
112
|
controllerBearingAncestor(m, resolveDef) !== undefined;
|
|
224
113
|
if (capability === "Telo.Provider" && !hasControllers && !hasProvide && !inheritsController) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-references.d.ts","sourceRoot":"","sources":["../src/validate-references.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAarD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"validate-references.d.ts","sourceRoot":"","sources":["../src/validate-references.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAarD,OAAO,EAAsB,KAAK,kBAAkB,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAyInE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,kBAAkB;AAC5B;8EAC8E;AAC9E,aAAa,UAAQ,GACpB,OAAO,CAwBT;AAgED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,OAAO,EAAE,eAAe,GACvB,kBAAkB,EAAE,CAsgBtB"}
|
|
@@ -6,8 +6,139 @@ import { REF_VALIDATION_SKIP_KINDS as SYSTEM_KINDS } from "./system-kinds.js";
|
|
|
6
6
|
import { resolveTypeFieldToSchema } from "./validate-cel-context.js";
|
|
7
7
|
import { DiagnosticSeverity } from "./types.js";
|
|
8
8
|
import { moduleAliasScope } from "./module-alias-scope.js";
|
|
9
|
+
import { isModuleKind } from "./module-kinds.js";
|
|
9
10
|
import { isInjectedDeclaration } from "./resource-input.js";
|
|
10
11
|
const SOURCE = "telo-analyzer";
|
|
12
|
+
/** What a name IS on one side of a collision. The three shapes share the
|
|
13
|
+
* kernel's one namespace but read as different things to an author — an alias
|
|
14
|
+
* is not a resource, and a module's own name is not a declaration inside it —
|
|
15
|
+
* so calling all three "resource name" describes two of them wrongly. */
|
|
16
|
+
function describeNamed(m, name) {
|
|
17
|
+
if (m.kind === "Telo.Import")
|
|
18
|
+
return `import alias '${name}'`;
|
|
19
|
+
if (isModuleKind(m.kind))
|
|
20
|
+
return `this module's own name (${m.kind} '${name}')`;
|
|
21
|
+
return `resource ${m.kind}/${name}`;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* WHAT SHARES A NAME AT THE KERNEL.
|
|
25
|
+
*
|
|
26
|
+
* `registerManifest` keys on `metadata.name` alone, per module context, for
|
|
27
|
+
* EVERY kind — so an import alias, a kind definition and an ordinary resource
|
|
28
|
+
* are one namespace. This check used to model a narrower one: `Telo.Import` was
|
|
29
|
+
* excluded outright, on the stated grounds that an alias "lives in a separate
|
|
30
|
+
* namespace from resources", and `Telo.Definition` / `Telo.Abstract` fell out
|
|
31
|
+
* through the ref-validation skip set, which answers a different question. All
|
|
32
|
+
* three passed `telo check` and then died at boot with `ERR_DUPLICATE_RESOURCE`
|
|
33
|
+
* — an application named after one of its own imports (`metadata.name: Schedule`
|
|
34
|
+
* beside `Schedule: oci://…/scheduler`) being the shape that reaches an author,
|
|
35
|
+
* since nothing about the two lines looks like one name written twice.
|
|
36
|
+
*
|
|
37
|
+
* Grouped per DECLARING MODULE, which is what makes including imports sound: a
|
|
38
|
+
* library's own `Telo.Import` / `Telo.Definition` docs are forwarded into a
|
|
39
|
+
* consumer's flat set, and two modules sharing an alias (`Console` in an app and
|
|
40
|
+
* again in a library it imports) is ordinary rather than a collision. A module
|
|
41
|
+
* doc carries no `metadata.module` and IS its own scope — that is what puts an
|
|
42
|
+
* application's own name in the same group as its imports.
|
|
43
|
+
*
|
|
44
|
+
* Kept apart from the resolution lookup it used to share a map with: that one
|
|
45
|
+
* must hold resolution targets alone, so the two disagree about membership by
|
|
46
|
+
* design and merging them re-keyed every bare-name reference.
|
|
47
|
+
*/
|
|
48
|
+
function duplicateNameDiagnostics(resources, isForeign, moduleOf) {
|
|
49
|
+
const diagnostics = [];
|
|
50
|
+
const moduleDocNames = new Set();
|
|
51
|
+
for (const r of resources) {
|
|
52
|
+
if (isModuleKind(r.kind) && typeof r.metadata?.name === "string") {
|
|
53
|
+
moduleDocNames.add(r.metadata.name);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// A module doc belongs in the scope its OWN resources are in. Flattened, they
|
|
57
|
+
// carry `metadata.module` equal to its name, so it scopes to itself — which is
|
|
58
|
+
// what puts an application's name beside its imports. Unflattened (a hand-built
|
|
59
|
+
// fixture, a single-file editor analysis) nothing is stamped, so its resources
|
|
60
|
+
// sit in the unnamed scope and the doc has to join them there or a collision
|
|
61
|
+
// with one of them splits across two groups and goes unreported.
|
|
62
|
+
const stampedModules = new Set();
|
|
63
|
+
for (const r of resources) {
|
|
64
|
+
const m = moduleOf(r);
|
|
65
|
+
if (m)
|
|
66
|
+
stampedModules.add(m);
|
|
67
|
+
}
|
|
68
|
+
// scope → name → declarations, so no separator has to be safe against a name.
|
|
69
|
+
const byScope = new Map();
|
|
70
|
+
const seen = new Set();
|
|
71
|
+
for (const r of resources) {
|
|
72
|
+
if (!r.metadata?.name || isForeign(r))
|
|
73
|
+
continue;
|
|
74
|
+
const name = r.metadata.name;
|
|
75
|
+
const scope = isModuleKind(r.kind)
|
|
76
|
+
? (stampedModules.has(name) ? name : "")
|
|
77
|
+
: (moduleOf(r) ?? "");
|
|
78
|
+
// A scope with no module doc in this set is an imported library's, whose
|
|
79
|
+
// doc `selectModuleManifestsForAnalysis` drops — its internals are its own
|
|
80
|
+
// author's to fix, and its own `telo check` reports them.
|
|
81
|
+
if (scope !== "" && moduleDocNames.size > 0 && !moduleDocNames.has(scope))
|
|
82
|
+
continue;
|
|
83
|
+
// Dedup pipeline echoes — the same physical document emitted twice through
|
|
84
|
+
// an analyzer host's pipeline (telo studio walks a file reachable as both an
|
|
85
|
+
// entry module and an `include:` partial). Keyed on (kind, name, source,
|
|
86
|
+
// sourceLine), so two textually-distinct docs in one file keep separate
|
|
87
|
+
// fingerprints and still trip the diagnostic.
|
|
88
|
+
const meta = r.metadata;
|
|
89
|
+
const fingerprint = `${r.kind} ${name} ${meta.source} ${meta.sourceLine}`;
|
|
90
|
+
if (seen.has(fingerprint))
|
|
91
|
+
continue;
|
|
92
|
+
seen.add(fingerprint);
|
|
93
|
+
let names = byScope.get(scope);
|
|
94
|
+
if (!names)
|
|
95
|
+
byScope.set(scope, (names = new Map()));
|
|
96
|
+
const existing = names.get(name);
|
|
97
|
+
if (existing)
|
|
98
|
+
existing.push(r);
|
|
99
|
+
else
|
|
100
|
+
names.set(name, [r]);
|
|
101
|
+
}
|
|
102
|
+
for (const names of byScope.values()) {
|
|
103
|
+
for (const [name, list] of names) {
|
|
104
|
+
if (list.length <= 1)
|
|
105
|
+
continue;
|
|
106
|
+
const [first, ...rest] = list;
|
|
107
|
+
for (const dup of rest) {
|
|
108
|
+
// Two imports sharing an alias is ONE defect with its own diagnostic
|
|
109
|
+
// (`DUPLICATE_IMPORT_ALIAS`), which says what to do about it; reporting
|
|
110
|
+
// it again here would describe one mistake as two.
|
|
111
|
+
if (dup.kind === "Telo.Import" && first.kind === "Telo.Import")
|
|
112
|
+
continue;
|
|
113
|
+
const dupMeta = dup.metadata;
|
|
114
|
+
// The precomputed range matters because editor hosts resolve positions
|
|
115
|
+
// via a `${file}::${kind}::${name}` lookup, which collides on duplicates.
|
|
116
|
+
const range = typeof dupMeta?.sourceLine === "number"
|
|
117
|
+
? {
|
|
118
|
+
start: { line: dupMeta.sourceLine, character: 0 },
|
|
119
|
+
end: { line: dupMeta.sourceLine, character: Number.MAX_SAFE_INTEGER },
|
|
120
|
+
}
|
|
121
|
+
: undefined;
|
|
122
|
+
diagnostics.push({
|
|
123
|
+
severity: DiagnosticSeverity.Error,
|
|
124
|
+
code: "DUPLICATE_RESOURCE_NAME",
|
|
125
|
+
source: SOURCE,
|
|
126
|
+
message: `${dup.kind}/${name}: ${describeNamed(dup, name)} collides with ` +
|
|
127
|
+
`${describeNamed(first, name)} declared earlier — the kernel registers both ` +
|
|
128
|
+
`under '${name}' in one namespace, so boot fails with ERR_DUPLICATE_RESOURCE. ` +
|
|
129
|
+
`Rename one of them.`,
|
|
130
|
+
...(range ? { range } : {}),
|
|
131
|
+
data: {
|
|
132
|
+
resource: { kind: dup.kind, name },
|
|
133
|
+
filePath: dupMeta?.source,
|
|
134
|
+
path: "metadata.name",
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return diagnostics;
|
|
141
|
+
}
|
|
11
142
|
/**
|
|
12
143
|
* Liskov substitutability at a kind constraint: is `resolved` (a canonical
|
|
13
144
|
* `<module>.<Kind>`) accepted where `targetKind` is required?
|
|
@@ -142,40 +273,16 @@ export function validateReferences(resources, context) {
|
|
|
142
273
|
const aliasesByModule = context.aliasesByModule;
|
|
143
274
|
if (!aliases || !registry)
|
|
144
275
|
return diagnostics;
|
|
145
|
-
// Build outer resource lookup by name for resolution
|
|
146
|
-
//
|
|
147
|
-
//
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
// kernel refuses to start" surprises.)
|
|
152
|
-
//
|
|
153
|
-
// Telo.Import is excluded from the duplicate check on top of the
|
|
154
|
-
// SYSTEM_KINDS skip: its `metadata.name` is an alias, not a resource
|
|
155
|
-
// identity (aliases live in a separate namespace from resources, and
|
|
156
|
-
// colliding aliases vs. resource names is benign — the alias is only
|
|
157
|
-
// ever read as a kind prefix).
|
|
158
|
-
// Group manifests by name to detect collisions. Two subtleties:
|
|
276
|
+
// Build the outer resource lookup by name, for the resolution checks below.
|
|
277
|
+
// WHICH NAMES COLLIDE is a different question over a different namespace and
|
|
278
|
+
// is answered by `duplicateNameDiagnostics`; this map answers only "what does
|
|
279
|
+
// a bare `!ref <name>` resolve to", so it holds resolution TARGETS alone — an
|
|
280
|
+
// import alias and a kind definition are neither, and admitting them here
|
|
281
|
+
// would resolve a reference to something no ref slot can accept.
|
|
159
282
|
//
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
// reachable from two angles (entry module + `include:` partial)
|
|
164
|
-
// shows up twice. The fingerprint includes `sourceLine` so identical
|
|
165
|
-
// docs (same kind, name, source, AND source line) collapse to one,
|
|
166
|
-
// while two textually-separate documents in the same file (different
|
|
167
|
-
// source lines) keep separate fingerprints and trip the diagnostic.
|
|
168
|
-
// 2. The diagnostic carries a precomputed `range` pointing at the
|
|
169
|
-
// duplicate's source line — editor hosts that resolve diagnostic
|
|
170
|
-
// positions via a `${file}::${kind}::${name}` lookup would otherwise
|
|
171
|
-
// collide on duplicates (Map.set overwrites) and place the squiggle
|
|
172
|
-
// ambiguously. The explicit `range` short-circuits that lookup.
|
|
173
|
-
// Dedup pipeline echoes — the same physical document emitted twice
|
|
174
|
-
// through an analyzer host's pipeline. Keyed on (kind, name, source,
|
|
175
|
-
// sourceLine), so two textually-distinct docs in the same file (same
|
|
176
|
-
// source, different sourceLine) keep separate fingerprints and still
|
|
177
|
-
// trip the diagnostic. `analyze()` enforces that every non-system
|
|
178
|
-
// manifest carries both positional fields — no defensive guard needed.
|
|
283
|
+
// The list per name survives because resolution falls back to the FIRST
|
|
284
|
+
// occurrence when a collision exists, which keeps the rest of the pass
|
|
285
|
+
// behaving as it did before duplicates were reported at all.
|
|
179
286
|
// Forwarded foreign exports (an imported library's exported instances, carrying a
|
|
180
287
|
// metadata.module that isn't a root module) are resolution TARGETS only: excluded from
|
|
181
288
|
// duplicate detection and local name resolution, and never walked as ref sources.
|
|
@@ -229,33 +336,7 @@ export function validateReferences(resources, context) {
|
|
|
229
336
|
else
|
|
230
337
|
byNameAll.set(name, [r]);
|
|
231
338
|
}
|
|
232
|
-
|
|
233
|
-
if (list.length <= 1)
|
|
234
|
-
continue;
|
|
235
|
-
const [first, ...rest] = list;
|
|
236
|
-
const firstLabel = `${first.kind}/${name}`;
|
|
237
|
-
for (const dup of rest) {
|
|
238
|
-
const dupMeta = dup.metadata;
|
|
239
|
-
const range = typeof dupMeta?.sourceLine === "number"
|
|
240
|
-
? {
|
|
241
|
-
start: { line: dupMeta.sourceLine, character: 0 },
|
|
242
|
-
end: { line: dupMeta.sourceLine, character: Number.MAX_SAFE_INTEGER },
|
|
243
|
-
}
|
|
244
|
-
: undefined;
|
|
245
|
-
diagnostics.push({
|
|
246
|
-
severity: DiagnosticSeverity.Error,
|
|
247
|
-
code: "DUPLICATE_RESOURCE_NAME",
|
|
248
|
-
source: SOURCE,
|
|
249
|
-
message: `${dup.kind}/${name}: resource name collides with ${firstLabel} declared earlier (kernel runtime would fail with ERR_DUPLICATE_RESOURCE)`,
|
|
250
|
-
...(range ? { range } : {}),
|
|
251
|
-
data: {
|
|
252
|
-
resource: { kind: dup.kind, name },
|
|
253
|
-
filePath: dupMeta?.source,
|
|
254
|
-
path: "metadata.name",
|
|
255
|
-
},
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
}
|
|
339
|
+
diagnostics.push(...duplicateNameDiagnostics(resources, isForeign, moduleOf));
|
|
259
340
|
// The dot rule that used to live here is now the strictest special case of
|
|
260
341
|
// the identifier grammar in `validate-identifier-names.ts` — a dot is one of
|
|
261
342
|
// several characters that make a name unreferenceable, and checking one of
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ResourceManifest } from "@telorun/sdk";
|
|
2
|
+
import type { AliasResolver } from "./alias-resolver.js";
|
|
3
|
+
import type { DefinitionRegistry } from "./definition-registry.js";
|
|
4
|
+
import { type AnalysisDiagnostic } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* A TEMPLATE BODY IS WRITTEN LIKE EVERY OTHER MANIFEST, AND CHECKED LIKE ONE.
|
|
7
|
+
*
|
|
8
|
+
* A `Telo.Definition` is in both reference skip sets — its body holds
|
|
9
|
+
* declarations of OTHER kinds, and its dispatch slots carry no `x-telo-ref` — so
|
|
10
|
+
* no reference pass reached it, and each rule about it was added per construct:
|
|
11
|
+
* `provide:` and `mount:` had a target check for the `{ kind, name }` object
|
|
12
|
+
* form, `!ref` had one that switched itself off for any definition with a
|
|
13
|
+
* CEL-named entry, and `invoke:` / `run:` had none. What was tagged was caught
|
|
14
|
+
* and what was a plain name was resolved by the kernel alone. This pass is the
|
|
15
|
+
* one reader of a body's reference surface, and it rests on one spelling:
|
|
16
|
+
*
|
|
17
|
+
* - every `resources:` entry is named by a LITERAL (`TEMPLATE_ENTRY_NAME_DYNAMIC`).
|
|
18
|
+
* Each instance of a template owns its children in a child context of its
|
|
19
|
+
* own, so a per-instance suffix (`self.name + '-query'`) buys nothing — and a
|
|
20
|
+
* `!ref` is looked up verbatim, so a CEL-named sibling is one nothing can name;
|
|
21
|
+
* - a dispatch slot is `!ref <entry>` naming an entry
|
|
22
|
+
* (`TEMPLATE_DISPATCH_UNKNOWN`); the legacy spellings are deprecated rather
|
|
23
|
+
* than refused, since published artifacts carry them. What the target's
|
|
24
|
+
* CAPABILITY is stays unchecked — see `DISPATCH_SLOTS`;
|
|
25
|
+
* - a reference slot INSIDE an entry follows the rule every other slot does —
|
|
26
|
+
* `!ref` or an inline declaration, never `{ kind, name }` or a bare string
|
|
27
|
+
* (`INVALID_REFERENCE_FORM`) — and a bare `!ref` names a sibling or a
|
|
28
|
+
* resource of the defining module (`TEMPLATE_REF_UNKNOWN`). Slots are found
|
|
29
|
+
* through the nested kind's own field map, resolved in the DEFINING module's
|
|
30
|
+
* alias scope, since that is where the body's kinds are written.
|
|
31
|
+
*
|
|
32
|
+
* Entry-module-scoped, like every other declaration check: a published
|
|
33
|
+
* dependency's template body is not the consumer's to fix. Browser-safe.
|
|
34
|
+
*/
|
|
35
|
+
export declare function validateTemplateBody(manifests: ResourceManifest[], registry: DefinitionRegistry, aliases: AliasResolver, aliasesByModule: Map<string, AliasResolver>, rootModules: ReadonlySet<string>): AnalysisDiagnostic[];
|
|
36
|
+
//# sourceMappingURL=validate-template-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-template-body.d.ts","sourceRoot":"","sources":["../src/validate-template-body.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,qBAAqB,CAAC;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAInE,OAAO,EAAqC,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAiBxF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,gBAAgB,EAAE,EAC7B,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,aAAa,EACtB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,EAC3C,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAC/B,kBAAkB,EAAE,CAiMtB"}
|