@specverse/engines 4.1.5 → 4.1.6

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 (120) hide show
  1. package/dist/libs/instance-factories/applications/templates/generic/backend-env-generator.js +22 -0
  2. package/dist/libs/instance-factories/applications/templates/generic/backend-package-json-generator.js +66 -0
  3. package/dist/libs/instance-factories/applications/templates/generic/backend-tsconfig-generator.js +54 -0
  4. package/dist/libs/instance-factories/applications/templates/generic/main-generator.js +290 -0
  5. package/dist/libs/instance-factories/applications/templates/react/_view-components-source.js +530 -0
  6. package/dist/libs/instance-factories/applications/templates/react/api-client-generator.js +437 -0
  7. package/dist/libs/instance-factories/applications/templates/react/api-types-generator.js +146 -0
  8. package/dist/libs/instance-factories/applications/templates/react/app-tsx-generator.js +73 -0
  9. package/dist/libs/instance-factories/applications/templates/react/env-example-generator.js +18 -0
  10. package/dist/libs/instance-factories/applications/templates/react/field-helpers-generator.js +99 -0
  11. package/dist/libs/instance-factories/applications/templates/react/gitignore-generator.js +35 -0
  12. package/dist/libs/instance-factories/applications/templates/react/index-css-generator.js +9 -0
  13. package/dist/libs/instance-factories/applications/templates/react/index-html-generator.js +23 -0
  14. package/dist/libs/instance-factories/applications/templates/react/main-tsx-generator.js +29 -0
  15. package/dist/libs/instance-factories/applications/templates/react/package-json-generator.js +49 -0
  16. package/dist/libs/instance-factories/applications/templates/react/pattern-adapter-generator.js +156 -0
  17. package/dist/libs/instance-factories/applications/templates/react/react-pattern-adapter.js +935 -0
  18. package/dist/libs/instance-factories/applications/templates/react/relationship-field-generator.js +143 -0
  19. package/dist/libs/instance-factories/applications/templates/react/runtime-app-tsx-generator.js +101 -0
  20. package/dist/libs/instance-factories/applications/templates/react/runtime-package-json-generator.js +50 -0
  21. package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.js +646 -0
  22. package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.js +65 -0
  23. package/dist/libs/instance-factories/applications/templates/react/tsconfig-generator.js +28 -0
  24. package/dist/libs/instance-factories/applications/templates/react/use-api-hooks-generator.js +132 -0
  25. package/dist/libs/instance-factories/applications/templates/react/view-dashboard-generator.js +143 -0
  26. package/dist/libs/instance-factories/applications/templates/react/view-detail-generator.js +143 -0
  27. package/dist/libs/instance-factories/applications/templates/react/view-form-generator.js +355 -0
  28. package/dist/libs/instance-factories/applications/templates/react/view-list-generator.js +91 -0
  29. package/dist/libs/instance-factories/applications/templates/react/view-router-generator.js +79 -0
  30. package/dist/libs/instance-factories/applications/templates/react/vite-config-generator.js +42 -0
  31. package/dist/libs/instance-factories/cli/templates/commander/cli-bin-wrapper-generator.js +11 -0
  32. package/dist/libs/instance-factories/cli/templates/commander/cli-entry-generator.js +111 -0
  33. package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +928 -0
  34. package/dist/libs/instance-factories/communication/templates/eventemitter/bus-generator.js +83 -0
  35. package/dist/libs/instance-factories/communication/templates/eventemitter/publisher-generator.js +91 -0
  36. package/dist/libs/instance-factories/communication/templates/eventemitter/subscriber-generator.js +86 -0
  37. package/dist/libs/instance-factories/controllers/templates/fastify/meta-routes-generator.js +93 -0
  38. package/dist/libs/instance-factories/controllers/templates/fastify/routes-generator.js +280 -0
  39. package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +125 -0
  40. package/dist/libs/instance-factories/infrastructure/templates/docker-k8s/infrastructure-generator.js +25 -0
  41. package/dist/libs/instance-factories/orms/templates/prisma/schema-generator.js +371 -0
  42. package/dist/libs/instance-factories/orms/templates/prisma/services-generator.js +266 -0
  43. package/dist/libs/instance-factories/scaffolding/templates/generic/env-example-generator.js +51 -0
  44. package/dist/libs/instance-factories/scaffolding/templates/generic/env-generator.js +61 -0
  45. package/dist/libs/instance-factories/scaffolding/templates/generic/gitignore-generator.js +59 -0
  46. package/dist/libs/instance-factories/scaffolding/templates/generic/package-json-generator.js +126 -0
  47. package/dist/libs/instance-factories/scaffolding/templates/generic/readme-generator.js +159 -0
  48. package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-generator.js +56 -0
  49. package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-react-generator.js +37 -0
  50. package/dist/libs/instance-factories/sdks/templates/python/sdk-generator.js +29 -0
  51. package/dist/libs/instance-factories/sdks/templates/typescript/sdk-generator.js +28 -0
  52. package/dist/libs/instance-factories/services/templates/memory/generate-interpreter.js +14 -0
  53. package/dist/libs/instance-factories/services/templates/memory/step-conventions-memory.js +415 -0
  54. package/dist/libs/instance-factories/services/templates/prisma/behavior-generator.js +177 -0
  55. package/dist/libs/instance-factories/services/templates/prisma/controller-generator.js +413 -0
  56. package/dist/libs/instance-factories/services/templates/prisma/service-generator.js +243 -0
  57. package/dist/libs/instance-factories/services/templates/prisma/step-conventions.js +264 -0
  58. package/dist/libs/instance-factories/services/templates/shared-patterns.js +24 -0
  59. package/dist/libs/instance-factories/shared/path-resolver.js +59 -0
  60. package/dist/libs/instance-factories/storage/templates/mongodb/config-generator.js +13 -0
  61. package/dist/libs/instance-factories/storage/templates/mongodb/docker-generator.js +16 -0
  62. package/dist/libs/instance-factories/storage/templates/postgresql/config-generator.js +45 -0
  63. package/dist/libs/instance-factories/storage/templates/postgresql/docker-generator.js +46 -0
  64. package/dist/libs/instance-factories/storage/templates/redis/config-generator.js +14 -0
  65. package/dist/libs/instance-factories/storage/templates/redis/docker-generator.js +16 -0
  66. package/dist/libs/instance-factories/test-generation.js +145 -0
  67. package/dist/libs/instance-factories/testing/templates/vitest/tests-generator.js +30 -0
  68. package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +149 -0
  69. package/dist/libs/instance-factories/tools/templates/mcp/static/src/controllers/MCPServerController.js +232 -0
  70. package/dist/libs/instance-factories/tools/templates/mcp/static/src/events/EventEmitter.js +49 -0
  71. package/dist/libs/instance-factories/tools/templates/mcp/static/src/index.js +18 -0
  72. package/dist/libs/instance-factories/tools/templates/mcp/static/src/interfaces/ResourceProvider.js +0 -0
  73. package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/LibrarySuggestion.js +97 -0
  74. package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/SpecVerseResource.js +64 -0
  75. package/dist/libs/instance-factories/tools/templates/mcp/static/src/server/mcp-server.js +182 -0
  76. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/CLIProxyService.js +1210 -0
  77. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EmbeddedResourcesAdapter.js +172 -0
  78. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EntityModuleService.js +240 -0
  79. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/HybridResourcesProvider.js +147 -0
  80. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.js +281 -0
  81. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.js +409 -0
  82. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorToolsService.js +414 -0
  83. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.js +467 -0
  84. package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/ResourcesProviderService.js +135 -0
  85. package/dist/libs/instance-factories/tools/templates/mcp/static/src/types/index.js +0 -0
  86. package/dist/libs/instance-factories/tools/templates/vscode/static/extension.js +965 -0
  87. package/dist/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.js +238 -0
  88. package/dist/libs/instance-factories/validation/templates/zod/validation-generator.js +25 -0
  89. package/dist/libs/instance-factories/views/index.js +48 -0
  90. package/dist/libs/instance-factories/views/templates/react/adapters/antd-adapter.js +742 -0
  91. package/dist/libs/instance-factories/views/templates/react/adapters/mui-adapter.js +824 -0
  92. package/dist/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.js +719 -0
  93. package/dist/libs/instance-factories/views/templates/react/app-generator.js +45 -0
  94. package/dist/libs/instance-factories/views/templates/react/components-generator.js +779 -0
  95. package/dist/libs/instance-factories/views/templates/react/forms-generator.js +285 -0
  96. package/dist/libs/instance-factories/views/templates/react/frontend-package-json-generator.js +46 -0
  97. package/dist/libs/instance-factories/views/templates/react/hooks-generator.js +111 -0
  98. package/dist/libs/instance-factories/views/templates/react/index-css-generator.js +9 -0
  99. package/dist/libs/instance-factories/views/templates/react/index-html-generator.js +23 -0
  100. package/dist/libs/instance-factories/views/templates/react/main-tsx-generator.js +21 -0
  101. package/dist/libs/instance-factories/views/templates/react/react-component-generator.js +299 -0
  102. package/dist/libs/instance-factories/views/templates/react/router-generator.js +136 -0
  103. package/dist/libs/instance-factories/views/templates/react/router-generic-generator.js +107 -0
  104. package/dist/libs/instance-factories/views/templates/react/shared-utils-generator.js +179 -0
  105. package/dist/libs/instance-factories/views/templates/react/spec-json-generator.js +7 -0
  106. package/dist/libs/instance-factories/views/templates/react/types-generator.js +56 -0
  107. package/dist/libs/instance-factories/views/templates/react/views-metadata-generator.js +27 -0
  108. package/dist/libs/instance-factories/views/templates/react/vite-config-generator.js +29 -0
  109. package/dist/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js +261 -0
  110. package/dist/libs/instance-factories/views/templates/shared/adapter-types.js +34 -0
  111. package/dist/libs/instance-factories/views/templates/shared/atomic-components-registry.js +800 -0
  112. package/dist/libs/instance-factories/views/templates/shared/base-generator.js +305 -0
  113. package/dist/libs/instance-factories/views/templates/shared/component-metadata.js +517 -0
  114. package/dist/libs/instance-factories/views/templates/shared/composite-pattern-types.js +0 -0
  115. package/dist/libs/instance-factories/views/templates/shared/composite-patterns.js +445 -0
  116. package/dist/libs/instance-factories/views/templates/shared/index.js +80 -0
  117. package/dist/libs/instance-factories/views/templates/shared/pattern-validator.js +210 -0
  118. package/dist/libs/instance-factories/views/templates/shared/property-mapper.js +492 -0
  119. package/dist/libs/instance-factories/views/templates/shared/syntax-mapper.js +321 -0
  120. package/package.json +3 -2
