@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.
Files changed (207) hide show
  1. package/README.md +57 -42
  2. package/dist/{transport → acl/irwire}/frame-reader.d.ts +2 -0
  3. package/dist/{transport → acl/irwire}/frame-reader.js +57 -5
  4. package/dist/{transport → acl/irwire}/stdio-engine-client.d.ts +2 -2
  5. package/dist/{transport → acl/irwire}/stdio-engine-client.js +4 -4
  6. package/dist/bin/pbuilder-codegen.js +30 -35
  7. package/dist/bin/pbuilder-runner.js +6 -6
  8. package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +106 -0
  9. package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +202 -0
  10. package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.d.ts +2 -2
  11. package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.d.ts +12 -9
  12. package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.js +59 -120
  13. package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.d.ts +5 -0
  14. package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.js +15 -0
  15. package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.d.ts +51 -0
  16. package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.js +105 -0
  17. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.d.ts +2 -1
  18. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.js +13 -7
  19. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.d.ts +1 -1
  20. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.js +7 -6
  21. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.d.ts +11 -10
  22. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.js +21 -48
  23. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.d.ts +2 -3
  24. package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.js +37 -56
  25. package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.d.ts +2 -2
  26. package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.js +1 -1
  27. package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.d.ts +1 -1
  28. package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.js +10 -10
  29. package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.d.ts +1 -1
  30. package/dist/bounded-contexts/authoring/domain/ports/package-files.d.ts +53 -0
  31. package/dist/bounded-contexts/authoring/domain/ports/package-files.js +11 -0
  32. package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.d.ts +2 -2
  33. package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.js +3 -3
  34. package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.d.ts +2 -2
  35. package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.js +37 -12
  36. package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.d.ts +7 -5
  37. package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.js +28 -8
  38. package/dist/{core/jsx-name-validator.d.ts → bounded-contexts/authoring/domain/services/identifier-names.d.ts} +8 -4
  39. package/dist/{core/jsx-name-validator.js → bounded-contexts/authoring/domain/services/identifier-names.js} +21 -28
  40. package/dist/bounded-contexts/authoring/domain/services/reject-tail.d.ts +9 -0
  41. package/dist/bounded-contexts/authoring/domain/services/reject-tail.js +30 -0
  42. package/dist/bounded-contexts/authoring/domain/services/run-context.d.ts +5 -0
  43. package/dist/bounded-contexts/authoring/domain/services/run-context.js +70 -0
  44. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.d.ts +1 -1
  45. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.js +1 -1
  46. package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.d.ts +2 -0
  47. package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.js +6 -0
  48. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.d.ts +2 -1
  49. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.js +13 -2
  50. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.d.ts +1 -1
  51. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.js +2 -14
  52. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.d.ts +4 -3
  53. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.js +8 -4
  54. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.d.ts +1 -1
  55. package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.js +1 -1
  56. package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.js +1 -1
  57. package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/wire.d.ts +0 -3
  58. package/dist/bounded-contexts/authoring/domain/valueobjects/wire.js +28 -0
  59. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +27 -0
  60. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +306 -0
  61. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +7 -0
  62. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +68 -0
  63. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +19 -0
  64. package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +131 -0
  65. package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +182 -0
  66. package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +94 -0
  67. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +63 -0
  68. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +68 -0
  69. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.js +9 -9
  70. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +40 -0
  71. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +38 -0
  72. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.js +2 -2
  73. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +55 -0
  74. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +54 -0
  75. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.d.ts +1 -1
  76. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.js +35 -8
  77. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +43 -0
  78. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +46 -0
  79. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.js +7 -7
  80. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +52 -0
  81. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +73 -0
  82. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.d.ts +4 -0
  83. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.js +18 -0
  84. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.d.ts +4 -0
  85. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.js +25 -0
  86. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.js +5 -3
  87. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.d.ts +7 -2
  88. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.js +29 -15
  89. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.d.ts +5 -1
  90. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.js +22 -4
  91. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.js +14 -19
  92. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +53 -0
  93. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +37 -0
  94. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.d.ts +6 -1
  95. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.js +90 -54
  96. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +69 -0
  97. package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +70 -0
  98. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.d.ts +1 -1
  99. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.js +2 -2
  100. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.js +1 -1
  101. package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.js +2 -2
  102. package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.d.ts +8 -0
  103. package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.js +133 -0
  104. package/dist/bounded-contexts/authoring/testing/conformance/index.d.ts +157 -0
  105. package/dist/bounded-contexts/authoring/testing/conformance/index.js +261 -0
  106. package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.d.ts +2 -2
  107. package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.js +4 -3
  108. package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +89 -0
  109. package/dist/bounded-contexts/authoring/testing/harness/index.js +85 -0
  110. package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.d.ts +1 -1
  111. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.js +2 -2
  112. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.js +5 -4
  113. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.js +1 -1
  114. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.d.ts +4 -0
  115. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.js +49 -23
  116. package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.js +1 -1
  117. package/dist/commons/index.d.ts +1 -278
  118. package/dist/commons/index.js +1 -286
  119. package/dist/conformance/index.d.ts +1 -157
  120. package/dist/conformance/index.js +1 -261
  121. package/dist/dialects/angular/index.d.ts +1 -63
  122. package/dist/dialects/angular/index.js +1 -68
  123. package/dist/dialects/css/index.d.ts +1 -40
  124. package/dist/dialects/css/index.js +1 -38
  125. package/dist/dialects/json/index.d.ts +1 -55
  126. package/dist/dialects/json/index.js +1 -54
  127. package/dist/dialects/nestjs/index.d.ts +1 -43
  128. package/dist/dialects/nestjs/index.js +1 -46
  129. package/dist/dialects/react/index.d.ts +1 -52
  130. package/dist/dialects/react/index.js +1 -73
  131. package/dist/dialects/typescript/index.d.ts +1 -53
  132. package/dist/dialects/typescript/index.js +1 -37
  133. package/dist/dialects/yaml/index.d.ts +1 -69
  134. package/dist/dialects/yaml/index.js +1 -70
  135. package/dist/{core → platform}/deep-equal.js +2 -2
  136. package/dist/{transport → platform}/error-text.js +2 -2
  137. package/dist/runner-manifest.json +66 -46
  138. package/dist/shared-kernel/batch-cap.d.ts +4 -0
  139. package/dist/{core/wire.js → shared-kernel/batch-cap.js} +9 -26
  140. package/dist/{transport → shared-kernel}/framing.js +2 -2
  141. package/dist/{transport → shared-kernel}/wire-protocol.js +1 -1
  142. package/dist/testing/index.d.ts +1 -84
  143. package/dist/testing/index.js +1 -82
  144. package/package.json +9 -3
  145. package/dist/core/index.d.ts +0 -10
  146. package/dist/core/index.js +0 -6
  147. package/dist/core/reject-tail.d.ts +0 -13
  148. package/dist/core/reject-tail.js +0 -52
  149. package/dist/core/schema/schema-discovery.d.ts +0 -13
  150. package/dist/core/schema/schema-discovery.js +0 -51
  151. package/dist/scaffold/classify-transport.d.ts +0 -54
  152. package/dist/scaffold/classify-transport.js +0 -119
  153. /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.d.ts +0 -0
  154. /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.js +0 -0
  155. /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.js +0 -0
  156. /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.d.ts +0 -0
  157. /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.js +0 -0
  158. /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.d.ts +0 -0
  159. /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.js +0 -0
  160. /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.d.ts +0 -0
  161. /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.js +0 -0
  162. /package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.js +0 -0
  163. /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.d.ts +0 -0
  164. /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.js +0 -0
  165. /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.d.ts +0 -0
  166. /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.js +0 -0
  167. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.d.ts +0 -0
  168. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.d.ts +0 -0
  169. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.js +0 -0
  170. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.d.ts +0 -0
  171. /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.js +0 -0
  172. /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.d.ts +0 -0
  173. /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.js +0 -0
  174. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.d.ts +0 -0
  175. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.d.ts +0 -0
  176. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.js +0 -0
  177. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.d.ts +0 -0
  178. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.d.ts +0 -0
  179. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.js +0 -0
  180. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.d.ts +0 -0
  181. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.d.ts +0 -0
  182. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.js +0 -0
  183. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.d.ts +0 -0
  184. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.d.ts +0 -0
  185. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.d.ts +0 -0
  186. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.js +0 -0
  187. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.d.ts +0 -0
  188. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.js +0 -0
  189. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.d.ts +0 -0
  190. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.js +0 -0
  191. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.d.ts +0 -0
  192. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.js +0 -0
  193. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.d.ts +0 -0
  194. /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.d.ts +0 -0
  195. /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.d.ts +0 -0
  196. /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.js +0 -0
  197. /package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.js +0 -0
  198. /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.d.ts +0 -0
  199. /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.d.ts +0 -0
  200. /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.d.ts +0 -0
  201. /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.d.ts +0 -0
  202. /package/dist/{core → platform}/deep-equal.d.ts +0 -0
  203. /package/dist/{transport → platform}/error-text.d.ts +0 -0
  204. /package/dist/{core → platform}/fs-errors.d.ts +0 -0
  205. /package/dist/{core → platform}/fs-errors.js +0 -0
  206. /package/dist/{transport → shared-kernel}/framing.d.ts +0 -0
  207. /package/dist/{transport → shared-kernel}/wire-protocol.d.ts +0 -0
