@specverse/engines 4.1.5 → 4.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/libs/instance-factories/applications/templates/generic/backend-env-generator.js +22 -0
- package/dist/libs/instance-factories/applications/templates/generic/backend-package-json-generator.js +66 -0
- package/dist/libs/instance-factories/applications/templates/generic/backend-tsconfig-generator.js +54 -0
- package/dist/libs/instance-factories/applications/templates/generic/main-generator.js +290 -0
- package/dist/libs/instance-factories/applications/templates/react/_view-components-source.js +530 -0
- package/dist/libs/instance-factories/applications/templates/react/api-client-generator.js +437 -0
- package/dist/libs/instance-factories/applications/templates/react/api-types-generator.js +146 -0
- package/dist/libs/instance-factories/applications/templates/react/app-tsx-generator.js +73 -0
- package/dist/libs/instance-factories/applications/templates/react/env-example-generator.js +18 -0
- package/dist/libs/instance-factories/applications/templates/react/field-helpers-generator.js +99 -0
- package/dist/libs/instance-factories/applications/templates/react/gitignore-generator.js +35 -0
- package/dist/libs/instance-factories/applications/templates/react/index-css-generator.js +9 -0
- package/dist/libs/instance-factories/applications/templates/react/index-html-generator.js +23 -0
- package/dist/libs/instance-factories/applications/templates/react/main-tsx-generator.js +29 -0
- package/dist/libs/instance-factories/applications/templates/react/package-json-generator.js +49 -0
- package/dist/libs/instance-factories/applications/templates/react/pattern-adapter-generator.js +156 -0
- package/dist/libs/instance-factories/applications/templates/react/react-pattern-adapter.js +935 -0
- package/dist/libs/instance-factories/applications/templates/react/relationship-field-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/runtime-app-tsx-generator.js +101 -0
- package/dist/libs/instance-factories/applications/templates/react/runtime-package-json-generator.js +50 -0
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-generator.js +646 -0
- package/dist/libs/instance-factories/applications/templates/react/tailwind-adapter-wrapper-generator.js +65 -0
- package/dist/libs/instance-factories/applications/templates/react/tsconfig-generator.js +28 -0
- package/dist/libs/instance-factories/applications/templates/react/use-api-hooks-generator.js +132 -0
- package/dist/libs/instance-factories/applications/templates/react/view-dashboard-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/view-detail-generator.js +143 -0
- package/dist/libs/instance-factories/applications/templates/react/view-form-generator.js +355 -0
- package/dist/libs/instance-factories/applications/templates/react/view-list-generator.js +91 -0
- package/dist/libs/instance-factories/applications/templates/react/view-router-generator.js +79 -0
- package/dist/libs/instance-factories/applications/templates/react/vite-config-generator.js +42 -0
- package/dist/libs/instance-factories/cli/templates/commander/cli-bin-wrapper-generator.js +11 -0
- package/dist/libs/instance-factories/cli/templates/commander/cli-entry-generator.js +111 -0
- package/dist/libs/instance-factories/cli/templates/commander/command-generator.js +928 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/bus-generator.js +83 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/publisher-generator.js +91 -0
- package/dist/libs/instance-factories/communication/templates/eventemitter/subscriber-generator.js +86 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/meta-routes-generator.js +93 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/routes-generator.js +280 -0
- package/dist/libs/instance-factories/controllers/templates/fastify/server-generator.js +125 -0
- package/dist/libs/instance-factories/infrastructure/templates/docker-k8s/infrastructure-generator.js +25 -0
- package/dist/libs/instance-factories/orms/templates/prisma/schema-generator.js +371 -0
- package/dist/libs/instance-factories/orms/templates/prisma/services-generator.js +266 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/env-example-generator.js +51 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/env-generator.js +61 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/gitignore-generator.js +59 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/package-json-generator.js +126 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/readme-generator.js +159 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-generator.js +56 -0
- package/dist/libs/instance-factories/scaffolding/templates/generic/tsconfig-react-generator.js +37 -0
- package/dist/libs/instance-factories/sdks/templates/python/sdk-generator.js +29 -0
- package/dist/libs/instance-factories/sdks/templates/typescript/sdk-generator.js +28 -0
- package/dist/libs/instance-factories/services/templates/memory/generate-interpreter.js +14 -0
- package/dist/libs/instance-factories/services/templates/memory/step-conventions-memory.js +415 -0
- package/dist/libs/instance-factories/services/templates/prisma/behavior-generator.js +177 -0
- package/dist/libs/instance-factories/services/templates/prisma/controller-generator.js +413 -0
- package/dist/libs/instance-factories/services/templates/prisma/service-generator.js +243 -0
- package/dist/libs/instance-factories/services/templates/prisma/step-conventions.js +264 -0
- package/dist/libs/instance-factories/services/templates/shared-patterns.js +24 -0
- package/dist/libs/instance-factories/shared/path-resolver.js +59 -0
- package/dist/libs/instance-factories/storage/templates/mongodb/config-generator.js +13 -0
- package/dist/libs/instance-factories/storage/templates/mongodb/docker-generator.js +16 -0
- package/dist/libs/instance-factories/storage/templates/postgresql/config-generator.js +45 -0
- package/dist/libs/instance-factories/storage/templates/postgresql/docker-generator.js +46 -0
- package/dist/libs/instance-factories/storage/templates/redis/config-generator.js +14 -0
- package/dist/libs/instance-factories/storage/templates/redis/docker-generator.js +16 -0
- package/dist/libs/instance-factories/test-generation.js +145 -0
- package/dist/libs/instance-factories/testing/templates/vitest/tests-generator.js +30 -0
- package/dist/libs/instance-factories/tools/templates/mcp/mcp-server-generator.js +149 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/controllers/MCPServerController.js +232 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/events/EventEmitter.js +49 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/index.js +18 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/interfaces/ResourceProvider.js +0 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/LibrarySuggestion.js +97 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/models/SpecVerseResource.js +64 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/server/mcp-server.js +182 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/CLIProxyService.js +1210 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EmbeddedResourcesAdapter.js +172 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/EntityModuleService.js +240 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/HybridResourcesProvider.js +147 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/LibraryToolsService.js +281 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorBridge.js +409 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/OrchestratorToolsService.js +414 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/PromptToolsService.js +467 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/services/ResourcesProviderService.js +135 -0
- package/dist/libs/instance-factories/tools/templates/mcp/static/src/types/index.js +0 -0
- package/dist/libs/instance-factories/tools/templates/vscode/static/extension.js +965 -0
- package/dist/libs/instance-factories/tools/templates/vscode/vscode-extension-generator.js +238 -0
- package/dist/libs/instance-factories/validation/templates/zod/validation-generator.js +25 -0
- package/dist/libs/instance-factories/views/index.js +48 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/antd-adapter.js +742 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/mui-adapter.js +824 -0
- package/dist/libs/instance-factories/views/templates/react/adapters/shadcn-adapter.js +719 -0
- package/dist/libs/instance-factories/views/templates/react/app-generator.js +45 -0
- package/dist/libs/instance-factories/views/templates/react/components-generator.js +779 -0
- package/dist/libs/instance-factories/views/templates/react/forms-generator.js +285 -0
- package/dist/libs/instance-factories/views/templates/react/frontend-package-json-generator.js +46 -0
- package/dist/libs/instance-factories/views/templates/react/hooks-generator.js +111 -0
- package/dist/libs/instance-factories/views/templates/react/index-css-generator.js +9 -0
- package/dist/libs/instance-factories/views/templates/react/index-html-generator.js +23 -0
- package/dist/libs/instance-factories/views/templates/react/main-tsx-generator.js +21 -0
- package/dist/libs/instance-factories/views/templates/react/react-component-generator.js +299 -0
- package/dist/libs/instance-factories/views/templates/react/router-generator.js +136 -0
- package/dist/libs/instance-factories/views/templates/react/router-generic-generator.js +107 -0
- package/dist/libs/instance-factories/views/templates/react/shared-utils-generator.js +179 -0
- package/dist/libs/instance-factories/views/templates/react/spec-json-generator.js +7 -0
- package/dist/libs/instance-factories/views/templates/react/types-generator.js +56 -0
- package/dist/libs/instance-factories/views/templates/react/views-metadata-generator.js +27 -0
- package/dist/libs/instance-factories/views/templates/react/vite-config-generator.js +29 -0
- package/dist/libs/instance-factories/views/templates/runtime/runtime-view-renderer.js +261 -0
- package/dist/libs/instance-factories/views/templates/shared/adapter-types.js +34 -0
- package/dist/libs/instance-factories/views/templates/shared/atomic-components-registry.js +800 -0
- package/dist/libs/instance-factories/views/templates/shared/base-generator.js +305 -0
- package/dist/libs/instance-factories/views/templates/shared/component-metadata.js +517 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-pattern-types.js +0 -0
- package/dist/libs/instance-factories/views/templates/shared/composite-patterns.js +445 -0
- package/dist/libs/instance-factories/views/templates/shared/index.js +80 -0
- package/dist/libs/instance-factories/views/templates/shared/pattern-validator.js +210 -0
- package/dist/libs/instance-factories/views/templates/shared/property-mapper.js +492 -0
- package/dist/libs/instance-factories/views/templates/shared/syntax-mapper.js +321 -0
- package/dist/realize/index.js +36 -12
- package/dist/realize/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
async function generate(context) {
|
|
2
|
+
return `/**
|
|
3
|
+
* StandardFormView - Controller-Based Form View Component
|
|
4
|
+
*
|
|
5
|
+
* LOCAL VERSION - Uses local hooks with instance-factory-specific API client
|
|
6
|
+
*
|
|
7
|
+
* Supports both Create and Edit modes with:
|
|
8
|
+
* - Controller-driven form generation
|
|
9
|
+
* - Smart input types (text, number, boolean, relationship selectors)
|
|
10
|
+
* - Auto-generated field detection
|
|
11
|
+
* - Validation and error handling
|
|
12
|
+
* - Lifecycle management (Edit/Evolve tabs)
|
|
13
|
+
* - Foreign key relationship fields
|
|
14
|
+
* - Two-panel layout (form + entity list)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { useState, useEffect } from 'react';
|
|
18
|
+
import { useEntitiesQuery, useModelSchemaQuery, useExecuteOperationMutation, useTransitionStateMutation } from '../../hooks/useApi';
|
|
19
|
+
import { isAutoGeneratedField, isFieldRequired, initializeFormData } from '../../utils/field-helpers';
|
|
20
|
+
import { RelationshipField } from '../../components/fields/RelationshipField';
|
|
21
|
+
import type { View, Entity } from '../../types/api';
|
|
22
|
+
|
|
23
|
+
type FormMode = 'create' | 'update';
|
|
24
|
+
type ActiveTab = 'edit' | 'evolve';
|
|
25
|
+
|
|
26
|
+
interface StandardFormViewProps {
|
|
27
|
+
view: View;
|
|
28
|
+
spec?: any; // Full spec for controller access
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function FormView({ view, spec }: StandardFormViewProps) {
|
|
32
|
+
// Determine controller and model
|
|
33
|
+
let controllerName: string;
|
|
34
|
+
let modelName: string;
|
|
35
|
+
|
|
36
|
+
if (view.controller && spec) {
|
|
37
|
+
// New: Controller-based
|
|
38
|
+
controllerName = view.controller;
|
|
39
|
+
const controller = spec.controllers[view.controller];
|
|
40
|
+
modelName = controller.model;
|
|
41
|
+
} else {
|
|
42
|
+
// Legacy: Model-based
|
|
43
|
+
modelName = view.model as string;
|
|
44
|
+
controllerName = \`\${modelName}Controller\`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const [selectedEntity, setSelectedEntity] = useState<Entity | null>(null);
|
|
48
|
+
const [formMode, setFormMode] = useState<FormMode>('create');
|
|
49
|
+
const [activeTab, setActiveTab] = useState<ActiveTab>('edit');
|
|
50
|
+
const [formData, setFormData] = useState<Record<string, any>>({});
|
|
51
|
+
const [errors, setErrors] = useState<Record<string, string>>({});
|
|
52
|
+
const [selectedLifecycleStates, setSelectedLifecycleStates] = useState<Record<string, string>>({});
|
|
53
|
+
|
|
54
|
+
// Fetch entities and schema - USES LOCAL HOOKS
|
|
55
|
+
const { data: entities = [], isLoading: entitiesLoading } = useEntitiesQuery(controllerName, modelName);
|
|
56
|
+
const { data: schema } = useModelSchemaQuery(modelName);
|
|
57
|
+
const { mutate: executeOperation, isPending } = useExecuteOperationMutation();
|
|
58
|
+
const { mutate: transitionState, isPending: isTransitioning } = useTransitionStateMutation();
|
|
59
|
+
|
|
60
|
+
const attributes = schema?.attributes || {};
|
|
61
|
+
const relationships = schema?.relationships || {};
|
|
62
|
+
const lifecycles = schema?.lifecycles || {};
|
|
63
|
+
|
|
64
|
+
// Sync selected entity with updated entities list
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (selectedEntity && entities.length > 0) {
|
|
67
|
+
const updatedEntity = entities.find((e) => e.id === selectedEntity.id);
|
|
68
|
+
if (updatedEntity) {
|
|
69
|
+
const oldStates = JSON.stringify(selectedEntity.metadata?.lifecycleStates || {});
|
|
70
|
+
const newStates = JSON.stringify(updatedEntity.metadata?.lifecycleStates || {});
|
|
71
|
+
|
|
72
|
+
if (oldStates !== newStates) {
|
|
73
|
+
setSelectedEntity(updatedEntity);
|
|
74
|
+
setSelectedLifecycleStates({ ...(updatedEntity.metadata?.lifecycleStates || {}) });
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, [entities, selectedEntity?.id]);
|
|
79
|
+
|
|
80
|
+
// Initialize form data when schema changes or when switching modes
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
if (selectedEntity && formMode === 'update') {
|
|
83
|
+
setFormData({ ...selectedEntity.data });
|
|
84
|
+
const currentStates = selectedEntity.metadata?.lifecycleStates || {};
|
|
85
|
+
setSelectedLifecycleStates({ ...currentStates });
|
|
86
|
+
} else if (schema?.attributes) {
|
|
87
|
+
setFormData(initializeFormData(schema.attributes, { includeAutoGenerated: false }));
|
|
88
|
+
setSelectedLifecycleStates({});
|
|
89
|
+
}
|
|
90
|
+
}, [selectedEntity, formMode, schema]);
|
|
91
|
+
|
|
92
|
+
// Check if field should be shown
|
|
93
|
+
const shouldShowField = (attrName: string, attrDef: any): boolean => {
|
|
94
|
+
const isAuto = isAutoGeneratedField(attrName, attrDef);
|
|
95
|
+
// In create mode, hide auto-generated fields
|
|
96
|
+
if (formMode === 'create' && isAuto) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
// In update mode, show all fields
|
|
100
|
+
return true;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// Handle form submission
|
|
104
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
setErrors({});
|
|
107
|
+
|
|
108
|
+
const operation = formMode === 'create' ? 'create' : 'update';
|
|
109
|
+
const params = formMode === 'update' && selectedEntity
|
|
110
|
+
? { ...formData, id: selectedEntity.id }
|
|
111
|
+
: formData;
|
|
112
|
+
|
|
113
|
+
executeOperation(
|
|
114
|
+
{ controllerName, operationName: operation, params },
|
|
115
|
+
{
|
|
116
|
+
onSuccess: () => {
|
|
117
|
+
if (formMode === 'create' && schema?.attributes) {
|
|
118
|
+
setFormData(initializeFormData(schema.attributes, { includeAutoGenerated: false }));
|
|
119
|
+
}
|
|
120
|
+
setFormMode('create');
|
|
121
|
+
setSelectedEntity(null);
|
|
122
|
+
},
|
|
123
|
+
onError: (error: any) => {
|
|
124
|
+
setErrors({ _form: error.message || 'Operation failed' });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Handle entity selection for editing
|
|
131
|
+
const handleEntitySelect = (entity: Entity) => {
|
|
132
|
+
setSelectedEntity(entity);
|
|
133
|
+
setFormMode('update');
|
|
134
|
+
setActiveTab('edit');
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
// Handle lifecycle state transition
|
|
138
|
+
const handleLifecycleTransition = (lifecycleName: string, toState: string) => {
|
|
139
|
+
if (!selectedEntity) return;
|
|
140
|
+
|
|
141
|
+
transitionState(
|
|
142
|
+
{ modelName, entityId: selectedEntity.id, toState, lifecycleName },
|
|
143
|
+
{
|
|
144
|
+
onSuccess: () => {
|
|
145
|
+
setSelectedLifecycleStates((prev) => ({ ...prev, [lifecycleName]: toState }));
|
|
146
|
+
},
|
|
147
|
+
onError: (error: any) => {
|
|
148
|
+
setErrors({ _lifecycle: error.message || 'Transition failed' });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// Render field input
|
|
155
|
+
const renderFieldInput = (attrName: string, attrDef: any) => {
|
|
156
|
+
const value = formData[attrName] ?? '';
|
|
157
|
+
const isRequired = isFieldRequired(attrDef);
|
|
158
|
+
|
|
159
|
+
const handleChange = (newValue: any) => {
|
|
160
|
+
setFormData((prev) => ({ ...prev, [attrName]: newValue }));
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
// Boolean field
|
|
164
|
+
if (attrDef.type === 'Boolean') {
|
|
165
|
+
return (
|
|
166
|
+
<input
|
|
167
|
+
type="checkbox"
|
|
168
|
+
checked={!!value}
|
|
169
|
+
onChange={(e) => handleChange(e.target.checked)}
|
|
170
|
+
className="h-4 w-4 rounded border-gray-300"
|
|
171
|
+
/>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Number field
|
|
176
|
+
if (attrDef.type === 'Integer' || attrDef.type === 'Float' || attrDef.type === 'Decimal') {
|
|
177
|
+
return (
|
|
178
|
+
<input
|
|
179
|
+
type="number"
|
|
180
|
+
value={value}
|
|
181
|
+
onChange={(e) => handleChange(e.target.value ? Number(e.target.value) : '')}
|
|
182
|
+
required={isRequired}
|
|
183
|
+
className="block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
|
|
184
|
+
/>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Text field (default)
|
|
189
|
+
return (
|
|
190
|
+
<input
|
|
191
|
+
type="text"
|
|
192
|
+
value={value}
|
|
193
|
+
onChange={(e) => handleChange(e.target.value)}
|
|
194
|
+
required={isRequired}
|
|
195
|
+
className="block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500"
|
|
196
|
+
/>
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<div className="flex gap-4 h-full">
|
|
202
|
+
{/* Form Panel */}
|
|
203
|
+
<div className="flex-1 bg-white dark:bg-gray-800 rounded-lg shadow p-6">
|
|
204
|
+
<h2 className="text-2xl font-bold mb-4 text-gray-800 dark:text-white">
|
|
205
|
+
{formMode === 'create' ? \`Create \${modelName}\` : \`Edit \${modelName}\`}
|
|
206
|
+
</h2>
|
|
207
|
+
|
|
208
|
+
{/* Tabs for Edit/Evolve modes */}
|
|
209
|
+
{formMode === 'update' && Object.keys(lifecycles).length > 0 && (
|
|
210
|
+
<div className="flex gap-2 mb-4 border-b border-gray-200">
|
|
211
|
+
<button
|
|
212
|
+
onClick={() => setActiveTab('edit')}
|
|
213
|
+
className={\`px-4 py-2 font-medium \${activeTab === 'edit' ? 'border-b-2 border-blue-500 text-blue-600' : 'text-gray-500'}\`}
|
|
214
|
+
>
|
|
215
|
+
Edit Data
|
|
216
|
+
</button>
|
|
217
|
+
<button
|
|
218
|
+
onClick={() => setActiveTab('evolve')}
|
|
219
|
+
className={\`px-4 py-2 font-medium \${activeTab === 'evolve' ? 'border-b-2 border-blue-500 text-blue-600' : 'text-gray-500'}\`}
|
|
220
|
+
>
|
|
221
|
+
Lifecycle
|
|
222
|
+
</button>
|
|
223
|
+
</div>
|
|
224
|
+
)}
|
|
225
|
+
|
|
226
|
+
{activeTab === 'edit' ? (
|
|
227
|
+
<form onSubmit={handleSubmit} className="space-y-4">
|
|
228
|
+
{errors._form && (
|
|
229
|
+
<div className="p-3 bg-red-100 text-red-700 rounded-md">{errors._form}</div>
|
|
230
|
+
)}
|
|
231
|
+
|
|
232
|
+
{/* Attributes */}
|
|
233
|
+
{Object.entries(attributes).map(([attrName, attrDef]: [string, any]) => {
|
|
234
|
+
if (!shouldShowField(attrName, attrDef)) return null;
|
|
235
|
+
|
|
236
|
+
return (
|
|
237
|
+
<div key={attrName}>
|
|
238
|
+
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
|
239
|
+
{attrName}
|
|
240
|
+
{isFieldRequired(attrDef) && <span className="text-red-500">*</span>}
|
|
241
|
+
</label>
|
|
242
|
+
{renderFieldInput(attrName, attrDef)}
|
|
243
|
+
</div>
|
|
244
|
+
);
|
|
245
|
+
})}
|
|
246
|
+
|
|
247
|
+
{/* Relationships */}
|
|
248
|
+
{Object.entries(relationships).map(([relName, relDef]: [string, any]) => (
|
|
249
|
+
<RelationshipField
|
|
250
|
+
key={relName}
|
|
251
|
+
name={relName}
|
|
252
|
+
relationship={relDef}
|
|
253
|
+
value={formData[relName]}
|
|
254
|
+
onChange={(value) => setFormData((prev) => ({ ...prev, [relName]: value }))}
|
|
255
|
+
/>
|
|
256
|
+
))}
|
|
257
|
+
|
|
258
|
+
<div className="flex gap-2 pt-4">
|
|
259
|
+
<button
|
|
260
|
+
type="submit"
|
|
261
|
+
disabled={isPending}
|
|
262
|
+
className="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50"
|
|
263
|
+
>
|
|
264
|
+
{isPending ? 'Saving...' : formMode === 'create' ? 'Create' : 'Update'}
|
|
265
|
+
</button>
|
|
266
|
+
{formMode === 'update' && (
|
|
267
|
+
<button
|
|
268
|
+
type="button"
|
|
269
|
+
onClick={() => {
|
|
270
|
+
setFormMode('create');
|
|
271
|
+
setSelectedEntity(null);
|
|
272
|
+
if (schema?.attributes) {
|
|
273
|
+
setFormData(initializeFormData(schema.attributes, { includeAutoGenerated: false }));
|
|
274
|
+
}
|
|
275
|
+
}}
|
|
276
|
+
className="px-4 py-2 bg-gray-500 text-white rounded-md hover:bg-gray-600"
|
|
277
|
+
>
|
|
278
|
+
Cancel
|
|
279
|
+
</button>
|
|
280
|
+
)}
|
|
281
|
+
</div>
|
|
282
|
+
</form>
|
|
283
|
+
) : (
|
|
284
|
+
/* Lifecycle Tab */
|
|
285
|
+
<div className="space-y-4">
|
|
286
|
+
{errors._lifecycle && (
|
|
287
|
+
<div className="p-3 bg-red-100 text-red-700 rounded-md">{errors._lifecycle}</div>
|
|
288
|
+
)}
|
|
289
|
+
|
|
290
|
+
{Object.entries(lifecycles).map(([lifecycleName, lifecycle]: [string, any]) => {
|
|
291
|
+
const currentState = selectedLifecycleStates[lifecycleName] || lifecycle.initial;
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<div key={lifecycleName} className="border border-gray-200 rounded-lg p-4">
|
|
295
|
+
<h3 className="font-semibold text-lg mb-2">{lifecycleName}</h3>
|
|
296
|
+
<p className="text-sm text-gray-600 mb-3">Current: {currentState}</p>
|
|
297
|
+
|
|
298
|
+
<div className="flex flex-wrap gap-2">
|
|
299
|
+
{Object.keys(lifecycle.states || {}).map((state) => (
|
|
300
|
+
<button
|
|
301
|
+
key={state}
|
|
302
|
+
onClick={() => handleLifecycleTransition(lifecycleName, state)}
|
|
303
|
+
disabled={isTransitioning || state === currentState}
|
|
304
|
+
className={\`px-3 py-1 rounded-md \${state === currentState ? 'bg-blue-600 text-white' : 'bg-gray-200 text-gray-700 hover:bg-gray-300'} disabled:opacity-50\`}
|
|
305
|
+
>
|
|
306
|
+
{state}
|
|
307
|
+
</button>
|
|
308
|
+
))}
|
|
309
|
+
</div>
|
|
310
|
+
</div>
|
|
311
|
+
);
|
|
312
|
+
})}
|
|
313
|
+
</div>
|
|
314
|
+
)}
|
|
315
|
+
</div>
|
|
316
|
+
|
|
317
|
+
{/* Entity List Panel */}
|
|
318
|
+
<div className="w-80 bg-white dark:bg-gray-800 rounded-lg shadow p-4">
|
|
319
|
+
<h3 className="text-lg font-semibold mb-3 text-gray-800 dark:text-white">
|
|
320
|
+
{modelName} List
|
|
321
|
+
</h3>
|
|
322
|
+
|
|
323
|
+
{entitiesLoading ? (
|
|
324
|
+
<p className="text-gray-500">Loading...</p>
|
|
325
|
+
) : entities.length === 0 ? (
|
|
326
|
+
<p className="text-gray-500 italic">No entities yet</p>
|
|
327
|
+
) : (
|
|
328
|
+
<div className="space-y-2">
|
|
329
|
+
{entities.map((entity) => (
|
|
330
|
+
<div
|
|
331
|
+
key={entity.id}
|
|
332
|
+
onClick={() => handleEntitySelect(entity)}
|
|
333
|
+
className={\`p-3 rounded-md cursor-pointer \${selectedEntity?.id === entity.id ? 'bg-blue-100 border-blue-500' : 'bg-gray-50 hover:bg-gray-100'} border\`}
|
|
334
|
+
>
|
|
335
|
+
<p className="font-medium text-sm">{entity.id}</p>
|
|
336
|
+
{Object.entries(entity.data).slice(0, 2).map(([key, value]) => (
|
|
337
|
+
<p key={key} className="text-xs text-gray-600">
|
|
338
|
+
{key}: {String(value)}
|
|
339
|
+
</p>
|
|
340
|
+
))}
|
|
341
|
+
</div>
|
|
342
|
+
))}
|
|
343
|
+
</div>
|
|
344
|
+
)}
|
|
345
|
+
</div>
|
|
346
|
+
</div>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export default FormView;
|
|
351
|
+
`;
|
|
352
|
+
}
|
|
353
|
+
export {
|
|
354
|
+
generate
|
|
355
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
async function generate(context) {
|
|
2
|
+
return `/**
|
|
3
|
+
* ListView - Pattern-Based List View Component
|
|
4
|
+
*
|
|
5
|
+
* Uses pattern-based rendering with ReactPatternAdapter.
|
|
6
|
+
* Reads from modelSchemas for schema-driven field generation.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useMemo } from 'react';
|
|
10
|
+
import { useEntitiesQuery, useModelSchemaQuery } from '../../hooks/useApi';
|
|
11
|
+
import { usePatternAdapter, REACT_PROTOCOL_MAPPING } from '../../lib/react-pattern-adapter';
|
|
12
|
+
import type { View } from '../../types/api';
|
|
13
|
+
|
|
14
|
+
interface ListViewProps {
|
|
15
|
+
view: View;
|
|
16
|
+
spec?: any;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function ListView({ view, spec }: ListViewProps) {
|
|
20
|
+
const patternAdapter = usePatternAdapter();
|
|
21
|
+
|
|
22
|
+
// Determine controller and model
|
|
23
|
+
let controllerName: string;
|
|
24
|
+
let modelName: string;
|
|
25
|
+
|
|
26
|
+
if (view.controller && spec) {
|
|
27
|
+
controllerName = view.controller;
|
|
28
|
+
const controller = spec.controllers[view.controller];
|
|
29
|
+
modelName = controller.model;
|
|
30
|
+
} else {
|
|
31
|
+
modelName = view.model as string;
|
|
32
|
+
controllerName = \`\${modelName}Controller\`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Fetch data and schema
|
|
36
|
+
const { data: entities = [], isLoading } = useEntitiesQuery(controllerName, modelName);
|
|
37
|
+
const { data: schema } = useModelSchemaQuery(modelName);
|
|
38
|
+
|
|
39
|
+
// Build model data and schemas
|
|
40
|
+
const modelData = useMemo(() => ({
|
|
41
|
+
[modelName]: entities
|
|
42
|
+
}), [modelName, entities]);
|
|
43
|
+
|
|
44
|
+
const modelSchemas = useMemo(() =>
|
|
45
|
+
schema ? { [modelName]: schema } : {}
|
|
46
|
+
, [modelName, schema]);
|
|
47
|
+
|
|
48
|
+
if (isLoading) {
|
|
49
|
+
return <div className="p-4">Loading...</div>;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Detect pattern
|
|
53
|
+
const pattern = patternAdapter.detectPattern({ ...view, type: 'list' });
|
|
54
|
+
|
|
55
|
+
if (!pattern) {
|
|
56
|
+
return (
|
|
57
|
+
<div className="p-4 text-red-600">
|
|
58
|
+
Pattern not found for list view
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Build render context
|
|
64
|
+
const context = {
|
|
65
|
+
pattern,
|
|
66
|
+
viewSpec: { ...view, type: 'list', model: modelName },
|
|
67
|
+
modelData,
|
|
68
|
+
modelSchemas,
|
|
69
|
+
primaryModel: modelName,
|
|
70
|
+
selectedEntity: null,
|
|
71
|
+
primaryEntities: entities,
|
|
72
|
+
protocolMapping: REACT_PROTOCOL_MAPPING,
|
|
73
|
+
tailwindAdapter: patternAdapter['tailwindAdapter']
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Render pattern
|
|
77
|
+
const html = patternAdapter.renderPattern(context);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div className="runtime-view-container p-4 h-full overflow-auto">
|
|
81
|
+
<div dangerouslySetInnerHTML={{ __html: html }} />
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default ListView;
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
generate
|
|
91
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
async function generate(context) {
|
|
2
|
+
return `/**
|
|
3
|
+
* ViewRouter - Hybrid View Router
|
|
4
|
+
*
|
|
5
|
+
* Pattern-Based Rendering Architecture:
|
|
6
|
+
* - Forms (interactive) \u2192 FormView (controller-based with React hooks)
|
|
7
|
+
* - Display views \u2192 Pattern-based rendering (list, detail, dashboard)
|
|
8
|
+
*
|
|
9
|
+
* Benefits:
|
|
10
|
+
* - Forms get React hooks, state management, UUID handling
|
|
11
|
+
* - Display views get schema-driven pattern rendering
|
|
12
|
+
* - Both approaches coexist seamlessly
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { View } from '../../types/api';
|
|
16
|
+
import { FormView } from './FormView';
|
|
17
|
+
import { ListView } from './ListView';
|
|
18
|
+
import { DetailView } from './DetailView';
|
|
19
|
+
import { DashboardView } from './DashboardView';
|
|
20
|
+
|
|
21
|
+
interface ViewRouterProps {
|
|
22
|
+
view: View;
|
|
23
|
+
spec?: any; // Full spec for controller access
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ViewRouter({ view, spec }: ViewRouterProps) {
|
|
27
|
+
const viewType = view.type?.toLowerCase();
|
|
28
|
+
|
|
29
|
+
// Determine rendering strategy
|
|
30
|
+
const useFormRenderer = (type: string): boolean => {
|
|
31
|
+
// Forms require React hooks and state - use FormView (controller-based)
|
|
32
|
+
const interactiveTypes = ['form', 'create', 'edit', 'create-form', 'edit-form'];
|
|
33
|
+
return interactiveTypes.includes(type);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Route to appropriate renderer
|
|
37
|
+
if (useFormRenderer(viewType)) {
|
|
38
|
+
// Controller-based form with React hooks
|
|
39
|
+
return <FormView view={view} spec={spec} />;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Pattern-based rendering for display views
|
|
43
|
+
switch (viewType) {
|
|
44
|
+
case 'list':
|
|
45
|
+
case 'table':
|
|
46
|
+
return <ListView view={view} spec={spec} />;
|
|
47
|
+
|
|
48
|
+
case 'detail':
|
|
49
|
+
case 'master-detail':
|
|
50
|
+
return <DetailView view={view} spec={spec} />;
|
|
51
|
+
|
|
52
|
+
case 'dashboard':
|
|
53
|
+
return <DashboardView view={view} spec={spec} />;
|
|
54
|
+
|
|
55
|
+
default:
|
|
56
|
+
return (
|
|
57
|
+
<div className="flex items-center justify-center h-full p-8">
|
|
58
|
+
<div className="text-center">
|
|
59
|
+
<h3 className="text-lg font-semibold text-gray-800 dark:text-gray-100 mb-2">
|
|
60
|
+
Unknown View Type: {view.type}
|
|
61
|
+
</h3>
|
|
62
|
+
<p className="text-gray-500 dark:text-gray-400">
|
|
63
|
+
View "{view.name}" has an unsupported type.
|
|
64
|
+
</p>
|
|
65
|
+
<p className="text-sm text-gray-400 dark:text-gray-500 mt-2">
|
|
66
|
+
Supported types: list, detail, dashboard, form
|
|
67
|
+
</p>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default ViewRouter;
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
export {
|
|
78
|
+
generate
|
|
79
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { getApiBaseUrl, getPathConfig } from "../../../shared/path-resolver.js";
|
|
2
|
+
function generateViteConfig(context) {
|
|
3
|
+
const { configuration } = context;
|
|
4
|
+
const pathConfig = getPathConfig(context);
|
|
5
|
+
const vitePort = configuration?.vite?.port || 5173;
|
|
6
|
+
const viteHost = configuration?.vite?.host || "localhost";
|
|
7
|
+
const apiBaseUrl = getApiBaseUrl(pathConfig);
|
|
8
|
+
const apiProxy = configuration?.vite?.proxy?.["/api"] || apiBaseUrl;
|
|
9
|
+
return `import { defineConfig } from 'vite';
|
|
10
|
+
import react from '@vitejs/plugin-react';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
|
|
13
|
+
// https://vitejs.dev/config/
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
plugins: [react()],
|
|
16
|
+
server: {
|
|
17
|
+
port: ${vitePort},
|
|
18
|
+
host: '${viteHost}',
|
|
19
|
+
proxy: {
|
|
20
|
+
'/api': {
|
|
21
|
+
target: '${apiProxy}',
|
|
22
|
+
changeOrigin: true,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
build: {
|
|
27
|
+
outDir: 'dist',
|
|
28
|
+
sourcemap: true,
|
|
29
|
+
},
|
|
30
|
+
resolve: {
|
|
31
|
+
alias: {
|
|
32
|
+
'@': path.resolve(__dirname, './src'),
|
|
33
|
+
},
|
|
34
|
+
// Prevent React duplication when using local packages
|
|
35
|
+
dedupe: ['react', 'react-dom'],
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
export {
|
|
41
|
+
generateViteConfig as default
|
|
42
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function generateCLIBinWrapper(context) {
|
|
2
|
+
return `#!/usr/bin/env node
|
|
3
|
+
import { register } from 'tsx/esm/api';
|
|
4
|
+
const unregister = register();
|
|
5
|
+
await import('../src/cli/index.ts');
|
|
6
|
+
unregister();
|
|
7
|
+
`;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
generateCLIBinWrapper as default
|
|
11
|
+
};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
function generateCLIEntry(context) {
|
|
2
|
+
const { spec } = context;
|
|
3
|
+
const commands = context.commands ? Array.isArray(context.commands) ? context.commands : Object.entries(context.commands).map(([name, def]) => ({ name, ...def })) : extractCommands(spec);
|
|
4
|
+
if (commands.length === 0) {
|
|
5
|
+
return generateMinimalCLI(spec);
|
|
6
|
+
}
|
|
7
|
+
const rootCommand = commands[0];
|
|
8
|
+
const subcommands = rootCommand.subcommands ? Object.entries(rootCommand.subcommands) : [];
|
|
9
|
+
const imports = subcommands.map(
|
|
10
|
+
([name, _]) => `import { register${capitalize(name)}Command } from './commands/${name}.js';`
|
|
11
|
+
).join("\n");
|
|
12
|
+
const registrations = subcommands.map(
|
|
13
|
+
([name, _]) => ` register${capitalize(name)}Command(program);`
|
|
14
|
+
).join("\n");
|
|
15
|
+
const version = spec.version || spec.metadata?.version || context.componentVersion || (Array.isArray(spec.components) ? spec.components[0]?.version : Object.values(spec.components || {})[0]?.version) || "1.0.0";
|
|
16
|
+
return `#!/usr/bin/env node
|
|
17
|
+
/**
|
|
18
|
+
* ${rootCommand.description || "CLI Application"}
|
|
19
|
+
* Generated from SpecVerse specification
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { Command } from 'commander';
|
|
23
|
+
import { readFileSync } from 'fs';
|
|
24
|
+
import { fileURLToPath } from 'url';
|
|
25
|
+
import { dirname, join } from 'path';
|
|
26
|
+
${imports}
|
|
27
|
+
|
|
28
|
+
// Read version from package.json at runtime (not hardcoded)
|
|
29
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
30
|
+
const __dirname = dirname(__filename);
|
|
31
|
+
let _version = '${version}';
|
|
32
|
+
try {
|
|
33
|
+
// Walk up to find package.json
|
|
34
|
+
for (const rel of ['../../../package.json', '../../../../package.json', '../../../../../package.json']) {
|
|
35
|
+
try {
|
|
36
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, rel), 'utf8'));
|
|
37
|
+
if (pkg.version) { _version = pkg.version; break; }
|
|
38
|
+
} catch { /* try next */ }
|
|
39
|
+
}
|
|
40
|
+
} catch { /* use fallback */ }
|
|
41
|
+
|
|
42
|
+
const program = new Command();
|
|
43
|
+
|
|
44
|
+
program
|
|
45
|
+
.name('${rootCommand.name}')
|
|
46
|
+
.description('${rootCommand.description || ""}')
|
|
47
|
+
.version(_version);
|
|
48
|
+
|
|
49
|
+
// Register all commands
|
|
50
|
+
${registrations}
|
|
51
|
+
|
|
52
|
+
// Parse and execute
|
|
53
|
+
program.parseAsync(process.argv).catch((error) => {
|
|
54
|
+
console.error('Error:', error.message);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
});
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
function extractCommands(spec) {
|
|
60
|
+
if (spec.commands) {
|
|
61
|
+
if (Array.isArray(spec.commands)) return spec.commands;
|
|
62
|
+
return Object.entries(spec.commands).map(([name, def]) => ({
|
|
63
|
+
name,
|
|
64
|
+
...def
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
const components = spec.components || [];
|
|
68
|
+
const componentList = Array.isArray(components) ? components : Object.entries(components).map(([name, c]) => ({ name, ...c }));
|
|
69
|
+
for (const comp of componentList) {
|
|
70
|
+
if (comp.commands) {
|
|
71
|
+
if (Array.isArray(comp.commands)) return comp.commands;
|
|
72
|
+
return Object.entries(comp.commands).map(([name, def]) => ({
|
|
73
|
+
name,
|
|
74
|
+
...def
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
function generateMinimalCLI(spec) {
|
|
81
|
+
return `#!/usr/bin/env node
|
|
82
|
+
/**
|
|
83
|
+
* CLI Application
|
|
84
|
+
* Generated from SpecVerse specification
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
import { Command } from 'commander';
|
|
88
|
+
|
|
89
|
+
const program = new Command();
|
|
90
|
+
|
|
91
|
+
program
|
|
92
|
+
.name('app')
|
|
93
|
+
.description('Generated CLI application')
|
|
94
|
+
.version('1.0.0');
|
|
95
|
+
|
|
96
|
+
program
|
|
97
|
+
.command('status')
|
|
98
|
+
.description('Show application status')
|
|
99
|
+
.action(() => {
|
|
100
|
+
console.log('Application is running');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
program.parseAsync(process.argv);
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
function capitalize(str) {
|
|
107
|
+
return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
generateCLIEntry as default
|
|
111
|
+
};
|