@ingenyus/swarm-wasp 0.1.0 → 0.2.0

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 (123) hide show
  1. package/README.md +229 -21
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/common/filesystem.d.ts +0 -14
  4. package/dist/common/filesystem.d.ts.map +1 -1
  5. package/dist/common/filesystem.js +123 -0
  6. package/dist/common/index.js +391 -0
  7. package/dist/common/plugin.js +41 -0
  8. package/dist/common/prisma.js +140 -0
  9. package/dist/common/schemas.d.ts +8 -42
  10. package/dist/common/schemas.d.ts.map +1 -1
  11. package/dist/common/schemas.js +54 -0
  12. package/dist/common/templates.js +52 -0
  13. package/dist/generators/action/action-generator.d.ts +16 -29
  14. package/dist/generators/action/action-generator.d.ts.map +1 -1
  15. package/dist/generators/action/action-generator.js +1429 -0
  16. package/dist/generators/action/index.js +1429 -0
  17. package/dist/generators/action/schema.d.ts +11 -23
  18. package/dist/generators/action/schema.d.ts.map +1 -1
  19. package/dist/generators/action/schema.js +119 -0
  20. package/dist/generators/api/api-generator.d.ts +19 -26
  21. package/dist/generators/api/api-generator.d.ts.map +1 -1
  22. package/dist/generators/api/api-generator.js +1108 -0
  23. package/dist/generators/api/index.js +1108 -0
  24. package/dist/generators/api/schema.d.ts +13 -21
  25. package/dist/generators/api/schema.d.ts.map +1 -1
  26. package/dist/generators/api/schema.js +121 -0
  27. package/dist/generators/api-namespace/api-namespace-generator.d.ts +10 -17
  28. package/dist/generators/api-namespace/api-namespace-generator.d.ts.map +1 -1
  29. package/dist/generators/api-namespace/api-namespace-generator.js +1032 -0
  30. package/dist/generators/api-namespace/index.js +1032 -0
  31. package/dist/generators/api-namespace/schema.d.ts +4 -12
  32. package/dist/generators/api-namespace/schema.d.ts.map +1 -1
  33. package/dist/generators/api-namespace/schema.js +93 -0
  34. package/dist/generators/base/{entity-generator.base.d.ts → component-generator.base.d.ts} +9 -9
  35. package/dist/generators/base/component-generator.base.d.ts.map +1 -0
  36. package/dist/generators/base/component-generator.base.js +935 -0
  37. package/dist/generators/base/index.d.ts +1 -1
  38. package/dist/generators/base/index.d.ts.map +1 -1
  39. package/dist/generators/base/index.js +1334 -0
  40. package/dist/generators/base/operation-generator.base.d.ts +12 -3
  41. package/dist/generators/base/operation-generator.base.d.ts.map +1 -1
  42. package/dist/generators/base/operation-generator.base.js +1335 -0
  43. package/dist/generators/base/wasp-generator.base.d.ts +2 -1
  44. package/dist/generators/base/wasp-generator.base.d.ts.map +1 -1
  45. package/dist/generators/base/wasp-generator.base.js +710 -0
  46. package/dist/generators/config/config-generator.d.ts +7 -4
  47. package/dist/generators/config/config-generator.d.ts.map +1 -1
  48. package/dist/generators/config/config-generator.js +0 -0
  49. package/dist/generators/config/index.js +600 -0
  50. package/dist/generators/config/wasp-config-generator.d.ts +1 -1
  51. package/dist/generators/config/wasp-config-generator.d.ts.map +1 -1
  52. package/dist/generators/config/wasp-config-generator.js +600 -0
  53. package/dist/generators/crud/crud-generator.d.ts +34 -22
  54. package/dist/generators/crud/crud-generator.d.ts.map +1 -1
  55. package/dist/generators/crud/crud-generator.js +1554 -0
  56. package/dist/generators/crud/index.js +1554 -0
  57. package/dist/generators/crud/schema.d.ts +25 -18
  58. package/dist/generators/crud/schema.d.ts.map +1 -1
  59. package/dist/generators/crud/schema.js +137 -0
  60. package/dist/generators/feature/feature-generator.d.ts +20 -0
  61. package/dist/generators/feature/feature-generator.d.ts.map +1 -0
  62. package/dist/generators/feature/feature-generator.js +769 -0
  63. package/dist/generators/feature/index.d.ts +2 -0
  64. package/dist/generators/feature/index.d.ts.map +1 -0
  65. package/dist/generators/feature/index.js +769 -0
  66. package/dist/generators/feature/schema.d.ts +5 -0
  67. package/dist/generators/feature/schema.d.ts.map +1 -0
  68. package/dist/generators/feature/schema.js +90 -0
  69. package/dist/generators/index.d.ts +1 -1
  70. package/dist/generators/index.d.ts.map +1 -1
  71. package/dist/generators/index.js +2215 -0
  72. package/dist/generators/job/index.js +1103 -0
  73. package/dist/generators/job/job-generator.d.ts +12 -23
  74. package/dist/generators/job/job-generator.d.ts.map +1 -1
  75. package/dist/generators/job/job-generator.js +1103 -0
  76. package/dist/generators/job/schema.d.ts +6 -18
  77. package/dist/generators/job/schema.d.ts.map +1 -1
  78. package/dist/generators/job/schema.js +156 -0
  79. package/dist/generators/query/index.js +1429 -0
  80. package/dist/generators/query/query-generator.d.ts +16 -29
  81. package/dist/generators/query/query-generator.d.ts.map +1 -1
  82. package/dist/generators/query/query-generator.js +1429 -0
  83. package/dist/generators/query/schema.d.ts +11 -23
  84. package/dist/generators/query/schema.d.ts.map +1 -1
  85. package/dist/generators/query/schema.js +119 -0
  86. package/dist/generators/route/index.js +1042 -0
  87. package/dist/generators/route/route-generator.d.ts +11 -20
  88. package/dist/generators/route/route-generator.d.ts.map +1 -1
  89. package/dist/generators/route/route-generator.js +1042 -0
  90. package/dist/generators/route/schema.d.ts +5 -15
  91. package/dist/generators/route/schema.d.ts.map +1 -1
  92. package/dist/generators/route/schema.js +94 -0
  93. package/dist/index.d.ts +2 -10
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +1730 -1839
  96. package/dist/plugins/index.d.ts +2 -0
  97. package/dist/plugins/index.d.ts.map +1 -0
  98. package/dist/plugins/wasp.d.ts +3 -0
  99. package/dist/plugins/wasp.d.ts.map +1 -0
  100. package/dist/types/constants.d.ts +4 -22
  101. package/dist/types/constants.d.ts.map +1 -1
  102. package/dist/types/constants.js +8 -2
  103. package/dist/types/index.d.ts +2 -2
  104. package/dist/types/index.d.ts.map +1 -1
  105. package/dist/types/index.js +8 -2
  106. package/dist/wasp-config/app.d.ts +2 -1
  107. package/dist/wasp-config/app.d.ts.map +1 -1
  108. package/dist/wasp-config/app.js +357 -0
  109. package/dist/wasp-config/index.js +357 -0
  110. package/dist/wasp-config/stubs/index.js +48 -0
  111. package/package.json +5 -14
  112. package/dist/generators/args.types.d.ts +0 -85
  113. package/dist/generators/args.types.d.ts.map +0 -1
  114. package/dist/generators/base/entity-generator.base.d.ts.map +0 -1
  115. package/dist/generators/feature-directory/feature-directory-generator.d.ts +0 -18
  116. package/dist/generators/feature-directory/feature-directory-generator.d.ts.map +0 -1
  117. package/dist/generators/feature-directory/index.d.ts +0 -2
  118. package/dist/generators/feature-directory/index.d.ts.map +0 -1
  119. package/dist/generators/feature-directory/schema.d.ts +0 -8
  120. package/dist/generators/feature-directory/schema.d.ts.map +0 -1
  121. package/dist/plugin.d.ts +0 -6
  122. package/dist/plugin.d.ts.map +0 -1
  123. /package/dist/generators/{feature-directory → feature}/templates/feature.wasp.eta +0 -0
