@pbuilder/sdk 0.14.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +57 -42
- package/dist/{transport → acl/irwire}/frame-reader.d.ts +2 -0
- package/dist/{transport → acl/irwire}/frame-reader.js +57 -5
- package/dist/{transport → acl/irwire}/stdio-engine-client.d.ts +2 -2
- package/dist/{transport → acl/irwire}/stdio-engine-client.js +4 -4
- package/dist/bin/pbuilder-codegen.js +30 -35
- package/dist/bin/pbuilder-runner.js +6 -6
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +106 -0
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +202 -0
- package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.d.ts +12 -9
- package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.js +59 -120
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.d.ts +5 -0
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.js +15 -0
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.d.ts +51 -0
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.js +105 -0
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.d.ts +2 -1
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.js +13 -7
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.d.ts +1 -1
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.js +7 -6
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.d.ts +11 -10
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.js +21 -48
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.d.ts +2 -3
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.js +37 -56
- package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.js +10 -10
- package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.d.ts +1 -1
- package/dist/bounded-contexts/authoring/domain/ports/package-files.d.ts +53 -0
- package/dist/bounded-contexts/authoring/domain/ports/package-files.js +11 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.js +3 -3
- package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.js +37 -12
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.d.ts +7 -5
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.js +28 -8
- package/dist/{core/jsx-name-validator.d.ts → bounded-contexts/authoring/domain/services/identifier-names.d.ts} +8 -4
- package/dist/{core/jsx-name-validator.js → bounded-contexts/authoring/domain/services/identifier-names.js} +21 -28
- package/dist/bounded-contexts/authoring/domain/services/reject-tail.d.ts +9 -0
- package/dist/bounded-contexts/authoring/domain/services/reject-tail.js +30 -0
- package/dist/bounded-contexts/authoring/domain/services/run-context.d.ts +5 -0
- package/dist/bounded-contexts/authoring/domain/services/run-context.js +70 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.js +1 -1
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.d.ts +2 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.js +6 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.d.ts +2 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.js +13 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.js +2 -14
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.d.ts +4 -3
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.js +8 -4
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/wire.d.ts +0 -3
- package/dist/bounded-contexts/authoring/domain/valueobjects/wire.js +28 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +27 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +306 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +7 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +68 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +19 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +131 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +182 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +94 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +63 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +68 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.js +9 -9
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +40 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +38 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +55 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +54 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.d.ts +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.js +35 -8
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +43 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +46 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.js +7 -7
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +52 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +73 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.d.ts +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.js +18 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.d.ts +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.js +25 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.js +5 -3
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.d.ts +7 -2
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.js +29 -15
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.d.ts +5 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.js +22 -4
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.js +14 -19
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +53 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +37 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.d.ts +6 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.js +90 -54
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +69 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +70 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.d.ts +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.js +2 -2
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.js +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.d.ts +8 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.js +133 -0
- package/dist/bounded-contexts/authoring/testing/conformance/index.d.ts +157 -0
- package/dist/bounded-contexts/authoring/testing/conformance/index.js +261 -0
- package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.d.ts +2 -2
- package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.js +4 -3
- package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +89 -0
- package/dist/bounded-contexts/authoring/testing/harness/index.js +85 -0
- package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.d.ts +1 -1
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.js +2 -2
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.js +5 -4
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.js +1 -1
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.d.ts +4 -0
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.js +49 -23
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.js +1 -1
- package/dist/commons/index.d.ts +1 -278
- package/dist/commons/index.js +1 -286
- package/dist/conformance/index.d.ts +1 -157
- package/dist/conformance/index.js +1 -261
- package/dist/dialects/angular/index.d.ts +1 -63
- package/dist/dialects/angular/index.js +1 -68
- package/dist/dialects/css/index.d.ts +1 -40
- package/dist/dialects/css/index.js +1 -38
- package/dist/dialects/json/index.d.ts +1 -55
- package/dist/dialects/json/index.js +1 -54
- package/dist/dialects/nestjs/index.d.ts +1 -43
- package/dist/dialects/nestjs/index.js +1 -46
- package/dist/dialects/react/index.d.ts +1 -52
- package/dist/dialects/react/index.js +1 -73
- package/dist/dialects/typescript/index.d.ts +1 -53
- package/dist/dialects/typescript/index.js +1 -37
- package/dist/dialects/yaml/index.d.ts +1 -69
- package/dist/dialects/yaml/index.js +1 -70
- package/dist/{core → platform}/deep-equal.js +2 -2
- package/dist/{transport → platform}/error-text.js +2 -2
- package/dist/runner-manifest.json +66 -46
- package/dist/shared-kernel/batch-cap.d.ts +4 -0
- package/dist/{core/wire.js → shared-kernel/batch-cap.js} +9 -26
- package/dist/{transport → shared-kernel}/framing.js +2 -2
- package/dist/{transport → shared-kernel}/wire-protocol.js +1 -1
- package/dist/testing/index.d.ts +1 -84
- package/dist/testing/index.js +1 -82
- package/package.json +9 -3
- package/dist/core/index.d.ts +0 -10
- package/dist/core/index.js +0 -6
- package/dist/core/reject-tail.d.ts +0 -13
- package/dist/core/reject-tail.js +0 -52
- package/dist/core/schema/schema-discovery.d.ts +0 -13
- package/dist/core/schema/schema-discovery.js +0 -51
- package/dist/scaffold/classify-transport.d.ts +0 -54
- package/dist/scaffold/classify-transport.js +0 -119
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.d.ts +0 -0
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.js +0 -0
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.js +0 -0
- /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.d.ts +0 -0
- /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.js +0 -0
- /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.d.ts +0 -0
- /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.d.ts +0 -0
- /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.d.ts +0 -0
- /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.js +0 -0
- /package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.js +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.d.ts +0 -0
- /package/dist/{core → platform}/deep-equal.d.ts +0 -0
- /package/dist/{transport → platform}/error-text.d.ts +0 -0
- /package/dist/{core → platform}/fs-errors.d.ts +0 -0
- /package/dist/{core → platform}/fs-errors.js +0 -0
- /package/dist/{transport → shared-kernel}/framing.d.ts +0 -0
- /package/dist/{transport → shared-kernel}/wire-protocol.d.ts +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { defineDialect, defineOpPack, query, withOps } from "../../../../domain/services/define-dialect.js";
|
|
2
|
+
import { parse, print } from "./ast.js";
|
|
3
|
+
import { getDeclaration, removeDeclaration, setDeclaration } from "./ops.js";
|
|
4
|
+
export * as astLibrary from "postcss";
|
|
5
|
+
export { getDeclaration };
|
|
6
|
+
const opsPack = defineOpPack({ setDeclaration, removeDeclaration, getDeclaration: query(getDeclaration) });
|
|
7
|
+
const cssDialect = withOps(defineDialect({ extensions: [".css"], ast: { parse, print }, ops: {} }), opsPack);
|
|
8
|
+
/**
|
|
9
|
+
* Opens a `.css` file to set and remove declarations. A target names one top-level block —
|
|
10
|
+
* `{ selector: ":root" }`, `{ atRule: "theme" }`, or `{ atRule: "media", params, selector }` —
|
|
11
|
+
* and every op edits only the declaration it addresses: comments, `@import`s, other rules,
|
|
12
|
+
* indentation, line endings, and a BOM survive. Any other extension throws synchronously with
|
|
13
|
+
* the `dialect operation failed: ` prefix. `.modify(fn)` hands `fn` the live PostCSS `Root`;
|
|
14
|
+
* use `astLibrary` (`postcss`) for anything the ops do not cover.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* import * as css from "@pbuilder/sdk/css";
|
|
18
|
+
*
|
|
19
|
+
* // tokens.css before: @import "tailwindcss";\n\n@theme {\n --color-primary: #0b254d;\n}\n
|
|
20
|
+
* export const run = async () => {
|
|
21
|
+
* await css
|
|
22
|
+
* .find("tokens.css")
|
|
23
|
+
* .setDeclaration({ atRule: "theme" }, "--color-primary", "#1974f9")
|
|
24
|
+
* .setDeclaration({ selector: "html[data-theme='nylon']" }, "--color-primary", "#0b254d");
|
|
25
|
+
* };
|
|
26
|
+
* // -> @import "tailwindcss";
|
|
27
|
+
* // ->
|
|
28
|
+
* // -> @theme {
|
|
29
|
+
* // -> --color-primary: #1974f9;
|
|
30
|
+
* // -> }
|
|
31
|
+
* // ->
|
|
32
|
+
* // -> html[data-theme='nylon'] {
|
|
33
|
+
* // -> --color-primary: #0b254d;
|
|
34
|
+
* // -> }
|
|
35
|
+
*/
|
|
36
|
+
export function find(path) {
|
|
37
|
+
return cssDialect.find(path);
|
|
38
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { atRule, decl, parse, rule } from "postcss";
|
|
2
|
-
import { dialectError } from "
|
|
3
|
-
import { validatedOp } from "
|
|
2
|
+
import { dialectError } from "../../../../domain/valueobjects/dialect-error.js";
|
|
3
|
+
import { validatedOp } from "../../../../domain/services/identifier-names.js";
|
|
4
4
|
const REGULAR_PROPERTY = /^-?[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
5
5
|
// `*` admits Tailwind's namespace resets (`--color-*: initial`).
|
|
6
6
|
const CUSTOM_PROPERTY = /^--[A-Za-z0-9_*\u0080-\uFFFF-]+$/;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type Handle } from "../../../../domain/services/define-dialect.ts";
|
|
2
|
+
import type { JsonPath, JsonValue } from "../../../../domain/valueobjects/json-value.ts";
|
|
3
|
+
import { type JsonDocument } from "./ast.ts";
|
|
4
|
+
import { type AppendOptions, type KeyPosition, type SortOptions } from "./ops.ts";
|
|
5
|
+
export * as astLibrary from "jsonc-parser";
|
|
6
|
+
export type { JsonDocument, JsonPath, JsonValue, KeyPosition, AppendOptions, SortOptions };
|
|
7
|
+
type JsonOps = {
|
|
8
|
+
setValue: (ast: JsonDocument, path: JsonPath, value: JsonValue, options?: KeyPosition) => void;
|
|
9
|
+
addKey: (ast: JsonDocument, path: JsonPath, value: JsonValue, options?: KeyPosition) => void;
|
|
10
|
+
removeKey: (ast: JsonDocument, path: JsonPath) => void;
|
|
11
|
+
renameKey: (ast: JsonDocument, path: JsonPath, newKey: string) => void;
|
|
12
|
+
insertItem: (ast: JsonDocument, path: JsonPath, index: number, value: JsonValue) => void;
|
|
13
|
+
appendItem: (ast: JsonDocument, path: JsonPath, value: JsonValue, options?: AppendOptions) => void;
|
|
14
|
+
removeItem: (ast: JsonDocument, path: JsonPath, index: number) => void;
|
|
15
|
+
removeValue: (ast: JsonDocument, path: JsonPath, value: JsonValue) => void;
|
|
16
|
+
replaceItem: (ast: JsonDocument, path: JsonPath, index: number, value: JsonValue) => void;
|
|
17
|
+
moveItem: (ast: JsonDocument, path: JsonPath, from: number, to: number) => void;
|
|
18
|
+
merge: (ast: JsonDocument, path: JsonPath, value: {
|
|
19
|
+
[key: string]: JsonValue;
|
|
20
|
+
}) => void;
|
|
21
|
+
updateValue: <T extends JsonValue>(ast: JsonDocument, path: JsonPath, fn: (current: JsonValue | undefined) => T) => void;
|
|
22
|
+
moveValue: (ast: JsonDocument, from: JsonPath, to: JsonPath) => void;
|
|
23
|
+
copyValue: (ast: JsonDocument, from: JsonPath, to: JsonPath) => void;
|
|
24
|
+
sortKeys: (ast: JsonDocument, path: JsonPath, options?: SortOptions) => void;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Opens a `.json` or `.jsonc` file for structural editing. Every op addresses a value by a
|
|
28
|
+
* path array (`["scripts", "build"]`, `["files", 0]`) and edits only the bytes it must:
|
|
29
|
+
* comments, key order, indentation, line endings, a BOM, and the trailing newline survive.
|
|
30
|
+
* Any other extension, a basename with no stem (`.json`), or an extensionless path throws
|
|
31
|
+
* synchronously with the `dialect operation failed: ` prefix. `.modify(fn)` hands `fn` the
|
|
32
|
+
* live `JsonDocument`; edit its `text` with `astLibrary` (`jsonc-parser`) for anything the
|
|
33
|
+
* ops do not cover, such as comments.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* import * as json from "@pbuilder/sdk/json";
|
|
37
|
+
*
|
|
38
|
+
* // package.json before: {\n "name": "app"\n}\n
|
|
39
|
+
* export const run = async () => {
|
|
40
|
+
* await json
|
|
41
|
+
* .find("package.json")
|
|
42
|
+
* .setValue(["scripts", "build"], "tsc")
|
|
43
|
+
* .appendItem(["files"], "dist", { unique: true });
|
|
44
|
+
* };
|
|
45
|
+
* // -> {
|
|
46
|
+
* // -> "name": "app",
|
|
47
|
+
* // -> "scripts": {
|
|
48
|
+
* // -> "build": "tsc"
|
|
49
|
+
* // -> },
|
|
50
|
+
* // -> "files": [
|
|
51
|
+
* // -> "dist"
|
|
52
|
+
* // -> ]
|
|
53
|
+
* // -> }
|
|
54
|
+
*/
|
|
55
|
+
export declare function find(path: string): Handle<"found", JsonDocument, JsonOps>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { defineDialect, defineOpPack, withOps } from "../../../../domain/services/define-dialect.js";
|
|
2
|
+
import { parse, print } from "./ast.js";
|
|
3
|
+
import { addKey, appendItem, copyValue, insertItem, merge, moveItem, moveValue, removeItem, removeKey, removeValue, renameKey, replaceItem, setValue, sortKeys, updateValue, } from "./ops.js";
|
|
4
|
+
export * as astLibrary from "jsonc-parser";
|
|
5
|
+
const opsPack = defineOpPack({
|
|
6
|
+
setValue,
|
|
7
|
+
addKey,
|
|
8
|
+
removeKey,
|
|
9
|
+
renameKey,
|
|
10
|
+
insertItem,
|
|
11
|
+
appendItem,
|
|
12
|
+
removeItem,
|
|
13
|
+
removeValue,
|
|
14
|
+
replaceItem,
|
|
15
|
+
moveItem,
|
|
16
|
+
merge,
|
|
17
|
+
updateValue,
|
|
18
|
+
moveValue,
|
|
19
|
+
copyValue,
|
|
20
|
+
sortKeys,
|
|
21
|
+
});
|
|
22
|
+
const jsonDialect = withOps(defineDialect({ extensions: [".json", ".jsonc"], ast: { parse, print }, ops: {} }), opsPack);
|
|
23
|
+
/**
|
|
24
|
+
* Opens a `.json` or `.jsonc` file for structural editing. Every op addresses a value by a
|
|
25
|
+
* path array (`["scripts", "build"]`, `["files", 0]`) and edits only the bytes it must:
|
|
26
|
+
* comments, key order, indentation, line endings, a BOM, and the trailing newline survive.
|
|
27
|
+
* Any other extension, a basename with no stem (`.json`), or an extensionless path throws
|
|
28
|
+
* synchronously with the `dialect operation failed: ` prefix. `.modify(fn)` hands `fn` the
|
|
29
|
+
* live `JsonDocument`; edit its `text` with `astLibrary` (`jsonc-parser`) for anything the
|
|
30
|
+
* ops do not cover, such as comments.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* import * as json from "@pbuilder/sdk/json";
|
|
34
|
+
*
|
|
35
|
+
* // package.json before: {\n "name": "app"\n}\n
|
|
36
|
+
* export const run = async () => {
|
|
37
|
+
* await json
|
|
38
|
+
* .find("package.json")
|
|
39
|
+
* .setValue(["scripts", "build"], "tsc")
|
|
40
|
+
* .appendItem(["files"], "dist", { unique: true });
|
|
41
|
+
* };
|
|
42
|
+
* // -> {
|
|
43
|
+
* // -> "name": "app",
|
|
44
|
+
* // -> "scripts": {
|
|
45
|
+
* // -> "build": "tsc"
|
|
46
|
+
* // -> },
|
|
47
|
+
* // -> "files": [
|
|
48
|
+
* // -> "dist"
|
|
49
|
+
* // -> ]
|
|
50
|
+
* // -> }
|
|
51
|
+
*/
|
|
52
|
+
export function find(path) {
|
|
53
|
+
return jsonDialect.find(path);
|
|
54
|
+
}
|
package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.js
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { applyEdits, getNodeValue, modify, parseTree, } from "jsonc-parser";
|
|
2
|
-
import { deepEqual } from "
|
|
3
|
-
import { dialectError } from "
|
|
4
|
-
import { assertJsonValue, formatPath } from "
|
|
2
|
+
import { deepEqual } from "../../../../../../platform/deep-equal.js";
|
|
3
|
+
import { dialectError } from "../../../../domain/valueobjects/dialect-error.js";
|
|
4
|
+
import { assertJsonValue, formatPath } from "../../../../domain/valueobjects/json-value.js";
|
|
5
5
|
function fail(op, path, why) {
|
|
6
6
|
throw dialectError(`${op}(${formatPath(path)}) — ${why}`);
|
|
7
7
|
}
|
|
@@ -89,10 +89,11 @@ function detectFormatting(text) {
|
|
|
89
89
|
return { insertSpaces: true, tabSize: indent?.length ?? 2, eol };
|
|
90
90
|
}
|
|
91
91
|
// jsonc-parser formats every line an edit touches, which would explode a one-line container
|
|
92
|
-
// into many lines; edits inside one-line containers therefore stay unformatted.
|
|
92
|
+
// into many lines; edits inside one-line containers therefore stay unformatted. An empty
|
|
93
|
+
// container (`{}`) has no layout of its own, so the container that holds it decides.
|
|
93
94
|
function formattingFor(text, located, path) {
|
|
94
|
-
const ancestors = located.nodes.slice(0, Math.max(path.length, 1));
|
|
95
|
-
const container = ancestors.findLast((node) => node !==
|
|
95
|
+
const ancestors = located.nodes.slice(0, Math.max(path.length, 1)).filter((node) => node !== undefined);
|
|
96
|
+
const container = ancestors.findLast((node) => node.children?.length !== 0) ?? ancestors.at(-1);
|
|
96
97
|
if (container === undefined)
|
|
97
98
|
return detectFormatting(text);
|
|
98
99
|
return text.slice(container.offset, container.offset + container.length).includes("\n")
|
|
@@ -184,6 +185,25 @@ function indentUnit(text) {
|
|
|
184
185
|
const format = detectFormatting(text);
|
|
185
186
|
return format.insertSpaces ? " ".repeat(format.tabSize ?? 2) : "\t";
|
|
186
187
|
}
|
|
188
|
+
// One line, with a space after each comma and colon and none inside the brackets (A-23).
|
|
189
|
+
function inlineJson(value) {
|
|
190
|
+
if (Array.isArray(value))
|
|
191
|
+
return `[${value.map(inlineJson).join(", ")}]`;
|
|
192
|
+
if (value !== null && typeof value === "object") {
|
|
193
|
+
return `{${Object.entries(value).map(([key, item]) => `${JSON.stringify(key)}: ${inlineJson(item)}`).join(", ")}}`;
|
|
194
|
+
}
|
|
195
|
+
return JSON.stringify(value);
|
|
196
|
+
}
|
|
197
|
+
// A new array or object goes on one line when every other value of its kind in `container` is
|
|
198
|
+
// on one line; with no such value, or with both layouts, it goes across lines (A-23).
|
|
199
|
+
function followsInlineSiblings(text, container, value) {
|
|
200
|
+
const kind = Array.isArray(value) ? "array" : value !== null && typeof value === "object" ? "object" : undefined;
|
|
201
|
+
if (kind === undefined)
|
|
202
|
+
return false;
|
|
203
|
+
const values = (container.children ?? []).map((child) => (container.type === "object" ? child.children[1] : child));
|
|
204
|
+
const siblings = values.filter((sibling) => sibling.type === kind);
|
|
205
|
+
return siblings.length > 0 && siblings.every((sibling) => !text.slice(sibling.offset, end(sibling)).includes("\n"));
|
|
206
|
+
}
|
|
187
207
|
// Inserts `prefix + value` as its own line(s) before member `index`, or after the last member.
|
|
188
208
|
function insertLine(doc, container, lines, index, prefix, value) {
|
|
189
209
|
const text = doc.text;
|
|
@@ -191,7 +211,10 @@ function insertLine(doc, container, lines, index, prefix, value) {
|
|
|
191
211
|
const member = container.children[Math.min(index, lines.length - 1)];
|
|
192
212
|
const indent = /[ \t]*$/.exec(text.slice(0, member.offset))[0];
|
|
193
213
|
const eol = text.slice(lines[0].tailEnd, lines[0].lineEnd);
|
|
194
|
-
const
|
|
214
|
+
const rendered = followsInlineSiblings(text, container, value)
|
|
215
|
+
? inlineJson(value)
|
|
216
|
+
: JSON.stringify(value, null, indentUnit(text)).split("\n").join(eol + indent);
|
|
217
|
+
const line = indent + prefix + rendered;
|
|
195
218
|
if (index < lines.length) {
|
|
196
219
|
splice(doc, at.leadStart, at.leadStart, `${line},${eol}`);
|
|
197
220
|
return;
|
|
@@ -546,8 +569,12 @@ function sortedText(text, node, recursive) {
|
|
|
546
569
|
.join("") +
|
|
547
570
|
slice(lines.at(-1).lineEnd, nodeEnd));
|
|
548
571
|
}
|
|
572
|
+
// The whitespace before a member belongs to its position; a comment moves with its member.
|
|
573
|
+
const spacing = (lead) => /^\s*/.exec(lead)[0];
|
|
549
574
|
return ("{" +
|
|
550
|
-
sorted
|
|
575
|
+
sorted
|
|
576
|
+
.map((member, index) => members[index].separator + spacing(members[index].lead) + member.lead.trimStart() + member.body)
|
|
577
|
+
.join("") +
|
|
551
578
|
slice(last.offset + last.length, nodeEnd));
|
|
552
579
|
}
|
|
553
580
|
/** Orders the object's members by key (code-point order); `{ recursive: true }` sorts nested objects too. */
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { SourceFile } from "ts-morph";
|
|
2
|
+
import { type Handle } from "../../../../domain/services/define-dialect.ts";
|
|
3
|
+
import { typescriptOps } from "../typescript/pack.ts";
|
|
4
|
+
export * as astLibrary from "ts-morph";
|
|
5
|
+
type ModuleOps = {
|
|
6
|
+
addProvider: (ast: SourceFile, name: string, from: string) => void;
|
|
7
|
+
addController: (ast: SourceFile, name: string, from: string) => void;
|
|
8
|
+
addModuleImport: (ast: SourceFile, name: string, from: string) => void;
|
|
9
|
+
addExport: (ast: SourceFile, name: string, from: string) => void;
|
|
10
|
+
};
|
|
11
|
+
type NestOps = typeof typescriptOps & ModuleOps;
|
|
12
|
+
/**
|
|
13
|
+
* Opens a `.ts` file of a NestJS project for editing. The handle carries every
|
|
14
|
+
* `@pbuilder/sdk/typescript` op plus the `@Module` ops below, chained on one handle and
|
|
15
|
+
* written once.
|
|
16
|
+
*
|
|
17
|
+
* `addProvider`, `addController`, `addModuleImport` and `addExport` each take
|
|
18
|
+
* `(name, from)`: they add `import { name } from "from"` with the same rules as `addImport`,
|
|
19
|
+
* then append `name` to the `providers`, `controllers`, `imports` or `exports` array of the
|
|
20
|
+
* file's only `@Module` class, creating the metadata object or the array when missing. They
|
|
21
|
+
* reject, leaving the file unchanged, when the file has no `@Module` class or more than one,
|
|
22
|
+
* or when the metadata or the array is not a literal. Use `.modify(fn)` for those files and
|
|
23
|
+
* for entries that are not a plain class name, such as `ConfigModule.forRoot()`.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* import * as nestjs from "@pbuilder/sdk/nestjs";
|
|
27
|
+
*
|
|
28
|
+
* // src/app.module.ts before:
|
|
29
|
+
* // @Module({ providers: [AppService] })
|
|
30
|
+
* // export class AppModule {}
|
|
31
|
+
* export const run = async () => {
|
|
32
|
+
* await nestjs
|
|
33
|
+
* .find("src/app.module.ts")
|
|
34
|
+
* .addModuleImport("UsersModule", "./users/users.module")
|
|
35
|
+
* .addProvider("UsersService", "./users/users.service");
|
|
36
|
+
* };
|
|
37
|
+
* // -> import { UsersModule } from "./users/users.module";
|
|
38
|
+
* // -> import { UsersService } from "./users/users.service";
|
|
39
|
+
* // ->
|
|
40
|
+
* // -> @Module({ providers: [AppService, UsersService], imports: [UsersModule] })
|
|
41
|
+
* // -> export class AppModule {}
|
|
42
|
+
*/
|
|
43
|
+
export declare function find(path: string): Handle<"found", SourceFile, NestOps>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { defineDialect, defineOpPack, withOps } from "../../../../domain/services/define-dialect.js";
|
|
2
|
+
import { parse, print } from "../typescript/ast.js";
|
|
3
|
+
import { typescriptOps } from "../typescript/pack.js";
|
|
4
|
+
import { addController, addExport, addModuleImport, addProvider } from "./ops.js";
|
|
5
|
+
export * as astLibrary from "ts-morph";
|
|
6
|
+
const moduleOps = defineOpPack({ addProvider, addController, addModuleImport, addExport });
|
|
7
|
+
const baseDialect = defineDialect({
|
|
8
|
+
extensions: [".ts"],
|
|
9
|
+
ast: { parse, print },
|
|
10
|
+
ops: {},
|
|
11
|
+
});
|
|
12
|
+
const nestjsDialect = withOps(baseDialect, typescriptOps, moduleOps);
|
|
13
|
+
/**
|
|
14
|
+
* Opens a `.ts` file of a NestJS project for editing. The handle carries every
|
|
15
|
+
* `@pbuilder/sdk/typescript` op plus the `@Module` ops below, chained on one handle and
|
|
16
|
+
* written once.
|
|
17
|
+
*
|
|
18
|
+
* `addProvider`, `addController`, `addModuleImport` and `addExport` each take
|
|
19
|
+
* `(name, from)`: they add `import { name } from "from"` with the same rules as `addImport`,
|
|
20
|
+
* then append `name` to the `providers`, `controllers`, `imports` or `exports` array of the
|
|
21
|
+
* file's only `@Module` class, creating the metadata object or the array when missing. They
|
|
22
|
+
* reject, leaving the file unchanged, when the file has no `@Module` class or more than one,
|
|
23
|
+
* or when the metadata or the array is not a literal. Use `.modify(fn)` for those files and
|
|
24
|
+
* for entries that are not a plain class name, such as `ConfigModule.forRoot()`.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* import * as nestjs from "@pbuilder/sdk/nestjs";
|
|
28
|
+
*
|
|
29
|
+
* // src/app.module.ts before:
|
|
30
|
+
* // @Module({ providers: [AppService] })
|
|
31
|
+
* // export class AppModule {}
|
|
32
|
+
* export const run = async () => {
|
|
33
|
+
* await nestjs
|
|
34
|
+
* .find("src/app.module.ts")
|
|
35
|
+
* .addModuleImport("UsersModule", "./users/users.module")
|
|
36
|
+
* .addProvider("UsersService", "./users/users.service");
|
|
37
|
+
* };
|
|
38
|
+
* // -> import { UsersModule } from "./users/users.module";
|
|
39
|
+
* // -> import { UsersService } from "./users/users.service";
|
|
40
|
+
* // ->
|
|
41
|
+
* // -> @Module({ providers: [AppService, UsersService], imports: [UsersModule] })
|
|
42
|
+
* // -> export class AppModule {}
|
|
43
|
+
*/
|
|
44
|
+
export function find(path) {
|
|
45
|
+
return nestjsDialect.find(path);
|
|
46
|
+
}
|
package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.js
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { SyntaxKind, } from "ts-morph";
|
|
2
|
-
import { dialectError } from "
|
|
3
|
-
import { handlePathFor } from "
|
|
4
|
-
import { assertValidImportBinding } from "
|
|
2
|
+
import { dialectError } from "../../../../domain/valueobjects/dialect-error.js";
|
|
3
|
+
import { handlePathFor } from "../../../../domain/entities/dialect-handle.js";
|
|
4
|
+
import { assertValidImportBinding } from "../../../../domain/services/identifier-names.js";
|
|
5
5
|
import { appendEntry } from "../typescript/array-element.js";
|
|
6
|
-
import {
|
|
6
|
+
import { importBinding } from "../typescript/ops.js";
|
|
7
7
|
function moduleDecorator(ast, fail) {
|
|
8
8
|
const decorators = ast
|
|
9
9
|
.getClasses()
|
|
@@ -54,10 +54,10 @@ function moduleArrayOp(verb, property) {
|
|
|
54
54
|
const fail = (reason) => {
|
|
55
55
|
throw dialectError(`${verb}("${name}") on "${handlePathFor(ast)}" — ${reason}. Edit it with .modify().`);
|
|
56
56
|
};
|
|
57
|
-
// Locating first rejects an unusable @Module before
|
|
58
|
-
// nodes are located again afterwards because
|
|
57
|
+
// Locating first rejects an unusable @Module before the import is added; the
|
|
58
|
+
// nodes are located again afterwards because adding the import may have rewritten them.
|
|
59
59
|
locate(ast, property, name, fail);
|
|
60
|
-
|
|
60
|
+
importBinding(ast, verb, name, from);
|
|
61
61
|
write(ast, locate(ast, property, name, fail), property, name);
|
|
62
62
|
};
|
|
63
63
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SourceFile } from "ts-morph";
|
|
2
|
+
import { type Handle } from "../../../../domain/services/define-dialect.ts";
|
|
3
|
+
import { typescriptOps } from "../typescript/pack.ts";
|
|
4
|
+
import { type JsxTarget } from "./ops.ts";
|
|
5
|
+
export * as astLibrary from "ts-morph";
|
|
6
|
+
export type { JsxTarget };
|
|
7
|
+
type JsxOps = {
|
|
8
|
+
setJsxProp: (ast: SourceFile, target: JsxTarget, propName: string, value?: string) => void;
|
|
9
|
+
removeJsxProp: (ast: SourceFile, target: JsxTarget, propName: string) => void;
|
|
10
|
+
addJsxChild: (ast: SourceFile, target: JsxTarget, jsx: string) => void;
|
|
11
|
+
wrapJsxElement: (ast: SourceFile, target: JsxTarget, wrapper: string) => void;
|
|
12
|
+
addHookCall: (ast: SourceFile, component: string, statement: string) => void;
|
|
13
|
+
addComponentProp: (ast: SourceFile, component: string, name: string, type: string, options?: {
|
|
14
|
+
optional?: boolean;
|
|
15
|
+
}) => void;
|
|
16
|
+
renameJsxElement: (ast: SourceFile, target: JsxTarget, tag: string) => void;
|
|
17
|
+
};
|
|
18
|
+
type ReactOps = typeof typescriptOps & JsxOps;
|
|
19
|
+
/**
|
|
20
|
+
* Opens a `.tsx` or `.jsx` file for React-dialect-aware editing — the dialect's entry verb into
|
|
21
|
+
* a Session that carries every `@pbuilder/sdk/typescript` op plus the JSX ops, chained on one
|
|
22
|
+
* handle (REQ-DG-01.2). Both extensions get the same handle: on `.jsx`, which parses as plain
|
|
23
|
+
* JavaScript with JSX, `addTypeImport`, `addComponentProp` and `addClassProperty`'s `scope`/
|
|
24
|
+
* `readonly` reject at call time because they write TypeScript syntax, leaving the file
|
|
25
|
+
* unchanged. The gate below runs SYNCHRONOUSLY, before any op is chained and before any run
|
|
26
|
+
* flush, so a rejected path throws on the bare `find()` call itself. `.ts` files are TypeScript,
|
|
27
|
+
* not this dialect — use `@pbuilder/sdk/typescript`. Every other extension, dotfile basename,
|
|
28
|
+
* trailing-dot basename, and extensionless path is rejected the same way —
|
|
29
|
+
* no normalization, always an explicit `.tsx` or `.jsx`, so neither extension is ever assumed.
|
|
30
|
+
* Every gate rejection throws via `dialectError`, so its message carries the standard
|
|
31
|
+
* `dialect operation failed: ` prefix.
|
|
32
|
+
*
|
|
33
|
+
* Trust boundary: a value handed to a structured mutation (e.g. `setJsxProp`'s `value`
|
|
34
|
+
* argument) is emitted verbatim into the output and becomes executable code — the SDK
|
|
35
|
+
* performs no validation, escaping, or sanitisation on it; the author is solely responsible
|
|
36
|
+
* for any untrusted input reaching that channel.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* import * as react from "@pbuilder/sdk/react";
|
|
40
|
+
*
|
|
41
|
+
* // src/Button.tsx before: const el = <Button />;
|
|
42
|
+
* export const run = async () => {
|
|
43
|
+
* await react
|
|
44
|
+
* .find("src/Button.tsx")
|
|
45
|
+
* .addImport("handleClick", "./handlers")
|
|
46
|
+
* .setJsxProp("Button", "onClick", "{handleClick}");
|
|
47
|
+
* };
|
|
48
|
+
* // -> import { handleClick } from "./handlers";
|
|
49
|
+
* // ->
|
|
50
|
+
* // -> const el = <Button onClick={handleClick} />;
|
|
51
|
+
*/
|
|
52
|
+
export declare function find(path: string): Handle<"found", SourceFile, ReactOps>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// S-000: the React dialect module — `@pbuilder/sdk/react` (REQ-RXD-01, walking skeleton).
|
|
2
|
+
// Composes the sanctioned kit surface ONLY (`defineDialect`/`defineOpPack`/`withOps` from
|
|
3
|
+
// ../../core/define-dialect.ts) — mirrors src/dialects/typescript/index.ts's shape exactly,
|
|
4
|
+
// no port-internal machinery imported anywhere in this tree (REQ-DG-04.1, fit-08/fit-10).
|
|
5
|
+
// The parser stays local: typescript/ast.ts parses as `.ts`, which rejects JSX syntax.
|
|
6
|
+
import { basename } from "node:path";
|
|
7
|
+
import { byExtension, defineDialect, defineOpPack, overrideOps, withOps, withoutOps } from "../../../../domain/services/define-dialect.js";
|
|
8
|
+
import { dialectError } from "../../../../domain/valueobjects/dialect-error.js";
|
|
9
|
+
import { addClassProperty } from "../typescript/class-property.js";
|
|
10
|
+
import { typescriptOps } from "../typescript/pack.js";
|
|
11
|
+
import { parse, parseJsx, print } from "./ast.js";
|
|
12
|
+
import { addComponentProp, addHookCall, addJsxChild, removeJsxProp, renameJsxElement, setJsxProp, wrapJsxElement, } from "./ops.js";
|
|
13
|
+
export * as astLibrary from "ts-morph";
|
|
14
|
+
const jsxOps = defineOpPack({ setJsxProp, removeJsxProp, addJsxChild, wrapJsxElement, addHookCall, addComponentProp, renameJsxElement });
|
|
15
|
+
const tsxDialect = withOps(defineDialect({ extensions: [".tsx"], ast: { parse, print }, ops: {} }), typescriptOps, jsxOps);
|
|
16
|
+
const jsxDialect = overrideOps(withoutOps(defineDialect({ extensions: [".jsx"], ast: { parse: parseJsx, print }, ops: tsxDialect.ops }), ["addTypeImport", "addComponentProp"], "they write TypeScript type syntax, which a .jsx file cannot hold"), {
|
|
17
|
+
addClassProperty: (ast, className, name, initializer, options) => {
|
|
18
|
+
if (options?.scope !== undefined || options?.readonly !== undefined) {
|
|
19
|
+
throw dialectError("addClassProperty's `scope` and `readonly` are TypeScript modifiers, which a .jsx file cannot hold — " +
|
|
20
|
+
"omit them, or use .modify() to make this edit directly.");
|
|
21
|
+
}
|
|
22
|
+
addClassProperty(ast, className, name, initializer);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const reactDialect = byExtension({ ".tsx": tsxDialect, ".jsx": jsxDialect });
|
|
26
|
+
/**
|
|
27
|
+
* Opens a `.tsx` or `.jsx` file for React-dialect-aware editing — the dialect's entry verb into
|
|
28
|
+
* a Session that carries every `@pbuilder/sdk/typescript` op plus the JSX ops, chained on one
|
|
29
|
+
* handle (REQ-DG-01.2). Both extensions get the same handle: on `.jsx`, which parses as plain
|
|
30
|
+
* JavaScript with JSX, `addTypeImport`, `addComponentProp` and `addClassProperty`'s `scope`/
|
|
31
|
+
* `readonly` reject at call time because they write TypeScript syntax, leaving the file
|
|
32
|
+
* unchanged. The gate below runs SYNCHRONOUSLY, before any op is chained and before any run
|
|
33
|
+
* flush, so a rejected path throws on the bare `find()` call itself. `.ts` files are TypeScript,
|
|
34
|
+
* not this dialect — use `@pbuilder/sdk/typescript`. Every other extension, dotfile basename,
|
|
35
|
+
* trailing-dot basename, and extensionless path is rejected the same way —
|
|
36
|
+
* no normalization, always an explicit `.tsx` or `.jsx`, so neither extension is ever assumed.
|
|
37
|
+
* Every gate rejection throws via `dialectError`, so its message carries the standard
|
|
38
|
+
* `dialect operation failed: ` prefix.
|
|
39
|
+
*
|
|
40
|
+
* Trust boundary: a value handed to a structured mutation (e.g. `setJsxProp`'s `value`
|
|
41
|
+
* argument) is emitted verbatim into the output and becomes executable code — the SDK
|
|
42
|
+
* performs no validation, escaping, or sanitisation on it; the author is solely responsible
|
|
43
|
+
* for any untrusted input reaching that channel.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* import * as react from "@pbuilder/sdk/react";
|
|
47
|
+
*
|
|
48
|
+
* // src/Button.tsx before: const el = <Button />;
|
|
49
|
+
* export const run = async () => {
|
|
50
|
+
* await react
|
|
51
|
+
* .find("src/Button.tsx")
|
|
52
|
+
* .addImport("handleClick", "./handlers")
|
|
53
|
+
* .setJsxProp("Button", "onClick", "{handleClick}");
|
|
54
|
+
* };
|
|
55
|
+
* // -> import { handleClick } from "./handlers";
|
|
56
|
+
* // ->
|
|
57
|
+
* // -> const el = <Button onClick={handleClick} />;
|
|
58
|
+
*/
|
|
59
|
+
export function find(path) {
|
|
60
|
+
const base = basename(path);
|
|
61
|
+
// A non-empty stem that does not end in a dot: `.tsx` and `a..tsx` name no file of that type.
|
|
62
|
+
const routed = reactDialect.extensions.some((extension) => base.endsWith(extension) && base.length > extension.length && !base.endsWith(`.${extension}`));
|
|
63
|
+
if (routed) {
|
|
64
|
+
return reactDialect.find(path);
|
|
65
|
+
}
|
|
66
|
+
if (!base.includes(".")) {
|
|
67
|
+
throw dialectError("find(path) — the React dialect requires an explicit .tsx or .jsx extension; received a path with no extension. Append .tsx or .jsx to the path.");
|
|
68
|
+
}
|
|
69
|
+
if (base.endsWith(".ts")) {
|
|
70
|
+
throw dialectError("find(path) — .ts is not a React file; use @pbuilder/sdk/typescript for TypeScript sources.");
|
|
71
|
+
}
|
|
72
|
+
throw dialectError("find(path) — .tsx and .jsx are the only extensions the React dialect supports.");
|
|
73
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** `assertValidAttributeName`'s propName grammar — hyphens + one optional `:namespace` segment. */
|
|
2
|
+
export declare function assertValidAttributeName(propName: string): void;
|
|
3
|
+
/** `assertValidElementName`'s lookup-only JSX-name grammar — identifier/hyphenated, dot-joined. */
|
|
4
|
+
export declare function assertValidElementName(elementName: string, argName?: string): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The React dialect's JSX name grammars (ARCH-2, ADR-0071), built on the shared identifier
|
|
2
|
+
// checks. Verbatim from the shared contract (slices.md rev 2, "Name grammars + denylist"):
|
|
3
|
+
// - attribute name: letters/digits/underscore/hyphen, one optional `:namespace` segment.
|
|
4
|
+
// - element name (lookup-only, never spliced): identifier-or-hyphenated segments, dot-joined
|
|
5
|
+
// (admits `Button`, `Menu.Item`, `my-web-component`).
|
|
6
|
+
import { assertGrammar, assertNotDenylisted } from "../../../../domain/services/identifier-names.js";
|
|
7
|
+
const ATTRIBUTE_NAME_GRAMMAR = /^[A-Za-z_][A-Za-z0-9_-]*(:[A-Za-z_][A-Za-z0-9_-]*)?$/;
|
|
8
|
+
const ELEMENT_NAME_GRAMMAR = /^[A-Za-z_][A-Za-z0-9_-]*(\.[A-Za-z_][A-Za-z0-9_-]*)*$/;
|
|
9
|
+
/** `assertValidAttributeName`'s propName grammar — hyphens + one optional `:namespace` segment. */
|
|
10
|
+
export function assertValidAttributeName(propName) {
|
|
11
|
+
assertGrammar("propName", propName, ATTRIBUTE_NAME_GRAMMAR, "match the attribute-name grammar (letters, digits, underscore, and hyphen, with one optional `:namespace` segment)");
|
|
12
|
+
assertNotDenylisted("propName", propName);
|
|
13
|
+
}
|
|
14
|
+
/** `assertValidElementName`'s lookup-only JSX-name grammar — identifier/hyphenated, dot-joined. */
|
|
15
|
+
export function assertValidElementName(elementName, argName = "elementName") {
|
|
16
|
+
assertGrammar(argName, elementName, ELEMENT_NAME_GRAMMAR, "match the JSX element-name grammar (identifier or hyphenated segments, optionally joined by `.`)");
|
|
17
|
+
assertNotDenylisted(argName, elementName);
|
|
18
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** A JSX op's zero-match reject tail (REQ-RXD-04.4) — names the missing element, bounded. */
|
|
2
|
+
export declare function zeroMatchTail(elementName: string, propNames?: readonly string[]): string;
|
|
3
|
+
/** A JSX op's multi-match reject tail (REQ-RXD-04.5) — names the element + count, bounded. */
|
|
4
|
+
export declare function multiMatchTail(opName: string, elementName: string, matchCount: number, propNames?: readonly string[]): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// The React dialect's match-count reject tails (REQ-RXD-04), built on the shared echo bound
|
|
2
|
+
// (ARCH-2, ADR-0071).
|
|
3
|
+
import { elementNameEcho } from "../../../../domain/services/reject-tail.js";
|
|
4
|
+
// ARCH-3 (council; corrected V8 — judgment-day Round 2, Judge B): `setJsxProp`'s match-count
|
|
5
|
+
// rejects (REQ-RXD-04) echo a POST-VALIDATION argument value (`elementName`) rather than
|
|
6
|
+
// refusing to — deliberate UX (naming which element wasn't found / matched), sanctioned by
|
|
7
|
+
// design §4.4. `elementName` is grammar-constrained (no quotes, no newlines — never an
|
|
8
|
+
// injection vector), but the grammar has no LENGTH ceiling, so the echo routes through
|
|
9
|
+
// `elementNameEcho` (reject-tail.ts's wide, marked 100-char bound) — NOT `boundedFragment`'s 16-char
|
|
10
|
+
// hostile-value cap — keeping every react reject message bounded without mangling ordinary
|
|
11
|
+
// names.
|
|
12
|
+
// Target prop NAMES are grammar-validated like `elementName`; their values are never echoed.
|
|
13
|
+
function withProps(propNames) {
|
|
14
|
+
return propNames.length === 0 ? "" : ` with props ${propNames.map((name) => `\`${elementNameEcho(name)}\``).join(", ")}`;
|
|
15
|
+
}
|
|
16
|
+
/** A JSX op's zero-match reject tail (REQ-RXD-04.4) — names the missing element, bounded. */
|
|
17
|
+
export function zeroMatchTail(elementName, propNames = []) {
|
|
18
|
+
return (`no element named \`${elementNameEcho(elementName)}\`${withProps(propNames)} was found — use \`.modify()\` to inspect ` +
|
|
19
|
+
"the file and edit it directly.");
|
|
20
|
+
}
|
|
21
|
+
/** A JSX op's multi-match reject tail (REQ-RXD-04.5) — names the element + count, bounded. */
|
|
22
|
+
export function multiMatchTail(opName, elementName, matchCount, propNames = []) {
|
|
23
|
+
return (`\`${elementNameEcho(elementName)}\`${withProps(propNames)} matched ${matchCount} elements — ${opName} requires ` +
|
|
24
|
+
"exactly one match; use `.modify()` to disambiguate.");
|
|
25
|
+
}
|
package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.js
RENAMED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
// contract, REQ-RXD-11/12 verbatim: it is emitted AS-IS, malformed or not, and becomes
|
|
5
5
|
// executable code the author is solely responsible for).
|
|
6
6
|
import { Node, SyntaxKind, } from "ts-morph";
|
|
7
|
-
import { dialectError } from "
|
|
8
|
-
import {
|
|
9
|
-
import { elementNameEcho
|
|
7
|
+
import { dialectError } from "../../../../domain/valueobjects/dialect-error.js";
|
|
8
|
+
import { assertValidImportBinding, validatedOp } from "../../../../domain/services/identifier-names.js";
|
|
9
|
+
import { elementNameEcho } from "../../../../domain/services/reject-tail.js";
|
|
10
|
+
import { assertValidAttributeName, assertValidElementName } from "./jsx-names.js";
|
|
11
|
+
import { multiMatchTail, zeroMatchTail } from "./match-tails.js";
|
|
10
12
|
import { parse } from "./ast.js";
|
|
11
13
|
function targetParts(target) {
|
|
12
14
|
if (typeof target === "string")
|
|
@@ -18,6 +18,8 @@ export type ArrayElement = string | {
|
|
|
18
18
|
};
|
|
19
19
|
export declare function appendEntry(ast: SourceFile, list: Node, entries: Node[], item: string, empty: string): void;
|
|
20
20
|
export declare function tokensOf(node: Node): string[];
|
|
21
|
+
export declare function sameTokens(a: string[], b: string[]): boolean;
|
|
22
|
+
export declare function declarationTokens(node: Node): string[];
|
|
21
23
|
/** True when `node` and the validated `element` are the same code, compared token by token. */
|
|
22
24
|
export declare function isSameElement(node: Node, element: unknown): boolean;
|
|
23
25
|
export declare function unwrap(node: Expression): Expression;
|
|
@@ -32,8 +34,11 @@ export declare function unwrap(node: Expression): Expression;
|
|
|
32
34
|
* author-trusted, like `addFunction`'s `source`.
|
|
33
35
|
*/
|
|
34
36
|
export declare function addArrayElement(ast: SourceFile, locator: ArrayLocator, element: ArrayElement): void;
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
+
/**
|
|
38
|
+
* The validated source text of `element`, parsed as code of the file `ast` belongs to; rejects
|
|
39
|
+
* like `addArrayElement` does.
|
|
40
|
+
*/
|
|
41
|
+
export declare function elementText(element: unknown, ast?: SourceFile): string;
|
|
37
42
|
/**
|
|
38
43
|
* `addArrayElement` for a dialect that builds `locator` itself: `label` heads the reject
|
|
39
44
|
* tail in place of `addArrayElement(<locator>)`.
|