@powerhousedao/codegen 6.0.0-dev.191 → 6.0.0-dev.193
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/{templates-BbNsigQX.mjs → file-builders-BkbVW0kT.mjs} +2322 -383
- package/dist/file-builders-BkbVW0kT.mjs.map +1 -0
- package/dist/index-CEDWX5sL.d.mts +349 -0
- package/dist/index-CEDWX5sL.d.mts.map +1 -0
- package/dist/index.d.mts +42 -101
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +4492 -325
- package/dist/index.mjs.map +1 -1
- package/dist/src/file-builders/index.d.mts +2 -3
- package/dist/src/file-builders/index.mjs +2 -3
- package/dist/src/name-builders/index.d.mts +2 -2
- package/dist/src/name-builders/index.mjs +2 -146
- package/dist/src/templates/index.d.mts +34 -74
- package/dist/src/templates/index.d.mts.map +1 -1
- package/dist/src/templates/index.mjs +2 -2
- package/dist/src/utils/index.d.mts +6 -18
- package/dist/src/utils/index.d.mts.map +1 -1
- package/dist/src/utils/index.mjs +2 -380
- package/dist/{validation-Bpg_44mW.d.mts → validation-Z3z0BJlu.d.mts} +2 -2
- package/dist/{validation-Bpg_44mW.d.mts.map → validation-Z3z0BJlu.d.mts.map} +1 -1
- package/package.json +16 -9
- package/dist/file-builders-BV9wDPPZ.mjs +0 -1652
- package/dist/file-builders-BV9wDPPZ.mjs.map +0 -1
- package/dist/index-CHAnPBj2.d.mts +0 -199
- package/dist/index-CHAnPBj2.d.mts.map +0 -1
- package/dist/index-CJZGVSYg.d.mts +0 -65
- package/dist/index-CJZGVSYg.d.mts.map +0 -1
- package/dist/src/name-builders/index.mjs.map +0 -1
- package/dist/src/utils/index.mjs.map +0 -1
- package/dist/templates-BbNsigQX.mjs.map +0 -1
- package/dist/types-e2ztuDtG.d.mts +0 -87
- package/dist/types-e2ztuDtG.d.mts.map +0 -1
package/dist/src/utils/index.mjs
CHANGED
|
@@ -1,380 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { IndentationText, Project, SyntaxKind, ts } from "ts-morph";
|
|
4
|
-
import arg from "arg";
|
|
5
|
-
import { format } from "prettier";
|
|
6
|
-
//#region src/utils/cli.ts
|
|
7
|
-
const configSpec = {
|
|
8
|
-
"--document-models": String,
|
|
9
|
-
"--editors": String,
|
|
10
|
-
"--interactive": Boolean,
|
|
11
|
-
"--skip-format": Boolean,
|
|
12
|
-
"--watch": Boolean,
|
|
13
|
-
"-i": "--interactive",
|
|
14
|
-
"-sf": "--skip-format",
|
|
15
|
-
"-w": "--watch"
|
|
16
|
-
};
|
|
17
|
-
function parseArgs(argv, spec) {
|
|
18
|
-
return arg(spec, {
|
|
19
|
-
permissive: true,
|
|
20
|
-
argv
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
function parseConfig(argv) {
|
|
24
|
-
const config = {};
|
|
25
|
-
const args = parseArgs(argv, configSpec);
|
|
26
|
-
if ("--document-models" in args) config.documentModelsDir = args["--document-models"];
|
|
27
|
-
if ("--editors" in args) config.editorsDir = args["--editors"];
|
|
28
|
-
if ("--skip-format" in args) config.skipFormat = true;
|
|
29
|
-
if ("--interactive" in args) config.interactive = true;
|
|
30
|
-
if ("--watch" in args) config.watch = true;
|
|
31
|
-
return config;
|
|
32
|
-
}
|
|
33
|
-
//#endregion
|
|
34
|
-
//#region src/utils/constants.ts
|
|
35
|
-
/** Document model metadata for the `powerhouse/document-model` document type.
|
|
36
|
-
*
|
|
37
|
-
* Assumed to always be present during codegen.
|
|
38
|
-
*/
|
|
39
|
-
const documentModelDocumentTypeMetadata = {
|
|
40
|
-
documentModelId: "powerhouse/document-model",
|
|
41
|
-
documentModelDocumentTypeName: "DocumentModelDocument",
|
|
42
|
-
documentModelDirName: "document-model",
|
|
43
|
-
documentModelImportPath: "document-model"
|
|
44
|
-
};
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/utils/syntax-getters.ts
|
|
47
|
-
/** Returns a ts-morph ObjectLiteralExpression from a variable statement
|
|
48
|
-
* if the type matches
|
|
49
|
-
*/
|
|
50
|
-
function getObjectLiteral(statement) {
|
|
51
|
-
return statement?.getDeclarations().at(0)?.getInitializerIfKind(SyntaxKind.ObjectLiteralExpression);
|
|
52
|
-
}
|
|
53
|
-
/** Returns the value of a property in a ts-morph ObjectLiteralExpression of type T if it exists */
|
|
54
|
-
function getObjectProperty(object, propertyName, propertyType) {
|
|
55
|
-
return object?.getProperty(propertyName)?.asKind(SyntaxKind.PropertyAssignment)?.getChildren().find((child) => child.getKind() === propertyType)?.asKindOrThrow(propertyType);
|
|
56
|
-
}
|
|
57
|
-
function getVariableDeclarationByTypeName(sourceFile, typeName) {
|
|
58
|
-
return sourceFile.getVariableDeclaration((declaration) => {
|
|
59
|
-
if ((declaration.getTypeNode()?.getText() ?? "").includes(typeName)) return true;
|
|
60
|
-
return declaration.getType().getText().includes(typeName);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
//#endregion
|
|
64
|
-
//#region src/utils/document-type-metadata.ts
|
|
65
|
-
/** Gets the document model metadata for the --document-type argument
|
|
66
|
-
* passed to the `generate --editor` and `generate --app` commands.
|
|
67
|
-
*/
|
|
68
|
-
function getDocumentTypeMetadata({ project, documentModelId, documentModelsDirPath }) {
|
|
69
|
-
const sourceFile = project.getSourceFiles().filter((file) => {
|
|
70
|
-
return file.getBaseName() === "document-model.ts";
|
|
71
|
-
}).find((file) => getDocumentModelFileByDocumentId(file, documentModelId));
|
|
72
|
-
if (!sourceFile) throw new Error(`No document-model.ts file exists for ${documentModelId}`);
|
|
73
|
-
const documentModelsDir = project.getDirectory(documentModelsDirPath);
|
|
74
|
-
if (!documentModelsDir) throw new Error(`No document-models dir exists for ${documentModelId}`);
|
|
75
|
-
const documentModelDir = project.getDirectories().find((dir) => sourceFile.getDirectory().isDescendantOf(dir) && dir.isDescendantOf(documentModelsDir));
|
|
76
|
-
if (!documentModelDir) throw new Error(`No document model dir exists for ${documentModelId}`);
|
|
77
|
-
const documentModelDirName = documentModelDir.getBaseName();
|
|
78
|
-
const documentModelImportPath = path.join("document-models", documentModelDirName);
|
|
79
|
-
const sourceFileDir = sourceFile.getDirectoryPath();
|
|
80
|
-
const documentModelGenTypesFilePath = path.join(sourceFileDir, "types.ts");
|
|
81
|
-
const documentModelGenTypesFile = project.getSourceFile(documentModelGenTypesFilePath);
|
|
82
|
-
if (!documentModelGenTypesFile) throw new Error(`No generated types file exists for ${documentModelId}`);
|
|
83
|
-
const documentModelDocumentTypeName = getPHDocumentTypeNameFromSourceFile(documentModelGenTypesFile);
|
|
84
|
-
if (!documentModelDocumentTypeName) throw new Error(`Generated type file is missing PHDocument type declaration for ${documentModelId}`);
|
|
85
|
-
return {
|
|
86
|
-
documentModelDirName,
|
|
87
|
-
documentModelDocumentTypeName,
|
|
88
|
-
documentModelId,
|
|
89
|
-
documentModelImportPath
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function getDocumentModelFileByDocumentId(sourceFile, documentModelId) {
|
|
93
|
-
const documentModelStatement = sourceFile.getVariableStatement("documentModel");
|
|
94
|
-
if (!documentModelStatement) return false;
|
|
95
|
-
const documentModelObject = getObjectLiteral(documentModelStatement);
|
|
96
|
-
if (!documentModelObject) return false;
|
|
97
|
-
return getObjectProperty(documentModelObject, "id", SyntaxKind.StringLiteral)?.getLiteralValue() === documentModelId;
|
|
98
|
-
}
|
|
99
|
-
function getPHDocumentTypeNameFromSourceFile(sourceFile) {
|
|
100
|
-
return sourceFile.getTypeAliases().find((alias) => {
|
|
101
|
-
return (alias.getTypeNode()?.getText())?.includes("PHDocument");
|
|
102
|
-
})?.getName();
|
|
103
|
-
}
|
|
104
|
-
//#endregion
|
|
105
|
-
//#region src/utils/format-with-prettier.ts
|
|
106
|
-
/** Formats the text of a ts-morph source file with prettier before writing the text to memory */
|
|
107
|
-
async function formatSourceFileWithPrettier(sourceFile) {
|
|
108
|
-
const sourceText = sourceFile.getFullText();
|
|
109
|
-
let formattedText = sourceText;
|
|
110
|
-
try {
|
|
111
|
-
formattedText = await format(sourceText, { parser: "typescript" });
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error(error);
|
|
114
|
-
}
|
|
115
|
-
sourceFile.replaceWithText(formattedText);
|
|
116
|
-
}
|
|
117
|
-
async function runPrettier() {
|
|
118
|
-
await spawnAsync("npx", [
|
|
119
|
-
"prettier",
|
|
120
|
-
"--write",
|
|
121
|
-
"."
|
|
122
|
-
]);
|
|
123
|
-
}
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/utils/source-files.ts
|
|
126
|
-
/** Gets a SourceFile by name in a ts-morph Project, or creates a new one
|
|
127
|
-
* if none with that path exists.
|
|
128
|
-
*/
|
|
129
|
-
function getOrCreateSourceFile(project, filePath) {
|
|
130
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
131
|
-
if (!sourceFile) return {
|
|
132
|
-
alreadyExists: false,
|
|
133
|
-
sourceFile: project.createSourceFile(filePath, "")
|
|
134
|
-
};
|
|
135
|
-
return {
|
|
136
|
-
alreadyExists: true,
|
|
137
|
-
sourceFile
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
/** Gets a Directory by name in a ts-morph Project, or creates a new one
|
|
141
|
-
* if none with that path exists.
|
|
142
|
-
*/
|
|
143
|
-
function getOrCreateDirectory(project, dirPath) {
|
|
144
|
-
const directory = project.getDirectory(dirPath);
|
|
145
|
-
if (!directory) return {
|
|
146
|
-
alreadyExists: false,
|
|
147
|
-
directory: project.createDirectory(dirPath)
|
|
148
|
-
};
|
|
149
|
-
return {
|
|
150
|
-
alreadyExists: true,
|
|
151
|
-
directory
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
/** Ensures that the directories at the given paths exist within the
|
|
155
|
-
* ts-morph Project
|
|
156
|
-
*/
|
|
157
|
-
async function ensureDirectoriesExist(project, ...pathsToEnsure) {
|
|
158
|
-
for (const dirPath of pathsToEnsure) if (!project.getDirectory(dirPath)) project.createDirectory(dirPath);
|
|
159
|
-
await project.save();
|
|
160
|
-
}
|
|
161
|
-
function getPreviousVersionSourceFile(args) {
|
|
162
|
-
const { project, version, filePath } = args;
|
|
163
|
-
const previousVersion = version - 1;
|
|
164
|
-
if (previousVersion < 1) return;
|
|
165
|
-
const previousVersionFilePath = filePath.replace(`/v${version}/`, `/v${previousVersion}/`);
|
|
166
|
-
return project.getSourceFile(previousVersionFilePath);
|
|
167
|
-
}
|
|
168
|
-
//#endregion
|
|
169
|
-
//#region src/utils/syntax-builders.ts
|
|
170
|
-
/** Builds a ts-morph ObjectLiteralExpression from a ts/js object
|
|
171
|
-
* Useful for substituting the value of a runtime object in templates
|
|
172
|
-
*/
|
|
173
|
-
function buildObjectLiteral(inputObject, sourceFile) {
|
|
174
|
-
const propertyAssignments = [];
|
|
175
|
-
for (const [key, value] of Object.entries(inputObject)) {
|
|
176
|
-
const propertyAssignment = buildPropertyAssignment(key, value);
|
|
177
|
-
propertyAssignments.push(propertyAssignment);
|
|
178
|
-
}
|
|
179
|
-
const objectLiteral = ts.factory.createObjectLiteralExpression(propertyAssignments, true);
|
|
180
|
-
return buildNodePrinter(sourceFile)(objectLiteral);
|
|
181
|
-
}
|
|
182
|
-
function buildFalse() {
|
|
183
|
-
return ts.factory.createFalse();
|
|
184
|
-
}
|
|
185
|
-
function buildTrue() {
|
|
186
|
-
return ts.factory.createTrue();
|
|
187
|
-
}
|
|
188
|
-
function buildBoolean(value) {
|
|
189
|
-
return value ? buildTrue() : buildFalse();
|
|
190
|
-
}
|
|
191
|
-
function buildNull() {
|
|
192
|
-
return ts.factory.createNull();
|
|
193
|
-
}
|
|
194
|
-
function buildUndefined() {
|
|
195
|
-
return ts.factory.createIdentifier("undefined");
|
|
196
|
-
}
|
|
197
|
-
function buildNumericLiteral(value) {
|
|
198
|
-
return ts.factory.createNumericLiteral(value);
|
|
199
|
-
}
|
|
200
|
-
function buildStringLiteral(value) {
|
|
201
|
-
return ts.factory.createStringLiteral(value);
|
|
202
|
-
}
|
|
203
|
-
function buildArrayLiteral(elements) {
|
|
204
|
-
return ts.factory.createArrayLiteralExpression(elements, true);
|
|
205
|
-
}
|
|
206
|
-
function valueToExpression(value) {
|
|
207
|
-
if (value === null) return buildNull();
|
|
208
|
-
if (value === void 0) return buildUndefined();
|
|
209
|
-
if (typeof value === "boolean") return buildBoolean(value);
|
|
210
|
-
if (typeof value === "string") return buildStringLiteral(value);
|
|
211
|
-
if (typeof value === "number") return buildNumericLiteral(value);
|
|
212
|
-
if (Array.isArray(value)) return buildArrayLiteral(value.map((item) => valueToExpression(item)));
|
|
213
|
-
if (typeof value === "object") return ts.factory.createObjectLiteralExpression(Object.entries(value).map(([key, v]) => {
|
|
214
|
-
const name = ts.factory.createIdentifier(key);
|
|
215
|
-
return ts.factory.createPropertyAssignment(name, valueToExpression(v));
|
|
216
|
-
}), true);
|
|
217
|
-
throw new Error("Invalid value passed: ", value);
|
|
218
|
-
}
|
|
219
|
-
function buildPropertyAssignment(name, value) {
|
|
220
|
-
const nameIdentifier = ts.factory.createIdentifier(name);
|
|
221
|
-
const valueExpression = valueToExpression(value);
|
|
222
|
-
return ts.factory.createPropertyAssignment(nameIdentifier, valueExpression);
|
|
223
|
-
}
|
|
224
|
-
function buildNodePrinter(sourceFile) {
|
|
225
|
-
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
226
|
-
return (node) => printer.printNode(ts.EmitHint.Unspecified, node, sourceFile.compilerNode);
|
|
227
|
-
}
|
|
228
|
-
//#endregion
|
|
229
|
-
//#region src/utils/ts-morph-project.ts
|
|
230
|
-
const DEFAULT_PROJECT_OPTIONS = {
|
|
231
|
-
skipAddingFilesFromTsConfig: true,
|
|
232
|
-
skipLoadingLibFiles: true,
|
|
233
|
-
manipulationSettings: {
|
|
234
|
-
useTrailingCommas: true,
|
|
235
|
-
indentationText: IndentationText.TwoSpaces,
|
|
236
|
-
indentMultiLineObjectLiteralBeginningOnBlankLine: true
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
/** Returns the minimal typescript config for use in ts-morph file generation */
|
|
240
|
-
function getDefaultProjectOptions(tsConfigFilePath) {
|
|
241
|
-
return {
|
|
242
|
-
...DEFAULT_PROJECT_OPTIONS,
|
|
243
|
-
tsConfigFilePath
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
/** Instantiates a ts-morph Project using the default typescript config and nearest tsconfig.json file */
|
|
247
|
-
function buildTsMorphProject(projectDir) {
|
|
248
|
-
return new Project(getDefaultProjectOptions(path.join(projectDir, "tsconfig.json")));
|
|
249
|
-
}
|
|
250
|
-
//#endregion
|
|
251
|
-
//#region src/utils/unsafe-utils.ts
|
|
252
|
-
function getInitialStates(scopeState) {
|
|
253
|
-
const { global, local } = scopeState;
|
|
254
|
-
const scopes = {
|
|
255
|
-
global,
|
|
256
|
-
local
|
|
257
|
-
};
|
|
258
|
-
Object.entries(scopes).forEach(([scope, state]) => {
|
|
259
|
-
if (!isEmptyStateSchema(state.schema) && state.initialValue === "") throw new Error(`${scope.charAt(0).toLocaleUpperCase() + scope.slice(1)} scope has a defined schema but is missing an initial value.`);
|
|
260
|
-
});
|
|
261
|
-
return {
|
|
262
|
-
initialGlobalState: handleEmptyState(global.initialValue),
|
|
263
|
-
initialLocalState: handleEmptyState(local.initialValue)
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
function isEmptyStateSchema(schema) {
|
|
267
|
-
return schema === "" || !schema.includes("{");
|
|
268
|
-
}
|
|
269
|
-
function handleEmptyState(state) {
|
|
270
|
-
return state === "" ? "{}" : state;
|
|
271
|
-
}
|
|
272
|
-
//#endregion
|
|
273
|
-
//#region src/utils/validation.ts
|
|
274
|
-
/**
|
|
275
|
-
* Validates that a DocumentModelGlobalState has all required properties for successful code generation.
|
|
276
|
-
*
|
|
277
|
-
* @param documentModelState - The DocumentModelGlobalState to validate
|
|
278
|
-
* @returns Validation result with isValid flag and error messages
|
|
279
|
-
*/
|
|
280
|
-
function validateDocumentModelState(documentModelState) {
|
|
281
|
-
const errors = [];
|
|
282
|
-
if (!documentModelState.id || typeof documentModelState.id !== "string" || documentModelState.id.trim() === "") errors.push("Property \"id\" is required and must be a non-empty string");
|
|
283
|
-
if (!documentModelState.name || typeof documentModelState.name !== "string" || documentModelState.name.trim() === "") errors.push("Property \"name\" is required and must be a non-empty string");
|
|
284
|
-
if (typeof documentModelState.extension !== "string") errors.push("Property \"extension\" must be a string");
|
|
285
|
-
if (!Array.isArray(documentModelState.specifications) || documentModelState.specifications.length === 0) {
|
|
286
|
-
errors.push("Property \"specifications\" is required and must be a non-empty array");
|
|
287
|
-
return {
|
|
288
|
-
isValid: false,
|
|
289
|
-
errors
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
const latestSpec = documentModelState.specifications[documentModelState.specifications.length - 1];
|
|
293
|
-
if (!latestSpec) {
|
|
294
|
-
errors.push("Latest specification is missing or invalid");
|
|
295
|
-
return {
|
|
296
|
-
isValid: false,
|
|
297
|
-
errors
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
if (!latestSpec.state) {
|
|
301
|
-
errors.push("Latest specification must have a \"state\" property");
|
|
302
|
-
return {
|
|
303
|
-
isValid: false,
|
|
304
|
-
errors
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
if (!latestSpec.state.global) errors.push("Latest specification state must have a \"global\" property");
|
|
308
|
-
else {
|
|
309
|
-
const globalState = latestSpec.state.global;
|
|
310
|
-
if (typeof globalState.schema !== "string") errors.push("Global state \"schema\" must be a string");
|
|
311
|
-
if (typeof globalState.initialValue !== "string") errors.push("Global state \"initialValue\" must be a string");
|
|
312
|
-
if (globalState.schema && globalState.schema.trim() !== "" && globalState.schema.includes("{") && (!globalState.initialValue || globalState.initialValue.trim() === "")) errors.push("Global state has a defined schema but is missing an initial value");
|
|
313
|
-
}
|
|
314
|
-
if (!latestSpec.state.local) errors.push("Latest specification state must have a \"local\" property");
|
|
315
|
-
else {
|
|
316
|
-
const localState = latestSpec.state.local;
|
|
317
|
-
if (typeof localState.schema !== "string") errors.push("Local state \"schema\" must be a string");
|
|
318
|
-
if (typeof localState.initialValue !== "string") errors.push("Local state \"initialValue\" must be a string");
|
|
319
|
-
if (localState.schema && localState.schema.trim() !== "" && localState.schema.includes("{") && (!localState.initialValue || localState.initialValue.trim() === "")) errors.push("Local state has a defined schema but is missing an initial value");
|
|
320
|
-
}
|
|
321
|
-
if (!Array.isArray(latestSpec.modules)) errors.push("Latest specification must have a \"modules\" array");
|
|
322
|
-
else {
|
|
323
|
-
if (latestSpec.modules.length === 0) errors.push("Latest specification must have at least one module defined");
|
|
324
|
-
latestSpec.modules.forEach((module, moduleIndex) => {
|
|
325
|
-
if (!module.name || typeof module.name !== "string" || module.name.trim() === "") errors.push(`Module at index ${moduleIndex} must have a non-empty "name" property`);
|
|
326
|
-
if (!Array.isArray(module.operations)) errors.push(`Module "${module.name || `at index ${moduleIndex}`}" must have an "operations" array`);
|
|
327
|
-
else {
|
|
328
|
-
if (module.operations.length === 0) errors.push(`Module "${module.name || `at index ${moduleIndex}`}" must have at least one operation defined`);
|
|
329
|
-
module.operations.forEach((operation, operationIndex) => {
|
|
330
|
-
const operationId = operation.name || `at index ${operationIndex}`;
|
|
331
|
-
const moduleId = module.name || `at index ${moduleIndex}`;
|
|
332
|
-
if (!operation.name || typeof operation.name !== "string" || operation.name.trim() === "") errors.push(`Operation ${operationId} in module "${moduleId}" must have a non-empty "name" property`);
|
|
333
|
-
if (operation.schema !== null && typeof operation.schema !== "string") errors.push(`Operation "${operationId}" in module "${moduleId}" must have a "schema" that is either null or a string`);
|
|
334
|
-
if (operation.scope !== void 0 && typeof operation.scope !== "string") errors.push(`Operation "${operationId}" in module "${moduleId}" must have a "scope" that is a string if provided`);
|
|
335
|
-
if (!Array.isArray(operation.errors)) errors.push(`Operation "${operationId}" in module "${moduleId}" must have an "errors" array`);
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
return {
|
|
341
|
-
isValid: errors.length === 0,
|
|
342
|
-
errors
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
//#endregion
|
|
346
|
-
//#region src/utils/graphql-type-prefixes.ts
|
|
347
|
-
/**
|
|
348
|
-
* Extract type names from a GraphQL schema.
|
|
349
|
-
* Finds all type, enum, union, interface, and input definitions.
|
|
350
|
-
*/
|
|
351
|
-
function extractTypeNames(schema) {
|
|
352
|
-
const found = schema.match(/(type|enum|union|interface|input)\s+(\w+)\s/g);
|
|
353
|
-
if (!found) return [];
|
|
354
|
-
return found.map((f) => f.replaceAll("type ", "").replaceAll("enum ", "").replaceAll("union ", "").replaceAll("interface ", "").replaceAll("input ", "").trim());
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Apply type prefixes to GraphQL schema to namespace types and avoid collisions.
|
|
358
|
-
*/
|
|
359
|
-
function applyGraphQLTypePrefixes(schema, prefix, externalTypeNames = []) {
|
|
360
|
-
if (!schema || !schema.trim()) return schema;
|
|
361
|
-
let processedSchema = schema;
|
|
362
|
-
const localTypeNames = extractTypeNames(schema);
|
|
363
|
-
const allTypeNames = [...new Set([...localTypeNames, ...externalTypeNames])];
|
|
364
|
-
if (allTypeNames.length === 0) return schema;
|
|
365
|
-
allTypeNames.forEach((typeName) => {
|
|
366
|
-
const typeRegex = new RegExp(`(?<![_A-Za-z0-9])(${typeName})(?![_A-Za-z0-9])|\\[(${typeName})\\]|\\[(${typeName})!\\]|\\[(${typeName})\\]!|\\[(${typeName})!\\]!`, "g");
|
|
367
|
-
processedSchema = processedSchema.replace(typeRegex, (match, p1, p2, p3, p4, p5) => {
|
|
368
|
-
if (match.startsWith("[")) {
|
|
369
|
-
const captured = p2 || p3 || p4 || p5;
|
|
370
|
-
return match.replace(captured, `${prefix}_${captured}`);
|
|
371
|
-
}
|
|
372
|
-
return `${prefix}_${p1}`;
|
|
373
|
-
});
|
|
374
|
-
});
|
|
375
|
-
return processedSchema;
|
|
376
|
-
}
|
|
377
|
-
//#endregion
|
|
378
|
-
export { DEFAULT_PROJECT_OPTIONS, applyGraphQLTypePrefixes, buildObjectLiteral, buildStringLiteral, buildTsMorphProject, configSpec, documentModelDocumentTypeMetadata, ensureDirectoriesExist, extractTypeNames, formatSourceFileWithPrettier, getDefaultProjectOptions, getDocumentTypeMetadata, getInitialStates, getObjectLiteral, getObjectProperty, getOrCreateDirectory, getOrCreateSourceFile, getPHDocumentTypeNameFromSourceFile, getPreviousVersionSourceFile, getVariableDeclarationByTypeName, parseArgs, parseConfig, runPrettier, validateDocumentModelState };
|
|
379
|
-
|
|
380
|
-
//# sourceMappingURL=index.mjs.map
|
|
1
|
+
import { $ as ensureDirectoriesExist, G as DEFAULT_PROJECT_OPTIONS, J as getObjectLiteral, K as buildTsMorphProject, Q as buildStringLiteral, U as validateDocumentModelState, W as getInitialStates, X as getVariableDeclarationByTypeName, Y as getObjectProperty, Z as buildObjectLiteral, at as runPrettier, ct as configSpec, et as getOrCreateDirectory, it as formatSourceFileWithPrettier, lt as parseArgs, nt as getPreviousVersionSourceFile, ot as getDocumentTypeMetadata, q as getDefaultProjectOptions, rt as formatSafe, st as documentModelDocumentTypeMetadata, tt as getOrCreateSourceFile, ut as parseConfig } from "../../file-builders-BkbVW0kT.mjs";
|
|
2
|
+
export { DEFAULT_PROJECT_OPTIONS, buildObjectLiteral, buildStringLiteral, buildTsMorphProject, configSpec, documentModelDocumentTypeMetadata, ensureDirectoriesExist, formatSafe, formatSourceFileWithPrettier, getDefaultProjectOptions, getDocumentTypeMetadata, getInitialStates, getObjectLiteral, getObjectProperty, getOrCreateDirectory, getOrCreateSourceFile, getPreviousVersionSourceFile, getVariableDeclarationByTypeName, parseArgs, parseConfig, runPrettier, validateDocumentModelState };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import arg from "arg";
|
|
2
1
|
import { DocumentModelGlobalState } from "@powerhousedao/shared/document-model";
|
|
2
|
+
import arg from "arg";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/cli.d.ts
|
|
5
5
|
declare const configSpec: {
|
|
@@ -40,4 +40,4 @@ interface DocumentModelStateValidationResult {
|
|
|
40
40
|
declare function validateDocumentModelState(documentModelState: DocumentModelGlobalState): DocumentModelStateValidationResult;
|
|
41
41
|
//#endregion
|
|
42
42
|
export { parseConfig as a, parseArgs as i, validateDocumentModelState as n, configSpec as r, DocumentModelStateValidationResult as t };
|
|
43
|
-
//# sourceMappingURL=validation-
|
|
43
|
+
//# sourceMappingURL=validation-Z3z0BJlu.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation-
|
|
1
|
+
{"version":3,"file":"validation-Z3z0BJlu.d.mts","names":[],"sources":["../src/utils/cli.ts","../src/utils/validation.ts"],"mappings":";;;;cAEa,UAAA;EAAA;;;;;;;;;iBAWG,SAAA,WAAoB,GAAA,CAAI,IAAA,CAAA,CAAM,IAAA,YAAgB,IAAA,EAAM,CAAA,GAAC,GAAA,CAAA,MAAA,CAAA,CAAA;AAAA,iBASrD,WAAA,CAAY,IAAA,aAAc,OAAA;;;;;;;;;;;;UCjBzB,kCAAA;EDMP;ECJR,OAAA;;EAEA,MAAA;AAAA;;;;;;;iBASc,0BAAA,CACd,kBAAA,EAAoB,wBAAA,GACnB,kCAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/codegen",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.193",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -34,30 +34,37 @@
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"write-package": "7.2.0",
|
|
38
|
-
"read-pkg": "10.1.0",
|
|
39
|
-
"get-tsconfig": "4.13.7",
|
|
40
|
-
"@powerhousedao/document-engineering": "1.40.1",
|
|
41
37
|
"@graphql-codegen/add": "6.0.0",
|
|
42
38
|
"@graphql-codegen/cli": "6.1.1",
|
|
43
39
|
"@graphql-codegen/typescript": "5.0.7",
|
|
40
|
+
"@pnpm/find-workspace-dir": "^1000.1.5",
|
|
41
|
+
"@pnpm/find-workspace-packages": "^6.0.9",
|
|
42
|
+
"@powerhousedao/document-engineering": "1.40.1",
|
|
43
|
+
"@types/node": "25.2.3",
|
|
44
44
|
"arg": "^5.0.2",
|
|
45
45
|
"chalk": "5.6.2",
|
|
46
46
|
"change-case": "5.4.4",
|
|
47
47
|
"enquirer": "2.4.1",
|
|
48
48
|
"execa": "^8.0.1",
|
|
49
|
+
"get-tsconfig": "4.13.7",
|
|
49
50
|
"graphql": "16.12.0",
|
|
50
51
|
"graphql-codegen-typescript-validation-schema": "0.18.1",
|
|
52
|
+
"load-json-file": "^7.0.1",
|
|
53
|
+
"npm-registry-fetch": "^19.1.1",
|
|
51
54
|
"prettier": "3.8.1",
|
|
55
|
+
"read-pkg": "10.1.0",
|
|
56
|
+
"remeda": "^2.33.7",
|
|
52
57
|
"semver": "7.7.4",
|
|
53
58
|
"ts-morph": "27.0.2",
|
|
54
|
-
"@types/node": "25.2.3",
|
|
55
59
|
"tsdown": "0.21.1",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
60
|
+
"write-json-file": "^7.0.0",
|
|
61
|
+
"write-package": "7.2.0",
|
|
62
|
+
"@powerhousedao/shared": "6.0.0-dev.193",
|
|
63
|
+
"document-model": "6.0.0-dev.193"
|
|
58
64
|
},
|
|
59
65
|
"devDependencies": {
|
|
60
|
-
"@tmpl/core": "npm:@jsr/tmpl__core@^0.6.3"
|
|
66
|
+
"@tmpl/core": "npm:@jsr/tmpl__core@^0.6.3",
|
|
67
|
+
"@types/npm-registry-fetch": "^8.0.9"
|
|
61
68
|
},
|
|
62
69
|
"scripts": {
|
|
63
70
|
"tsc": "tsc",
|