@powerhousedao/vetra 6.2.3-dev.8 → 6.2.3-dev.81

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 (171) hide show
  1. package/dist/codegen/index.d.ts +26 -19
  2. package/dist/codegen/index.d.ts.map +1 -1
  3. package/dist/codegen/index.js +21 -21
  4. package/dist/codegen/index.js.map +1 -1
  5. package/dist/codegen/spec.d.ts +3 -2
  6. package/dist/codegen/spec.js +1 -1
  7. package/dist/{connect-qpJ9OUaH.js → connect-EqImHuZ2.js} +1 -1
  8. package/dist/{connect-qpJ9OUaH.js.map → connect-EqImHuZ2.js.map} +1 -1
  9. package/dist/document-models/app-module/index.d.ts +4 -12
  10. package/dist/document-models/app-module/index.js +4 -4
  11. package/dist/document-models/app-module/index.js.map +1 -1
  12. package/dist/document-models/document-editor/index.d.ts +4 -12
  13. package/dist/document-models/document-editor/index.js +4 -4
  14. package/dist/document-models/document-editor/index.js.map +1 -1
  15. package/dist/document-models/index.d.ts +7 -6
  16. package/dist/document-models/index.js +5 -5
  17. package/dist/document-models/processor-module/index.d.ts +4 -12
  18. package/dist/document-models/processor-module/index.js +5 -5
  19. package/dist/document-models/processor-module/index.js.map +1 -1
  20. package/dist/document-models/subgraph-module/index.d.ts +4 -12
  21. package/dist/document-models/subgraph-module/index.js +4 -4
  22. package/dist/document-models/subgraph-module/index.js.map +1 -1
  23. package/dist/document-models/vetra-package/index.d.ts +4 -12
  24. package/dist/document-models/vetra-package/index.js +3 -3
  25. package/dist/{editor-_0gdltOt.js → editor-BDR7IYJG.js} +5 -7
  26. package/dist/editor-BDR7IYJG.js.map +1 -0
  27. package/dist/{editor-CLbvu3pG.js → editor-CbT_8Z6A.js} +6 -8
  28. package/dist/editor-CbT_8Z6A.js.map +1 -0
  29. package/dist/{editor-CCdg1mJL.js → editor-CnfajXGg.js} +5 -7
  30. package/dist/{editor-CCdg1mJL.js.map → editor-CnfajXGg.js.map} +1 -1
  31. package/dist/{editor-Fgw7attg.js → editor-Cnk0M044.js} +70 -51
  32. package/dist/editor-Cnk0M044.js.map +1 -0
  33. package/dist/{editor-LRAwrgdQ.js → editor-D5SIbFn_.js} +10 -9
  34. package/dist/editor-D5SIbFn_.js.map +1 -0
  35. package/dist/{editor-C13SvgUy.js → editor-SJk7cr6k.js} +5 -7
  36. package/dist/editor-SJk7cr6k.js.map +1 -0
  37. package/dist/editors/components/index.d.ts +3 -3
  38. package/dist/editors/components/index.d.ts.map +1 -1
  39. package/dist/editors/components/index.js.map +1 -1
  40. package/dist/editors/hooks/index.d.ts +3 -3
  41. package/dist/editors/hooks/index.d.ts.map +1 -1
  42. package/dist/editors/hooks/index.js +1 -1
  43. package/dist/editors/index.d.ts +18 -8
  44. package/dist/editors/index.d.ts.map +1 -1
  45. package/dist/editors/index.js +1 -1
  46. package/dist/{factory-DMl8eB3P.js → factory-BQp6QPQO.js} +16 -12
  47. package/dist/factory-BQp6QPQO.js.map +1 -0
  48. package/dist/{factory-5eiZohiv.js → factory-BUuO4fIN.js} +12 -4
  49. package/dist/factory-BUuO4fIN.js.map +1 -0
  50. package/dist/{hooks-BIgFcbaF.js → hooks-BbxvC-C3.js} +2 -2
  51. package/dist/{hooks-BIgFcbaF.js.map → hooks-BbxvC-C3.js.map} +1 -1
  52. package/dist/index-6UbC6P89.d.ts +39 -0
  53. package/dist/index-6UbC6P89.d.ts.map +1 -0
  54. package/dist/index-7hPKQROx.d.ts +33 -0
  55. package/dist/index-7hPKQROx.d.ts.map +1 -0
  56. package/dist/index-BAeTvhwh.d.ts +35 -0
  57. package/dist/index-BAeTvhwh.d.ts.map +1 -0
  58. package/dist/{index-f_um1g-i.d.ts → index-CBcJ_oc6.d.ts} +26 -62
  59. package/dist/index-CBcJ_oc6.d.ts.map +1 -0
  60. package/dist/index-CScZx1m9.d.ts +42 -0
  61. package/dist/index-CScZx1m9.d.ts.map +1 -0
  62. package/dist/{index-Dm_gN1DR.d.ts → index-D6Ai0OOc.d.ts} +26 -59
  63. package/dist/index-D6Ai0OOc.d.ts.map +1 -0
  64. package/dist/{index-SB-AtQdU.d.ts → index-DIpsNezM.d.ts} +30 -64
  65. package/dist/index-DIpsNezM.d.ts.map +1 -0
  66. package/dist/index-D_rwE-2_.d.ts +31 -0
  67. package/dist/index-D_rwE-2_.d.ts.map +1 -0
  68. package/dist/{index-B5ijieNt.d.ts → index-DplUuZMT.d.ts} +21 -55
  69. package/dist/index-DplUuZMT.d.ts.map +1 -0
  70. package/dist/index.d.ts +51 -93
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +84 -12
  73. package/dist/index.js.map +1 -1
  74. package/dist/{logger-WHD0fyLm.js → logger-BFxMdimR.js} +1 -1
  75. package/dist/{logger-WHD0fyLm.js.map → logger-BFxMdimR.js.map} +1 -1
  76. package/dist/{module-CRq_lUkG.js → module-23VayWKe.js} +9 -9
  77. package/dist/module-23VayWKe.js.map +1 -0
  78. package/dist/{module-Chqkdq4U.js → module-2JZcvfVs.js} +3 -3
  79. package/dist/{module-Chqkdq4U.js.map → module-2JZcvfVs.js.map} +1 -1
  80. package/dist/{module-DXT-FMxU.js → module-B6S4QGOx.js} +7 -7
  81. package/dist/module-B6S4QGOx.js.map +1 -0
  82. package/dist/{module-bKT_e3CH.js → module-BktWa0rB.js} +11 -9
  83. package/dist/module-BktWa0rB.js.map +1 -0
  84. package/dist/{module-ciAK1LUC.d.ts → module-D4lqkHHK.d.ts} +37 -70
  85. package/dist/module-D4lqkHHK.d.ts.map +1 -0
  86. package/dist/{module-CRfHlbnq.js → module-FXJRy_1W.js} +2 -2
  87. package/dist/{module-CRfHlbnq.js.map → module-FXJRy_1W.js.map} +1 -1
  88. package/dist/{module-Bx1OEHxF.js → module-hLzF5tCL.js} +3 -3
  89. package/dist/{module-Bx1OEHxF.js.map → module-hLzF5tCL.js.map} +1 -1
  90. package/dist/{ph-factories-CjbIAMgT.js → ph-factories-Bgnr3mK3.js} +2 -2
  91. package/dist/{ph-factories-CjbIAMgT.js.map → ph-factories-Bgnr3mK3.js.map} +1 -1
  92. package/dist/{ph-factories-Ce8oAqs9.js → ph-factories-CgoFCmG0.js} +2 -2
  93. package/dist/{ph-factories-Ce8oAqs9.js.map → ph-factories-CgoFCmG0.js.map} +1 -1
  94. package/dist/{ph-factories-dVj6mIlR.js → ph-factories-DhLtvC7j.js} +2 -2
  95. package/dist/{ph-factories-dVj6mIlR.js.map → ph-factories-DhLtvC7j.js.map} +1 -1
  96. package/dist/{ph-factories-CljTAAVS.js → ph-factories-fEke-Nr8.js} +2 -2
  97. package/dist/{ph-factories-CljTAAVS.js.map → ph-factories-fEke-Nr8.js.map} +1 -1
  98. package/dist/powerhouse.manifest.json +76 -0
  99. package/dist/{processor-trJFuoHh.js → processor-C_zliXhw.js} +435 -327
  100. package/dist/processor-C_zliXhw.js.map +1 -0
  101. package/dist/processors/codegen/index.d.ts +14 -6
  102. package/dist/processors/codegen/index.d.ts.map +1 -1
  103. package/dist/processors/codegen/index.js +2 -2
  104. package/dist/processors/index.d.ts +2 -3
  105. package/dist/processors/index.d.ts.map +1 -1
  106. package/dist/processors/index.js +1 -1
  107. package/dist/processors/index.js.map +1 -1
  108. package/dist/processors/vetra-read-model/index.d.ts +47 -49
  109. package/dist/processors/vetra-read-model/index.d.ts.map +1 -1
  110. package/dist/processors/vetra-read-model/index.js +1 -1
  111. package/dist/{spec-api-DobY5TUJ.js → spec-api-BGj7gcQn.js} +24 -18
  112. package/dist/{spec-api-DobY5TUJ.js.map → spec-api-BGj7gcQn.js.map} +1 -1
  113. package/dist/{specs-BeVdfCwg.d.ts → specs-DoTSfuxN.d.ts} +7 -4
  114. package/dist/specs-DoTSfuxN.d.ts.map +1 -0
  115. package/dist/subgraph-type-lint-Dr8Wu0VB.js +94 -0
  116. package/dist/subgraph-type-lint-Dr8Wu0VB.js.map +1 -0
  117. package/dist/switchboard-DjCPLtMW.js +8 -0
  118. package/dist/{switchboard-Bf0uvxSu.js.map → switchboard-DjCPLtMW.js.map} +1 -1
  119. package/dist/{upgrade-manifest-OlS1ALVv.js → upgrade-manifest-BOZ5nmyK.js} +1 -1
  120. package/dist/{upgrade-manifest-OlS1ALVv.js.map → upgrade-manifest-BOZ5nmyK.js.map} +1 -1
  121. package/dist/{upgrade-manifest-BGuy0v65.js → upgrade-manifest-D7xKGmZc.js} +1 -1
  122. package/dist/{upgrade-manifest-BGuy0v65.js.map → upgrade-manifest-D7xKGmZc.js.map} +1 -1
  123. package/dist/{upgrade-manifest-Ck3Mgwhc.js → upgrade-manifest-DLxSL23q.js} +1 -1
  124. package/dist/{upgrade-manifest-Ck3Mgwhc.js.map → upgrade-manifest-DLxSL23q.js.map} +1 -1
  125. package/dist/{upgrade-manifest-XdOLymuP.js → upgrade-manifest-Dv62Cod7.js} +1 -1
  126. package/dist/{upgrade-manifest-XdOLymuP.js.map → upgrade-manifest-Dv62Cod7.js.map} +1 -1
  127. package/dist/{upgrade-manifest-NaS4SWk9.js → upgrade-manifest-d3LquK-H.js} +1 -1
  128. package/dist/{upgrade-manifest-NaS4SWk9.js.map → upgrade-manifest-d3LquK-H.js.map} +1 -1
  129. package/dist/{utils-DXCsvCXL.js → utils-876N1Sph.js} +2 -2
  130. package/dist/{utils-DXCsvCXL.js.map → utils-876N1Sph.js.map} +1 -1
  131. package/dist/{utils-CkxGmQ2_.js → utils-Al_SGg2a.js} +2 -2
  132. package/dist/{utils-CkxGmQ2_.js.map → utils-Al_SGg2a.js.map} +1 -1
  133. package/dist/{utils-DmOIDVQo.js → utils-BJk4_43W.js} +24 -4
  134. package/dist/utils-BJk4_43W.js.map +1 -0
  135. package/dist/{utils-B4KdjDnp.js → utils-COP7hJ-K.js} +2 -2
  136. package/dist/{utils-B4KdjDnp.js.map → utils-COP7hJ-K.js.map} +1 -1
  137. package/dist/{vetra-package-Bl6TC4wx.js → vetra-package-DSyRtkdJ.js} +2 -2
  138. package/dist/{vetra-package-Bl6TC4wx.js.map → vetra-package-DSyRtkdJ.js.map} +1 -1
  139. package/package.json +17 -14
  140. package/style.css +2 -0
  141. package/dist/document-models/app-module/index.d.ts.map +0 -1
  142. package/dist/document-models/document-editor/index.d.ts.map +0 -1
  143. package/dist/document-models/processor-module/index.d.ts.map +0 -1
  144. package/dist/document-models/subgraph-module/index.d.ts.map +0 -1
  145. package/dist/document-models/vetra-package/index.d.ts.map +0 -1
  146. package/dist/editor-C13SvgUy.js.map +0 -1
  147. package/dist/editor-CLbvu3pG.js.map +0 -1
  148. package/dist/editor-Fgw7attg.js.map +0 -1
  149. package/dist/editor-LRAwrgdQ.js.map +0 -1
  150. package/dist/editor-_0gdltOt.js.map +0 -1
  151. package/dist/factory-5eiZohiv.js.map +0 -1
  152. package/dist/factory-DMl8eB3P.js.map +0 -1
  153. package/dist/index-B5ijieNt.d.ts.map +0 -1
  154. package/dist/index-Dm_gN1DR.d.ts.map +0 -1
  155. package/dist/index-SB-AtQdU.d.ts.map +0 -1
  156. package/dist/index-f_um1g-i.d.ts.map +0 -1
  157. package/dist/module-CRq_lUkG.js.map +0 -1
  158. package/dist/module-DXT-FMxU.js.map +0 -1
  159. package/dist/module-bKT_e3CH.js.map +0 -1
  160. package/dist/module-ciAK1LUC.d.ts.map +0 -1
  161. package/dist/powerhouse.manifest.d.ts +0 -34
  162. package/dist/powerhouse.manifest.d.ts.map +0 -1
  163. package/dist/powerhouse.manifest.js +0 -86
  164. package/dist/powerhouse.manifest.js.map +0 -1
  165. package/dist/processor-trJFuoHh.js.map +0 -1
  166. package/dist/specs-BeVdfCwg.d.ts.map +0 -1
  167. package/dist/switchboard-Bf0uvxSu.js +0 -8
  168. package/dist/useVetraDocument-BlLdlhrQ.js +0 -30
  169. package/dist/useVetraDocument-BlLdlhrQ.js.map +0 -1
  170. package/dist/utils-DmOIDVQo.js.map +0 -1
  171. /package/dist/{chunk-pbuEa-1d.js → rolldown-runtime-D7D4PA-g.js} +0 -0
