@mxpicture/gcp-functions-generator 1.1.91 → 1.2.2

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 (142) hide show
  1. package/dist/4testing/templates/template.example.d.ts +4 -3
  2. package/dist/4testing/templates/template.example.d.ts.map +1 -1
  3. package/dist/4testing/templates/template.example.js.map +1 -1
  4. package/dist/4testing/templates/template.medication.d.ts +2 -1
  5. package/dist/4testing/templates/template.medication.d.ts.map +1 -1
  6. package/dist/4testing/templates/template.medication.js.map +1 -1
  7. package/dist/4testing/templates/template.settings.d.ts +2 -1
  8. package/dist/4testing/templates/template.settings.d.ts.map +1 -1
  9. package/dist/4testing/templates/template.settings.js.map +1 -1
  10. package/dist/4testing/utils.d.ts +1 -1
  11. package/dist/4testing/utils.d.ts.map +1 -1
  12. package/dist/4testing/utils.js +24 -2
  13. package/dist/4testing/utils.js.map +1 -1
  14. package/dist/common/file.common.d.ts +11 -2
  15. package/dist/common/file.common.d.ts.map +1 -1
  16. package/dist/common/file.common.js +44 -8
  17. package/dist/common/file.common.js.map +1 -1
  18. package/dist/common/index.d.ts +1 -6
  19. package/dist/common/index.d.ts.map +1 -1
  20. package/dist/common/index.js +1 -6
  21. package/dist/common/index.js.map +1 -1
  22. package/dist/common/job.common.d.ts +1 -1
  23. package/dist/common/job.common.d.ts.map +1 -1
  24. package/dist/common/resolve.common.d.ts +17 -0
  25. package/dist/common/resolve.common.d.ts.map +1 -0
  26. package/dist/common/resolve.common.js +46 -0
  27. package/dist/common/resolve.common.js.map +1 -0
  28. package/dist/common/types.common.d.ts +42 -2
  29. package/dist/common/types.common.d.ts.map +1 -1
  30. package/dist/decorator/DecoExtractor.d.ts +22 -0
  31. package/dist/decorator/DecoExtractor.d.ts.map +1 -0
  32. package/dist/{common/Extractor.js → decorator/DecoExtractor.js} +2 -23
  33. package/dist/decorator/DecoExtractor.js.map +1 -0
  34. package/dist/decorator/deco.names.d.ts +4 -45
  35. package/dist/decorator/deco.names.d.ts.map +1 -1
  36. package/dist/decorator/deco.names.js +35 -61
  37. package/dist/decorator/deco.names.js.map +1 -1
  38. package/dist/decorator/index.d.ts +1 -1
  39. package/dist/decorator/index.d.ts.map +1 -1
  40. package/dist/decorator/index.js +1 -1
  41. package/dist/decorator/index.js.map +1 -1
  42. package/dist/exports.gen.json +1357 -0
  43. package/dist/generator/Generator.d.ts +20 -106
  44. package/dist/generator/Generator.d.ts.map +1 -1
  45. package/dist/generator/Generator.js +87 -172
  46. package/dist/generator/Generator.js.map +1 -1
  47. package/dist/generator/GeneratorAnnotations.d.ts +3 -4
  48. package/dist/generator/GeneratorAnnotations.d.ts.map +1 -1
  49. package/dist/generator/GeneratorAnnotations.js +20 -46
  50. package/dist/generator/GeneratorAnnotations.js.map +1 -1
  51. package/dist/generator/GeneratorBackend.d.ts +11 -30
  52. package/dist/generator/GeneratorBackend.d.ts.map +1 -1
  53. package/dist/generator/GeneratorBackend.js +73 -182
  54. package/dist/generator/GeneratorBackend.js.map +1 -1
  55. package/dist/generator/GeneratorDoc.d.ts +8 -9
  56. package/dist/generator/GeneratorDoc.d.ts.map +1 -1
  57. package/dist/generator/GeneratorDoc.js +34 -35
  58. package/dist/generator/GeneratorDoc.js.map +1 -1
  59. package/dist/generator/GeneratorEnum.d.ts +6 -7
  60. package/dist/generator/GeneratorEnum.d.ts.map +1 -1
  61. package/dist/generator/GeneratorEnum.js +26 -15
  62. package/dist/generator/GeneratorEnum.js.map +1 -1
  63. package/dist/generator/GeneratorFrontend.d.ts +5 -6
  64. package/dist/generator/GeneratorFrontend.d.ts.map +1 -1
  65. package/dist/generator/GeneratorFrontend.js +28 -48
  66. package/dist/generator/GeneratorFrontend.js.map +1 -1
  67. package/dist/generator/GeneratorRoutes.d.ts +6 -7
  68. package/dist/generator/GeneratorRoutes.d.ts.map +1 -1
  69. package/dist/generator/GeneratorRoutes.js +26 -31
  70. package/dist/generator/GeneratorRoutes.js.map +1 -1
  71. package/dist/generator/GeneratorZod.d.ts +9 -10
  72. package/dist/generator/GeneratorZod.d.ts.map +1 -1
  73. package/dist/generator/GeneratorZod.js +29 -25
  74. package/dist/generator/GeneratorZod.js.map +1 -1
  75. package/dist/run/GeneratorBarrel.d.ts +11 -0
  76. package/dist/run/GeneratorBarrel.d.ts.map +1 -0
  77. package/dist/run/GeneratorBarrel.js +22 -0
  78. package/dist/run/GeneratorBarrel.js.map +1 -0
  79. package/dist/run/GeneratorBase.d.ts +6 -0
  80. package/dist/run/GeneratorBase.d.ts.map +1 -0
  81. package/dist/run/GeneratorBase.js +4 -0
  82. package/dist/run/GeneratorBase.js.map +1 -0
  83. package/dist/run/GeneratorBaseFile.d.ts +16 -0
  84. package/dist/run/GeneratorBaseFile.d.ts.map +1 -0
  85. package/dist/run/GeneratorBaseFile.js +36 -0
  86. package/dist/run/GeneratorBaseFile.js.map +1 -0
  87. package/dist/run/GeneratorDirectory.d.ts +18 -0
  88. package/dist/run/GeneratorDirectory.d.ts.map +1 -0
  89. package/dist/run/GeneratorDirectory.js +42 -0
  90. package/dist/run/GeneratorDirectory.js.map +1 -0
  91. package/dist/run/GeneratorFile.d.ts +12 -0
  92. package/dist/run/GeneratorFile.d.ts.map +1 -0
  93. package/dist/run/GeneratorFile.js +31 -0
  94. package/dist/run/GeneratorFile.js.map +1 -0
  95. package/dist/run/GeneratorFs.d.ts +27 -0
  96. package/dist/run/GeneratorFs.d.ts.map +1 -0
  97. package/dist/run/GeneratorFs.js +81 -0
  98. package/dist/run/GeneratorFs.js.map +1 -0
  99. package/dist/run/GeneratorPackage.d.ts +21 -0
  100. package/dist/run/GeneratorPackage.d.ts.map +1 -0
  101. package/dist/run/GeneratorPackage.js +57 -0
  102. package/dist/run/GeneratorPackage.js.map +1 -0
  103. package/dist/run/GeneratorRun.d.ts +27 -0
  104. package/dist/run/GeneratorRun.d.ts.map +1 -0
  105. package/dist/run/GeneratorRun.js +60 -0
  106. package/dist/run/GeneratorRun.js.map +1 -0
  107. package/dist/run/GeneratorTemplate.d.ts +10 -0
  108. package/dist/run/GeneratorTemplate.d.ts.map +1 -0
  109. package/dist/run/GeneratorTemplate.js +27 -0
  110. package/dist/run/GeneratorTemplate.js.map +1 -0
  111. package/dist/run/index.d.ts +10 -0
  112. package/dist/run/index.d.ts.map +1 -0
  113. package/dist/run/index.js +11 -0
  114. package/dist/run/index.js.map +1 -0
  115. package/package.json +7 -6
  116. package/dist/common/Barrel.d.ts +0 -75
  117. package/dist/common/Barrel.d.ts.map +0 -1
  118. package/dist/common/Barrel.js +0 -119
  119. package/dist/common/Barrel.js.map +0 -1
  120. package/dist/common/CodeCollector.d.ts +0 -11
  121. package/dist/common/CodeCollector.d.ts.map +0 -1
  122. package/dist/common/CodeCollector.js +0 -29
  123. package/dist/common/CodeCollector.js.map +0 -1
  124. package/dist/common/Collector.d.ts +0 -70
  125. package/dist/common/Collector.d.ts.map +0 -1
  126. package/dist/common/Collector.js +0 -77
  127. package/dist/common/Collector.js.map +0 -1
  128. package/dist/common/Directories.d.ts +0 -60
  129. package/dist/common/Directories.d.ts.map +0 -1
  130. package/dist/common/Directories.js +0 -76
  131. package/dist/common/Directories.js.map +0 -1
  132. package/dist/common/Extractor.d.ts +0 -36
  133. package/dist/common/Extractor.d.ts.map +0 -1
  134. package/dist/common/Extractor.js.map +0 -1
  135. package/dist/common/generator.common.d.ts +0 -80
  136. package/dist/common/generator.common.d.ts.map +0 -1
  137. package/dist/common/generator.common.js +0 -138
  138. package/dist/common/generator.common.js.map +0 -1
  139. package/dist/decorator/deco.imports.d.ts +0 -31
  140. package/dist/decorator/deco.imports.d.ts.map +0 -1
  141. package/dist/decorator/deco.imports.js +0 -71
  142. package/dist/decorator/deco.imports.js.map +0 -1
