@powerhousedao/codegen 6.0.0-dev.195 → 6.0.0-dev.197
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/{file-builders-_tcDYQmm.mjs → file-builders-Cfc3km_-.mjs} +92 -12
- package/dist/file-builders-Cfc3km_-.mjs.map +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +157 -157
- package/dist/index.mjs.map +1 -1
- package/dist/src/file-builders/index.mjs +1 -1
- package/dist/src/name-builders/index.mjs +1 -1
- package/dist/src/templates/index.mjs +1 -1
- package/dist/src/utils/index.d.mts +39 -1
- package/dist/src/utils/index.d.mts.map +1 -1
- package/dist/src/utils/index.mjs +2 -2
- package/package.json +4 -3
- package/dist/file-builders-_tcDYQmm.mjs.map +0 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { DocumentModelGlobalStateSchema, ManifestSchema } from "@powerhousedao/shared/document-model";
|
|
2
2
|
import { camelCase, capitalCase, constantCase, kebabCase, pascalCase } from "change-case";
|
|
3
3
|
import path, { join } from "path";
|
|
4
|
-
import { capitalize, concat, filter, find, flatMap, forEach, fromEntries, isIncludedIn, isNonNullish, isString, isTruthy, last, map, merge, pipe, prop, sort, subtract, unique, uniqueBy, when } from "remeda";
|
|
4
|
+
import { capitalize, concat, conditional, constant, filter, find, first, flatMap, forEach, fromEntries, isDefined, isIncludedIn, isNonNullish, isNot, isStrictEqual, isString, isTruthy, last, map, merge, pipe, prop, sort, split, startsWith, subtract, unique, uniqueBy, when } from "remeda";
|
|
5
5
|
import { IndentationText, Project, SyntaxKind, VariableDeclarationKind, ts } from "ts-morph";
|
|
6
6
|
import arg from "arg";
|
|
7
|
-
import { readdirSync
|
|
8
|
-
import {
|
|
9
|
-
import { VERSIONED_DEPENDENCIES, VERSIONED_DEV_DEPENDENCIES, directoryExists, fileExists, makeVersionedDependencies, spawnAsync, writeFileEnsuringDir } from "@powerhousedao/shared/clis";
|
|
7
|
+
import { readdirSync } from "fs";
|
|
8
|
+
import { VERSIONED_DEPENDENCIES, VERSIONED_DEV_DEPENDENCIES, directoryExists, fileExists, fileExistsSync, isDirectory, makeVersionedDependencies, spawnAsync, writeFileEnsuringDir } from "@powerhousedao/shared/clis";
|
|
10
9
|
import { format } from "prettier";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { loadJsonFile, loadJsonFileSync } from "load-json-file";
|
|
11
12
|
import fs, { copyFile, mkdir, readdir, writeFile } from "node:fs/promises";
|
|
12
13
|
import { stripVTControlCharacters } from "node:util";
|
|
13
14
|
import path$1, { join as join$1, relative } from "node:path";
|
|
@@ -4297,9 +4298,9 @@ const exportsTemplate = json`
|
|
|
4297
4298
|
"node": "./dist/node/editors/index.mjs"
|
|
4298
4299
|
},
|
|
4299
4300
|
"./editors/*": {
|
|
4300
|
-
"types": "./dist/editors/*/
|
|
4301
|
-
"browser": "./dist/browser/editors/*/
|
|
4302
|
-
"node": "./dist/node/editors/*/
|
|
4301
|
+
"types": "./dist/editors/*/editor.d.ts",
|
|
4302
|
+
"browser": "./dist/browser/editors/*/editor.js",
|
|
4303
|
+
"node": "./dist/node/editors/*/editor.mjs"
|
|
4303
4304
|
},
|
|
4304
4305
|
"./subgraphs": {
|
|
4305
4306
|
"types": "./dist/subgraphs/index.d.ts",
|
|
@@ -5516,7 +5517,7 @@ export function createGlobalState(
|
|
|
5516
5517
|
return {
|
|
5517
5518
|
...defaultGlobalState(),
|
|
5518
5519
|
...(state || {}),
|
|
5519
|
-
}
|
|
5520
|
+
};
|
|
5520
5521
|
}
|
|
5521
5522
|
|
|
5522
5523
|
export function createLocalState(
|
|
@@ -6488,7 +6489,7 @@ const documentModelDocumentTypeMetadata = {
|
|
|
6488
6489
|
*/
|
|
6489
6490
|
function getDocumentTypeMetadata({ project, documentModelId }) {
|
|
6490
6491
|
const { directory: documentModelsDir } = getOrCreateDirectory(project, "document-models");
|
|
6491
|
-
const documentModelVariableNames = pipe(readdirSync(documentModelsDir.getPath(), { withFileTypes: true }),
|
|
6492
|
+
const documentModelVariableNames = pipe(readdirSync(documentModelsDir.getPath(), { withFileTypes: true }), map(loadDocumentModelInDir), filter(isDefined), filter((state) => isStrictEqual(state.id, documentModelId)), first(), prop("name"), when(isString, getDocumentModelVariableNames));
|
|
6492
6493
|
if (!documentModelVariableNames) throw new Error(`Failed to get document type metadata for document type: ${documentModelId}.`);
|
|
6493
6494
|
const { kebabCaseDocumentType, phDocumentTypeName } = documentModelVariableNames;
|
|
6494
6495
|
return {
|
|
@@ -6522,6 +6523,53 @@ async function runPrettier() {
|
|
|
6522
6523
|
]);
|
|
6523
6524
|
}
|
|
6524
6525
|
//#endregion
|
|
6526
|
+
//#region src/utils/get-editor-metadata.ts
|
|
6527
|
+
const EditorMetadataSchema = z.object({
|
|
6528
|
+
name: z.string(),
|
|
6529
|
+
id: z.string(),
|
|
6530
|
+
dirName: z.string(),
|
|
6531
|
+
documentTypes: z.array(z.string())
|
|
6532
|
+
});
|
|
6533
|
+
function getEditorMetadata(project, dirName) {
|
|
6534
|
+
const { directory: editorDir } = getOrCreateDirectory(project, join("editors", dirName));
|
|
6535
|
+
const parsedMetadata = pipe(editorDir, (dir) => dir.getSourceFile("module.ts"), (sourceFile) => ({
|
|
6536
|
+
dirName: sourceFile?.getDirectory().getBaseName(),
|
|
6537
|
+
id: getStringPropertyValue(sourceFile, "id"),
|
|
6538
|
+
name: getStringPropertyValue(sourceFile, "name"),
|
|
6539
|
+
documentTypes: getStringArrayPropertyElements(sourceFile, "documentTypes")
|
|
6540
|
+
}), (data) => EditorMetadataSchema.safeParse(data));
|
|
6541
|
+
if (parsedMetadata.success) return parsedMetadata.data;
|
|
6542
|
+
}
|
|
6543
|
+
function getAppMetadata(project, dirName) {
|
|
6544
|
+
const editorMetadata = getEditorMetadata(project, dirName);
|
|
6545
|
+
if (!editorMetadata || isIncludedIn("powerhouse/document-drive", editorMetadata.documentTypes)) return void 0;
|
|
6546
|
+
return merge(editorMetadata, pipe(project.getSourceFile(join("editors", dirName, "config.ts")), (sourceFile) => ({
|
|
6547
|
+
isDragAndDropEnabled: getBooleanPropertyValue(sourceFile, "isDragAndDropEnabled", true),
|
|
6548
|
+
allowedDocumentTypes: getStringArrayPropertyElements(sourceFile, "allowedDocumentTypes")
|
|
6549
|
+
})));
|
|
6550
|
+
}
|
|
6551
|
+
//#endregion
|
|
6552
|
+
//#region src/utils/get-processor-metadata.ts
|
|
6553
|
+
function getProcessorMetadata(project, dirName) {
|
|
6554
|
+
const { directory: processorsDir } = getOrCreateDirectory(project, "processors");
|
|
6555
|
+
const { directory: processorDir } = getOrCreateDirectory(project, join("processors", dirName));
|
|
6556
|
+
const connectProcessorNames = getProcessorNames(processorsDir.getSourceFile("connect.ts"));
|
|
6557
|
+
const switchboardProcessorNames = getProcessorNames(processorsDir.getSourceFile("switchboard.ts"));
|
|
6558
|
+
return pipe(dirName, (dirName) => ({
|
|
6559
|
+
processorName: dirName,
|
|
6560
|
+
processorApps: conditional(dirName, [isNot(isIncludedIn(connectProcessorNames)), constant(["switchboard"])], [isNot(isIncludedIn(switchboardProcessorNames)), constant(["connect"])], constant(["switchboard", "connect"])),
|
|
6561
|
+
processorType: pipe(processorDir.getSourceFile("processor.ts") ?? processorDir.getSourceFile("index.ts"), getAllImportNames, conditional([(specifiers) => isIncludedIn("RelationalDbProcessor", specifiers), constant("relationalDb")], [(specifiers) => isIncludedIn("IAnalyticsStore", specifiers), constant("analytics")], constant("analytics"))),
|
|
6562
|
+
documentTypes: getStringArrayPropertyElements(processorDir.getSourceFile("factory.ts"), "documentTypes")
|
|
6563
|
+
}));
|
|
6564
|
+
}
|
|
6565
|
+
const getProcessorNames = (sourceFile) => pipe(sourceFile, getAllImportModuleSpecifiers, filter(startsWith("processors/")), map(split("/")), map((s) => s.at(1)), filter(isString));
|
|
6566
|
+
//#endregion
|
|
6567
|
+
//#region src/utils/get-subgraph-metadata.ts
|
|
6568
|
+
function getSubgraphMetadata(project, dirName) {
|
|
6569
|
+
const { directory: subgraphDir } = getOrCreateDirectory(project, join("subgraphs", dirName));
|
|
6570
|
+
return pipe(subgraphDir.getSourceFile("index.ts")?.getClasses() ?? [], find((classDeclaration) => classDeclaration.getBaseClass()?.getText().includes("BaseSubgraph") ?? false), (classDeclaration) => classDeclaration?.getInstanceProperty("name")?.asKind(SyntaxKind.PropertyDeclaration)?.getInitializerIfKind(SyntaxKind.StringLiteral)?.getLiteralValue(), (subgraphName) => ({ subgraphName }));
|
|
6571
|
+
}
|
|
6572
|
+
//#endregion
|
|
6525
6573
|
//#region src/utils/source-files.ts
|
|
6526
6574
|
/** Gets a SourceFile by name in a ts-morph Project, or creates a new one
|
|
6527
6575
|
* if none with that path exists.
|
|
@@ -6644,6 +6692,34 @@ function getVariableDeclarationByTypeName(sourceFile, typeName) {
|
|
|
6644
6692
|
return declaration.getType().getText().includes(typeName);
|
|
6645
6693
|
});
|
|
6646
6694
|
}
|
|
6695
|
+
function getProperyAssignmentByName(sourceFile, propertyName) {
|
|
6696
|
+
if (!isDefined(sourceFile)) return void 0;
|
|
6697
|
+
return find(sourceFile.getDescendantsOfKind(SyntaxKind.PropertyAssignment), (assignment) => isStrictEqual(assignment.getName(), propertyName));
|
|
6698
|
+
}
|
|
6699
|
+
function getStringPropertyValue(sourceFile, propertyName) {
|
|
6700
|
+
return getProperyAssignmentByName(sourceFile, propertyName)?.getFirstDescendantByKind(SyntaxKind.StringLiteral)?.getLiteralValue();
|
|
6701
|
+
}
|
|
6702
|
+
function getStringArrayPropertyElements(sourceFile, propertyName) {
|
|
6703
|
+
return pipe(getProperyAssignmentByName(sourceFile, propertyName)?.getFirstDescendantByKind(SyntaxKind.ArrayLiteralExpression)?.getElements() ?? [], map((element) => element.asKind(SyntaxKind.StringLiteral)?.getLiteralValue()), filter(isString));
|
|
6704
|
+
}
|
|
6705
|
+
function getBooleanPropertyValue(sourceFile, propertyName, fallback) {
|
|
6706
|
+
return pipe(getProperyAssignmentByName(sourceFile, propertyName)?.getDescendants() ?? [], map((descendant) => descendant.getKind()), conditional([(kinds) => isIncludedIn(SyntaxKind.TrueKeyword, kinds), constant(true)], [(kinds) => isIncludedIn(SyntaxKind.FalseKeyword, kinds), constant(false)], constant(fallback)));
|
|
6707
|
+
}
|
|
6708
|
+
function loadDocumentModelInDir(dirent) {
|
|
6709
|
+
if (!isDirectory(dirent)) return void 0;
|
|
6710
|
+
const parseResult = pipe(dirent, (dir) => path.join(dir.parentPath, `${dir.name}/${dir.name}.json`), when(fileExistsSync, loadJsonFileSync), (stateFile) => DocumentModelGlobalStateSchema().safeParse(stateFile));
|
|
6711
|
+
if (!parseResult.success) {
|
|
6712
|
+
console.error(parseResult.error);
|
|
6713
|
+
return;
|
|
6714
|
+
}
|
|
6715
|
+
return parseResult.data;
|
|
6716
|
+
}
|
|
6717
|
+
function getAllImportNames(sourceFile) {
|
|
6718
|
+
return pipe(sourceFile?.getImportDeclarations() ?? [], flatMap((importDeclaration) => importDeclaration.getNamedImports()), map((importSpecifier) => importSpecifier.getText()));
|
|
6719
|
+
}
|
|
6720
|
+
function getAllImportModuleSpecifiers(sourceFile) {
|
|
6721
|
+
return pipe(sourceFile?.getImportDeclarations() ?? [], flatMap((importDeclaration) => importDeclaration.getModuleSpecifier().getLiteralValue()));
|
|
6722
|
+
}
|
|
6647
6723
|
//#endregion
|
|
6648
6724
|
//#region src/utils/ts-morph-project.ts
|
|
6649
6725
|
const DEFAULT_PROJECT_OPTIONS = {
|
|
@@ -7289,7 +7365,11 @@ async function generateTypesAndZodSchemasFromGraphql(args) {
|
|
|
7289
7365
|
[`${schemaDirPath}/zod.ts`]: {
|
|
7290
7366
|
schema,
|
|
7291
7367
|
config: validationSchemaConfig,
|
|
7292
|
-
plugins: [
|
|
7368
|
+
plugins: [
|
|
7369
|
+
{ add: { content: "/* eslint-disable @typescript-eslint/no-empty-object-type */" } },
|
|
7370
|
+
{ add: { content: "/* eslint-disable @typescript-eslint/no-unused-vars */" } },
|
|
7371
|
+
{ "graphql-codegen-typescript-validation-schema": validationSchemaConfig }
|
|
7372
|
+
]
|
|
7293
7373
|
}
|
|
7294
7374
|
}
|
|
7295
7375
|
}, true);
|
|
@@ -8322,6 +8402,6 @@ async function makeSubgraphsIndexFile(args) {
|
|
|
8322
8402
|
await formatSourceFileWithPrettier(sourceFile);
|
|
8323
8403
|
}
|
|
8324
8404
|
//#endregion
|
|
8325
|
-
export {
|
|
8405
|
+
export { getProperyAssignmentByName as $, documentModelsTemplate as $n, documentModelGenReducerFileTemplate as $t, writeAllGeneratedProjectFiles as A, styleTemplate as An, relationalDbFactoryTemplate as At, makeEditorModuleFile as B, mainTsxTemplate as Bn, documentModelOperationsModuleTestFileTemplate as Bt, rootExportPaths as C, documentEditorModuleFileTemplate as Cn, customSubgraphSchemaTemplate as Ct, writeCliDocsMarkdownFile as D, tsConfigTemplate as Dn, relationalDbProcessorTemplate as Dt, makeCliDocsFromHelp as E, vitestConfigTemplate as En, relationalDbSchemaTemplate as Et, writeGeneratedProjectRootFiles as F, packageJsonScriptsTemplate as Fn, analyticsIndexTemplate as Ft, DEFAULT_PROJECT_OPTIONS as G, gitIgnoreTemplate as Gn, documentModelSrcUtilsTemplate as Gt, makeEditorsIndexFile as H, indexTsTemplate as Hn, makeOperationsImports as Ht, writeGeneratedSubgraphsFiles as I, exportsTemplate as In, analyticsFactoryTemplate as It, getAllImportModuleSpecifiers as J, eslintConfigTemplate as Jn, documentModelIndexTemplate as Jt, buildTsMorphProject as K, syncAndPublishWorkflowTemplate as Kn, documentModelSrcIndexFileTemplate as Kt, writeModuleFiles as L, packageJsonTemplate as Ln, documentModelUtilsTemplate as Lt, writeGeneratedDocumentModelsFiles as M, ManifestTemplate as Mn, processorsFactoryTemplate as Mt, writeGeneratedEditorsFiles as N, buildPowerhouseConfigTemplate as Nn, factoryBuildersTemplate as Nt, buildBoilerplatePackageJson as O, tsconfigPathsTemplate as On, relationalDbMigrationsTemplate as Ot, writeGeneratedProcessorsFiles as P, packageJsonExportsTemplate as Pn, analyticsProcessorTemplate as Pt, getObjectProperty as Q, documentModelsIndexTemplate as Qn, documentModelSchemaIndexTemplate as Qt, writeProjectRootFiles as R, npmrcTemplate as Rn, upgradeTransitionTemplate as Rt, packageScripts as S, documentModelRootActionsFileTemplate as Sn, customSubgraphResolversTemplate as St, getCommandsHelpInfo as T, docsFromCliHelpTemplate as Tn, subgraphIndexFileTemplate as Tt, validateDocumentModelState as U, legacyIndexHtmlTemplate as Un, makeTestCaseForOperation as Ut, makeEditorsFile as V, licenseTemplate as Vn, makeOperationImportNames as Vt, getInitialStates as W, indexHtmlTemplate as Wn, documentModelTestFileTemplate as Wt, getBooleanPropertyValue as X, editorsTemplate as Xn, documentModelGenUtilsTemplate as Xt, getAllImportNames as Y, editorsIndexTemplate as Yn, documentModelHooksFileTemplate as Yt, getObjectLiteral as Z, upgradeManifestsTemplate as Zn, documentModelGenTypesTemplate as Zt, defaultManifest as _, documentModelDocumentTypeTemplate as _n, getDocumentTypeMetadata as _t, createOrUpdateManifest as a, getModuleExportType as an, claudeSettingsLocalTemplate as ar, buildStringLiteral as at, externalDevDependencies as b, documentModelGenControllerFileTemplate as bn, parseArgs as bt, operationHasAttachment as c, getDocumentModelVariableNames as cn, appConfigFileTemplate as cr, getOrCreateSourceFile as ct, tsMorphGenerateDocumentModel as d, getLatestDocumentModelSpecVersionNumber as dn, appFoldersFileTemplate as dr, getProcessorMetadata as dt, documentModelPhFactoriesFileTemplate as en, switchboardEntrypointTemplate as er, getStringArrayPropertyElements as et, generateDocumentModelZodSchemas as f, getActionInputName as fn, appFilesFileTemplate as fr, getAppMetadata as ft, tsMorphGenerateDocumentEditor as g, documentModelGenIndexFileTemplate as gn, createDocumentFileTemplate as gr, runPrettier as gt, scalarsValidation as h, getActionTypeName as hn, appDriveContentsFileTemplate as hr, formatSourceFileWithPrettier as ht, makePackageJsonExports as i, documentModelOperationModuleActionsFileTemplate as in, cursorMcpTemplate as ir, buildObjectLiteral as it, writeCIFiles as j, readmeTemplate as jn, processorsIndexTemplate as jt, writeAiConfigFiles as k, subgraphsIndexTemplate as kn, relationalDbIndexTemplate as kt, operationHasEmptyInput as l, getEditorVariableNames as ln, driveExplorerNavigationBreadcrumbsFileTemplate as lr, getPreviousVersionSourceFile as lt, scalars as m, getActionType as mn, driveExplorerFileTemplate as mr, formatSafe as mt, tsMorphGenerateSubgraph as n, documentModelOperationsModuleErrorFileTemplate as nn, dockerfileTemplate as nr, getVariableDeclarationByTypeName as nt, getOrCreateManifestFile as o, getDocumentModelDirName as on, agentsTemplate as or, ensureDirectoriesExist as ot, generateTypesAndZodSchemasFromGraphql as p, getActionInputTypeNames as pn, emptyStateFileTemplate as pr, getEditorMetadata as pt, getDefaultProjectOptions as q, geminiSettingsTemplate as qn, documentModelModuleFileTemplate as qt, tsMorphGenerateProcessor as r, documentModelOperationsModuleCreatorsFileTemplate as rn, connectEntrypointTemplate as rr, loadDocumentModelInDir as rt, makeModulesIndexFile as s, getDocumentModelSpecByVersionNumber as sn, appEditorFileTemplate as sr, getOrCreateDirectory as st, makeSubgraphsIndexFile as t, documentModelOperationsModuleOperationsFileTemplate as tn, nginxConfTemplate as tr, getStringPropertyValue as tt, operationHasInput as u, getLatestDocumentModelSpec as un, folderTreeFileTemplate as ur, getSubgraphMetadata as ut, exportPaths as v, documentModelDocumentSchemaFileTemplate as vn, documentModelDocumentTypeMetadata as vt, getCommandHelpInfo as w, documentEditorEditorFileTemplate as wn, subgraphLibFileTemplate as wt, nonStandardExportPaths as x, documentModelGenActionsFileTemplate as xn, parseConfig as xt, externalDependencies as y, documentModelGenCreatorsFileTemplate as yn, configSpec as yt, tsMorphGenerateApp as z, mcpTemplate as zn, upgradeManifestTemplate as zt };
|
|
8326
8406
|
|
|
8327
|
-
//# sourceMappingURL=file-builders-
|
|
8407
|
+
//# sourceMappingURL=file-builders-Cfc3km_-.mjs.map
|