@@ -0,0 +1,131 @@
1
+ import { lstatSync, statSync, readFileSync, realpathSync } from "node:fs";
2
+ import { dirname, join, resolve } from "node:path";
3
+ import { isErrnoException } from "../../../../../platform/fs-errors.js";
4
+ import { isPlainObject } from "../../../domain/valueobjects/schema-model.js";
5
+ function readObject(path) {
6
+ // Static nonregular inputs must not reach a blocking JSON read.
7
+ if (!statSync(path).isFile())
8
+ throw new Error("nonregular input");
9
+ const value = JSON.parse(readFileSync(path, "utf8").replace(/^\uFEFF/, ""));
10
+ if (!isPlainObject(value))
11
+ throw new Error("invalid object");
12
+ return value;
13
+ }
14
+ export function discoverProject(directory) {
15
+ let selected = resolve(directory ?? process.cwd());
16
+ if (directory === undefined) {
17
+ for (;;) {
18
+ try {
19
+ lstatSync(join(selected, "project-builder.json"));
20
+ break;
21
+ }
22
+ catch (error) {
23
+ if (!isErrnoException(error) || error.code !== "ENOENT") {
24
+ return { ok: false, diagnostic: `cannot load project configuration at ${JSON.stringify(selected)}` };
25
+ }
26
+ }
27
+ const parent = dirname(selected);
28
+ if (parent === selected)
29
+ return { ok: false, diagnostic: "project-builder.json not found" };
30
+ selected = parent;
31
+ }
32
+ }
33
+ let root;
34
+ let collections;
35
+ try {
36
+ root = realpathSync(selected);
37
+ const config = readObject(join(root, "project-builder.json"));
38
+ const value = Object.hasOwn(config, "collections") ? config.collections : {};
39
+ if (!isPlainObject(value))
40
+ throw new Error("invalid collections");
41
+ collections = value;
42
+ }
43
+ catch {
44
+ return { ok: false, diagnostic: `cannot load project configuration at ${JSON.stringify(selected)}` };
45
+ }
46
+ const entries = [];
47
+ for (const name of Object.keys(collections).sort()) {
48
+ const collection = collections[name];
49
+ if (!isPlainObject(collection)) {
50
+ entries.push({ kind: "failure", label: name, diagnostic: "collection must be an object" });
51
+ continue;
52
+ }
53
+ if (typeof collection.path === "string") {
54
+ let manifest;
55
+ const path = resolve(root, collection.path);
56
+ try {
57
+ const value = readObject(path);
58
+ const schematics = Object.hasOwn(value, "schematics") ? value.schematics : {};
59
+ if (!isPlainObject(schematics))
60
+ throw new Error("invalid schematics");
61
+ manifest = schematics;
62
+ }
63
+ catch {
64
+ entries.push({ kind: "failure", label: name, diagnostic: `cannot load collection manifest ${JSON.stringify(path)}` });
65
+ continue;
66
+ }
67
+ for (const key of Object.keys(manifest).sort()) {
68
+ const label = `${name}/${key}`;
69
+ const registration = manifest[key];
70
+ const pointer = isPlainObject(registration) ? registration.factory : undefined;
71
+ const split = typeof pointer === "string" ? pointer.lastIndexOf("#") : -1;
72
+ if (typeof pointer !== "string" || split <= 0 || !/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(pointer.slice(split + 1))) {
73
+ entries.push({ kind: "failure", label, diagnostic: "factory must name a module and explicit export (module#export)" });
74
+ continue;
75
+ }
76
+ const module = resolve(dirname(path), pointer.slice(0, split));
77
+ try {
78
+ if (!statSync(module).isFile())
79
+ throw new Error("nonregular module");
80
+ entries.push({ kind: "target", label, directory: dirname(realpathSync(module)) });
81
+ }
82
+ catch {
83
+ entries.push({ kind: "failure", label, diagnostic: `cannot resolve factory module ${JSON.stringify(module)}` });
84
+ }
85
+ }
86
+ continue;
87
+ }
88
+ const inline = Object.hasOwn(collection, "schematics") ? collection.schematics : {};
89
+ if (!isPlainObject(inline)) {
90
+ entries.push({ kind: "failure", label: name, diagnostic: "inline schematics must be an object" });
91
+ continue;
92
+ }
93
+ const directKeys = Object.keys(collection).filter((key) => key !== "schematics");
94
+ for (const key of [...new Set([...directKeys, ...Object.keys(inline)])].sort()) {
95
+ const label = `${name}/${key}`;
96
+ if (Object.hasOwn(inline, key)) {
97
+ entries.push({ kind: "failure", label, diagnostic: Object.hasOwn(collection, key) ? "ambiguous direct and inline registration" : "inline inputs have no file target" });
98
+ continue;
99
+ }
100
+ const registration = collection[key];
101
+ if (!isPlainObject(registration) || typeof registration.path !== "string" || registration.path.length === 0) {
102
+ entries.push({ kind: "failure", label, diagnostic: "schematic must name a directory path" });
103
+ continue;
104
+ }
105
+ const path = resolve(root, registration.path);
106
+ try {
107
+ if (!statSync(path).isDirectory())
108
+ throw new Error("not a directory");
109
+ let factories = 0;
110
+ for (const leaf of ["factory.ts", "factory.js"]) {
111
+ try {
112
+ if (!statSync(join(path, leaf)).isFile())
113
+ throw new Error("nonregular factory");
114
+ factories++;
115
+ }
116
+ catch (error) {
117
+ if (!isErrnoException(error) || error.code !== "ENOENT")
118
+ throw error;
119
+ }
120
+ }
121
+ if (factories !== 1)
122
+ throw new Error("ambiguous or missing factory");
123
+ entries.push({ kind: "target", label, directory: realpathSync(path) });
124
+ }
125
+ catch {
126
+ entries.push({ kind: "failure", label, diagnostic: `directory requires exactly one regular factory.ts or factory.js: ${JSON.stringify(path)}` });
127
+ }
128
+ }
129
+ }
130
+ return { ok: true, root, entries };
131
+ }
@@ -0,0 +1,182 @@
1
+ import type { JsonValue } from "../../../domain/valueobjects/wire.ts";
2
+ import type { FoundHandle, WritableHandle } from "../../../domain/entities/handle-state.ts";
3
+ import { AuthoringError } from "../../../domain/valueobjects/authoring-error.ts";
4
+ import type { AuthoringVerb, AuthoringReason, AuthoringOrigin } from "../../../domain/valueobjects/authoring-error.ts";
5
+ import type { ScaffoldArgs } from "../../../application/usecases/scaffold/index.ts";
6
+ export type { FoundHandle, WritableHandle };
7
+ export { AuthoringError };
8
+ export type { AuthoringVerb, AuthoringReason, AuthoringOrigin };
9
+ export { classifyContent } from "../../../domain/services/classify-content.ts";
10
+ export type { ContentState } from "../../../domain/services/classify-content.ts";
11
+ export { find, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.ts";
12
+ /**
13
+ * Options for the `create` author verb.
14
+ *
15
+ * @example
16
+ * const opts: CreateOptions = {
17
+ * template: "export const {= .name =} = '{= .value =}';",
18
+ * options: { name: "greeting", value: "hello" },
19
+ * };
20
+ */
21
+ export interface CreateOptions {
22
+ template: string;
23
+ options: JsonValue;
24
+ force?: boolean;
25
+ }
26
+ /**
27
+ * Options for the `create({ templateFile })` render request — an explicit, package-local
28
+ * alternative to an inline `template` string (REQ-FEH-01). `templateFile` is a
29
+ * package-relative path (resolved against the active Session's `packageDir`), read at
30
+ * emission time; its content becomes the `create` directive's `template` field —
31
+ * the existing `create` IR, zero wire change. `templateFile` REQUESTS a render: a binary
32
+ * or oversized source fails loud (`invalid-input`), it never silently falls back to a
33
+ * by-reference copy (REQ-FEH-02).
34
+ *
35
+ * @example
36
+ * const opts: CreateFromTemplateFileOptions = {
37
+ * templateFile: "tpl.ts.template",
38
+ * options: { name: "greeting" },
39
+ * };
40
+ */
41
+ export interface CreateFromTemplateFileOptions {
42
+ templateFile: string;
43
+ options: JsonValue;
44
+ force?: boolean;
45
+ }
46
+ /**
47
+ * Schedules a file-creation directive and returns a `WritableHandle` for chaining.
48
+ * The file is written when the session flushes — on the next `read()` call (REQ-KIT-02)
49
+ * or at run end (REQ-KIT-05). A factory that never calls `read()` still emits all
50
+ * buffered directives when the runner resolves.
51
+ *
52
+ * SEAM-01 (REQ-01): a generic type parameter `S` narrows `options` from the bare
53
+ * `JsonValue` to the schema's keys at the type level only — the runtime body is unchanged.
54
+ *
55
+ * Creating over an existing file is rejected at the engine seam unless
56
+ * `{ force: true }` is passed (overwrite-on-collision, ADR-0017 fail-closed) — a
57
+ * rejected Session throws `AuthoringError`.
58
+ *
59
+ * `templateFile` is a THIRD overload (REQ-FEH-01): pass a package-local path instead of an
60
+ * inline `template` string — its content is read at emission time and becomes the
61
+ * directive's `template` field. `template` and `templateFile` are mutually exclusive forms;
62
+ * only usable inside a factory invocation started with packageDir (there is no resolution anchor
63
+ * to read a package-local file against otherwise — `invalid-input`, never a cwd fallback).
64
+ * `templateFile`'s VALUE is a literal package-relative path, read verbatim by CONTENT —
65
+ * it is NOT run through `scaffold`'s filename pipeline (no rename remap, no `__x__` token
66
+ * translation, no `.template`-suffix strip applied to the path itself); this is an
67
+ * explicit REQUEST to render one named file, unlike `scaffold`'s per-entry filename
68
+ * processing. Because `templateFile` REQUESTS a render, it has no silent by-reference
69
+ * fallback (REQ-FEH-02): a binary file (a null byte or invalid UTF-8 anywhere in the
70
+ * whole file) or a file too large to render inline (over the 4 MiB limit) both reject
71
+ * fail-loud with reason `invalid-input` — never a silent copy.
72
+ *
73
+ * @example
74
+ * create("src/index.ts", {
75
+ * template: "export const version = '{= .version =}';",
76
+ * options: { version: "1.0.0" },
77
+ * });
78
+ * @example
79
+ * create("src/index.ts", {
80
+ * templateFile: "index.ts.template",
81
+ * options: { version: "1.0.0" },
82
+ * });
83
+ */
84
+ export declare function create<S>(path: string, opts: {
85
+ template: string;
86
+ options: {
87
+ [K in keyof S]: S[K];
88
+ };
89
+ force?: boolean;
90
+ }): WritableHandle;
91
+ export declare function create(path: string, opts: CreateOptions): WritableHandle;
92
+ export declare function create(path: string, opts: CreateFromTemplateFileOptions): WritableHandle;
93
+ /**
94
+ * Author-facing options for the `scaffold` verb — walks a package-local folder and mirrors
95
+ * it into the target tree. `from`/`to` are mandatory. `options` defaults `{}`, `include`
96
+ * defaults to matching everything, `exclude` defaults to matching nothing (`exclude` wins
97
+ * on overlap), `rename` defaults to no remap, `force` defaults `false`.
98
+ *
99
+ * @example
100
+ * const opts: ScaffoldOptions = {
101
+ * from: "files",
102
+ * to: "src/generated",
103
+ * options: { name: "Widget" },
104
+ * exclude: ["*.spec.ts"],
105
+ * };
106
+ */
107
+ export type ScaffoldOptions = ScaffoldArgs;
108
+ /**
109
+ * Walks a package-local folder (`from`, resolved against the active Session's `packageDir`)
110
+ * and mirrors every entry into `to`, applying the rename → filename-token-translation →
111
+ * `.template`-strip pipeline (REQ-FSC-05) and include/exclude glob filtering (REQ-FSC-03,
112
+ * `exclude` wins on overlap). A source matching one of the `binary` globs (against the same
113
+ * original path) is copied byte for byte (`copyIn`); every other source renders through a
114
+ * `create` directive. A source that cannot render rejects naming it, never falling back to a
115
+ * copy: one that is not valid UTF-8 text (with a `binary: [...]` suggestion), one too large
116
+ * for one emit frame (naming its size), or one both `.template`-marked and declared binary. A `from` folder with zero entries
117
+ * no-ops silently; `include`/`exclude` eliminating every entry rejects fail-loud, naming
118
+ * the filters (REQ-FSC-04 — two distinct outcomes, never collapsed). `force` (default
119
+ * `false`) passes through unchanged to every emitted directive, no per-file override
120
+ * (REQ-FSC-06). Two or more sources collapsing to the same destination reject fail-loud,
121
+ * naming every offending source (REQ-FSC-08). Only usable inside a
122
+ * factory invocation started with packageDir — there is no resolution anchor to walk a
123
+ * package-local folder against otherwise (`invalid-input`, never a cwd fallback).
124
+ *
125
+ * `rename` is a static REMAP TABLE (`Record<originalSourceRelativePath,
126
+ * newDestinationRelativePath>`), matched against the ORIGINAL (pre-token-translation)
127
+ * source path — distinct from the `rename()` verb, which renames one already-targeted
128
+ * file's basename at emit time, not a folder-walk's per-entry destination.
129
+ *
130
+ * A NESTED symlinked directory is never descended, regardless of where its target
131
+ * resolves — skipped silently, no error; enumeration determinism and cycle-safety are the
132
+ * rationale (a symlinked directory could point anywhere, including into a cycle — never
133
+ * descending is the simplest invariant that is safe under all targets, REQ-FSC-09). The
134
+ * walk ROOT (`from` itself) is held to a stricter standard: a symlinked root REJECTS
135
+ * (`invalid-input`) rather than being followed or silently skipped (owner ruling 16) — but
136
+ * this check inspects only `from`'s FINAL path component; a symlink at a MID-path segment
137
+ * (e.g. `from: "link/sub"`) is not detected and the walk proceeds through it, the same
138
+ * documented residual SECURITY.md covers for `create`/`copyIn` reads. The walk is capped
139
+ * at 10,000 enumerated entries per call, failing loud and naming the bound past that
140
+ * (REQ-FSC-09) — a loop-safety/DoS resource guard no real schematic collection should
141
+ * approach.
142
+ *
143
+ * **Packaging caveat**: the empty-folder no-op (above) depends on `from` existing ON
144
+ * DISK at run time — npm tarball packaging commonly DROPS empty directories, so an
145
+ * empty `from` folder that relies on this no-op may not survive `npm publish` at all
146
+ * (REQ-FSC-04). Ship at least a placeholder file if the folder's presence matters.
147
+ *
148
+ * Returns `void` (REQ-FSC-07) — fire-and-forget, no chainable handle group.
149
+ *
150
+ * @example
151
+ * scaffold({ from: "files", to: "src/generated", options: { name: "Widget" } });
152
+ */
153
+ export declare function scaffold(args: ScaffoldOptions): void;
154
+ /**
155
+ * Emits a by-reference copy of ONE package-local file (`from`, resolved against the active
156
+ * run's `packageDir`) to `to` — ALWAYS by-reference, NEVER classified or rendered
157
+ * (REQ-FEH-03), regardless of the source's own text-vs-binary shape: a text asset
158
+ * containing `{= =}`-like sequences (that `scaffold` would otherwise render as tokens)
159
+ * travels verbatim — the documented escape from `scaffold`'s by-value classification
160
+ * (`content-classification` REQ-CCL-04). Contrast with tree→tree `copy`: `copyIn`'s source
161
+ * is a PACKAGE-LOCAL path read at emission time, not an existing tree entry.
162
+ *
163
+ * `from`/`to` are mandatory; `force` defaults `false`. A missing `from`/`to` rejects
164
+ * fail-loud before any emission (REQ-FEH-04.1/.2). Collision without `force` rejects;
165
+ * `force: true` overwrites (`by-reference-copy-wire` REQ-BRC-05). Only usable inside a
166
+ * factory invocation started with packageDir — there is no resolution anchor to read a
167
+ * package-local file against otherwise (`invalid-input`, never a cwd fallback).
168
+ *
169
+ * Returns `void` (REQ-FEH-04.3) — NOT a `WritableHandle`, unlike `copy`: a by-reference
170
+ * destination's bytes exist only after the ENGINE applies the directive (the fake never
171
+ * materializes them, `author-test-harness` REQ-ATH-15) — a handle chaining over tree
172
+ * CONTENT would lie about content that was never staged. This asymmetry with `copy`
173
+ * (which DOES stage tree→tree content the fake can chain over) is deliberate.
174
+ *
175
+ * @example
176
+ * copyIn("assets/logo.svg", "src/generated/logo.svg");
177
+ */
178
+ export declare function copyIn(from: string, to: string, opts?: {
179
+ force?: boolean;
180
+ }): void;
181
+ import type { PendingDirective } from "../../../application/usecases/pending-directives/render.ts";
182
+ export type { PendingDirective };
@@ -0,0 +1,94 @@
1
+ // Author surface: positional + trailing options, frozen public API (KIT-03/SKEL-01/KIT-04).
2
+ // No AST imports. All handle write-ops wired (S-003).
3
+ import * as verbs from "../../../application/usecases/authoring-verbs/index.js";
4
+ import { AuthoringError } from "../../../domain/valueobjects/authoring-error.js";
5
+ import { readTemplateFile, runScaffold, runCopyIn } from "../../../application/usecases/scaffold/index.js";
6
+ // ADR-0023: AuthoringError (+ its supporting types) is an author-facing DATA type, not
7
+ // kit MACHINERY (the port, the session, the directive factory stay unexported) — it
8
+ // legitimately crosses the ADR-0009 boundary via the same two-step pattern
9
+ // FoundHandle/WritableHandle already use.
10
+ export { AuthoringError };
11
+ // 2.3 (CQ-1, droppable): classifyContent + ContentState give authors a named,
12
+ // branchable read-result classification (see find()'s JSDoc in the authoring-verbs use case). Severable
13
+ // from the AuthoringError cluster above — no other component references it.
14
+ export { classifyContent } from "../../../domain/services/classify-content.js";
15
+ // The verbs that need no adapting are the use case's own functions.
16
+ export { find, replaceContent, remove, rename, move, copy, pendingDirectives } from "../../../application/usecases/authoring-verbs/index.js";
17
+ export function create(path, opts) {
18
+ return verbs.create(path, opts, (options) => "templateFile" in opts ? readTemplateFile(opts.templateFile, path, options, opts.force) : opts.template);
19
+ }
20
+ /**
21
+ * Walks a package-local folder (`from`, resolved against the active Session's `packageDir`)
22
+ * and mirrors every entry into `to`, applying the rename → filename-token-translation →
23
+ * `.template`-strip pipeline (REQ-FSC-05) and include/exclude glob filtering (REQ-FSC-03,
24
+ * `exclude` wins on overlap). A source matching one of the `binary` globs (against the same
25
+ * original path) is copied byte for byte (`copyIn`); every other source renders through a
26
+ * `create` directive. A source that cannot render rejects naming it, never falling back to a
27
+ * copy: one that is not valid UTF-8 text (with a `binary: [...]` suggestion), one too large
28
+ * for one emit frame (naming its size), or one both `.template`-marked and declared binary. A `from` folder with zero entries
29
+ * no-ops silently; `include`/`exclude` eliminating every entry rejects fail-loud, naming
30
+ * the filters (REQ-FSC-04 — two distinct outcomes, never collapsed). `force` (default
31
+ * `false`) passes through unchanged to every emitted directive, no per-file override
32
+ * (REQ-FSC-06). Two or more sources collapsing to the same destination reject fail-loud,
33
+ * naming every offending source (REQ-FSC-08). Only usable inside a
34
+ * factory invocation started with packageDir — there is no resolution anchor to walk a
35
+ * package-local folder against otherwise (`invalid-input`, never a cwd fallback).
36
+ *
37
+ * `rename` is a static REMAP TABLE (`Record<originalSourceRelativePath,
38
+ * newDestinationRelativePath>`), matched against the ORIGINAL (pre-token-translation)
39
+ * source path — distinct from the `rename()` verb, which renames one already-targeted
40
+ * file's basename at emit time, not a folder-walk's per-entry destination.
41
+ *
42
+ * A NESTED symlinked directory is never descended, regardless of where its target
43
+ * resolves — skipped silently, no error; enumeration determinism and cycle-safety are the
44
+ * rationale (a symlinked directory could point anywhere, including into a cycle — never
45
+ * descending is the simplest invariant that is safe under all targets, REQ-FSC-09). The
46
+ * walk ROOT (`from` itself) is held to a stricter standard: a symlinked root REJECTS
47
+ * (`invalid-input`) rather than being followed or silently skipped (owner ruling 16) — but
48
+ * this check inspects only `from`'s FINAL path component; a symlink at a MID-path segment
49
+ * (e.g. `from: "link/sub"`) is not detected and the walk proceeds through it, the same
50
+ * documented residual SECURITY.md covers for `create`/`copyIn` reads. The walk is capped
51
+ * at 10,000 enumerated entries per call, failing loud and naming the bound past that
52
+ * (REQ-FSC-09) — a loop-safety/DoS resource guard no real schematic collection should
53
+ * approach.
54
+ *
55
+ * **Packaging caveat**: the empty-folder no-op (above) depends on `from` existing ON
56
+ * DISK at run time — npm tarball packaging commonly DROPS empty directories, so an
57
+ * empty `from` folder that relies on this no-op may not survive `npm publish` at all
58
+ * (REQ-FSC-04). Ship at least a placeholder file if the folder's presence matters.
59
+ *
60
+ * Returns `void` (REQ-FSC-07) — fire-and-forget, no chainable handle group.
61
+ *
62
+ * @example
63
+ * scaffold({ from: "files", to: "src/generated", options: { name: "Widget" } });
64
+ */
65
+ export function scaffold(args) {
66
+ runScaffold(args);
67
+ }
68
+ /**
69
+ * Emits a by-reference copy of ONE package-local file (`from`, resolved against the active
70
+ * run's `packageDir`) to `to` — ALWAYS by-reference, NEVER classified or rendered
71
+ * (REQ-FEH-03), regardless of the source's own text-vs-binary shape: a text asset
72
+ * containing `{= =}`-like sequences (that `scaffold` would otherwise render as tokens)
73
+ * travels verbatim — the documented escape from `scaffold`'s by-value classification
74
+ * (`content-classification` REQ-CCL-04). Contrast with tree→tree `copy`: `copyIn`'s source
75
+ * is a PACKAGE-LOCAL path read at emission time, not an existing tree entry.
76
+ *
77
+ * `from`/`to` are mandatory; `force` defaults `false`. A missing `from`/`to` rejects
78
+ * fail-loud before any emission (REQ-FEH-04.1/.2). Collision without `force` rejects;
79
+ * `force: true` overwrites (`by-reference-copy-wire` REQ-BRC-05). Only usable inside a
80
+ * factory invocation started with packageDir — there is no resolution anchor to read a
81
+ * package-local file against otherwise (`invalid-input`, never a cwd fallback).
82
+ *
83
+ * Returns `void` (REQ-FEH-04.3) — NOT a `WritableHandle`, unlike `copy`: a by-reference
84
+ * destination's bytes exist only after the ENGINE applies the directive (the fake never
85
+ * materializes them, `author-test-harness` REQ-ATH-15) — a handle chaining over tree
86
+ * CONTENT would lie about content that was never staged. This asymmetry with `copy`
87
+ * (which DOES stage tree→tree content the fake can chain over) is deliberate.
88
+ *
89
+ * @example
90
+ * copyIn("assets/logo.svg", "src/generated/logo.svg");
91
+ */
92
+ export function copyIn(from, to, opts) {
93
+ runCopyIn({ from, to, force: opts?.force });
94
+ }
@@ -0,0 +1,63 @@
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 { ArrayElement } from "../typescript/array-element.ts";
5
+ import { type InjectionOptions, type InputOptions, type LazyRouteSpec, type NamedImport, type OutputOptions, type RouteSpec, type StateOptions } from "./ops.ts";
6
+ export * as astLibrary from "ts-morph";
7
+ export type { InjectionOptions, InputOptions, LazyRouteSpec, NamedImport, OutputOptions, RouteSpec, StateOptions };
8
+ type InsertOp = (ast: SourceFile, element: ArrayElement, imports?: readonly NamedImport[]) => void;
9
+ type AngularOps = {
10
+ addComponentImport: InsertOp;
11
+ addComponentProvider: InsertOp;
12
+ addRootProvider: InsertOp;
13
+ addRoute: (ast: SourceFile, route: RouteSpec) => void;
14
+ addLazyRoute: (ast: SourceFile, route: LazyRouteSpec) => void;
15
+ addInjection: (ast: SourceFile, name: string, token: ArrayElement, options?: InjectionOptions) => void;
16
+ addInput: (ast: SourceFile, name: string, options?: InputOptions) => void;
17
+ addModel: (ast: SourceFile, name: string, options?: InputOptions) => void;
18
+ addOutput: (ast: SourceFile, name: string, options?: OutputOptions) => void;
19
+ addSignal: (ast: SourceFile, name: string, initial: string, options?: StateOptions) => void;
20
+ addComputed: (ast: SourceFile, name: string, expression: string, options?: StateOptions) => void;
21
+ addNgModuleImport: InsertOp;
22
+ addDeclaration: InsertOp;
23
+ addNgModuleProvider: InsertOp;
24
+ addNgModuleExport: InsertOp;
25
+ addBootstrap: InsertOp;
26
+ };
27
+ /**
28
+ * Opens a `.ts` file of an Angular project for editing. The handle carries every
29
+ * `@pbuilder/sdk/typescript` op plus the Angular ops below, chained on one handle and written
30
+ * once.
31
+ *
32
+ * Each op takes `(element, imports?)`: `element` is an identifier, or `{ expression }` for
33
+ * code such as `provideHttpClient(withFetch())`, and `imports` lists the `{ name, from }`
34
+ * named imports that code needs, each added with `addImport`'s rules. An element already
35
+ * listed is a no-op.
36
+ *
37
+ * - `addComponentImport` / `addComponentProvider` append to `imports` / `providers` of the
38
+ * file's only `@Component`, creating the metadata object or the array when missing.
39
+ * - `addRootProvider` appends to the root `providers` of the file's only variable typed
40
+ * `ApplicationConfig`, or of the only `bootstrapApplication(...)` config object.
41
+ * - `addRoute({ path, component, from })` imports `component` and adds an eager route;
42
+ * `addLazyRoute({ path, loadComponent | loadChildren, export? })` adds a lazy one. Both go
43
+ * to the file's only variable typed `Routes` or `Route[]`, before a `**` route when there is
44
+ * one, since the first matching route wins. A different route with the same `path` rejects.
45
+ *
46
+ * They reject, leaving the file unchanged, when the target is missing, ambiguous, or not a
47
+ * literal. Use `.modify(fn)` for those files.
48
+ *
49
+ * @example
50
+ * import * as angular from "@pbuilder/sdk/angular";
51
+ *
52
+ * // src/app/app.config.ts before:
53
+ * // export const appConfig: ApplicationConfig = { providers: [provideRouter(routes)] };
54
+ * export const run = async () => {
55
+ * await angular.find("src/app/app.config.ts").addRootProvider({ expression: "provideHttpClient(withFetch())" }, [
56
+ * { name: "provideHttpClient", from: "@angular/common/http" },
57
+ * { name: "withFetch", from: "@angular/common/http" },
58
+ * ]);
59
+ * };
60
+ * // -> import { provideHttpClient, withFetch } from "@angular/common/http";
61
+ * // -> export const appConfig: ApplicationConfig = { providers: [provideRouter(routes), provideHttpClient(withFetch())] };
62
+ */
63
+ export declare function find(path: string): Handle<"found", SourceFile, AngularOps & typeof typescriptOps>;
@@ -0,0 +1,68 @@
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 { addBootstrap, addComponentImport, addComponentProvider, addComputed, addDeclaration, addInjection, addInput, addLazyRoute, addModel, addNgModuleExport, addNgModuleImport, addNgModuleProvider, addOutput, addRootProvider, addRoute, addSignal, } from "./ops.js";
5
+ export * as astLibrary from "ts-morph";
6
+ const angularOps = defineOpPack({
7
+ addComponentImport,
8
+ addComponentProvider,
9
+ addRootProvider,
10
+ addRoute,
11
+ addLazyRoute,
12
+ addInjection,
13
+ addInput,
14
+ addModel,
15
+ addOutput,
16
+ addSignal,
17
+ addComputed,
18
+ addNgModuleImport,
19
+ addDeclaration,
20
+ addNgModuleProvider,
21
+ addNgModuleExport,
22
+ addBootstrap,
23
+ });
24
+ const baseDialect = defineDialect({
25
+ extensions: [".ts"],
26
+ ast: { parse, print },
27
+ ops: {},
28
+ });
29
+ const angularDialect = withOps(baseDialect, typescriptOps, angularOps);
30
+ /**
31
+ * Opens a `.ts` file of an Angular project for editing. The handle carries every
32
+ * `@pbuilder/sdk/typescript` op plus the Angular ops below, chained on one handle and written
33
+ * once.
34
+ *
35
+ * Each op takes `(element, imports?)`: `element` is an identifier, or `{ expression }` for
36
+ * code such as `provideHttpClient(withFetch())`, and `imports` lists the `{ name, from }`
37
+ * named imports that code needs, each added with `addImport`'s rules. An element already
38
+ * listed is a no-op.
39
+ *
40
+ * - `addComponentImport` / `addComponentProvider` append to `imports` / `providers` of the
41
+ * file's only `@Component`, creating the metadata object or the array when missing.
42
+ * - `addRootProvider` appends to the root `providers` of the file's only variable typed
43
+ * `ApplicationConfig`, or of the only `bootstrapApplication(...)` config object.
44
+ * - `addRoute({ path, component, from })` imports `component` and adds an eager route;
45
+ * `addLazyRoute({ path, loadComponent | loadChildren, export? })` adds a lazy one. Both go
46
+ * to the file's only variable typed `Routes` or `Route[]`, before a `**` route when there is
47
+ * one, since the first matching route wins. A different route with the same `path` rejects.
48
+ *
49
+ * They reject, leaving the file unchanged, when the target is missing, ambiguous, or not a
50
+ * literal. Use `.modify(fn)` for those files.
51
+ *
52
+ * @example
53
+ * import * as angular from "@pbuilder/sdk/angular";
54
+ *
55
+ * // src/app/app.config.ts before:
56
+ * // export const appConfig: ApplicationConfig = { providers: [provideRouter(routes)] };
57
+ * export const run = async () => {
58
+ * await angular.find("src/app/app.config.ts").addRootProvider({ expression: "provideHttpClient(withFetch())" }, [
59
+ * { name: "provideHttpClient", from: "@angular/common/http" },
60
+ * { name: "withFetch", from: "@angular/common/http" },
61
+ * ]);
62
+ * };
63
+ * // -> import { provideHttpClient, withFetch } from "@angular/common/http";
64
+ * // -> export const appConfig: ApplicationConfig = { providers: [provideRouter(routes), provideHttpClient(withFetch())] };
65
+ */
66
+ export function find(path) {
67
+ return angularDialect.find(path);
68
+ }
@@ -1,12 +1,12 @@
1
1
  import { Node, SyntaxKind, } from "ts-morph";
2
- import { dialectError } from "../../core/dialect-error.js";
3
- import { handlePathFor } from "../../core/dialect-handle.js";
4
- import { assertValidImportBinding } from "../../core/jsx-name-validator.js";
5
- import { elementNameEcho } from "../../core/reject-tail.js";
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
+ import { elementNameEcho } from "../../../../domain/services/reject-tail.js";
6
6
  import { appendArrayElement, appendEntry, elementText, isSameElement, unwrap, } from "../typescript/array-element.js";
7
7
  import { parse } from "../typescript/ast.js";
8
8
  import { insertClassProperty } from "../typescript/class-property.js";
9
- import { addImport } from "../typescript/ops.js";
9
+ import { importBinding } from "../typescript/ops.js";
10
10
  const IMPORTS_SHAPE = "`imports` must be a list of { name, from } strings — fix the imports, or use `.modify()` to make this edit directly.";
11
11
  function assertImports(imports) {
12
12
  if (imports === undefined)
@@ -33,7 +33,7 @@ function insertOp(opName, locate) {
33
33
  };
34
34
  appendArrayElement(ast, locate(ast, fail), element, label);
35
35
  for (const { name, from } of imports ?? [])
36
- addImport(ast, name, from);
36
+ importBinding(ast, opName, name, from);
37
37
  };
38
38
  }