@@ -1,57 +1,8 @@
1
- import { DecoFile, DecoImport, DecoSingleImport } from "@mxpicture/gcp-functions-common/types";
2
- import { DecoFileType, DecoFileExtension, DecoTargetType, DecoNames, Decorator } from "@mxpicture/gcp-functions-common/decorator";
3
- import { Collector } from "../common/Collector.js";
4
- import { GeneratorEnv } from "../common/types.common.js";
5
- import { CodeCollector } from "../common/CodeCollector.js";
6
- /**
7
- * Base structure shared by all generator outputs, containing imports and code lines.
8
- */
9
- export interface GeneratorBase {
10
- imports: DecoImport[];
11
- code: string[];
12
- }
13
- /**
14
- * Generator output for a single decorator header, including a name identifier.
15
- */
16
- export interface GeneratorHeader extends GeneratorBase {
17
- name: string;
18
- }
19
- /**
20
- * Full result file produced by a generator, ready to be written to disk.
21
- */
22
- export interface GeneratorResultFile extends GeneratorBase {
23
- type: DecoFileType;
24
- ext: DecoFileExtension;
25
- inputFilePath: string;
26
- targetFilePath: string;
27
- targetType: DecoTargetType;
28
- importsCode: string[];
29
- }
30
- /**
31
- * Pairs a decorator with its resolved names for processing by a generator.
32
- */
33
- export interface GeneratorRunItem {
34
- decorator: Decorator;
35
- names: DecoNames;
36
- }
37
- /**
38
- * A record of run items keyed by decorator name, providing lookup for cross-references.
39
- */
40
- export type GeneratorRunItems = Record<string, GeneratorRunItem>;
41
- /**
42
- * Converts an array of {@link DecoImport} entries into TypeScript import statement strings.
43
- *
44
- * @param imports - The imports to convert.
45
- * @returns An array of import statement strings (empty imports are filtered out).
46
- */
47
- export declare const importsToCode: (imports: DecoImport[]) => string[];
48
- /**
49
- * Async variant of {@link importsToCode}.
50
- *
51
- * @param imports - The imports to convert.
52
- * @returns A promise resolving to an array of import statement strings.
53
- */
54
- export declare const importsToCodeAsync: (imports: DecoImport[]) => Promise<string[]>;
1
+ import type { DecoFile } from "@mxpicture/gcp-functions-common/types";
2
+ import { type DecoFileType, type DecoFileExtension, DecoPackageType, type Decorator } from "@mxpicture/gcp-functions-common/decorator";
3
+ import type { GeneratorEnv, GeneratorHeader, GeneratorRunItem, GeneratorRunItems, GeneratorRunResult } from "../common/types.common.js";
4
+ import type { GeneratorFs } from "../run/GeneratorFs.js";
5
+ import type { GeneratorFile } from "../run/GeneratorFile.js";
55
6
  /**
56
7
  * Abstract base class for all code generators.
57
8
  *
@@ -61,24 +12,22 @@ export declare const importsToCodeAsync: (imports: DecoImport[]) => Promise<stri
61
12
  * formatting, and writing to disk.
62
13
  */