@@ -1,46 +1,43 @@
1
- import { t as __exportAll } from "./chunk-pbuEa-1d.js";
2
- import { t as logger } from "./logger-WHD0fyLm.js";
3
- import { PROCESSOR_APPS } from "@powerhousedao/shared/processors";
4
- import { generateApp, generateDocumentModel, generateEditor, generateProcessor, generateSubgraph, validateDocumentModelState } from "@powerhousedao/codegen";
1
+ import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
2
+ import { n as lintSubgraphTypes, t as findSubgraphNameConflict } from "./subgraph-type-lint-Dr8Wu0VB.js";
3
+ import { t as logger } from "./logger-BFxMdimR.js";
4
+ import { PROCESSOR_APPS, getCodegenStatusRegistry } from "@powerhousedao/shared/processors";
5
+ import { afterPendingInstalls, generateApp, generateDocumentModel, generateEditor, generateProcessor, generateSubgraph, installFeatureDependencies, installsPending, validateDocumentModelState } from "@powerhousedao/codegen";
5
6
  import { kebabCase } from "change-case";
6
7
  import { baseMinimalSaveToFile } from "document-model/node";
7
- import { mkdir } from "node:fs/promises";
8
- import { join } from "node:path";
8
+ import { mkdir, readdir, stat } from "node:fs/promises";
9
+ import { join, relative } from "node:path";
9
10
  import { createInterface } from "node:readline";