39
39
  // The declared type of a top-level variable: its annotation, or the type it `satisfies`.
@@ -188,7 +188,7 @@ export function addRoute(ast, route) {
188
188
  throw dialectError(ROUTE_SHAPE);
189
189
  assertValidImportBinding(route.component, "component");
190
190
  insertRoute(ast, "addRoute", route.path, `{ path: ${JSON.stringify(route.path)}, component: ${route.component} }`);
191
- addImport(ast, route.component, route.from);
191
+ importBinding(ast, "addRoute", route.component, route.from);
192
192
  }
193
193
  /**
194
194
  * Same placement and duplicate rules as `addRoute`, for a lazy route:
@@ -275,9 +275,9 @@ function addMember(ast, opName, name, decorators, property, imports) {
275
275
  };
276
276
  const cls = decoratedClass(ast, decorators, fail);
277
277
  insertClassProperty(ast, cls, { name, initializer: property.initializer, scope: property.scope, readonly: true }, fail);
278
- addImport(ast, property.core, "@angular/core");
278
+ importBinding(ast, opName, property.core, "@angular/core");
279
279
  for (const entry of imports ?? [])
280
- addImport(ast, entry.name, entry.from);
280
+ importBinding(ast, opName, entry.name, entry.from);
281
281
  }
282
282
  function signalInputOp(opName, fn) {
283
283
  return (ast, name, options) => {
@@ -0,0 +1,40 @@
1
+ import type { Root } from "postcss";
2
+ import { type Handle, type Query } from "../../../../domain/services/define-dialect.ts";
3
+ import { getDeclaration, type CssTarget, type DeclarationOptions } from "./ops.ts";
4
+ export * as astLibrary from "postcss";
5
+ export { getDeclaration };
6
+ export type { CssTarget, DeclarationOptions };
7
+ type CssOps = {
8
+ setDeclaration: (ast: Root, target: CssTarget, property: string, value: string, options?: DeclarationOptions) => void;
9
+ removeDeclaration: (ast: Root, target: CssTarget, property: string) => void;
10
+ getDeclaration: Query<Root, [target: CssTarget, property: string], ReturnType<typeof getDeclaration>>;
11
+ };
12
+ /**
13
+ * Opens a `.css` file to set and remove declarations. A target names one top-level block —
14
+ * `{ selector: ":root" }`, `{ atRule: "theme" }`, or `{ atRule: "media", params, selector }` —
15
+ * and every op edits only the declaration it addresses: comments, `@import`s, other rules,
16
+ * indentation, line endings, and a BOM survive. Any other extension throws synchronously with
17
+ * the `dialect operation failed: ` prefix. `.modify(fn)` hands `fn` the live PostCSS `Root`;
18
+ * use `astLibrary` (`postcss`) for anything the ops do not cover.
19
+ *
20
+ * @example
21
+ * import * as css from "@pbuilder/sdk/css";
22
+ *
23
+ * // tokens.css before: @import "tailwindcss";\n\n@theme {\n --color-primary: #0b254d;\n}\n
24
+ * export const run = async () => {
25
+ * await css
26
+ * .find("tokens.css")
27
+ * .setDeclaration({ atRule: "theme" }, "--color-primary", "#1974f9")
28
+ * .setDeclaration({ selector: "html[data-theme='nylon']" }, "--color-primary", "#0b254d");
29
+ * };
30
+ * // -> @import "tailwindcss";
31
+ * // ->
32
+ * // -> @theme {
33
+ * // -> --color-primary: #1974f9;
34
+ * // -> }
35
+ * // ->
36
+ * // -> html[data-theme='nylon'] {
37
+ * // -> --color-primary: #0b254d;
38
+ * // -> }
39
+ */
40
+ export declare function find(path: string): Handle<"found", Root, CssOps>;