@pbuilder/sdk 0.1.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/LICENSE +21 -0
- package/README.md +202 -0
- package/dist/bin/pbuilder-codegen.js +506 -0
- package/dist/bin/pbuilder-runner.d.ts +1 -0
- package/dist/bin/pbuilder-runner.js +47 -0
- package/dist/commons/classify-content.d.ts +40 -0
- package/dist/commons/classify-content.js +32 -0
- package/dist/commons/index.d.ts +271 -0
- package/dist/commons/index.js +276 -0
- package/dist/conformance/index.d.ts +115 -0
- package/dist/conformance/index.js +218 -0
- package/dist/conformance/run-vehicle.d.ts +19 -0
- package/dist/conformance/run-vehicle.js +104 -0
- package/dist/core/authoring-error.d.ts +116 -0
- package/dist/core/authoring-error.js +205 -0
- package/dist/core/base-handle.d.ts +17 -0
- package/dist/core/base-handle.js +4 -0
- package/dist/core/context.d.ts +85 -0
- package/dist/core/context.js +356 -0
- package/dist/core/deep-equal.d.ts +1 -0
- package/dist/core/deep-equal.js +29 -0
- package/dist/core/define-dialect.d.ts +94 -0
- package/dist/core/define-dialect.js +121 -0
- package/dist/core/dialect-error.d.ts +8 -0
- package/dist/core/dialect-error.js +26 -0
- package/dist/core/dialect-handle.d.ts +21 -0
- package/dist/core/dialect-handle.js +382 -0
- package/dist/core/directive-factory.d.ts +47 -0
- package/dist/core/directive-factory.js +154 -0
- package/dist/core/emit-rejection.d.ts +19 -0
- package/dist/core/emit-rejection.js +31 -0
- package/dist/core/engine-client.d.ts +7 -0
- package/dist/core/engine-client.js +5 -0
- package/dist/core/fs-errors.d.ts +1 -0
- package/dist/core/fs-errors.js +5 -0
- package/dist/core/handle-state.d.ts +24 -0
- package/dist/core/handle-state.js +4 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.js +6 -0
- package/dist/core/jsx-name-validator.d.ts +19 -0
- package/dist/core/jsx-name-validator.js +104 -0
- package/dist/core/reject-tail.d.ts +23 -0
- package/dist/core/reject-tail.js +63 -0
- package/dist/core/schema/input-rejection.d.ts +4 -0
- package/dist/core/schema/input-rejection.js +32 -0
- package/dist/core/schema/schema-digest.d.ts +1 -0
- package/dist/core/schema/schema-digest.js +7 -0
- package/dist/core/schema/schema-discovery.d.ts +13 -0
- package/dist/core/schema/schema-discovery.js +51 -0
- package/dist/core/schema/schema-locate.d.ts +10 -0
- package/dist/core/schema/schema-locate.js +192 -0
- package/dist/core/schema/schema-model.d.ts +18 -0
- package/dist/core/schema/schema-model.js +15 -0
- package/dist/core/schema/schema-parse.d.ts +20 -0
- package/dist/core/schema/schema-parse.js +80 -0
- package/dist/core/schema/schema-sufficiency.d.ts +17 -0
- package/dist/core/schema/schema-sufficiency.js +54 -0
- package/dist/core/schema/schema-validate.d.ts +14 -0
- package/dist/core/schema/schema-validate.js +64 -0
- package/dist/core/session.d.ts +13 -0
- package/dist/core/session.js +72 -0
- package/dist/core/wire.d.ts +87 -0
- package/dist/core/wire.js +49 -0
- package/dist/dialects/react/ast.d.ts +25 -0
- package/dist/dialects/react/ast.js +80 -0
- package/dist/dialects/react/index.d.ts +39 -0
- package/dist/dialects/react/index.js +71 -0
- package/dist/dialects/react/ops.d.ts +56 -0
- package/dist/dialects/react/ops.js +186 -0
- package/dist/dialects/typescript/ast.d.ts +42 -0
- package/dist/dialects/typescript/ast.js +93 -0
- package/dist/dialects/typescript/index.d.ts +32 -0
- package/dist/dialects/typescript/index.js +40 -0
- package/dist/dialects/typescript/ops.d.ts +123 -0
- package/dist/dialects/typescript/ops.js +365 -0
- package/dist/dry-run/index.d.ts +2 -0
- package/dist/dry-run/index.js +1 -0
- package/dist/dry-run/plan.d.ts +69 -0
- package/dist/dry-run/plan.js +44 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/runner-manifest.json +104 -0
- package/dist/scaffold/classify-transport.d.ts +57 -0
- package/dist/scaffold/classify-transport.js +123 -0
- package/dist/scaffold/containment.d.ts +54 -0
- package/dist/scaffold/containment.js +242 -0
- package/dist/scaffold/expander.d.ts +30 -0
- package/dist/scaffold/expander.js +161 -0
- package/dist/scaffold/filename-pipeline.d.ts +39 -0
- package/dist/scaffold/filename-pipeline.js +125 -0
- package/dist/scaffold/index.d.ts +45 -0
- package/dist/scaffold/index.js +99 -0
- package/dist/scaffold/walk.d.ts +25 -0
- package/dist/scaffold/walk.js +124 -0
- package/dist/testing/contract-fake.d.ts +17 -0
- package/dist/testing/contract-fake.js +221 -0
- package/dist/testing/index.d.ts +84 -0
- package/dist/testing/index.js +82 -0
- package/dist/testing/rejection-messages.d.ts +7 -0
- package/dist/testing/rejection-messages.js +12 -0
- package/dist/transport/bootstrap-bridge.d.ts +33 -0
- package/dist/transport/bootstrap-bridge.js +65 -0
- package/dist/transport/error-text.d.ts +8 -0
- package/dist/transport/error-text.js +44 -0
- package/dist/transport/exit-codes.d.ts +2 -0
- package/dist/transport/exit-codes.js +35 -0
- package/dist/transport/factory-pointer.d.ts +32 -0
- package/dist/transport/factory-pointer.js +63 -0
- package/dist/transport/frame-reader.d.ts +10 -0
- package/dist/transport/frame-reader.js +81 -0
- package/dist/transport/framing.d.ts +20 -0
- package/dist/transport/framing.js +98 -0
- package/dist/transport/runner.d.ts +25 -0
- package/dist/transport/runner.js +308 -0
- package/dist/transport/single-instance-probe.d.ts +23 -0
- package/dist/transport/single-instance-probe.js +119 -0
- package/dist/transport/stdio-engine-client.d.ts +27 -0
- package/dist/transport/stdio-engine-client.js +243 -0
- package/dist/transport/wire-protocol.d.ts +33 -0
- package/dist/transport/wire-protocol.js +22 -0
- package/package.json +93 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
// KIT-03: pure args→Directive; never renders templates, never touches AST.
|
|
2
|
+
// Key-omission semantics are spec-pinned: `"force" in directive === false` when undefined —
|
|
3
|
+
// never emit `force: undefined`.
|
|
4
|
+
export function forceEntry(force) {
|
|
5
|
+
return force !== undefined ? { force } : {};
|
|
6
|
+
}
|
|
7
|
+
// REQ-TOE-01: shallow top-level composite (array/plain-object) -> JSON string; everything
|
|
8
|
+
// else passes through verbatim. Assembly uses Object.defineProperty (never spread/`result[k]=`)
|
|
9
|
+
// per REQ-TOE-05 — enumerable:true is load-bearing, defineProperty defaults it to false and an
|
|
10
|
+
// unenumerable key silently drops from JSON.stringify at the wire boundary.
|
|
11
|
+
// REQ-TOE-01.5: a null-prototype object (Object.create(null)) is a plain, dict-like data
|
|
12
|
+
// container and encodes like any other plain object — only a prototype OUTSIDE
|
|
13
|
+
// {Object.prototype, null} (Date/Map/class instances) is non-plain (REQ-TOE-04, S-002).
|
|
14
|
+
function isPlainObject(v) {
|
|
15
|
+
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
16
|
+
return false;
|
|
17
|
+
const proto = Object.getPrototypeOf(v);
|
|
18
|
+
return proto === Object.prototype || proto === null;
|
|
19
|
+
}
|
|
20
|
+
// REQ-TOE-04: names the offending value's kind for the reject message. Date/Map get their
|
|
21
|
+
// own recognizable name; everything else non-plain (custom class instances) is generic.
|
|
22
|
+
function kindOf(value) {
|
|
23
|
+
if (value instanceof Date)
|
|
24
|
+
return "Date";
|
|
25
|
+
if (value instanceof Map)
|
|
26
|
+
return "Map";
|
|
27
|
+
return "a class instance";
|
|
28
|
+
}
|
|
29
|
+
// REQ-TOE-04, ADR-03: plain Error (interim — full AuthoringError attribution is a
|
|
30
|
+
// registered followup, ADR-03 Consequence). Message template pinned verbatim (slices.md
|
|
31
|
+
// Executor Context, TW-F1): names the top-level offending key, the offending kind + a
|
|
32
|
+
// dotted/indexed location, and echoes docs §8's allowed set for actionability. NEVER raw
|
|
33
|
+
// serializer text (no "Do not know how to serialize a BigInt", no "Converting circular
|
|
34
|
+
// structure to JSON").
|
|
35
|
+
function rejectOption(optionKey, detail) {
|
|
36
|
+
throw new Error(`option "${optionKey}" is not a plain-JSON value the engine can render (${detail}). ` +
|
|
37
|
+
"Options must be strings, numbers, booleans, null, arrays, or plain objects.");
|
|
38
|
+
}
|
|
39
|
+
// REQ-TOE-04: recursively rejects any value (top-level or nested inside a composite) that
|
|
40
|
+
// is undefined, a function, a symbol, a BigInt, a circular reference, or a non-plain object
|
|
41
|
+
// (Date/Map/class instance) — never a silent drop (JSON.stringify's own undefined/function
|
|
42
|
+
// behavior) and never a raw serializer TypeError.
|
|
43
|
+
// ARCH-F2 (design §4.3): `ancestors` is an ANCESTOR-PATH set — added on descent, removed on
|
|
44
|
+
// ascent (add-recurse-delete, scoped per top-level call via the default parameter) — never a
|
|
45
|
+
// global "ever-visited" set. Only a value that is its own ancestor (a true cycle) rejects; an
|
|
46
|
+
// acyclic SHARED reference (`const s = {x:1}; {a:s,b:s}`) is revisited from a clean ancestor
|
|
47
|
+
// path each time and encodes normally, matching native JSON.stringify.
|
|
48
|
+
function assertEncodable(value, optionKey, ancestors = new Set(), path = optionKey) {
|
|
49
|
+
if (value === undefined)
|
|
50
|
+
rejectOption(optionKey, `undefined at ${path}`);
|
|
51
|
+
if (typeof value === "function")
|
|
52
|
+
rejectOption(optionKey, `function at ${path}`);
|
|
53
|
+
if (typeof value === "symbol")
|
|
54
|
+
rejectOption(optionKey, `symbol at ${path}`);
|
|
55
|
+
if (typeof value === "bigint")
|
|
56
|
+
rejectOption(optionKey, `BigInt at ${path}`);
|
|
57
|
+
if (value === null || typeof value !== "object")
|
|
58
|
+
return; // string/number/boolean/null: fine
|
|
59
|
+
if (Array.isArray(value) || isPlainObject(value)) {
|
|
60
|
+
if (ancestors.has(value))
|
|
61
|
+
rejectOption(optionKey, `a circular reference at ${path}`);
|
|
62
|
+
ancestors.add(value);
|
|
63
|
+
try {
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
value.forEach((item, i) => assertEncodable(item, optionKey, ancestors, `${path}[${i}]`));
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
for (const [k, v] of Object.entries(value)) {
|
|
69
|
+
assertEncodable(v, optionKey, ancestors, `${path}.${k}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
ancestors.delete(value);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
rejectOption(optionKey, `${kindOf(value)} at ${path}`);
|
|
79
|
+
}
|
|
80
|
+
export function encodeOptions(options) {
|
|
81
|
+
if (!isPlainObject(options))
|
|
82
|
+
return options;
|
|
83
|
+
const result = {};
|
|
84
|
+
for (const [key, value] of Object.entries(options)) {
|
|
85
|
+
assertEncodable(value, key);
|
|
86
|
+
const encoded = Array.isArray(value) || isPlainObject(value) ? JSON.stringify(value) : value;
|
|
87
|
+
Object.defineProperty(result, key, { value: encoded, enumerable: true, writable: true, configurable: true });
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
export class DirectiveFactory {
|
|
92
|
+
create(a) {
|
|
93
|
+
return {
|
|
94
|
+
op: "create",
|
|
95
|
+
create: {
|
|
96
|
+
pathTemplate: a.pathTemplate,
|
|
97
|
+
template: a.template,
|
|
98
|
+
options: encodeOptions(a.options),
|
|
99
|
+
...forceEntry(a.force),
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
modify(a) {
|
|
104
|
+
return { op: "modify", modify: { path: a.path, content: a.content } };
|
|
105
|
+
}
|
|
106
|
+
// Author verb `remove` lowers to wire op `delete` — ADR-0013 vocabulary; they deliberately differ.
|
|
107
|
+
remove(a) {
|
|
108
|
+
return { op: "delete", delete: { path: a.path } };
|
|
109
|
+
}
|
|
110
|
+
rename(a) {
|
|
111
|
+
return {
|
|
112
|
+
op: "rename",
|
|
113
|
+
rename: {
|
|
114
|
+
path: a.path,
|
|
115
|
+
newName: a.newName,
|
|
116
|
+
...forceEntry(a.force),
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
move(a) {
|
|
121
|
+
return {
|
|
122
|
+
op: "move",
|
|
123
|
+
move: {
|
|
124
|
+
path: a.path,
|
|
125
|
+
toDir: a.toDir,
|
|
126
|
+
...forceEntry(a.force),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
// `copy` emits the ADR-0013 shape only — apply behaviour is deferred to vNext.
|
|
131
|
+
copy(a) {
|
|
132
|
+
return {
|
|
133
|
+
op: "copy",
|
|
134
|
+
copy: {
|
|
135
|
+
from: a.from,
|
|
136
|
+
to: a.to,
|
|
137
|
+
...forceEntry(a.force),
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// `copyIn` mirrors `copy` exactly (ADR-0043) — the distinction is entirely in the `op`
|
|
142
|
+
// name (package-read trust domain, REQ-BRC-02) and what the engine does with `from` at
|
|
143
|
+
// apply time (resolves against packageDir, not tree-relative).
|
|
144
|
+
copyIn(a) {
|
|
145
|
+
return {
|
|
146
|
+
op: "copyIn",
|
|
147
|
+
copyIn: {
|
|
148
|
+
from: a.from,
|
|
149
|
+
to: a.to,
|
|
150
|
+
...forceEntry(a.force),
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type EmitRejectionCode = "collision" | "not-found" | "unrepresentable" | "cap" | "unknown";
|
|
2
|
+
/**
|
|
3
|
+
* Port-contract precondition (ADR-0022 — binding on every EngineClient implementation,
|
|
4
|
+
* including the Stage 6 real engine): a DIRECTIVE-level rejection (`code: "collision" |
|
|
5
|
+
* "not-found"`) MUST carry a `failedIndex` in range of the emitted batch's instructions.
|
|
6
|
+
* A thrower that violates this yields `verb`/`path` `undefined` on the translated
|
|
7
|
+
* `AuthoringError` BY CONTRACT — the translation does not guess an offender, and the
|
|
8
|
+
* message template is selected BY REASON (REQ-AEC-06), never by verb/path presence, so
|
|
9
|
+
* no fallback masks the violation.
|
|
10
|
+
*/
|
|
11
|
+
export declare class EmitRejection extends Error {
|
|
12
|
+
readonly code: EmitRejectionCode;
|
|
13
|
+
readonly failedIndex?: number;
|
|
14
|
+
readonly appliedCount: number;
|
|
15
|
+
constructor(code: EmitRejectionCode, message: string, pos?: {
|
|
16
|
+
failedIndex: number;
|
|
17
|
+
appliedCount: number;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// SEAM-04 port-internal rejection shape (ADR-0022). `EmitRejection` carries WHICH
|
|
2
|
+
// directive failed (`failedIndex`, directive-level only) and how many already applied,
|
|
3
|
+
// classified by a closed `code` — never by message text (REQ-ERM-01 ban on string
|
|
4
|
+
// parsing). It is a contributor-kit concern (ADR-0009): never re-exported from
|
|
5
|
+
// `src/core/index.ts`, never crosses to `./commons`. FIT-10 extends its structural port
|
|
6
|
+
// guard to this identifier; the only consumers are `authoring-error.ts` (translation)
|
|
7
|
+
// and the allow-listed `test/support/contract-fake.ts` (the one legitimate thrower).
|
|
8
|
+
/**
|
|
9
|
+
* Port-contract precondition (ADR-0022 — binding on every EngineClient implementation,
|
|
10
|
+
* including the Stage 6 real engine): a DIRECTIVE-level rejection (`code: "collision" |
|
|
11
|
+
* "not-found"`) MUST carry a `failedIndex` in range of the emitted batch's instructions.
|
|
12
|
+
* A thrower that violates this yields `verb`/`path` `undefined` on the translated
|
|
13
|
+
* `AuthoringError` BY CONTRACT — the translation does not guess an offender, and the
|
|
14
|
+
* message template is selected BY REASON (REQ-AEC-06), never by verb/path presence, so
|
|
15
|
+
* no fallback masks the violation.
|
|
16
|
+
*/
|
|
17
|
+
export class EmitRejection extends Error {
|
|
18
|
+
code;
|
|
19
|
+
// Directive-level only — absent for a batch-level rejection (no directive to blame).
|
|
20
|
+
failedIndex;
|
|
21
|
+
// Directive-level: === failedIndex (every earlier directive in this batch applied).
|
|
22
|
+
// Batch-level: 0 (rejected before the apply loop starts).
|
|
23
|
+
appliedCount;
|
|
24
|
+
constructor(code, message, pos) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.name = "EmitRejection";
|
|
27
|
+
this.code = code;
|
|
28
|
+
this.failedIndex = pos?.failedIndex;
|
|
29
|
+
this.appliedCount = pos?.appliedCount ?? 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// KIT-01: sole transport seam. The fake and the real client both implement this.
|
|
2
|
+
// read() returns Promise<string | undefined> — content string, or undefined for not-found
|
|
3
|
+
// (ADR-01: the PORT owns the not-found contract; not-found is a return, never a throw). The
|
|
4
|
+
// served-from tag is fake-internal state, never in the read return.
|
|
5
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isErrnoException(err: unknown): err is NodeJS.ErrnoException;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ReadOps, WriteOps } from "./base-handle.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Returned by every write verb (`create`, `replaceContent`, `rename`, `move`, `copy`).
|
|
4
|
+
* Supports chaining — each method returns a fresh `WritableHandle` for the result path.
|
|
5
|
+
* Does NOT have `remove()`: a write makes remove incoherent (ADR-0004 chaining table).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const h = replaceContent("src/config.ts", "export const version = '2.0.0';");
|
|
9
|
+
* const c = await h.read(); // string | undefined — branch with === undefined / === ""
|
|
10
|
+
*/
|
|
11
|
+
export interface WritableHandle extends ReadOps, WriteOps {
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returned exclusively by `find(path)`.
|
|
15
|
+
* Has `remove()` because an unmodified found file may be deleted.
|
|
16
|
+
* `remove` is absent from `WritableHandle` so `create().remove` does not typecheck.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const h = find("src/legacy.ts");
|
|
20
|
+
* h.remove();
|
|
21
|
+
*/
|
|
22
|
+
export interface FoundHandle extends ReadOps, WriteOps {
|
|
23
|
+
remove(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { EngineClient } from "./engine-client.ts";
|
|
2
|
+
export type { Batch, Directive, JsonValue } from "./wire.ts";
|
|
3
|
+
export { Session } from "./session.ts";
|
|
4
|
+
export { DirectiveFactory } from "./directive-factory.ts";
|
|
5
|
+
export type { RunContext } from "./context.ts";
|
|
6
|
+
export { defineFactory, currentContext } from "./context.ts";
|
|
7
|
+
export type { ReadOps, WriteOps, WritableHandleRef } from "./base-handle.ts";
|
|
8
|
+
export type { FoundHandle, WritableHandle } from "./handle-state.ts";
|
|
9
|
+
export { defineDialect, defineOpPack, withOps } from "./define-dialect.ts";
|
|
10
|
+
export type { Dialect, OpPack } from "./define-dialect.ts";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Internal kit root (ADR-0009 boundary). Not exported to authors.
|
|
2
|
+
// Extraction-ready: becomes @pbuilder/sdk-kit when the first external dialect lands.
|
|
3
|
+
export { Session } from "./session.js";
|
|
4
|
+
export { DirectiveFactory } from "./directive-factory.js";
|
|
5
|
+
export { defineFactory, currentContext } from "./context.js";
|
|
6
|
+
export { defineDialect, defineOpPack, withOps } from "./define-dialect.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** V4 denylist, checked via `.has()` equality only — NEVER an object literal, never regex-encoded. */
|
|
2
|
+
export declare const JSX_NAME_DENYLIST: ReadonlySet<string>;
|
|
3
|
+
export declare const IMPORT_RESERVED_WORDS: ReadonlySet<string>;
|
|
4
|
+
/** `assertValidAttributeName`'s propName grammar — hyphens + one optional `:namespace` segment. */
|
|
5
|
+
export declare function assertValidAttributeName(propName: string): void;
|
|
6
|
+
/** `assertValidElementName`'s lookup-only JSX-name grammar — identifier/hyphenated, dot-joined. */
|
|
7
|
+
export declare function assertValidElementName(elementName: string): void;
|
|
8
|
+
/**
|
|
9
|
+
* `assertValidImportBinding`'s plain-JS-identifier grammar. The regex alone admits any
|
|
10
|
+
* `IdentifierName` (including reserved words) — `import { name }` requires a `BindingIdentifier`,
|
|
11
|
+
* so a reserved-word check (V5, SEC-1) runs alongside the denylist.
|
|
12
|
+
*/
|
|
13
|
+
export declare function assertValidImportBinding(name: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* The single validate-before-mutate chokepoint (ADR-02): `validators` runs first over the
|
|
16
|
+
* op's full argument tuple and throws via `dialectError` on any failure — `body` (the actual
|
|
17
|
+
* mutation) is structurally unreachable before every declared arg validates.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validatedOp<Ast, A extends unknown[]>(validators: (args: A) => void, body: (ast: Ast, ...args: A) => void): (ast: Ast, ...args: A) => void;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// S-001: the single validate-before-mutate chokepoint (design §4.4/ADR-02) — three per-arg
|
|
2
|
+
// grammars, a frozen denylist, and `validatedOp`, the higher-order wrapper every react op
|
|
3
|
+
// composes with so mutation code (`body`) is structurally unreachable before every declared
|
|
4
|
+
// arg validates. Kit-internal: no barrel/subpath export (dialect-error.ts/deep-equal.ts
|
|
5
|
+
// precedent — see src/core/index.ts, which does not re-export this module).
|
|
6
|
+
//
|
|
7
|
+
// Set-key-safety clause (ADR-02): `propName`/`elementName` are NEVER used as plain-object
|
|
8
|
+
// keys anywhere in this file or src/dialects/react/** — no `record[name]`, no `{[name]: …}`,
|
|
9
|
+
// no `counts[tag]++`. Set/Map/`===` only. This, not denylist width, is the real Stage-4b
|
|
10
|
+
// `__proto__` defence (test/dialects/react/name-validation.test.ts pins it via static scan).
|
|
11
|
+
import { dialectError } from "./dialect-error.js";
|
|
12
|
+
import { boundedFragment, nameRuleTail } from "./reject-tail.js";
|
|
13
|
+
// judgment-day (comment-only fix): "Frozen" previously implied a RUNTIME immutability
|
|
14
|
+
// guarantee. `ReadonlySet<string>` is a compile-time-only guard — it does not stop
|
|
15
|
+
// `Set.prototype.add`/`.delete`/`.clear` at runtime, and no `Object.freeze` wraps this value
|
|
16
|
+
// (a prior gate correctly ruled that actually freezing it would be theatre: the module is
|
|
17
|
+
// kit-internal, never re-exported through any barrel/subpath, so no external caller can ever
|
|
18
|
+
// obtain a reference to mutate it). The real, load-bearing property is Set-key-safety
|
|
19
|
+
// (below) and membership via `.has()` equality — never denylist-object mutability.
|
|
20
|
+
/** V4 denylist, checked via `.has()` equality only — NEVER an object literal, never regex-encoded. */
|
|
21
|
+
export const JSX_NAME_DENYLIST = new Set(["__proto__", "constructor", "prototype"]);
|
|
22
|
+
// V5 (REQ-RXD-06, SEC-1): `IMPORT_BINDING_GRAMMAR` alone admits any `IdentifierName`, not a
|
|
23
|
+
// `BindingIdentifier` — `import { name }` requires the latter. This set (36 always-reserved
|
|
24
|
+
// ECMAScript keywords + 9 strict-mode-reserved words + `await`, which is reserved
|
|
25
|
+
// unconditionally here because `addImport` always emits into an ES module, and ES modules are
|
|
26
|
+
// always strict) closes that gap. Typed `ReadonlySet<string>` — a compile-time-only guard, not
|
|
27
|
+
// a runtime freeze (see the note above `JSX_NAME_DENYLIST`); its membership is `.has()`
|
|
28
|
+
// equality only — never regex-encoded — same mechanism as `JSX_NAME_DENYLIST`.
|
|
29
|
+
//
|
|
30
|
+
// V6 (F-1): `eval`/`arguments` added — 46 -> 48. These are strict-mode-RESTRICTED
|
|
31
|
+
// `BindingIdentifier` names, a DIFFERENT grammar category from the 46 reserved words above: both
|
|
32
|
+
// remain valid identifiers outside binding position, so a reserved-word set cannot contain them
|
|
33
|
+
// by construction. The set is now COMPLETE for the BindingIdentifier-in-strict-ES-module problem
|
|
34
|
+
// this argument validates (proven by exhaustive sweep against node's real ES module parser).
|
|
35
|
+
export const IMPORT_RESERVED_WORDS = new Set([
|
|
36
|
+
"break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do",
|
|
37
|
+
"else", "enum", "export", "extends", "false", "finally", "for", "function", "if", "import", "in",
|
|
38
|
+
"instanceof", "new", "null", "return", "super", "switch", "this", "throw", "true", "try", "typeof",
|
|
39
|
+
"var", "void", "while", "with",
|
|
40
|
+
"implements", "interface", "let", "package", "private", "protected", "public", "static", "yield",
|
|
41
|
+
"await",
|
|
42
|
+
"eval", "arguments",
|
|
43
|
+
]);
|
|
44
|
+
// Verbatim from the shared contract (slices.md rev 2, "Name grammars + denylist"):
|
|
45
|
+
// - attribute name: letters/digits/underscore/hyphen, one optional `:namespace` segment.
|
|
46
|
+
// - element name (lookup-only, never spliced): identifier-or-hyphenated segments, dot-joined
|
|
47
|
+
// (admits `Button`, `Menu.Item`, `my-web-component`).
|
|
48
|
+
// - import binding: a plain JS identifier (no alias handling).
|
|
49
|
+
const ATTRIBUTE_NAME_GRAMMAR = /^[A-Za-z_][A-Za-z0-9_-]*(:[A-Za-z_][A-Za-z0-9_-]*)?$/;
|
|
50
|
+
const ELEMENT_NAME_GRAMMAR = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)*$/;
|
|
51
|
+
const IMPORT_BINDING_GRAMMAR = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
52
|
+
// Denylist reject: MAY echo the fixed literal (it's the rule's own vocabulary, not author
|
|
53
|
+
// data, and every denylisted name is well under the 16-char `boundedFragment` ceiling).
|
|
54
|
+
function assertNotDenylisted(argName, value) {
|
|
55
|
+
if (!JSX_NAME_DENYLIST.has(value))
|
|
56
|
+
return;
|
|
57
|
+
throw dialectError(`\`${argName}\` "${boundedFragment(value)}" is a reserved name and cannot be used — fix the name, ` +
|
|
58
|
+
"or use `.modify()` to make this edit directly.");
|
|
59
|
+
}
|
|
60
|
+
// Reserved-word reject (V5, SEC-1): exact Set membership only, never substring/prefix — a
|
|
61
|
+
// name that merely CONTAINS a reserved word (`classroom`, `imported`, `defaultValue`) passes.
|
|
62
|
+
function assertNotReservedWord(argName, value) {
|
|
63
|
+
if (!IMPORT_RESERVED_WORDS.has(value))
|
|
64
|
+
return;
|
|
65
|
+
throw dialectError(`\`${argName}\` "${boundedFragment(value)}" is a reserved word and cannot be used as an import ` +
|
|
66
|
+
"binding — fix the name, or use `.modify()` to make this edit directly.");
|
|
67
|
+
}
|
|
68
|
+
// Grammar reject: routes through `nameRuleTail` — default ZERO echo of the rejected value.
|
|
69
|
+
function assertGrammar(argName, value, grammar, ruleLabel) {
|
|
70
|
+
if (grammar.test(value))
|
|
71
|
+
return;
|
|
72
|
+
throw dialectError(nameRuleTail(argName, ruleLabel));
|
|
73
|
+
}
|
|
74
|
+
/** `assertValidAttributeName`'s propName grammar — hyphens + one optional `:namespace` segment. */
|
|
75
|
+
export function assertValidAttributeName(propName) {
|
|
76
|
+
assertGrammar("propName", propName, ATTRIBUTE_NAME_GRAMMAR, "match the attribute-name grammar (letters, digits, underscore, and hyphen, with one optional `:namespace` segment)");
|
|
77
|
+
assertNotDenylisted("propName", propName);
|
|
78
|
+
}
|
|
79
|
+
/** `assertValidElementName`'s lookup-only JSX-name grammar — identifier/hyphenated, dot-joined. */
|
|
80
|
+
export function assertValidElementName(elementName) {
|
|
81
|
+
assertGrammar("elementName", elementName, ELEMENT_NAME_GRAMMAR, "match the JSX element-name grammar (identifier or hyphenated segments, optionally joined by `.`)");
|
|
82
|
+
assertNotDenylisted("elementName", elementName);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* `assertValidImportBinding`'s plain-JS-identifier grammar. The regex alone admits any
|
|
86
|
+
* `IdentifierName` (including reserved words) — `import { name }` requires a `BindingIdentifier`,
|
|
87
|
+
* so a reserved-word check (V5, SEC-1) runs alongside the denylist.
|
|
88
|
+
*/
|
|
89
|
+
export function assertValidImportBinding(name) {
|
|
90
|
+
assertGrammar("name", name, IMPORT_BINDING_GRAMMAR, "be a valid JavaScript identifier");
|
|
91
|
+
assertNotReservedWord("name", name);
|
|
92
|
+
assertNotDenylisted("name", name);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The single validate-before-mutate chokepoint (ADR-02): `validators` runs first over the
|
|
96
|
+
* op's full argument tuple and throws via `dialectError` on any failure — `body` (the actual
|
|
97
|
+
* mutation) is structurally unreachable before every declared arg validates.
|
|
98
|
+
*/
|
|
99
|
+
export function validatedOp(validators, body) {
|
|
100
|
+
return (ast, ...args) => {
|
|
101
|
+
validators(args);
|
|
102
|
+
body(ast, ...args);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Hard 16-char ceiling for the rare diagnostic fragment — never a norm, always a last resort. */
|
|
2
|
+
export declare function boundedFragment(s: string, cap?: number): string;
|
|
3
|
+
/** `zeroMatchTail`/`multiMatchTail`'s `elementName` echo bound — see the note above `boundedFragment`. */
|
|
4
|
+
export declare function elementNameEcho(s: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Builds a reject tail naming `argName` + `ruleLabel` plus the standard two-remedy pair (fix
|
|
7
|
+
* the name / use `.modify()`) — never the rejected VALUE (REQ-RXD-13.3's zero-echo contract).
|
|
8
|
+
*/
|
|
9
|
+
export declare function nameRuleTail(argName: string, ruleLabel: string): string;
|
|
10
|
+
/** `setJsxProp`'s zero-match reject tail (REQ-RXD-04.4) — names the missing element, bounded. */
|
|
11
|
+
export declare function zeroMatchTail(elementName: string): string;
|
|
12
|
+
/** `setJsxProp`'s multi-match reject tail (REQ-RXD-04.5) — names the element + count, bounded. */
|
|
13
|
+
export declare function multiMatchTail(elementName: string, matchCount: number): string;
|
|
14
|
+
/**
|
|
15
|
+
* `addImport`'s file-wide collision reject tail (REQ-RXD-05, V7 Step 2; echo bound fixed V8,
|
|
16
|
+
* REQ-RXD-05.18) — names `name` and the rule. `name` is POST-VALIDATION at this point
|
|
17
|
+
* (REQ-RXD-06 already ran), so — the same class as `zeroMatchTail`/`multiMatchTail`'s
|
|
18
|
+
* `elementName` echo — it routes through the wider, marked `elementNameEcho` bound, NEVER
|
|
19
|
+
* REQ-RXD-13's 16-char hostile-value `boundedFragment` cap (that cap silently mangled
|
|
20
|
+
* realistic names, e.g. `useDebouncedCallback` -> `useDebouncedCall`, with no signal anything
|
|
21
|
+
* was cut).
|
|
22
|
+
*/
|
|
23
|
+
export declare function claimedNameTail(name: string): string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// S-001: the no-echo tail chokepoint (design §4.4, ADR-02). Every react validator/targeting
|
|
2
|
+
// reject routes its message through here — default ZERO echo of the rejected VALUE (argument
|
|
3
|
+
// NAMES may appear freely; the hostile value itself never does). `boundedFragment` exists for
|
|
4
|
+
// the rare diagnostic that MUST echo a fixed, non-hostile literal (e.g. a denylist entry) —
|
|
5
|
+
// its 16-char cap is a ceiling, not a norm; most tails never call it.
|
|
6
|
+
/** Hard 16-char ceiling for the rare diagnostic fragment — never a norm, always a last resort. */
|
|
7
|
+
export function boundedFragment(s, cap = 16) {
|
|
8
|
+
return s.length > cap ? s.slice(0, cap) : s;
|
|
9
|
+
}
|
|
10
|
+
// `boundedFragment`'s 16-char cap is sized for REQ-RXD-13's hostile-VALUE diagnostics — never
|
|
11
|
+
// widen it, that's a different reject class with a signed cap. `setJsxProp`'s match-count
|
|
12
|
+
// rejects (REQ-RXD-04) echo `elementName` instead: a POST-VALIDATION, grammar-constrained
|
|
13
|
+
// argument (no quotes, no newlines — never an injection vector), not a hostile value, so
|
|
14
|
+
// reusing the 16-char cap here bought nothing but silently mangled ordinary component names
|
|
15
|
+
// (`NotificationPreferencesPanel` -> `NotificationPref`) into ones matching nothing in the
|
|
16
|
+
// author's source, with no signal anything was cut. This wider cap comfortably covers
|
|
17
|
+
// realistic component names; on the rare name that still exceeds it, an explicit `…` marker is
|
|
18
|
+
// appended so a cut name is never mistaken for the element's real one.
|
|
19
|
+
const ELEMENT_NAME_ECHO_CAP = 100;
|
|
20
|
+
/** `zeroMatchTail`/`multiMatchTail`'s `elementName` echo bound — see the note above `boundedFragment`. */
|
|
21
|
+
export function elementNameEcho(s) {
|
|
22
|
+
return s.length > ELEMENT_NAME_ECHO_CAP ? `${s.slice(0, ELEMENT_NAME_ECHO_CAP)}…` : s;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Builds a reject tail naming `argName` + `ruleLabel` plus the standard two-remedy pair (fix
|
|
26
|
+
* the name / use `.modify()`) — never the rejected VALUE (REQ-RXD-13.3's zero-echo contract).
|
|
27
|
+
*/
|
|
28
|
+
export function nameRuleTail(argName, ruleLabel) {
|
|
29
|
+
return `\`${argName}\` must ${ruleLabel} — fix the name, or use \`.modify()\` to make this edit directly.`;
|
|
30
|
+
}
|
|
31
|
+
// ARCH-3 (council; corrected V8 — judgment-day Round 2, Judge B): `setJsxProp`'s match-count
|
|
32
|
+
// rejects (REQ-RXD-04) echo a POST-VALIDATION argument value (`elementName`) rather than
|
|
33
|
+
// refusing to — deliberate UX (naming which element wasn't found / matched), sanctioned by
|
|
34
|
+
// design §4.4. `elementName` is grammar-constrained (no quotes, no newlines — never an
|
|
35
|
+
// injection vector), but the grammar has no LENGTH ceiling, so the echo routes through
|
|
36
|
+
// `elementNameEcho` (the wide, marked 100-char bound above) — NOT `boundedFragment`'s 16-char
|
|
37
|
+
// hostile-value cap — keeping every react reject message bounded without mangling ordinary
|
|
38
|
+
// names. `addImport`'s collision-reject tail (`claimedNameTail`, below) echoes `name` the same
|
|
39
|
+
// way, for the same reason (V8).
|
|
40
|
+
/** `setJsxProp`'s zero-match reject tail (REQ-RXD-04.4) — names the missing element, bounded. */
|
|
41
|
+
export function zeroMatchTail(elementName) {
|
|
42
|
+
return (`no element named \`${elementNameEcho(elementName)}\` was found — use \`.modify()\` to inspect ` +
|
|
43
|
+
"the file and edit it directly.");
|
|
44
|
+
}
|
|
45
|
+
/** `setJsxProp`'s multi-match reject tail (REQ-RXD-04.5) — names the element + count, bounded. */
|
|
46
|
+
export function multiMatchTail(elementName, matchCount) {
|
|
47
|
+
return (`\`${elementNameEcho(elementName)}\` matched ${matchCount} elements — setJsxProp requires ` +
|
|
48
|
+
"exactly one match; use `.modify()` to disambiguate.");
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* `addImport`'s file-wide collision reject tail (REQ-RXD-05, V7 Step 2; echo bound fixed V8,
|
|
52
|
+
* REQ-RXD-05.18) — names `name` and the rule. `name` is POST-VALIDATION at this point
|
|
53
|
+
* (REQ-RXD-06 already ran), so — the same class as `zeroMatchTail`/`multiMatchTail`'s
|
|
54
|
+
* `elementName` echo — it routes through the wider, marked `elementNameEcho` bound, NEVER
|
|
55
|
+
* REQ-RXD-13's 16-char hostile-value `boundedFragment` cap (that cap silently mangled
|
|
56
|
+
* realistic names, e.g. `useDebouncedCallback` -> `useDebouncedCall`, with no signal anything
|
|
57
|
+
* was cut).
|
|
58
|
+
*/
|
|
59
|
+
export function claimedNameTail(name) {
|
|
60
|
+
return (`\`name\` "${elementNameEcho(name)}" is already bound elsewhere in the file — addImport ` +
|
|
61
|
+
"cannot create a second local binding under an already-claimed name; rename the existing " +
|
|
62
|
+
"binding or choose a different `name`, or use `.modify()` to make this edit directly.");
|
|
63
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { AuthoringError } from "../authoring-error.ts";
|
|
2
|
+
import type { ValidationFinding } from "./schema-validate.ts";
|
|
3
|
+
export declare function rejectionFor(finding: ValidationFinding): AuthoringError;
|
|
4
|
+
export declare function rejectionForReservedName(name: string): AuthoringError;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Maps a validation finding -> a thrown rejection (design §4.2). S-006 (post
|
|
2
|
+
// stage-2-error-attribution archive + coordinated amendment, REQ-AEC-07/08/09): both throw
|
|
3
|
+
// sites construct `AuthoringError{origin:"authoring-rejected", reason}` via
|
|
4
|
+
// authoring-error.ts's public API — the constructor's `message` field overrides the
|
|
5
|
+
// derived template (authoring-error.ts's `messageFor` has no default for these two
|
|
6
|
+
// SDK-side reasons; see its own comment). This file stays the sole Stage-2-coupled module
|
|
7
|
+
// (constraint 1/6) — both this cluster's throw sites (run-boundary validation AND
|
|
8
|
+
// reserved-lifecycle-name rejection, S-004) live here, one place for the S-006 upgrade.
|
|
9
|
+
//
|
|
10
|
+
// Message literals are REQ-AEC-09's single source of truth (slices Load-bearing literals),
|
|
11
|
+
// UNCHANGED by this upgrade — only the thrown value's shape changed, not its text:
|
|
12
|
+
// `invalid input: {field} must be {expectedType}` (missing/wrong-type);
|
|
13
|
+
// `invalid input: {field} is a reserved or disallowed key` (excess/reserved-input-key/
|
|
14
|
+
// proto-key — branch→template mapping, all three collapse to one template);
|
|
15
|
+
// `reserved lifecycle name: {name} is reserved and cannot be declared by a factory module`
|
|
16
|
+
// (RLN-02.1, distinguishable-in-kind from the two templates above by literal text alone).
|
|
17
|
+
import { AuthoringError } from "../authoring-error.js";
|
|
18
|
+
function rejection(reason, message) {
|
|
19
|
+
return new AuthoringError({ verb: undefined, path: undefined, appliedCount: 0, reason, message });
|
|
20
|
+
}
|
|
21
|
+
export function rejectionFor(finding) {
|
|
22
|
+
switch (finding.kind) {
|
|
23
|
+
case "missing":
|
|
24
|
+
case "wrong-type":
|
|
25
|
+
return rejection("invalid-input", `invalid input: ${finding.field} must be ${finding.expectedType}`);
|
|
26
|
+
case "disallowed-key":
|
|
27
|
+
return rejection("invalid-input", `invalid input: ${finding.field} is a reserved or disallowed key`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function rejectionForReservedName(name) {
|
|
31
|
+
return rejection("reserved-name", `reserved lifecycle name: ${name} is reserved and cannot be declared by a factory module`);
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function computeSchemaDigest(raw: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// SHA-256 of a schema.json's raw bytes (design §4.2). The bin embeds this in the
|
|
2
|
+
// generated header's `// @schema-digest sha256:<...>` line; FIT-12 (S-002) recomputes it
|
|
3
|
+
// against the committed schema.json to detect drift without a text diff.
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
export function computeSchemaDigest(raw) {
|
|
6
|
+
return createHash("sha256").update(raw, "utf8").digest("hex");
|
|
7
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const SCHEMA_FILENAME = "schema.json";
|
|
2
|
+
export declare function schemaPathFor(packageDir: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* Scans a factory package's OWN DIRECTORY ENTRIES (never resolved run-time inputs and
|
|
5
|
+
* never `schema.json` field names — REQ-RLN-01) for a reserved-lifecycle-name sibling: a
|
|
6
|
+
* `pre-execute`/`post-execute` file (`.ts`/`.js`, case-insensitive) or directory (dir-form,
|
|
7
|
+
* e.g. `pre-execute/index.ts`). Returns the matched reserved name, or `undefined` for a
|
|
8
|
+
* clean package. A non-existent package directory (ENOENT) is not a failure — returns
|
|
9
|
+
* `undefined`, same as "no reserved siblings" (mirrors RBV-03's opt-out posture); any other
|
|
10
|
+
* read error (EACCES/EPERM/EISDIR) FAILS CLOSED — thrown, never silently downgraded
|
|
11
|
+
* (constraint 4, SEC-3).
|
|
12
|
+
*/
|
|
13
|
+
export declare function findReservedSibling(packageDir: string): string | undefined;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Locates a factory package's adjacent schema.json (design §4.2, REQ-FPS-01.1, ADR-0031),
|
|
2
|
+
// and (S-004) its reserved-lifecycle-name siblings (REQ-RLN-01, ADR-0028). No configuration
|
|
3
|
+
// surface — the canonical shapes are fixed and discoverable from the package directory alone.
|
|
4
|
+
import { readdirSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { RESERVED_LIFECYCLE_NAMES } from "./schema-model.js";
|
|
7
|
+
import { isErrnoException } from "../fs-errors.js";
|
|
8
|
+
export const SCHEMA_FILENAME = "schema.json";
|
|
9
|
+
export function schemaPathFor(packageDir) {
|
|
10
|
+
return join(packageDir, SCHEMA_FILENAME);
|
|
11
|
+
}
|
|
12
|
+
const RESERVED_EXTENSIONS = [".ts", ".js"];
|
|
13
|
+
// Strips a recognized extension (case-insensitively) so `pre-execute.ts`, `PRE-EXECUTE.TS`,
|
|
14
|
+
// and the dir-form entry `pre-execute` (no extension at all) all normalize to the same
|
|
15
|
+
// lowercase kebab token before comparison (ADR-0028: case-insensitive, strip-extension).
|
|
16
|
+
function normalizeEntry(name) {
|
|
17
|
+
const lower = name.toLowerCase();
|
|
18
|
+
for (const ext of RESERVED_EXTENSIONS) {
|
|
19
|
+
if (lower.endsWith(ext))
|
|
20
|
+
return lower.slice(0, -ext.length);
|
|
21
|
+
}
|
|
22
|
+
return lower;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Scans a factory package's OWN DIRECTORY ENTRIES (never resolved run-time inputs and
|
|
26
|
+
* never `schema.json` field names — REQ-RLN-01) for a reserved-lifecycle-name sibling: a
|
|
27
|
+
* `pre-execute`/`post-execute` file (`.ts`/`.js`, case-insensitive) or directory (dir-form,
|
|
28
|
+
* e.g. `pre-execute/index.ts`). Returns the matched reserved name, or `undefined` for a
|
|
29
|
+
* clean package. A non-existent package directory (ENOENT) is not a failure — returns
|
|
30
|
+
* `undefined`, same as "no reserved siblings" (mirrors RBV-03's opt-out posture); any other
|
|
31
|
+
* read error (EACCES/EPERM/EISDIR) FAILS CLOSED — thrown, never silently downgraded
|
|
32
|
+
* (constraint 4, SEC-3).
|
|
33
|
+
*/
|
|
34
|
+
export function findReservedSibling(packageDir) {
|
|
35
|
+
let entries;
|
|
36
|
+
try {
|
|
37
|
+
entries = readdirSync(packageDir);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
if (isErrnoException(err) && err.code === "ENOENT")
|
|
41
|
+
return undefined;
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
for (const entry of entries) {
|
|
45
|
+
const normalized = normalizeEntry(entry);
|
|
46
|
+
const match = RESERVED_LIFECYCLE_NAMES.find((name) => name === normalized);
|
|
47
|
+
if (match !== undefined)
|
|
48
|
+
return match;
|
|
49
|
+
}
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-scans `raw` (text already rejected by `JSON.parse`) to pin the 1-based `{line, column}`
|
|
3
|
+
* of the first JSON-grammar deviation. Returns `undefined` when the scanner completes without
|
|
4
|
+
* finding one — either an in-string escape violation (bounded fidelity, ADR-0032) or a
|
|
5
|
+
* defensive scanner/`JSON.parse` divergence. Pure; no I/O.
|
|
6
|
+
*/
|
|
7
|
+
export declare function locateFirstJsonSyntaxError(raw: string): {
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
} | undefined;
|