@pbuilder/sdk 0.14.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 +13 -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 +7 -5
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.js +28 -8
- 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
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Re-scans `raw` (text already rejected by `JSON.parse`) to pin the 1-based `{line, column}`
|
|
3
3
|
* of the first JSON-grammar deviation. Returns `undefined` when the scanner completes without
|
|
4
4
|
* finding one — either an in-string escape violation (bounded fidelity, ADR-0032) or a
|
|
5
|
-
* defensive scanner/`JSON.parse` divergence
|
|
5
|
+
* defensive scanner/`JSON.parse` divergence — and when the document is nested too deeply for
|
|
6
|
+
* the recursive scanner, whose stack overflow is not a grammar finding. Pure; no I/O.
|
|
6
7
|
*/
|
|
7
8
|
export declare function locateFirstJsonSyntaxError(raw: string): {
|
|
8
9
|
line: number;
|
|
@@ -177,10 +177,21 @@ function offsetToLineColumn(raw, offset) {
|
|
|
177
177
|
* Re-scans `raw` (text already rejected by `JSON.parse`) to pin the 1-based `{line, column}`
|
|
178
178
|
* of the first JSON-grammar deviation. Returns `undefined` when the scanner completes without
|
|
179
179
|
* finding one — either an in-string escape violation (bounded fidelity, ADR-0032) or a
|
|
180
|
-
* defensive scanner/`JSON.parse` divergence
|
|
180
|
+
* defensive scanner/`JSON.parse` divergence — and when the document is nested too deeply for
|
|
181
|
+
* the recursive scanner, whose stack overflow is not a grammar finding. Pure; no I/O.
|
|
181
182
|
*/
|
|
182
183
|
export function locateFirstJsonSyntaxError(raw) {
|
|
183
|
-
|
|
184
|
+
let result;
|
|
185
|
+
try {
|
|
186
|
+
result = scanValue(raw, 0);
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
// Only the recursion's stack overflow means "too deep to locate"; anything else is a
|
|
190
|
+
// scanner defect and must surface.
|
|
191
|
+
if (err instanceof RangeError)
|
|
192
|
+
return undefined;
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
184
195
|
if (!result.ok) {
|
|
185
196
|
return offsetToLineColumn(raw, result.offset);
|
|
186
197
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Bytes -> Schema. Shared by the bin (TFO-04's parse-error template) and the runtime
|
|
2
2
|
// (RBV-05.1's fail-closed literal) — both format SchemaParseFailure into their own
|
|
3
3
|
// vocabulary; this module never renders a caller-facing message itself (no-echo, ADR-0027).
|
|
4
|
-
import { isPlainObject } from "
|
|
4
|
+
import { isPlainObject } from "../../valueobjects/schema-model.js";
|
|
5
5
|
import { locateFirstJsonSyntaxError } from "./schema-locate.js";
|
|
6
6
|
export class SchemaParseFailure extends Error {
|
|
7
7
|
problem;
|
|
@@ -33,19 +33,7 @@ export function parseSchema(raw) {
|
|
|
33
33
|
parsed = JSON.parse(raw);
|
|
34
34
|
}
|
|
35
35
|
catch (err) {
|
|
36
|
-
|
|
37
|
-
// pathologically deep document (e.g. thousands of nested `[`) can overflow the call
|
|
38
|
-
// stack. That RangeError is not a grammar finding; degrade to the same "no offset"
|
|
39
|
-
// fallback as a bounded-fidelity locator result rather than let it escape raw.
|
|
40
|
-
let locator;
|
|
41
|
-
if (err instanceof SyntaxError) {
|
|
42
|
-
try {
|
|
43
|
-
locator = locateFirstJsonSyntaxError(raw);
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
locator = undefined;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
36
|
+
const locator = err instanceof SyntaxError ? locateFirstJsonSyntaxError(raw) : undefined;
|
|
49
37
|
throw new SchemaParseFailure({
|
|
50
38
|
problem: "invalid JSON",
|
|
51
39
|
line: locator?.line,
|
package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.d.ts
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const RECOGNIZED_KINDS: Set<string>;
|
|
2
|
-
export type SufficiencyReason = "forbidden-key" | "missing-type" | "nonsensical-type" | "enum-missing-choices" | "missing-label";
|
|
2
|
+
export type SufficiencyReason = "forbidden-key" | "missing-type" | "nonsensical-type" | "enum-missing-choices" | "enum-non-string-choices" | "missing-label";
|
|
3
3
|
export interface SufficiencyFinding {
|
|
4
4
|
key: string;
|
|
5
5
|
reason: SufficiencyReason;
|
|
@@ -7,8 +7,9 @@ export interface SufficiencyFinding {
|
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* Hard-fail rules over the raw `schema.json` `"properties"` map (REQ-SCP-02): missing
|
|
10
|
-
* `type`; an unrecognized `type` value; an enum property missing (or empty) `choices
|
|
11
|
-
*
|
|
10
|
+
* `type`; an unrecognized `type` value; an enum property missing (or empty) `choices`, or with
|
|
11
|
+
* a choice that is not a string (the run-boundary validator accepts only strings); a missing
|
|
12
|
+
* `label`; or a `__proto__`/`constructor`/`prototype` property key. Does NOT fail
|
|
12
13
|
* for a property missing `default`, `required`, or `description` (advisory only, SCP-02.6).
|
|
13
14
|
*
|
|
14
15
|
* Assumes `raw` is syntactically valid JSON (JSON-validity is schema-parse.ts's/RBV-05's
|
package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.js
RENAMED
|
@@ -7,15 +7,16 @@
|
|
|
7
7
|
// Safe iteration via Object.keys only (constraint 5) — a hostile `__proto__`-named property
|
|
8
8
|
// is itself one of the hard-fail conditions this module exists to catch, so the walk must
|
|
9
9
|
// never trigger a prototype getter via bare/for-in access.
|
|
10
|
-
import { FORBIDDEN_KEYS, isPlainObject } from "
|
|
11
|
-
// Exported as the single canonical allow-list — `emitPropertyType` (
|
|
10
|
+
import { FORBIDDEN_KEYS, isPlainObject } from "../../valueobjects/schema-model.js";
|
|
11
|
+
// Exported as the single canonical allow-list — `emitPropertyType` (the codegen adapter's emit-type.ts) reuses
|
|
12
12
|
// this same Set as its last-line-of-defence guard against an unrecognized `type`, rather than
|
|
13
13
|
// duplicating the recognized-kind vocabulary at the emit boundary.
|
|
14
14
|
export const RECOGNIZED_KINDS = new Set(["string", "number", "boolean", "enum"]);
|
|
15
15
|
/**
|
|
16
16
|
* Hard-fail rules over the raw `schema.json` `"properties"` map (REQ-SCP-02): missing
|
|
17
|
-
* `type`; an unrecognized `type` value; an enum property missing (or empty) `choices
|
|
18
|
-
*
|
|
17
|
+
* `type`; an unrecognized `type` value; an enum property missing (or empty) `choices`, or with
|
|
18
|
+
* a choice that is not a string (the run-boundary validator accepts only strings); a missing
|
|
19
|
+
* `label`; or a `__proto__`/`constructor`/`prototype` property key. Does NOT fail
|
|
19
20
|
* for a property missing `default`, `required`, or `description` (advisory only, SCP-02.6).
|
|
20
21
|
*
|
|
21
22
|
* Assumes `raw` is syntactically valid JSON (JSON-validity is schema-parse.ts's/RBV-05's
|
|
@@ -46,6 +47,9 @@ export function checkSufficiency(raw) {
|
|
|
46
47
|
else if (type === "enum" && (!Array.isArray(value.choices) || value.choices.length === 0)) {
|
|
47
48
|
findings.push({ key, reason: "enum-missing-choices" });
|
|
48
49
|
}
|
|
50
|
+
else if (type === "enum" && !value.choices.every((choice) => typeof choice === "string")) {
|
|
51
|
+
findings.push({ key, reason: "enum-non-string-choices" });
|
|
52
|
+
}
|
|
49
53
|
if (typeof value.label !== "string") {
|
|
50
54
|
findings.push({ key, reason: "missing-label" });
|
|
51
55
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
//
|
|
9
9
|
// S-000 built the "missing" finding (RBV-01.1 site proof). S-003 (this module) triangulates
|
|
10
10
|
// the remaining branches — see slices Coverage Check.
|
|
11
|
-
import { FORBIDDEN_KEYS, RESERVED_LIFECYCLE_NAMES } from "
|
|
11
|
+
import { FORBIDDEN_KEYS, RESERVED_LIFECYCLE_NAMES } from "../../valueobjects/schema-model.js";
|
|
12
12
|
const RESERVED_INPUT_KEYS = new Set(RESERVED_LIFECYCLE_NAMES);
|
|
13
13
|
// {expectedType} rendering (design §4.4, branch table): always the DECLARED expectation,
|
|
14
14
|
// never the received value's kind — an enum renders its choice list, everything else
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// reason/verb/path; the raw engine text is discarded and never chained via `.cause`, so
|
|
9
9
|
// the no-engine-text guarantee (REQ-AEC-05, FIT-11) holds for the WHOLE error object, not
|
|
10
10
|
// only `.message`.
|
|
11
|
-
import { EmitRejection } from "
|
|
11
|
+
import { EmitRejection } from "../ports/emit-rejection.js";
|
|
12
12
|
// ADR-0021: origin is DERIVED from reason via an exhaustive switch with a `never`
|
|
13
13
|
// default arm — adding a 12th reason breaks the BUILD here, forcing a deliberate origin
|
|
14
14
|
// assignment instead of an accidental default (mirrored by the compile-time pin in
|
|
@@ -77,11 +77,8 @@ export type Batch = {
|
|
|
77
77
|
force: boolean;
|
|
78
78
|
instructions: Directive[];
|
|
79
79
|
};
|
|
80
|
-
export declare const BATCH_CAP_BYTES: number;
|
|
81
80
|
export declare function serializedBatchBytes(batch: Batch): number;
|
|
82
81
|
export declare function serializedBatchSize(instructions: readonly Directive[]): number;
|
|
83
82
|
export declare function exceedsBatchCap(subject: Batch): boolean;
|
|
84
83
|
export declare function exceedsBatchCap(subject: number): boolean;
|
|
85
|
-
export declare const EMIT_FRAME_ENVELOPE_ALLOWANCE_BYTES: number;
|
|
86
|
-
export declare const EMIT_BATCH_BUDGET_BYTES: number;
|
|
87
84
|
export declare function exceedsEmitBatchBudget(batch: Batch): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ADR-0001 / ADR-0013: SDK↔engine wire contract (adopts engine ADR-0028 directive shapes).
|
|
2
|
+
// The SDK emits these shapes over JSON; the engine deserialises them. Types are opaque to
|
|
3
|
+
// the template DSL — SDK treats template/pathTemplate as uninterpreted strings.
|
|
4
|
+
import { EMIT_FRAME_ENVELOPE_ALLOWANCE_BYTES, exceedsBatchCap as exceedsCapBytes } from "../../../../shared-kernel/batch-cap.js";
|
|
5
|
+
// REQ-WPS-04 / fit-32 (cap-single-source, stdio-engine-client change): the UTF-8 serialized
|
|
6
|
+
// byte length of a full Batch envelope — the one measurer both `serializedBatchSize` (below)
|
|
7
|
+
// and `exceedsBatchCap`'s outbound leg consume, so the envelope shape can never drift.
|
|
8
|
+
export function serializedBatchBytes(batch) {
|
|
9
|
+
return Buffer.byteLength(JSON.stringify(batch), "utf8");
|
|
10
|
+
}
|
|
11
|
+
// The one shared measurer of what `instructions` serialize to inside the wire envelope —
|
|
12
|
+
// the SAME shape `Session.flush` emits and the fake's `emit` cap check measures
|
|
13
|
+
// (ADR-0018/0019). The expander's chunk heuristic and the batch-cap tests both consume
|
|
14
|
+
// this so the envelope shape can never drift between them.
|
|
15
|
+
export function serializedBatchSize(instructions) {
|
|
16
|
+
const batch = { protocolVersion: 1, force: false, instructions: [...instructions] };
|
|
17
|
+
return serializedBatchBytes(batch);
|
|
18
|
+
}
|
|
19
|
+
export function exceedsBatchCap(subject) {
|
|
20
|
+
return exceedsCapBytes(typeof subject === "number" ? subject : serializedBatchBytes(subject));
|
|
21
|
+
}
|
|
22
|
+
// The ONE outbound-leg measurer (fit-32 cap-single-source): both `ContractFake.emit` (the
|
|
23
|
+
// engine stand-in) and `StdioEngineClient.emit` (the real transport) route through this,
|
|
24
|
+
// so the two can never diverge on an accept/reject verdict for the same batch. `>` via
|
|
25
|
+
// `exceedsBatchCap`, never a re-derived comparison: exactly-at-budget is WITHIN the budget.
|
|
26
|
+
export function exceedsEmitBatchBudget(batch) {
|
|
27
|
+
return exceedsCapBytes(serializedBatchBytes(batch) + EMIT_FRAME_ENVELOPE_ALLOWANCE_BYTES);
|
|
28
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type SufficiencyFinding } from "../../../domain/services/schema/schema-sufficiency.ts";
|
|
2
|
+
export declare const GENERATED_FILENAME = "schema.generated.ts";
|
|
3
|
+
export declare const SUCCESS_LINE = "pbuilder-codegen: wrote schema.generated.ts";
|
|
4
|
+
export declare const USAGE: string;
|
|
5
|
+
export interface GenerateResult {
|
|
6
|
+
outputPath: string;
|
|
7
|
+
digest: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class SchemaSufficiencyFailure extends Error {
|
|
10
|
+
readonly findings: SufficiencyFinding[];
|
|
11
|
+
constructor(findings: SufficiencyFinding[]);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 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).
|
|
16
|
+
*/
|
|
17
|
+
export declare function generateSchema(packageDir: string): GenerateResult;
|
|
18
|
+
export declare class WriteContainmentRefusal extends Error {
|
|
19
|
+
constructor(message: string);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Runs the CLI logic for `argv` (`process.argv.slice(2)`) and returns the process exit
|
|
23
|
+
* code, printing usage/success/error text to STDOUT/STDERR per the CLI contract
|
|
24
|
+
* (ADR-0027). Exported (not just the `import.meta.main` block) so the exit-code/output
|
|
25
|
+
* contract can be exercised without a subprocess where that is sufficient.
|
|
26
|
+
*/
|
|
27
|
+
export declare function runCli(argv: string[]): number;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// CLI: parse a factory's adjacent schema.json -> emit schema.generated.ts (design §4.1/
|
|
2
|
+
// §4.4, ADR-0027). generateSchema() is the S-000 core (discover/read/parse/emit/write),
|
|
3
|
+
// unchanged and still called directly by unit tests against arbitrary (non-contained)
|
|
4
|
+
// directories. The CLI surface below — usage/exit/stream discipline (TFO-03/04, FPS-01/05)
|
|
5
|
+
// and write-containment (TFO-05/SEC-4) — is S-001 scope, layered ONLY at the
|
|
6
|
+
// `import.meta.main` entry point so generateSchema() itself stays containment-agnostic.
|
|
7
|
+
//
|
|
8
|
+
// Authoring's codegen driving adapter: it calls the domain's schema services, and
|
|
9
|
+
// bin/pbuilder-codegen.ts runs it as the process entry (fit-49 binImporters: bin->src only, never src->bin).
|
|
10
|
+
import { readFileSync, writeFileSync, existsSync, realpathSync, lstatSync, statSync, openSync, fstatSync, ftruncateSync, closeSync, constants, } from "node:fs";
|
|
11
|
+
import { join, dirname, basename, resolve, sep } from "node:path";
|
|
12
|
+
import { parseSchema, SchemaParseFailure, formatLocator } from "../../../domain/services/schema/schema-parse.js";
|
|
13
|
+
import { computeSchemaDigest } from "../../../domain/services/schema/schema-digest.js";
|
|
14
|
+
import { schemaPathFor } from "../../../domain/services/schema/schema-files.js";
|
|
15
|
+
import { checkSufficiency } from "../../../domain/services/schema/schema-sufficiency.js";
|
|
16
|
+
import { isErrnoException } from "../../../../../platform/fs-errors.js";
|
|
17
|
+
import { emitInputType, UnrecognizedPropertyTypeError } from "./emit-type.js";
|
|
18
|
+
import { discoverProject } from "./project-codegen.js";
|
|
19
|
+
export const GENERATED_FILENAME = "schema.generated.ts";
|
|
20
|
+
export const SUCCESS_LINE = "pbuilder-codegen: wrote schema.generated.ts";
|
|
21
|
+
export const USAGE = [
|
|
22
|
+
"pbuilder-codegen: derive a TypeScript Input type from a factory's schema.json",
|
|
23
|
+
"",
|
|
24
|
+
"Usage: pbuilder-codegen <package-dir>",
|
|
25
|
+
].join("\n");
|
|
26
|
+
// SEC-1/TFO-01 belt-and-suspenders: checkSufficiency's `nonsensical-type` rule already flags
|
|
27
|
+
// an unrecognized `type` (and the other hard-fail shapes) — refusing to emit here is the
|
|
28
|
+
// PRIMARY defence against a hostile schema.json reaching the emitter; `emitPropertyType`'s
|
|
29
|
+
// own allow-list (emit-type.ts) is the backstop if this call site is ever bypassed.
|
|
30
|
+
export class SchemaSufficiencyFailure extends Error {
|
|
31
|
+
findings;
|
|
32
|
+
constructor(findings) {
|
|
33
|
+
super(`schema sufficiency failure: ${findings.length} finding(s)`);
|
|
34
|
+
this.name = "SchemaSufficiencyFailure";
|
|
35
|
+
this.findings = findings;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
class OutputWriteFailure extends Error {
|
|
39
|
+
constructor(outputPath, cause, reason) {
|
|
40
|
+
const code = isErrnoException(cause) ? cause.code : undefined;
|
|
41
|
+
super(`pbuilder-codegen: ${outputPath}: ${reason ?? (code === "ELOOP" ? "refusing symbolic-link output" : `cannot write output (${code ?? "unknown"})`)}`, { cause });
|
|
42
|
+
this.name = "OutputWriteFailure";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function assertOutputLeaf(outputPath) {
|
|
46
|
+
try {
|
|
47
|
+
const leaf = lstatSync(outputPath);
|
|
48
|
+
if (leaf.isSymbolicLink()) {
|
|
49
|
+
throw new OutputWriteFailure(outputPath, undefined, "refusing symbolic-link output");
|
|
50
|
+
}
|
|
51
|
+
if (!leaf.isFile()) {
|
|
52
|
+
throw new OutputWriteFailure(outputPath, undefined, "output is not a regular file");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
if (isErrnoException(err) && err.code === "ENOENT")
|
|
57
|
+
return;
|
|
58
|
+
throw err instanceof OutputWriteFailure ? err : new OutputWriteFailure(outputPath, err);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 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).
|
|
64
|
+
*/
|
|
65
|
+
export function generateSchema(packageDir) {
|
|
66
|
+
const schemaPath = schemaPathFor(packageDir);
|
|
67
|
+
const raw = readFileSync(schemaPath, "utf-8");
|
|
68
|
+
const schema = parseSchema(raw);
|
|
69
|
+
const sufficiencyFindings = checkSufficiency(raw);
|
|
70
|
+
if (sufficiencyFindings.length > 0) {
|
|
71
|
+
throw new SchemaSufficiencyFailure(sufficiencyFindings);
|
|
72
|
+
}
|
|
73
|
+
const digest = computeSchemaDigest(raw);
|
|
74
|
+
const output = emitInputType(schema, digest);
|
|
75
|
+
const outputPath = join(packageDir, GENERATED_FILENAME);
|
|
76
|
+
try {
|
|
77
|
+
if (process.platform === "linux" || process.platform === "darwin") {
|
|
78
|
+
assertOutputLeaf(outputPath);
|
|
79
|
+
if (!constants.O_NOFOLLOW || !constants.O_NONBLOCK) {
|
|
80
|
+
throw new OutputWriteFailure(outputPath, undefined, "safe output opening is unavailable");
|
|
81
|
+
}
|
|
82
|
+
// Bind mutation to the checked descriptor; pathname validation alone races with leaf substitution.
|
|
83
|
+
const fd = openSync(outputPath, constants.O_WRONLY | constants.O_CREAT | constants.O_NOFOLLOW | constants.O_NONBLOCK, 0o666);
|
|
84
|
+
let failed = false;
|
|
85
|
+
try {
|
|
86
|
+
if (!fstatSync(fd).isFile()) {
|
|
87
|
+
throw new OutputWriteFailure(outputPath, undefined, "output is not a regular file");
|
|
88
|
+
}
|
|
89
|
+
ftruncateSync(fd, 0);
|
|
90
|
+
writeFileSync(fd, output, "utf-8");
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
failed = true;
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
try {
|
|
98
|
+
closeSync(fd);
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
if (!failed)
|
|
102
|
+
throw err;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
writeFileSync(outputPath, output, "utf-8");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
throw err instanceof OutputWriteFailure ? err : new OutputWriteFailure(outputPath, err);
|
|
112
|
+
}
|
|
113
|
+
return { outputPath, digest };
|
|
114
|
+
}
|
|
115
|
+
// --- CLI-only surface (S-001): argv discipline + write containment ------------------
|
|
116
|
+
export class WriteContainmentRefusal extends Error {
|
|
117
|
+
constructor(message) {
|
|
118
|
+
super(message);
|
|
119
|
+
this.name = "WriteContainmentRefusal";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Walks up from `startDir` to the nearest ancestor containing a `package.json` — the
|
|
123
|
+
// invoking PROCESS's project root (ADR-0027 Gap 3: anchored to process.cwd(), never to
|
|
124
|
+
// `<package-dir>` itself, which would be circular). Falls back to `startDir` in the
|
|
125
|
+
// degenerate case where no ancestor carries a package.json.
|
|
126
|
+
function findProjectRoot(startDir) {
|
|
127
|
+
let dir = startDir;
|
|
128
|
+
for (;;) {
|
|
129
|
+
if (existsSync(join(dir, "package.json")))
|
|
130
|
+
return dir;
|
|
131
|
+
const parent = dirname(dir);
|
|
132
|
+
if (parent === dir)
|
|
133
|
+
return startDir;
|
|
134
|
+
dir = parent;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Canonicalizes a path that may not exist yet (the output file usually doesn't): resolves
|
|
138
|
+
// the nearest EXISTING ancestor via realpathSync (defeats symlink escapes — a string-level
|
|
139
|
+
// `../` check alone is bypassable) and re-appends the not-yet-existing suffix segments.
|
|
140
|
+
function realpathNearestExisting(p) {
|
|
141
|
+
let current = p;
|
|
142
|
+
const suffix = [];
|
|
143
|
+
while (!existsSync(current)) {
|
|
144
|
+
const parent = dirname(current);
|
|
145
|
+
if (parent === current)
|
|
146
|
+
break;
|
|
147
|
+
suffix.unshift(basename(current));
|
|
148
|
+
current = parent;
|
|
149
|
+
}
|
|
150
|
+
const real = realpathSync(current);
|
|
151
|
+
return suffix.length > 0 ? join(real, ...suffix) : real;
|
|
152
|
+
}
|
|
153
|
+
function isWithin(anchor, target) {
|
|
154
|
+
return target === anchor || target.startsWith(anchor.endsWith(sep) ? anchor : anchor + sep);
|
|
155
|
+
}
|
|
156
|
+
// SEC-4/REQ-TFO-05: refuses BEFORE any read/write when either the resolved package dir or
|
|
157
|
+
// the resolved output path escapes the invoking process's project root. Schema content is
|
|
158
|
+
// never consulted here — the output path is structurally fixed (TFO-05.3), never templated.
|
|
159
|
+
function assertWriteContained(packageDirArg, outputPath, selectedRoot) {
|
|
160
|
+
const anchor = selectedRoot ?? realpathSync(findProjectRoot(process.cwd()));
|
|
161
|
+
const resolvedPackageDir = realpathNearestExisting(resolve(packageDirArg));
|
|
162
|
+
if (selectedRoot !== undefined || process.platform === "linux" || process.platform === "darwin")
|
|
163
|
+
assertOutputLeaf(outputPath);
|
|
164
|
+
const resolvedOutputPath = realpathNearestExisting(resolve(outputPath));
|
|
165
|
+
if (!isWithin(anchor, resolvedPackageDir) || !isWithin(anchor, resolvedOutputPath)) {
|
|
166
|
+
throw new WriteContainmentRefusal(`pbuilder-codegen: refusing to write outside the project root: "${packageDirArg}"`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// TW-m6 pinned template: `pbuilder-codegen: <file>: <problem> (line L, column C)`, with the
|
|
170
|
+
// ADR-0027 Gap-8 `(position unknown)` fallback when the engine's SyntaxError carried no
|
|
171
|
+
// extractable offset. Never echoes raw file content or the underlying parser's own text.
|
|
172
|
+
function formatParseError(schemaPath, err) {
|
|
173
|
+
return `pbuilder-codegen: ${schemaPath}: ${err.problem} ${formatLocator(err.line, err.column)}`;
|
|
174
|
+
}
|
|
175
|
+
// Bounded, author-vocabulary descriptions per REQ-SCP-02 reason — never echoes a finding's
|
|
176
|
+
// `detail` (the raw offending value, e.g. an injection payload lives in `nonsensical-type`'s
|
|
177
|
+
// `detail`); only property KEYS surface, matching the same canary-asymmetry no-echo contract
|
|
178
|
+
// as the run-boundary rejection templates (key names may appear, values never).
|
|
179
|
+
function describeSufficiencyFinding(finding) {
|
|
180
|
+
switch (finding.reason) {
|
|
181
|
+
case "forbidden-key":
|
|
182
|
+
return `property "${finding.key}" uses a forbidden key`;
|
|
183
|
+
case "missing-type":
|
|
184
|
+
return `property "${finding.key}" is missing a type`;
|
|
185
|
+
case "nonsensical-type":
|
|
186
|
+
return `unrecognized property type for "${finding.key}"`;
|
|
187
|
+
case "enum-missing-choices":
|
|
188
|
+
return `enum property "${finding.key}" is missing choices`;
|
|
189
|
+
case "enum-non-string-choices":
|
|
190
|
+
return `enum property "${finding.key}" has a choice that is not a string`;
|
|
191
|
+
case "missing-label":
|
|
192
|
+
return `property "${finding.key}" is missing a label`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function formatSufficiencyError(schemaPath, err) {
|
|
196
|
+
const reasons = err.findings.map(describeSufficiencyFinding).join("; ");
|
|
197
|
+
return `pbuilder-codegen: ${schemaPath}: ${reasons}`;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Runs the CLI logic for `argv` (`process.argv.slice(2)`) and returns the process exit
|
|
201
|
+
* code, printing usage/success/error text to STDOUT/STDERR per the CLI contract
|
|
202
|
+
* (ADR-0027). Exported (not just the `import.meta.main` block) so the exit-code/output
|
|
203
|
+
* contract can be exercised without a subprocess where that is sufficient.
|
|
204
|
+
*/
|
|
205
|
+
export function runCli(argv) {
|
|
206
|
+
const [first] = argv;
|
|
207
|
+
if (first === undefined || first === "--project") {
|
|
208
|
+
if (first === "--project" && (!argv[1] || argv[1].startsWith("-") || argv.length !== 2)) {
|
|
209
|
+
console.error(USAGE);
|
|
210
|
+
return 1;
|
|
211
|
+
}
|
|
212
|
+
return runProject(argv[1]);
|
|
213
|
+
}
|
|
214
|
+
if (first === "--help" || first === "-h") {
|
|
215
|
+
console.log(USAGE);
|
|
216
|
+
return 0;
|
|
217
|
+
}
|
|
218
|
+
if (first.startsWith("-")) {
|
|
219
|
+
console.error(USAGE);
|
|
220
|
+
return 1;
|
|
221
|
+
}
|
|
222
|
+
const packageDir = first;
|
|
223
|
+
const outputPath = join(packageDir, GENERATED_FILENAME);
|
|
224
|
+
const schemaPath = schemaPathFor(packageDir);
|
|
225
|
+
try {
|
|
226
|
+
assertWriteContained(packageDir, outputPath);
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
230
|
+
return 1;
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
generateSchema(packageDir);
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
if (err instanceof OutputWriteFailure) {
|
|
237
|
+
console.error(err.message);
|
|
238
|
+
return 1;
|
|
239
|
+
}
|
|
240
|
+
if (err instanceof SchemaParseFailure) {
|
|
241
|
+
console.error(formatParseError(schemaPath, err));
|
|
242
|
+
return 1;
|
|
243
|
+
}
|
|
244
|
+
if (err instanceof SchemaSufficiencyFailure) {
|
|
245
|
+
console.error(formatSufficiencyError(schemaPath, err));
|
|
246
|
+
return 1;
|
|
247
|
+
}
|
|
248
|
+
// Backstop: emitPropertyType's own allow-list (emit-type.ts) should be unreachable
|
|
249
|
+
// given the sufficiency gate above, but a bypass must still fail closed with the standard
|
|
250
|
+
// template rather than an uncaught internal stack trace.
|
|
251
|
+
if (err instanceof UnrecognizedPropertyTypeError) {
|
|
252
|
+
console.error(`pbuilder-codegen: ${schemaPath}: ${err.message}`);
|
|
253
|
+
return 1;
|
|
254
|
+
}
|
|
255
|
+
if (isErrnoException(err) && err.code === "ENOENT") {
|
|
256
|
+
console.error(`pbuilder-codegen: ${schemaPath}: schema.json not found`);
|
|
257
|
+
return 1;
|
|
258
|
+
}
|
|
259
|
+
throw err;
|
|
260
|
+
}
|
|
261
|
+
console.log(SUCCESS_LINE);
|
|
262
|
+
return 0;
|
|
263
|
+
}
|
|
264
|
+
function runProject(directory) {
|
|
265
|
+
const project = discoverProject(directory);
|
|
266
|
+
if (!project.ok) {
|
|
267
|
+
console.error(`pbuilder-codegen: ${project.diagnostic}`);
|
|
268
|
+
return 1;
|
|
269
|
+
}
|
|
270
|
+
const seen = new Set();
|
|
271
|
+
let generated = 0;
|
|
272
|
+
let failed = 0;
|
|
273
|
+
let duplicates = 0;
|
|
274
|
+
for (const entry of project.entries) {
|
|
275
|
+
if (entry.kind === "failure") {
|
|
276
|
+
failed++;
|
|
277
|
+
console.error(`pbuilder-codegen: ${JSON.stringify(entry.label)}: ${entry.diagnostic}`);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
const output = join(entry.directory, GENERATED_FILENAME);
|
|
281
|
+
const schemaPath = schemaPathFor(entry.directory);
|
|
282
|
+
try {
|
|
283
|
+
assertWriteContained(entry.directory, output, project.root);
|
|
284
|
+
if (seen.has(output)) {
|
|
285
|
+
duplicates++;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
seen.add(output);
|
|
289
|
+
if (!statSync(schemaPath).isFile())
|
|
290
|
+
throw new Error("nonregular schema");
|
|
291
|
+
generateSchema(entry.directory);
|
|
292
|
+
generated++;
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
failed++;
|
|
296
|
+
const diagnostic = error instanceof SchemaParseFailure ? formatParseError(schemaPath, error)
|
|
297
|
+
: error instanceof SchemaSufficiencyFailure ? formatSufficiencyError(schemaPath, error)
|
|
298
|
+
: error instanceof WriteContainmentRefusal ? "refusing to write outside the selected project root"
|
|
299
|
+
: error instanceof OutputWriteFailure ? "cannot write a regular, non-symbolic-link output"
|
|
300
|
+
: "cannot read or generate schema.json";
|
|
301
|
+
console.error(`pbuilder-codegen: ${JSON.stringify(entry.label)} (${JSON.stringify(entry.directory)}): ${JSON.stringify(diagnostic)}`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
console.log(`pbuilder-codegen: generated ${generated}, failed ${failed}, duplicates ${duplicates}`);
|
|
305
|
+
return failed > 0 ? 1 : 0;
|
|
306
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Schema } from "../../../domain/valueobjects/schema-model.ts";
|
|
2
|
+
export declare const GENERATED_HEADER = "// AUTO-GENERATED by pbuilder-codegen \u2014 do not edit. Regenerate: pbuilder-codegen <package-dir>";
|
|
3
|
+
export declare class UnrecognizedPropertyTypeError extends Error {
|
|
4
|
+
readonly field: string;
|
|
5
|
+
constructor(field: string);
|
|
6
|
+
}
|
|
7
|
+
export declare function emitInputType(schema: Schema, digest: string): string;
|
|
@@ -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 {};
|