@@ -0,0 +1,305 @@
1
+ import { mapProperties } from "./property-mapper.js";
2
+ import { getSyntaxPattern } from "./syntax-mapper.js";
3
+ import { ATOMIC_COMPONENTS_REGISTRY } from "./atomic-components-registry.js";
4
+ class BaseComponentGenerator {
5
+ // Configuration
6
+ config;
7
+ adapter;
8
+ // Architectural constraints
9
+ MAX_DEPTH;
10
+ ENABLE_WARNINGS;
11
+ // Tracking
12
+ warnings = [];
13
+ imports = /* @__PURE__ */ new Set();
14
+ constructor(adapter, config) {
15
+ this.adapter = adapter;
16
+ this.config = config;
17
+ this.MAX_DEPTH = config.maxDepth ?? 3;
18
+ this.ENABLE_WARNINGS = config.enableWarnings ?? true;
19
+ }
20
+ // ============================================================================
21
+ // Public API
22
+ // ============================================================================
23
+ /**
24
+ * Generate code for a complete view specification
25
+ *
26
+ * @param viewSpec - View specification from SpecVerse
27
+ * @returns Generation result with code, imports, and warnings
28
+ */
29
+ generate(viewSpec) {
30
+ this.reset();
31
+ const importStatements = this.generateImports(viewSpec);
32
+ const stateCode = viewSpec.state ? this.generateState(viewSpec.state) : "";
33
+ const eventsCode = viewSpec.events ? this.generateEvents(viewSpec.events) : "";
34
+ const componentsCode = this.generateComponentTree(viewSpec.components);
35
+ const code = this.generateComponent({
36
+ name: viewSpec.name,
37
+ imports: importStatements,
38
+ state: stateCode,
39
+ events: eventsCode,
40
+ components: componentsCode
41
+ });
42
+ return {
43
+ code,
44
+ imports: Array.from(this.imports),
45
+ warnings: this.warnings
46
+ };
47
+ }
48
+ // ============================================================================
49
+ // Shared Component Rendering (Framework-Agnostic)
50
+ // ============================================================================
51
+ /**
52
+ * Render all components in the view
53
+ */
54
+ generateComponentTree(components) {
55
+ const rendered = Object.entries(components).map(([name, component]) => {
56
+ return this.renderComponent(component, {
57
+ depth: 0,
58
+ path: [name],
59
+ dataContext: void 0
60
+ });
61
+ });
62
+ return rendered.join("\n\n");
63
+ }
64
+ /**
65
+ * Render a single component with depth tracking and nesting enforcement
66
+ *
67
+ * This is the core shared logic - applies to ALL frameworks
68
+ */
69
+ renderComponent(component, context) {
70
+ if (context.depth > this.MAX_DEPTH) {
71
+ this.addWarning(
72
+ `Component at path ${context.path.join(".")} exceeds max depth (${this.MAX_DEPTH}). Flattening to maintain readability.`
73
+ );
74
+ return this.renderFlattened(component, context);
75
+ }
76
+ const componentDef = ATOMIC_COMPONENTS_REGISTRY[component.type];
77
+ if (!componentDef) {
78
+ this.addWarning(`Unknown component type: ${component.type}`);
79
+ return `<!-- Unknown component: ${component.type} -->`;
80
+ }
81
+ const mappedProps = this.mapComponentProperties(component, componentDef);
82
+ if (component.condition) {
83
+ return this.renderConditional(component, mappedProps, context);
84
+ }
85
+ if (component.dataSource) {
86
+ return this.renderList(component, mappedProps, context);
87
+ }
88
+ const children = component.children ? this.renderChildren(component.children, context) : void 0;
89
+ return this.renderAdapterComponent(
90
+ component.type,
91
+ mappedProps,
92
+ children,
93
+ context
94
+ );
95
+ }
96
+ /**
97
+ * Map component properties using property-mapper
98
+ */
99
+ mapComponentProperties(component, componentDef) {
100
+ if (!component.properties) {
101
+ return {};
102
+ }
103
+ return mapProperties(
104
+ component.type,
105
+ component.properties,
106
+ this.config.target
107
+ );
108
+ }
109
+ /**
110
+ * Render child components with incremented depth
111
+ */
112
+ renderChildren(children, parentContext) {
113
+ const childContext = {
114
+ ...parentContext,
115
+ depth: parentContext.depth + 1
116
+ };
117
+ return children.map((child, index) => {
118
+ const childPath = [...parentContext.path, `child_${index}`];
119
+ return this.renderComponent(child, {
120
+ ...childContext,
121
+ path: childPath
122
+ });
123
+ }).join("\n");
124
+ }
125
+ /**
126
+ * Render conditional component using syntax-mapper
127
+ */
128
+ renderConditional(component, mappedProps, context) {
129
+ const innerComponent = this.renderAdapterComponent(
130
+ component.type,
131
+ mappedProps,
132
+ component.children ? this.renderChildren(component.children, context) : void 0,
133
+ context
134
+ );
135
+ return getSyntaxPattern("conditionalRender", this.config.framework, {
136
+ condition: component.condition,
137
+ Component: this.getComponentName(component.type),
138
+ props: this.formatProps(mappedProps)
139
+ });
140
+ }
141
+ /**
142
+ * Render list (loop) component using syntax-mapper
143
+ */
144
+ renderList(component, mappedProps, context) {
145
+ const itemName = this.getItemName(component.dataSource);
146
+ const keyProperty = this.getKeyProperty(component);
147
+ const childContext = {
148
+ ...context,
149
+ depth: context.depth + 1,
150
+ dataContext: itemName
151
+ };
152
+ return getSyntaxPattern("loopRender", this.config.framework, {
153
+ array: component.dataSource,
154
+ item: itemName,
155
+ key: keyProperty,
156
+ Component: this.getComponentName(component.type)
157
+ });
158
+ }
159
+ /**
160
+ * Flatten component when depth exceeded
161
+ *
162
+ * Extracts nested children into sibling components to reduce nesting
163
+ */
164
+ renderFlattened(component, context) {
165
+ const componentDef = ATOMIC_COMPONENTS_REGISTRY[component.type];
166
+ const mappedProps = this.mapComponentProperties(component, componentDef);
167
+ const flatComponent = this.renderAdapterComponent(
168
+ component.type,
169
+ mappedProps,
170
+ void 0,
171
+ // No children
172
+ context
173
+ );
174
+ const flattenedChildren = component.children ? component.children.map((child, index) => {
175
+ return this.renderComponent(child, {
176
+ depth: context.depth,
177
+ // Same depth (sibling)
178
+ path: [...context.path, `flattened_${index}`]
179
+ });
180
+ }).join("\n") : "";
181
+ return flatComponent + "\n" + flattenedChildren;
182
+ }
183
+ /**
184
+ * Delegate to adapter for actual component rendering
185
+ */
186
+ renderAdapterComponent(type, properties, children, context) {
187
+ const adapterComponent = this.adapter.components[type];
188
+ if (!adapterComponent) {
189
+ this.addWarning(`Adapter missing component: ${type}`);
190
+ return `<!-- Missing adapter for: ${type} -->`;
191
+ }
192
+ return adapterComponent.render({
193
+ properties,
194
+ children
195
+ });
196
+ }
197
+ // ============================================================================
198
+ // Helper Methods
199
+ // ============================================================================
200
+ /**
201
+ * Get component name for import/usage
202
+ */
203
+ getComponentName(type) {
204
+ const componentDef = ATOMIC_COMPONENTS_REGISTRY[type];
205
+ return componentDef?.name || type.charAt(0).toUpperCase() + type.slice(1);
206
+ }
207
+ /**
208
+ * Get item variable name for loop rendering
209
+ */
210
+ getItemName(dataSource) {
211
+ if (dataSource.endsWith("s")) {
212
+ return dataSource.slice(0, -1);
213
+ }
214
+ return dataSource + "Item";
215
+ }
216
+ /**
217
+ * Get key property for list items
218
+ */
219
+ getKeyProperty(component) {
220
+ return component.properties?.keyProperty || "id";
221
+ }
222
+ /**
223
+ * Format properties for inline rendering
224
+ */
225
+ formatProps(properties) {
226
+ return Object.entries(properties).map(([key, value]) => {
227
+ if (typeof value === "string") {
228
+ return `${key}="${value}"`;
229
+ }
230
+ return `${key}={${JSON.stringify(value)}}`;
231
+ }).join(" ");
232
+ }
233
+ /**
234
+ * Add warning message
235
+ */
236
+ addWarning(message) {
237
+ if (this.ENABLE_WARNINGS) {
238
+ this.warnings.push(message);
239
+ }
240
+ }
241
+ /**
242
+ * Reset generator state for new generation
243
+ */
244
+ reset() {
245
+ this.warnings = [];
246
+ this.imports = /* @__PURE__ */ new Set();
247
+ }
248
+ /**
249
+ * Add import statement
250
+ */
251
+ addImport(importStatement) {
252
+ this.imports.add(importStatement);
253
+ }
254
+ }
255
+ function validateNestingDepth(component, maxDepth = 3) {
256
+ const issues = [];
257
+ function calculateDepth(comp, currentDepth) {
258
+ if (!comp.children || comp.children.length === 0) {
259
+ return currentDepth;
260
+ }
261
+ const childDepths = comp.children.map(
262
+ (child) => calculateDepth(child, currentDepth + 1)
263
+ );
264
+ return Math.max(...childDepths);
265
+ }
266
+ const actualDepth = calculateDepth(component, 0);
267
+ if (actualDepth > maxDepth) {
268
+ issues.push(
269
+ `Component nesting depth (${actualDepth}) exceeds maximum (${maxDepth})`
270
+ );
271
+ }
272
+ return {
273
+ valid: actualDepth <= maxDepth,
274
+ actualDepth,
275
+ issues
276
+ };
277
+ }
278
+ function extractComponentTypes(components) {
279
+ const types = /* @__PURE__ */ new Set();
280
+ function walk(component) {
281
+ types.add(component.type);
282
+ if (component.children) {
283
+ component.children.forEach(walk);
284
+ }
285
+ }
286
+ Object.values(components).forEach(walk);
287
+ return types;
288
+ }
289
+ function countComponents(components) {
290
+ let count = 0;
291
+ function walk(component) {
292
+ count++;
293
+ if (component.children) {
294
+ component.children.forEach(walk);
295
+ }
296
+ }
297
+ Object.values(components).forEach(walk);
298
+ return count;
299
+ }
300
+ export {
301
+ BaseComponentGenerator,
302
+ countComponents,
303
+ extractComponentTypes,
304
+ validateNestingDepth
305
+ };