10
11
  import { createOrUpdateManifest } from "@powerhousedao/codegen/file-builders";
11
12
  //#region processors/codegen/document-handlers/base-document-gen.ts
12
- /**
13
- * Abstract base class for document generators
14
- * Defines the interface that all document-type handlers must implement
15
- */
13
+ /** The base of the generators, one per document type or set of types. */
16
14
  var BaseDocumentGen = class {
15
+ config;
17
16
  project;
18
17
  constructor(config, project) {
19
18
  this.config = config;
20
19
  this.project = project;
21
20
  }
22
- /**
23
- * Check if this generator supports the given document type
24
- */
25
21
  supportsDocumentType(documentType) {
26
22
  if (typeof this.supportedDocumentTypes === "string") return this.supportedDocumentTypes === documentType;
27
23
  return this.supportedDocumentTypes.includes(documentType);
28
24
  }
29
- /**
30
- * Get all supported document types as an array
31
- */
32
25
  getSupportedDocumentTypes() {
33
26
  if (typeof this.supportedDocumentTypes === "string") return [this.supportedDocumentTypes];
34
27
  return [...this.supportedDocumentTypes];
35
28
  }
36
- /**
37
- * Validate if this strand should be processed
38
- * Override this method in specific generators to add custom validation logic
39
- */
29
+ /** The module's name in the strand's state, for its codegen status. */
30
+ moduleName(strand) {
31
+ const name = strand.state?.global?.name;
32
+ return typeof name === "string" && name !== "" ? name : void 0;
33
+ }
34
+ /** Why this strand is not generated from; undefined when it is. */
35
+ skipReason(strand) {
36
+ if (!strand.documentId || !strand.documentType) return "The operation names no document";
37
+ if (!this.supportsDocumentType(strand.documentType)) return `No generator for document type ${strand.documentType}`;
38
+ }
40
39
  shouldProcess(strand) {
41
- if (!strand.documentId || !strand.documentType) return false;
42
- if (!this.supportsDocumentType(strand.documentType)) return false;
43
- return true;
40
+ return this.skipReason(strand) === void 0;
44
41
  }
45
42
  };
46
43
  //#endregion
@@ -71,6 +68,12 @@ var InteractiveManager = class {
71
68
  logger.debug(`>>> Queued strand for ${documentKey}, queue size: ${this.strandQueue.size}`);
72
69
  }
73
70
  /**
71
+ * Drop the queued strands the predicate matches
72
+ */
73
+ discardWhere(predicate) {
74
+ for (const [key, queued] of this.strandQueue) if (predicate(queued.strand)) this.strandQueue.delete(key);
75
+ }
76
+ /**
74
77
  * Get all queued strands
75
78
  */
