@powerhousedao/codegen 4.1.0-dev.1 → 4.1.0-dev.11

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 (63) hide show
  1. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/reducer.esm.t +1 -1
  2. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model/types.esm.t +1 -1
  3. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/actions.esm.t +3 -3
  4. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts +1 -2
  5. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/index.d.ts.map +1 -1
  6. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/resolvers.esm.t +59 -50
  7. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-subgraph/schema.esm.t +3 -3
  8. package/dist/src/codegen/graphql.d.ts +5 -1
  9. package/dist/src/codegen/graphql.d.ts.map +1 -1
  10. package/dist/src/codegen/graphql.js +28 -5
  11. package/dist/src/codegen/graphql.js.map +1 -1
  12. package/dist/src/codegen/hygen.d.ts +2 -1
  13. package/dist/src/codegen/hygen.d.ts.map +1 -1
  14. package/dist/src/codegen/hygen.js +17 -1
  15. package/dist/src/codegen/hygen.js.map +1 -1
  16. package/dist/src/codegen/index.d.ts +4 -4
  17. package/dist/src/codegen/index.d.ts.map +1 -1
  18. package/dist/src/codegen/index.js +59 -1
  19. package/dist/src/codegen/index.js.map +1 -1
  20. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts +10 -0
  21. package/dist/src/ts-morph-generator/core/FileGenerator.d.ts.map +1 -0
  22. package/dist/src/ts-morph-generator/core/FileGenerator.js +9 -0
  23. package/dist/src/ts-morph-generator/core/FileGenerator.js.map +1 -0
  24. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts +28 -0
  25. package/dist/src/ts-morph-generator/core/GenerationContext.d.ts.map +1 -0
  26. package/dist/src/ts-morph-generator/core/GenerationContext.js +2 -0
  27. package/dist/src/ts-morph-generator/core/GenerationContext.js.map +1 -0
  28. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts +18 -0
  29. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.d.ts.map +1 -0
  30. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js +112 -0
  31. package/dist/src/ts-morph-generator/core/TSMorphCodeGenerator.js.map +1 -0
  32. package/dist/src/ts-morph-generator/core/index.d.ts +4 -0
  33. package/dist/src/ts-morph-generator/core/index.d.ts.map +1 -0
  34. package/dist/src/ts-morph-generator/core/index.js +4 -0
  35. package/dist/src/ts-morph-generator/core/index.js.map +1 -0
  36. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts +9 -0
  37. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.d.ts.map +1 -0
  38. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js +69 -0
  39. package/dist/src/ts-morph-generator/file-generators/ReducerGenerator.js.map +1 -0
  40. package/dist/src/ts-morph-generator/file-generators/index.d.ts +2 -0
  41. package/dist/src/ts-morph-generator/file-generators/index.d.ts.map +1 -0
  42. package/dist/src/ts-morph-generator/file-generators/index.js +2 -0
  43. package/dist/src/ts-morph-generator/file-generators/index.js.map +1 -0
  44. package/dist/src/ts-morph-generator/index.d.ts +4 -0
  45. package/dist/src/ts-morph-generator/index.d.ts.map +1 -0
  46. package/dist/src/ts-morph-generator/index.js +4 -0
  47. package/dist/src/ts-morph-generator/index.js.map +1 -0
  48. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts +13 -0
  49. package/dist/src/ts-morph-generator/utilities/DirectoryManager.d.ts.map +1 -0
  50. package/dist/src/ts-morph-generator/utilities/DirectoryManager.js +45 -0
  51. package/dist/src/ts-morph-generator/utilities/DirectoryManager.js.map +1 -0
  52. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts +14 -0
  53. package/dist/src/ts-morph-generator/utilities/ImportManager.d.ts.map +1 -0
  54. package/dist/src/ts-morph-generator/utilities/ImportManager.js +40 -0
  55. package/dist/src/ts-morph-generator/utilities/ImportManager.js.map +1 -0
  56. package/dist/src/ts-morph-generator/utilities/index.d.ts +3 -0
  57. package/dist/src/ts-morph-generator/utilities/index.d.ts.map +1 -0
  58. package/dist/src/ts-morph-generator/utilities/index.js +3 -0
  59. package/dist/src/ts-morph-generator/utilities/index.js.map +1 -0
  60. package/dist/tsconfig.hygen.tsbuildinfo +1 -1
  61. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  62. package/package.json +7 -6
  63. package/dist/src/codegen/.hygen/templates/powerhouse/generate-document-model-module/customReducers.esm.t +0 -20
