@pbuilder/sdk 0.14.0 → 0.15.1
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
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
// module lives under src/core/**, is never a public subpath, and its shape is not
|
|
7
7
|
// fitness-pinned. Only the PUBLIC `find(path)` signature and the `Handle<State, Ast, Ops>`
|
|
8
8
|
// TYPE (define-dialect.ts) are frozen.
|
|
9
|
-
import {
|
|
10
|
-
import { dialectError, isContained } from "
|
|
9
|
+
import { currentRun } from "../services/run-context.js";
|
|
10
|
+
import { dialectError, isContained } from "../valueobjects/dialect-error.js";
|
|
11
11
|
// `.modify()`'s `fn` is typed `(ast: Ast) => void`, but TS's void-return compatibility lets an
|
|
12
12
|
// author pass an async function anyway — this is the runtime check that catches that case.
|
|
13
13
|
function isThenable(value) {
|
|
@@ -129,7 +129,7 @@ class DialectHandleController {
|
|
|
129
129
|
// one every later op/read surfaces, unchanged).
|
|
130
130
|
#chain(step) {
|
|
131
131
|
const guardedStep = async () => {
|
|
132
|
-
const ctx =
|
|
132
|
+
const ctx = currentRun();
|
|
133
133
|
if (ctx.sessionFailure !== undefined) {
|
|
134
134
|
throw ctx.sessionFailure.reason;
|
|
135
135
|
}
|
|
@@ -156,7 +156,7 @@ class DialectHandleController {
|
|
|
156
156
|
}
|
|
157
157
|
#bufferDirective(build) {
|
|
158
158
|
this.#enqueue(() => {
|
|
159
|
-
const { session, factory } =
|
|
159
|
+
const { session, factory } = currentRun();
|
|
160
160
|
session.buffer(build(factory));
|
|
161
161
|
});
|
|
162
162
|
}
|
|
@@ -164,12 +164,12 @@ class DialectHandleController {
|
|
|
164
164
|
if (this.#registered)
|
|
165
165
|
return;
|
|
166
166
|
this.#registered = true;
|
|
167
|
-
|
|
167
|
+
currentRun().dialects.register({ settle: () => this.settle() });
|
|
168
168
|
}
|
|
169
169
|
async #ensureLive() {
|
|
170
170
|
if (this.#live !== undefined)
|
|
171
171
|
return;
|
|
172
|
-
const { session } =
|
|
172
|
+
const { session } = currentRun();
|
|
173
173
|
const content = await session.read(this.#path);
|
|
174
174
|
if (content === undefined) {
|
|
175
175
|
throw dialectError(`"${this.#path}" does not exist — create it first in this run`);
|
|
@@ -195,7 +195,7 @@ class DialectHandleController {
|
|
|
195
195
|
// buffered, undrained? #ensureOpen consults it to skip re-registration while the prior
|
|
196
196
|
// directive is still pending; runReplaceContent consults the SAME check to reject a
|
|
197
197
|
// conflicting .replaceContent() (ADR-0039). `session` is passed in rather than re-derived
|
|
198
|
-
// via
|
|
198
|
+
// via currentRun() — both call sites already have it in scope from their own context
|
|
199
199
|
// lookup.
|
|
200
200
|
#hasOpenPendingDirective(session) {
|
|
201
201
|
return this.#openDirective !== undefined && session.isPending(this.#openDirective);
|
|
@@ -223,7 +223,7 @@ class DialectHandleController {
|
|
|
223
223
|
// #openDirective so the zero-directive gate below re-evaluates against the fresh baseline
|
|
224
224
|
// instead of unconditionally re-registering a byte-identical directive.
|
|
225
225
|
#ensureOpen() {
|
|
226
|
-
const { session } =
|
|
226
|
+
const { session } = currentRun();
|
|
227
227
|
if (this.#hasOpenPendingDirective(session)) {
|
|
228
228
|
return;
|
|
229
229
|
}
|
|
@@ -322,7 +322,7 @@ class DialectHandleController {
|
|
|
322
322
|
// first, so a `.replaceContent()` chained after a `.read()` is unaffected).
|
|
323
323
|
runReplaceContent(content) {
|
|
324
324
|
this.#enqueue(() => {
|
|
325
|
-
const { session, factory } =
|
|
325
|
+
const { session, factory } = currentRun();
|
|
326
326
|
if (this.#hasOpenPendingDirective(session)) {
|
|
327
327
|
throw dialectError(`cannot .replaceContent() "${this.#path}" while a structured edit is pending — the pending edit would be lost; call .read() to commit it first, then .replaceContent()`);
|
|
328
328
|
}
|
|
@@ -351,7 +351,7 @@ class DialectHandleController {
|
|
|
351
351
|
// one mechanism instead of two subtly different ones.
|
|
352
352
|
read() {
|
|
353
353
|
return this.#chain(async () => {
|
|
354
|
-
const { session } =
|
|
354
|
+
const { session } = currentRun();
|
|
355
355
|
return session.read(this.#path);
|
|
356
356
|
});
|
|
357
357
|
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare class PackageReadFailure extends Error {
|
|
2
|
+
readonly problem: string;
|
|
3
|
+
constructor(problem: string);
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* What a package-local source path holds, following symlinks. `unreadable` carries the
|
|
7
|
+
* author-facing category; the path is resolved lexically against the package folder, never
|
|
8
|
+
* canonicalized on disk.
|
|
9
|
+
*/
|
|
10
|
+
export type PackageSource = {
|
|
11
|
+
kind: "file";
|
|
12
|
+
size: number;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "missing";
|
|
15
|
+
} | {
|
|
16
|
+
kind: "directory";
|
|
17
|
+
} | {
|
|
18
|
+
kind: "other";
|
|
19
|
+
} | {
|
|
20
|
+
kind: "unreadable";
|
|
21
|
+
detail: "permission or I/O error" | "symlink cycle" | "path contains an invalid character";
|
|
22
|
+
};
|
|
23
|
+
/** Why a path under the package could not be inspected: it is gone, a segment is not a folder, or anything else. */
|
|
24
|
+
export type PackageEntryFailure = "missing" | "not-a-directory" | "unreadable";
|
|
25
|
+
/** What a path holds without following a final symlink, or why it could not be inspected. */
|
|
26
|
+
export type PackageEntry = {
|
|
27
|
+
kind: "symlink" | "directory" | "other";
|
|
28
|
+
} | {
|
|
29
|
+
failure: PackageEntryFailure;
|
|
30
|
+
};
|
|
31
|
+
export interface PackageFiles {
|
|
32
|
+
/** The file's UTF-8 text, or `undefined` when nothing exists at `path`. */
|
|
33
|
+
readText(path: string): string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The reserved lifecycle name among the package folder's own entries (REQ-RLN-01,
|
|
36
|
+
* ADR-0028), or `undefined` for a clean package or a folder that does not exist.
|
|
37
|
+
*/
|
|
38
|
+
findReservedSibling(packageDir: string): string | undefined;
|
|
39
|
+
/** `path` relative to the working directory, for messages that must not leak an absolute path. */
|
|
40
|
+
relativeToCwd(path: string): string;
|
|
41
|
+
/** What `relPath` under `packageDir` holds; never throws. */
|
|
42
|
+
statSource(packageDir: string, relPath: string): PackageSource;
|
|
43
|
+
/** The bytes of `relPath` under `packageDir`; any failure throws PackageReadFailure. */
|
|
44
|
+
readBytes(packageDir: string, relPath: string): Uint8Array;
|
|
45
|
+
/** What `path` holds, not following a final symlink; never throws. */
|
|
46
|
+
entryAt(path: string): PackageEntry;
|
|
47
|
+
/** The names in folder `dir`, in no particular order, or why it could not be listed; never throws. */
|
|
48
|
+
namesIn(dir: string): string[] | {
|
|
49
|
+
failure: PackageEntryFailure;
|
|
50
|
+
};
|
|
51
|
+
/** Whether `path` is a folder once symlinks are followed; `false` on any failure. */
|
|
52
|
+
isFolder(path: string): boolean;
|
|
53
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The one filesystem port: reads under a factory package's folder. Absence is a return, never
|
|
2
|
+
// a throw; every other failure throws PackageReadFailure carrying the author-facing problem
|
|
3
|
+
// text, so callers never branch on filesystem error codes.
|
|
4
|
+
export class PackageReadFailure extends Error {
|
|
5
|
+
problem;
|
|
6
|
+
constructor(problem) {
|
|
7
|
+
super(problem);
|
|
8
|
+
this.problem = problem;
|
|
9
|
+
this.name = "PackageReadFailure";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ReadOps } from "
|
|
2
|
-
export { query } from "
|
|
1
|
+
import type { ReadOps } from "../entities/base-handle.ts";
|
|
2
|
+
export { query } from "../entities/dialect-handle.ts";
|
|
3
3
|
export type Op<Ast = any> = (ast: Ast, ...args: never[]) => void;
|
|
4
4
|
declare const QUERY: unique symbol;
|
|
5
5
|
export type Query<Ast = any, A extends unknown[] = any[], R = unknown> = ((ast: Ast, ...args: A) => R) & {
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
// but `any` short-circuits variance checking in both directions, which is exactly the
|
|
13
13
|
// "don't care about the concrete Ast" erasure this bare form needs.
|
|
14
14
|
import { basename } from "node:path";
|
|
15
|
-
import { createDialectHandle } from "
|
|
16
|
-
import { dialectError } from "
|
|
17
|
-
export { query } from "
|
|
15
|
+
import { createDialectHandle } from "../entities/dialect-handle.js";
|
|
16
|
+
import { dialectError } from "../valueobjects/dialect-error.js";
|
|
17
|
+
export { query } from "../entities/dialect-handle.js";
|
|
18
18
|
/**
|
|
19
19
|
* Declares a named collection of ops over one AST type — usable standalone (REQ-DG-02.3),
|
|
20
20
|
* e.g. shareable across two dialects targeting the same AST type, before any `withOps`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Directive, JsonValue } from "
|
|
1
|
+
import type { Directive, JsonValue } from "../valueobjects/wire.ts";
|
|
2
2
|
export interface CreateArgs {
|
|
3
3
|
pathTemplate: string;
|
|
4
4
|
template: string;
|
|
@@ -35,7 +35,7 @@ export interface CopyInArgs {
|
|
|
35
35
|
export declare function forceEntry(force: boolean | undefined): {
|
|
36
36
|
force?: boolean;
|
|
37
37
|
};
|
|
38
|
-
export declare function encodeOptions(options: JsonValue): JsonValue;
|
|
38
|
+
export declare function encodeOptions(options: JsonValue, pathTemplate?: string): JsonValue;
|
|
39
39
|
export declare class DirectiveFactory {
|
|
40
40
|
create(a: CreateArgs): Directive;
|
|
41
41
|
modify(a: ModifyArgs): Directive;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// KIT-03: pure args→Directive; never renders templates, never touches AST.
|
|
2
|
+
import { AuthoringError } from "../valueobjects/authoring-error.js";
|
|
2
3
|
// Key-omission semantics are spec-pinned: `"force" in directive === false` when undefined —
|
|
3
4
|
// never emit `force: undefined`.
|
|
4
5
|
export function forceEntry(force) {
|
|
@@ -26,16 +27,30 @@ function kindOf(value) {
|
|
|
26
27
|
return "Map";
|
|
27
28
|
return "a class instance";
|
|
28
29
|
}
|
|
29
|
-
// REQ-TOE-04
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
|
|
30
|
+
// REQ-TOE-04: an `invalid-input` AuthoringError on the `create` that carries the options.
|
|
31
|
+
// Message template pinned verbatim (slices.md Executor Context, TW-F1): names the top-level
|
|
32
|
+
// offending key, the offending kind + a dotted/indexed location, and echoes docs §8's allowed
|
|
33
|
+
// set for actionability. NEVER raw serializer text (no "Do not know how to serialize a
|
|
34
|
+
// BigInt", no "Converting circular structure to JSON").
|
|
35
|
+
class OptionRejection extends Error {
|
|
36
|
+
}
|
|
35
37
|
function rejectOption(optionKey, detail) {
|
|
36
|
-
throw new
|
|
38
|
+
throw new OptionRejection(`option "${optionKey}" is not a plain-JSON value the engine can render (${detail}). ` +
|
|
37
39
|
"Options must be strings, numbers, booleans, null, arrays, or plain objects.");
|
|
38
40
|
}
|
|
41
|
+
// A getter or proxy trap that throws, or nesting deep enough to overflow the walk, would
|
|
42
|
+
// otherwise surface its own error; it rejects like any other value the engine cannot render,
|
|
43
|
+
// without echoing what it threw.
|
|
44
|
+
function encodeOption(value, optionKey) {
|
|
45
|
+
try {
|
|
46
|
+
return assertEncodable(value, optionKey);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
if (err instanceof OptionRejection)
|
|
50
|
+
throw err;
|
|
51
|
+
return rejectOption(optionKey, err instanceof RangeError ? `a value nested too deeply at ${optionKey}` : `a value that could not be read at ${optionKey}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
39
54
|
// REQ-TOE-04: recursively rejects any value (top-level or nested inside a composite) that
|
|
40
55
|
// is undefined, a function, a symbol, a BigInt, a circular reference, or a non-plain object
|
|
41
56
|
// (Date/Map/class instance) — never a silent drop (JSON.stringify's own undefined/function
|
|
@@ -64,6 +79,9 @@ function assertEncodable(value, optionKey, ancestors = new Set(), path = optionK
|
|
|
64
79
|
if (Array.isArray(value) || isPlainObject(value)) {
|
|
65
80
|
if (ancestors.has(value))
|
|
66
81
|
rejectOption(optionKey, `a circular reference at ${path}`);
|
|
82
|
+
// JSON.stringify would call it, but options are plain data: code that runs to produce them is not.
|
|
83
|
+
if (typeof value.toJSON === "function")
|
|
84
|
+
rejectOption(optionKey, `an object with a toJSON method at ${path}`);
|
|
67
85
|
ancestors.add(value);
|
|
68
86
|
try {
|
|
69
87
|
if (Array.isArray(value)) {
|
|
@@ -87,10 +105,17 @@ function copyEntries(source, copy) {
|
|
|
87
105
|
// ADR-0082: composites reach the wire as native JSON. The copy snapshots the author's value
|
|
88
106
|
// at scheduling time and keeps nested non-finite numbers, so the flush-time round-trip
|
|
89
107
|
// guard sees them (REQ-TOE-03.3).
|
|
90
|
-
export function encodeOptions(options) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
108
|
+
export function encodeOptions(options, pathTemplate) {
|
|
109
|
+
try {
|
|
110
|
+
if (!isPlainObject(options))
|
|
111
|
+
return options;
|
|
112
|
+
return copyEntries(options, ([key, value]) => encodeOption(value, key));
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
if (!(err instanceof OptionRejection))
|
|
116
|
+
throw err;
|
|
117
|
+
throw new AuthoringError({ verb: "create", path: pathTemplate, reason: "invalid-input", appliedCount: 0, message: err.message });
|
|
118
|
+
}
|
|
94
119
|
}
|
|
95
120
|
export class DirectiveFactory {
|
|
96
121
|
create(a) {
|
|
@@ -99,7 +124,7 @@ export class DirectiveFactory {
|
|
|
99
124
|
create: {
|
|
100
125
|
pathTemplate: a.pathTemplate,
|
|
101
126
|
template: a.template,
|
|
102
|
-
options: encodeOptions(a.options),
|
|
127
|
+
options: encodeOptions(a.options, a.pathTemplate),
|
|
103
128
|
...forceEntry(a.force),
|
|
104
129
|
},
|
|
105
130
|
};
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
/** A-17 for a source-relative path as written on disk. */
|
|
2
|
+
export declare function checkSourceName(relPath: string): void;
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
4
|
+
* A-17 for the other text that becomes destination path components (#157): the `to` prefix
|
|
5
|
+
* and every `rename` value, as the author wrote them, before token translation. A non-string
|
|
6
|
+
* rename value is left to the pipeline, which rejects it naming its key.
|
|
5
7
|
*/
|
|
6
|
-
export declare function
|
|
8
|
+
export declare function checkDestinationNames(to: string, rename: Record<string, string> | undefined): void;
|
|
7
9
|
/**
|
|
8
10
|
* Translates on-disk filename tokens to the wire `pathTemplate` syntax the ENGINE
|
|
9
11
|
* substitutes (obs #915 ruling 4) — the SDK never renders these itself, only rewrites the
|
|
10
12
|
* marker syntax. `__name@dasherize__` → `{= .name | dasherize =}`; a bare `__name__`
|
|
11
13
|
* (no `@pipe`) → `{= .name =}`. The dotted field reference is REQUIRED by the engine's
|
|
12
|
-
* templating (bare `{= name =}` was migrated away — docs/templating/migration-note.md in
|
|
14
|
+
* templating (bare `{= name =}` was migrated away — docs/contracts/templating/migration-note.md in
|
|
13
15
|
* the engine repo); emitting the bare form makes every tokenized filename fail
|
|
14
16
|
* path-render at ingest (`path-render-failed`, exit 2).
|
|
15
17
|
*/
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// destination-collision detection (REQ-FSC-08). Zero I/O — pure string transforms over
|
|
7
7
|
// already-enumerated `walk.ts` entries.
|
|
8
8
|
import { posix } from "node:path";
|
|
9
|
-
import { invalidInput } from "../
|
|
9
|
+
import { invalidInput } from "../valueobjects/authoring-error.js";
|
|
10
10
|
const TEMPLATE_SUFFIX = ".template";
|
|
11
11
|
const TOKEN_MARKER = "__";
|
|
12
12
|
// A key starts with a letter, so an opening `__` inside a longer underscore run is its last
|
|
@@ -51,17 +51,37 @@ function portableNameViolation(name) {
|
|
|
51
51
|
return undefined;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
|
-
* Architecture A-17: rejects
|
|
55
|
-
*
|
|
56
|
-
*
|
|
54
|
+
* Architecture A-17: rejects `path` when any of its components holds `{=` or `=}` or is a name
|
|
55
|
+
* Windows refuses — on every OS. A well-formed token holds only letters, digits, `_` and `@`,
|
|
56
|
+
* so it never trips this check. `.` and empty components name no file and are left to the
|
|
57
|
+
* lexical path guards. `subject` opens the message, naming where the path came from.
|
|
57
58
|
*/
|
|
58
|
-
|
|
59
|
-
for (const name of
|
|
59
|
+
function checkPortablePath(path, subject) {
|
|
60
|
+
for (const name of path.split("/")) {
|
|
61
|
+
if (name === "" || name === ".")
|
|
62
|
+
continue;
|
|
60
63
|
const violation = name.includes("{=") || name.includes("=}") ? { rule: "template syntax" } : portableNameViolation(name);
|
|
61
64
|
if (violation === undefined)
|
|
62
65
|
continue;
|
|
63
66
|
const suffix = violation.character === undefined ? "" : ` (${violation.character})`;
|
|
64
|
-
throw invalidInput(`invalid input:
|
|
67
|
+
throw invalidInput(`invalid input: ${subject}: the name "${name}" breaks the rule "${violation.rule}"${suffix}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** A-17 for a source-relative path as written on disk. */
|
|
71
|
+
export function checkSourceName(relPath) {
|
|
72
|
+
checkPortablePath(relPath, `scaffold file name "${relPath}"`);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A-17 for the other text that becomes destination path components (#157): the `to` prefix
|
|
76
|
+
* and every `rename` value, as the author wrote them, before token translation. A non-string
|
|
77
|
+
* rename value is left to the pipeline, which rejects it naming its key.
|
|
78
|
+
*/
|
|
79
|
+
export function checkDestinationNames(to, rename) {
|
|
80
|
+
checkPortablePath(to, `scaffold "to" ${JSON.stringify(to)}`);
|
|
81
|
+
for (const key of Object.keys(rename ?? {}).sort(compareCodePoints)) {
|
|
82
|
+
const value = rename[key];
|
|
83
|
+
if (typeof value === "string")
|
|
84
|
+
checkPortablePath(value, `scaffold rename value ${JSON.stringify(value)}`);
|
|
65
85
|
}
|
|
66
86
|
}
|
|
67
87
|
/**
|
|
@@ -69,7 +89,7 @@ export function checkSourceName(relPath) {
|
|
|
69
89
|
* substitutes (obs #915 ruling 4) — the SDK never renders these itself, only rewrites the
|
|
70
90
|
* marker syntax. `__name@dasherize__` → `{= .name | dasherize =}`; a bare `__name__`
|
|
71
91
|
* (no `@pipe`) → `{= .name =}`. The dotted field reference is REQUIRED by the engine's
|
|
72
|
-
* templating (bare `{= name =}` was migrated away — docs/templating/migration-note.md in
|
|
92
|
+
* templating (bare `{= name =}` was migrated away — docs/contracts/templating/migration-note.md in
|
|
73
93
|
* the engine repo); emitting the bare form makes every tokenized filename fail
|
|
74
94
|
* path-render at ingest (`path-render-failed`, exit 2).
|
|
75
95
|
*/
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/** V4 denylist, checked via `.has()` equality only — NEVER an object literal, never regex-encoded. */
|
|
2
2
|
export declare const JSX_NAME_DENYLIST: ReadonlySet<string>;
|
|
3
3
|
export declare const IMPORT_RESERVED_WORDS: ReadonlySet<string>;
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
|
|
7
|
-
export declare function assertValidElementName(elementName: string, argName?: string): void;
|
|
4
|
+
export declare const IMPORT_BINDING_GRAMMAR: RegExp;
|
|
5
|
+
export declare function assertNotDenylisted(argName: string, value: string): void;
|
|
6
|
+
export declare function assertGrammar(argName: string, value: string, grammar: RegExp, ruleLabel: string): void;
|
|
8
7
|
/**
|
|
9
8
|
* `assertValidImportBinding`'s plain-JS-identifier grammar. The regex alone admits any
|
|
10
9
|
* `IdentifierName` (including reserved words) — `import { name }` requires a `BindingIdentifier`,
|
|
11
10
|
* so a reserved-word check (V5, SEC-1) runs alongside the denylist.
|
|
12
11
|
*/
|
|
13
12
|
export declare function assertValidImportBinding(name: string, argName?: string): void;
|
|
13
|
+
/**
|
|
14
|
+
* A name an op only looks up and never writes. A reserved word can be found (`{ default as x }`),
|
|
15
|
+
* so only the grammar applies.
|
|
16
|
+
*/
|
|
17
|
+
export declare function assertValidLookupName(name: string, argName?: string): void;
|
|
14
18
|
/**
|
|
15
19
|
* A plain-identifier object key. Reserved words are legal keys (`{ default: 1 }`), so only the
|
|
16
20
|
* grammar and the denylist apply: a created `__proto__: [...]` would set the prototype.
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// Name rules several dialects share (ADR-0071: no longer React's alone): the identifier grammar
|
|
2
|
+
// for import bindings and object keys, the reserved-word and denylist checks, and
|
|
3
|
+
// `validatedOp`, the validate-before-mutate wrapper (design §4.4/ADR-02) that makes mutation
|
|
4
|
+
// code (`body`) structurally unreachable before every declared arg validates. The React-only
|
|
5
|
+
// JSX grammars build on these checks in the React adapter (`dialects/react/jsx-names.ts`).
|
|
6
|
+
// Kit-internal: no barrel/subpath export (dialect-error.ts/deep-equal.ts precedent).
|
|
6
7
|
//
|
|
7
8
|
// Set-key-safety clause (ADR-02): `propName`/`elementName` are NEVER used as plain-object
|
|
8
|
-
// keys anywhere in this file or
|
|
9
|
+
// keys anywhere in this file or the React adapter (infrastructure/out/dialects/react/) — no `record[name]`, no `{[name]: …}`,
|
|
9
10
|
// 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 "
|
|
11
|
+
// `__proto__` defence (test/bounded-contexts/authoring/infrastructure/out/dialects/react/name-validation.test.ts pins it via static scan).
|
|
12
|
+
import { dialectError } from "../valueobjects/dialect-error.js";
|
|
12
13
|
import { boundedFragment, nameRuleTail } from "./reject-tail.js";
|
|
13
14
|
// judgment-day (comment-only fix): "Frozen" previously implied a RUNTIME immutability
|
|
14
15
|
// guarantee. `ReadonlySet<string>` is a compile-time-only guard — it does not stop
|
|
@@ -41,17 +42,12 @@ export const IMPORT_RESERVED_WORDS = new Set([
|
|
|
41
42
|
"await",
|
|
42
43
|
"eval", "arguments",
|
|
43
44
|
]);
|
|
44
|
-
// Verbatim from the shared contract (slices.md rev 2, "Name grammars + denylist"):
|
|
45
|
-
//
|
|
46
|
-
|
|
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_$]*$/;
|
|
45
|
+
// Verbatim from the shared contract (slices.md rev 2, "Name grammars + denylist"): an import
|
|
46
|
+
// binding is a plain JS identifier (no alias handling).
|
|
47
|
+
export const IMPORT_BINDING_GRAMMAR = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
52
48
|
// Denylist reject: MAY echo the fixed literal (it's the rule's own vocabulary, not author
|
|
53
49
|
// data, and every denylisted name is well under the 16-char `boundedFragment` ceiling).
|
|
54
|
-
function assertNotDenylisted(argName, value) {
|
|
50
|
+
export function assertNotDenylisted(argName, value) {
|
|
55
51
|
if (!JSX_NAME_DENYLIST.has(value))
|
|
56
52
|
return;
|
|
57
53
|
throw dialectError(`\`${argName}\` "${boundedFragment(value)}" is a reserved name and cannot be used — fix the name, ` +
|
|
@@ -66,21 +62,11 @@ function assertNotReservedWord(argName, value) {
|
|
|
66
62
|
"binding — fix the name, or use `.modify()` to make this edit directly.");
|
|
67
63
|
}
|
|
68
64
|
// Grammar reject: routes through `nameRuleTail` — default ZERO echo of the rejected value.
|
|
69
|
-
function assertGrammar(argName, value, grammar, ruleLabel) {
|
|
65
|
+
export function assertGrammar(argName, value, grammar, ruleLabel) {
|
|
70
66
|
if (grammar.test(value))
|
|
71
67
|
return;
|
|
72
68
|
throw dialectError(nameRuleTail(argName, ruleLabel));
|
|
73
69
|
}
|
|
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, argName = "elementName") {
|
|
81
|
-
assertGrammar(argName, elementName, ELEMENT_NAME_GRAMMAR, "match the JSX element-name grammar (identifier or hyphenated segments, optionally joined by `.`)");
|
|
82
|
-
assertNotDenylisted(argName, elementName);
|
|
83
|
-
}
|
|
84
70
|
/**
|
|
85
71
|
* `assertValidImportBinding`'s plain-JS-identifier grammar. The regex alone admits any
|
|
86
72
|
* `IdentifierName` (including reserved words) — `import { name }` requires a `BindingIdentifier`,
|
|
@@ -91,6 +77,13 @@ export function assertValidImportBinding(name, argName = "name") {
|
|
|
91
77
|
assertNotReservedWord(argName, name);
|
|
92
78
|
assertNotDenylisted(argName, name);
|
|
93
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* A name an op only looks up and never writes. A reserved word can be found (`{ default as x }`),
|
|
82
|
+
* so only the grammar applies.
|
|
83
|
+
*/
|
|
84
|
+
export function assertValidLookupName(name, argName = "name") {
|
|
85
|
+
assertGrammar(argName, name, IMPORT_BINDING_GRAMMAR, "be a valid JavaScript identifier");
|
|
86
|
+
}
|
|
94
87
|
/**
|
|
95
88
|
* A plain-identifier object key. Reserved words are legal keys (`{ default: 1 }`), so only the
|
|
96
89
|
* grammar and the denylist apply: a created `__proto__: [...]` would set the prototype.
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
/** The `elementName` echo bound for match-count rejects — 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;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// The no-echo tail chokepoint (design §4.4, ADR-02), shared by the dialects. Every name or
|
|
2
|
+
// targeting 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
|
+
/** The `elementName` echo bound for match-count rejects — 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
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
export declare const SESSION_ALS_REGISTRY_KEY = "@pbuilder/sdk:core/context#session-als";
|
|
3
|
+
export declare function resolveSessionAls<T>(slotValue: unknown): AsyncLocalStorage<T>;
|
|
4
|
+
export declare function getSessionAls<T>(): AsyncLocalStorage<T>;
|
|
5
|
+
export declare function currentRun<T>(): T;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The run a call belongs to, shared by every copy of the SDK loaded in one process. A Dialect
|
|
2
|
+
// handle looks it up at each step, never when it is made, so `find()` at module top level and a
|
|
3
|
+
// handle reused across runs both keep working. `T` is the store `defineFactory` puts in it.
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
import { AuthoringError } from "../valueobjects/authoring-error.js";
|
|
6
|
+
// context-singleton-fix (REQ-MIS-01/02, design §4.3): a module-scope `als` is realm-local —
|
|
7
|
+
// when `dist/bin/pbuilder-runner.js` and a src-relative `.ts` factory co-execute in one Bun
|
|
8
|
+
// process, each resolves its OWN copy of this module and its OWN `als`, so a Session entered in
|
|
9
|
+
// one realm is invisible to `currentContext()` in the other. The store is therefore parked at
|
|
10
|
+
// `globalThis[Symbol.for(SESSION_ALS_REGISTRY_KEY)]` — a process-singleton every realm resolving
|
|
11
|
+
// this file reaches via the SAME well-known key — lazily installed on first access.
|
|
12
|
+
export const SESSION_ALS_REGISTRY_KEY = "@pbuilder/sdk:core/context#session-als";
|
|
13
|
+
function isAsyncLocalStorageLike(value) {
|
|
14
|
+
return (typeof value === "object" &&
|
|
15
|
+
value !== null &&
|
|
16
|
+
typeof value.run === "function" &&
|
|
17
|
+
typeof value.getStore === "function");
|
|
18
|
+
}
|
|
19
|
+
// PURE 3-state decision (design §4.3, rev 3 purity split) — no globalThis, no side effects.
|
|
20
|
+
// `undefined` (slot absent) -> fresh ALS; a duck-valid ALS-shaped value (cross-realm reuse)
|
|
21
|
+
// -> returned verbatim, SAME instance; anything else -> fail LOUD (occupied-slot contract,
|
|
22
|
+
// ADR-01 addendum): a foreign/corrupted occupant under this well-known key must never be
|
|
23
|
+
// trusted or silently clobbered. Plain `Error` (NOT AuthoringError) — this is
|
|
24
|
+
// environment/integration corruption, not author-input misuse; the closed reason enum has no
|
|
25
|
+
// member for it (mirrors `validateAtRunBoundary`'s read-path posture).
|
|
26
|
+
export function resolveSessionAls(slotValue) {
|
|
27
|
+
if (slotValue === undefined) {
|
|
28
|
+
return new AsyncLocalStorage();
|
|
29
|
+
}
|
|
30
|
+
if (isAsyncLocalStorageLike(slotValue)) {
|
|
31
|
+
return slotValue;
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`[pbuilder] run-context registry slot Symbol.for("${SESSION_ALS_REGISTRY_KEY}") is occupied by an ` +
|
|
34
|
+
`incompatible value (expected an AsyncLocalStorage, got ${typeof slotValue}) — another module ` +
|
|
35
|
+
"may have polluted globalThis");
|
|
36
|
+
}
|
|
37
|
+
// IMPURE thin shell: reads the shared slot, delegates the 3-state decision to the pure
|
|
38
|
+
// `resolveSessionAls`, and installs the resolved ALS ONLY when the slot was absent — a frozen
|
|
39
|
+
// descriptor (non-enumerable, non-configurable, non-writable) so REQ-MIS-01.2's no-pollution
|
|
40
|
+
// guarantee holds and the slot can never be silently reassigned after first install.
|
|
41
|
+
export function getSessionAls() {
|
|
42
|
+
const registryKey = Symbol.for(SESSION_ALS_REGISTRY_KEY);
|
|
43
|
+
const slot = globalThis[registryKey];
|
|
44
|
+
const resolved = resolveSessionAls(slot);
|
|
45
|
+
if (slot === undefined) {
|
|
46
|
+
Object.defineProperty(globalThis, registryKey, {
|
|
47
|
+
value: resolved,
|
|
48
|
+
writable: false,
|
|
49
|
+
enumerable: false,
|
|
50
|
+
configurable: false,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return resolved;
|
|
54
|
+
}
|
|
55
|
+
// REQ-AEC-02.1 (2.4): a verb called outside any defineFactory Session is SDK-side misuse,
|
|
56
|
+
// independent of any engine round-trip — an AuthoringError{authoring-rejected,outside-session},
|
|
57
|
+
// not a plain Error. The prose lives in authoring-error.ts's outside-session message template
|
|
58
|
+
// (the third template, REQ-AEC-06); this is the one call site that reaches it.
|
|
59
|
+
export function currentRun() {
|
|
60
|
+
const ctx = getSessionAls().getStore();
|
|
61
|
+
if (ctx === undefined) {
|
|
62
|
+
throw new AuthoringError({
|
|
63
|
+
verb: undefined,
|
|
64
|
+
path: undefined,
|
|
65
|
+
reason: "outside-session",
|
|
66
|
+
appliedCount: 0,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return ctx;
|
|
70
|
+
}
|
package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.d.ts
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthoringError } from "
|
|
1
|
+
import { AuthoringError } from "../../valueobjects/authoring-error.ts";
|
|
2
2
|
import type { ValidationFinding } from "./schema-validate.ts";
|
|
3
3
|
export declare function rejectionFor(finding: ValidationFinding): AuthoringError;
|
|
4
4
|
export declare function rejectionForReservedName(name: string): AuthoringError;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// proto-key — branch→template mapping, all three collapse to one template);
|
|
15
15
|
// `reserved lifecycle name: {name} is reserved and cannot be declared by a factory module`
|
|
16
16
|
// (RLN-02.1, distinguishable-in-kind from the two templates above by literal text alone).
|
|
17
|
-
import { AuthoringError } from "
|
|
17
|
+
import { AuthoringError } from "../../valueobjects/authoring-error.js";
|
|
18
18
|
function rejection(reason, message) {
|
|
19
19
|
return new AuthoringError({ verb: undefined, path: undefined, appliedCount: 0, reason, message });
|
|
20
20
|
}
|