63
14
  export declare abstract class Generator {
64
- readonly order: number;
65
- readonly type: DecoFileType;
15
+ readonly fileType: DecoFileType;
66
16
  readonly ext: DecoFileExtension;
67
- readonly targetType: DecoTargetType;
68
- readonly collector: Collector;
69
- readonly useAdditionalImports: boolean;
70
- protected usedImports: DecoSingleImport[];
17
+ readonly packageType: DecoPackageType;
71
18
  /**
72
19
  * Creates a new generator.
73
20
  *
74
- * @param order - Execution order generators.
75
- * @param type - The decorator file type this generator produces.
21
+ * @param fileType - The decorator file type this generator produces.
76
22
  * @param ext - The output file extension.
77
- * @param targetType - The target package (common, backend, frontend).
78
- * @param collector - The shared collector for cross-generator lookups.
23
+ * @param packageType - The target package (common, backend, frontend).
79
24
  * @param useAdditionalImports - Whether to include additional imports from the decorator.
80
25
  */
81
- constructor(order: number, type: DecoFileType, ext: DecoFileExtension, targetType: DecoTargetType, collector: Collector, useAdditionalImports?: boolean);
26
+ constructor(p: {
27
+ fileType: DecoFileType;
28
+ ext: DecoFileExtension;
29
+ packageType: DecoPackageType;
30
+ });
82
31
  /**
83
32
  * Processes a decorator file by running all its headers through the generator.
84
33
  *
@@ -87,46 +36,11 @@ export declare abstract class Generator {
87
36
  * @returns A promise resolving to the assembled result file.
88
37
  * @throws Error if no headers are produced for the file.
89
38
  */
90
- run(file: DecoFile, env: GeneratorEnv): Promise<GeneratorResultFile>;
91
- /**
92
- * Formats and writes one or more generator result files to disk.
93
- *
94
- * @param files - The result files to write.
95
- */
96
- static write(...files: GeneratorResultFile[]): Promise<void>;
97
- /**
98
- * Resolves an import path from the current generator's context to a target type and file type.
99
- *
100
- * @param targetType - The target type of the import destination.
101
- * @param fileType - The file type of the import destination.
102
- * @returns The resolved import path string.
103
- */
104
- resolveImport(targetType: DecoTargetType, fileType: DecoFileType): string;
105
- /**
106
- * Resolves an import path to the common target for the given file type.
107
- *
108
- * @param fileType - The file type to import from common.
109
- * @returns The resolved import path.
110
- */
111
- importCommon(fileType: DecoFileType): string;
112
- /**
113
- * Resolves an import path to the frontend target for the given file type.
114
- *
115
- * @param fileType - The file type to import from frontend.
116
- * @returns The resolved import path.
117
- */
118
- importFrontend(fileType: DecoFileType): string;
119
- /**
120
- * Resolves an import path to the backend target for the given file type.
121
- *
122
- * @param fileType - The file type to import from backend.
123
- * @returns The resolved import path.
124
- */
125
- importBackend(fileType: DecoFileType): string;
126
- protected processHeader(curretItem: GeneratorRunItem, all: GeneratorRunItems, env: GeneratorEnv): Promise<(GeneratorHeader & {
127
- inputFilePath: string;
128
- }) | null>;
129
- protected i(_prop: string, isType?: boolean): string;
130
- protected abstract runHeader(current: GeneratorRunItem, all: GeneratorRunItems, env: GeneratorEnv, result: CodeCollector): Promise<string | null>;
39
+ run4codes(decoFiles: DecoFile[], env: GeneratorEnv, fs: GeneratorFs): Promise<void>;
40
+ protected run4code(decoFile: DecoFile, env: GeneratorEnv, fs: GeneratorFs, runItems: GeneratorRunItems): Promise<GeneratorFile>;
41
+ run4imports(): Promise<void>;
42
+ protected buildRunItems(packageType: DecoPackageType, decorators: Decorator[]): GeneratorRunItems;
43
+ protected processHeader(curretItem: GeneratorRunItem, env: GeneratorEnv): Promise<GeneratorHeader | null>;
44
+ protected abstract runHeader(item: GeneratorRunItem, env: GeneratorEnv): Promise<GeneratorRunResult | null>;
131
45
  }