76
79
  getQueuedStrands() {
@@ -135,7 +138,7 @@ var InteractiveManager = class {
135
138
  * Process all queued strands with a single user confirmation
136
139
  * This is the main method for queue-based interactive processing
137
140
  */
138
- async processQueueWithConfirmation(processor) {
141
+ async processQueueWithConfirmation(processor, onCancel) {
139
142
  if (this.processingConfirmation) {
140
143
  logger.debug("Already processing confirmation, skipping queue processing");
141
144
  return;
@@ -149,7 +152,7 @@ var InteractiveManager = class {
149
152
  try {
150
153
  if (!await this.promptUserConfirmation()) {
151
154
  logger.info("❌ Code generation cancelled by user");
152
- this.clearQueue();
155
+ onCancel?.(this.clearQueue());
153
156
  return;
154
157
  }
155
158
  queuedStrands = this.clearQueue();
@@ -179,22 +182,75 @@ var InteractiveManager = class {
179
182
  }
180
183
  };
181
184
  //#endregion
185
+ //#region processors/codegen/written-files.ts
186
+ const SKIPPED_DIRS = /* @__PURE__ */ new Set([
187
+ "node_modules",
188
+ "dist",
189
+ "backup-documents"
190
+ ]);
191
+ const MAX_FILES = 500;
192
+ /** The project's files modified at or after `since`, relative and sorted. */
193
+ async function filesWrittenSince(projectDir, since) {
194
+ const written = [];
195
+ const visit = async (dir) => {
196
+ let entries;
197
+ try {
198
+ entries = await readdir(dir, { withFileTypes: true });
199
+ } catch {
200
+ return;
201
+ }
202
+ for (const entry of entries) {
203
+ if (written.length >= MAX_FILES) return;
204
+ const path = join(dir, entry.name);
205
+ if (entry.isDirectory()) {
206
+ if (entry.name.startsWith(".") || SKIPPED_DIRS.has(entry.name)) continue;
207
+ await visit(path);
208
+ } else if (entry.isFile()) try {
209
+ if ((await stat(path)).mtimeMs >= since) written.push(relative(projectDir, path).replaceAll("\\", "/"));
210
+ } catch {}
211
+ }
212
+ };
213
+ await visit(projectDir);
214
+ return written.sort();
215
+ }
216
+ //#endregion
182
217
  //#region processors/codegen/document-handlers/document-codegen-manager.ts
183
218
  const DEFAULT_DEBOUNCE_TIME = 1e3;
219
+ const MODULE_NOT_FOUND_CODES = /* @__PURE__ */ new Set([
220
+ "ERR_MODULE_NOT_FOUND",
221
+ "MODULE_NOT_FOUND",
222
+ "ERR_PACKAGE_PATH_NOT_EXPORTED"
223
+ ]);
224
+ const MODULE_NOT_FOUND_MESSAGE = /Cannot find (module|package)|Failed to resolve (import|entry)|Failed to load url/;
184
225
  /**
185
226
  * Manager class responsible for routing documents to the correct generator
186
227
  * and managing generator registration and instantiation
187
228
  */
188
229
  var DocumentCodegenManager = class {
230
+ config;
189
231
  project;
190
232
  generators = /* @__PURE__ */ new Map();
191
233
  debounceTimers = /* @__PURE__ */ new Map();
192
- processingQueue = Promise.resolve();
234
+ jobs = Promise.resolve();
235
+ queuedJobs = /* @__PURE__ */ new Map();
236
+ runningJobs = 0;
237
+ /** The wait before retrying a module-resolution failure when no install is queued. */
238
+ retryDelayMs = 3e3;
193
239
  interactiveManager;
194
- constructor(config, project, interactiveMode = false) {
240
+ isInScope = () => Promise.resolve(true);
241
+ status;
242
+ constructor(config, project, interactiveMode = false, status = getCodegenStatusRegistry()) {
195
243
  this.config = config;
196
244
  this.project = project;
197
245
  this.interactiveManager = new InteractiveManager(interactiveMode);
246
+ this.status = status;
247
+ }
248
+ /**
249
+ * Limit generation to the documents `isInScope` accepts, checked when the
250
+ * debounce fires
251
+ */
252
+ setScope(isInScope) {
253
+ this.isInScope = isInScope;
198
254
  }
199
255
  /**
200
256
  * Register a generator class for a specific document type
@@ -245,16 +301,17 @@ var DocumentCodegenManager = class {
245
301
  logger.error("❌ Document type is missing from strand state");
246
302
  throw new Error("Document type is missing from strand state");
247
303
  }
248
- const generator = this.getGenerator(documentType);
249
- if (!generator) {
304
+ if (!this.getGenerator(documentType)) {
250
305
  logger.warn(`⚠️ No generator found for document type: ${documentType}`);
251
306
  logger.warn(`ℹ️ Supported document types: ${this.getRegisteredDocumentTypes().join(", ")}`);
252
307
  throw new Error(`Unsupported document type: ${documentType}`);
253
308
  }
254
- if (!generator.shouldProcess(strand)) {
255
- logger.debug(`>>> Generator validation failed for ${documentType}:${strand.documentId}, skipping processing`);
256
- return Promise.resolve();
257
- }
309
+ this.status.set({
310
+ documentId: strand.documentId,
311
+ documentType,
312
+ state: "queued",
313
+ message: this.interactiveManager.isInteractive() ? "Waiting for confirmation in the terminal running Vetra" : "Waiting for the document's changes to settle"
314
+ });
258
315
  if (this.interactiveManager.isInteractive()) {
259
316
  logger.debug(`>>> Queueing strand for interactive processing: ${documentType}:${strand.documentId}`);
260
317
  this.interactiveManager.queueStrand(strand);
@@ -262,8 +319,13 @@ var DocumentCodegenManager = class {
262
319
  if (existingTimer) clearTimeout(existingTimer);
263
320
  const debounceTimer = setTimeout(async () => {
264
321
  try {
322
+ const rejected = /* @__PURE__ */ new Set();
323
+ for (const { strand } of this.interactiveManager.getQueuedStrands()) if (!await this.accepts(strand)) rejected.add(strand);
324
+ this.interactiveManager.discardWhere((queued) => rejected.has(queued));
265
325
  await this.interactiveManager.processQueueWithConfirmation(async (queuedStrands) => {
266
326
  await this.processQueuedStrands(queuedStrands);
327
+ }, (cancelled) => {
328
+ for (const { strand } of cancelled) this.setStatus(strand, "skipped", "Cancelled in the terminal");
267
329
  });
268
330
  } catch (error) {
269
331
  logger.error("❌ Error during interactive batch processing: @error", error);
@@ -278,11 +340,9 @@ var DocumentCodegenManager = class {
278
340
  if (existingTimer) clearTimeout(existingTimer);
279
341
  const debounceTimer = setTimeout(async () => {
280
342
  try {
343
+ if (!await this.accepts(strand)) return;
281
344
  logger.debug(`🔄 Routing document type "${documentType}" to generator (debounced)`);
282
- await generator.generate(strand);
283
- logger.debug(`✅ Successfully generated code for document type: ${documentType}`);
284
- } catch (error) {
285
- logger.error(`❌ Error generating code for document type "${documentType}":`, error);
345
+ await this.enqueueJob(strand);
286
346
  } finally {
287
347
  this.debounceTimers.delete(timerKey);
288
348
  }
@@ -291,6 +351,99 @@ var DocumentCodegenManager = class {
291
351
  }
292
352
  return Promise.resolve();
293
353
  }
354
+ /** In scope first, so documents out of scope are never validated or logged. */
355
+ async accepts(strand) {
356
+ const generator = this.getGenerator(strand.documentType);
357
+ if (!generator) return false;
358
+ if (!await this.isInScope(strand.documentId)) {
359
+ logger.debug(`Document ${strand.documentId} is not in the Vetra drive, skipping codegen`);
360
+ this.status.delete(strand.documentId);
361
+ this.queuedJobs.delete(strand.documentId);
362
+ return false;
363
+ }
364
+ const reason = generator.skipReason(strand);
365
+ if (reason !== void 0) {
366
+ this.setStatus(strand, "skipped", reason);
367
+ this.queuedJobs.delete(strand.documentId);
368
+ return false;
369
+ }
370
+ return true;
371
+ }
372
+ /** Queues a job; one already queued for the document runs the latest strand. */
373
+ enqueueJob(strand) {
374
+ const { documentId } = strand;
375
+ const alreadyQueued = this.queuedJobs.has(documentId);
376
+ this.queuedJobs.set(documentId, strand);
377
+ if (this.runningJobs > 0) this.setStatus(strand, "queued", "Waiting for codegen of other documents to finish");
378
+ if (alreadyQueued) return this.jobs;
379
+ this.jobs = this.jobs.then(async () => {
380
+ const latest = this.queuedJobs.get(documentId);
381
+ this.queuedJobs.delete(documentId);
382
+ const generator = latest && this.getGenerator(latest.documentType);
383
+ if (!latest || !generator) return;
384
+ this.runningJobs++;
385
+ try {
386
+ await this.runJob(latest, generator);
387
+ } finally {
388
+ this.runningJobs--;
389
+ }
390
+ });
391
+ return this.jobs;
392
+ }
393
+ /** Runs a job after pending installs, once more after a module-resolution failure. */
394
+ async runJob(strand, generator) {
395
+ await this.afterInstalls(strand, "Waiting for a dependency install to finish");
396
+ const error = await this.attempt(strand, generator);
397
+ if (error === void 0) return;
398
+ if (!isModuleResolutionError(error)) {
399
+ this.setStatus(strand, "failed", errorMessage(error));
400
+ return;
401
+ }
402
+ logger.warn(`Codegen for ${strand.documentType} ${strand.documentId} could not resolve a module; retrying once installs finish: ${errorMessage(error)}`);
403
+ if (!await this.afterInstalls(strand, `Retrying once dependency installs finish, after: ${errorMessage(error)}`)) await new Promise((resolve) => setTimeout(resolve, this.retryDelayMs));
404
+ const retryError = await this.attempt(strand, generator);
405
+ if (retryError !== void 0) this.setStatus(strand, "failed", `${errorMessage(retryError)} (also after a retry; if an install is running, run it to the end, then change the document again)`);
406
+ }
407
+ /** Waits for queued installs, saying so; resolves to whether any was queued. */
408
+ async afterInstalls(strand, message) {
409
+ if (!installsPending()) return false;
410
+ this.setStatus(strand, "waiting-for-install", message);
411
+ await afterPendingInstalls();
412
+ return true;
413
+ }
414
+ /** Generates once; records done or skipped, or resolves to the error. */
415
+ async attempt(strand, generator) {
416
+ const startedAt = Date.now();
417
+ const job = {
418
+ waitingForInstall: (message) => this.setStatus(strand, "waiting-for-install", message),
419
+ running: () => this.setStatus(strand, "running")
420
+ };
421
+ job.running();
422
+ try {
423
+ const result = await generator.generate(strand, job);
424
+ if (result) {
425
+ this.setStatus(strand, "skipped", result.skipped);
426
+ return;
427
+ }
428
+ const files = await filesWrittenSince(this.config.CURRENT_WORKING_DIR, startedAt);
429
+ this.setStatus(strand, "done", void 0, files);
430
+ logger.debug(`✅ Successfully generated code for document type: ${strand.documentType}`);
431
+ return;
432
+ } catch (error) {
433
+ logger.error(`❌ Error generating code for document type "${strand.documentType}":`, error);
434
+ return error ?? /* @__PURE__ */ new Error("Codegen failed");
435
+ }
436
+ }
437
+ setStatus(strand, state, message, files) {
438
+ this.status.set({
439
+ documentId: strand.documentId,
440
+ documentType: strand.documentType,
441
+ name: this.getGenerator(strand.documentType)?.moduleName(strand),
442
+ state,
443
+ message,
444
+ files
445
+ });
446
+ }
294
447
  /**
295
448
  * Process multiple strands in priority order (document-model types first)
296
449
  */
@@ -307,18 +460,12 @@ var DocumentCodegenManager = class {
307
460
  */
308
461
  async processStrand(strand) {
309
462
  const documentType = strand.documentType;
310
- const generator = this.getGenerator(documentType);
311
- if (!generator) {
463
+ if (!this.getGenerator(documentType)) {
312
464
  logger.warn(`⚠️ No generator found for document type: ${documentType}`);
313
465
  return;
314
466
  }
315
- try {
316
- logger.debug(`🔄 Generating code for document type: ${documentType}`);
317
- await generator.generate(strand);
318
- logger.debug(`✅ Successfully generated code for document type: ${documentType}`);
319
- } catch (error) {
320
- logger.error(`❌ Error generating code for document type "${documentType}":`, error);
321
- }
467
+ logger.debug(`🔄 Generating code for document type: ${documentType}`);
468
+ await this.enqueueJob(strand);
322
469
  }
323
470
  /**
324
471
  * Clear all registered generators
@@ -355,6 +502,19 @@ var DocumentCodegenManager = class {
355
502
  return this.interactiveManager.isProcessing();
356
503
  }
357
504
  };
505
+ function isModuleResolutionError(error) {
506
+ for (let cause = error; cause instanceof Error; cause = cause.cause) {
507
+ const code = cause.code;
508
+ if (code && MODULE_NOT_FOUND_CODES.has(code)) return true;
509
+ if (MODULE_NOT_FOUND_MESSAGE.test(cause.message)) return true;
510
+ }
511
+ return false;
512
+ }
513
+ function errorMessage(error) {
514
+ if (!(error instanceof Error)) return String(error);
515
+ const cause = error.cause instanceof Error ? `: ${error.cause.message}` : "";
516
+ return `${error.message}${cause}`;
517
+ }
358
518
  //#endregion
359
519
  //#region processors/codegen/document-handlers/generators/utils.ts
360
520
  const BACKUP_FOLDER = "backup-documents";
@@ -363,10 +523,15 @@ const BACKUP_FOLDER = "backup-documents";
363
523
  * Used when the full document is not available (e.g., in onOperations handler).
364
524
  */
365
525
  async function minimalBackupDocument(data, workingDir, extension) {
526
+ const { header, ...state } = data.state;
366
527
  try {
367
528
  const backupPath = join(workingDir, BACKUP_FOLDER);
368
529
  await mkdir(backupPath, { recursive: true });
369
- const filePath = await baseMinimalSaveToFile(data, backupPath, extension ?? "");
530
+ const filePath = await baseMinimalSaveToFile({
531
+ ...data,
532
+ state,
533
+ protocolVersions: data.protocolVersions ?? header?.protocolVersions
534
+ }, backupPath, extension ?? "");
370
535
  logger.debug(`Document backed up to: ${filePath}`);
371
536
  return filePath;
372
537
  } catch (error) {
@@ -374,6 +539,36 @@ async function minimalBackupDocument(data, workingDir, extension) {
374
539
  return;
375
540
  }
376
541
  }
542
+ async function warnSubgraphTypeConflicts(workingDir) {
543
+ let warnings;
544
+ try {
545
+ warnings = await lintSubgraphTypes(workingDir);
546
+ } catch (error) {
547
+ logger.warn(`Failed to check subgraph type names: ${error instanceof Error ? error.message : String(error)}`);
548
+ return;
549
+ }
550
+ for (const warning of warnings) logger.warn(`⚠️ ${warning}`);
551
+ }
552
+ /** Adds and installs what `features` need before their files are written:
553
+ * the package loader reloads on those files, so their imports must resolve. */
554
+ async function installFeatureDependencies$1(features, projectDir, waiting, job) {
555
+ const install = { ran: false };
556
+ try {
557
+ await installFeatureDependencies(features, projectDir, {
558
+ log: (message) => logger.info(message),
559
+ warn: (message) => logger.warn(`⚠️ ${message}`),
560
+ waiting,
561
+ onInstall: (packages, command) => {
562
+ install.ran = true;
563
+ job?.waitingForInstall(`Installing ${packages.join(", ")} with \`${command}\``);
564
+ }
565
+ });
566
+ } catch (error) {
567
+ logger.warn(`⚠️ Could not add the dependencies of ${features.join(", ")}: ${error.message}`);
568
+ } finally {
569
+ if (install.ran) job?.running();
570
+ }
571
+ }
377
572
  //#endregion
378
573
  //#region processors/codegen/document-handlers/generators/app-generator.ts
379
574
  /**
@@ -381,71 +576,47 @@ async function minimalBackupDocument(data, workingDir, extension) {
381
576
  */
382
577
  var AppGenerator = class extends BaseDocumentGen {
383
578
  supportedDocumentTypes = "powerhouse/app";
384
- /**
385
- * Parse and extract the global state from the serialized state string
386
- */
387
579
  extractGlobalState(input) {
388
580
  if (!input.state) return;
389
581
  return input.state.global;
390
582
  }
391
- /**
392
- * Validate if this app strand should be processed
393
- */
394
- shouldProcess(input) {
395
- if (!super.shouldProcess(input)) return false;
583
+ skipReason(input) {
584
+ const base = super.skipReason(input);
585
+ if (base) return base;
396
586
  const state = this.extractGlobalState(input);
397
- if (!state) {
398
- logger.debug(`No state found for app: ${input.documentId}`);
399
- return false;
400
- }
401
- if (!state.name) {
402
- logger.debug(`No name found for app: ${input.documentId}`);
403
- return false;
404
- }
405
- if (state.status !== "CONFIRMED") {
406
- logger.debug(`App not confirmed: ${state.name} (status: ${state.status})`);
407
- return false;
408
- }
409
- return true;
587
+ let reason;
588
+ if (!state) reason = "The app has no state";
589
+ else if (!state.name) reason = "The app has no name";
590
+ else if (state.status !== "CONFIRMED") reason = `App "${state.name}" is not confirmed (status: ${state.status}); codegen runs once it is CONFIRMED`;
591
+ if (reason) logger.debug(reason);
592
+ return reason;
410
593
  }
411
594
  async generate(input) {
412
595
  const state = this.extractGlobalState(input);
413
- if (!state) {
414
- logger.error(`No state found for app: ${input.documentId}`);
415
- return;
416
- }
417
- if (state.name && state.status === "CONFIRMED") {
418
- logger.info(`🔄 Starting app generation for app: ${state.name}`);
419
- try {
420
- const appId = kebabCase(state.name);
421
- await generateApp({
422
- ...this.config.PH_CONFIG,
423
- appName: state.name,
424
- appId,
425
- allowedDocumentTypes: state.allowedDocumentTypes ?? [],
426
- isDragAndDropEnabled: state.isDragAndDropEnabled
427
- }, this.project);
428
- await this.project.save();
429
- logger.info(`✅ App generation completed successfully for app: ${state.name}`);
430
- const fullState = input.state;
431
- await minimalBackupDocument({
432
- documentId: input.documentId,
433
- documentType: input.documentType,
434
- branch: input.branch,
435
- state: fullState,
436
- name: state.name
437
- }, this.config.CURRENT_WORKING_DIR);
438
- } catch (error) {
439
- logger.error(`❌ Error during app generation for app ${state.name}:`, error);
440
- if (error instanceof Error) logger.error(`❌ Error message: ${error.message}`);
441
- }
442
- } else if (!state.name) {
443
- logger.error(`❌ Skipping app generation - missing name for app`);
444
- return;
445
- } else if (state.status !== "CONFIRMED") {
446
- logger.error(`❌ Skipping app generation - app "${state.name}" is not confirmed (status: ${state.status})`);
447
- return;
596
+ const reason = this.skipReason(input);
597
+ if (!state || reason) return { skipped: reason ?? "The app has no state" };
598
+ logger.info(`🔄 Starting app generation for app: ${state.name}`);
599
+ try {
600
+ await generateApp({
601
+ ...this.config.PH_CONFIG,
602
+ appName: state.name,
603
+ appId: kebabCase(state.name),
604
+ allowedDocumentTypes: state.allowedDocumentTypes ?? [],
605
+ isDragAndDropEnabled: state.isDragAndDropEnabled
606
+ }, this.project);
607
+ await this.project.save();
608
+ } catch (error) {
609
+ logger.error(`❌ Error during app generation for app ${state.name}:`, error);
610
+ throw error;
448
611
  }
612
+ logger.info(`✅ App generation completed successfully for app: ${state.name}`);
613
+ await minimalBackupDocument({
614
+ documentId: input.documentId,
615
+ documentType: input.documentType,
616
+ branch: input.branch,
617
+ state: input.state,
618
+ name: state.name
619
+ }, this.config.CURRENT_WORKING_DIR);
449
620
  }
450
621
  };
451
622
  //#endregion
@@ -455,68 +626,46 @@ var AppGenerator = class extends BaseDocumentGen {
455
626
  */
456
627
  var DocumentEditorGenerator = class extends BaseDocumentGen {
457
628
  supportedDocumentTypes = "powerhouse/document-editor";
458
- /**
459
- * Parse and extract the global state from the serialized state string
460
- */
461
629
  extractGlobalState(input) {
462
630
  if (!input.state) return;
463
631
  return input.state.global;
464
632
  }
465
- /**
466
- * Validate if this document editor strand should be processed
467
- */
468
- shouldProcess(input) {
469
- if (!super.shouldProcess(input)) return false;
633
+ skipReason(input) {
634
+ const base = super.skipReason(input);
635
+ if (base) return base;
470
636
  const state = this.extractGlobalState(input);
471
- if (!state) {
472
- logger.debug(`No state found for document editor: ${input.documentId}`);
473
- return false;
474
- }
475
- if (!state.name) {
476
- logger.debug(`No name found for document editor: ${input.documentId}`);
477
- return false;
478
- }
479
- if (!state.documentTypes || state.documentTypes.length === 0) {
480
- logger.debug(`No document types found for document editor: ${state.name}`);
481
- return false;
482
- }
483
- if (state.status !== "CONFIRMED") {
484
- logger.debug(`Document editor not confirmed: ${state.name} (status: ${state.status})`);
485
- return false;
486
- }
487
- return true;
637
+ let reason;
638
+ if (!state) reason = "The editor has no state";
639
+ else if (!state.name) reason = "The editor has no name";
640
+ else if (state.documentTypes.length === 0) reason = `Editor "${state.name}" has no document types`;
641
+ else if (state.status !== "CONFIRMED") reason = `Editor "${state.name}" is not confirmed (status: ${state.status}); codegen runs once it is CONFIRMED`;
642
+ if (reason) logger.debug(reason);
643
+ return reason;
488
644
  }
489
645
  async generate(input) {
490
646
  const state = this.extractGlobalState(input);
491
- if (!state) {
492
- logger.error(`No state found for document editor: ${input.documentId}`);
493
- return;
494
- }
647
+ if (!state) return { skipped: "The editor has no state" };
495
648
  logger.info(`🔄 Starting editor generation for: ${state.name}`);
496
649
  try {
497
- const documentTypes = state.documentTypes.map((dt) => dt.documentType);
498
- const editorId = kebabCase(state.name);
499
650
  await generateEditor({
500
651
  ...this.config.PH_CONFIG,
501
652
  editorName: state.name,
502
- documentTypes,
503
- editorId
653
+ documentTypes: state.documentTypes.map((dt) => dt.documentType),
654
+ editorId: kebabCase(state.name)
504
655
  }, this.project);
505
656
  await this.project.save();
506
- logger.info(`✅ Editor generation completed successfully for: ${state.name}`);
507
- const fullState = input.state;
508
- await minimalBackupDocument({
509
- documentId: input.documentId,
510
- documentType: input.documentType,
511
- branch: input.branch,
512
- state: fullState,
513
- name: state.name
514
- }, this.config.CURRENT_WORKING_DIR);
515
657
  } catch (error) {
516
658
  logger.error(`❌ Error during editor generation for ${state.name}:`, error);
517
- if (error instanceof Error) logger.error(`❌ Error message: ${error.message}`);
518
- return;
659
+ throw error;
519
660
  }
661
+ logger.info(`✅ Editor generation completed successfully for: ${state.name}`);
662
+ await minimalBackupDocument({
663
+ documentId: input.documentId,
664
+ documentType: input.documentType,
665
+ branch: input.branch,
666
+ state: input.state,
667
+ name: state.name
668
+ }, this.config.CURRENT_WORKING_DIR);
520
669
  }
521
670
  };
522
671
  //#endregion
@@ -526,56 +675,48 @@ var DocumentEditorGenerator = class extends BaseDocumentGen {
526
675
  */
527
676
  var DocumentModelGenerator = class extends BaseDocumentGen {
528
677
  supportedDocumentTypes = "powerhouse/document-model";
529
- /**
530
- * Parse and extract the global state from the serialized state string
531
- */
532
678
  extractGlobalState(input) {
533
679
  if (!input.state) return;
534
680
  return input.state.global;
535
681
  }
536
- /**
537
- * Validate if this document model strand should be processed
538
- */
539
- shouldProcess(input) {
540
- if (!super.shouldProcess(input)) return false;
682
+ skipReason(input) {
683
+ const base = super.skipReason(input);
684
+ if (base) return base;
541
685
  const globalState = this.extractGlobalState(input);
542
686
  if (!globalState) {
543
687
  logger.debug(`>>> No global state found for document model: ${input.documentId}`);
544
- return false;
688
+ return "The document model has no global state";
545
689
  }
546
690
  const validationResult = validateDocumentModelState(globalState);
547
691
  if (!validationResult.isValid) {
548
692
  const errorList = validationResult.errors.map((error) => ` - ${error}`).join("\n");
549
693
  logger.info(`⚠️ Skipped code generation for '${globalState.name || input.documentId}' due to validation errors:\n${errorList}`);
550
- return false;
694
+ return `The document model is not ready for code generation:\n${errorList}`;
551
695
  }
552
696
  logger.info(`Document model ${globalState.name} is valid, proceeding with code generation`);
553
- return true;
554
697
  }
555
698
  async generate(input) {
556
699
  const globalState = this.extractGlobalState(input);
557
- if (!globalState) {
558
- logger.error(`❌ No global state found for document model: ${input.documentId}`);
559
- return;
560
- }
700
+ if (!globalState) throw new Error(`No global state found for document model: ${input.documentId}`);
561
701
  logger.debug(`🔄 Starting code generation for document model: ${globalState.name}`);
562
702
  try {
563
703
  await generateDocumentModel(globalState, this.project);
564
704
  await this.project.save();
565
- logger.info(`✅ Code generation completed successfully for: ${globalState.name}`);
566
- const fullState = input.state;
567
- const extension = globalState.extension?.replace(/^\.+|\.+$/g, "") || "";
568
- await minimalBackupDocument({
569
- documentId: input.documentId,
570
- documentType: input.documentType,
571
- branch: input.branch,
572
- state: fullState,
573
- name: globalState.name
574
- }, this.config.CURRENT_WORKING_DIR, extension);
575
705
  } catch (error) {
576
706
  logger.error(`❌ Error during code generation for ${globalState.name}:`, error);
577
- return;
707
+ throw error;
578
708
  }
709
+ logger.info(`✅ Code generation completed successfully for: ${globalState.name}`);
710
+ await warnSubgraphTypeConflicts(this.config.CURRENT_WORKING_DIR);
711
+ const fullState = input.state;
712
+ const extension = globalState.extension?.replace(/^\.+|\.+$/g, "") || "";
713
+ await minimalBackupDocument({
714
+ documentId: input.documentId,
715
+ documentType: input.documentType,
716
+ branch: input.branch,
717
+ state: fullState,
718
+ name: globalState.name
719
+ }, this.config.CURRENT_WORKING_DIR, extension);
579
720
  }
580
721
  };
581
722
  //#endregion
@@ -585,16 +726,13 @@ var DocumentModelGenerator = class extends BaseDocumentGen {
585
726
  */
586
727
  var PackageGenerator = class extends BaseDocumentGen {
587
728
  supportedDocumentTypes = "powerhouse/package";
588
- /**
589
- * Validate if this package strand should be processed
590
- */
591
- shouldProcess(input) {
592
- if (!super.shouldProcess(input)) return false;
729
+ skipReason(input) {
730
+ const base = super.skipReason(input);
731
+ if (base) return base;
593
732
  if (!input.state) {
594
733
  logger.debug(`>>> No state found for package: ${input.documentId}`);
595
- return false;
734
+ return "The package has no state";
596
735
  }
597
- return true;
598
736
  }
599
737
  async generate(input) {
600
738
  const fullState = input.state;
@@ -619,107 +757,67 @@ var PackageGenerator = class extends BaseDocumentGen {
619
757
  };
620
758
  //#endregion
621
759
  //#region processors/codegen/document-handlers/generators/processor-generator.ts
760
+ const PROCESSOR_TYPES = {
761
+ analytics: "analytics",
762
+ relational: "relationalDb"
763
+ };
622
764
  /**
623
765
  * Generator for processor documents
624
766
  */
625
767
  var ProcessorGenerator = class extends BaseDocumentGen {
626
768
  supportedDocumentTypes = "powerhouse/processor";
627
- /**
628
- * Parse and extract the global state from the serialized state string
629
- */
630
769
  extractGlobalState(input) {
631
770
  if (!input.state) return;
632
771
  return input.state.global;
633
772
  }
634
- /**
635
- * Validate if this processor strand should be processed
636
- */
637
- shouldProcess(input) {
638
- if (!super.shouldProcess(input)) return false;
639
- const state = this.extractGlobalState(input);
640
- if (!state) {
641
- logger.debug(`No state found for processor: ${input.documentId}`);
642
- return false;
643
- }
644
- if (!state.name) {
645
- logger.debug(`No name found for processor: ${input.documentId}`);
646
- return false;
647
- }
648
- if (!state.type) {
649
- logger.debug(`No type found for processor: ${state.name}`);
650
- return false;
651
- }
652
- if (!state.documentTypes || state.documentTypes.length === 0) {
653
- logger.debug(`No document types found for processor: ${state.name}`);
654
- return false;
655
- }
656
- if (!state.processorApps || state.processorApps.length === 0) {
657
- logger.debug(`No processor apps found for processor: ${state.name}`);
658
- return false;
659
- }
660
- if (state.status !== "CONFIRMED") {
661
- logger.debug(`Processor not confirmed: ${state.name} (status: ${state.status})`);
662
- return false;
663
- }
664
- return true;
773
+ skipReason(input) {
774
+ const base = super.skipReason(input);
775
+ if (base) return base;
776
+ const reason = invalidReason(this.extractGlobalState(input));
777
+ if (reason) logger.debug(reason);
778
+ return reason;
665
779
  }
666
- async generate(input) {
780
+ async generate(input, job) {
667
781
  const state = this.extractGlobalState(input);
668
- if (!state) {
669
- logger.error(`No state found for processor: ${input.documentId}`);
670
- return;
671
- }
672
- if (state.name && state.type && state.documentTypes.length > 0 && state.processorApps.length > 0 && state.status === "CONFIRMED") {
673
- logger.info(`🔄 Starting processor generation for: ${state.name}`);
674
- try {
675
- let processorType;
676
- if (state.type === "analytics") processorType = "analytics";
677
- else if (state.type === "relational") processorType = "relationalDb";
678
- else {
679
- logger.error(`❌ Unsupported processor type: ${state.type}`);
680
- return;
681
- }
682
- const documentTypes = state.documentTypes.map((dt) => dt.documentType);
683
- const processorApps = state.processorApps;
684
- if (!isProcessorApps(processorApps)) {
685
- logger.error(`❌ Unsupported processor apps: ${processorApps.join(", ")}`);
686
- return;
687
- }
688
- await generateProcessor({
689
- processorName: state.name,
690
- processorType,
691
- documentTypes,
692
- processorApps
693
- }, this.project);
694
- await this.project.save();
695
- logger.info(`✅ Processor generation completed successfully for: ${state.name}`);
696
- const fullState = input.state;
697
- await minimalBackupDocument({
698
- documentId: input.documentId,
699
- documentType: input.documentType,
700
- branch: input.branch,
701
- state: fullState,
702
- name: state.name
703
- }, this.config.CURRENT_WORKING_DIR);
704
- } catch (error) {
705
- logger.error(`❌ Error during processor generation for ${state.name}:`, error);
706
- if (error instanceof Error) logger.error(`❌ Error message: ${error.message}`);
707
- }
708
- } else if (!state.name) {
709
- logger.error(`❌ Skipping processor generation - missing name for processor`);
710
- return;
711
- } else if (!state.type) {
712
- logger.error(`❌ Skipping processor generation - missing type for processor "${state.name}"`);
713
- return;
714
- } else if (state.documentTypes.length === 0) {
715
- logger.error(`❌ Skipping processor generation - missing document types for processor "${state.name}"`);
716
- return;
717
- } else if (state.status !== "CONFIRMED") {
718
- logger.error(`❌ Skipping processor generation - processor "${state.name}" is not confirmed (status: ${state.status})`);
719
- return;
782
+ const reason = this.skipReason(input);
783
+ if (!state || reason) return { skipped: reason ?? "The processor has no state" };
784
+ const processorType = PROCESSOR_TYPES[state.type];
785
+ const processorApps = state.processorApps;
786
+ logger.info(`🔄 Starting processor generation for: ${state.name}`);
787
+ try {
788
+ await installFeatureDependencies$1(processorType === "analytics" ? ["analyticsProcessor"] : ["relationalDbProcessor"], this.config.CURRENT_WORKING_DIR, `processor "${state.name}"`, job);
789
+ await generateProcessor({
790
+ processorName: state.name,
791
+ processorType,
792
+ documentTypes: state.documentTypes.map((dt) => dt.documentType),
793
+ processorApps
794
+ }, this.project);
795
+ await this.project.save();
796
+ } catch (error) {
797
+ logger.error(`❌ Error during processor generation for ${state.name}:`, error);
798
+ throw error;
720
799
  }
800
+ logger.info(`✅ Processor generation completed successfully for: ${state.name}`);
801
+ await minimalBackupDocument({
802
+ documentId: input.documentId,
803
+ documentType: input.documentType,
804
+ branch: input.branch,
805
+ state: input.state,
806
+ name: state.name
807
+ }, this.config.CURRENT_WORKING_DIR);
721
808
  }
722
809
  };
810
+ function invalidReason(state) {
811
+ if (!state) return "The processor has no state";
812
+ if (!state.name) return "The processor has no name";
813
+ const processor = `Processor "${state.name}"`;
814
+ if (!state.type) return `${processor} has no type`;
815
+ if (!(state.type in PROCESSOR_TYPES)) return `${processor} has the unsupported type "${state.type}"; use ${Object.keys(PROCESSOR_TYPES).join(" or ")}`;
816
+ if (state.documentTypes.length === 0) return `${processor} has no document types`;
817
+ if (state.processorApps.length === 0) return `${processor} has no processor apps`;
818
+ if (!isProcessorApps(state.processorApps)) return `${processor} has unsupported processor apps (${state.processorApps.join(", ")}); use ${PROCESSOR_APPS.join(", ")}, each once`;
819
+ if (state.status !== "CONFIRMED") return `${processor} is not confirmed (status: ${state.status}); codegen runs once it is CONFIRMED`;
820
+ }
723
821
  function isProcessorApps(input) {
724
822
  if (input.length === 0) return false;
725
823
  if (new Set(input).size !== input.length) return false;
@@ -733,63 +831,48 @@ function isProcessorApps(input) {
733
831
  */
734
832
  var SubgraphGenerator = class extends BaseDocumentGen {
735
833
  supportedDocumentTypes = "powerhouse/subgraph";
736
- /**
737
- * Parse and extract the global state from the serialized state string
738
- */
739
834
  extractGlobalState(input) {
740
835
  if (!input.state) return;
741
836
  return input.state.global;
742
837
  }
743
- /**
744
- * Validate if this subgraph strand should be processed
745
- */
746
- shouldProcess(input) {
747
- if (!super.shouldProcess(input)) return false;
838
+ skipReason(input) {
839
+ const base = super.skipReason(input);
840
+ if (base) return base;
748
841
  const state = this.extractGlobalState(input);
749
- if (!state) {
750
- logger.debug(`No state found for subgraph: ${input.documentId}`);
751
- return false;
752
- }
753
- if (!state.name) {
754
- logger.debug(`No name found for subgraph: ${input.documentId}`);
755
- return false;
756
- }
757
- if (state.status !== "CONFIRMED") {
758
- logger.debug(`Subgraph not confirmed: ${state.name} (status: ${state.status})`);
759
- return false;
760
- }
761
- return true;
762
- }
763
- async generate(input) {
842
+ let reason;
843
+ if (!state) reason = "The subgraph has no state";
844
+ else if (!state.name) reason = "The subgraph has no name";
845
+ else if (state.status !== "CONFIRMED") reason = `Subgraph "${state.name}" is not confirmed (status: ${state.status}); codegen runs once it is CONFIRMED`;
846
+ if (reason) logger.debug(reason);
847
+ return reason;
848
+ }
849
+ async generate(input, job) {
764
850
  const state = this.extractGlobalState(input);
765
- if (!state) {
766
- logger.error(`No state found for subgraph: ${input.documentId}`);
767
- return;
768
- }
769
- if (state.name && state.status === "CONFIRMED") {
770
- logger.info(`🔄 Starting subgraph generation for: ${state.name}`);
771
- try {
772
- await generateSubgraph(state.name, this.project);
773
- await this.project.save();
774
- logger.info(`✅ Subgraph generation completed successfully for: ${state.name}`);
775
- const fullState = input.state;
776
- await minimalBackupDocument({
777
- documentId: input.documentId,
778
- documentType: input.documentType,
779
- branch: input.branch,
780
- state: fullState,
781
- name: state.name
782
- }, this.config.CURRENT_WORKING_DIR);
783
- } catch (error) {
784
- logger.error(`❌ Error during subgraph generation for ${state.name}:`, error);
851
+ const reason = this.skipReason(input);
852
+ if (!state || reason) return { skipped: reason ?? "The subgraph has no state" };
853
+ logger.info(`🔄 Starting subgraph generation for: ${state.name}`);
854
+ try {
855
+ const conflict = await findSubgraphNameConflict(this.config.CURRENT_WORKING_DIR, state.name);
856
+ if (conflict) {
857
+ logger.error(`❌ Skipping subgraph generation: ${conflict}`);
858
+ return { skipped: conflict };
785
859
  }
786
- } else if (!state.name) {
787
- logger.error(`❌ Skipping subgraph generation - missing name for subgraph`);
788
- return;
789
- } else if (state.status !== "CONFIRMED") {
790
- logger.error(`❌ Skipping subgraph generation - subgraph "${state.name}" is not confirmed (status: ${state.status})`);
791
- return;
860
+ await installFeatureDependencies$1(["subgraph"], this.config.CURRENT_WORKING_DIR, `subgraph "${state.name}"`, job);
861
+ await generateSubgraph(state.name, this.project);
862
+ await this.project.save();
863
+ } catch (error) {
864
+ logger.error(`❌ Error during subgraph generation for ${state.name}:`, error);
865
+ throw error;
792
866
  }
867
+ logger.info(`✅ Subgraph generation completed successfully for: ${state.name}`);
868
+ await warnSubgraphTypeConflicts(this.config.CURRENT_WORKING_DIR);
869
+ await minimalBackupDocument({
870
+ documentId: input.documentId,
871
+ documentType: input.documentType,
872
+ branch: input.branch,
873
+ state: input.state,
874
+ name: state.name
875
+ }, this.config.CURRENT_WORKING_DIR);
793
876
  }
794
877
  };
795
878
  //#endregion
@@ -802,8 +885,8 @@ var DocumentCodegenFactory = class {
802
885
  /**
803
886
  * Create a DocumentCodegenManager with all standard generators registered
804
887
  */
805
- static createManager(config, project, interactiveMode = false) {
806
- const manager = new DocumentCodegenManager(config, project, interactiveMode);
888
+ static createManager(config, project, interactiveMode = false, status) {
889
+ const manager = new DocumentCodegenManager(config, project, interactiveMode, status);
807
890
  manager.registerGenerator("powerhouse/document-model", DocumentModelGenerator);
808
891
  manager.registerGenerator("powerhouse/package", PackageGenerator);
809
892
  manager.registerGenerator("powerhouse/app", AppGenerator);
@@ -815,8 +898,8 @@ var DocumentCodegenFactory = class {
815
898
  /**
816
899
  * Create a DocumentCodegenManager with only specific generators
817
900
  */
818
- static createManagerWithGenerators(config, generators, project, interactiveMode = false) {
819
- const manager = new DocumentCodegenManager(config, project, interactiveMode);
901
+ static createManagerWithGenerators(config, generators, project, interactiveMode = false, status) {
902
+ const manager = new DocumentCodegenManager(config, project, interactiveMode, status);
820
903
  for (const generatorClass of generators) {
821
904
  const supportedTypes = new generatorClass(config).getSupportedDocumentTypes();
822
905
  for (const documentType of supportedTypes) manager.registerGenerator(documentType, generatorClass);
@@ -841,20 +924,26 @@ var DocumentCodegenFactory = class {
841
924
  //#region processors/codegen/processor.ts
842
925
  var processor_exports = /* @__PURE__ */ __exportAll({ CodegenProcessor: () => CodegenProcessor });
843
926
  var CodegenProcessor = class {
927
+ driveId;
928
+ client;
844
929
  manager;
845
- constructor(project, config, cwd, interactiveMode = false) {
930
+ constructor(project, config, cwd, driveId, client, interactiveMode = false) {
931
+ this.driveId = driveId;
932
+ this.client = client;
846
933
  this.manager = DocumentCodegenFactory.createManager({
847
934
  PH_CONFIG: config,
848
935
  CURRENT_WORKING_DIR: cwd
849
936
  }, project, interactiveMode);
937
+ this.manager.setScope((documentId) => this.isInDrive(documentId));
850
938
  if (interactiveMode) logger.info(`CodegenProcessor initialized with interactive mode enabled`);
851
939
  else logger.debug(`CodegenProcessor initialized with interactive mode disabled`);
852
940
  }
853
941
  async onOperations(operations) {
854
- logger.info("CodegenProcessor.onOperations()");
855
- for (const { context } of operations) {
856
- const generator = this.manager.getGenerator(context.documentType);
857
- if (!generator) {
942
+ logger.debug("CodegenProcessor.onOperations()");
943
+ const latest = /* @__PURE__ */ new Map();
944
+ for (const operation of operations) latest.set(operation.context.documentId, operation);
945
+ for (const { context } of latest.values()) {
946
+ if (!this.manager.getGenerator(context.documentType)) {
858
947
  logger.debug(`No generator found for document type: ${context.documentType}`);
859
948
  continue;
860
949
  }
@@ -865,7 +954,7 @@ var CodegenProcessor = class {
865
954
  branch: context.branch,
866
955
  state: context.resultingState ? JSON.parse(context.resultingState) : void 0
867
956
  };
868
- if (generator.shouldProcess(input)) await this.manager.routeAndGenerate(input);
957
+ await this.manager.routeAndGenerate(input);
869
958
  }
870
959
  }
871
960
  async onDisconnect() {}
@@ -878,8 +967,27 @@ var CodegenProcessor = class {
878
967
  isProcessingInteractive() {
879
968
  return this.manager.isProcessingInteractive();
880
969
  }
970
+ /**
971
+ * The reactor delivers every drive's operations, so membership is checked
972
+ * here: a node of the drive (in any folder, and in drives older than
973
+ * relationship edges), or a child edge from it (a document attached by
974
+ * relationship alone).
975
+ */
976
+ async isInDrive(documentId) {
977
+ try {
978
+ if ((await this.client.get(this.driveId)).state.global.nodes.some((node) => node.id === documentId)) return true;
979
+ } catch (error) {
980
+ logger.debug(`Could not read the Vetra drive ${this.driveId}:`, error);
981
+ }
982
+ try {
983
+ return (await this.client.getIncomingRelationshipEdges(documentId, "child")).results.some((edge) => edge.sourceId === this.driveId);
984
+ } catch (error) {
985
+ logger.debug(`Could not read the parents of ${documentId}:`, error);
986
+ return false;
987
+ }
988
+ }
881
989
  };
882
990
  //#endregion
883
991
  export { processor_exports as n, CodegenProcessor as t };
884
992
 
885
- //# sourceMappingURL=processor-trJFuoHh.js.map
993
+ //# sourceMappingURL=processor-C_zliXhw.js.map