@pbuilder/sdk 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -42
- package/dist/{transport → acl/irwire}/frame-reader.d.ts +2 -0
- package/dist/{transport → acl/irwire}/frame-reader.js +57 -5
- package/dist/{transport → acl/irwire}/stdio-engine-client.d.ts +2 -2
- package/dist/{transport → acl/irwire}/stdio-engine-client.js +4 -4
- package/dist/bin/pbuilder-codegen.js +30 -35
- package/dist/bin/pbuilder-runner.js +6 -6
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +106 -0
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +202 -0
- package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.d.ts +12 -9
- package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.js +59 -120
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.d.ts +5 -0
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.js +15 -0
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.d.ts +51 -0
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.js +105 -0
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.d.ts +2 -1
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.js +16 -7
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.d.ts +1 -1
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.js +7 -6
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.d.ts +11 -10
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.js +21 -48
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.d.ts +2 -3
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.js +37 -56
- package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.js +10 -10
- package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.d.ts +1 -1
- package/dist/bounded-contexts/authoring/domain/ports/package-files.d.ts +53 -0
- package/dist/bounded-contexts/authoring/domain/ports/package-files.js +11 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.js +3 -3
- package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.js +37 -12
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.d.ts +11 -1
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.js +94 -3
- package/dist/{core/jsx-name-validator.d.ts → bounded-contexts/authoring/domain/services/identifier-names.d.ts} +8 -4
- package/dist/{core/jsx-name-validator.js → bounded-contexts/authoring/domain/services/identifier-names.js} +21 -28
- package/dist/bounded-contexts/authoring/domain/services/reject-tail.d.ts +9 -0
- package/dist/bounded-contexts/authoring/domain/services/reject-tail.js +30 -0
- package/dist/bounded-contexts/authoring/domain/services/run-context.d.ts +5 -0
- package/dist/bounded-contexts/authoring/domain/services/run-context.js +70 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.js +1 -1
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.d.ts +2 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.js +6 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.d.ts +2 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.js +13 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.js +2 -14
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.d.ts +4 -3
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.js +8 -4
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/wire.d.ts +0 -3
- package/dist/bounded-contexts/authoring/domain/valueobjects/wire.js +28 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +27 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +306 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +7 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +68 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +19 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +131 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +182 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +94 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +63 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +68 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.js +9 -9
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +40 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +38 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +55 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +54 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.d.ts +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.js +35 -8
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +43 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +46 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.js +7 -7
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +52 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +73 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.d.ts +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.js +18 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.d.ts +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.js +25 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.js +5 -3
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.d.ts +7 -2
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.js +29 -15
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.d.ts +5 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.js +22 -4
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.js +14 -19
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +53 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +37 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.d.ts +6 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.js +90 -54
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +69 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +70 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.d.ts +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.js +2 -2
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.js +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.d.ts +8 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.js +133 -0
- package/dist/bounded-contexts/authoring/testing/conformance/index.d.ts +157 -0
- package/dist/bounded-contexts/authoring/testing/conformance/index.js +261 -0
- package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.d.ts +2 -2
- package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.js +4 -3
- package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +89 -0
- package/dist/bounded-contexts/authoring/testing/harness/index.js +85 -0
- package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.d.ts +1 -1
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.js +2 -2
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.js +5 -4
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.js +1 -1
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.d.ts +4 -0
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.js +49 -23
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.js +1 -1
- package/dist/commons/index.d.ts +1 -278
- package/dist/commons/index.js +1 -286
- package/dist/conformance/index.d.ts +1 -157
- package/dist/conformance/index.js +1 -261
- package/dist/dialects/angular/index.d.ts +1 -63
- package/dist/dialects/angular/index.js +1 -68
- package/dist/dialects/css/index.d.ts +1 -40
- package/dist/dialects/css/index.js +1 -38
- package/dist/dialects/json/index.d.ts +1 -55
- package/dist/dialects/json/index.js +1 -54
- package/dist/dialects/nestjs/index.d.ts +1 -43
- package/dist/dialects/nestjs/index.js +1 -46
- package/dist/dialects/react/index.d.ts +1 -52
- package/dist/dialects/react/index.js +1 -73
- package/dist/dialects/typescript/index.d.ts +1 -53
- package/dist/dialects/typescript/index.js +1 -37
- package/dist/dialects/yaml/index.d.ts +1 -69
- package/dist/dialects/yaml/index.js +1 -70
- package/dist/{core → platform}/deep-equal.js +2 -2
- package/dist/{transport → platform}/error-text.js +2 -2
- package/dist/runner-manifest.json +66 -46
- package/dist/shared-kernel/batch-cap.d.ts +4 -0
- package/dist/{core/wire.js → shared-kernel/batch-cap.js} +9 -26
- package/dist/{transport → shared-kernel}/framing.js +2 -2
- package/dist/{transport → shared-kernel}/wire-protocol.js +1 -1
- package/dist/testing/index.d.ts +1 -84
- package/dist/testing/index.js +1 -82
- package/package.json +9 -3
- package/dist/core/index.d.ts +0 -10
- package/dist/core/index.js +0 -6
- package/dist/core/reject-tail.d.ts +0 -13
- package/dist/core/reject-tail.js +0 -52
- package/dist/core/schema/schema-discovery.d.ts +0 -13
- package/dist/core/schema/schema-discovery.js +0 -51
- package/dist/scaffold/classify-transport.d.ts +0 -54
- package/dist/scaffold/classify-transport.js +0 -119
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.d.ts +0 -0
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.js +0 -0
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.js +0 -0
- /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.d.ts +0 -0
- /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.js +0 -0
- /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.d.ts +0 -0
- /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.d.ts +0 -0
- /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.d.ts +0 -0
- /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.js +0 -0
- /package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.js +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.d.ts +0 -0
- /package/dist/{core → platform}/deep-equal.d.ts +0 -0
- /package/dist/{transport → platform}/error-text.d.ts +0 -0
- /package/dist/{core → platform}/fs-errors.d.ts +0 -0
- /package/dist/{core → platform}/fs-errors.js +0 -0
- /package/dist/{transport → shared-kernel}/framing.d.ts +0 -0
- /package/dist/{transport → shared-kernel}/wire-protocol.d.ts +0 -0
package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.js
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// S-002: the `addImport` named op (REQ-TSD-01, frozen call signature
|
|
2
2
|
// `addImport(name: string, from: string)`, design §4.4).
|
|
3
3
|
//
|
|
4
|
-
// S-001: `addFunction` (REQ-TSD-09) + the shared `
|
|
4
|
+
// S-001: `addFunction` (REQ-TSD-09) + the shared `addDeclaration` predicate it (and
|
|
5
5
|
// S-003's addVariable/addClass) reuse (design §4.5 ADR-0039).
|
|
6
6
|
//
|
|
7
7
|
// S-003: `addVariable` (REQ-TSD-10) + `addClass` (REQ-TSD-11) — same insert-mechanism and
|
|
@@ -14,26 +14,28 @@
|
|
|
14
14
|
//
|
|
15
15
|
// ts-addimport-collision/S-001: Step 2 (file-wide collision reject) lands here, strictly
|
|
16
16
|
// AFTER Step 1 (REQ-TSD-01.24, mutant-kill ordering invariant) and before Step 3/4.
|
|
17
|
-
// `isValueNamespaceClaimed` is EXTRACTED from `
|
|
18
|
-
// and consumed by BOTH `
|
|
17
|
+
// `isValueNamespaceClaimed` is EXTRACTED from `addDeclaration` below (design §4.5 ADR-01)
|
|
18
|
+
// and consumed by BOTH `addDeclaration` (behaviour-preserving, siblings' own import-scan
|
|
19
19
|
// posture UNCHANGED) and `addImport`'s new Step 2 (design §4.4 — TS house-style tail, built
|
|
20
|
-
// inline, NOT reusing `
|
|
20
|
+
// inline, NOT reusing `addDeclaration`'s own message: "two bindings sharing a name" here,
|
|
21
21
|
// vs "two value declarations sharing a name" there — `addImport`'s collision surface also
|
|
22
22
|
// fires on import-vs-import and type-only claims, which are not value declarations, F10).
|
|
23
23
|
//
|
|
24
24
|
// ts-addimport-collision/S-002: REQ-TSD-13's injection-safety validation gate lands here —
|
|
25
|
-
// `assertValidImportBinding` (reused verbatim from `
|
|
25
|
+
// `assertValidImportBinding` (reused verbatim from `domain/services/identifier-names.ts`, ADR-02)
|
|
26
26
|
// runs INLINE as `addImport`'s first statement, strictly BEFORE Step 1/2/3/4 ever evaluate
|
|
27
27
|
// `name` (REQ-TSD-13.6 precedence pin). Its PATH-LESS reject shape is deliberately distinct
|
|
28
28
|
// from Step 2's path-ful `dialectError` tail below — see `addImport`'s own JSDoc.
|
|
29
|
-
import {
|
|
30
|
-
import { dialectError } from "
|
|
31
|
-
import { handlePathFor } from "
|
|
32
|
-
import { elementNameEcho } from "
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
import { assertValidImportBinding } from "
|
|
29
|
+
import { SyntaxKind, } from "ts-morph";
|
|
30
|
+
import { dialectError } from "../../../../domain/valueobjects/dialect-error.js";
|
|
31
|
+
import { handlePathFor } from "../../../../domain/entities/dialect-handle.js";
|
|
32
|
+
import { elementNameEcho, nameRuleTail } from "../../../../domain/services/reject-tail.js";
|
|
33
|
+
// The identifier rules every dialect shares; the JSX-only grammars live in the React adapter
|
|
34
|
+
// (ARCH-2, ADR-0071).
|
|
35
|
+
import { assertValidImportBinding, assertValidLookupName } from "../../../../domain/services/identifier-names.js";
|
|
36
36
|
import { closeGapAfter, sortedPlacement, sortedSpecifierIndex } from "./import-order.js";
|
|
37
|
+
import { omitsSemicolons, parse } from "./ast.js";
|
|
38
|
+
import { declarationTokens, sameTokens } from "./array-element.js";
|
|
37
39
|
// Collects every local name a single declaration binds, across all three clause shapes at
|
|
38
40
|
// once (a declaration can carry a default AND a named clause simultaneously, e.g.
|
|
39
41
|
// `import Def, { B } from "m"`). Set-key-safety clause: names are compared via
|
|
@@ -101,7 +103,7 @@ function isNonTypeOnlyNamedImportClause(decl) {
|
|
|
101
103
|
return namedBindings !== undefined && namedBindings.getKind() === SyntaxKind.NamedImports;
|
|
102
104
|
}
|
|
103
105
|
// ADR-0039 collision-namespace pin (owner ruling #4), EXTRACTED (S-001, design §4.5 ADR-01)
|
|
104
|
-
// from `
|
|
106
|
+
// from `addDeclaration` below so both it and `addImport`'s Step 2 share ONE predicate: a
|
|
105
107
|
// top-level VALUE-NAMESPACE declaration (function/const/let/var/class/enum/namespace) under
|
|
106
108
|
// `name` collides; `type`/`interface` are exempt (legal TS coexistence). Syntactic search
|
|
107
109
|
// only (no language service, REQ-TSD-02.3) — SourceFile-wide, not scope-aware.
|
|
@@ -116,9 +118,7 @@ function isValueNamespaceClaimed(ast, name) {
|
|
|
116
118
|
// `ExpressionStatement`s starting at statement 0, stopping at the first non-directive
|
|
117
119
|
// statement (a directive is only live when first-in-scope; a string literal appearing
|
|
118
120
|
// later in the file is an ordinary expression statement, not a directive). A shebang is
|
|
119
|
-
// SourceFile leading trivia, never a statement, so it never contributes here
|
|
120
|
-
// branch below falls through to its pre-existing `addImportDeclaration` path for a shebang
|
|
121
|
-
// file, leaving REQ-TSD-01.33's fail-closed containment untouched (ADR-03).
|
|
121
|
+
// SourceFile leading trivia, never a statement, so it never contributes here.
|
|
122
122
|
function leadingDirectiveCount(ast) {
|
|
123
123
|
let count = 0;
|
|
124
124
|
for (const statement of ast.getStatements()) {
|
|
@@ -155,7 +155,7 @@ function directiveInsertIndex(ast, directiveCount) {
|
|
|
155
155
|
* 0. Validation (REQ-TSD-13, runs FIRST, strictly before Step 1): `name` MUST be a valid
|
|
156
156
|
* plain-JS identifier, MUST NOT be a reserved or strict-mode-restricted word, and MUST
|
|
157
157
|
* NOT be a denylisted name (`assertValidImportBinding`, reused verbatim from
|
|
158
|
-
* `
|
|
158
|
+
* `domain/services/identifier-names.ts`) — REJECTS via a PATH-LESS `dialectError` before Step
|
|
159
159
|
* 1/2/3/4 ever evaluate `name`, even when `name` would ALSO collide under Step 2
|
|
160
160
|
* (REQ-TSD-13.6, precedence pinned: validation wins, never the collision message).
|
|
161
161
|
* 1. Already-bound (idempotency, SAME module only): if an EXISTING declaration for `from`
|
|
@@ -224,6 +224,13 @@ export function addImport(ast, name, from, options) {
|
|
|
224
224
|
throw dialectError(`addImport("${name}") on "${handlePathFor(ast)}" — \`position\` must be "sorted" or omitted. ` +
|
|
225
225
|
"Fix the option, or edit the file with .modify().");
|
|
226
226
|
}
|
|
227
|
+
importBinding(ast, "addImport", name, from, sorted);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* `addImport`'s steps 1-4 for a `name` already validated, rejecting a taken name under `opName`:
|
|
231
|
+
* the op the author called, which may add the import on the author's behalf.
|
|
232
|
+
*/
|
|
233
|
+
export function importBinding(ast, opName, name, from, sorted = false) {
|
|
227
234
|
// Single pass: one `getImportDeclarations()` call, one `boundNamesIn` per declaration —
|
|
228
235
|
// Step 1 and Step 2 below both read from `declarationBoundNames` instead of each re-walking
|
|
229
236
|
// the AST. Step 1 still fully evaluates (and early-returns) before Step 2 ever runs
|
|
@@ -241,7 +248,7 @@ export function addImport(ast, name, from, options) {
|
|
|
241
248
|
const claimed = declarationBoundNames.some(([, bound]) => bound.some((b) => b.localName === name)) ||
|
|
242
249
|
isValueNamespaceClaimed(ast, name);
|
|
243
250
|
if (claimed)
|
|
244
|
-
throw claimedBindingError(ast,
|
|
251
|
+
throw claimedBindingError(ast, opName, name);
|
|
245
252
|
const mergeTarget = declarationsForModule.find(isNonTypeOnlyNamedImportClause);
|
|
246
253
|
if (mergeTarget !== undefined) {
|
|
247
254
|
if (sorted)
|
|
@@ -279,24 +286,24 @@ function insertImport(ast, structure, index) {
|
|
|
279
286
|
const inserted = index !== undefined
|
|
280
287
|
? ast.insertImportDeclaration(index, structure)
|
|
281
288
|
: directiveCount === 0
|
|
282
|
-
? ast
|
|
289
|
+
? addFirstImport(ast, structure)
|
|
283
290
|
: ast.insertImportDeclaration(directiveInsertIndex(ast, directiveCount), structure);
|
|
284
|
-
return dropSemicolon ?
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
return
|
|
291
|
+
return dropSemicolon ? withoutSemicolon(inserted) : inserted;
|
|
292
|
+
}
|
|
293
|
+
function withoutSemicolon(statement) {
|
|
294
|
+
return statement.replaceWithText(statement.getText().slice(0, -1));
|
|
295
|
+
}
|
|
296
|
+
// ts-morph cannot put the first import of a file below a shebang: it throws when code follows the
|
|
297
|
+
// shebang and drops the shebang when nothing does. The shebang is lifted out, the import added to
|
|
298
|
+
// the rest, and the shebang put back above it.
|
|
299
|
+
function addFirstImport(ast, structure) {
|
|
300
|
+
const shebang = /^#![^\n]*\n?/.exec(ast.getFullText())?.[0];
|
|
301
|
+
if (shebang === undefined || ast.getImportDeclarations().length > 0)
|
|
302
|
+
return ast.addImportDeclaration(structure);
|
|
303
|
+
ast.removeText(0, shebang.length);
|
|
304
|
+
ast.addImportDeclaration(structure);
|
|
305
|
+
ast.insertText(0, shebang.endsWith("\n") ? shebang : `${shebang}\n`);
|
|
306
|
+
return ast.getImportDeclarations()[0];
|
|
300
307
|
}
|
|
301
308
|
// The value-bound (not whole-declaration type-only) declarations importing `from`.
|
|
302
309
|
function valueImportsOf(ast, from) {
|
|
@@ -406,9 +413,28 @@ function exportPrefixFor(options) {
|
|
|
406
413
|
// message (design §4.4's pinned "on {path}" clause) — position-independent (keyed by the
|
|
407
414
|
// live AST instance, not a runtime argument position), so it can never collide with `name`/
|
|
408
415
|
// `options` regardless of which trailing args the author omitted.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
416
|
+
// Appends the declaration `text` of `name`. When `name` is taken, a top-level statement that is
|
|
417
|
+
// `text` token for token (trivia and a trailing `;` aside) leaves the file as it is, so running
|
|
418
|
+
// the op again is a no-op; any other binding of `name` rejects.
|
|
419
|
+
function addDeclaration(ast, name, opName, text) {
|
|
420
|
+
if (isBindingClaimed(ast, name)) {
|
|
421
|
+
if (declaresIdentically(ast, text))
|
|
422
|
+
return;
|
|
423
|
+
throwCollision(ast, name, opName);
|
|
424
|
+
}
|
|
425
|
+
ast.addStatements(text);
|
|
426
|
+
}
|
|
427
|
+
function declaresIdentically(ast, text) {
|
|
428
|
+
let written;
|
|
429
|
+
try {
|
|
430
|
+
written = declarationTokens(parse(text).getStatements()[0]);
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
return ast.getStatements().some((statement) => sameTokens(declarationTokens(statement), written));
|
|
436
|
+
}
|
|
437
|
+
function throwCollision(ast, name, opName) {
|
|
412
438
|
throw dialectError(`${opName}("${name}") on "${handlePathFor(ast)}" — a value or import binding named "${name}" already exists; ` +
|
|
413
439
|
`TypeScript forbids two value declarations sharing a name. Rename or remove the existing one, or edit it with .modify().`);
|
|
414
440
|
}
|
|
@@ -428,8 +454,7 @@ function assertNoCollision(ast, name, opName) {
|
|
|
428
454
|
*/
|
|
429
455
|
export function addFunction(ast, name, source, options) {
|
|
430
456
|
assertValidImportBinding(name);
|
|
431
|
-
|
|
432
|
-
ast.addStatements(`${exportPrefixFor(options)}function ${name}${source}`);
|
|
457
|
+
addDeclaration(ast, name, "addFunction", `${exportPrefixFor(options)}function ${name}${source}`);
|
|
433
458
|
}
|
|
434
459
|
/**
|
|
435
460
|
* Inserts a new top-level variable declaration `{export }{kind} {name} = {initializer};` at
|
|
@@ -450,8 +475,7 @@ export function addVariable(ast, name, initializer, options) {
|
|
|
450
475
|
throw dialectError(`addVariable("${name}") on "${handlePathFor(ast)}" — \`kind\` must be "const", "let", or "var". ` +
|
|
451
476
|
"Fix the option, or edit the file with .modify().");
|
|
452
477
|
}
|
|
453
|
-
|
|
454
|
-
ast.addStatements(`${exportPrefixFor(options)}${kind} ${name} = ${initializer};`);
|
|
478
|
+
addDeclaration(ast, name, "addVariable", `${exportPrefixFor(options)}${kind} ${name} = ${initializer}${omitsSemicolons(ast) ? "" : ";"}`);
|
|
455
479
|
}
|
|
456
480
|
/**
|
|
457
481
|
* Inserts a new top-level class declaration `{export }class {name} {\n{source}\n}` at the
|
|
@@ -469,8 +493,7 @@ export function addVariable(ast, name, initializer, options) {
|
|
|
469
493
|
*/
|
|
470
494
|
export function addClass(ast, name, source, options) {
|
|
471
495
|
assertValidImportBinding(name);
|
|
472
|
-
|
|
473
|
-
ast.addStatements(`${exportPrefixFor(options)}class ${name} {\n${source}\n}`);
|
|
496
|
+
addDeclaration(ast, name, "addClass", `${exportPrefixFor(options)}class ${name} {\n${source}\n}`);
|
|
474
497
|
}
|
|
475
498
|
/**
|
|
476
499
|
* Removes the named binding from `from`'s import clause (REQ-TSD-08). Idempotent: an
|
|
@@ -492,7 +515,7 @@ export function addClass(ast, name, source, options) {
|
|
|
492
515
|
* is first-match-only. Sibling declarations from the same module are never touched.
|
|
493
516
|
*/
|
|
494
517
|
export function removeImport(ast, name, from) {
|
|
495
|
-
|
|
518
|
+
assertValidLookupName(name);
|
|
496
519
|
const decls = ast.getImportDeclarations().filter((d) => d.getModuleSpecifierValue() === from);
|
|
497
520
|
for (const decl of decls) {
|
|
498
521
|
const namedImports = decl.getNamedImports();
|
|
@@ -561,10 +584,27 @@ function assertNotExported(ast, name, opName) {
|
|
|
561
584
|
throw dialectError(`${opName}("${echoedName}") on "${handlePathFor(ast)}" — the file already exports a binding named "${echoedName}"; ` +
|
|
562
585
|
"TypeScript forbids two exports sharing a name. Rename or remove the existing one, or edit it with .modify().");
|
|
563
586
|
}
|
|
587
|
+
function addExport(ast, structure) {
|
|
588
|
+
const dropSemicolon = omitsSemicolons(ast);
|
|
589
|
+
const added = ast.addExportDeclaration(structure);
|
|
590
|
+
if (dropSemicolon)
|
|
591
|
+
withoutSemicolon(added);
|
|
592
|
+
}
|
|
564
593
|
function exportsOf(ast, from) {
|
|
565
594
|
return ast.getExportDeclarations().filter((decl) => decl.getModuleSpecifierValue() === from);
|
|
566
595
|
}
|
|
567
596
|
// `export * from "m"` when `as` is undefined, `export * as ns from "m"` when it is "ns".
|
|
597
|
+
// An `as` that is present is a name like any other: `null` or another non-string rejects instead of
|
|
598
|
+
// reading as the bare `export *` form.
|
|
599
|
+
function namespaceExportName(options, assertName) {
|
|
600
|
+
const as = options?.as;
|
|
601
|
+
if (as === undefined)
|
|
602
|
+
return undefined;
|
|
603
|
+
if (typeof as !== "string")
|
|
604
|
+
throw dialectError(nameRuleTail("as", "be a valid JavaScript identifier"));
|
|
605
|
+
assertName(as, "as");
|
|
606
|
+
return as;
|
|
607
|
+
}
|
|
568
608
|
function isExportAll(decl, as) {
|
|
569
609
|
if (decl.isTypeOnly())
|
|
570
610
|
return false;
|
|
@@ -591,7 +631,7 @@ export function addReExport(ast, name, from) {
|
|
|
591
631
|
mergeTarget.addNamedExport(name);
|
|
592
632
|
return;
|
|
593
633
|
}
|
|
594
|
-
ast
|
|
634
|
+
addExport(ast, { moduleSpecifier: from, namedExports: [name] });
|
|
595
635
|
}
|
|
596
636
|
/**
|
|
597
637
|
* Adds `export * from "from";`, or `export * as ns from "from";` with `{ as: "ns" }` (V2
|
|
@@ -600,14 +640,12 @@ export function addReExport(ast, name, from) {
|
|
|
600
640
|
* exports it.
|
|
601
641
|
*/
|
|
602
642
|
export function addExportAll(ast, from, options) {
|
|
603
|
-
const as = options
|
|
604
|
-
if (as !== undefined)
|
|
605
|
-
assertValidImportBinding(as);
|
|
643
|
+
const as = namespaceExportName(options, assertValidImportBinding);
|
|
606
644
|
if (exportsOf(ast, from).some((decl) => isExportAll(decl, as)))
|
|
607
645
|
return;
|
|
608
646
|
if (as !== undefined)
|
|
609
647
|
assertNotExported(ast, as, "addExportAll");
|
|
610
|
-
ast
|
|
648
|
+
addExport(ast, as === undefined ? { moduleSpecifier: from } : { moduleSpecifier: from, namespaceExport: as });
|
|
611
649
|
}
|
|
612
650
|
/**
|
|
613
651
|
* Removes the re-export of `name` from `export { … } from "from"` (V2 REQ-TSD-19), deleting
|
|
@@ -616,7 +654,7 @@ export function addExportAll(ast, from, options) {
|
|
|
616
654
|
* `export *` statements are never touched — see `removeExportAll`.
|
|
617
655
|
*/
|
|
618
656
|
export function removeExport(ast, name, from) {
|
|
619
|
-
|
|
657
|
+
assertValidLookupName(name);
|
|
620
658
|
for (const decl of exportsOf(ast, from)) {
|
|
621
659
|
const namedExports = decl.getNamedExports();
|
|
622
660
|
const specifier = namedExports.find((named) => named.getName() === name);
|
|
@@ -636,9 +674,7 @@ export function removeExport(ast, name, from) {
|
|
|
636
674
|
* form only removes itself; an absent statement is a no-op.
|
|
637
675
|
*/
|
|
638
676
|
export function removeExportAll(ast, from, options) {
|
|
639
|
-
const as = options
|
|
640
|
-
if (as !== undefined)
|
|
641
|
-
assertValidImportBinding(as);
|
|
677
|
+
const as = namespaceExportName(options, assertValidLookupName);
|
|
642
678
|
exportsOf(ast, from)
|
|
643
679
|
.find((decl) => isExportAll(decl, as))
|
|
644
680
|
?.remove();
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type Handle } from "../../../../domain/services/define-dialect.ts";
|
|
2
|
+
import { type YamlStream } from "./ast.ts";
|
|
3
|
+
import type { DocumentOption, YamlPath, YamlValue } from "./paths.ts";
|
|
4
|
+
import { type CollectionStyle, type CommentOptions, type ScalarStyle } from "./presentation.ts";
|
|
5
|
+
import { type KeyOptions } from "./structural.ts";
|
|
6
|
+
export * as astLibrary from "yaml";
|
|
7
|
+
export type { YamlStream, YamlPath, YamlValue };
|
|
8
|
+
type YamlOps = {
|
|
9
|
+
setValue: (ast: YamlStream, path: YamlPath, value: YamlValue, options?: KeyOptions) => void;
|
|
10
|
+
addKey: (ast: YamlStream, path: YamlPath, value: YamlValue, options?: KeyOptions) => void;
|
|
11
|
+
removeKey: (ast: YamlStream, path: YamlPath, options?: DocumentOption) => void;
|
|
12
|
+
renameKey: (ast: YamlStream, path: YamlPath, newKey: string, options?: DocumentOption) => void;
|
|
13
|
+
insertItem: (ast: YamlStream, path: YamlPath, index: number, value: YamlValue, options?: DocumentOption) => void;
|
|
14
|
+
appendItem: (ast: YamlStream, path: YamlPath, value: YamlValue, options?: DocumentOption & {
|
|
15
|
+
unique?: boolean;
|
|
16
|
+
}) => void;
|
|
17
|
+
removeItem: (ast: YamlStream, path: YamlPath, index: number, options?: DocumentOption) => void;
|
|
18
|
+
removeValue: (ast: YamlStream, path: YamlPath, value: YamlValue, options?: DocumentOption) => void;
|
|
19
|
+
replaceItem: (ast: YamlStream, path: YamlPath, index: number, value: YamlValue, options?: DocumentOption) => void;
|
|
20
|
+
moveItem: (ast: YamlStream, path: YamlPath, from: number, to: number, options?: DocumentOption) => void;
|
|
21
|
+
merge: (ast: YamlStream, path: YamlPath, value: {
|
|
22
|
+
[key: string]: YamlValue;
|
|
23
|
+
}, options?: DocumentOption) => void;
|
|
24
|
+
updateValue: (ast: YamlStream, path: YamlPath, fn: (current: YamlValue | undefined) => YamlValue, options?: DocumentOption) => void;
|
|
25
|
+
setComment: (ast: YamlStream, path: YamlPath, comment: string, options?: CommentOptions) => void;
|
|
26
|
+
removeComment: (ast: YamlStream, path: YamlPath, options?: CommentOptions) => void;
|
|
27
|
+
setAnchor: (ast: YamlStream, path: YamlPath, name: string, options?: DocumentOption) => void;
|
|
28
|
+
removeAnchor: (ast: YamlStream, path: YamlPath, options?: DocumentOption) => void;
|
|
29
|
+
setAlias: (ast: YamlStream, path: YamlPath, anchor: string, options?: DocumentOption) => void;
|
|
30
|
+
addMergeKey: (ast: YamlStream, path: YamlPath, anchor: string, options?: DocumentOption) => void;
|
|
31
|
+
setStyle: (ast: YamlStream, path: YamlPath, style: CollectionStyle | ScalarStyle, options?: DocumentOption) => void;
|
|
32
|
+
addDocument: (ast: YamlStream, value: YamlValue, options?: {
|
|
33
|
+
index?: number;
|
|
34
|
+
}) => void;
|
|
35
|
+
removeDocument: (ast: YamlStream, index: number) => void;
|
|
36
|
+
moveValue: (ast: YamlStream, from: YamlPath, to: YamlPath, options?: DocumentOption) => void;
|
|
37
|
+
copyValue: (ast: YamlStream, from: YamlPath, to: YamlPath, options?: DocumentOption) => void;
|
|
38
|
+
sortKeys: (ast: YamlStream, path: YamlPath, options?: DocumentOption & {
|
|
39
|
+
recursive?: boolean;
|
|
40
|
+
}) => void;
|
|
41
|
+
setTag: (ast: YamlStream, path: YamlPath, tag: string | null, options?: DocumentOption) => void;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Opens a `.yaml` or `.yml` file for YAML-dialect editing. The basename must end in one of those
|
|
45
|
+
* extensions after a non-empty stem; every other path throws synchronously, before any op runs,
|
|
46
|
+
* with the `dialect operation failed: ` prefix.
|
|
47
|
+
*
|
|
48
|
+
* Every named op addresses a node by a path array (`["services", "web", "ports", 0]`) and takes
|
|
49
|
+
* an optional last `{ document }` option selecting a document of a multi-document file.
|
|
50
|
+
* Documents no op touched print byte-identical to their source.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* import * as yaml from "@pbuilder/sdk/yaml";
|
|
54
|
+
*
|
|
55
|
+
* // compose.yaml before: services:\n web:\n image: node\n
|
|
56
|
+
* export const run = async () => {
|
|
57
|
+
* await yaml
|
|
58
|
+
* .find("compose.yaml")
|
|
59
|
+
* .setValue(["services", "web", "ports"], ["3000:3000"])
|
|
60
|
+
* .setComment(["services", "web"], "Frontend");
|
|
61
|
+
* };
|
|
62
|
+
* // -> services:
|
|
63
|
+
* // -> # Frontend
|
|
64
|
+
* // -> web:
|
|
65
|
+
* // -> image: node
|
|
66
|
+
* // -> ports:
|
|
67
|
+
* // -> - 3000:3000
|
|
68
|
+
*/
|
|
69
|
+
export declare function find(path: string): Handle<"found", YamlStream, YamlOps>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The YAML dialect module, `@pbuilder/sdk/yaml`. Composes the sanctioned kit surface only
|
|
2
|
+
// (`defineDialect`/`defineOpPack`/`withOps`), mirroring the other dialect modules.
|
|
3
|
+
import { defineDialect, defineOpPack, withOps } from "../../../../domain/services/define-dialect.js";
|
|
4
|
+
import { parse, print } from "./ast.js";
|
|
5
|
+
import { addDocument, removeDocument } from "./documents.js";
|
|
6
|
+
import { addMergeKey, removeAnchor, removeComment, setAlias, setAnchor, setComment, setStyle, setTag, } from "./presentation.js";
|
|
7
|
+
import { addKey, appendItem, copyValue, insertItem, merge, moveItem, moveValue, removeItem, removeKey, removeValue, renameKey, replaceItem, setValue, sortKeys, updateValue, } from "./structural.js";
|
|
8
|
+
export * as astLibrary from "yaml";
|
|
9
|
+
const opsPack = defineOpPack({
|
|
10
|
+
setValue,
|
|
11
|
+
addKey,
|
|
12
|
+
removeKey,
|
|
13
|
+
renameKey,
|
|
14
|
+
insertItem,
|
|
15
|
+
appendItem,
|
|
16
|
+
removeItem,
|
|
17
|
+
removeValue,
|
|
18
|
+
replaceItem,
|
|
19
|
+
moveItem,
|
|
20
|
+
merge,
|
|
21
|
+
updateValue,
|
|
22
|
+
setComment,
|
|
23
|
+
removeComment,
|
|
24
|
+
setAnchor,
|
|
25
|
+
removeAnchor,
|
|
26
|
+
setAlias,
|
|
27
|
+
addMergeKey,
|
|
28
|
+
setStyle,
|
|
29
|
+
addDocument,
|
|
30
|
+
removeDocument,
|
|
31
|
+
moveValue,
|
|
32
|
+
copyValue,
|
|
33
|
+
sortKeys,
|
|
34
|
+
setTag,
|
|
35
|
+
});
|
|
36
|
+
const baseDialect = defineDialect({
|
|
37
|
+
extensions: [".yaml", ".yml"],
|
|
38
|
+
ast: { parse, print },
|
|
39
|
+
ops: {},
|
|
40
|
+
});
|
|
41
|
+
const yamlDialect = withOps(baseDialect, opsPack);
|
|
42
|
+
/**
|
|
43
|
+
* Opens a `.yaml` or `.yml` file for YAML-dialect editing. The basename must end in one of those
|
|
44
|
+
* extensions after a non-empty stem; every other path throws synchronously, before any op runs,
|
|
45
|
+
* with the `dialect operation failed: ` prefix.
|
|
46
|
+
*
|
|
47
|
+
* Every named op addresses a node by a path array (`["services", "web", "ports", 0]`) and takes
|
|
48
|
+
* an optional last `{ document }` option selecting a document of a multi-document file.
|
|
49
|
+
* Documents no op touched print byte-identical to their source.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* import * as yaml from "@pbuilder/sdk/yaml";
|
|
53
|
+
*
|
|
54
|
+
* // compose.yaml before: services:\n web:\n image: node\n
|
|
55
|
+
* export const run = async () => {
|
|
56
|
+
* await yaml
|
|
57
|
+
* .find("compose.yaml")
|
|
58
|
+
* .setValue(["services", "web", "ports"], ["3000:3000"])
|
|
59
|
+
* .setComment(["services", "web"], "Frontend");
|
|
60
|
+
* };
|
|
61
|
+
* // -> services:
|
|
62
|
+
* // -> # Frontend
|
|
63
|
+
* // -> web:
|
|
64
|
+
* // -> image: node
|
|
65
|
+
* // -> ports:
|
|
66
|
+
* // -> - 3000:3000
|
|
67
|
+
*/
|
|
68
|
+
export function find(path) {
|
|
69
|
+
return yamlDialect.find(path);
|
|
70
|
+
}
|
package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.d.ts
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Pair, type Document, type Node, type YAMLMap, type YAMLSeq } from "yaml";
|
|
2
|
-
import { type JsonPath, type JsonValue } from "
|
|
2
|
+
import { type JsonPath, type JsonValue } from "../../../../domain/valueobjects/json-value.ts";
|
|
3
3
|
import { type YamlStream } from "./ast.ts";
|
|
4
4
|
export type YamlValue = JsonValue;
|
|
5
5
|
export type YamlPath = JsonPath;
|
package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.js
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Shared plumbing for the YAML ops: document selection, path resolution over `yaml` nodes,
|
|
2
2
|
// node replacement that keeps comments and anchors, and the alias-order invariant.
|
|
3
3
|
import { Pair, Scalar, isAlias, isMap, isNode, isScalar, isSeq, visit } from "yaml";
|
|
4
|
-
import { dialectError } from "
|
|
5
|
-
import { assertJsonValue, formatPath } from "
|
|
4
|
+
import { dialectError } from "../../../../domain/valueobjects/dialect-error.js";
|
|
5
|
+
import { assertJsonValue, formatPath } from "../../../../domain/valueobjects/json-value.js";
|
|
6
6
|
import { newDocument } from "./ast.js";
|
|
7
7
|
export function fail(op, path, tail) {
|
|
8
8
|
throw dialectError(path === null ? `${op}: ${tail}` : `${op} ${formatPath(path)}: ${tail}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Presentation ops only YAML has: comments, anchors, aliases, merge keys, styles, and tags.
|
|
2
2
|
import { Alias, Document, Pair, Scalar, isAlias, isMap, isScalar, isSeq, parseDocument, visit } from "yaml";
|
|
3
|
-
import { deepEqual } from "
|
|
3
|
+
import { deepEqual } from "../../../../../../platform/deep-equal.js";
|
|
4
4
|
import { assertAliasesResolve, assertPath, fail, findAnchored, findPair, resolve, selectDocument, toValue, writeSlot, } from "./paths.js";
|
|
5
5
|
function existingSlot(op, document, path) {
|
|
6
6
|
const slot = resolve(op, document, path, "write");
|
package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.js
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Structural ops: the JSON dialect's catalogue over `yaml` nodes, with "object" read as mapping
|
|
2
2
|
// and "array" as sequence.
|
|
3
3
|
import { isAlias, isMap, isSeq } from "yaml";
|
|
4
|
-
import { deepEqual } from "
|
|
5
|
-
import { formatPath } from "
|
|
4
|
+
import { deepEqual } from "../../../../../../platform/deep-equal.js";
|
|
5
|
+
import { formatPath } from "../../../../domain/valueobjects/json-value.js";
|
|
6
6
|
import { assertAliasesResolve, assertPath, assertPosition, assertValue, createNode, fail, findPair, isPlainObject, keyLabel, replacement, resolve, resolveAlias, selectDocument, toValue, writeSlot, } from "./paths.js";
|
|
7
7
|
function upsert(op, document, path, value, options) {
|
|
8
8
|
assertPosition(op, path, document, options);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type PackageFiles } from "../../../domain/ports/package-files.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The reserved lifecycle name among a package folder's own entry names — a
|
|
4
|
+
* `pre-execute`/`post-execute` file (`.ts`/`.js`, case-insensitive) or directory — or
|
|
5
|
+
* `undefined`. Never run-time inputs or `schema.json` field names (REQ-RLN-01.4).
|
|
6
|
+
*/
|
|
7
|
+
export declare function reservedSiblingIn(entryNames: readonly string[]): string | undefined;
|
|
8
|
+
export declare const nodePackageFiles: PackageFiles;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// The node:fs adapter of the package-files port. ENOENT is absence; any other failure is
|
|
2
|
+
// described in author vocabulary, never by its raw errno message.
|
|
3
|
+
import { lstatSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { join, relative } from "node:path";
|
|
5
|
+
import { PackageReadFailure, } from "../../../domain/ports/package-files.js";
|
|
6
|
+
import { RESERVED_LIFECYCLE_NAMES } from "../../../domain/valueobjects/schema-model.js";
|
|
7
|
+
import { isErrnoException } from "../../../../../platform/fs-errors.js";
|
|
8
|
+
function describeReadFailure(err) {
|
|
9
|
+
if (isErrnoException(err)) {
|
|
10
|
+
if (err.code === "EACCES" || err.code === "EPERM")
|
|
11
|
+
return "permission denied";
|
|
12
|
+
if (err.code === "EISDIR")
|
|
13
|
+
return "is a directory, not a file";
|
|
14
|
+
}
|
|
15
|
+
return "unreadable";
|
|
16
|
+
}
|
|
17
|
+
function unlessAbsent(read) {
|
|
18
|
+
try {
|
|
19
|
+
return read();
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
if (isErrnoException(err) && err.code === "ENOENT")
|
|
23
|
+
return undefined;
|
|
24
|
+
throw new PackageReadFailure(describeReadFailure(err));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const RESERVED_EXTENSIONS = [".ts", ".js"];
|
|
28
|
+
// Strips a recognized extension (case-insensitively) so `pre-execute.ts`, `PRE-EXECUTE.TS`,
|
|
29
|
+
// and the dir-form entry `pre-execute` (no extension at all) all normalize to the same
|
|
30
|
+
// lowercase kebab token before comparison (ADR-0028: case-insensitive, strip-extension).
|
|
31
|
+
function normalizeEntry(name) {
|
|
32
|
+
const lower = name.toLowerCase();
|
|
33
|
+
for (const ext of RESERVED_EXTENSIONS) {
|
|
34
|
+
if (lower.endsWith(ext))
|
|
35
|
+
return lower.slice(0, -ext.length);
|
|
36
|
+
}
|
|
37
|
+
return lower;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The reserved lifecycle name among a package folder's own entry names — a
|
|
41
|
+
* `pre-execute`/`post-execute` file (`.ts`/`.js`, case-insensitive) or directory — or
|
|
42
|
+
* `undefined`. Never run-time inputs or `schema.json` field names (REQ-RLN-01.4).
|
|
43
|
+
*/
|
|
44
|
+
export function reservedSiblingIn(entryNames) {
|
|
45
|
+
for (const entry of entryNames) {
|
|
46
|
+
const normalized = normalizeEntry(entry);
|
|
47
|
+
const match = RESERVED_LIFECYCLE_NAMES.find((name) => name === normalized);
|
|
48
|
+
if (match !== undefined)
|
|
49
|
+
return match;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
// The path is joined lexically, never canonicalized on disk; the operating system resolves a
|
|
54
|
+
// relative package folder against the working directory. This file is in the runner closure,
|
|
55
|
+
// where `path.resolve` (it reads the working directory) is not an admitted origin.
|
|
56
|
+
function statSource(packageDir, relPath) {
|
|
57
|
+
try {
|
|
58
|
+
const stat = statSync(join(packageDir, relPath));
|
|
59
|
+
if (stat.isDirectory())
|
|
60
|
+
return { kind: "directory" };
|
|
61
|
+
return stat.isFile() ? { kind: "file", size: stat.size } : { kind: "other" };
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
if (isErrnoException(err)) {
|
|
65
|
+
// ENOTDIR/ENAMETOOLONG both mean the path, as given, does not exist: a segment along
|
|
66
|
+
// the way is a regular file, or the resolved string exceeds the filesystem's name
|
|
67
|
+
// limit. Neither is a permission or I/O failure on an existing path.
|
|
68
|
+
if (err.code === "ENOENT" || err.code === "ENOTDIR" || err.code === "ENAMETOOLONG")
|
|
69
|
+
return { kind: "missing" };
|
|
70
|
+
if (err.code === "ELOOP")
|
|
71
|
+
return { kind: "unreadable", detail: "symlink cycle" };
|
|
72
|
+
if (err.code === "ERR_INVALID_ARG_VALUE")
|
|
73
|
+
return { kind: "unreadable", detail: "path contains an invalid character" };
|
|
74
|
+
}
|
|
75
|
+
// EACCES/EPERM/EMFILE/…, or no `.code` at all: never interpolates the raw error.
|
|
76
|
+
return { kind: "unreadable", detail: "permission or I/O error" };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// The walk names a vanished entry and a non-folder root differently from every other failure.
|
|
80
|
+
function entryFailure(err) {
|
|
81
|
+
if (isErrnoException(err) && err.code === "ENOENT")
|
|
82
|
+
return "missing";
|
|
83
|
+
if (isErrnoException(err) && err.code === "ENOTDIR")
|
|
84
|
+
return "not-a-directory";
|
|
85
|
+
return "unreadable";
|
|
86
|
+
}
|
|
87
|
+
function entryAt(path) {
|
|
88
|
+
try {
|
|
89
|
+
const stat = lstatSync(path);
|
|
90
|
+
if (stat.isSymbolicLink())
|
|
91
|
+
return { kind: "symlink" };
|
|
92
|
+
return { kind: stat.isDirectory() ? "directory" : "other" };
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
return { failure: entryFailure(err) };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function namesIn(dir) {
|
|
99
|
+
try {
|
|
100
|
+
return readdirSync(dir);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
return { failure: entryFailure(err) };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function isFolder(path) {
|
|
107
|
+
try {
|
|
108
|
+
return statSync(path).isDirectory();
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export const nodePackageFiles = {
|
|
115
|
+
readText: (path) => unlessAbsent(() => readFileSync(path, "utf-8")),
|
|
116
|
+
findReservedSibling: (packageDir) => {
|
|
117
|
+
const entries = unlessAbsent(() => readdirSync(packageDir));
|
|
118
|
+
return entries === undefined ? undefined : reservedSiblingIn(entries);
|
|
119
|
+
},
|
|
120
|
+
relativeToCwd: (path) => relative(process.cwd(), path),
|
|
121
|
+
statSource,
|
|
122
|
+
readBytes: (packageDir, relPath) => {
|
|
123
|
+
try {
|
|
124
|
+
return readFileSync(join(packageDir, relPath));
|
|
125
|
+
}
|
|
126
|
+
catch (err) {
|
|
127
|
+
throw new PackageReadFailure(describeReadFailure(err));
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
entryAt,
|
|
131
|
+
namesIn,
|
|
132
|
+
isFolder,
|
|
133
|
+
};
|