132
46
  //# sourceMappingURL=Generator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["../../src/generator/Generator.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,QAAQ,EACR,UAAU,EACV,gBAAgB,EACjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,SAAS,EACT,SAAS,EACV,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AASnD,OA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AkB,GAAG,IAAI,CAAC;CACtC"}
@@ -1,29 +1,7 @@
1
- import { basename, dirname } from "node:path";
2
- import { mkdir, writeFile } from "node:fs/promises";
3
- import { DecoFileExtension, DecoTargetType, } from "@mxpicture/gcp-functions-common/decorator";
4
- import { directories } from "../common/Directories.js";
5
- import { decoBackendNamesAsync, decoFrontendNamesAsync, decoNamesAsync, } from "../decorator/deco.names.js";
6
- import { formatCode, formatJson } from "@mxpicture/build-api/code";
1
+ import { DecoPackageType, } from "@mxpicture/gcp-functions-common/decorator";
7
2
  import { toFilename } from "../common/file.common.js";
8
- import { CodeCollector } from "../common/CodeCollector.js";
9
- const importToCode = (imp) => imp.props.length > 0
10
- ? `import ${imp.isType ? "type " : ""}{ ${[...imp.props].join(", ")} } from "${imp.path}"`
11
- : null;
12
- const importToCodeAsync = async (imp) => Promise.resolve().then(() => importToCode(imp));
13
- /**
14
- * Converts an array of {@link DecoImport} entries into TypeScript import statement strings.
15
- *
16
- * @param imports - The imports to convert.
17
- * @returns An array of import statement strings (empty imports are filtered out).
18
- */
19
- export const importsToCode = (imports) => imports.map(importToCode).filter((imp) => imp !== null);
20
- /**
21
- * Async variant of {@link importsToCode}.
22
- *
23
- * @param imports - The imports to convert.
24
- * @returns A promise resolving to an array of import statement strings.
25
- */
26
- export const importsToCodeAsync = async (imports) => (await Promise.all(imports.map(importToCodeAsync))).filter((imp) => imp !== null);
3
+ import { basename } from "node:path";
4
+ import { decoBackendNames, decoFrontendNames, decoNames, } from "../decorator/deco.names.js";
27
5
  /**
28
6
  * Abstract base class for all code generators.
29
7
  *
@@ -33,30 +11,21 @@ export const importsToCodeAsync = async (imports) => (await Promise.all(imports.
33
11
  * formatting, and writing to disk.
34
12
  */
