@pbuilder/sdk 0.19.0 → 0.20.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/README.md +46 -3
- package/dist/acl/irwire/stdio-engine-client.d.ts +1 -0
- package/dist/acl/irwire/stdio-engine-client.js +9 -0
- package/dist/bin/pbuilder-codegen.js +90 -18
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +15 -0
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +17 -0
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.d.ts +16 -3
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.js +45 -11
- package/dist/bounded-contexts/authoring/domain/aggregates/session/session.d.ts +3 -1
- package/dist/bounded-contexts/authoring/domain/aggregates/session/session.js +10 -1
- package/dist/bounded-contexts/authoring/domain/ports/engine-client.d.ts +1 -0
- package/dist/bounded-contexts/authoring/domain/services/define-dialect.d.ts +28 -1
- package/dist/bounded-contexts/authoring/domain/services/define-dialect.js +27 -3
- package/dist/bounded-contexts/authoring/domain/services/evaluation.d.ts +29 -0
- package/dist/bounded-contexts/authoring/domain/services/evaluation.js +43 -0
- package/dist/bounded-contexts/authoring/domain/services/glob-match.d.ts +4 -0
- package/dist/bounded-contexts/authoring/domain/services/glob-match.js +81 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/input-rejection.d.ts +1 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/input-rejection.js +4 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-validate.d.ts +2 -1
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-validate.js +6 -2
- package/dist/bounded-contexts/authoring/domain/valueobjects/findings.d.ts +12 -0
- package/dist/bounded-contexts/authoring/domain/valueobjects/findings.js +57 -0
- package/dist/bounded-contexts/authoring/domain/valueobjects/schema-model.d.ts +2 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +7 -2
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +28 -7
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +6 -2
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +23 -13
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +1 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +5 -2
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +2 -1
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +1 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/csharp/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/csharp/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +15 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +14 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +15 -0
- package/dist/bounded-contexts/authoring/testing/contract-fake.d.ts +1 -0
- package/dist/bounded-contexts/authoring/testing/contract-fake.js +8 -0
- package/dist/bounded-contexts/authoring/testing/glob-pattern.d.ts +5 -0
- package/dist/bounded-contexts/authoring/testing/glob-pattern.js +20 -0
- package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +8 -0
- package/dist/bounded-contexts/authoring/testing/harness/index.js +12 -1
- package/dist/bounded-contexts/authoring/testing/run-vehicle.d.ts +1 -0
- package/dist/bounded-contexts/authoring/testing/run-vehicle.js +4 -0
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/bootstrap-bridge.d.ts +3 -0
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/bootstrap-bridge.js +4 -0
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/runner.js +15 -3
- package/dist/runner-manifest.json +33 -9
- package/dist/shared-kernel/wire-protocol.d.ts +1 -1
- package/dist/shared-kernel/wire-protocol.js +1 -1
- package/package.json +1 -1
|
@@ -13,8 +13,13 @@
|
|
|
13
13
|
// "don't care about the concrete Ast" erasure this bare form needs.
|
|
14
14
|
import { basename } from "node:path";
|
|
15
15
|
import { createDialectHandle } from "../entities/dialect-handle.js";
|
|
16
|
+
import { currentRun } from "./run-context.js";
|
|
16
17
|
import { dialectError } from "../valueobjects/dialect-error.js";
|
|
17
18
|
export { query } from "../entities/dialect-handle.js";
|
|
19
|
+
/** The paths a `glob` of the active run lists, after the run's buffered writes (A-131). */
|
|
20
|
+
function listed(pattern, options) {
|
|
21
|
+
return currentRun().session.list(pattern, options?.ignore);
|
|
22
|
+
}
|
|
18
23
|
/**
|
|
19
24
|
* Declares a named collection of ops over one AST type — usable standalone (REQ-DG-02.3),
|
|
20
25
|
* e.g. shareable across two dialects targeting the same AST type, before any `withOps`
|
|
@@ -54,7 +59,7 @@ export function defineDialect(d) {
|
|
|
54
59
|
// The handle spreads its ops over its verbs, so an op named after a verb would replace it.
|
|
55
60
|
for (const name of Object.keys(d.ops))
|
|
56
61
|
assertNotReserved(name);
|
|
57
|
-
|
|
62
|
+
const dialect = {
|
|
58
63
|
name: d.name,
|
|
59
64
|
extensions: d.extensions,
|
|
60
65
|
ast: d.ast,
|
|
@@ -65,7 +70,13 @@ export function defineDialect(d) {
|
|
|
65
70
|
}
|
|
66
71
|
return createDialectHandle(d.ast, d.ops, path, d.name);
|
|
67
72
|
},
|
|
73
|
+
// A-133: written once here, so every dialect built from a descriptor has it.
|
|
74
|
+
async glob(pattern, options) {
|
|
75
|
+
const paths = await listed(pattern, options);
|
|
76
|
+
return paths.filter((path) => hasDeclaredExtension(path, d.extensions)).map((path) => dialect.find(path));
|
|
77
|
+
},
|
|
68
78
|
};
|
|
79
|
+
return dialect;
|
|
69
80
|
}
|
|
70
81
|
/**
|
|
71
82
|
* Defines an author-defined dialect, named by the package that ships it (A-16): a factory opens
|
|
@@ -209,16 +220,29 @@ export function byExtension(dialects) {
|
|
|
209
220
|
if (!declared.includes(extension)) {
|
|
210
221
|
throw new Error(`dialect routing failed: "${extension}" is not an extension its dialect declares (${declared.join(", ")}).`);
|
|
211
222
|
}
|
|
223
|
+
// A-134: the routing key is set as `extension` on every handle, over any op of that name.
|
|
224
|
+
if (Object.hasOwn(dialects[extension].ops, "extension")) {
|
|
225
|
+
throw new Error(`dialect routing failed: the dialect of "${extension}" has an op named "extension", the field that carries the routing key on its handles.`);
|
|
226
|
+
}
|
|
212
227
|
}
|
|
213
228
|
const longestFirst = [...extensions].sort((a, b) => b.length - a.length);
|
|
229
|
+
const routeOf = (path) => longestFirst.find((candidate) => hasDeclaredExtension(path, [candidate]));
|
|
230
|
+
const open = (path, extension) => Object.assign(dialects[extension].find(path), { extension });
|
|
214
231
|
return {
|
|
215
232
|
extensions,
|
|
216
233
|
find(path) {
|
|
217
|
-
const extension =
|
|
234
|
+
const extension = routeOf(path);
|
|
218
235
|
if (extension === undefined) {
|
|
219
236
|
throw dialectError(`find(${JSON.stringify(path)}) — the file's extension is not one this dialect declares (${extensions.join(", ")}).`);
|
|
220
237
|
}
|
|
221
|
-
return
|
|
238
|
+
return open(path, extension);
|
|
239
|
+
},
|
|
240
|
+
async glob(pattern, options) {
|
|
241
|
+
const paths = await listed(pattern, options);
|
|
242
|
+
return paths.flatMap((path) => {
|
|
243
|
+
const extension = routeOf(path);
|
|
244
|
+
return extension === undefined ? [] : [open(path, extension)];
|
|
245
|
+
});
|
|
222
246
|
},
|
|
223
247
|
};
|
|
224
248
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Whether a workspace-relative path is in the scope. */
|
|
2
|
+
export type InScope = (path: string) => boolean;
|
|
3
|
+
/**
|
|
4
|
+
* The scope `include` less `exclude` names, or no scope when neither is given. A problem names the
|
|
5
|
+
* scope input that is not an array of strings.
|
|
6
|
+
*/
|
|
7
|
+
export declare function scopeOf(input: unknown): {
|
|
8
|
+
readonly inScope?: InScope;
|
|
9
|
+
} | {
|
|
10
|
+
readonly problem: string;
|
|
11
|
+
};
|
|
12
|
+
type Finding = {
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The Findings a factory returned, already checked against SOURCED_FINDINGS: each kept finding
|
|
17
|
+
* gets `source`, and one whose `path` falls outside the scope is dropped. A problem names the first
|
|
18
|
+
* finding whose author set `source`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function handedOnFindings(findings: {
|
|
21
|
+
readonly items: readonly Finding[];
|
|
22
|
+
}, source: string, inScope: InScope | undefined): {
|
|
23
|
+
readonly result: {
|
|
24
|
+
items: Finding[];
|
|
25
|
+
};
|
|
26
|
+
} | {
|
|
27
|
+
readonly problem: string;
|
|
28
|
+
};
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// The run-boundary side of the role `evaluation`: the scope its inputs name (A-122, A-123) and
|
|
2
|
+
// the Findings it hands on, each with the `source` the SDK sets (A-121) and inside the scope (A-124).
|
|
3
|
+
import { isPlainObject } from "../valueobjects/schema-model.js";
|
|
4
|
+
import { globMatcher } from "./glob-match.js";
|
|
5
|
+
function globsOf(record, name) {
|
|
6
|
+
const value = Object.hasOwn(record, name) ? record[name] : undefined;
|
|
7
|
+
if (value === undefined)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (!Array.isArray(value) || !value.every((entry) => typeof entry === "string")) {
|
|
10
|
+
return `invalid input: ${name} must be an array of strings`;
|
|
11
|
+
}
|
|
12
|
+
return value.map(globMatcher);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The scope `include` less `exclude` names, or no scope when neither is given. A problem names the
|
|
16
|
+
* scope input that is not an array of strings.
|
|
17
|
+
*/
|
|
18
|
+
export function scopeOf(input) {
|
|
19
|
+
const record = isPlainObject(input) ? input : {};
|
|
20
|
+
const include = globsOf(record, "include");
|
|
21
|
+
if (typeof include === "string")
|
|
22
|
+
return { problem: include };
|
|
23
|
+
const exclude = globsOf(record, "exclude");
|
|
24
|
+
if (typeof exclude === "string")
|
|
25
|
+
return { problem: exclude };
|
|
26
|
+
if (include === undefined && exclude === undefined)
|
|
27
|
+
return {};
|
|
28
|
+
return {
|
|
29
|
+
inScope: (path) => (include === undefined || include.some((matches) => matches(path))) && !(exclude ?? []).some((matches) => matches(path)),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The Findings a factory returned, already checked against SOURCED_FINDINGS: each kept finding
|
|
34
|
+
* gets `source`, and one whose `path` falls outside the scope is dropped. A problem names the first
|
|
35
|
+
* finding whose author set `source`.
|
|
36
|
+
*/
|
|
37
|
+
export function handedOnFindings(findings, source, inScope) {
|
|
38
|
+
const sourced = findings.items.findIndex((finding) => Object.hasOwn(finding, "source"));
|
|
39
|
+
if (sourced !== -1)
|
|
40
|
+
return { problem: `Result.items[${sourced}].source is set by the SDK, and a finding may not set it` };
|
|
41
|
+
const kept = findings.items.filter((finding) => inScope === undefined || typeof finding.path !== "string" || inScope(finding.path));
|
|
42
|
+
return { result: { items: kept.map((finding) => ({ ...finding, source })) } };
|
|
43
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Every brace-free pattern `{a,b}` groups stand for. A `{` with no closing `}` is literal. */
|
|
2
|
+
export declare function alternatives(pattern: string): string[];
|
|
3
|
+
/** Whether a workspace-relative path matches `pattern`. */
|
|
4
|
+
export declare function globMatcher(pattern: string): (path: string) => boolean;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Glob matching as the engine's `tree.list` matches (E-37, engine ADR-0070): `*` is any run of
|
|
2
|
+
// characters in one segment, `?` one character, `**` as a whole segment any number of segments,
|
|
3
|
+
// zero included, and `{a,b}` either alternative, nested groups included. Every other character is
|
|
4
|
+
// literal, so there is no negation and no class.
|
|
5
|
+
/** Every brace-free pattern `{a,b}` groups stand for. A `{` with no closing `}` is literal. */
|
|
6
|
+
export function alternatives(pattern) {
|
|
7
|
+
const open = pattern.indexOf("{");
|
|
8
|
+
if (open === -1)
|
|
9
|
+
return [pattern];
|
|
10
|
+
const commas = [];
|
|
11
|
+
let depth = 0;
|
|
12
|
+
for (let i = open; i < pattern.length; i++) {
|
|
13
|
+
const char = pattern[i];
|
|
14
|
+
if (char === "{")
|
|
15
|
+
depth++;
|
|
16
|
+
else if (char === "," && depth === 1)
|
|
17
|
+
commas.push(i);
|
|
18
|
+
else if (char === "}" && --depth === 0) {
|
|
19
|
+
const bounds = [open, ...commas, i];
|
|
20
|
+
const rest = pattern.slice(i + 1);
|
|
21
|
+
return bounds
|
|
22
|
+
.slice(1)
|
|
23
|
+
.flatMap((end, k) => alternatives(pattern.slice(0, open) + pattern.slice(bounds[k] + 1, end) + rest));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return alternatives(pattern.slice(open + 1)).map((tail) => pattern.slice(0, open + 1) + tail);
|
|
27
|
+
}
|
|
28
|
+
// Matched without RegExp, which the runner closure does not admit (Constraint 4).
|
|
29
|
+
// `*` is any run of characters in one segment and `?` one character, by backtracking on the last `*`.
|
|
30
|
+
function segmentMatches(pattern, text) {
|
|
31
|
+
let p = 0;
|
|
32
|
+
let t = 0;
|
|
33
|
+
let star = -1;
|
|
34
|
+
let mark = 0;
|
|
35
|
+
while (t < text.length) {
|
|
36
|
+
if (p < pattern.length && pattern[p] === "*") {
|
|
37
|
+
star = p++;
|
|
38
|
+
mark = t;
|
|
39
|
+
}
|
|
40
|
+
else if (p < pattern.length && (pattern[p] === "?" || pattern[p] === text[t])) {
|
|
41
|
+
p++;
|
|
42
|
+
t++;
|
|
43
|
+
}
|
|
44
|
+
else if (star !== -1) {
|
|
45
|
+
p = star + 1;
|
|
46
|
+
t = ++mark;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
while (pattern[p] === "*")
|
|
53
|
+
p++;
|
|
54
|
+
return p === pattern.length;
|
|
55
|
+
}
|
|
56
|
+
// A `**` segment matches any number of segments, zero included; as the last segment it matches
|
|
57
|
+
// the rest of the path, so it needs at least one more segment there.
|
|
58
|
+
function segmentsMatch(pattern, path, i, j) {
|
|
59
|
+
if (i === pattern.length)
|
|
60
|
+
return j === path.length;
|
|
61
|
+
const segment = pattern[i];
|
|
62
|
+
if (segment !== "**")
|
|
63
|
+
return j < path.length && segmentMatches(segment, path[j]) && segmentsMatch(pattern, path, i + 1, j + 1);
|
|
64
|
+
if (i === pattern.length - 1)
|
|
65
|
+
return j < path.length;
|
|
66
|
+
for (let k = j; k <= path.length; k++) {
|
|
67
|
+
if (k > j && path[k - 1] === "")
|
|
68
|
+
return false;
|
|
69
|
+
if (segmentsMatch(pattern, path, i + 1, k))
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
/** Whether a workspace-relative path matches `pattern`. */
|
|
75
|
+
export function globMatcher(pattern) {
|
|
76
|
+
const compiled = alternatives(pattern).map((alternative) => alternative.split("/"));
|
|
77
|
+
return (path) => {
|
|
78
|
+
const segments = path.split("/");
|
|
79
|
+
return compiled.some((alternative) => segmentsMatch(alternative, segments, 0, 0));
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -3,3 +3,4 @@ import type { ValidationFinding } from "./schema-validate.ts";
|
|
|
3
3
|
export declare function rejectionFor(finding: ValidationFinding): AuthoringError;
|
|
4
4
|
export declare function rejectionForReservedName(name: string): AuthoringError;
|
|
5
5
|
export declare function rejectionForResult(problem: string): AuthoringError;
|
|
6
|
+
export declare function rejectionForScopeInput(problem: string): AuthoringError;
|
|
@@ -34,3 +34,7 @@ export function rejectionForReservedName(name) {
|
|
|
34
34
|
export function rejectionForResult(problem) {
|
|
35
35
|
return rejection("invalid-result", `invalid Result: ${problem}`);
|
|
36
36
|
}
|
|
37
|
+
// A-122: a scope input of an evaluation factory that is not an array of strings.
|
|
38
|
+
export function rejectionForScopeInput(problem) {
|
|
39
|
+
return rejection("invalid-input", problem);
|
|
40
|
+
}
|
|
@@ -11,7 +11,8 @@ export type ValidationFinding = {
|
|
|
11
11
|
kind: "disallowed-key";
|
|
12
12
|
field: string;
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
/** `imposed` names the inputs a role adds, which `schema.json` never declares (A-122). */
|
|
15
|
+
export declare function validateInput(schema: Schema, input: unknown, imposed?: readonly string[]): ValidationFinding[];
|
|
15
16
|
/** E-40: the largest JSON encoding of a Result, in UTF-8 bytes; exactly at it is allowed. */
|
|
16
17
|
export declare const RESULT_CEILING_BYTES = 1048576;
|
|
17
18
|
export type ResultCheck = {
|
|
@@ -31,7 +31,8 @@ function matchesType(property, value) {
|
|
|
31
31
|
return typeof value === "string" && (property.choices ?? []).includes(value);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
/** `imposed` names the inputs a role adds, which `schema.json` never declares (A-122). */
|
|
35
|
+
export function validateInput(schema, input, imposed = []) {
|
|
35
36
|
const findings = [];
|
|
36
37
|
const record = (input !== null && typeof input === "object" ? input : {});
|
|
37
38
|
for (const property of schema.properties) {
|
|
@@ -56,7 +57,7 @@ export function validateInput(schema, input) {
|
|
|
56
57
|
// mapping, slices load-bearing literals).
|
|
57
58
|
const declaredKeys = new Set(schema.properties.map((property) => property.key));
|
|
58
59
|
for (const key of Object.keys(record)) {
|
|
59
|
-
if (RESERVED_INPUT_KEYS.has(key) || FORBIDDEN_KEYS.has(key) || !declaredKeys.has(key)) {
|
|
60
|
+
if (RESERVED_INPUT_KEYS.has(key) || FORBIDDEN_KEYS.has(key) || !(declaredKeys.has(key) || imposed.includes(key))) {
|
|
60
61
|
findings.push({ kind: "disallowed-key", field: key });
|
|
61
62
|
}
|
|
62
63
|
}
|
|
@@ -159,6 +160,9 @@ function shapeProblem(declared, value, where) {
|
|
|
159
160
|
const kind = kindOf(value);
|
|
160
161
|
if (!declared.types.includes(kind))
|
|
161
162
|
return `${where} must be ${declared.types.join(" or ")}`;
|
|
163
|
+
if (kind === "string" && declared.choices !== undefined && !declared.choices.includes(value)) {
|
|
164
|
+
return `${where} must be one of: ${declared.choices.join(", ")}`;
|
|
165
|
+
}
|
|
162
166
|
if (kind === "array" && declared.items !== undefined) {
|
|
163
167
|
const items = declared.items;
|
|
164
168
|
for (const [index, item] of value.entries()) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ResultSchema } from "./schema-model.ts";
|
|
2
|
+
/** The role a schematic declares in its Collection definition entry (CA-14). */
|
|
3
|
+
export type Role = "generator" | "setup" | "teardown" | "evaluation";
|
|
4
|
+
/** The inputs the role `evaluation` imposes; an author input with either name is rejected (A-122). */
|
|
5
|
+
export declare const SCOPE_INPUTS: readonly string[];
|
|
6
|
+
/** The Findings an evaluation factory returns: what codegen emits as its Result type. */
|
|
7
|
+
export declare const FINDINGS: ResultSchema;
|
|
8
|
+
/**
|
|
9
|
+
* FINDINGS with the `source` the SDK sets. The run boundary checks a returned value against it,
|
|
10
|
+
* so an author-set `source` passes the shape check and is then rejected by name.
|
|
11
|
+
*/
|
|
12
|
+
export declare const SOURCED_FINDINGS: ResultSchema;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// A-120 / A-121 / A-122: what the role `evaluation` imposes on a factory, as data both codegen and
|
|
2
|
+
// the run boundary read, so the emitted types and the checked shape cannot drift apart.
|
|
3
|
+
/** The inputs the role `evaluation` imposes; an author input with either name is rejected (A-122). */
|
|
4
|
+
export const SCOPE_INPUTS = ["include", "exclude"];
|
|
5
|
+
const STRING = { types: ["string"] };
|
|
6
|
+
const NUMBER = { types: ["number"] };
|
|
7
|
+
const POSITION = {
|
|
8
|
+
types: ["object"],
|
|
9
|
+
properties: [
|
|
10
|
+
{ key: "line", schema: NUMBER },
|
|
11
|
+
{ key: "column", schema: NUMBER },
|
|
12
|
+
],
|
|
13
|
+
required: ["line", "column"],
|
|
14
|
+
};
|
|
15
|
+
function findingsWith(extra) {
|
|
16
|
+
const finding = {
|
|
17
|
+
types: ["object"],
|
|
18
|
+
properties: [
|
|
19
|
+
{ key: "rule", schema: STRING },
|
|
20
|
+
{ key: "message", schema: STRING },
|
|
21
|
+
{ key: "severity", schema: { types: ["string"], choices: ["error", "warning"] } },
|
|
22
|
+
{ key: "path", schema: STRING },
|
|
23
|
+
{
|
|
24
|
+
key: "range",
|
|
25
|
+
schema: {
|
|
26
|
+
types: ["object"],
|
|
27
|
+
properties: [
|
|
28
|
+
{ key: "start", schema: POSITION },
|
|
29
|
+
{ key: "end", schema: POSITION },
|
|
30
|
+
],
|
|
31
|
+
required: ["start"],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "fix",
|
|
36
|
+
schema: {
|
|
37
|
+
types: ["object"],
|
|
38
|
+
properties: [
|
|
39
|
+
{ key: "schematic", schema: STRING },
|
|
40
|
+
{ key: "inputs", schema: { types: ["object"] } },
|
|
41
|
+
],
|
|
42
|
+
required: ["schematic"],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
...extra,
|
|
46
|
+
],
|
|
47
|
+
required: ["rule", "message", "severity"],
|
|
48
|
+
};
|
|
49
|
+
return { types: ["object"], properties: [{ key: "items", schema: { types: ["array"], items: finding } }], required: ["items"] };
|
|
50
|
+
}
|
|
51
|
+
/** The Findings an evaluation factory returns: what codegen emits as its Result type. */
|
|
52
|
+
export const FINDINGS = findingsWith([]);
|
|
53
|
+
/**
|
|
54
|
+
* FINDINGS with the `source` the SDK sets. The run boundary checks a returned value against it,
|
|
55
|
+
* so an author-set `source` passes the shape check and is then rejected by name.
|
|
56
|
+
*/
|
|
57
|
+
export const SOURCED_FINDINGS = findingsWith([{ key: "source", schema: STRING }]);
|
|
@@ -22,6 +22,8 @@ export interface ResultSchema {
|
|
|
22
22
|
}>;
|
|
23
23
|
required?: string[];
|
|
24
24
|
items?: ResultSchema;
|
|
25
|
+
/** The values a string may take. `schema.json` cannot declare it; a shape a role imposes can. */
|
|
26
|
+
choices?: string[];
|
|
25
27
|
}
|
|
26
28
|
export interface Schema {
|
|
27
29
|
properties: SchemaProperty[];
|
|
@@ -10,11 +10,16 @@ export declare class SchemaSufficiencyFailure extends Error {
|
|
|
10
10
|
readonly findings: SufficiencyFinding[];
|
|
11
11
|
constructor(findings: SufficiencyFinding[]);
|
|
12
12
|
}
|
|
13
|
+
/** A-120 / A-122: a `schema.json` that declares what the role `evaluation` imposes. */
|
|
14
|
+
export declare class RoleContractFailure extends Error {
|
|
15
|
+
constructor(problem: string);
|
|
16
|
+
}
|
|
13
17
|
/**
|
|
14
18
|
* Reads `<packageDir>/schema.json`, parses it, and writes `<packageDir>/schema.generated.ts`
|
|
15
|
-
* — the bin's fixed, non-configurable output location (REQ-TFO-05.1/FPS-01).
|
|
19
|
+
* — the bin's fixed, non-configurable output location (REQ-TFO-05.1/FPS-01). `evaluation` is set
|
|
20
|
+
* when the schematic's Collection definition entry declares the role `evaluation`.
|
|
16
21
|
*/
|
|
17
|
-
export declare function generateSchema(packageDir: string): GenerateResult;
|
|
22
|
+
export declare function generateSchema(packageDir: string, evaluation?: boolean): GenerateResult;
|
|
18
23
|
export declare class WriteContainmentRefusal extends Error {
|
|
19
24
|
constructor(message: string);
|
|
20
25
|
}
|
|
@@ -16,6 +16,7 @@ import { checkSufficiency } from "../../../domain/services/schema/schema-suffici
|
|
|
16
16
|
import { isErrnoException } from "../../../../../platform/fs-errors.js";
|
|
17
17
|
import { emitInputType, UnrecognizedPropertyTypeError } from "./emit-type.js";
|
|
18
18
|
import { discoverProject } from "./project-codegen.js";
|
|
19
|
+
import { SCOPE_INPUTS } from "../../../domain/valueobjects/findings.js";
|
|
19
20
|
export const GENERATED_FILENAME = "schema.generated.ts";
|
|
20
21
|
export const SUCCESS_LINE = "pbuilder-codegen: wrote schema.generated.ts";
|
|
21
22
|
export const USAGE = [
|
|
@@ -35,6 +36,22 @@ export class SchemaSufficiencyFailure extends Error {
|
|
|
35
36
|
this.findings = findings;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
39
|
+
/** A-120 / A-122: a `schema.json` that declares what the role `evaluation` imposes. */
|
|
40
|
+
export class RoleContractFailure extends Error {
|
|
41
|
+
constructor(problem) {
|
|
42
|
+
super(problem);
|
|
43
|
+
this.name = "RoleContractFailure";
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function checkEvaluationSchema(schema) {
|
|
47
|
+
if (schema.result !== undefined) {
|
|
48
|
+
throw new RoleContractFailure("an evaluation schematic declares a Result, which the role fixes as Findings");
|
|
49
|
+
}
|
|
50
|
+
const imposed = schema.properties.find((property) => SCOPE_INPUTS.includes(property.key));
|
|
51
|
+
if (imposed !== undefined) {
|
|
52
|
+
throw new RoleContractFailure(`an evaluation schematic declares the input ${JSON.stringify(imposed.key)}, which the role imposes`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
38
55
|
class OutputWriteFailure extends Error {
|
|
39
56
|
constructor(outputPath, cause, reason) {
|
|
40
57
|
const code = isErrnoException(cause) ? cause.code : undefined;
|
|
@@ -60,9 +77,10 @@ function assertOutputLeaf(outputPath) {
|
|
|
60
77
|
}
|
|
61
78
|
/**
|
|
62
79
|
* Reads `<packageDir>/schema.json`, parses it, and writes `<packageDir>/schema.generated.ts`
|
|
63
|
-
* — the bin's fixed, non-configurable output location (REQ-TFO-05.1/FPS-01).
|
|
80
|
+
* — the bin's fixed, non-configurable output location (REQ-TFO-05.1/FPS-01). `evaluation` is set
|
|
81
|
+
* when the schematic's Collection definition entry declares the role `evaluation`.
|
|
64
82
|
*/
|
|
65
|
-
export function generateSchema(packageDir) {
|
|
83
|
+
export function generateSchema(packageDir, evaluation = false) {
|
|
66
84
|
const schemaPath = schemaPathFor(packageDir);
|
|
67
85
|
const raw = readFileSync(schemaPath, "utf-8");
|
|
68
86
|
const schema = parseSchema(raw);
|
|
@@ -70,8 +88,10 @@ export function generateSchema(packageDir) {
|
|
|
70
88
|
if (sufficiencyFindings.length > 0) {
|
|
71
89
|
throw new SchemaSufficiencyFailure(sufficiencyFindings);
|
|
72
90
|
}
|
|
91
|
+
if (evaluation)
|
|
92
|
+
checkEvaluationSchema(schema);
|
|
73
93
|
const digest = computeSchemaDigest(raw);
|
|
74
|
-
const output = emitInputType(schema, digest);
|
|
94
|
+
const output = emitInputType(schema, digest, evaluation);
|
|
75
95
|
const outputPath = join(packageDir, GENERATED_FILENAME);
|
|
76
96
|
try {
|
|
77
97
|
if (process.platform === "linux" || process.platform === "darwin") {
|
|
@@ -288,16 +308,17 @@ function runProject(directory) {
|
|
|
288
308
|
seen.add(output);
|
|
289
309
|
if (!statSync(schemaPath).isFile())
|
|
290
310
|
throw new Error("nonregular schema");
|
|
291
|
-
generateSchema(entry.directory);
|
|
311
|
+
generateSchema(entry.directory, entry.evaluation);
|
|
292
312
|
generated++;
|
|
293
313
|
}
|
|
294
314
|
catch (error) {
|
|
295
315
|
failed++;
|
|
296
316
|
const diagnostic = error instanceof SchemaParseFailure ? formatParseError(schemaPath, error)
|
|
297
317
|
: error instanceof SchemaSufficiencyFailure ? formatSufficiencyError(schemaPath, error)
|
|
298
|
-
: error instanceof
|
|
299
|
-
: error instanceof
|
|
300
|
-
: "cannot
|
|
318
|
+
: error instanceof RoleContractFailure ? `pbuilder-codegen: ${schemaPath}: ${error.message}`
|
|
319
|
+
: error instanceof WriteContainmentRefusal ? "refusing to write outside the selected project root"
|
|
320
|
+
: error instanceof OutputWriteFailure ? "cannot write a regular, non-symbolic-link output"
|
|
321
|
+
: "cannot read or generate schema.json";
|
|
301
322
|
console.error(`pbuilder-codegen: ${JSON.stringify(entry.label)} (${JSON.stringify(entry.directory)}): ${JSON.stringify(diagnostic)}`);
|
|
302
323
|
}
|
|
303
324
|
}
|
|
@@ -4,5 +4,9 @@ export declare class UnrecognizedPropertyTypeError extends Error {
|
|
|
4
4
|
readonly field: string;
|
|
5
5
|
constructor(field: string);
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* The Input type, and the Result type when the schema declares a Result (A-15). With the role
|
|
9
|
+
* `evaluation` the Input also holds the scope inputs and the Result is the Findings the role
|
|
10
|
+
* imposes (A-120, A-122); the caller has already refused a schema that declares either.
|
|
11
|
+
*/
|
|
12
|
+
export declare function emitInputType(schema: Schema, digest: string, evaluation?: boolean): string;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// discipline still holds so a hostile schema can never distort the emitted TEXT into
|
|
7
7
|
// something a human misreads or a downstream tool mis-tokenizes.
|
|
8
8
|
import { RECOGNIZED_KINDS } from "../../../domain/services/schema/schema-sufficiency.js";
|
|
9
|
+
import { FINDINGS } from "../../../domain/valueobjects/findings.js";
|
|
9
10
|
export const GENERATED_HEADER = "// AUTO-GENERATED by pbuilder-codegen — do not edit. Regenerate: pbuilder-codegen <package-dir>";
|
|
10
11
|
const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
11
12
|
// schema-parse.ts casts `type` to `SchemaKind` with zero runtime validation (`value.type as
|
|
@@ -69,23 +70,32 @@ function emitResult(result) {
|
|
|
69
70
|
const members = result.properties.map(({ key, schema }) => `${emitPropertyKey(key)}${required.has(key) ? "" : "?"}: ${emitResult(schema)}`);
|
|
70
71
|
return members.length === 0 ? "Record<string, never>" : `{ ${members.join("; ")} }`;
|
|
71
72
|
}
|
|
73
|
+
case "string":
|
|
74
|
+
return result.choices === undefined ? kind : result.choices.map((choice) => JSON.stringify(choice)).join(" | ");
|
|
72
75
|
default:
|
|
73
76
|
return kind;
|
|
74
77
|
}
|
|
75
78
|
})
|
|
76
79
|
.join(" | ");
|
|
77
80
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
81
|
+
// A-122: the scope inputs the role `evaluation` imposes, after the author's own.
|
|
82
|
+
const SCOPE_MEMBERS = [
|
|
83
|
+
" /** Globs or literal paths to check */",
|
|
84
|
+
" include?: string[];",
|
|
85
|
+
" /** Globs or literal paths to skip */",
|
|
86
|
+
" exclude?: string[];",
|
|
87
|
+
];
|
|
88
|
+
/**
|
|
89
|
+
* The Input type, and the Result type when the schema declares a Result (A-15). With the role
|
|
90
|
+
* `evaluation` the Input also holds the scope inputs and the Result is the Findings the role
|
|
91
|
+
* imposes (A-120, A-122); the caller has already refused a schema that declares either.
|
|
92
|
+
*/
|
|
93
|
+
export function emitInputType(schema, digest, evaluation = false) {
|
|
94
|
+
const members = [...schema.properties.map(emitProperty), ...(evaluation ? SCOPE_MEMBERS : [])].join("\n");
|
|
95
|
+
const result = evaluation
|
|
96
|
+
? ["", `export type Findings = ${emitResult(FINDINGS)};`, "", "export type Result = Findings;"]
|
|
97
|
+
: schema.result === undefined
|
|
98
|
+
? []
|
|
99
|
+
: ["", `export type Result = ${emitResult(schema.result)};`];
|
|
100
|
+
return [GENERATED_HEADER, `// @schema-digest sha256:${digest}`, "", "export type Input = {", members, "};", ...result, ""].join("\n");
|
|
91
101
|
}
|
|
@@ -11,6 +11,9 @@ function readObject(path) {
|
|
|
11
11
|
throw new Error("invalid object");
|
|
12
12
|
return value;
|
|
13
13
|
}
|
|
14
|
+
function isEvaluation(registration) {
|
|
15
|
+
return isPlainObject(registration) && registration.role === "evaluation";
|
|
16
|
+
}
|
|
14
17
|
export function discoverProject(directory) {
|
|
15
18
|
let selected = resolve(directory ?? process.cwd());
|
|
16
19
|
if (directory === undefined) {
|
|
@@ -77,7 +80,7 @@ export function discoverProject(directory) {
|
|
|
77
80
|
try {
|
|
78
81
|
if (!statSync(module).isFile())
|
|
79
82
|
throw new Error("nonregular module");
|
|
80
|
-
entries.push({ kind: "target", label, directory: dirname(realpathSync(module)) });
|
|
83
|
+
entries.push({ kind: "target", label, directory: dirname(realpathSync(module)), evaluation: isEvaluation(registration) });
|
|
81
84
|
}
|
|
82
85
|
catch {
|
|
83
86
|
entries.push({ kind: "failure", label, diagnostic: `cannot resolve factory module ${JSON.stringify(module)}` });
|
|
@@ -120,7 +123,7 @@ export function discoverProject(directory) {
|
|
|
120
123
|
}
|
|
121
124
|
if (factories !== 1)
|
|
122
125
|
throw new Error("ambiguous or missing factory");
|
|
123
|
-
entries.push({ kind: "target", label, directory: realpathSync(path) });
|
|
126
|
+
entries.push({ kind: "target", label, directory: realpathSync(path), evaluation: isEvaluation(registration) });
|
|
124
127
|
}
|
|
125
128
|
catch {
|
|
126
129
|
entries.push({ kind: "failure", label, diagnostic: `directory requires exactly one regular factory.ts or factory.js: ${JSON.stringify(path)}` });
|
|
@@ -4,11 +4,12 @@ import { AuthoringError } from "../../../domain/valueobjects/authoring-error.ts"
|
|
|
4
4
|
import type { AuthoringVerb, AuthoringReason, AuthoringOrigin } from "../../../domain/valueobjects/authoring-error.ts";
|
|
5
5
|
import type { ScaffoldArgs } from "../../../application/usecases/scaffold/index.ts";
|
|
6
6
|
export type { FoundHandle, WritableHandle };
|
|
7
|
+
export type { GlobOptions } from "../../../domain/services/define-dialect.ts";
|
|
7
8
|
export { AuthoringError };
|
|
8
9
|
export type { AuthoringVerb, AuthoringReason, AuthoringOrigin };
|
|
9
10
|
export { classifyContent } from "../../../domain/services/classify-content.ts";
|
|
10
11
|
export type { ContentState } from "../../../domain/services/classify-content.ts";
|
|
11
|
-
export { find, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.ts";
|
|
12
|
+
export { find, glob, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.ts";
|
|
12
13
|
/**
|
|
13
14
|
* Options for the `create` author verb.
|
|
14
15
|
*
|
|
@@ -13,7 +13,7 @@ export { AuthoringError };
|
|
|
13
13
|
// from the AuthoringError cluster above — no other component references it.
|
|
14
14
|
export { classifyContent } from "../../../domain/services/classify-content.js";
|
|
15
15
|
// The verbs that need no adapting are the use case's own functions.
|
|
16
|
-
export { find, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.js";
|
|
16
|
+
export { find, glob, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.js";
|
|
17
17
|
export function create(path, opts) {
|
|
18
18
|
return verbs.create(path, opts, (options) => "templateFile" in opts ? readTemplateFile(opts.templateFile, path, options, opts.force) : opts.template);
|
|
19
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SourceFile } from "ts-morph";
|
|
2
|
-
import { type Handle } from "../../../../domain/services/define-dialect.ts";
|
|
2
|
+
import { type GlobOptions, type Handle } from "../../../../domain/services/define-dialect.ts";
|
|
3
3
|
import { typescriptOps } from "../typescript/pack.ts";
|
|
4
4
|
import type { ArrayElement } from "../typescript/array-element.ts";
|
|
5
5
|
import { type InjectionOptions, type InputOptions, type LazyRouteSpec, type NamedImport, type OutputOptions, type RouteSpec, type StateOptions } from "./ops.ts";
|
|
@@ -61,3 +61,16 @@ type AngularOps = {
|
|
|
61
61
|
* // -> export const appConfig: ApplicationConfig = { providers: [provideRouter(routes), provideHttpClient(withFetch())] };
|
|
62
62
|
*/
|
|
63
63
|
export declare function find(path: string): Handle<"found", SourceFile, AngularOps & typeof typescriptOps>;
|
|
64
|
+
/**
|
|
65
|
+
* Opens every file `pattern` matches that this dialect edits, ordered by path; a file of any
|
|
66
|
+
* other extension is left out without an error (A-132). Resolves `[]` when none matches. The
|
|
67
|
+
* pattern syntax and `ignore` are commons `glob`'s, and it sees the run as `find` does.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* import * as angular from "@pbuilder/sdk/angular";
|
|
71
|
+
*
|
|
72
|
+
* export const run = async () => {
|
|
73
|
+
* for (const file of await angular.glob("src/app/**\/*.ts")) await file.read();
|
|
74
|
+
* };
|
|
75
|
+
*/
|
|
76
|
+
export declare function glob(pattern: string, options?: GlobOptions): Promise<Handle<"found", SourceFile, AngularOps & typeof typescriptOps>[]>;
|
|
@@ -66,3 +66,18 @@ const angularDialect = withOps(baseDialect, typescriptOps, angularOps);
|
|
|
66
66
|
export function find(path) {
|
|
67
67
|
return angularDialect.find(path);
|
|
68
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Opens every file `pattern` matches that this dialect edits, ordered by path; a file of any
|
|
71
|
+
* other extension is left out without an error (A-132). Resolves `[]` when none matches. The
|
|
72
|
+
* pattern syntax and `ignore` are commons `glob`'s, and it sees the run as `find` does.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* import * as angular from "@pbuilder/sdk/angular";
|
|
76
|
+
*
|
|
77
|
+
* export const run = async () => {
|
|
78
|
+
* for (const file of await angular.glob("src/app/**\/*.ts")) await file.read();
|
|
79
|
+
* };
|
|
80
|
+
*/
|
|
81
|
+
export function glob(pattern, options) {
|
|
82
|
+
return angularDialect.glob(pattern, options);
|
|
83
|
+
}
|