@@ -0,0 +1,28 @@
1
+ import { type DocumentModelState } from "document-model";
2
+ import { type Project } from "ts-morph";
3
+ export type Actions = {
4
+ name: string | null;
5
+ hasInput: boolean;
6
+ hasAttachment: boolean | undefined;
7
+ scope: string;
8
+ state: string;
9
+ errors?: unknown;
10
+ };
11
+ export type ModuleSpec = DocumentModelState["specifications"][0]["modules"][0];
12
+ export interface GenerationContext {
13
+ rootDir: string;
14
+ docModel: DocumentModelState;
15
+ module: ModuleSpec;
16
+ project: Project;
17
+ actions: Actions[];
18
+ }
19
+ export type PHProjectDirectories = {
20
+ documentModelDir?: string;
21
+ editorsDir?: string;
22
+ processorsDir?: string;
23
+ subgraphsDir?: string;
24
+ };
25
+ export type CodeGeneratorOptions = {
26
+ directories?: PHProjectDirectories;
27
+ };
28
+ //# sourceMappingURL=GenerationContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenerationContext.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/core/GenerationContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,aAAa,EAAE,OAAO,GAAG,SAAS,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,CAAC;AAGF,MAAM,MAAM,UAAU,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/E,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,CAAC,EAAE,oBAAoB,CAAC;CACpC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=GenerationContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenerationContext.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/core/GenerationContext.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { type DocumentModelState } from "document-model";
2
+ import { type CodeGeneratorOptions } from "./GenerationContext.js";
3
+ export declare class TSMorphCodeGenerator {
4
+ private rootDir;
5
+ private docModels;
6
+ private project;
7
+ private generators;
8
+ private directories;
9
+ constructor(rootDir: string, docModels: DocumentModelState[], options?: CodeGeneratorOptions);
10
+ private setupGenerators;
11
+ generateReducers(): Promise<void>;
12
+ generateAll(): Promise<void>;
13
+ private generateFileType;
14
+ private setupProject;
15
+ private createGenerationContext;
16
+ private ensureDirectoryExists;
17
+ }
18
+ //# sourceMappingURL=TSMorphCodeGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TSMorphCodeGenerator.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/core/TSMorphCodeGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAOzD,OAAO,EAEL,KAAK,oBAAoB,EAI1B,MAAM,wBAAwB,CAAC;AAChC,qBAAa,oBAAoB;IAW7B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,SAAS;IAXnB,OAAO,CAAC,OAAO,CAAiB;IAChC,OAAO,CAAC,UAAU,CAAoC;IACtD,OAAO,CAAC,WAAW,CAKjB;gBAGQ,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,kBAAkB,EAAE,EACvC,OAAO,GAAE,oBAA0C;IAUrD,OAAO,CAAC,eAAe;IAYjB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAKjC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;YAMpB,gBAAgB;YAoBhB,YAAY;IAiC1B,OAAO,CAAC,uBAAuB;YAsBjB,qBAAqB;CAQpC"}
@@ -0,0 +1,112 @@
1
+ import fs from "fs/promises";
2
+ import { Project } from "ts-morph";
3
+ import { ReducerGenerator } from "../file-generators/ReducerGenerator.js";
4
+ import { DirectoryManager } from "../utilities/DirectoryManager.js";
5
+ import { ImportManager } from "../utilities/ImportManager.js";
6
+ export class TSMorphCodeGenerator {
7
+ rootDir;
8
+ docModels;
9
+ project = new Project();
10
+ generators = new Map();
11
+ directories = {
12
+ documentModelDir: "document-model",
13
+ editorsDir: "editors",
14
+ processorsDir: "processors",
15
+ subgraphsDir: "subgraphs",
16
+ };
17
+ constructor(rootDir, docModels, options = { directories: {} }) {
18
+ this.rootDir = rootDir;
19
+ this.docModels = docModels;
20
+ this.directories = {
21
+ ...this.directories,
22
+ ...options.directories,
23
+ };
24
+ this.setupGenerators();
25
+ }
26
+ setupGenerators() {
27
+ const importManager = new ImportManager();
28
+ const directoryManager = new DirectoryManager(this.directories);
29
+ // Register all generators
30
+ this.generators.set("reducers", new ReducerGenerator(importManager, directoryManager));
31
+ }
32
+ // Generate specific file types
33
+ async generateReducers() {
34
+ await this.generateFileType("reducers");
35
+ }
36
+ // Generate everything
37
+ async generateAll() {
38
+ for (const [type] of this.generators) {
39
+ await this.generateFileType(type);
40
+ }
41
+ }
42
+ async generateFileType(type) {
43
+ const generator = this.generators.get(type);
44
+ if (!generator) {
45
+ throw new Error(`No generator registered for type: ${type}`);
46
+ }
47
+ await this.setupProject();
48
+ for (const docModel of this.docModels) {
49
+ const latestSpec = docModel.specifications[docModel.specifications.length - 1];
50
+ for (const module of latestSpec.modules) {
51
+ const context = this.createGenerationContext(docModel, module);
52
+ await generator.generate(context);
53
+ }
54
+ }
55
+ }
56
+ async setupProject() {
57
+ // Only load files from configured directories
58
+ const sourcePaths = [];
59
+ if (this.directories.documentModelDir) {
60
+ const dirPath = `${this.rootDir}/${this.directories.documentModelDir}`;
61
+ await this.ensureDirectoryExists(dirPath);
62
+ sourcePaths.push(`${dirPath}/**/*.ts`);
63
+ }
64
+ if (this.directories.editorsDir) {
65
+ const dirPath = `${this.rootDir}/${this.directories.editorsDir}`;
66
+ await this.ensureDirectoryExists(dirPath);
67
+ sourcePaths.push(`${dirPath}/**/*.ts`);
68
+ }
69
+ if (this.directories.processorsDir) {
70
+ const dirPath = `${this.rootDir}/${this.directories.processorsDir}`;
71
+ await this.ensureDirectoryExists(dirPath);
72
+ sourcePaths.push(`${dirPath}/**/*.ts`);
73
+ }
74
+ if (this.directories.subgraphsDir) {
75
+ const dirPath = `${this.rootDir}/${this.directories.subgraphsDir}`;
76
+ await this.ensureDirectoryExists(dirPath);
77
+ sourcePaths.push(`${dirPath}/**/*.ts`);
78
+ }
79
+ // Exclude node_modules from all paths
80
+ sourcePaths.push(`!${this.rootDir}/**/node_modules/**`);
81
+ if (sourcePaths.length > 0) {
82
+ this.project.addSourceFilesAtPaths(sourcePaths);
83
+ }
84
+ }
85
+ createGenerationContext(docModel, module) {
86
+ const actions = module.operations.map((op) => ({
87
+ name: op.name,
88
+ hasInput: op.schema !== null,
89
+ hasAttachment: op.schema?.includes(": Attachment"),
90
+ scope: op.scope || "global",
91
+ state: op.scope === "global" ? "" : op.scope,
92
+ errors: op.errors,
93
+ }));
94
+ return {
95
+ rootDir: this.rootDir,
96
+ docModel,
97
+ module,
98
+ project: this.project,
99
+ actions,
100
+ };
101
+ }
102
+ async ensureDirectoryExists(dirPath) {
103
+ try {
104
+ await fs.mkdir(dirPath, { recursive: true });
105
+ }
106
+ catch (err) {
107
+ console.error(`Failed to create directory: ${dirPath}`, err);
108
+ throw err;
109
+ }
110
+ }
111
+ }
112
+ //# sourceMappingURL=TSMorphCodeGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TSMorphCodeGenerator.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/core/TSMorphCodeGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAC1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAS9D,MAAM,OAAO,oBAAoB;IAWrB;IACA;IAXF,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IACxB,UAAU,GAAG,IAAI,GAAG,EAAyB,CAAC;IAC9C,WAAW,GAAyB;QAC1C,gBAAgB,EAAE,gBAAgB;QAClC,UAAU,EAAE,SAAS;QACrB,aAAa,EAAE,YAAY;QAC3B,YAAY,EAAE,WAAW;KAC1B,CAAC;IAE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AAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,+BAA+B,OAAO,EAAE,EAAE,GAAG,CAAC,CAAC;YAC7D,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export * from "./FileGenerator.js";
2
+ export * from "./GenerationContext.js";
3
+ export * from "./TSMorphCodeGenerator.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./FileGenerator.js";
2
+ export * from "./GenerationContext.js";
3
+ export * from "./TSMorphCodeGenerator.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { FileGenerator } from "../core/FileGenerator.js";
2
+ import { type GenerationContext } from "../core/GenerationContext.js";
3
+ export declare class ReducerGenerator extends FileGenerator {
4
+ generate(context: GenerationContext): Promise<void>;
5
+ private getOutputPath;
6
+ private createReducerObject;
7
+ private addReducerMethod;
8
+ }
9
+ //# sourceMappingURL=ReducerGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReducerGenerator.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/file-generators/ReducerGenerator.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,8BAA8B,CAAC;AAEtC,qBAAa,gBAAiB,SAAQ,aAAa;IAC3C,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA2BzD,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,mBAAmB;IAqC3B,OAAO,CAAC,gBAAgB;CAqBzB"}
@@ -0,0 +1,69 @@
1
+ import { camelCase, paramCase, pascalCase } from "change-case";
2
+ import { SyntaxKind, VariableDeclarationKind, } from "ts-morph";
3
+ import { FileGenerator } from "../core/FileGenerator.js";
4
+ export class ReducerGenerator extends FileGenerator {
5
+ async generate(context) {
6
+ // Skip if no actions to generate
7
+ if (context.actions.length === 0)
8
+ return;
9
+ const filePath = this.getOutputPath(context);
10
+ const sourceFile = await this.directoryManager.createSourceFile(context.project, filePath);
11
+ // Reducer-specific import logic
12
+ const typeImportName = `${pascalCase(context.docModel.name)}${pascalCase(context.module.name)}Operations`;
13
+ const typeImportPath = `../../gen/${paramCase(context.module.name)}/operations.js`;
14
+ // Import management (shared utility)
15
+ this.importManager.addTypeImport(sourceFile, typeImportName, typeImportPath);
16
+ // AST logic (specific to reducers)
17
+ this.createReducerObject(sourceFile, typeImportName, context.actions);
18
+ await sourceFile.save();
19
+ }
20
+ getOutputPath(context) {
21
+ return this.directoryManager.getReducerPath(context.rootDir, context.docModel.name, context.module.name);
22
+ }
23
+ createReducerObject(sourceFile, typeName, actions) {
24
+ let reducerVar = sourceFile.getVariableDeclaration("reducer");
25
+ if (!reducerVar) {
26
+ sourceFile.addVariableStatement({
27
+ declarationKind: VariableDeclarationKind.Const,
28
+ isExported: true,
29
+ declarations: [
30
+ {
31
+ name: "reducer",
32
+ type: typeName,
33
+ initializer: "{}",
34
+ },
35
+ ],
36
+ });
37
+ reducerVar = sourceFile.getVariableDeclarationOrThrow("reducer");
38
+ }
39
+ else {
40
+ // Ensure correct type
41
+ const typeNode = reducerVar.getTypeNode();
42
+ if (!typeNode || typeNode.getText() !== typeName) {
43
+ reducerVar.setType(typeName);
44
+ }
45
+ }
46
+ const initializer = reducerVar.getInitializerIfKindOrThrow(SyntaxKind.ObjectLiteralExpression);
47
+ for (const action of actions) {
48
+ this.addReducerMethod(initializer, action);
49
+ }
50
+ }
51
+ addReducerMethod(objectLiteral, action) {
52
+ const actionName = camelCase(action.name ?? "");
53
+ if (!actionName)
54
+ return;
55
+ const methodName = `${actionName}Operation`;
56
+ // Skip if method already exists
57
+ if (objectLiteral.getProperty(methodName))
58
+ return;
59
+ objectLiteral.addMethod({
60
+ name: methodName,
61
+ parameters: [{ name: "state" }, { name: "action" }, { name: "dispatch" }],
62
+ statements: [
63
+ `// TODO: Implement "${methodName}" reducer`,
64
+ `throw new Error('Reducer "${methodName}" not yet implemented');`,
65
+ ],
66
+ });
67
+ }
68
+ }
69
+ //# sourceMappingURL=ReducerGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReducerGenerator.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/file-generators/ReducerGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EACL,UAAU,EACV,uBAAuB,GAGxB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAMzD,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACjD,KAAK,CAAC,QAAQ,CAAC,OAA0B;QACvC,iCAAiC;QACjC,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAEzC,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAC7D,OAAO,CAAC,OAAO,EACf,QAAQ,CACT,CAA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W,EAAE,CAAC;YAC1C,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;gBACjD,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,MAAM,WAAW,GAAG,UAAU,CAAC,2BAA2B,CACxD,UAAU,CAAC,uBAAuB,CACnC,CAAC;QAEF,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;IAEO,gBAAgB,CACtB,aAAsC,EACtC,MAAe;QAEf,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,UAAU;YAAE,OAAO;QAExB,MAAM,UAAU,GAAG,GAAG,UAAU,WAAW,CAAC;QAE5C,gCAAgC;QAChC,IAAI,aAAa,CAAC,WAAW,CAAC,UAAU,CAAC;YAAE,OAAO;QAElD,aAAa,CAAC,SAAS,CAAC;YACtB,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;YACzE,UAAU,EAAE;gBACV,uBAAuB,UAAU,WAAW;gBAC5C,6BAA6B,UAAU,0BAA0B;aAClE;SACF,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export * from "./ReducerGenerator.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/file-generators/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./ReducerGenerator.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/file-generators/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./core/index.js";
2
+ export * from "./file-generators/index.js";
3
+ export * from "./utilities/index.js";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ts-morph-generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./core/index.js";
2
+ export * from "./file-generators/index.js";
3
+ export * from "./utilities/index.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ts-morph-generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type Project, type SourceFile } from "ts-morph";
2
+ import { type PHProjectDirectories } from "../core/GenerationContext.js";
3
+ export declare class DirectoryManager {
4
+ private directories;
5
+ constructor(directories?: PHProjectDirectories);
6
+ ensureExists(dirPath: string): Promise<void>;
7
+ getReducerPath(rootDir: string, docModelName: string, moduleName: string): string;
8
+ getActionsPath(rootDir: string, docModelName: string, moduleName: string): string;
9
+ getComponentPath(rootDir: string, docModelName: string, componentName: string): string;
10
+ getTypesPath(rootDir: string, docModelName: string): string;
11
+ createSourceFile(project: Project, filePath: string): Promise<SourceFile>;
12
+ }
13
+ //# sourceMappingURL=DirectoryManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DirectoryManager.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/DirectoryManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAEzE,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,WAAW,CAKjB;gBAEU,WAAW,GAAE,oBAAyB;IAM5C,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUlD,cAAc,CACZ,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM;IAWT,cAAc,CACZ,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM;IAWT,gBAAgB,CACd,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,GACpB,MAAM;IAWT,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM;IAUrD,gBAAgB,CACpB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC;CAOvB"}
@@ -0,0 +1,45 @@
1
+ import { paramCase, pascalCase } from "change-case";
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+ export class DirectoryManager {
5
+ directories = {
6
+ documentModelDir: "document-model",
7
+ editorsDir: "editors",
8
+ processorsDir: "processors",
9
+ subgraphsDir: "subgraphs",
10
+ };
11
+ constructor(directories = {}) {
12
+ this.directories = {
13
+ ...this.directories,
14
+ ...directories,
15
+ };
16
+ }
17
+ async ensureExists(dirPath) {
18
+ try {
19
+ await fs.mkdir(dirPath, { recursive: true });
20
+ }
21
+ catch (err) {
22
+ console.error(`Failed to create directory: ${dirPath}`, err);
23
+ throw err;
24
+ }
25
+ }
26
+ // Path builders for different file types
27
+ getReducerPath(rootDir, docModelName, moduleName) {
28
+ return path.join(rootDir, this.directories.documentModelDir, paramCase(docModelName), "src", "reducers", `${paramCase(moduleName)}.ts`);
29
+ }
30
+ getActionsPath(rootDir, docModelName, moduleName) {
31
+ return path.join(rootDir, this.directories.documentModelDir, paramCase(docModelName), "src", "actions", `${paramCase(moduleName)}.ts`);
32
+ }
33
+ getComponentPath(rootDir, docModelName, componentName) {
34
+ return path.join(rootDir, this.directories.documentModelDir, paramCase(docModelName), "src", "components", `${pascalCase(componentName)}.tsx`);
35
+ }
36
+ getTypesPath(rootDir, docModelName) {
37
+ return path.join(rootDir, this.directories.documentModelDir, paramCase(docModelName), "src", "types.ts");
38
+ }
39
+ async createSourceFile(project, filePath) {
40
+ await this.ensureExists(path.dirname(filePath));
41
+ return (project.addSourceFileAtPathIfExists(filePath) ??
42
+ project.createSourceFile(filePath, "", { overwrite: false }));
43
+ }
44
+ }
45
+ //# sourceMappingURL=DirectoryManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DirectoryManager.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/DirectoryManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AAIxB,MAAM,OAAO,gBAAgB;IACnB,WAAW,GAAmC;QACpD,gBAAgB,EAAE,gBAAgB;QAClC,UAAU,EAAE,SAAS;QACrB,aAAa,EAAE,YAAY;QAC3B,YAAY,EAAE,WAAW;KAC1B,CAAC;IAEF,YAAY,cAAoC,EAAE;QAChD,IAAI,CAAC,WAAW,GAAG;YACjB,GAAG,IAAI,CAAC,WAAW;YACnB,GAAG,WAAW;SACf,CAAC;IACJ,CAAC;IACD,KAAK,CAAC,YAAY,CAAC,OAAe;QAChC,IAAI,CAAC;YACH,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE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,QAAQ,CAAC,CAAC,CAAC;QAChD,OAAO,CACL,OAAO,CAAC,2BAA2B,CAAC,QAAQ,CAAC;YAC7C,OAAO,CAAC,gBAAgB,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAC7D,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ import { type SourceFile } from "ts-morph";
2
+ export interface ImportSpec {
3
+ moduleSpecifier: string;
4
+ namedImports?: string[];
5
+ defaultImport?: string;
6
+ isTypeOnly?: boolean;
7
+ }
8
+ export declare class ImportManager {
9
+ addImport(sourceFile: SourceFile, spec: ImportSpec): void;
10
+ addTypeImport(sourceFile: SourceFile, typeName: string, path: string): void;
11
+ addNamedImports(sourceFile: SourceFile, imports: string[], path: string): void;
12
+ private mergeImports;
13
+ }
14
+ //# sourceMappingURL=ImportManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportManager.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/ImportManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAEnE,MAAM,WAAW,UAAU;IACzB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,qBAAa,aAAa;IACxB,SAAS,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IAazD,aAAa,CAAC,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ3E,eAAe,CACb,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,MAAM,EAAE,EACjB,IAAI,EAAE,MAAM,GACX,IAAI;IAOP,OAAO,CAAC,YAAY;CAkBrB"}
@@ -0,0 +1,40 @@
1
+ export class ImportManager {
2
+ addImport(sourceFile, spec) {
3
+ // Check if import already exists
4
+ const existing = sourceFile
5
+ .getImportDeclarations()
6
+ .find((imp) => imp.getModuleSpecifierValue() === spec.moduleSpecifier);
7
+ if (existing) {
8
+ this.mergeImports(existing, spec);
9
+ }
10
+ else {
11
+ sourceFile.addImportDeclaration(spec);
12
+ }
13
+ }
14
+ addTypeImport(sourceFile, typeName, path) {
15
+ this.addImport(sourceFile, {
16
+ moduleSpecifier: path,
17
+ namedImports: [typeName],
18
+ isTypeOnly: true,
19
+ });
20
+ }
21
+ addNamedImports(sourceFile, imports, path) {
22
+ this.addImport(sourceFile, {
23
+ moduleSpecifier: path,
24
+ namedImports: imports,
25
+ });
26
+ }
27
+ mergeImports(existingImport, newSpec) {
28
+ // Logic to merge named imports if they don't already exist
29
+ if (newSpec.namedImports) {
30
+ const existingNames = existingImport
31
+ .getNamedImports()
32
+ .map((ni) => ni.getName());
33
+ const newNames = newSpec.namedImports.filter((name) => !existingNames.includes(name));
34
+ if (newNames.length > 0) {
35
+ existingImport.addNamedImports(newNames);
36
+ }
37
+ }
38
+ }
39
+ }
40
+ //# sourceMappingURL=ImportManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportManager.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/ImportManager.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,aAAa;IACxB,SAAS,CAAC,UAAsB,EAAE,IAAgB;QAChD,iCAAiC;QACjC,MAAM,QAAQ,GAAG,UAAU;aACxB,qBAAqB,EAAE;aACvB,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,uBAAuB,EAAE,KAAK,IAAI,CAAC,eAAe,CAAC,CAAC;QAEzE,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACpC,CAAC;aAAM,CAAC;YACN,UAAU,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED,aAAa,CAAC,UAAsB,EAAE,QAAgB,EAAE,IAAY;QAClE,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;YACzB,eAAe,EAAE,IAAI;YACrB,YAAY,EAAE,CAAC,QAAQ,CAAC;YACxB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;IACL,CAAC;IAED,eAAe,CACb,UAAsB,EACtB,OAAiB,EACjB,IAAY;QAEZ,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE;YACzB,eAAe,EAAE,IAAI;YACrB,YAAY,EAAE,OAAO;SACtB,CAAC,CAAC;IACL,CAAC;IAEO,YAAY,CAClB,cAAiC,EACjC,OAAmB;QAEnB,2DAA2D;QAC3D,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;YACzB,MAAM,aAAa,GAAG,cAAc;iBACjC,eAAe,EAAE;iBACjB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;YAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,MAAM,CAC1C,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CACxC,CAAC;YAEF,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACxB,cAAc,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ export * from "./DirectoryManager.js";
2
+ export * from "./ImportManager.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./DirectoryManager.js";
2
+ export * from "./ImportManager.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/ts-morph-generator/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC"}