@@ -0,0 +1,600 @@
1
+ // src/generators/config/wasp-config-generator.ts
2
+ import {
3
+ handleFatalError,
4
+ parseHelperMethodDefinition,
5
+ logger as singletonLogger
6
+ } from "@ingenyus/swarm";
7
+ import path5 from "path";
8
+
9
+ // src/common/filesystem.ts
10
+ import { toPascalCase, validateFeaturePath } from "@ingenyus/swarm";
11
+ import fs from "fs";
12
+ import path from "path";
13
+ var realFileSystem = {
14
+ readFileSync: fs.readFileSync,
15
+ writeFileSync: fs.writeFileSync,
16
+ existsSync: fs.existsSync,
17
+ copyFileSync: fs.copyFileSync,
18
+ mkdirSync: fs.mkdirSync,
19
+ readdirSync: fs.readdirSync,
20
+ statSync: fs.statSync
21
+ };
22
+ function findWaspRoot(fileSystem, startDir = process.cwd()) {
23
+ const startDirPath = path.resolve(startDir);
24
+ let currentDirPath = startDirPath;
25
+ const root = path.parse(currentDirPath).root;
26
+ while (currentDirPath !== root) {
27
+ const waspRootPath = path.join(currentDirPath, ".wasproot");
28
+ if (fileSystem.existsSync(waspRootPath)) {
29
+ return currentDirPath;
30
+ }
31
+ currentDirPath = path.dirname(currentDirPath);
32
+ }
33
+ throw new Error(
34
+ `Couldn't find Wasp application root from ${startDirPath}. Make sure you are running this command from within a Wasp project directory.`
35
+ );
36
+ }
37
+ function normaliseFeaturePath(featurePath) {
38
+ const segments = validateFeaturePath(featurePath);
39
+ const normalisedSegments = [];
40
+ for (let i = 0; i < segments.length; i++) {
41
+ const segment = segments[i];
42
+ const previousSegment = normalisedSegments[normalisedSegments.length - 1];
43
+ if (previousSegment !== "features" && segment !== "features") {
44
+ normalisedSegments.push("features");
45
+ }
46
+ normalisedSegments.push(segment);
47
+ }
48
+ return normalisedSegments.join("/");
49
+ }
50
+ function getFeatureDir(fileSystem, featureName) {
51
+ const waspRoot = findWaspRoot(fileSystem);
52
+ const normalisedPath = normaliseFeaturePath(featureName);
53
+ return path.join(waspRoot, "src", normalisedPath);
54
+ }
55
+
56
+ // src/common/plugin.ts
57
+ import path2 from "path";
58
+ import { fileURLToPath } from "url";
59
+
60
+ // src/common/prisma.ts
61
+ import {
62
+ getSchema
63
+ } from "@mrleebo/prisma-ast";
64
+ import fs2 from "fs";
65
+ import path3 from "path";
66
+
67
+ // src/common/schemas.ts
68
+ import { commandRegistry } from "@ingenyus/swarm";
69
+ import { z } from "zod";
70
+ var commonSchemas = {
71
+ feature: z.string().min(1, "Feature is required").meta({
72
+ description: "The feature directory this component will be generated in"
73
+ }).register(commandRegistry, {
74
+ shortName: "f",
75
+ examples: ["root", "auth", "dashboard/users"],
76
+ helpText: "Can be nested as a logical or relative path, e.g. 'dashboard/users' or 'features/dashboard/features/users'"
77
+ }),
78
+ name: z.string().min(1, "Name is required").meta({ description: "The name of the generated component" }).register(commandRegistry, {
79
+ shortName: "n",
80
+ examples: ["users", "task"],
81
+ helpText: "Will be used for generated files and configuration entries"
82
+ }),
83
+ target: z.string().min(1, "Target directory is required").meta({ description: "The target path of the generated directory" }).register(commandRegistry, {
84
+ shortName: "t",
85
+ examples: ["dashboard/users", "features/dashboard/features/users"],
86
+ helpText: "A logical or relative path, e.g. 'dashboard/users' or 'features/dashboard/features/users'"
87
+ }),
88
+ path: z.string().min(1, "Path is required").meta({ description: "The path that this component will be accessible at" }).register(commandRegistry, {
89
+ shortName: "p",
90
+ examples: ["/api/users/:id", "/api/products"],
91
+ helpText: "Supports Express-style placeholders, e.g. '/api/users/:id'"
92
+ }),
93
+ dataType: z.string().min(1, "Data type is required").meta({ description: "The data type/model name for this operation" }).register(commandRegistry, {
94
+ shortName: "d",
95
+ examples: ["User", "Product", "Task"],
96
+ helpText: "The Wasp entity or model name this operation will interact with"
97
+ }),
98
+ entities: z.array(z.string()).optional().meta({
99
+ description: "The Wasp entities that will be available to this component (optional)"
100
+ }).register(commandRegistry, {
101
+ shortName: "e",
102
+ examples: ["User", "User Task"],
103
+ helpText: "An array of Wasp entity names"
104
+ }),
105
+ force: z.boolean().optional().meta({
106
+ description: "Force overwrite of existing files and configuration entries (optional)"
107
+ }).register(commandRegistry, {
108
+ shortName: "F",
109
+ helpText: "CAUTION: Will overwrite existing files and configuration entries with current parameters"
110
+ }),
111
+ auth: z.boolean().optional().meta({
112
+ description: "Require authentication for this component (optional)"
113
+ }).register(commandRegistry, {
114
+ shortName: "a",
115
+ helpText: "Will generate authentication checks"
116
+ })
117
+ };
118
+
119
+ // src/common/templates.ts
120
+ import { toKebabCase } from "@ingenyus/swarm";
121
+ import { Eta } from "eta";
122
+ import path4 from "path";
123
+ var TemplateUtility = class {
124
+ constructor(fileSystem) {
125
+ this.fileSystem = fileSystem;
126
+ }
127
+ processTemplate(templatePath, replacements) {
128
+ const declarations = Object.keys(replacements).map((key) => `${key}=it.${key}`).join(", ");
129
+ const functionHeader = declarations ? `const ${declarations};` : void 0;
130
+ const templateDir = path4.dirname(templatePath);
131
+ const eta = new Eta({
132
+ autoTrim: false,
133
+ autoEscape: false,
134
+ views: templateDir,
135
+ functionHeader
136
+ });
137
+ const templateName = path4.basename(templatePath).replace(/\.eta$/, "");
138
+ if (this.fileSystem.existsSync(templatePath)) {
139
+ return eta.render(templateName, replacements);
140
+ } else {
141
+ const template = this.fileSystem.readFileSync(templatePath, "utf8");
142
+ return eta.renderString(template, replacements);
143
+ }
144
+ }
145
+ /**
146
+ * Helper method to resolve template paths for concrete generators
147
+ * @param relativePath - The relative path to the template file
148
+ * @param generatorName - The name of the generator (e.g., 'api', 'job')
149
+ * @param currentFileUrl - The import.meta.url from the concrete generator class
150
+ * @returns The full path to the template file
151
+ */
152
+ resolveTemplatePath(relativePath, generatorName, currentFileUrl) {
153
+ const generatorDirName = toKebabCase(generatorName);
154
+ const currentFilePath = new URL(currentFileUrl).pathname;
155
+ const currentFileDir = path4.dirname(currentFilePath);
156
+ const currentFileName = path4.basename(currentFilePath);
157
+ const isInstalledPackage = currentFileDir.includes("node_modules") && currentFileDir.endsWith("/dist") && currentFileName === "index.js";
158
+ const startDir = isInstalledPackage ? currentFileDir : path4.dirname(path4.dirname(currentFileDir));
159
+ return path4.join(
160
+ startDir,
161
+ "generators",
162
+ generatorDirName,
163
+ "templates",
164
+ relativePath
165
+ );
166
+ }
167
+ };
168
+
169
+ // src/generators/config/wasp-config-generator.ts
170
+ var WaspConfigGenerator = class {
171
+ constructor(logger = singletonLogger, fileSystem = realFileSystem) {
172
+ this.logger = logger;
173
+ this.fileSystem = fileSystem;
174
+ this.templateUtility = new TemplateUtility(fileSystem);
175
+ }
176
+ path = path5;
177
+ templateUtility;
178
+ /**
179
+ * Gets the template path for feature config templates.
180
+ * Feature config templates are located in the feature generator's templates directory.
181
+ * @param templateName - The name of the template file (e.g., 'feature.wasp.eta')
182
+ * @returns The full path to the template file
183
+ */
184
+ getTemplatePath(templateName) {
185
+ return this.templateUtility.resolveTemplatePath(
186
+ templateName,
187
+ "feature",
188
+ import.meta.url
189
+ );
190
+ }
191
+ /**
192
+ * Generate a TypeScript Wasp config file in a feature directory
193
+ * @param featurePath - The feature directory path
194
+ */
195
+ generate(featurePath) {
196
+ const featureDir = getFeatureDir(this.fileSystem, featurePath);
197
+ if (!this.fileSystem.existsSync(featureDir)) {
198
+ this.fileSystem.mkdirSync(featureDir, { recursive: true });
199
+ }
200
+ const templatePath = this.getTemplatePath("feature.wasp.eta");
201
+ if (!this.fileSystem.existsSync(templatePath)) {
202
+ this.logger.error(`Template not found: ${templatePath}`);
203
+ return;
204
+ }
205
+ const configFilePath = path5.join(featureDir, `feature.wasp.ts`);
206
+ if (this.fileSystem.existsSync(configFilePath)) {
207
+ this.logger.warn(`Feature config already exists: ${configFilePath}`);
208
+ return;
209
+ }
210
+ this.fileSystem.copyFileSync(templatePath, configFilePath);
211
+ this.logger.success(`Generated feature config: ${configFilePath}`);
212
+ }
213
+ /**
214
+ * Updates or creates a feature configuration file with a pre-built declaration.
215
+ * @param featurePath - The path to the feature
216
+ * @param declaration - The pre-built declaration string to add or update
217
+ * @returns The updated feature configuration file
218
+ */
219
+ update(featurePath, declaration) {
220
+ const configDir = getFeatureDir(this.fileSystem, featurePath);
221
+ const configFilePath = path5.join(configDir, `feature.wasp.ts`);
222
+ if (!this.fileSystem.existsSync(configFilePath)) {
223
+ const templatePath = this.getTemplatePath("feature.wasp.eta");
224
+ if (!this.fileSystem.existsSync(templatePath)) {
225
+ handleFatalError(`Feature config template not found: ${templatePath}`);
226
+ }
227
+ this.fileSystem.copyFileSync(templatePath, configFilePath);
228
+ }
229
+ let content = this.fileSystem.readFileSync(configFilePath, "utf8");
230
+ content = this.normaliseSemicolons(content);
231
+ const parsed = parseHelperMethodDefinition(declaration);
232
+ if (!parsed) {
233
+ handleFatalError(`Could not parse definition: ${declaration}`);
234
+ return content;
235
+ }
236
+ const { methodName } = parsed;
237
+ const hadExistingDefinitions = this.hasExistingDefinitions(
238
+ content,
239
+ methodName
240
+ );
241
+ content = this.removeExistingDefinition(content, declaration);
242
+ const hasExistingDefinitions = this.hasExistingDefinitions(
243
+ content,
244
+ methodName
245
+ );
246
+ const lines = content.split("\n");
247
+ const configureFunctionStart = lines.findIndex(
248
+ (line) => line.trim().startsWith("export default function")
249
+ );
250
+ if (configureFunctionStart === -1) {
251
+ handleFatalError("Could not find configure function in feature config");
252
+ }
253
+ const appLineIndex = lines.findIndex(
254
+ (line, index) => index > configureFunctionStart && line.trim() === "app"
255
+ );
256
+ if (appLineIndex === -1) {
257
+ const insertIndex = configureFunctionStart + 1;
258
+ const itemsToInsert = [" app"];
259
+ const comment = this.getMethodComment(methodName);
260
+ itemsToInsert.push(` ${comment}`);
261
+ itemsToInsert.push(declaration.trimEnd());
262
+ lines.splice(insertIndex, 0, ...itemsToInsert);
263
+ } else {
264
+ const { insertIndex, addComment } = this.findGroupInsertionPoint(
265
+ lines,
266
+ methodName,
267
+ declaration,
268
+ hadExistingDefinitions || hasExistingDefinitions
269
+ );
270
+ const newLines = this.insertWithSpacing(
271
+ lines,
272
+ declaration,
273
+ insertIndex,
274
+ methodName,
275
+ addComment
276
+ );
277
+ const normalisedContent2 = this.normaliseSemicolons(newLines.join("\n"));
278
+ this.fileSystem.writeFileSync(configFilePath, normalisedContent2);
279
+ return configFilePath;
280
+ }
281
+ const normalisedContent = this.normaliseSemicolons(lines.join("\n"));
282
+ this.fileSystem.writeFileSync(configFilePath, normalisedContent);
283
+ return configFilePath;
284
+ }
285
+ /**
286
+ * Determines the insertion index for a method name based on alphabetical ordering
287
+ * of existing groups in the configuration file.
288
+ * @param groups - Object containing existing method groups
289
+ * @param methodName - The method name to find insertion index for
290
+ * @returns The insertion index for the method name
291
+ */
292
+ getInsertionIndexForMethod(groups, methodName) {
293
+ const existingMethods = Object.keys(groups).filter(
294
+ (method) => groups[method].length > 0
295
+ );
296
+ const allMethods = [...existingMethods, methodName].sort();
297
+ return allMethods.indexOf(methodName);
298
+ }
299
+ /**
300
+ * Gets the comment text for a method type.
301
+ * @param methodName The method name (e.g., 'addApi')
302
+ * @returns The comment text for the method type
303
+ */
304
+ getMethodComment(methodName) {
305
+ const entityName = methodName.startsWith("add") ? methodName.slice(3) : methodName;
306
+ return `// ${entityName} definitions`;
307
+ }
308
+ /**
309
+ * Finds the correct insertion point for a new configuration item.
310
+ * @param lines - Array of file lines
311
+ * @param methodName - The method name (e.g., 'addApi')
312
+ * @param definition - The definition string to parse for item name
313
+ * @returns Object with insertion index and whether to add a comment
314
+ */
315
+ findGroupInsertionPoint(lines, methodName, definition, hasExistingDefinitionsOfType) {
316
+ const appLineIndex = lines.findIndex((line) => line.trim() === "app");
317
+ if (appLineIndex === -1) {
318
+ return { insertIndex: appLineIndex + 1, addComment: false };
319
+ }
320
+ const methodCalls = [];
321
+ for (let i = appLineIndex + 1; i < lines.length; i++) {
322
+ const line = lines[i].trim();
323
+ if (line.startsWith(".") && line.includes("(")) {
324
+ let methodCallContent = line;
325
+ let j = i;
326
+ let closingParenCount = 0;
327
+ let foundClosingParen = false;
328
+ for (let k = 0; k < methodCallContent.length; k++) {
329
+ if (methodCallContent[k] === "(") closingParenCount++;
330
+ if (methodCallContent[k] === ")") closingParenCount--;
331
+ if (closingParenCount === 0 && methodCallContent[k] === ")") {
332
+ foundClosingParen = true;
333
+ break;
334
+ }
335
+ }
336
+ while (!foundClosingParen && j < lines.length - 1) {
337
+ j++;
338
+ methodCallContent += " " + lines[j].trim();
339
+ for (let k = 0; k < lines[j].length; k++) {
340
+ if (lines[j][k] === "(") closingParenCount++;
341
+ if (lines[j][k] === ")") closingParenCount--;
342
+ if (closingParenCount === 0 && lines[j][k] === ")") {
343
+ foundClosingParen = true;
344
+ break;
345
+ }
346
+ }
347
+ }
348
+ const match = methodCallContent.match(
349
+ /\.(\w+)\([^,]+,\s*['"`]([^'"`]+)['"`]/
350
+ );
351
+ if (match) {
352
+ methodCalls.push({
353
+ lineIndex: i,
354
+ endLineIndex: j,
355
+ methodName: match[1],
356
+ itemName: match[2]
357
+ });
358
+ }
359
+ }
360
+ }
361
+ const groups = {};
362
+ methodCalls.forEach((call) => {
363
+ if (!groups[call.methodName]) {
364
+ groups[call.methodName] = [];
365
+ }
366
+ groups[call.methodName].push({
367
+ lineIndex: call.lineIndex,
368
+ endLineIndex: call.endLineIndex,
369
+ itemName: call.itemName
370
+ });
371
+ });
372
+ const targetGroup = groups[methodName] || [];
373
+ if (targetGroup.length === 0) {
374
+ const targetGroupIndex = this.getInsertionIndexForMethod(
375
+ groups,
376
+ methodName
377
+ );
378
+ const existingMethods = Object.keys(groups).filter((method) => groups[method].length > 0).sort();
379
+ for (let i = targetGroupIndex; i < existingMethods.length; i++) {
380
+ const groupMethod = existingMethods[i];
381
+ if (groups[groupMethod] && groups[groupMethod].length > 0) {
382
+ const firstItem = groups[groupMethod][0];
383
+ let insertIndex = firstItem.lineIndex;
384
+ for (let j = firstItem.lineIndex - 1; j > appLineIndex; j--) {
385
+ const line = lines[j].trim();
386
+ if (line.startsWith("//") && line.includes("definitions")) {
387
+ insertIndex = j;
388
+ break;
389
+ } else if (line.startsWith(".") || line === "") {
390
+ continue;
391
+ } else {
392
+ break;
393
+ }
394
+ }
395
+ return { insertIndex, addComment: !hasExistingDefinitionsOfType };
396
+ }
397
+ }
398
+ for (let i = targetGroupIndex - 1; i >= 0; i--) {
399
+ const groupMethod = existingMethods[i];
400
+ if (groups[groupMethod] && groups[groupMethod].length > 0) {
401
+ const lastItem2 = groups[groupMethod][groups[groupMethod].length - 1];
402
+ return {
403
+ insertIndex: lastItem2.endLineIndex + 1,
404
+ addComment: !hasExistingDefinitionsOfType
405
+ };
406
+ }
407
+ }
408
+ return {
409
+ insertIndex: appLineIndex + 1,
410
+ addComment: !hasExistingDefinitionsOfType
411
+ };
412
+ }
413
+ const parsed = parseHelperMethodDefinition(definition);
414
+ if (!parsed) {
415
+ return { insertIndex: appLineIndex + 1, addComment: false };
416
+ }
417
+ const { firstParam: itemName } = parsed;
418
+ for (let i = 0; i < targetGroup.length; i++) {
419
+ if (itemName.localeCompare(targetGroup[i].itemName) < 0) {
420
+ return { insertIndex: targetGroup[i].lineIndex, addComment: false };
421
+ }
422
+ }
423
+ const lastItem = targetGroup[targetGroup.length - 1];
424
+ return { insertIndex: lastItem.endLineIndex + 1, addComment: false };
425
+ }
426
+ /**
427
+ * Inserts a definition with optional comment header.
428
+ * @param lines - Array of file lines
429
+ * @param declaration - The declaration to insert
430
+ * @param insertIndex - The index where to insert
431
+ * @param methodName - The method name for comment generation
432
+ * @param addComment - Whether to add a comment before the declaration
433
+ * @returns The modified lines array
434
+ */
435
+ insertWithSpacing(lines, declaration, insertIndex, methodName, addComment = false) {
436
+ const newLines = [...lines];
437
+ if (addComment) {
438
+ const comment = this.getMethodComment(methodName);
439
+ newLines.splice(insertIndex, 0, ` ${comment}`);
440
+ insertIndex += 1;
441
+ }
442
+ newLines.splice(insertIndex, 0, declaration.trimEnd());
443
+ return newLines;
444
+ }
445
+ /**
446
+ * Checks if there are any existing definitions of a specific type in the content.
447
+ * @param content - The file content to search
448
+ * @param methodName - The method name to check for (e.g., 'addJob', 'addApi')
449
+ * @returns true if there are existing definitions of this type, false otherwise
450
+ */
451
+ hasExistingDefinitions(content, methodName) {
452
+ const lines = content.split("\n");
453
+ for (const line of lines) {
454
+ if (line.trim().startsWith(`.${methodName}(`)) {
455
+ return true;
456
+ }
457
+ }
458
+ return false;
459
+ }
460
+ /**
461
+ * Removes an existing definition from the content by finding the helper method call
462
+ * and removing the entire method call block.
463
+ * @param content - The file content
464
+ * @param definition - The new definition to find the existing one from
465
+ * @returns The content with the existing definition removed
466
+ */
467
+ removeExistingDefinition(content, definition) {
468
+ const parsed = parseHelperMethodDefinition(definition);
469
+ if (!parsed) {
470
+ return content;
471
+ }
472
+ const { methodName, firstParam } = parsed;
473
+ let contentLines = content.split("\n");
474
+ let openingLineIndex = -1;
475
+ for (let i = 0; i < contentLines.length; i++) {
476
+ const line = contentLines[i];
477
+ if (line.trim().startsWith(`.${methodName}(`)) {
478
+ if (firstParam && line.includes(firstParam)) {
479
+ openingLineIndex = i;
480
+ break;
481
+ }
482
+ }
483
+ }
484
+ if (openingLineIndex === -1) {
485
+ return content;
486
+ }
487
+ let closingLineIndex = -1;
488
+ let parenCount = 0;
489
+ let braceCount = 0;
490
+ let foundOpening = false;
491
+ for (let i = openingLineIndex; i < contentLines.length; i++) {
492
+ const line = contentLines[i];
493
+ for (const char of line) {
494
+ if (char === "(") {
495
+ parenCount++;
496
+ foundOpening = true;
497
+ } else if (char === ")") {
498
+ parenCount--;
499
+ if (foundOpening && parenCount === 0 && braceCount === 0) {
500
+ closingLineIndex = i;
501
+ break;
502
+ }
503
+ } else if (char === "{") {
504
+ braceCount++;
505
+ } else if (char === "}") {
506
+ braceCount--;
507
+ }
508
+ }
509
+ if (closingLineIndex !== -1) {
510
+ break;
511
+ }
512
+ }
513
+ if (closingLineIndex === -1) {
514
+ this.logger.warn(
515
+ "Could not find closing parenthesis for existing definition"
516
+ );
517
+ return content;
518
+ }
519
+ contentLines.splice(
520
+ openingLineIndex,
521
+ closingLineIndex - openingLineIndex + 1
522
+ );
523
+ return contentLines.join("\n");
524
+ }
525
+ /**
526
+ * Adds a definition to the content by finding the appropriate place to insert it.
527
+ * @param content - The current file content
528
+ * @param definition - The definition to add
529
+ * @returns The updated content with the new definition
530
+ */
531
+ addDefinitionToContent(content, definition) {
532
+ const lines = content.split("\n");
533
+ const lastLineIndex = lines.length - 1;
534
+ let insertIndex = lastLineIndex;
535
+ for (let i = lastLineIndex; i >= 0; i--) {
536
+ const line = lines[i].trim();
537
+ if (line && !line.startsWith("}")) {
538
+ insertIndex = i;
539
+ break;
540
+ }
541
+ }
542
+ lines.splice(insertIndex + 1, 0, ` ${definition}`);
543
+ return lines.join("\n");
544
+ }
545
+ /**
546
+ * Normalises semicolons in the config file by removing them from method chain calls
547
+ * while preserving them in other contexts (imports, declarations, etc.).
548
+ * @param content - The file content to normalise
549
+ * @returns The normalised content
550
+ */
551
+ normaliseSemicolons(content) {
552
+ const lines = content.split("\n");
553
+ const configureFunctionStart = lines.findIndex(
554
+ (line) => line.trim().startsWith("export default function")
555
+ );
556
+ if (configureFunctionStart === -1) {
557
+ return content;
558
+ }
559
+ const appLineIndex = lines.findIndex(
560
+ (line, index) => index > configureFunctionStart && line.trim().startsWith("app")
561
+ );
562
+ if (appLineIndex === -1) {
563
+ return content;
564
+ }
565
+ let braceCount = 0;
566
+ let functionEndIndex = lines.length - 1;
567
+ for (let i = configureFunctionStart; i < lines.length; i++) {
568
+ const line = lines[i];
569
+ for (const char of line) {
570
+ if (char === "{") braceCount++;
571
+ if (char === "}") {
572
+ braceCount--;
573
+ if (braceCount === 0) {
574
+ functionEndIndex = i;
575
+ break;
576
+ }
577
+ }
578
+ }
579
+ if (braceCount === 0 && i > configureFunctionStart) {
580
+ break;
581
+ }
582
+ }
583
+ let lastMethodCallIndex = -1;
584
+ for (let i = appLineIndex + 1; i < functionEndIndex; i++) {
585
+ const line = lines[i];
586
+ const trimmed = line.trim();
587
+ if ((trimmed.endsWith(")") || trimmed.endsWith(");")) && !trimmed.startsWith("//")) {
588
+ lines[i] = line.replace(/;\s*$/, "");
589
+ lastMethodCallIndex = i;
590
+ }
591
+ }
592
+ if (lastMethodCallIndex !== -1 && !lines[lastMethodCallIndex].trim().endsWith(";")) {
593
+ lines[lastMethodCallIndex] = lines[lastMethodCallIndex] + ";";
594
+ }
595
+ return lines.join("\n");
596
+ }
597
+ };
598
+ export {
599
+ WaspConfigGenerator
600
+ };
@@ -1,31 +1,43 @@
1
- import { CrudFlags } from '../../generators/args.types';
1
+ import { Out } from '@ingenyus/swarm';
2
2
  import { CONFIG_TYPES } from '../../types';
3
3
  import { OperationGeneratorBase } from '../base';
4
- export declare class CrudGenerator extends OperationGeneratorBase<typeof CONFIG_TYPES.CRUD> {
5
- protected get entityType(): "Crud";
4
+ import { schema } from './schema';
5
+ export declare class CrudGenerator extends OperationGeneratorBase<typeof schema, typeof CONFIG_TYPES.CRUD> {
6
+ protected get componentType(): "Crud";
6
7
  description: string;
7
8
  schema: import("zod").ZodObject<{
8
- feature: import("zod").ZodString & {
9
- _metadata: import("@ingenyus/swarm").FieldMetadata;
10
- };
11
- name: import("zod").ZodString & {
12
- _metadata: import("@ingenyus/swarm").FieldMetadata;
13
- };
14
- public: import("zod").ZodPipe<import("zod").ZodOptional<import("zod").ZodString>, import("zod").ZodTransform<("create" | "update" | "delete" | "get" | "getAll")[] | undefined, string | undefined>> & {
15
- _metadata: import("@ingenyus/swarm").FieldMetadata;
16
- };
17
- override: import("zod").ZodPipe<import("zod").ZodOptional<import("zod").ZodString>, import("zod").ZodTransform<("create" | "update" | "delete" | "get" | "getAll")[] | undefined, string | undefined>> & {
18
- _metadata: import("@ingenyus/swarm").FieldMetadata;
19
- };
20
- exclude: import("zod").ZodPipe<import("zod").ZodOptional<import("zod").ZodString>, import("zod").ZodTransform<("create" | "update" | "delete" | "get" | "getAll")[] | undefined, string | undefined>> & {
21
- _metadata: import("@ingenyus/swarm").FieldMetadata;
22
- };
23
- force: import("zod").ZodOptional<import("zod").ZodBoolean> & {
24
- _metadata: import("@ingenyus/swarm").FieldMetadata;
25
- };
9
+ feature: import("zod").ZodString;
10
+ name: import("zod").ZodString;
11
+ dataType: import("zod").ZodString;
12
+ public: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodTransform<string, string>>, import("zod").ZodEnum<{
13
+ readonly CREATE: "create";
14
+ readonly GET: "get";
15
+ readonly GETALL: "getAll";
16
+ readonly UPDATE: "update";
17
+ readonly DELETE: "delete";
18
+ }>>>>;
19
+ override: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodTransform<string, string>>, import("zod").ZodEnum<{
20
+ readonly CREATE: "create";
21
+ readonly GET: "get";
22
+ readonly GETALL: "getAll";
23
+ readonly UPDATE: "update";
24
+ readonly DELETE: "delete";
25
+ }>>>>;
26
+ exclude: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodPipe<import("zod").ZodPipe<import("zod").ZodString, import("zod").ZodTransform<string, string>>, import("zod").ZodEnum<{
27
+ readonly CREATE: "create";
28
+ readonly GET: "get";
29
+ readonly GETALL: "getAll";
30
+ readonly UPDATE: "update";
31
+ readonly DELETE: "delete";
32
+ }>>>>;
33
+ force: import("zod").ZodOptional<import("zod").ZodBoolean>;
26
34
  }, import("zod/v4/core").$strip>;
27
- generate(flags: CrudFlags): Promise<void>;
35
+ generate(args: Out<typeof schema>): Promise<void>;
28
36
  private generateCrudFile;
37
+ /**
38
+ * Generates import statements for an operation.
39
+ */
40
+ private generateCrudImports;
29
41
  private updateConfigFile;
30
42
  private buildOperations;
31
43
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"crud-generator.d.ts","sourceRoot":"","sources":["../../../src/generators/crud/crud-generator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAWjD,qBAAa,aAAc,SAAQ,sBAAsB,CACvD,OAAO,YAAY,CAAC,IAAI,CACzB;IACC,SAAS,KAAK,UAAU,WAEvB;IAED,WAAW,SAAoD;IAC/D,MAAM;;;;;;;;;;;;;;;;;;;qCAAU;IAEV,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;YAwCjC,gBAAgB;YAyBhB,gBAAgB;IAoB9B,OAAO,CAAC,eAAe;IA+BvB;;OAEG;YACW,iBAAiB;IA0B/B;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,MAAM;CAoB3E"}
1
+ {"version":3,"file":"crud-generator.d.ts","sourceRoot":"","sources":["../../../src/generators/crud/crud-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,GAAG,EAA6B,MAAM,iBAAiB,CAAC;AAE5E,OAAO,EAAE,YAAY,EAAiC,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAUlC,qBAAa,aAAc,SAAQ,sBAAsB,CACvD,OAAO,MAAM,EACb,OAAO,YAAY,CAAC,IAAI,CACzB;IACC,SAAS,KAAK,aAAa,WAE1B;IAED,WAAW,SAAqC;IAChD,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;qCAAU;IAEV,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAuCzC,gBAAgB;IA8B9B;;OAEG;IACH,OAAO,CAAC,mBAAmB;YAsBb,gBAAgB;IAoB9B,OAAO,CAAC,eAAe;IA+BvB;;OAEG;YACW,iBAAiB;IA4B/B;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,MAAM;CAoB3E"}