@intentius/chant 0.124.21 → 0.124.23
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/audit/rules-doc.js +1 -1
- package/dist/cli/handlers/graph.js +24 -1
- package/dist/codegen/docs-pages.d.ts +1 -0
- package/dist/codegen/docs-pages.d.ts.map +1 -1
- package/dist/codegen/docs-pages.js +1 -0
- package/dist/codegen/docs-sections.d.ts +2 -0
- package/dist/codegen/docs-sections.d.ts.map +1 -1
- package/dist/codegen/docs-sections.js +8 -0
- package/dist/codegen/docs-types.d.ts +7 -0
- package/dist/codegen/docs-types.d.ts.map +1 -1
- package/dist/codegen/docs.d.ts.map +1 -1
- package/dist/codegen/docs.js +20 -0
- package/dist/fold/subset.d.ts +3 -1
- package/dist/fold/subset.d.ts.map +1 -1
- package/dist/fold/subset.js +3 -1
- package/dist/graph-ir.d.ts +43 -0
- package/dist/graph-ir.d.ts.map +1 -1
- package/dist/graph-ir.js +27 -0
- package/dist/lexicon.d.ts +25 -1
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lint/rules/evl004-spread-non-const.d.ts.map +1 -1
- package/dist/lint/rules/evl004-spread-non-const.js +19 -1
- package/dist/wave-runtime.mjs +222 -206
- package/dist/workspace/checks/links.d.ts +5 -0
- package/dist/workspace/checks/links.d.ts.map +1 -1
- package/dist/workspace/checks/links.js +54 -8
- package/dist/workspace/checks.d.ts +4 -1
- package/dist/workspace/checks.d.ts.map +1 -1
- package/dist/workspace/checks.js +6 -2
- package/dist/workspace/compose-graph.d.ts +4 -1
- package/dist/workspace/compose-graph.d.ts.map +1 -1
- package/dist/workspace/compose-graph.js +3 -2
- package/dist/workspace/dbt-project-reader.d.ts +36 -0
- package/dist/workspace/dbt-project-reader.d.ts.map +1 -0
- package/dist/workspace/dbt-project-reader.js +290 -0
- package/dist/workspace/graph-cli.d.ts.map +1 -1
- package/dist/workspace/graph-cli.js +3 -1
- package/dist/workspace/graph.schema.json +41 -3
- package/dist/workspace/intent.js +7 -2
- package/dist/workspace/kind-link-readers.d.ts +84 -0
- package/dist/workspace/kind-link-readers.d.ts.map +1 -0
- package/dist/workspace/kind-link-readers.js +53 -0
- package/dist/workspace/kinds.d.ts +15 -0
- package/dist/workspace/kinds.d.ts.map +1 -1
- package/dist/workspace/kinds.js +11 -0
- package/dist/workspace/lexicon-outputs.d.ts +63 -0
- package/dist/workspace/lexicon-outputs.d.ts.map +1 -0
- package/dist/workspace/lexicon-outputs.js +241 -0
- package/dist/workspace/links.d.ts +29 -7
- package/dist/workspace/links.d.ts.map +1 -1
- package/dist/workspace/links.js +109 -34
- package/dist/workspace/member-handles.d.ts +18 -1
- package/dist/workspace/member-handles.d.ts.map +1 -1
- package/dist/workspace/member-handles.js +31 -14
- package/dist/workspace/records-checkout.d.ts +11 -1
- package/dist/workspace/records-checkout.d.ts.map +1 -1
- package/dist/workspace/records-checkout.js +38 -2
- package/dist/workspace/status.d.ts.map +1 -1
- package/dist/workspace/status.js +3 -2
- package/dist/workspace/workspace-kinds.schema.json +5 -0
- package/package.json +1 -1
- package/src/audit/rules-doc.ts +1 -1
- package/src/cli/handlers/graph.ts +22 -1
- package/src/codegen/docs-pages.ts +1 -0
- package/src/codegen/docs-sections.ts +8 -0
- package/src/codegen/docs-site/AgentPrompt.astro +153 -0
- package/src/codegen/docs-types.ts +7 -0
- package/src/codegen/docs.ts +27 -0
- package/src/fold/subset.ts +3 -1
- package/src/graph-ir.test.ts +23 -1
- package/src/graph-ir.ts +65 -0
- package/src/lexicon.ts +26 -1
- package/src/lint/rules/evl004-spread-non-const.test.ts +18 -0
- package/src/lint/rules/evl004-spread-non-const.ts +16 -1
- package/src/wave-loop-golden.test.ts +3 -0
- package/src/workspace/checks/links.ts +57 -8
- package/src/workspace/checks.e2e.test.ts +1 -1
- package/src/workspace/checks.ts +9 -2
- package/src/workspace/compose-graph.ts +5 -3
- package/src/workspace/dbt-kind.e2e.test.ts +95 -0
- package/src/workspace/dbt-kind.test.ts +283 -0
- package/src/workspace/dbt-project-reader.ts +291 -0
- package/src/workspace/graph-cli.ts +3 -1
- package/src/workspace/graph.schema.json +41 -3
- package/src/workspace/intent.ts +7 -2
- package/src/workspace/kind-link-readers.ts +109 -0
- package/src/workspace/kinds.ts +21 -1
- package/src/workspace/lexicon-outputs.ts +272 -0
- package/src/workspace/links.test.ts +22 -0
- package/src/workspace/links.ts +129 -34
- package/src/workspace/member-handles.ts +28 -8
- package/src/workspace/records-checkout.ts +36 -2
- package/src/workspace/records-uncommitted.test.ts +5 -1
- package/src/workspace/status.ts +3 -2
- package/src/workspace/workspace-kinds.schema.json +5 -0
|
@@ -181,6 +181,13 @@
|
|
|
181
181
|
},
|
|
182
182
|
"member": {
|
|
183
183
|
"type": "string"
|
|
184
|
+
},
|
|
185
|
+
"previously": {
|
|
186
|
+
"type": "array",
|
|
187
|
+
"items": {
|
|
188
|
+
"type": "string"
|
|
189
|
+
},
|
|
190
|
+
"description": "Names this output had before, from a rename hint a lexicon read in the member's source (a sql `-- previously:` comment). A link to one of them is told the new name."
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
193
|
}
|
|
@@ -636,8 +643,23 @@
|
|
|
636
643
|
"origin": {
|
|
637
644
|
"enum": [
|
|
638
645
|
"declared",
|
|
646
|
+
"kind-reader",
|
|
639
647
|
"inferred:joinKey"
|
|
640
|
-
]
|
|
648
|
+
],
|
|
649
|
+
"description": "How the row was found: declared in chant.workspace.json, read from the member's own files by its kind's link reader (#3932), or inferred by joinKey()."
|
|
650
|
+
},
|
|
651
|
+
"reader": {
|
|
652
|
+
"type": "string",
|
|
653
|
+
"description": "A kind-reader row (#3932): the link reader that found it, such as dbt-project."
|
|
654
|
+
},
|
|
655
|
+
"file": {
|
|
656
|
+
"type": "string",
|
|
657
|
+
"description": "A kind-reader row (#3932): the file that states the link, from the workspace root."
|
|
658
|
+
},
|
|
659
|
+
"line": {
|
|
660
|
+
"type": "integer",
|
|
661
|
+
"minimum": 1,
|
|
662
|
+
"description": "A kind-reader row (#3932): the line of file that states the link."
|
|
641
663
|
},
|
|
642
664
|
"resolves": {
|
|
643
665
|
"const": "source"
|
|
@@ -728,8 +750,23 @@
|
|
|
728
750
|
"origin": {
|
|
729
751
|
"enum": [
|
|
730
752
|
"declared",
|
|
753
|
+
"kind-reader",
|
|
731
754
|
"inferred:joinKey"
|
|
732
|
-
]
|
|
755
|
+
],
|
|
756
|
+
"description": "How the row was found: declared in chant.workspace.json, read from the member's own files by its kind's link reader (#3932), or inferred by joinKey()."
|
|
757
|
+
},
|
|
758
|
+
"reader": {
|
|
759
|
+
"type": "string",
|
|
760
|
+
"description": "A kind-reader row (#3932): the link reader that found it, such as dbt-project."
|
|
761
|
+
},
|
|
762
|
+
"file": {
|
|
763
|
+
"type": "string",
|
|
764
|
+
"description": "A kind-reader row (#3932): the file that states the link, from the workspace root."
|
|
765
|
+
},
|
|
766
|
+
"line": {
|
|
767
|
+
"type": "integer",
|
|
768
|
+
"minimum": 1,
|
|
769
|
+
"description": "A kind-reader row (#3932): the line of file that states the link."
|
|
733
770
|
},
|
|
734
771
|
"resolves": {
|
|
735
772
|
"const": "source"
|
|
@@ -746,7 +783,8 @@
|
|
|
746
783
|
"description": "The consumer's parameter node, when known."
|
|
747
784
|
},
|
|
748
785
|
"input": {
|
|
749
|
-
"type": "string"
|
|
786
|
+
"type": "string",
|
|
787
|
+
"description": "The consumer's parameter the join would feed; for a kind-reader row (#3932), the output its file reads, which no single member was found to produce."
|
|
750
788
|
},
|
|
751
789
|
"status": {
|
|
752
790
|
"const": "ambiguous"
|
package/dist/workspace/intent.js
CHANGED
|
@@ -75,7 +75,7 @@ import { followSquashes, squashLineOrigins } from "./squash.js";
|
|
|
75
75
|
import { memberDirOnDisk, memberSymbolResolvers } from "./lexicon-symbols.js";
|
|
76
76
|
import { resolveSymbol, symbolResolverFor } from "./symbols.js";
|
|
77
77
|
import { readTrailerJoins } from "./trailer-joins.js";
|
|
78
|
-
import { joinPath, skippedDir } from "./tree.js";
|
|
78
|
+
import { joinPath, skippedDir, workingTree } from "./tree.js";
|
|
79
79
|
import { activeAttestors } from "./trust/attestor.js";
|
|
80
80
|
import { commitProvenance, policyAtBase, resolveBase } from "./trust/provenance.js";
|
|
81
81
|
import { locateWorkspace } from "./which-chant.js";
|
|
@@ -1295,7 +1295,12 @@ async function walk(query, head) {
|
|
|
1295
1295
|
try {
|
|
1296
1296
|
const groups = resolveGroups(declaration, located.tree);
|
|
1297
1297
|
const kindsRegistry = loadKindRegistry(declaration.pins, located.rootOnDisk).registry;
|
|
1298
|
-
|
|
1298
|
+
const { gatherLexiconOutputs } = await import("./lexicon-outputs.js");
|
|
1299
|
+
const lexiconOutputs = await gatherLexiconOutputs(located.rootOnDisk, declaration, located.at ? workingTree(located.rootOnDisk) : located.tree, groups, kindsRegistry, {
|
|
1300
|
+
atRevision: located.at !== null,
|
|
1301
|
+
...(query.loadLexicon ? { load: query.loadLexicon } : {}),
|
|
1302
|
+
});
|
|
1303
|
+
rows = resolveLinks(declaration, sourceMemberHandles(declaration, located.tree, groups, kindsRegistry, lexiconOutputs)).filter((r) => r.origin === "declared");
|
|
1299
1304
|
}
|
|
1300
1305
|
catch (err) {
|
|
1301
1306
|
if (!(err instanceof WorkspaceReadError))
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links a kind reads from its member's own files (#3932).
|
|
3
|
+
*
|
|
4
|
+
* A member's links usually come from its entry in `chant.workspace.json`, or
|
|
5
|
+
* are inferred from a chant member's parameters by `joinKey()`. Some members
|
|
6
|
+
* already say what they read in files of their own: a dbt project names the
|
|
7
|
+
* tables it reads in its `sources:` YAML. A kind can name a link reader in its
|
|
8
|
+
* kinds file (`reader`), and chant runs that reader over the member's
|
|
9
|
+
* directory to derive the member's links.
|
|
10
|
+
*
|
|
11
|
+
* The readers are chant's code, listed in {@link KIND_LINK_READERS}: a kinds
|
|
12
|
+
* file stays data, and chant never imports the package that supplies it. A
|
|
13
|
+
* reader runs offline and parses files as data. It never invokes the tool
|
|
14
|
+
* whose files it reads, so `chant workspace check` keeps its promise of no
|
|
15
|
+
* network and no member code.
|
|
16
|
+
*
|
|
17
|
+
* A reader returns links with the file and line that state them, and gaps:
|
|
18
|
+
* the places it could not read without guessing, such as a templated value.
|
|
19
|
+
* `resolveLinks` (`./links.ts`) resolves the links beside the declared ones,
|
|
20
|
+
* with origin `kind-reader`; WSP093 and WSP094 name the reader's file and line,
|
|
21
|
+
* and WSP099 reports the gaps.
|
|
22
|
+
*/
|
|
23
|
+
import type { Declaration, Member } from "./declaration.js";
|
|
24
|
+
import { type FieldValue, type KindLinkReaderName, type KindRegistry } from "./kinds.js";
|
|
25
|
+
import type { WorkspaceTree } from "./tree.js";
|
|
26
|
+
/** One link a reader found in the member's files. */
|
|
27
|
+
export interface KindReadLink {
|
|
28
|
+
/**
|
|
29
|
+
* The producer the link names, or null when the member's files don't say
|
|
30
|
+
* which member produces it. A null producer is found among the members
|
|
31
|
+
* whose outputs include {@link anchor}; see `resolveLinks`.
|
|
32
|
+
*/
|
|
33
|
+
member: string | null;
|
|
34
|
+
/** The producer's output the link reads. */
|
|
35
|
+
output: string;
|
|
36
|
+
/**
|
|
37
|
+
* The output that picks the producer when `member` is null; unset, the
|
|
38
|
+
* output itself. A dbt source column is anchored on its table, so a dropped
|
|
39
|
+
* column is missing from the member that still has the table.
|
|
40
|
+
*/
|
|
41
|
+
anchor?: string;
|
|
42
|
+
/** The file that states the link, relative to the workspace root. */
|
|
43
|
+
file: string;
|
|
44
|
+
/** Its line, from 1. */
|
|
45
|
+
line: number;
|
|
46
|
+
}
|
|
47
|
+
/** A place the reader could not read without guessing. The links it would have stated are left out. */
|
|
48
|
+
export interface KindReadGap {
|
|
49
|
+
/** Relative to the workspace root. */
|
|
50
|
+
file: string;
|
|
51
|
+
line: number;
|
|
52
|
+
message: string;
|
|
53
|
+
}
|
|
54
|
+
export interface KindLinkRead {
|
|
55
|
+
/** The reader that ran. */
|
|
56
|
+
reader: KindLinkReaderName;
|
|
57
|
+
links: KindReadLink[];
|
|
58
|
+
gaps: KindReadGap[];
|
|
59
|
+
/**
|
|
60
|
+
* The member field that names the producer, for messages that ask the
|
|
61
|
+
* author to set it when the files don't say (`sqlMember` for dbt).
|
|
62
|
+
*/
|
|
63
|
+
producerField?: string;
|
|
64
|
+
}
|
|
65
|
+
/** What a reader gets: the member, its directory and resolved fields, and the tree read. */
|
|
66
|
+
export interface KindReaderInput {
|
|
67
|
+
member: Member;
|
|
68
|
+
/** The member's directory, tree-relative; "" for the workspace root. */
|
|
69
|
+
dir: string;
|
|
70
|
+
/** The member's fields, defaults filled in (#3151); null when its kind declares none. */
|
|
71
|
+
fields: Record<string, FieldValue | null | Record<string, FieldValue | null>> | null;
|
|
72
|
+
tree: WorkspaceTree;
|
|
73
|
+
}
|
|
74
|
+
export type KindLinkReader = (input: KindReaderInput) => KindLinkRead;
|
|
75
|
+
/** Every reader chant ships, by the name a kinds file uses. */
|
|
76
|
+
export declare const LINK_READERS: Record<KindLinkReaderName, KindLinkReader>;
|
|
77
|
+
/**
|
|
78
|
+
* Run the link reader of every member whose kind has one. A member whose
|
|
79
|
+
* directory is missing is left out. A reader that throws is reported as a
|
|
80
|
+
* gap on the member's directory, so one unreadable project never stops
|
|
81
|
+
* the check.
|
|
82
|
+
*/
|
|
83
|
+
export declare function readKindLinks(declaration: Declaration, tree: WorkspaceTree, kinds: KindRegistry): Map<string, KindLinkRead>;
|
|
84
|
+
//# sourceMappingURL=kind-link-readers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kind-link-readers.d.ts","sourceRoot":"","sources":["../../src/workspace/kind-link-readers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAuB,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,KAAK,YA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AAE,WAAW,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,GAAG,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAe3H"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Links a kind reads from its member's own files (#3932).
|
|
3
|
+
*
|
|
4
|
+
* A member's links usually come from its entry in `chant.workspace.json`, or
|
|
5
|
+
* are inferred from a chant member's parameters by `joinKey()`. Some members
|
|
6
|
+
* already say what they read in files of their own: a dbt project names the
|
|
7
|
+
* tables it reads in its `sources:` YAML. A kind can name a link reader in its
|
|
8
|
+
* kinds file (`reader`), and chant runs that reader over the member's
|
|
9
|
+
* directory to derive the member's links.
|
|
10
|
+
*
|
|
11
|
+
* The readers are chant's code, listed in {@link KIND_LINK_READERS}: a kinds
|
|
12
|
+
* file stays data, and chant never imports the package that supplies it. A
|
|
13
|
+
* reader runs offline and parses files as data. It never invokes the tool
|
|
14
|
+
* whose files it reads, so `chant workspace check` keeps its promise of no
|
|
15
|
+
* network and no member code.
|
|
16
|
+
*
|
|
17
|
+
* A reader returns links with the file and line that state them, and gaps:
|
|
18
|
+
* the places it could not read without guessing, such as a templated value.
|
|
19
|
+
* `resolveLinks` (`./links.ts`) resolves the links beside the declared ones,
|
|
20
|
+
* with origin `kind-reader`; WSP093 and WSP094 name the reader's file and line,
|
|
21
|
+
* and WSP099 reports the gaps.
|
|
22
|
+
*/
|
|
23
|
+
import { resolveMemberFields } from "./kinds.js";
|
|
24
|
+
import { readDbtProject } from "./dbt-project-reader.js";
|
|
25
|
+
/** Every reader chant ships, by the name a kinds file uses. */
|
|
26
|
+
export const LINK_READERS = {
|
|
27
|
+
"dbt-project": readDbtProject,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Run the link reader of every member whose kind has one. A member whose
|
|
31
|
+
* directory is missing is left out. A reader that throws is reported as a
|
|
32
|
+
* gap on the member's directory, so one unreadable project never stops
|
|
33
|
+
* the check.
|
|
34
|
+
*/
|
|
35
|
+
export function readKindLinks(declaration, tree, kinds) {
|
|
36
|
+
const out = new Map();
|
|
37
|
+
for (const m of declaration.members) {
|
|
38
|
+
const kind = kinds.get(m.kind);
|
|
39
|
+
if (!kind?.reader)
|
|
40
|
+
continue;
|
|
41
|
+
const dir = m.dir === "." ? "" : m.dir;
|
|
42
|
+
if (tree.stat(dir) !== "dir")
|
|
43
|
+
continue;
|
|
44
|
+
const { fields } = resolveMemberFields(kind, m.fields);
|
|
45
|
+
try {
|
|
46
|
+
out.set(m.name, LINK_READERS[kind.reader]({ member: m, dir, fields, tree }));
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
out.set(m.name, { reader: kind.reader, links: [], gaps: [{ file: dir || ".", line: 1, message: `the ${kind.reader} reader failed: ${err.message}` }] });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
@@ -128,7 +128,22 @@ export interface MemberKind {
|
|
|
128
128
|
graph?: KindGraph;
|
|
129
129
|
/** The fields a member entry of this kind may set, with their defaults (#3151); unset, the kind declares none. */
|
|
130
130
|
fields?: Record<string, KindField>;
|
|
131
|
+
/**
|
|
132
|
+
* The link reader chant runs over a member's own files (#3932), by name, from
|
|
133
|
+
* {@link KIND_LINK_READERS}. It derives the member's links offline, from
|
|
134
|
+
* files it parses as data; unset, the member's links are only those its
|
|
135
|
+
* entry states.
|
|
136
|
+
*/
|
|
137
|
+
reader?: KindLinkReaderName;
|
|
131
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* The link readers chant ships (#3932). A kind names one in its kinds file as
|
|
141
|
+
* `reader`. The readers are chant's own code, not the package's: a kinds file
|
|
142
|
+
* stays data, and chant never imports the package that supplies it. Closed:
|
|
143
|
+
* a kind naming another reader is kept without one, and the load reports it.
|
|
144
|
+
*/
|
|
145
|
+
export declare const KIND_LINK_READERS: readonly ["dbt-project"];
|
|
146
|
+
export type KindLinkReaderName = (typeof KIND_LINK_READERS)[number];
|
|
132
147
|
export interface KindRegistry {
|
|
133
148
|
get(name: string): MemberKind | undefined;
|
|
134
149
|
/** Every member kind's name, sorted, for "unknown kind" messages. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../../src/workspace/kinds.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAG5C,OAAO,EAAoB,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGtE,eAAO,MAAM,eAAe,QAAa,CAAC;AAE1C,oDAAoD;AACpD,eAAO,MAAM,aAAa,sBAAsB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,WAAW,SAAS;IACxB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,EAAE,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;IAC9C;;;;;OAKG;IACH,UAAU,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CACnD;AAED,kFAAkF;AAClF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IACpC,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,+EAA+E;AAC/E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAC7C;AAED,MAAM,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AQ,EAAE,YAAY,CAAC;IACvB,QAAQ,EAAE,eAAe,EAAE,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAsBlI;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,EAAE,aAAa,EAAE,MAAM,GAAG,WAAW,CA4B7F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAcxE;AAID,6EAA6E;AAC7E,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAyCnD,sGAAsG;AACtG,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,uIAAuI;IACvI,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IACrF,QAAQ,EAAE,kBAAkB,EAAE,CAAC;CAChC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,YAAY,CAsCrH"}
|
package/dist/workspace/kinds.js
CHANGED
|
@@ -26,6 +26,13 @@ import { loadAjv2020 } from "./ajv2020.js";
|
|
|
26
26
|
export const KINDS_SCHEMA_ID = schema.$id;
|
|
27
27
|
/** The subpath a package publishes its kinds at. */
|
|
28
28
|
export const KINDS_SUBPATH = "./workspace-kinds";
|
|
29
|
+
/**
|
|
30
|
+
* The link readers chant ships (#3932). A kind names one in its kinds file as
|
|
31
|
+
* `reader`. The readers are chant's own code, not the package's: a kinds file
|
|
32
|
+
* stays data, and chant never imports the package that supplies it. Closed:
|
|
33
|
+
* a kind naming another reader is kept without one, and the load reports it.
|
|
34
|
+
*/
|
|
35
|
+
export const KIND_LINK_READERS = ["dbt-project"];
|
|
29
36
|
/** The group kind (ws-051). An entry of this kind is a group, not a member. */
|
|
30
37
|
export const EXAMPLES_KIND = "examples";
|
|
31
38
|
/** The data member kind that holds design artifacts (#2549, ws-062). */
|
|
@@ -274,7 +281,11 @@ export function parseKindData(text, source) {
|
|
|
274
281
|
source,
|
|
275
282
|
...(k.graph ? { graph: { lexicon: k.graph.lexicon, config: structuredClone(k.graph.config) } } : {}),
|
|
276
283
|
...(k.fields ? { fields: structuredClone(k.fields) } : {}),
|
|
284
|
+
...(k.reader && KIND_LINK_READERS.includes(k.reader) ? { reader: k.reader } : {}),
|
|
277
285
|
});
|
|
286
|
+
if (k.reader && !KIND_LINK_READERS.includes(k.reader)) {
|
|
287
|
+
problems.push(`${source}: kind ${k.name} names link reader ${k.reader}, which this chant does not have (it has ${KIND_LINK_READERS.join(", ")}); the kind is kept, and its members' links are only those their entries state`);
|
|
288
|
+
}
|
|
278
289
|
for (const problem of fieldDefaultProblems(k.fields ?? {}))
|
|
279
290
|
problems.push(`${source}: kind ${k.name} ${problem}`);
|
|
280
291
|
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outputs a member's lexicons report about their own declarations
|
|
3
|
+
* (#3931), read offline for `chant workspace check`.
|
|
4
|
+
*
|
|
5
|
+
* A sql member exposes each table and each column as a workspace output
|
|
6
|
+
* (`public.orders`, `public.orders.customer_id`) without anyone writing
|
|
7
|
+
* `output(...)`. The names are the lexicon's to give, so the lexicon answers
|
|
8
|
+
* through its `workspaceOutputs` hook, the way a CI lexicon answers
|
|
9
|
+
* `graphEdges` (#3910).
|
|
10
|
+
*
|
|
11
|
+
* The check never runs member code. The member's source files are folded
|
|
12
|
+
* with `foldProject` under `sandbox`, which evaluates the fold subset and
|
|
13
|
+
* imports nothing from the project: a sql `table` template becomes the real
|
|
14
|
+
* entity because the tag is the lexicon's own function, called with the
|
|
15
|
+
* folded parts. A file that does not fold is not run either. It is handed to
|
|
16
|
+
* the hook as unread, and when it is one of that lexicon's files (it uses the
|
|
17
|
+
* lexicon's tags), the hook records a gap: the member's outputs are then
|
|
18
|
+
* incomplete, and a link to a name not in them is unresolved rather than
|
|
19
|
+
* missing.
|
|
20
|
+
*
|
|
21
|
+
* Folding is asynchronous and the checks are not, so the outputs are
|
|
22
|
+
* gathered before the checks run, only for the members some declared link
|
|
23
|
+
* targets, and only for the kinds whose outputs are read from source.
|
|
24
|
+
*
|
|
25
|
+
* Under `--at` the revision's files are not on disk to fold, so a member
|
|
26
|
+
* whose lexicons report outputs gets a gap instead.
|
|
27
|
+
*/
|
|
28
|
+
import { type Declarable } from "../declarable.js";
|
|
29
|
+
import type { LexiconUnreadSource, LexiconWorkspaceOutput } from "../graph-ir.js";
|
|
30
|
+
import type { BuildRootContext, BuildRootContribution, IntrinsicDef } from "../lexicon.js";
|
|
31
|
+
import type { Declaration, ResolvedGroup } from "./declaration.js";
|
|
32
|
+
import type { KindRegistry } from "./kinds.js";
|
|
33
|
+
import type { WorkspaceTree } from "./tree.js";
|
|
34
|
+
/** What one member's lexicons report: its outputs, and why the list may be incomplete. */
|
|
35
|
+
export interface MemberLexiconOutputs {
|
|
36
|
+
outputs: Pick<LexiconWorkspaceOutput, "name" | "previously">[];
|
|
37
|
+
gaps: string[];
|
|
38
|
+
}
|
|
39
|
+
/** The part of a lexicon plugin this reader uses. */
|
|
40
|
+
export interface OutputsPlugin {
|
|
41
|
+
name?: string;
|
|
42
|
+
intrinsics?: () => IntrinsicDef[];
|
|
43
|
+
buildRoots?: (ctx: BuildRootContext) => Promise<BuildRootContribution>;
|
|
44
|
+
workspaceOutputs?: (entities: ReadonlyMap<string, Declarable>, unread?: readonly LexiconUnreadSource[]) => {
|
|
45
|
+
outputs: LexiconWorkspaceOutput[];
|
|
46
|
+
gaps?: string[];
|
|
47
|
+
} | undefined;
|
|
48
|
+
}
|
|
49
|
+
/** Loads a lexicon plugin by name; `loadPlugin` from the CLI unless a test swaps it. */
|
|
50
|
+
export type OutputsPluginLoader = (name: string) => Promise<OutputsPlugin>;
|
|
51
|
+
export interface GatherLexiconOutputsOptions {
|
|
52
|
+
/** Read under `--at`: the member's files are a revision's, not on disk, so nothing is folded. */
|
|
53
|
+
atRevision?: boolean;
|
|
54
|
+
load?: OutputsPluginLoader;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The lexicon outputs of every member a declared link, or a link a kind's
|
|
58
|
+
* reader found (#3932), targets, keyed by
|
|
59
|
+
* member name. A member whose lexicons report nothing is left out.
|
|
60
|
+
* `tree` is the working tree under `root`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function gatherLexiconOutputs(root: string, declaration: Declaration, tree: WorkspaceTree, groups: readonly ResolvedGroup[], kinds: KindRegistry, options?: GatherLexiconOutputsOptions): Promise<Map<string, MemberLexiconOutputs>>;
|
|
63
|
+
//# sourceMappingURL=lexicon-outputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lexicon-outputs.d.ts","sourceRoot":"","sources":["../../src/workspace/lexicon-outputs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,KAAK,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AACxF,OAAO,KAAK,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G,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAmB5C"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The outputs a member's lexicons report about their own declarations
|
|
3
|
+
* (#3931), read offline for `chant workspace check`.
|
|
4
|
+
*
|
|
5
|
+
* A sql member exposes each table and each column as a workspace output
|
|
6
|
+
* (`public.orders`, `public.orders.customer_id`) without anyone writing
|
|
7
|
+
* `output(...)`. The names are the lexicon's to give, so the lexicon answers
|
|
8
|
+
* through its `workspaceOutputs` hook, the way a CI lexicon answers
|
|
9
|
+
* `graphEdges` (#3910).
|
|
10
|
+
*
|
|
11
|
+
* The check never runs member code. The member's source files are folded
|
|
12
|
+
* with `foldProject` under `sandbox`, which evaluates the fold subset and
|
|
13
|
+
* imports nothing from the project: a sql `table` template becomes the real
|
|
14
|
+
* entity because the tag is the lexicon's own function, called with the
|
|
15
|
+
* folded parts. A file that does not fold is not run either. It is handed to
|
|
16
|
+
* the hook as unread, and when it is one of that lexicon's files (it uses the
|
|
17
|
+
* lexicon's tags), the hook records a gap: the member's outputs are then
|
|
18
|
+
* incomplete, and a link to a name not in them is unresolved rather than
|
|
19
|
+
* missing.
|
|
20
|
+
*
|
|
21
|
+
* Folding is asynchronous and the checks are not, so the outputs are
|
|
22
|
+
* gathered before the checks run, only for the members some declared link
|
|
23
|
+
* targets, and only for the kinds whose outputs are read from source.
|
|
24
|
+
*
|
|
25
|
+
* Under `--at` the revision's files are not on disk to fold, so a member
|
|
26
|
+
* whose lexicons report outputs gets a gap instead.
|
|
27
|
+
*/
|
|
28
|
+
import { join, posix } from "node:path";
|
|
29
|
+
import { isDeclarable } from "../declarable.js";
|
|
30
|
+
import { kindHandles } from "./links.js";
|
|
31
|
+
import { readKindLinks } from "./kind-link-readers.js";
|
|
32
|
+
import { memberExcludes, sourceFiles } from "./member-handles.js";
|
|
33
|
+
import { memberDirOnDisk } from "./lexicon-symbols.js";
|
|
34
|
+
const firstLine = (err) => (err instanceof Error ? err.message : String(err)).split("\n")[0];
|
|
35
|
+
const memberDir = (dir) => (dir === "." ? "" : dir);
|
|
36
|
+
/** The `sourceDir` a member's config sets, read without running it. */
|
|
37
|
+
function staticSourceDir(read) {
|
|
38
|
+
const value = read.status === "read" ? read.fields.sourceDir : undefined;
|
|
39
|
+
if (typeof value !== "string")
|
|
40
|
+
return undefined;
|
|
41
|
+
const dir = posix.normalize(value.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
42
|
+
return dir === "." || dir === "" ? undefined : dir;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Only the files under the member's `sourceDir`, when its config sets one, as
|
|
46
|
+
* a build reads them (#3941). Without one, every source file of the member.
|
|
47
|
+
*/
|
|
48
|
+
function withinSourceDir(files, member, sourceDir) {
|
|
49
|
+
if (!sourceDir)
|
|
50
|
+
return files;
|
|
51
|
+
const prefix = `${member ? `${member}/` : ""}${sourceDir}/`;
|
|
52
|
+
return files.filter((f) => f.startsWith(prefix));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A folded file's exports, less the entities of lexicons the member doesn't
|
|
56
|
+
* declare (#3941). An Op is a `chant` entity, and several files exporting
|
|
57
|
+
* `op` would otherwise collide and leave the whole member unread, though no
|
|
58
|
+
* hook reads Ops. Values that are not entities (a composite) are kept.
|
|
59
|
+
*/
|
|
60
|
+
function ownExports(exports, lexicons) {
|
|
61
|
+
const own = new Set(lexicons);
|
|
62
|
+
const out = {};
|
|
63
|
+
for (const [name, value] of exports) {
|
|
64
|
+
if (isDeclarable(value) && !own.has(value.lexicon))
|
|
65
|
+
continue;
|
|
66
|
+
out[name] = value;
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The lexicon names a member's config declares, read without running it.
|
|
72
|
+
* Unlike the intent walk, a config that can't be read statically is not
|
|
73
|
+
* loaded: the check runs no member code, so it is a gap.
|
|
74
|
+
*/
|
|
75
|
+
async function staticMemberLexicons(dir) {
|
|
76
|
+
const { readLexiconDeclarationsStatically } = await import("../config-static.js");
|
|
77
|
+
const read = readLexiconDeclarationsStatically(dir);
|
|
78
|
+
if (read.status === "no-config")
|
|
79
|
+
return [];
|
|
80
|
+
if (read.status !== "read")
|
|
81
|
+
throw new Error(read.reason);
|
|
82
|
+
const { lexiconNames, registerLexiconDeclarations } = await import("../lexicon-module.js");
|
|
83
|
+
const { dirname } = await import("node:path");
|
|
84
|
+
registerLexiconDeclarations(read.entries, dirname(read.configPath));
|
|
85
|
+
return lexiconNames(read.entries);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The lexicon outputs of every member a declared link, or a link a kind's
|
|
89
|
+
* reader found (#3932), targets, keyed by
|
|
90
|
+
* member name. A member whose lexicons report nothing is left out.
|
|
91
|
+
* `tree` is the working tree under `root`.
|
|
92
|
+
*/
|
|
93
|
+
export async function gatherLexiconOutputs(root, declaration, tree, groups, kinds, options = {}) {
|
|
94
|
+
const out = new Map();
|
|
95
|
+
const targets = new Set(declaration.members.flatMap((m) => m.links.filter((l) => l.member !== m.name).map((l) => l.member)));
|
|
96
|
+
// Links a kind's reader finds in a member's files target members too (#3932). One that names no
|
|
97
|
+
// producer may be any other member's, so every other member is read.
|
|
98
|
+
for (const [consumer, read] of readKindLinks(declaration, tree, kinds)) {
|
|
99
|
+
for (const link of read.links) {
|
|
100
|
+
if (link.member !== null)
|
|
101
|
+
targets.add(link.member);
|
|
102
|
+
else
|
|
103
|
+
for (const m of declaration.members)
|
|
104
|
+
if (m.name !== consumer)
|
|
105
|
+
targets.add(m.name);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
for (const m of declaration.members) {
|
|
109
|
+
if (!targets.has(m.name))
|
|
110
|
+
continue;
|
|
111
|
+
const kind = kinds.get(m.kind);
|
|
112
|
+
if (!kind || kindHandles(m, kind) || tree.stat(memberDir(m.dir)) !== "dir")
|
|
113
|
+
continue;
|
|
114
|
+
const read = await readMemberLexiconOutputs(root, declaration, tree, groups, m, options);
|
|
115
|
+
if (read)
|
|
116
|
+
out.set(m.name, read);
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
/** The lexicons the files import, by the package name chant gives a lexicon. */
|
|
121
|
+
function importedLexicons(tree, files) {
|
|
122
|
+
const names = new Set();
|
|
123
|
+
for (const file of files) {
|
|
124
|
+
let text;
|
|
125
|
+
try {
|
|
126
|
+
text = tree.read(file);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
for (const m of text.matchAll(/from\s+["']@intentius\/chant-lexicon-([a-z0-9-]+)(?:\/[^"']*)?["']/g))
|
|
132
|
+
names.add(m[1]);
|
|
133
|
+
}
|
|
134
|
+
return [...names].sort();
|
|
135
|
+
}
|
|
136
|
+
async function readMemberLexiconOutputs(root, declaration, tree, groups, m, options) {
|
|
137
|
+
const dir = memberDirOnDisk(root, m.dir);
|
|
138
|
+
const { readConfigFieldsStatically } = await import("../config-static.js");
|
|
139
|
+
const files = withinSourceDir(sourceFiles(tree, memberDir(m.dir), memberExcludes(declaration, groups, m)), memberDir(m.dir), staticSourceDir(readConfigFieldsStatically(dir, ["sourceDir"])));
|
|
140
|
+
let names;
|
|
141
|
+
try {
|
|
142
|
+
names = await staticMemberLexicons(dir);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// A config that can't be read statically is not run. The lexicons the
|
|
146
|
+
// source imports stand in for the ones it names.
|
|
147
|
+
names = importedLexicons(tree, files);
|
|
148
|
+
}
|
|
149
|
+
if (names.length === 0)
|
|
150
|
+
return undefined;
|
|
151
|
+
const load = options.load ?? (await import("../cli/plugins.js")).loadPlugin;
|
|
152
|
+
const plugins = [];
|
|
153
|
+
const gaps = [];
|
|
154
|
+
for (const name of names) {
|
|
155
|
+
try {
|
|
156
|
+
plugins.push({ name, plugin: await load(name) });
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
gaps.push(`lexicon "${name}" could not be loaded, so the outputs it reads were not (${firstLine(err)})`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
const reporting = plugins.filter((p) => typeof p.plugin.workspaceOutputs === "function");
|
|
163
|
+
if (reporting.length === 0)
|
|
164
|
+
return gaps.length ? { outputs: [], gaps } : undefined;
|
|
165
|
+
if (options.atRevision) {
|
|
166
|
+
return { outputs: [], gaps: [`the outputs of lexicon ${reporting.map((p) => p.name).join(", ")} are read from the working tree's files, not a revision's`] };
|
|
167
|
+
}
|
|
168
|
+
// Fold the member's source, never run it.
|
|
169
|
+
const abs = (file) => join(root, ...file.split("/"));
|
|
170
|
+
const intrinsics = plugins.flatMap((p) => {
|
|
171
|
+
try {
|
|
172
|
+
return p.plugin.intrinsics?.() ?? [];
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return [];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
let entities = new Map();
|
|
179
|
+
const unread = [];
|
|
180
|
+
try {
|
|
181
|
+
const { foldProject } = await import("../discovery/fold-import.js");
|
|
182
|
+
const { collectEntities } = await import("../discovery/collect.js");
|
|
183
|
+
const verdicts = await foldProject(files.map(abs), intrinsics, { lexicons: names, sandbox: true });
|
|
184
|
+
const folded = [];
|
|
185
|
+
for (const file of files) {
|
|
186
|
+
const v = verdicts.get(abs(file));
|
|
187
|
+
if (v?.verdict === "fold" && v.exports) {
|
|
188
|
+
folded.push({ file: abs(file), exports: ownExports(v.exports, names) });
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
let text = "";
|
|
192
|
+
try {
|
|
193
|
+
text = tree.read(file);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
// An unreadable file is still unread; the hook decides whether it matters.
|
|
197
|
+
}
|
|
198
|
+
const reason = v?.reason ?? (v?.taintedBy ? `it imports ${v.taintedBy.from}, which does not fold` : "it does not fold");
|
|
199
|
+
unread.push({ file, text, reason });
|
|
200
|
+
}
|
|
201
|
+
entities = collectEntities(folded, dir);
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
return { outputs: [], gaps: [...gaps, `${m.dir}: its source could not be folded, so its lexicons' outputs were not read (${firstLine(err)})`] };
|
|
205
|
+
}
|
|
206
|
+
// A reporting lexicon's own build roots (the sql lexicon's `.sql` files) join
|
|
207
|
+
// the folded entities, as they join a build's. Only these lexicons' hooks
|
|
208
|
+
// run: they read files, and start nothing.
|
|
209
|
+
for (const { name, plugin } of reporting) {
|
|
210
|
+
if (typeof plugin.buildRoots !== "function")
|
|
211
|
+
continue;
|
|
212
|
+
const read = readConfigFieldsStatically(dir, [name, "sourceDir"]);
|
|
213
|
+
const config = read.status === "read" ? read.fields : {};
|
|
214
|
+
const sourceDir = typeof config.sourceDir === "string" ? join(dir, config.sourceDir) : undefined;
|
|
215
|
+
try {
|
|
216
|
+
const contributed = await plugin.buildRoots({ projectRoot: dir, config, entities, ...(sourceDir ? { sourceDir } : {}) });
|
|
217
|
+
for (const [key, entity] of contributed.entities)
|
|
218
|
+
if (!entities.has(key))
|
|
219
|
+
entities.set(key, entity);
|
|
220
|
+
}
|
|
221
|
+
catch (err) {
|
|
222
|
+
gaps.push(`lexicon "${name}" could not read the member's other source files, so their declarations were not read (${firstLine(err)})`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const outputs = [];
|
|
226
|
+
for (const { name, plugin } of reporting) {
|
|
227
|
+
try {
|
|
228
|
+
const report = plugin.workspaceOutputs(entities, unread);
|
|
229
|
+
if (!report)
|
|
230
|
+
continue;
|
|
231
|
+
for (const o of report.outputs)
|
|
232
|
+
outputs.push({ name: o.name, ...(o.previously?.length ? { previously: o.previously } : {}) });
|
|
233
|
+
for (const g of report.gaps ?? [])
|
|
234
|
+
gaps.push(g);
|
|
235
|
+
}
|
|
236
|
+
catch (err) {
|
|
237
|
+
gaps.push(`lexicon "${name}" workspaceOutputs threw, so its outputs were not read (${firstLine(err)})`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return { outputs, gaps };
|
|
241
|
+
}
|