@powerhousedao/vetra 6.2.3-dev.78 → 6.2.3-dev.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codegen/index.d.ts +2 -2
- package/dist/codegen/index.js +2 -2
- package/dist/codegen/spec.js +1 -1
- package/dist/document-models/app-module/index.d.ts +2 -2
- package/dist/document-models/app-module/index.js +1 -1
- package/dist/document-models/index.d.ts +2 -2
- package/dist/document-models/index.js +2 -2
- package/dist/document-models/processor-module/index.d.ts +3 -3
- package/dist/document-models/processor-module/index.js +4 -4
- package/dist/{editor-DbE7t0TU.js → editor-CbT_8Z6A.js} +2 -2
- package/dist/{editor-DbE7t0TU.js.map → editor-CbT_8Z6A.js.map} +1 -1
- package/dist/editors/index.d.ts +4 -4
- package/dist/editors/index.js +1 -1
- package/dist/{factory-BLQkEgxk.js → factory-BQp6QPQO.js} +15 -11
- package/dist/factory-BQp6QPQO.js.map +1 -0
- package/dist/{index-CKCays-S.d.ts → index-BAeTvhwh.d.ts} +2 -2
- package/dist/{index-CKCays-S.d.ts.map → index-BAeTvhwh.d.ts.map} +1 -1
- package/dist/{index-mYlWU47F.d.ts → index-CBcJ_oc6.d.ts} +2 -2
- package/dist/{index-mYlWU47F.d.ts.map → index-CBcJ_oc6.d.ts.map} +1 -1
- package/dist/{index-cdL5k2sw.d.ts → index-CScZx1m9.d.ts} +9 -3
- package/dist/index-CScZx1m9.d.ts.map +1 -0
- package/dist/{index-B52jv-LY.d.ts → index-DIpsNezM.d.ts} +2 -2
- package/dist/{index-B52jv-LY.d.ts.map → index-DIpsNezM.d.ts.map} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/{module-d1-9VDGb.js → module-23VayWKe.js} +5 -5
- package/dist/module-23VayWKe.js.map +1 -0
- package/dist/{module-CZLWjrD_.js → module-B6S4QGOx.js} +2 -2
- package/dist/{module-CZLWjrD_.js.map → module-B6S4QGOx.js.map} +1 -1
- package/dist/{module-Db8mmgzN.js → module-BktWa0rB.js} +11 -9
- package/dist/module-BktWa0rB.js.map +1 -0
- package/dist/{ph-factories-HuC7_vvF.js → ph-factories-fEke-Nr8.js} +2 -2
- package/dist/{ph-factories-HuC7_vvF.js.map → ph-factories-fEke-Nr8.js.map} +1 -1
- package/dist/{processor-kRJ48ypM.js → processor-C_zliXhw.js} +356 -322
- package/dist/processor-C_zliXhw.js.map +1 -0
- package/dist/processors/codegen/index.d.ts.map +1 -1
- package/dist/processors/codegen/index.js +2 -2
- package/dist/processors/index.js +1 -1
- package/dist/{spec-api-B01RpZM-.js → spec-api-BGj7gcQn.js} +16 -10
- package/dist/{spec-api-B01RpZM-.js.map → spec-api-BGj7gcQn.js.map} +1 -1
- package/dist/{switchboard-CZ87bHRJ.js → switchboard-DjCPLtMW.js} +2 -2
- package/dist/{switchboard-CZ87bHRJ.js.map → switchboard-DjCPLtMW.js.map} +1 -1
- package/dist/{utils-w_21RRK6.js → utils-BJk4_43W.js} +22 -2
- package/dist/utils-BJk4_43W.js.map +1 -0
- package/package.json +9 -9
- package/dist/factory-BLQkEgxk.js.map +0 -1
- package/dist/index-cdL5k2sw.d.ts.map +0 -1
- package/dist/module-Db8mmgzN.js.map +0 -1
- package/dist/module-d1-9VDGb.js.map +0 -1
- package/dist/processor-kRJ48ypM.js.map +0 -1
- package/dist/utils-w_21RRK6.js.map +0 -1
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { n as lintSubgraphTypes, t as findSubgraphNameConflict } from "./subgraph-type-lint-Dr8Wu0VB.js";
|
|
3
3
|
import { t as logger } from "./logger-BFxMdimR.js";
|
|
4
|
-
import { PROCESSOR_APPS } from "@powerhousedao/shared/processors";
|
|
5
|
-
import { generateApp, generateDocumentModel, generateEditor, generateProcessor, generateSubgraph, validateDocumentModelState } from "@powerhousedao/codegen";
|
|
4
|
+
import { PROCESSOR_APPS, getCodegenStatusRegistry } from "@powerhousedao/shared/processors";
|
|
5
|
+
import { afterPendingInstalls, generateApp, generateDocumentModel, generateEditor, generateProcessor, generateSubgraph, installFeatureDependencies, installsPending, validateDocumentModelState } from "@powerhousedao/codegen";
|
|
6
6
|
import { kebabCase } from "change-case";
|
|
7
7
|
import { baseMinimalSaveToFile } from "document-model/node";
|
|
8
|
-
import { mkdir } from "node:fs/promises";
|
|
9
|
-
import { join } from "node:path";
|
|
8
|
+
import { mkdir, readdir, stat } from "node:fs/promises";
|
|
9
|
+
import { join, relative } from "node:path";
|
|
10
10
|
import { createInterface } from "node:readline";
|
|
11
11
|
import { createOrUpdateManifest } from "@powerhousedao/codegen/file-builders";
|
|
12
12
|
//#region processors/codegen/document-handlers/base-document-gen.ts
|
|
13
|
-
/**
|
|
14
|
-
* Abstract base class for document generators
|
|
15
|
-
* Defines the interface that all document-type handlers must implement
|
|
16
|
-
*/
|
|
13
|
+
/** The base of the generators, one per document type or set of types. */
|
|
17
14
|
var BaseDocumentGen = class {
|
|
18
15
|
config;
|
|
19
16
|
project;
|
|
@@ -21,28 +18,26 @@ var BaseDocumentGen = class {
|
|
|
21
18
|
this.config = config;
|
|
22
19
|
this.project = project;
|
|
23
20
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Check if this generator supports the given document type
|
|
26
|
-
*/
|
|
27
21
|
supportsDocumentType(documentType) {
|
|
28
22
|
if (typeof this.supportedDocumentTypes === "string") return this.supportedDocumentTypes === documentType;
|
|
29
23
|
return this.supportedDocumentTypes.includes(documentType);
|
|
30
24
|
}
|
|
31
|
-
/**
|
|
32
|
-
* Get all supported document types as an array
|
|
33
|
-
*/
|
|
34
25
|
getSupportedDocumentTypes() {
|
|
35
26
|
if (typeof this.supportedDocumentTypes === "string") return [this.supportedDocumentTypes];
|
|
36
27
|
return [...this.supportedDocumentTypes];
|
|
37
28
|
}
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
}
|
|
42
39
|
shouldProcess(strand) {
|
|
43
|
-
|
|
44
|
-
if (!this.supportsDocumentType(strand.documentType)) return false;
|
|
45
|
-
return true;
|
|
40
|
+
return this.skipReason(strand) === void 0;
|
|
46
41
|
}
|
|
47
42
|
};
|
|
48
43
|
//#endregion
|
|
@@ -143,7 +138,7 @@ var InteractiveManager = class {
|
|
|
143
138
|
* Process all queued strands with a single user confirmation
|
|
144
139
|
* This is the main method for queue-based interactive processing
|
|
145
140
|
*/
|
|
146
|
-
async processQueueWithConfirmation(processor) {
|
|
141
|
+
async processQueueWithConfirmation(processor, onCancel) {
|
|
147
142
|
if (this.processingConfirmation) {
|
|
148
143
|
logger.debug("Already processing confirmation, skipping queue processing");
|
|
149
144
|
return;
|
|
@@ -157,7 +152,7 @@ var InteractiveManager = class {
|
|
|
157
152
|
try {
|
|
158
153
|
if (!await this.promptUserConfirmation()) {
|
|
159
154
|
logger.info("❌ Code generation cancelled by user");
|
|
160
|
-
this.clearQueue();
|
|
155
|
+
onCancel?.(this.clearQueue());
|
|
161
156
|
return;
|
|
162
157
|
}
|
|
163
158
|
queuedStrands = this.clearQueue();
|
|
@@ -187,8 +182,46 @@ var InteractiveManager = class {
|
|
|
187
182
|
}
|
|
188
183
|
};
|
|
189
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
|
|
190
217
|
//#region processors/codegen/document-handlers/document-codegen-manager.ts
|
|
191
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/;
|
|
192
225
|
/**
|
|
193
226
|
* Manager class responsible for routing documents to the correct generator
|
|
194
227
|
* and managing generator registration and instantiation
|
|
@@ -198,13 +231,19 @@ var DocumentCodegenManager = class {
|
|
|
198
231
|
project;
|
|
199
232
|
generators = /* @__PURE__ */ new Map();
|
|
200
233
|
debounceTimers = /* @__PURE__ */ new Map();
|
|
201
|
-
|
|
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;
|
|
202
239
|
interactiveManager;
|
|
203
240
|
isInScope = () => Promise.resolve(true);
|
|
204
|
-
|
|
241
|
+
status;
|
|
242
|
+
constructor(config, project, interactiveMode = false, status = getCodegenStatusRegistry()) {
|
|
205
243
|
this.config = config;
|
|
206
244
|
this.project = project;
|
|
207
245
|
this.interactiveManager = new InteractiveManager(interactiveMode);
|
|
246
|
+
this.status = status;
|
|
208
247
|
}
|
|
209
248
|
/**
|
|
210
249
|
* Limit generation to the documents `isInScope` accepts, checked when the
|
|
@@ -262,12 +301,17 @@ var DocumentCodegenManager = class {
|
|
|
262
301
|
logger.error("❌ Document type is missing from strand state");
|
|
263
302
|
throw new Error("Document type is missing from strand state");
|
|
264
303
|
}
|
|
265
|
-
|
|
266
|
-
if (!generator) {
|
|
304
|
+
if (!this.getGenerator(documentType)) {
|
|
267
305
|
logger.warn(`⚠️ No generator found for document type: ${documentType}`);
|
|
268
306
|
logger.warn(`ℹ️ Supported document types: ${this.getRegisteredDocumentTypes().join(", ")}`);
|
|
269
307
|
throw new Error(`Unsupported document type: ${documentType}`);
|
|
270
308
|
}
|
|
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
|
+
});
|
|
271
315
|
if (this.interactiveManager.isInteractive()) {
|
|
272
316
|
logger.debug(`>>> Queueing strand for interactive processing: ${documentType}:${strand.documentId}`);
|
|
273
317
|
this.interactiveManager.queueStrand(strand);
|
|
@@ -280,6 +324,8 @@ var DocumentCodegenManager = class {
|
|
|
280
324
|
this.interactiveManager.discardWhere((queued) => rejected.has(queued));
|
|
281
325
|
await this.interactiveManager.processQueueWithConfirmation(async (queuedStrands) => {
|
|
282
326
|
await this.processQueuedStrands(queuedStrands);
|
|
327
|
+
}, (cancelled) => {
|
|
328
|
+
for (const { strand } of cancelled) this.setStatus(strand, "skipped", "Cancelled in the terminal");
|
|
283
329
|
});
|
|
284
330
|
} catch (error) {
|
|
285
331
|
logger.error("❌ Error during interactive batch processing: @error", error);
|
|
@@ -296,10 +342,7 @@ var DocumentCodegenManager = class {
|
|
|
296
342
|
try {
|
|
297
343
|
if (!await this.accepts(strand)) return;
|
|
298
344
|
logger.debug(`🔄 Routing document type "${documentType}" to generator (debounced)`);
|
|
299
|
-
await
|
|
300
|
-
logger.debug(`✅ Successfully generated code for document type: ${documentType}`);
|
|
301
|
-
} catch (error) {
|
|
302
|
-
logger.error(`❌ Error generating code for document type "${documentType}":`, error);
|
|
345
|
+
await this.enqueueJob(strand);
|
|
303
346
|
} finally {
|
|
304
347
|
this.debounceTimers.delete(timerKey);
|
|
305
348
|
}
|
|
@@ -314,9 +357,92 @@ var DocumentCodegenManager = class {
|
|
|
314
357
|
if (!generator) return false;
|
|
315
358
|
if (!await this.isInScope(strand.documentId)) {
|
|
316
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);
|
|
317
368
|
return false;
|
|
318
369
|
}
|
|
319
|
-
return
|
|
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
|
+
});
|
|
320
446
|
}
|
|
321
447
|
/**
|
|
322
448
|
* Process multiple strands in priority order (document-model types first)
|
|
@@ -334,18 +460,12 @@ var DocumentCodegenManager = class {
|
|
|
334
460
|
*/
|
|
335
461
|
async processStrand(strand) {
|
|
336
462
|
const documentType = strand.documentType;
|
|
337
|
-
|
|
338
|
-
if (!generator) {
|
|
463
|
+
if (!this.getGenerator(documentType)) {
|
|
339
464
|
logger.warn(`⚠️ No generator found for document type: ${documentType}`);
|
|
340
465
|
return;
|
|
341
466
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
await generator.generate(strand);
|
|
345
|
-
logger.debug(`✅ Successfully generated code for document type: ${documentType}`);
|
|
346
|
-
} catch (error) {
|
|
347
|
-
logger.error(`❌ Error generating code for document type "${documentType}":`, error);
|
|
348
|
-
}
|
|
467
|
+
logger.debug(`🔄 Generating code for document type: ${documentType}`);
|
|
468
|
+
await this.enqueueJob(strand);
|
|
349
469
|
}
|
|
350
470
|
/**
|
|
351
471
|
* Clear all registered generators
|
|
@@ -382,6 +502,19 @@ var DocumentCodegenManager = class {
|
|
|
382
502
|
return this.interactiveManager.isProcessing();
|
|
383
503
|
}
|
|
384
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
|
+
}
|
|
385
518
|
//#endregion
|
|
386
519
|
//#region processors/codegen/document-handlers/generators/utils.ts
|
|
387
520
|
const BACKUP_FOLDER = "backup-documents";
|
|
@@ -416,6 +549,26 @@ async function warnSubgraphTypeConflicts(workingDir) {
|
|
|
416
549
|
}
|
|
417
550
|
for (const warning of warnings) logger.warn(`⚠️ ${warning}`);
|
|
418
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
|
+
}
|
|
419
572
|
//#endregion
|
|
420
573
|
//#region processors/codegen/document-handlers/generators/app-generator.ts
|
|
421
574
|
/**
|
|
@@ -423,71 +576,47 @@ async function warnSubgraphTypeConflicts(workingDir) {
|
|
|
423
576
|
*/
|
|
424
577
|
var AppGenerator = class extends BaseDocumentGen {
|
|
425
578
|
supportedDocumentTypes = "powerhouse/app";
|
|
426
|
-
/**
|
|
427
|
-
* Parse and extract the global state from the serialized state string
|
|
428
|
-
*/
|
|
429
579
|
extractGlobalState(input) {
|
|
430
580
|
if (!input.state) return;
|
|
431
581
|
return input.state.global;
|
|
432
582
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
shouldProcess(input) {
|
|
437
|
-
if (!super.shouldProcess(input)) return false;
|
|
583
|
+
skipReason(input) {
|
|
584
|
+
const base = super.skipReason(input);
|
|
585
|
+
if (base) return base;
|
|
438
586
|
const state = this.extractGlobalState(input);
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
}
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
return false;
|
|
446
|
-
}
|
|
447
|
-
if (state.status !== "CONFIRMED") {
|
|
448
|
-
logger.debug(`App not confirmed: ${state.name} (status: ${state.status})`);
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
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;
|
|
452
593
|
}
|
|
453
594
|
async generate(input) {
|
|
454
595
|
const state = this.extractGlobalState(input);
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
await this.project.save();
|
|
471
|
-
logger.info(`✅ App generation completed successfully for app: ${state.name}`);
|
|
472
|
-
const fullState = input.state;
|
|
473
|
-
await minimalBackupDocument({
|
|
474
|
-
documentId: input.documentId,
|
|
475
|
-
documentType: input.documentType,
|
|
476
|
-
branch: input.branch,
|
|
477
|
-
state: fullState,
|
|
478
|
-
name: state.name
|
|
479
|
-
}, this.config.CURRENT_WORKING_DIR);
|
|
480
|
-
} catch (error) {
|
|
481
|
-
logger.error(`❌ Error during app generation for app ${state.name}:`, error);
|
|
482
|
-
if (error instanceof Error) logger.error(`❌ Error message: ${error.message}`);
|
|
483
|
-
}
|
|
484
|
-
} else if (!state.name) {
|
|
485
|
-
logger.error(`❌ Skipping app generation - missing name for app`);
|
|
486
|
-
return;
|
|
487
|
-
} else if (state.status !== "CONFIRMED") {
|
|
488
|
-
logger.error(`❌ Skipping app generation - app "${state.name}" is not confirmed (status: ${state.status})`);
|
|
489
|
-
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;
|
|
490
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);
|
|
491
620
|
}
|
|
492
621
|
};
|
|
493
622
|
//#endregion
|
|
@@ -497,68 +626,46 @@ var AppGenerator = class extends BaseDocumentGen {
|
|
|
497
626
|
*/
|
|
498
627
|
var DocumentEditorGenerator = class extends BaseDocumentGen {
|
|
499
628
|
supportedDocumentTypes = "powerhouse/document-editor";
|
|
500
|
-
/**
|
|
501
|
-
* Parse and extract the global state from the serialized state string
|
|
502
|
-
*/
|
|
503
629
|
extractGlobalState(input) {
|
|
504
630
|
if (!input.state) return;
|
|
505
631
|
return input.state.global;
|
|
506
632
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
shouldProcess(input) {
|
|
511
|
-
if (!super.shouldProcess(input)) return false;
|
|
633
|
+
skipReason(input) {
|
|
634
|
+
const base = super.skipReason(input);
|
|
635
|
+
if (base) return base;
|
|
512
636
|
const state = this.extractGlobalState(input);
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
}
|
|
517
|
-
if (
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
}
|
|
521
|
-
if (!state.documentTypes || state.documentTypes.length === 0) {
|
|
522
|
-
logger.debug(`No document types found for document editor: ${state.name}`);
|
|
523
|
-
return false;
|
|
524
|
-
}
|
|
525
|
-
if (state.status !== "CONFIRMED") {
|
|
526
|
-
logger.debug(`Document editor not confirmed: ${state.name} (status: ${state.status})`);
|
|
527
|
-
return false;
|
|
528
|
-
}
|
|
529
|
-
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;
|
|
530
644
|
}
|
|
531
645
|
async generate(input) {
|
|
532
646
|
const state = this.extractGlobalState(input);
|
|
533
|
-
if (!state) {
|
|
534
|
-
logger.error(`No state found for document editor: ${input.documentId}`);
|
|
535
|
-
return;
|
|
536
|
-
}
|
|
647
|
+
if (!state) return { skipped: "The editor has no state" };
|
|
537
648
|
logger.info(`🔄 Starting editor generation for: ${state.name}`);
|
|
538
649
|
try {
|
|
539
|
-
const documentTypes = state.documentTypes.map((dt) => dt.documentType);
|
|
540
|
-
const editorId = kebabCase(state.name);
|
|
541
650
|
await generateEditor({
|
|
542
651
|
...this.config.PH_CONFIG,
|
|
543
652
|
editorName: state.name,
|
|
544
|
-
documentTypes,
|
|
545
|
-
editorId
|
|
653
|
+
documentTypes: state.documentTypes.map((dt) => dt.documentType),
|
|
654
|
+
editorId: kebabCase(state.name)
|
|
546
655
|
}, this.project);
|
|
547
656
|
await this.project.save();
|
|
548
|
-
logger.info(`✅ Editor generation completed successfully for: ${state.name}`);
|
|
549
|
-
const fullState = input.state;
|
|
550
|
-
await minimalBackupDocument({
|
|
551
|
-
documentId: input.documentId,
|
|
552
|
-
documentType: input.documentType,
|
|
553
|
-
branch: input.branch,
|
|
554
|
-
state: fullState,
|
|
555
|
-
name: state.name
|
|
556
|
-
}, this.config.CURRENT_WORKING_DIR);
|
|
557
657
|
} catch (error) {
|
|
558
658
|
logger.error(`❌ Error during editor generation for ${state.name}:`, error);
|
|
559
|
-
|
|
560
|
-
return;
|
|
659
|
+
throw error;
|
|
561
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);
|
|
562
669
|
}
|
|
563
670
|
};
|
|
564
671
|
//#endregion
|
|
@@ -568,57 +675,48 @@ var DocumentEditorGenerator = class extends BaseDocumentGen {
|
|
|
568
675
|
*/
|
|
569
676
|
var DocumentModelGenerator = class extends BaseDocumentGen {
|
|
570
677
|
supportedDocumentTypes = "powerhouse/document-model";
|
|
571
|
-
/**
|
|
572
|
-
* Parse and extract the global state from the serialized state string
|
|
573
|
-
*/
|
|
574
678
|
extractGlobalState(input) {
|
|
575
679
|
if (!input.state) return;
|
|
576
680
|
return input.state.global;
|
|
577
681
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
shouldProcess(input) {
|
|
582
|
-
if (!super.shouldProcess(input)) return false;
|
|
682
|
+
skipReason(input) {
|
|
683
|
+
const base = super.skipReason(input);
|
|
684
|
+
if (base) return base;
|
|
583
685
|
const globalState = this.extractGlobalState(input);
|
|
584
686
|
if (!globalState) {
|
|
585
687
|
logger.debug(`>>> No global state found for document model: ${input.documentId}`);
|
|
586
|
-
return
|
|
688
|
+
return "The document model has no global state";
|
|
587
689
|
}
|
|
588
690
|
const validationResult = validateDocumentModelState(globalState);
|
|
589
691
|
if (!validationResult.isValid) {
|
|
590
692
|
const errorList = validationResult.errors.map((error) => ` - ${error}`).join("\n");
|
|
591
693
|
logger.info(`⚠️ Skipped code generation for '${globalState.name || input.documentId}' due to validation errors:\n${errorList}`);
|
|
592
|
-
return
|
|
694
|
+
return `The document model is not ready for code generation:\n${errorList}`;
|
|
593
695
|
}
|
|
594
696
|
logger.info(`Document model ${globalState.name} is valid, proceeding with code generation`);
|
|
595
|
-
return true;
|
|
596
697
|
}
|
|
597
698
|
async generate(input) {
|
|
598
699
|
const globalState = this.extractGlobalState(input);
|
|
599
|
-
if (!globalState) {
|
|
600
|
-
logger.error(`❌ No global state found for document model: ${input.documentId}`);
|
|
601
|
-
return;
|
|
602
|
-
}
|
|
700
|
+
if (!globalState) throw new Error(`No global state found for document model: ${input.documentId}`);
|
|
603
701
|
logger.debug(`🔄 Starting code generation for document model: ${globalState.name}`);
|
|
604
702
|
try {
|
|
605
703
|
await generateDocumentModel(globalState, this.project);
|
|
606
704
|
await this.project.save();
|
|
607
|
-
logger.info(`✅ Code generation completed successfully for: ${globalState.name}`);
|
|
608
|
-
await warnSubgraphTypeConflicts(this.config.CURRENT_WORKING_DIR);
|
|
609
|
-
const fullState = input.state;
|
|
610
|
-
const extension = globalState.extension?.replace(/^\.+|\.+$/g, "") || "";
|
|
611
|
-
await minimalBackupDocument({
|
|
612
|
-
documentId: input.documentId,
|
|
613
|
-
documentType: input.documentType,
|
|
614
|
-
branch: input.branch,
|
|
615
|
-
state: fullState,
|
|
616
|
-
name: globalState.name
|
|
617
|
-
}, this.config.CURRENT_WORKING_DIR, extension);
|
|
618
705
|
} catch (error) {
|
|
619
706
|
logger.error(`❌ Error during code generation for ${globalState.name}:`, error);
|
|
620
|
-
|
|
707
|
+
throw error;
|
|
621
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);
|
|
622
720
|
}
|
|
623
721
|
};
|
|
624
722
|
//#endregion
|
|
@@ -628,16 +726,13 @@ var DocumentModelGenerator = class extends BaseDocumentGen {
|
|
|
628
726
|
*/
|
|
629
727
|
var PackageGenerator = class extends BaseDocumentGen {
|
|
630
728
|
supportedDocumentTypes = "powerhouse/package";
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
shouldProcess(input) {
|
|
635
|
-
if (!super.shouldProcess(input)) return false;
|
|
729
|
+
skipReason(input) {
|
|
730
|
+
const base = super.skipReason(input);
|
|
731
|
+
if (base) return base;
|
|
636
732
|
if (!input.state) {
|
|
637
733
|
logger.debug(`>>> No state found for package: ${input.documentId}`);
|
|
638
|
-
return
|
|
734
|
+
return "The package has no state";
|
|
639
735
|
}
|
|
640
|
-
return true;
|
|
641
736
|
}
|
|
642
737
|
async generate(input) {
|
|
643
738
|
const fullState = input.state;
|
|
@@ -662,107 +757,67 @@ var PackageGenerator = class extends BaseDocumentGen {
|
|
|
662
757
|
};
|
|
663
758
|
//#endregion
|
|
664
759
|
//#region processors/codegen/document-handlers/generators/processor-generator.ts
|
|
760
|
+
const PROCESSOR_TYPES = {
|
|
761
|
+
analytics: "analytics",
|
|
762
|
+
relational: "relationalDb"
|
|
763
|
+
};
|
|
665
764
|
/**
|
|
666
765
|
* Generator for processor documents
|
|
667
766
|
*/
|
|
668
767
|
var ProcessorGenerator = class extends BaseDocumentGen {
|
|
669
768
|
supportedDocumentTypes = "powerhouse/processor";
|
|
670
|
-
/**
|
|
671
|
-
* Parse and extract the global state from the serialized state string
|
|
672
|
-
*/
|
|
673
769
|
extractGlobalState(input) {
|
|
674
770
|
if (!input.state) return;
|
|
675
771
|
return input.state.global;
|
|
676
772
|
}
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
if (
|
|
682
|
-
|
|
683
|
-
if (!state) {
|
|
684
|
-
logger.debug(`No state found for processor: ${input.documentId}`);
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
if (!state.name) {
|
|
688
|
-
logger.debug(`No name found for processor: ${input.documentId}`);
|
|
689
|
-
return false;
|
|
690
|
-
}
|
|
691
|
-
if (!state.type) {
|
|
692
|
-
logger.debug(`No type found for processor: ${state.name}`);
|
|
693
|
-
return false;
|
|
694
|
-
}
|
|
695
|
-
if (!state.documentTypes || state.documentTypes.length === 0) {
|
|
696
|
-
logger.debug(`No document types found for processor: ${state.name}`);
|
|
697
|
-
return false;
|
|
698
|
-
}
|
|
699
|
-
if (!state.processorApps || state.processorApps.length === 0) {
|
|
700
|
-
logger.debug(`No processor apps found for processor: ${state.name}`);
|
|
701
|
-
return false;
|
|
702
|
-
}
|
|
703
|
-
if (state.status !== "CONFIRMED") {
|
|
704
|
-
logger.debug(`Processor not confirmed: ${state.name} (status: ${state.status})`);
|
|
705
|
-
return false;
|
|
706
|
-
}
|
|
707
|
-
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;
|
|
708
779
|
}
|
|
709
|
-
async generate(input) {
|
|
780
|
+
async generate(input, job) {
|
|
710
781
|
const state = this.extractGlobalState(input);
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
logger.error(`❌ Unsupported processor apps: ${processorApps.join(", ")}`);
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
await generateProcessor({
|
|
732
|
-
processorName: state.name,
|
|
733
|
-
processorType,
|
|
734
|
-
documentTypes,
|
|
735
|
-
processorApps
|
|
736
|
-
}, this.project);
|
|
737
|
-
await this.project.save();
|
|
738
|
-
logger.info(`✅ Processor generation completed successfully for: ${state.name}`);
|
|
739
|
-
const fullState = input.state;
|
|
740
|
-
await minimalBackupDocument({
|
|
741
|
-
documentId: input.documentId,
|
|
742
|
-
documentType: input.documentType,
|
|
743
|
-
branch: input.branch,
|
|
744
|
-
state: fullState,
|
|
745
|
-
name: state.name
|
|
746
|
-
}, this.config.CURRENT_WORKING_DIR);
|
|
747
|
-
} catch (error) {
|
|
748
|
-
logger.error(`❌ Error during processor generation for ${state.name}:`, error);
|
|
749
|
-
if (error instanceof Error) logger.error(`❌ Error message: ${error.message}`);
|
|
750
|
-
}
|
|
751
|
-
} else if (!state.name) {
|
|
752
|
-
logger.error(`❌ Skipping processor generation - missing name for processor`);
|
|
753
|
-
return;
|
|
754
|
-
} else if (!state.type) {
|
|
755
|
-
logger.error(`❌ Skipping processor generation - missing type for processor "${state.name}"`);
|
|
756
|
-
return;
|
|
757
|
-
} else if (state.documentTypes.length === 0) {
|
|
758
|
-
logger.error(`❌ Skipping processor generation - missing document types for processor "${state.name}"`);
|
|
759
|
-
return;
|
|
760
|
-
} else if (state.status !== "CONFIRMED") {
|
|
761
|
-
logger.error(`❌ Skipping processor generation - processor "${state.name}" is not confirmed (status: ${state.status})`);
|
|
762
|
-
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;
|
|
763
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);
|
|
764
808
|
}
|
|
765
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
|
+
}
|
|
766
821
|
function isProcessorApps(input) {
|
|
767
822
|
if (input.length === 0) return false;
|
|
768
823
|
if (new Set(input).size !== input.length) return false;
|
|
@@ -776,69 +831,48 @@ function isProcessorApps(input) {
|
|
|
776
831
|
*/
|
|
777
832
|
var SubgraphGenerator = class extends BaseDocumentGen {
|
|
778
833
|
supportedDocumentTypes = "powerhouse/subgraph";
|
|
779
|
-
/**
|
|
780
|
-
* Parse and extract the global state from the serialized state string
|
|
781
|
-
*/
|
|
782
834
|
extractGlobalState(input) {
|
|
783
835
|
if (!input.state) return;
|
|
784
836
|
return input.state.global;
|
|
785
837
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
shouldProcess(input) {
|
|
790
|
-
if (!super.shouldProcess(input)) return false;
|
|
838
|
+
skipReason(input) {
|
|
839
|
+
const base = super.skipReason(input);
|
|
840
|
+
if (base) return base;
|
|
791
841
|
const state = this.extractGlobalState(input);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
}
|
|
796
|
-
if (
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
if (state.status !== "CONFIRMED") {
|
|
801
|
-
logger.debug(`Subgraph not confirmed: ${state.name} (status: ${state.status})`);
|
|
802
|
-
return false;
|
|
803
|
-
}
|
|
804
|
-
return true;
|
|
805
|
-
}
|
|
806
|
-
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) {
|
|
807
850
|
const state = this.extractGlobalState(input);
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
if (conflict) {
|
|
817
|
-
logger.error(`❌ Skipping subgraph generation: ${conflict}`);
|
|
818
|
-
return;
|
|
819
|
-
}
|
|
820
|
-
await generateSubgraph(state.name, this.project);
|
|
821
|
-
await this.project.save();
|
|
822
|
-
logger.info(`✅ Subgraph generation completed successfully for: ${state.name}`);
|
|
823
|
-
await warnSubgraphTypeConflicts(this.config.CURRENT_WORKING_DIR);
|
|
824
|
-
const fullState = input.state;
|
|
825
|
-
await minimalBackupDocument({
|
|
826
|
-
documentId: input.documentId,
|
|
827
|
-
documentType: input.documentType,
|
|
828
|
-
branch: input.branch,
|
|
829
|
-
state: fullState,
|
|
830
|
-
name: state.name
|
|
831
|
-
}, this.config.CURRENT_WORKING_DIR);
|
|
832
|
-
} catch (error) {
|
|
833
|
-
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 };
|
|
834
859
|
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
logger.error(`❌
|
|
840
|
-
|
|
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;
|
|
841
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);
|
|
842
876
|
}
|
|
843
877
|
};
|
|
844
878
|
//#endregion
|
|
@@ -851,8 +885,8 @@ var DocumentCodegenFactory = class {
|
|
|
851
885
|
/**
|
|
852
886
|
* Create a DocumentCodegenManager with all standard generators registered
|
|
853
887
|
*/
|
|
854
|
-
static createManager(config, project, interactiveMode = false) {
|
|
855
|
-
const manager = new DocumentCodegenManager(config, project, interactiveMode);
|
|
888
|
+
static createManager(config, project, interactiveMode = false, status) {
|
|
889
|
+
const manager = new DocumentCodegenManager(config, project, interactiveMode, status);
|
|
856
890
|
manager.registerGenerator("powerhouse/document-model", DocumentModelGenerator);
|
|
857
891
|
manager.registerGenerator("powerhouse/package", PackageGenerator);
|
|
858
892
|
manager.registerGenerator("powerhouse/app", AppGenerator);
|
|
@@ -864,8 +898,8 @@ var DocumentCodegenFactory = class {
|
|
|
864
898
|
/**
|
|
865
899
|
* Create a DocumentCodegenManager with only specific generators
|
|
866
900
|
*/
|
|
867
|
-
static createManagerWithGenerators(config, generators, project, interactiveMode = false) {
|
|
868
|
-
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);
|
|
869
903
|
for (const generatorClass of generators) {
|
|
870
904
|
const supportedTypes = new generatorClass(config).getSupportedDocumentTypes();
|
|
871
905
|
for (const documentType of supportedTypes) manager.registerGenerator(documentType, generatorClass);
|
|
@@ -956,4 +990,4 @@ var CodegenProcessor = class {
|
|
|
956
990
|
//#endregion
|
|
957
991
|
export { processor_exports as n, CodegenProcessor as t };
|
|
958
992
|
|
|
959
|
-
//# sourceMappingURL=processor-
|
|
993
|
+
//# sourceMappingURL=processor-C_zliXhw.js.map
|