@pbuilder/sdk 0.13.0 → 0.15.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 +57 -42
- package/dist/{transport → acl/irwire}/frame-reader.d.ts +2 -0
- package/dist/{transport → acl/irwire}/frame-reader.js +57 -5
- package/dist/{transport → acl/irwire}/stdio-engine-client.d.ts +2 -2
- package/dist/{transport → acl/irwire}/stdio-engine-client.js +4 -4
- package/dist/bin/pbuilder-codegen.js +30 -35
- package/dist/bin/pbuilder-runner.js +6 -6
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +106 -0
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +202 -0
- package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.d.ts +12 -9
- package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.js +59 -120
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.d.ts +5 -0
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.js +15 -0
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.d.ts +51 -0
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.js +105 -0
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.d.ts +2 -1
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.js +16 -7
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.d.ts +1 -1
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.js +7 -6
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.d.ts +11 -10
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.js +21 -48
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.d.ts +2 -3
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.js +37 -56
- package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.js +10 -10
- package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.d.ts +1 -1
- package/dist/bounded-contexts/authoring/domain/ports/package-files.d.ts +53 -0
- package/dist/bounded-contexts/authoring/domain/ports/package-files.js +11 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.js +3 -3
- package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.js +37 -12
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.d.ts +11 -1
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.js +94 -3
- package/dist/{core/jsx-name-validator.d.ts → bounded-contexts/authoring/domain/services/identifier-names.d.ts} +8 -4
- package/dist/{core/jsx-name-validator.js → bounded-contexts/authoring/domain/services/identifier-names.js} +21 -28
- package/dist/bounded-contexts/authoring/domain/services/reject-tail.d.ts +9 -0
- package/dist/bounded-contexts/authoring/domain/services/reject-tail.js +30 -0
- package/dist/bounded-contexts/authoring/domain/services/run-context.d.ts +5 -0
- package/dist/bounded-contexts/authoring/domain/services/run-context.js +70 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.js +1 -1
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.d.ts +2 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.js +6 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.d.ts +2 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.js +13 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.js +2 -14
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.d.ts +4 -3
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.js +8 -4
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/wire.d.ts +0 -3
- package/dist/bounded-contexts/authoring/domain/valueobjects/wire.js +28 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +27 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +306 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +7 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +68 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +19 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +131 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +182 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +94 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +63 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +68 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.js +9 -9
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +40 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +38 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +55 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +54 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.d.ts +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.js +35 -8
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +43 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +46 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.js +7 -7
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +52 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +73 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.d.ts +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.js +18 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.d.ts +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.js +25 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.js +5 -3
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.d.ts +7 -2
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.js +29 -15
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.d.ts +5 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.js +22 -4
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.js +14 -19
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +53 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +37 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.d.ts +6 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.js +90 -54
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +69 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +70 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.d.ts +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.js +2 -2
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.js +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.d.ts +8 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.js +133 -0
- package/dist/bounded-contexts/authoring/testing/conformance/index.d.ts +157 -0
- package/dist/bounded-contexts/authoring/testing/conformance/index.js +261 -0
- package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.d.ts +2 -2
- package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.js +4 -3
- package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +89 -0
- package/dist/bounded-contexts/authoring/testing/harness/index.js +85 -0
- package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.d.ts +1 -1
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.js +2 -2
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.js +5 -4
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.js +1 -1
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.d.ts +4 -0
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.js +49 -23
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.js +1 -1
- package/dist/commons/index.d.ts +1 -278
- package/dist/commons/index.js +1 -286
- package/dist/conformance/index.d.ts +1 -157
- package/dist/conformance/index.js +1 -261
- package/dist/dialects/angular/index.d.ts +1 -63
- package/dist/dialects/angular/index.js +1 -68
- package/dist/dialects/css/index.d.ts +1 -40
- package/dist/dialects/css/index.js +1 -38
- package/dist/dialects/json/index.d.ts +1 -55
- package/dist/dialects/json/index.js +1 -54
- package/dist/dialects/nestjs/index.d.ts +1 -43
- package/dist/dialects/nestjs/index.js +1 -46
- package/dist/dialects/react/index.d.ts +1 -52
- package/dist/dialects/react/index.js +1 -73
- package/dist/dialects/typescript/index.d.ts +1 -53
- package/dist/dialects/typescript/index.js +1 -37
- package/dist/dialects/yaml/index.d.ts +1 -69
- package/dist/dialects/yaml/index.js +1 -70
- package/dist/{core → platform}/deep-equal.js +2 -2
- package/dist/{transport → platform}/error-text.js +2 -2
- package/dist/runner-manifest.json +66 -46
- package/dist/shared-kernel/batch-cap.d.ts +4 -0
- package/dist/{core/wire.js → shared-kernel/batch-cap.js} +9 -26
- package/dist/{transport → shared-kernel}/framing.js +2 -2
- package/dist/{transport → shared-kernel}/wire-protocol.js +1 -1
- package/dist/testing/index.d.ts +1 -84
- package/dist/testing/index.js +1 -82
- package/package.json +9 -3
- package/dist/core/index.d.ts +0 -10
- package/dist/core/index.js +0 -6
- package/dist/core/reject-tail.d.ts +0 -13
- package/dist/core/reject-tail.js +0 -52
- package/dist/core/schema/schema-discovery.d.ts +0 -13
- package/dist/core/schema/schema-discovery.js +0 -51
- package/dist/scaffold/classify-transport.d.ts +0 -54
- package/dist/scaffold/classify-transport.js +0 -119
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.d.ts +0 -0
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.js +0 -0
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.js +0 -0
- /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.d.ts +0 -0
- /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.js +0 -0
- /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.d.ts +0 -0
- /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.d.ts +0 -0
- /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.d.ts +0 -0
- /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.js +0 -0
- /package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.js +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.d.ts +0 -0
- /package/dist/{core → platform}/deep-equal.d.ts +0 -0
- /package/dist/{transport → platform}/error-text.d.ts +0 -0
- /package/dist/{core → platform}/fs-errors.d.ts +0 -0
- /package/dist/{core → platform}/fs-errors.js +0 -0
- /package/dist/{transport → shared-kernel}/framing.d.ts +0 -0
- /package/dist/{transport → shared-kernel}/wire-protocol.d.ts +0 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Schema + digest -> `export type Input` text (design §4.3/§4.4, ADR-0027 Gap-4 emission
|
|
2
|
+
// table). Escaping is not optional (SEC-1): every schema-derived string reaches the
|
|
3
|
+
// generated .ts ONLY through JSON.stringify (string-literal / property-key positions),
|
|
4
|
+
// and a label destined for a JSDoc comment has the `*/` breakout sequence guarded. The
|
|
5
|
+
// generated file is TYPE-ONLY (ADR-0031) — it produces zero runtime JS — but the escaping
|
|
6
|
+
// discipline still holds so a hostile schema can never distort the emitted TEXT into
|
|
7
|
+
// something a human misreads or a downstream tool mis-tokenizes.
|
|
8
|
+
import { RECOGNIZED_KINDS } from "../../../domain/services/schema/schema-sufficiency.js";
|
|
9
|
+
export const GENERATED_HEADER = "// AUTO-GENERATED by pbuilder-codegen — do not edit. Regenerate: pbuilder-codegen <package-dir>";
|
|
10
|
+
const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
11
|
+
// schema-parse.ts casts `type` to `SchemaKind` with zero runtime validation (`value.type as
|
|
12
|
+
// SchemaKind`), so a hostile schema.json can hand this function ANY string at runtime despite
|
|
13
|
+
// the compile-time type saying otherwise. This is the last line of defence before emit: never
|
|
14
|
+
// trust the narrowing, always allow-list against the canonical recognized-kind set (also the
|
|
15
|
+
// checkSufficiency hard-fail set — generateSchema's belt-and-suspenders gate is the primary
|
|
16
|
+
// defence; this is the backstop if that gate is ever bypassed or its call site removed).
|
|
17
|
+
export class UnrecognizedPropertyTypeError extends Error {
|
|
18
|
+
field;
|
|
19
|
+
constructor(field) {
|
|
20
|
+
super(`unrecognized property type for "${field}"`);
|
|
21
|
+
this.name = "UnrecognizedPropertyTypeError";
|
|
22
|
+
this.field = field;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function emitPropertyKey(key) {
|
|
26
|
+
return IDENTIFIER_RE.test(key) ? key : JSON.stringify(key);
|
|
27
|
+
}
|
|
28
|
+
// Fixed vocabulary (string/number/boolean) is never schema-derived text; only the enum
|
|
29
|
+
// choices are — each goes through JSON.stringify individually (SEC-1). Anything outside the
|
|
30
|
+
// recognized-kind allow-list is refused rather than emitted verbatim (SEC-1/TFO-01) — a
|
|
31
|
+
// non-`SchemaKind` string reaching here is real top-level text bound for the generated .ts.
|
|
32
|
+
function emitPropertyType(property) {
|
|
33
|
+
if (property.type === "enum") {
|
|
34
|
+
const choices = property.choices ?? [];
|
|
35
|
+
return choices.map((choice) => JSON.stringify(choice)).join(" | ");
|
|
36
|
+
}
|
|
37
|
+
if (!RECOGNIZED_KINDS.has(property.type)) {
|
|
38
|
+
throw new UnrecognizedPropertyTypeError(property.key);
|
|
39
|
+
}
|
|
40
|
+
return property.type;
|
|
41
|
+
}
|
|
42
|
+
// Guards the `*/` comment-breakout sequence and strips newlines (keeps the doc comment a
|
|
43
|
+
// single, well-formed line regardless of hostile input) — labels are prose, not code, so
|
|
44
|
+
// they are escaped for the comment position rather than JSON.stringify'd.
|
|
45
|
+
function sanitizeLabelForComment(label) {
|
|
46
|
+
return label.replace(/\*\//g, "*\\/").replace(/[\r\n]+/g, " ");
|
|
47
|
+
}
|
|
48
|
+
function emitProperty(property) {
|
|
49
|
+
const key = emitPropertyKey(property.key);
|
|
50
|
+
const optional = property.required === false ? "?" : "";
|
|
51
|
+
const type = emitPropertyType(property);
|
|
52
|
+
const doc = property.label !== undefined
|
|
53
|
+
? ` /** ${sanitizeLabelForComment(property.label)} */\n`
|
|
54
|
+
: "";
|
|
55
|
+
return `${doc} ${key}${optional}: ${type};`;
|
|
56
|
+
}
|
|
57
|
+
export function emitInputType(schema, digest) {
|
|
58
|
+
const members = schema.properties.map(emitProperty).join("\n");
|
|
59
|
+
return [
|
|
60
|
+
GENERATED_HEADER,
|
|
61
|
+
`// @schema-digest sha256:${digest}`,
|
|
62
|
+
"",
|
|
63
|
+
"export type Input = {",
|
|
64
|
+
members,
|
|
65
|
+
"};",
|
|
66
|
+
"",
|
|
67
|
+
].join("\n");
|
|
68
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type ProjectEntry = {
|
|
2
|
+
kind: "target";
|
|
3
|
+
label: string;
|
|
4
|
+
directory: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "failure";
|
|
7
|
+
label: string;
|
|
8
|
+
diagnostic: string;
|
|
9
|
+
};
|
|
10
|
+
type ProjectDiscovery = {
|
|
11
|
+
ok: true;
|
|
12
|
+
root: string;
|
|
13
|
+
entries: ProjectEntry[];
|
|
14
|
+
} | {
|
|
15
|
+
ok: false;
|
|
16
|
+
diagnostic: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function discoverProject(directory?: string): ProjectDiscovery;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { lstatSync, statSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { isErrnoException } from "../../../../../platform/fs-errors.js";
|
|
4
|
+
import { isPlainObject } from "../../../domain/valueobjects/schema-model.js";
|
|
5
|
+
function readObject(path) {
|
|
6
|
+
// Static nonregular inputs must not reach a blocking JSON read.
|
|
7
|
+
if (!statSync(path).isFile())
|
|
8
|
+
throw new Error("nonregular input");
|
|
9
|
+
const value = JSON.parse(readFileSync(path, "utf8").replace(/^\uFEFF/, ""));
|
|
10
|
+
if (!isPlainObject(value))
|
|
11
|
+
throw new Error("invalid object");
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
export function discoverProject(directory) {
|
|
15
|
+
let selected = resolve(directory ?? process.cwd());
|
|
16
|
+
if (directory === undefined) {
|
|
17
|
+
for (;;) {
|
|
18
|
+
try {
|
|
19
|
+
lstatSync(join(selected, "project-builder.json"));
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (!isErrnoException(error) || error.code !== "ENOENT") {
|
|
24
|
+
return { ok: false, diagnostic: `cannot load project configuration at ${JSON.stringify(selected)}` };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const parent = dirname(selected);
|
|
28
|
+
if (parent === selected)
|
|
29
|
+
return { ok: false, diagnostic: "project-builder.json not found" };
|
|
30
|
+
selected = parent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let root;
|
|
34
|
+
let collections;
|
|
35
|
+
try {
|
|
36
|
+
root = realpathSync(selected);
|
|
37
|
+
const config = readObject(join(root, "project-builder.json"));
|
|
38
|
+
const value = Object.hasOwn(config, "collections") ? config.collections : {};
|
|
39
|
+
if (!isPlainObject(value))
|
|
40
|
+
throw new Error("invalid collections");
|
|
41
|
+
collections = value;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return { ok: false, diagnostic: `cannot load project configuration at ${JSON.stringify(selected)}` };
|
|
45
|
+
}
|
|
46
|
+
const entries = [];
|
|
47
|
+
for (const name of Object.keys(collections).sort()) {
|
|
48
|
+
const collection = collections[name];
|
|
49
|
+
if (!isPlainObject(collection)) {
|
|
50
|
+
entries.push({ kind: "failure", label: name, diagnostic: "collection must be an object" });
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (typeof collection.path === "string") {
|
|
54
|
+
let manifest;
|
|
55
|
+
const path = resolve(root, collection.path);
|
|
56
|
+
try {
|
|
57
|
+
const value = readObject(path);
|
|
58
|
+
const schematics = Object.hasOwn(value, "schematics") ? value.schematics : {};
|
|
59
|
+
if (!isPlainObject(schematics))
|
|
60
|
+
throw new Error("invalid schematics");
|
|
61
|
+
manifest = schematics;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
entries.push({ kind: "failure", label: name, diagnostic: `cannot load collection manifest ${JSON.stringify(path)}` });
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const key of Object.keys(manifest).sort()) {
|
|
68
|
+
const label = `${name}/${key}`;
|
|
69
|
+
const registration = manifest[key];
|
|
70
|
+
const pointer = isPlainObject(registration) ? registration.factory : undefined;
|
|
71
|
+
const split = typeof pointer === "string" ? pointer.lastIndexOf("#") : -1;
|
|
72
|
+
if (typeof pointer !== "string" || split <= 0 || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(pointer.slice(split + 1))) {
|
|
73
|
+
entries.push({ kind: "failure", label, diagnostic: "factory must name a module and explicit export (module#export)" });
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
const module = resolve(dirname(path), pointer.slice(0, split));
|
|
77
|
+
try {
|
|
78
|
+
if (!statSync(module).isFile())
|
|
79
|
+
throw new Error("nonregular module");
|
|
80
|
+
entries.push({ kind: "target", label, directory: dirname(realpathSync(module)) });
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
entries.push({ kind: "failure", label, diagnostic: `cannot resolve factory module ${JSON.stringify(module)}` });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const inline = Object.hasOwn(collection, "schematics") ? collection.schematics : {};
|
|
89
|
+
if (!isPlainObject(inline)) {
|
|
90
|
+
entries.push({ kind: "failure", label: name, diagnostic: "inline schematics must be an object" });
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const directKeys = Object.keys(collection).filter((key) => key !== "schematics");
|
|
94
|
+
for (const key of [...new Set([...directKeys, ...Object.keys(inline)])].sort()) {
|
|
95
|
+
const label = `${name}/${key}`;
|
|
96
|
+
if (Object.hasOwn(inline, key)) {
|
|
97
|
+
entries.push({ kind: "failure", label, diagnostic: Object.hasOwn(collection, key) ? "ambiguous direct and inline registration" : "inline inputs have no file target" });
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const registration = collection[key];
|
|
101
|
+
if (!isPlainObject(registration) || typeof registration.path !== "string" || registration.path.length === 0) {
|
|
102
|
+
entries.push({ kind: "failure", label, diagnostic: "schematic must name a directory path" });
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const path = resolve(root, registration.path);
|
|
106
|
+
try {
|
|
107
|
+
if (!statSync(path).isDirectory())
|
|
108
|
+
throw new Error("not a directory");
|
|
109
|
+
let factories = 0;
|
|
110
|
+
for (const leaf of ["factory.ts", "factory.js"]) {
|
|
111
|
+
try {
|
|
112
|
+
if (!statSync(join(path, leaf)).isFile())
|
|
113
|
+
throw new Error("nonregular factory");
|
|
114
|
+
factories++;
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
if (!isErrnoException(error) || error.code !== "ENOENT")
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (factories !== 1)
|
|
122
|
+
throw new Error("ambiguous or missing factory");
|
|
123
|
+
entries.push({ kind: "target", label, directory: realpathSync(path) });
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
entries.push({ kind: "failure", label, diagnostic: `directory requires exactly one regular factory.ts or factory.js: ${JSON.stringify(path)}` });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return { ok: true, root, entries };
|
|
131
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import type { JsonValue } from "../../../domain/valueobjects/wire.ts";
|
|
2
|
+
import type { FoundHandle, WritableHandle } from "../../../domain/entities/handle-state.ts";
|
|
3
|
+
import { AuthoringError } from "../../../domain/valueobjects/authoring-error.ts";
|
|
4
|
+
import type { AuthoringVerb, AuthoringReason, AuthoringOrigin } from "../../../domain/valueobjects/authoring-error.ts";
|
|
5
|
+
import type { ScaffoldArgs } from "../../../application/usecases/scaffold/index.ts";
|
|
6
|
+
export type { FoundHandle, WritableHandle };
|
|
7
|
+
export { AuthoringError };
|
|
8
|
+
export type { AuthoringVerb, AuthoringReason, AuthoringOrigin };
|
|
9
|
+
export { classifyContent } from "../../../domain/services/classify-content.ts";
|
|
10
|
+
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
|
+
/**
|
|
13
|
+
* Options for the `create` author verb.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const opts: CreateOptions = {
|
|
17
|
+
* template: "export const {= .name =} = '{= .value =}';",
|
|
18
|
+
* options: { name: "greeting", value: "hello" },
|
|
19
|
+
* };
|
|
20
|
+
*/
|
|
21
|
+
export interface CreateOptions {
|
|
22
|
+
template: string;
|
|
23
|
+
options: JsonValue;
|
|
24
|
+
force?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Options for the `create({ templateFile })` render request — an explicit, package-local
|
|
28
|
+
* alternative to an inline `template` string (REQ-FEH-01). `templateFile` is a
|
|
29
|
+
* package-relative path (resolved against the active Session's `packageDir`), read at
|
|
30
|
+
* emission time; its content becomes the `create` directive's `template` field —
|
|
31
|
+
* the existing `create` IR, zero wire change. `templateFile` REQUESTS a render: a binary
|
|
32
|
+
* or oversized source fails loud (`invalid-input`), it never silently falls back to a
|
|
33
|
+
* by-reference copy (REQ-FEH-02).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const opts: CreateFromTemplateFileOptions = {
|
|
37
|
+
* templateFile: "tpl.ts.template",
|
|
38
|
+
* options: { name: "greeting" },
|
|
39
|
+
* };
|
|
40
|
+
*/
|
|
41
|
+
export interface CreateFromTemplateFileOptions {
|
|
42
|
+
templateFile: string;
|
|
43
|
+
options: JsonValue;
|
|
44
|
+
force?: boolean;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Schedules a file-creation directive and returns a `WritableHandle` for chaining.
|
|
48
|
+
* The file is written when the session flushes — on the next `read()` call (REQ-KIT-02)
|
|
49
|
+
* or at run end (REQ-KIT-05). A factory that never calls `read()` still emits all
|
|
50
|
+
* buffered directives when the runner resolves.
|
|
51
|
+
*
|
|
52
|
+
* SEAM-01 (REQ-01): a generic type parameter `S` narrows `options` from the bare
|
|
53
|
+
* `JsonValue` to the schema's keys at the type level only — the runtime body is unchanged.
|
|
54
|
+
*
|
|
55
|
+
* Creating over an existing file is rejected at the engine seam unless
|
|
56
|
+
* `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
|
|
57
|
+
* rejected Session throws `AuthoringError`.
|
|
58
|
+
*
|
|
59
|
+
* `templateFile` is a THIRD overload (REQ-FEH-01): pass a package-local path instead of an
|
|
60
|
+
* inline `template` string — its content is read at emission time and becomes the
|
|
61
|
+
* directive's `template` field. `template` and `templateFile` are mutually exclusive forms;
|
|
62
|
+
* only usable inside a factory invocation started with packageDir (there is no resolution anchor
|
|
63
|
+
* to read a package-local file against otherwise — `invalid-input`, never a cwd fallback).
|
|
64
|
+
* `templateFile`'s VALUE is a literal package-relative path, read verbatim by CONTENT —
|
|
65
|
+
* it is NOT run through `scaffold`'s filename pipeline (no rename remap, no `__x__` token
|
|
66
|
+
* translation, no `.template`-suffix strip applied to the path itself); this is an
|
|
67
|
+
* explicit REQUEST to render one named file, unlike `scaffold`'s per-entry filename
|
|
68
|
+
* processing. Because `templateFile` REQUESTS a render, it has no silent by-reference
|
|
69
|
+
* fallback (REQ-FEH-02): a binary file (a null byte or invalid UTF-8 anywhere in the
|
|
70
|
+
* whole file) or a file too large to render inline (over the 4 MiB limit) both reject
|
|
71
|
+
* fail-loud with reason `invalid-input` — never a silent copy.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* create("src/index.ts", {
|
|
75
|
+
* template: "export const version = '{= .version =}';",
|
|
76
|
+
* options: { version: "1.0.0" },
|
|
77
|
+
* });
|
|
78
|
+
* @example
|
|
79
|
+
* create("src/index.ts", {
|
|
80
|
+
* templateFile: "index.ts.template",
|
|
81
|
+
* options: { version: "1.0.0" },
|
|
82
|
+
* });
|
|
83
|
+
*/
|
|
84
|
+
export declare function create<S>(path: string, opts: {
|
|
85
|
+
template: string;
|
|
86
|
+
options: {
|
|
87
|
+
[K in keyof S]: S[K];
|
|
88
|
+
};
|
|
89
|
+
force?: boolean;
|
|
90
|
+
}): WritableHandle;
|
|
91
|
+
export declare function create(path: string, opts: CreateOptions): WritableHandle;
|
|
92
|
+
export declare function create(path: string, opts: CreateFromTemplateFileOptions): WritableHandle;
|
|
93
|
+
/**
|
|
94
|
+
* Author-facing options for the `scaffold` verb — walks a package-local folder and mirrors
|
|
95
|
+
* it into the target tree. `from`/`to` are mandatory. `options` defaults `{}`, `include`
|
|
96
|
+
* defaults to matching everything, `exclude` defaults to matching nothing (`exclude` wins
|
|
97
|
+
* on overlap), `rename` defaults to no remap, `force` defaults `false`.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* const opts: ScaffoldOptions = {
|
|
101
|
+
* from: "files",
|
|
102
|
+
* to: "src/generated",
|
|
103
|
+
* options: { name: "Widget" },
|
|
104
|
+
* exclude: ["*.spec.ts"],
|
|
105
|
+
* };
|
|
106
|
+
*/
|
|
107
|
+
export type ScaffoldOptions = ScaffoldArgs;
|
|
108
|
+
/**
|
|
109
|
+
* Walks a package-local folder (`from`, resolved against the active Session's `packageDir`)
|
|
110
|
+
* and mirrors every entry into `to`, applying the rename → filename-token-translation →
|
|
111
|
+
* `.template`-strip pipeline (REQ-FSC-05) and include/exclude glob filtering (REQ-FSC-03,
|
|
112
|
+
* `exclude` wins on overlap). A source matching one of the `binary` globs (against the same
|
|
113
|
+
* original path) is copied byte for byte (`copyIn`); every other source renders through a
|
|
114
|
+
* `create` directive. A source that cannot render rejects naming it, never falling back to a
|
|
115
|
+
* copy: one that is not valid UTF-8 text (with a `binary: [...]` suggestion), one too large
|
|
116
|
+
* for one emit frame (naming its size), or one both `.template`-marked and declared binary. A `from` folder with zero entries
|
|
117
|
+
* no-ops silently; `include`/`exclude` eliminating every entry rejects fail-loud, naming
|
|
118
|
+
* the filters (REQ-FSC-04 — two distinct outcomes, never collapsed). `force` (default
|
|
119
|
+
* `false`) passes through unchanged to every emitted directive, no per-file override
|
|
120
|
+
* (REQ-FSC-06). Two or more sources collapsing to the same destination reject fail-loud,
|
|
121
|
+
* naming every offending source (REQ-FSC-08). Only usable inside a
|
|
122
|
+
* factory invocation started with packageDir — there is no resolution anchor to walk a
|
|
123
|
+
* package-local folder against otherwise (`invalid-input`, never a cwd fallback).
|
|
124
|
+
*
|
|
125
|
+
* `rename` is a static REMAP TABLE (`Record<originalSourceRelativePath,
|
|
126
|
+
* newDestinationRelativePath>`), matched against the ORIGINAL (pre-token-translation)
|
|
127
|
+
* source path — distinct from the `rename()` verb, which renames one already-targeted
|
|
128
|
+
* file's basename at emit time, not a folder-walk's per-entry destination.
|
|
129
|
+
*
|
|
130
|
+
* A NESTED symlinked directory is never descended, regardless of where its target
|
|
131
|
+
* resolves — skipped silently, no error; enumeration determinism and cycle-safety are the
|
|
132
|
+
* rationale (a symlinked directory could point anywhere, including into a cycle — never
|
|
133
|
+
* descending is the simplest invariant that is safe under all targets, REQ-FSC-09). The
|
|
134
|
+
* walk ROOT (`from` itself) is held to a stricter standard: a symlinked root REJECTS
|
|
135
|
+
* (`invalid-input`) rather than being followed or silently skipped (owner ruling 16) — but
|
|
136
|
+
* this check inspects only `from`'s FINAL path component; a symlink at a MID-path segment
|
|
137
|
+
* (e.g. `from: "link/sub"`) is not detected and the walk proceeds through it, the same
|
|
138
|
+
* documented residual SECURITY.md covers for `create`/`copyIn` reads. The walk is capped
|
|
139
|
+
* at 10,000 enumerated entries per call, failing loud and naming the bound past that
|
|
140
|
+
* (REQ-FSC-09) — a loop-safety/DoS resource guard no real schematic collection should
|
|
141
|
+
* approach.
|
|
142
|
+
*
|
|
143
|
+
* **Packaging caveat**: the empty-folder no-op (above) depends on `from` existing ON
|
|
144
|
+
* DISK at run time — npm tarball packaging commonly DROPS empty directories, so an
|
|
145
|
+
* empty `from` folder that relies on this no-op may not survive `npm publish` at all
|
|
146
|
+
* (REQ-FSC-04). Ship at least a placeholder file if the folder's presence matters.
|
|
147
|
+
*
|
|
148
|
+
* Returns `void` (REQ-FSC-07) — fire-and-forget, no chainable handle group.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* scaffold({ from: "files", to: "src/generated", options: { name: "Widget" } });
|
|
152
|
+
*/
|
|
153
|
+
export declare function scaffold(args: ScaffoldOptions): void;
|
|
154
|
+
/**
|
|
155
|
+
* Emits a by-reference copy of ONE package-local file (`from`, resolved against the active
|
|
156
|
+
* run's `packageDir`) to `to` — ALWAYS by-reference, NEVER classified or rendered
|
|
157
|
+
* (REQ-FEH-03), regardless of the source's own text-vs-binary shape: a text asset
|
|
158
|
+
* containing `{= =}`-like sequences (that `scaffold` would otherwise render as tokens)
|
|
159
|
+
* travels verbatim — the documented escape from `scaffold`'s by-value classification
|
|
160
|
+
* (`content-classification` REQ-CCL-04). Contrast with tree→tree `copy`: `copyIn`'s source
|
|
161
|
+
* is a PACKAGE-LOCAL path read at emission time, not an existing tree entry.
|
|
162
|
+
*
|
|
163
|
+
* `from`/`to` are mandatory; `force` defaults `false`. A missing `from`/`to` rejects
|
|
164
|
+
* fail-loud before any emission (REQ-FEH-04.1/.2). Collision without `force` rejects;
|
|
165
|
+
* `force: true` overwrites (`by-reference-copy-wire` REQ-BRC-05). Only usable inside a
|
|
166
|
+
* factory invocation started with packageDir — there is no resolution anchor to read a
|
|
167
|
+
* package-local file against otherwise (`invalid-input`, never a cwd fallback).
|
|
168
|
+
*
|
|
169
|
+
* Returns `void` (REQ-FEH-04.3) — NOT a `WritableHandle`, unlike `copy`: a by-reference
|
|
170
|
+
* destination's bytes exist only after the ENGINE applies the directive (the fake never
|
|
171
|
+
* materializes them, `author-test-harness` REQ-ATH-15) — a handle chaining over tree
|
|
172
|
+
* CONTENT would lie about content that was never staged. This asymmetry with `copy`
|
|
173
|
+
* (which DOES stage tree→tree content the fake can chain over) is deliberate.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* copyIn("assets/logo.svg", "src/generated/logo.svg");
|
|
177
|
+
*/
|
|
178
|
+
export declare function copyIn(from: string, to: string, opts?: {
|
|
179
|
+
force?: boolean;
|
|
180
|
+
}): void;
|
|
181
|
+
import type { PendingDirective } from "../../../application/usecases/pending-directives/render.ts";
|
|
182
|
+
export type { PendingDirective };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Author surface: positional + trailing options, frozen public API (KIT-03/SKEL-01/KIT-04).
|
|
2
|
+
// No AST imports. All handle write-ops wired (S-003).
|
|
3
|
+
import * as verbs from "../../../application/usecases/authoring-verbs/index.js";
|
|
4
|
+
import { AuthoringError } from "../../../domain/valueobjects/authoring-error.js";
|
|
5
|
+
import { readTemplateFile, runScaffold, runCopyIn } from "../../../application/usecases/scaffold/index.js";
|
|
6
|
+
// ADR-0023: AuthoringError (+ its supporting types) is an author-facing DATA type, not
|
|
7
|
+
// kit MACHINERY (the port, the session, the directive factory stay unexported) — it
|
|
8
|
+
// legitimately crosses the ADR-0009 boundary via the same two-step pattern
|
|
9
|
+
// FoundHandle/WritableHandle already use.
|
|
10
|
+
export { AuthoringError };
|
|
11
|
+
// 2.3 (CQ-1, droppable): classifyContent + ContentState give authors a named,
|
|
12
|
+
// branchable read-result classification (see find()'s JSDoc in the authoring-verbs use case). Severable
|
|
13
|
+
// from the AuthoringError cluster above — no other component references it.
|
|
14
|
+
export { classifyContent } from "../../../domain/services/classify-content.js";
|
|
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";
|
|
17
|
+
export function create(path, opts) {
|
|
18
|
+
return verbs.create(path, opts, (options) => "templateFile" in opts ? readTemplateFile(opts.templateFile, path, options, opts.force) : opts.template);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Walks a package-local folder (`from`, resolved against the active Session's `packageDir`)
|
|
22
|
+
* and mirrors every entry into `to`, applying the rename → filename-token-translation →
|
|
23
|
+
* `.template`-strip pipeline (REQ-FSC-05) and include/exclude glob filtering (REQ-FSC-03,
|
|
24
|
+
* `exclude` wins on overlap). A source matching one of the `binary` globs (against the same
|
|
25
|
+
* original path) is copied byte for byte (`copyIn`); every other source renders through a
|
|
26
|
+
* `create` directive. A source that cannot render rejects naming it, never falling back to a
|
|
27
|
+
* copy: one that is not valid UTF-8 text (with a `binary: [...]` suggestion), one too large
|
|
28
|
+
* for one emit frame (naming its size), or one both `.template`-marked and declared binary. A `from` folder with zero entries
|
|
29
|
+
* no-ops silently; `include`/`exclude` eliminating every entry rejects fail-loud, naming
|
|
30
|
+
* the filters (REQ-FSC-04 — two distinct outcomes, never collapsed). `force` (default
|
|
31
|
+
* `false`) passes through unchanged to every emitted directive, no per-file override
|
|
32
|
+
* (REQ-FSC-06). Two or more sources collapsing to the same destination reject fail-loud,
|
|
33
|
+
* naming every offending source (REQ-FSC-08). Only usable inside a
|
|
34
|
+
* factory invocation started with packageDir — there is no resolution anchor to walk a
|
|
35
|
+
* package-local folder against otherwise (`invalid-input`, never a cwd fallback).
|
|
36
|
+
*
|
|
37
|
+
* `rename` is a static REMAP TABLE (`Record<originalSourceRelativePath,
|
|
38
|
+
* newDestinationRelativePath>`), matched against the ORIGINAL (pre-token-translation)
|
|
39
|
+
* source path — distinct from the `rename()` verb, which renames one already-targeted
|
|
40
|
+
* file's basename at emit time, not a folder-walk's per-entry destination.
|
|
41
|
+
*
|
|
42
|
+
* A NESTED symlinked directory is never descended, regardless of where its target
|
|
43
|
+
* resolves — skipped silently, no error; enumeration determinism and cycle-safety are the
|
|
44
|
+
* rationale (a symlinked directory could point anywhere, including into a cycle — never
|
|
45
|
+
* descending is the simplest invariant that is safe under all targets, REQ-FSC-09). The
|
|
46
|
+
* walk ROOT (`from` itself) is held to a stricter standard: a symlinked root REJECTS
|
|
47
|
+
* (`invalid-input`) rather than being followed or silently skipped (owner ruling 16) — but
|
|
48
|
+
* this check inspects only `from`'s FINAL path component; a symlink at a MID-path segment
|
|
49
|
+
* (e.g. `from: "link/sub"`) is not detected and the walk proceeds through it, the same
|
|
50
|
+
* documented residual SECURITY.md covers for `create`/`copyIn` reads. The walk is capped
|
|
51
|
+
* at 10,000 enumerated entries per call, failing loud and naming the bound past that
|
|
52
|
+
* (REQ-FSC-09) — a loop-safety/DoS resource guard no real schematic collection should
|
|
53
|
+
* approach.
|
|
54
|
+
*
|
|
55
|
+
* **Packaging caveat**: the empty-folder no-op (above) depends on `from` existing ON
|
|
56
|
+
* DISK at run time — npm tarball packaging commonly DROPS empty directories, so an
|
|
57
|
+
* empty `from` folder that relies on this no-op may not survive `npm publish` at all
|
|
58
|
+
* (REQ-FSC-04). Ship at least a placeholder file if the folder's presence matters.
|
|
59
|
+
*
|
|
60
|
+
* Returns `void` (REQ-FSC-07) — fire-and-forget, no chainable handle group.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* scaffold({ from: "files", to: "src/generated", options: { name: "Widget" } });
|
|
64
|
+
*/
|
|
65
|
+
export function scaffold(args) {
|
|
66
|
+
runScaffold(args);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Emits a by-reference copy of ONE package-local file (`from`, resolved against the active
|
|
70
|
+
* run's `packageDir`) to `to` — ALWAYS by-reference, NEVER classified or rendered
|
|
71
|
+
* (REQ-FEH-03), regardless of the source's own text-vs-binary shape: a text asset
|
|
72
|
+
* containing `{= =}`-like sequences (that `scaffold` would otherwise render as tokens)
|
|
73
|
+
* travels verbatim — the documented escape from `scaffold`'s by-value classification
|
|
74
|
+
* (`content-classification` REQ-CCL-04). Contrast with tree→tree `copy`: `copyIn`'s source
|
|
75
|
+
* is a PACKAGE-LOCAL path read at emission time, not an existing tree entry.
|
|
76
|
+
*
|
|
77
|
+
* `from`/`to` are mandatory; `force` defaults `false`. A missing `from`/`to` rejects
|
|
78
|
+
* fail-loud before any emission (REQ-FEH-04.1/.2). Collision without `force` rejects;
|
|
79
|
+
* `force: true` overwrites (`by-reference-copy-wire` REQ-BRC-05). Only usable inside a
|
|
80
|
+
* factory invocation started with packageDir — there is no resolution anchor to read a
|
|
81
|
+
* package-local file against otherwise (`invalid-input`, never a cwd fallback).
|
|
82
|
+
*
|
|
83
|
+
* Returns `void` (REQ-FEH-04.3) — NOT a `WritableHandle`, unlike `copy`: a by-reference
|
|
84
|
+
* destination's bytes exist only after the ENGINE applies the directive (the fake never
|
|
85
|
+
* materializes them, `author-test-harness` REQ-ATH-15) — a handle chaining over tree
|
|
86
|
+
* CONTENT would lie about content that was never staged. This asymmetry with `copy`
|
|
87
|
+
* (which DOES stage tree→tree content the fake can chain over) is deliberate.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* copyIn("assets/logo.svg", "src/generated/logo.svg");
|
|
91
|
+
*/
|
|
92
|
+
export function copyIn(from, to, opts) {
|
|
93
|
+
runCopyIn({ from, to, force: opts?.force });
|
|
94
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { SourceFile } from "ts-morph";
|
|
2
|
+
import { type Handle } from "../../../../domain/services/define-dialect.ts";
|
|
3
|
+
import { typescriptOps } from "../typescript/pack.ts";
|
|
4
|
+
import type { ArrayElement } from "../typescript/array-element.ts";
|
|
5
|
+
import { type InjectionOptions, type InputOptions, type LazyRouteSpec, type NamedImport, type OutputOptions, type RouteSpec, type StateOptions } from "./ops.ts";
|
|
6
|
+
export * as astLibrary from "ts-morph";
|
|
7
|
+
export type { InjectionOptions, InputOptions, LazyRouteSpec, NamedImport, OutputOptions, RouteSpec, StateOptions };
|
|
8
|
+
type InsertOp = (ast: SourceFile, element: ArrayElement, imports?: readonly NamedImport[]) => void;
|
|
9
|
+
type AngularOps = {
|
|
10
|
+
addComponentImport: InsertOp;
|
|
11
|
+
addComponentProvider: InsertOp;
|
|
12
|
+
addRootProvider: InsertOp;
|
|
13
|
+
addRoute: (ast: SourceFile, route: RouteSpec) => void;
|
|
14
|
+
addLazyRoute: (ast: SourceFile, route: LazyRouteSpec) => void;
|
|
15
|
+
addInjection: (ast: SourceFile, name: string, token: ArrayElement, options?: InjectionOptions) => void;
|
|
16
|
+
addInput: (ast: SourceFile, name: string, options?: InputOptions) => void;
|
|
17
|
+
addModel: (ast: SourceFile, name: string, options?: InputOptions) => void;
|
|
18
|
+
addOutput: (ast: SourceFile, name: string, options?: OutputOptions) => void;
|
|
19
|
+
addSignal: (ast: SourceFile, name: string, initial: string, options?: StateOptions) => void;
|
|
20
|
+
addComputed: (ast: SourceFile, name: string, expression: string, options?: StateOptions) => void;
|
|
21
|
+
addNgModuleImport: InsertOp;
|
|
22
|
+
addDeclaration: InsertOp;
|
|
23
|
+
addNgModuleProvider: InsertOp;
|
|
24
|
+
addNgModuleExport: InsertOp;
|
|
25
|
+
addBootstrap: InsertOp;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Opens a `.ts` file of an Angular project for editing. The handle carries every
|
|
29
|
+
* `@pbuilder/sdk/typescript` op plus the Angular ops below, chained on one handle and written
|
|
30
|
+
* once.
|
|
31
|
+
*
|
|
32
|
+
* Each op takes `(element, imports?)`: `element` is an identifier, or `{ expression }` for
|
|
33
|
+
* code such as `provideHttpClient(withFetch())`, and `imports` lists the `{ name, from }`
|
|
34
|
+
* named imports that code needs, each added with `addImport`'s rules. An element already
|
|
35
|
+
* listed is a no-op.
|
|
36
|
+
*
|
|
37
|
+
* - `addComponentImport` / `addComponentProvider` append to `imports` / `providers` of the
|
|
38
|
+
* file's only `@Component`, creating the metadata object or the array when missing.
|
|
39
|
+
* - `addRootProvider` appends to the root `providers` of the file's only variable typed
|
|
40
|
+
* `ApplicationConfig`, or of the only `bootstrapApplication(...)` config object.
|
|
41
|
+
* - `addRoute({ path, component, from })` imports `component` and adds an eager route;
|
|
42
|
+
* `addLazyRoute({ path, loadComponent | loadChildren, export? })` adds a lazy one. Both go
|
|
43
|
+
* to the file's only variable typed `Routes` or `Route[]`, before a `**` route when there is
|
|
44
|
+
* one, since the first matching route wins. A different route with the same `path` rejects.
|
|
45
|
+
*
|
|
46
|
+
* They reject, leaving the file unchanged, when the target is missing, ambiguous, or not a
|
|
47
|
+
* literal. Use `.modify(fn)` for those files.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* import * as angular from "@pbuilder/sdk/angular";
|
|
51
|
+
*
|
|
52
|
+
* // src/app/app.config.ts before:
|
|
53
|
+
* // export const appConfig: ApplicationConfig = { providers: [provideRouter(routes)] };
|
|
54
|
+
* export const run = async () => {
|
|
55
|
+
* await angular.find("src/app/app.config.ts").addRootProvider({ expression: "provideHttpClient(withFetch())" }, [
|
|
56
|
+
* { name: "provideHttpClient", from: "@angular/common/http" },
|
|
57
|
+
* { name: "withFetch", from: "@angular/common/http" },
|
|
58
|
+
* ]);
|
|
59
|
+
* };
|
|
60
|
+
* // -> import { provideHttpClient, withFetch } from "@angular/common/http";
|
|
61
|
+
* // -> export const appConfig: ApplicationConfig = { providers: [provideRouter(routes), provideHttpClient(withFetch())] };
|
|
62
|
+
*/
|
|
63
|
+
export declare function find(path: string): Handle<"found", SourceFile, AngularOps & typeof typescriptOps>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { defineDialect, defineOpPack, withOps } from "../../../../domain/services/define-dialect.js";
|
|
2
|
+
import { parse, print } from "../typescript/ast.js";
|
|
3
|
+
import { typescriptOps } from "../typescript/pack.js";
|
|
4
|
+
import { addBootstrap, addComponentImport, addComponentProvider, addComputed, addDeclaration, addInjection, addInput, addLazyRoute, addModel, addNgModuleExport, addNgModuleImport, addNgModuleProvider, addOutput, addRootProvider, addRoute, addSignal, } from "./ops.js";
|
|
5
|
+
export * as astLibrary from "ts-morph";
|
|
6
|
+
const angularOps = defineOpPack({
|
|
7
|
+
addComponentImport,
|
|
8
|
+
addComponentProvider,
|
|
9
|
+
addRootProvider,
|
|
10
|
+
addRoute,
|
|
11
|
+
addLazyRoute,
|
|
12
|
+
addInjection,
|
|
13
|
+
addInput,
|
|
14
|
+
addModel,
|
|
15
|
+
addOutput,
|
|
16
|
+
addSignal,
|
|
17
|
+
addComputed,
|
|
18
|
+
addNgModuleImport,
|
|
19
|
+
addDeclaration,
|
|
20
|
+
addNgModuleProvider,
|
|
21
|
+
addNgModuleExport,
|
|
22
|
+
addBootstrap,
|
|
23
|
+
});
|
|
24
|
+
const baseDialect = defineDialect({
|
|
25
|
+
extensions: [".ts"],
|
|
26
|
+
ast: { parse, print },
|
|
27
|
+
ops: {},
|
|
28
|
+
});
|
|
29
|
+
const angularDialect = withOps(baseDialect, typescriptOps, angularOps);
|
|
30
|
+
/**
|
|
31
|
+
* Opens a `.ts` file of an Angular project for editing. The handle carries every
|
|
32
|
+
* `@pbuilder/sdk/typescript` op plus the Angular ops below, chained on one handle and written
|
|
33
|
+
* once.
|
|
34
|
+
*
|
|
35
|
+
* Each op takes `(element, imports?)`: `element` is an identifier, or `{ expression }` for
|
|
36
|
+
* code such as `provideHttpClient(withFetch())`, and `imports` lists the `{ name, from }`
|
|
37
|
+
* named imports that code needs, each added with `addImport`'s rules. An element already
|
|
38
|
+
* listed is a no-op.
|
|
39
|
+
*
|
|
40
|
+
* - `addComponentImport` / `addComponentProvider` append to `imports` / `providers` of the
|
|
41
|
+
* file's only `@Component`, creating the metadata object or the array when missing.
|
|
42
|
+
* - `addRootProvider` appends to the root `providers` of the file's only variable typed
|
|
43
|
+
* `ApplicationConfig`, or of the only `bootstrapApplication(...)` config object.
|
|
44
|
+
* - `addRoute({ path, component, from })` imports `component` and adds an eager route;
|
|
45
|
+
* `addLazyRoute({ path, loadComponent | loadChildren, export? })` adds a lazy one. Both go
|
|
46
|
+
* to the file's only variable typed `Routes` or `Route[]`, before a `**` route when there is
|
|
47
|
+
* one, since the first matching route wins. A different route with the same `path` rejects.
|
|
48
|
+
*
|
|
49
|
+
* They reject, leaving the file unchanged, when the target is missing, ambiguous, or not a
|
|
50
|
+
* literal. Use `.modify(fn)` for those files.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* import * as angular from "@pbuilder/sdk/angular";
|
|
54
|
+
*
|
|
55
|
+
* // src/app/app.config.ts before:
|
|
56
|
+
* // export const appConfig: ApplicationConfig = { providers: [provideRouter(routes)] };
|
|
57
|
+
* export const run = async () => {
|
|
58
|
+
* await angular.find("src/app/app.config.ts").addRootProvider({ expression: "provideHttpClient(withFetch())" }, [
|
|
59
|
+
* { name: "provideHttpClient", from: "@angular/common/http" },
|
|
60
|
+
* { name: "withFetch", from: "@angular/common/http" },
|
|
61
|
+
* ]);
|
|
62
|
+
* };
|
|
63
|
+
* // -> import { provideHttpClient, withFetch } from "@angular/common/http";
|
|
64
|
+
* // -> export const appConfig: ApplicationConfig = { providers: [provideRouter(routes), provideHttpClient(withFetch())] };
|
|
65
|
+
*/
|
|
66
|
+
export function find(path) {
|
|
67
|
+
return angularDialect.find(path);
|
|
68
|
+
}
|