35
13
  export class Generator {
36
- order;
37
- type;
14
+ fileType;
38
15
  ext;
39
- targetType;
40
- collector;
41
- useAdditionalImports;
42
- usedImports = [];
16
+ packageType;
43
17
  /**
44
18
  * Creates a new generator.
45
19
  *
46
- * @param order - Execution order generators.
47
- * @param type - The decorator file type this generator produces.
20
+ * @param fileType - The decorator file type this generator produces.
48
21
  * @param ext - The output file extension.
49
- * @param targetType - The target package (common, backend, frontend).
50
- * @param collector - The shared collector for cross-generator lookups.
22
+ * @param packageType - The target package (common, backend, frontend).
51
23
  * @param useAdditionalImports - Whether to include additional imports from the decorator.
52
24
  */
53
- constructor(order, type, ext, targetType, collector, useAdditionalImports = false) {
54
- this.order = order;
55
- this.type = type;
56
- this.ext = ext;
57
- this.targetType = targetType;
58
- this.collector = collector;
59
- this.useAdditionalImports = useAdditionalImports;
25
+ constructor(p) {
26
+ this.fileType = p.fileType;
27
+ this.ext = p.ext;
28
+ this.packageType = p.packageType;
60
29
  }
61
30
  /**
62
31
  * Processes a decorator file by running all its headers through the generator.
@@ -66,147 +35,93 @@ export class Generator {
66
35
  * @returns A promise resolving to the assembled result file.
67
36
  * @throws Error if no headers are produced for the file.
68
37
  */
69
- async run(file, env) {
70
- let result = null;
71
- const runHeaders = {};
72
- const resultsCollector = new CodeCollector();
73
- for (const decorator of file.decorators) {
38
+ async run4codes(decoFiles, env, fs) {
39
+ const collects = decoFiles.map((decoFile) => ({
40
+ decoFile,
41
+ runItems: this.buildRunItems(this.packageType, decoFile.decorators),
42
+ }));
43
+ await Promise.all(collects.map(async (collect) => this.run4code(collect.decoFile, env, fs, collect.runItems)));
44
+ }
45
+ async run4code(decoFile, env, fs, runItems) {
46
+ const headerResults = (await Promise.all(Object.values(runItems).map((p) => this.processHeader(p, env)))).filter((h) => !!h);
47
+ if (headerResults.length === 0)
48
+ throw new Error(`Generator ${this.fileType}, file ${decoFile.templateRepoFilePath}: no headers provided`);
49
+ const filename = toFilename({
50
+ filename: basename(headerResults[0].inputFilePath),
51
+ fileType: this.fileType,
52
+ ext: this.ext,
53
+ generated: true,
54
+ });
55
+ const file = fs.file(this.packageType, this.fileType, filename);
56
+ file.code = headerResults.flatMap((res) => res.code);
57
+ return file;
58
+ }
59
+ async run4imports() {
60
+ // file.code = headerResults.flatMap((result) => result.code);
61
+ // const imports = nodesToImports(this.expFinder.requestedNodes);
62
+ // for (const imp of imports) {
63
+ // const parts = splitPackagePath(imp.path);
64
+ // if (!parts) continue;
65
+ // imp.path = this.resolveImp(parts.packageType, parts.type);
66
+ // }
67
+ // resultFile.importsCode = importsToCode(imports);
68
+ // return resultFile;
69
+ }
70
+ // /**
71
+ // * Resolves an import path from the current generator's context to a target type and file type.
72
+ // *
73
+ // * @param packageType - The target type of the import destination.
74
+ // * @param fileType - The file type of the import destination.
75
+ // * @returns The resolved import path string.
76
+ // */
77
+ // public resolveImp(
78
+ // packageType: DecoPackageType,
79
+ // fileType: DecoFileType,
80
+ // ): string {
81
+ // return directories.resolveImport(
82
+ // { packageType, fileType },
83
+ // { packageType: this.packageType, fileType: this.type },
84
+ // );
85
+ // }
86
+ // public resolveImpString(path: string): string {
87
+ // const parts = splitPackagePath(path);
88
+ // return parts ? this.resolveImp(parts.packageType, parts.type) : path;
89
+ // }
90
+ // public resolveImpDeco(deco: DecoImport): DecoImport {
91
+ // deco.path = this.resolveImpString(deco.path);
92
+ // return deco;
93
+ // }
94
+ buildRunItems(packageType, decorators) {
95
+ const runItems = {};
96
+ const allNames = [];
97
+ for (const decorator of decorators) {
74
98
  const extr = decorator.extractRaw();
75
- const names = this.targetType === DecoTargetType.backend
76
- ? await decoBackendNamesAsync(extr.name, extr.namespace)
77
- : this.targetType === DecoTargetType.frontend
78
- ? await decoFrontendNamesAsync(extr.name, extr.namespace)
79
- : await decoNamesAsync(extr.name, extr.namespace);
80
- runHeaders[extr.name] = {
99
+ const names = packageType === DecoPackageType.backend
100
+ ? decoBackendNames(extr.name, extr.namespace)
101
+ : packageType === DecoPackageType.frontend
102
+ ? decoFrontendNames(extr.name, extr.namespace)
103
+ : decoNames(extr.name, extr.namespace);
104
+ allNames.push(names);
105
+ runItems[extr.name] = {
81
106
  decorator,
82
107
  names,
108
+ allNames,
83
109
  };
84
110
  }
85
- const interfaceResults = await Promise.all(Object.values(runHeaders).map((p) => this.processHeader(p, runHeaders, env)));
86
- for (const interfaceResult of interfaceResults) {
87
- if (!interfaceResult)
88
- continue;
89
- if (!result) {
90
- const targetFilename = toFilename({
91
- filename: basename(interfaceResult.inputFilePath),
92
- type: this.type,
93
- ext: this.ext,
94
- generated: true,
95
- });
96
- result = {
97
- inputFilePath: interfaceResult.inputFilePath,
98
- targetFilePath: directories.toTargetPath(this.type, targetFilename, this.targetType),
99
- targetType: this.targetType,
100
- imports: [],
101
- importsCode: [],
102
- code: [],
103
- ext: this.ext,
104
- type: this.type,
105
- };
106
- }
107
- resultsCollector.addCode(...interfaceResult.code);
108
- resultsCollector.addImport(...interfaceResult.imports);
109
- }
110
- if (!result)
111
- throw new Error(`Generator ${this.type}, file ${file.templateRepoFilePath}: no headers provided`);
112
- result.code = resultsCollector.code;
113
- result.imports = resultsCollector.imports;
114
- result.importsCode = await importsToCodeAsync(result.imports);
115
- return result;
111
+ return runItems;
116
112
  }
117
- /**
118
- * Formats and writes one or more generator result files to disk.
119
- *
120
- * @param files - The result files to write.
121
- */
122
- static async write(...files) {
123
- const promises = [];
124
- for (const file of files) {
125
- const preCode = [...file.importsCode, "", ...file.code].join("\n");
126
- promises.push((async () => {
127
- let code;
128
- if (file.ext === DecoFileExtension.ts)
129
- code = await formatCode(preCode);
130
- else if (file.ext === DecoFileExtension.json)
131
- code = await formatJson(preCode);
132
- else
133
- code = preCode;
134
- await mkdir(dirname(file.targetFilePath), { recursive: true });
135
- return writeFile(file.targetFilePath, code);
136
- })());
137
- }
138
- await Promise.all(promises);
139
- }
140
- /**
141
- * Resolves an import path from the current generator's context to a target type and file type.
142
- *
143
- * @param targetType - The target type of the import destination.
144
- * @param fileType - The file type of the import destination.
145
- * @returns The resolved import path string.
146
- */
147
- resolveImport(targetType, fileType) {
148
- return directories.resolveImport({ targetType, fileType }, { targetType: this.targetType, fileType: this.type });
149
- }
150
- /**
151
- * Resolves an import path to the common target for the given file type.
152
- *
153
- * @param fileType - The file type to import from common.
154
- * @returns The resolved import path.
155
- */
156
- importCommon(fileType) {
157
- return this.resolveImport(DecoTargetType.common, fileType);
158
- }
159
- /**
160
- * Resolves an import path to the frontend target for the given file type.
161
- *
162
- * @param fileType - The file type to import from frontend.
163
- * @returns The resolved import path.
164
- */
165
- importFrontend(fileType) {
166
- return this.resolveImport(DecoTargetType.frontend, fileType);
167
- }
168
- /**
169
- * Resolves an import path to the backend target for the given file type.
170
- *
171
- * @param fileType - The file type to import from backend.
172
- * @returns The resolved import path.
173
- */
174
- importBackend(fileType) {
175
- return this.resolveImport(DecoTargetType.backend, fileType);
176
- }
177
- async processHeader(curretItem, all, env) {
178
- const { decorator, names } = curretItem;
113
+ async processHeader(curretItem, env) {
114
+ const { decorator } = curretItem;
179
115
  const raw = decorator.extractRaw();
180
- this.collector.add(names.basename, this.targetType, {
181
- names: names,
182
- });
183
- const result = new CodeCollector();
184
- const name = await this.runHeader(curretItem, all, env, result);
185
- if (!name)
116
+ const headerResult = await this.runHeader(curretItem, env);
117
+ if (!headerResult)
186
118
  return null;
119
+ // this.processPredictions(headerResult.code);
187
120
  return {
188
- name,
121
+ name: headerResult.name,
189
122
  inputFilePath: raw.inputFilePath,
190
- code: [...result.code],
191
- imports: this.useAdditionalImports &&
192
- raw.additionalImports &&
193
- raw.additionalImports.length > 0
194
- ? [...result.imports, ...raw.additionalImports]
195
- : [...result.imports],
123
+ code: [...headerResult.code],
196
124
  };
197
125
  }
198
- // i for import
199
- i(_prop, isType) {
200
- // todo use it
201
- const prop = _prop.substring(0);
202
- let found = this.usedImports.find((i) => i.prop === prop);
203
- if (!found) {
204
- found = { prop, isType };
205
- this.usedImports.push(found);
206
- }
207
- if (found.isType && !isType)
208
- found.isType = false;
209
- return prop;
210
- }
211
126
  }
212
127
  //# sourceMappingURL=Generator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Generator.js","sourceRoot":"","sources":["../../src/generator/Generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OA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AAS,IAAI,UAAU,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;YAEpC,MAAM,KAAK,GACT,WAAW,KAAK,eAAe,CAAC,OAAO;gBACrC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBAC7C,CAAC,CAAC,WAAW,KAAK,eAAe,CAAC,QAAQ;oBACxC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBAC9C,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAE7C,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAErB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;gBACpB,SAAS;gBACT,KAAK;gBACL,QAAQ;aACT,CAAC;QACJ,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAES,KAAK,CAAC,aAAa,CAC3B,UAA4B,EAC5B,GAAiB;QAEjB,MAAM,EAAE,SAAS,EAAE,GAAG,UAAU,CAAC;QACjC,MAAM,GAAG,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC;QAEnC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAC3D,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC;QAE/B,8CAA8C;QAE9C,OAAO;YACL,IAAI,EAAE,YAAY,CAAC,IAAI;YACvB,aAAa,EAAE,GAAG,CAAC,aAAa;YAChC,IAAI,EAAE,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC;SAC7B,CAAC;IACJ,CAAC;CAMF"}
@@ -1,6 +1,5 @@
1
- import { Generator, GeneratorRunItem, GeneratorRunItems } from "./Generator.js";
2
- import { CodeCollector } from "../common/CodeCollector.js";
3
- import { GeneratorEnv } from "../common/types.common.js";
1
+ import { Generator } from "./Generator.js";
2
+ import type { GeneratorEnv, GeneratorRunItem, GeneratorRunResult } from "../common/types.common.js";
4
3
  /**
5
4
  * Generator that produces annotation metadata and initial-value factory functions.
6
5
  *
@@ -10,7 +9,7 @@ import { GeneratorEnv } from "../common/types.common.js";
10
9
  */
11
10
  export declare class GeneratorAnnotations extends Generator {
12
11
  constructor();
13
- protected runHeader(current: GeneratorRunItem, all: GeneratorRunItems, env: GeneratorEnv, result: CodeCollector): Promise<string | null>;
12
+ protected runHeader(item: GeneratorRunItem, env: GeneratorEnv): Promise<GeneratorRunResult | null>;
14
13
  }
15
14
  declare const _default: GeneratorAnnotations;
16
15
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"GeneratorAnnotations.d.ts","sourceRoot":"","sources":["../../src/generator/GeneratorAnnotations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAQhF,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AASzD;;;;;;GAMG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;;cAWxB,SAAS,CAChC,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,iBAAiB,EACtB,GAAG,EAAE,YAAY,EACjB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;CAiH1B;;AAED,wBAA0C"}
1
+ {"version":3,"file":"GeneratorAnnotations.d.ts","sourceRoot":"","sources":["../../src/generator/GeneratorAnnotations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAO3C,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,2BAA2B,CAAC;AASnC;;;;;;GAMG;AACH,qBAAa,oBAAqB,SAAQ,SAAS;;cASxB,SAAS,CAChC,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,YAAY,GAChB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;CAuEtC;;AAED,wBAA0C"}
@@ -1,7 +1,6 @@
1
1
  import { Generator } from "./Generator.js";
2
- import { Collector } from "../common/Collector.js";
3
2
  import { formatJsonStringify } from "@mxpicture/build-api/code";
4
- import { DecoFileExtension, DecoFileType, DecoTargetType, } from "@mxpicture/gcp-functions-common/decorator";
3
+ import { DecoFileExtension, DecoFileType, DecoPackageType, } from "@mxpicture/gcp-functions-common/decorator";
5
4
  const typeRegex = /\"type\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
6
5
  const itemTypeRegex = /\"itemType\": \"(DecoPropertyType\.|)([a-zA-Z][a-zA-Z0-9]*)\"/;
7
6
  const propertyRefRegex = /\"propertyRef\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
@@ -16,59 +15,46 @@ const dateFormatRegex = /\"dateFormat\": \"([a-zA-Z][a-zA-Z0-9]*)\"/;
16
15
  */
17
16
  export class GeneratorAnnotations extends Generator {
18
17
  constructor() {
19
- super(20, DecoFileType.annotations, DecoFileExtension.ts, DecoTargetType.common, Collector.instance());
20
- }
21
- async runHeader(current, all, env, result) {
22
- const names = current.names;
23
- result.addImport({
24
- path: "@mxpicture/gcp-functions-common/types",
25
- props: ["AnnotationsHeader"],
26
- isType: true,
27
- }, {
28
- path: "@mxpicture/gcp-functions-common/helper",
29
- props: ["annoDocInitial"],
30
- isType: false,
31
- }, {
32
- path: this.importCommon(DecoFileType.doc),
33
- props: [names.doc],
34
- isType: true,
18
+ super({
19
+ fileType: DecoFileType.annotations,
20
+ ext: DecoFileExtension.ts,
21
+ packageType: DecoPackageType.common,
35
22
  });
36
- const importDecoProps = new Set();
37
- const importDecoTypeProps = new Set();
38
- const header = current.decorator.extractAnnotations();
23
+ }
24
+ async runHeader(item, env) {
25
+ void env;
26
+ const names = item.names;
27
+ const code = [];
28
+ const header = item.decorator.extractAnnotations();
39
29
  const json = await formatJsonStringify(JSON.stringify(header));
40
30
  const lines = json.split("\n");
41
- result.addCode("", `export const ${names.initialFunc} = (): Partial<${this.i(names.doc, true)}> => ${this.i("annoDocInitial")}(${names.annotations}.properties);`, "");
42
- result.addCode(`export const ${names.annotations}: ${this.i("AnnotationsHeader", true)} = `);
31
+ code.push("", `export const ${names.initialFunc} = (): Partial<${names.doc}> => annoDocInitial(${names.annotations}.properties);`, "");
32
+ code.push(`export const ${names.annotations}: AnnotationsHeader = `);
43
33
  // replace enums and types
44
34
  for (let line of lines) {
45
35
  // type
46
36
  let match = null;
47
37
  match = line.match(typeRegex);
48
38
  while (match && match.length > 1) {
49
- importDecoProps.add("DecoPropertyType"); // todo remove after implementation of this.i()
50
- line = line.replace(typeRegex, `type: ${this.i("DecoPropertyType")}.${match[1]}`);
39
+ line = line.replace(typeRegex, `type: DecoPropertyType.${match[1]}`);
51
40
  match = line.match(typeRegex);
52
41
  }
53
42
  // itemType
54
43
  match = line.match(itemTypeRegex);
55
44
  while (match && match.length > 2) {
56
- importDecoProps.add("DecoPropertyType"); // todo remove after implementation of this.i()
57
- line = line.replace(itemTypeRegex, `itemType: ${this.i("DecoPropertyType")}.${match[2]}`);
45
+ line = line.replace(itemTypeRegex, `itemType: DecoPropertyType.${match[2]}`);
58
46
  match = line.match(itemTypeRegex);
59
47
  }
60
48
  // propertyRef
61
49
  match = line.match(propertyRefRegex);
62
50
  while (match && match.length > 1) {
63
- importDecoTypeProps.add("DecoPropertyDataWoType"); // todo remove after implementation of this.i()
64
- line = line.replace(propertyRefRegex, `propertyRef: "${match[1]}" as keyof ${this.i("DecoPropertyDataWoType")}`);
51
+ line = line.replace(propertyRefRegex, `propertyRef: "${match[1]}" as keyof DecoPropertyDataWoType`);
65
52
  match = line.match(propertyRefRegex);
66
53
  }
67
54
  // dateFormat
68
55
  match = line.match(dateFormatRegex);
69
56
  while (match && match.length > 1) {
70
- importDecoProps.add("DecoDateFormat"); // todo remove after implementation of this.i()
71
- line = line.replace(dateFormatRegex, `dateFormat: ${this.i("DecoDateFormat")}.${match[1]}`);
57
+ line = line.replace(dateFormatRegex, `dateFormat: DecoDateFormat.${match[1]}`);
72
58
  match = line.match(dateFormatRegex);
73
59
  }
74
60
  // subHeader(Name)
@@ -77,22 +63,10 @@ export class GeneratorAnnotations extends Generator {
77
63
  line = line.replace(subHeaderNameRegex, `subHeader: ${match[1]}`);
78
64
  match = line.match(subHeaderNameRegex);
79
65
  }
80
- result.addCode(line);
66
+ code.push(line);
81
67
  }
82
- result.addCode(";");
83
- if (importDecoTypeProps.size > 0)
84
- result.addImport({
85
- path: "@mxpicture/gcp-functions-common/decorator",
86
- props: [...importDecoTypeProps],
87
- isType: true,
88
- });
89
- if (importDecoProps.size > 0)
90
- result.addImport({
91
- path: "@mxpicture/gcp-functions-common/decorator",
92
- props: [...importDecoProps],
93
- isType: false,
94
- });
95
- return current.decorator.name;
68
+ code.push(";");
69
+ return { name: item.decorator.name, code };
96
70
  }
97
71
  }
98
72
  export default new GeneratorAnnotations();