@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.
- 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/package.json +3 -2
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
function generateSharedUtils(context) {
|
|
2
|
+
const files = [
|
|
3
|
+
{ path: "field-helpers.ts", content: generateFieldHelpers() },
|
|
4
|
+
{ path: "view-helpers.tsx", content: generateViewHelpers() }
|
|
5
|
+
];
|
|
6
|
+
return { files };
|
|
7
|
+
}
|
|
8
|
+
function generateFieldHelpers() {
|
|
9
|
+
return `/**
|
|
10
|
+
* Field Helpers \u2014 shared utilities for field classification and display
|
|
11
|
+
* Generated by SpecVerse React factory
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const METADATA_FIELDS = new Set([
|
|
15
|
+
'id', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy', 'deletedAt', 'version'
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
const AUTO_PATTERNS = new Set(['now', 'uuid4', 'autoincrement', 'auto']);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Check if a field is auto-generated (should be hidden from forms)
|
|
22
|
+
*/
|
|
23
|
+
export function isAutoField(name: string, attr: any): boolean {
|
|
24
|
+
if (attr?.auto && AUTO_PATTERNS.has(attr.auto)) return true;
|
|
25
|
+
if (name === 'id') return true;
|
|
26
|
+
if (METADATA_FIELDS.has(name) && attr?.type?.toLowerCase().includes('date')) return true;
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Check if a field is metadata (shown last, styled muted)
|
|
32
|
+
*/
|
|
33
|
+
export function isMetadataField(name: string): boolean {
|
|
34
|
+
return METADATA_FIELDS.has(name);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the best display name for an entity
|
|
39
|
+
* Searches common name fields in priority order
|
|
40
|
+
*/
|
|
41
|
+
export function getEntityDisplayName(entity: any): string {
|
|
42
|
+
if (!entity) return 'Unknown';
|
|
43
|
+
for (const field of ['name', 'title', 'displayName', 'label', 'username', 'email', 'subject']) {
|
|
44
|
+
if (entity[field]) return String(entity[field]);
|
|
45
|
+
}
|
|
46
|
+
return entity.id ? String(entity.id).slice(0, 8) + '...' : 'Unknown';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Classify attributes into ordered groups for display
|
|
51
|
+
*/
|
|
52
|
+
export function classifyFields(attributes: Array<{ name: string; type: string; auto?: string; required?: boolean }>): {
|
|
53
|
+
business: typeof attributes;
|
|
54
|
+
lifecycle: typeof attributes;
|
|
55
|
+
metadata: typeof attributes;
|
|
56
|
+
} {
|
|
57
|
+
const business: typeof attributes = [];
|
|
58
|
+
const lifecycle: typeof attributes = [];
|
|
59
|
+
const metadata: typeof attributes = [];
|
|
60
|
+
|
|
61
|
+
for (const attr of attributes) {
|
|
62
|
+
if (isAutoField(attr.name, attr) || isMetadataField(attr.name)) {
|
|
63
|
+
metadata.push(attr);
|
|
64
|
+
} else if (attr.name === 'status' || attr.name === 'state' || attr.name === 'phase') {
|
|
65
|
+
lifecycle.push(attr);
|
|
66
|
+
} else {
|
|
67
|
+
business.push(attr);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return { business, lifecycle, metadata };
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
}
|
|
75
|
+
function generateViewHelpers() {
|
|
76
|
+
return `/**
|
|
77
|
+
* View Helpers \u2014 formatting, colors, and UI utilities
|
|
78
|
+
* Generated by SpecVerse React factory
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Format a value for display
|
|
83
|
+
*/
|
|
84
|
+
export function formatValue(value: any, type?: string): string {
|
|
85
|
+
if (value === null || value === undefined) return '\u2014';
|
|
86
|
+
if (type?.toLowerCase().includes('date') || type?.toLowerCase().includes('timestamp')) {
|
|
87
|
+
return formatDate(value);
|
|
88
|
+
}
|
|
89
|
+
if (typeof value === 'boolean') return value ? 'Yes' : 'No';
|
|
90
|
+
return String(value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Format a date for display (relative for recent, absolute for old)
|
|
95
|
+
*/
|
|
96
|
+
export function formatDate(value: any): string {
|
|
97
|
+
if (!value) return '\u2014';
|
|
98
|
+
const date = new Date(value);
|
|
99
|
+
if (isNaN(date.getTime())) return String(value);
|
|
100
|
+
|
|
101
|
+
const now = new Date();
|
|
102
|
+
const diff = now.getTime() - date.getTime();
|
|
103
|
+
const minutes = Math.floor(diff / 60000);
|
|
104
|
+
const hours = Math.floor(diff / 3600000);
|
|
105
|
+
const days = Math.floor(diff / 86400000);
|
|
106
|
+
|
|
107
|
+
if (minutes < 1) return 'just now';
|
|
108
|
+
if (minutes < 60) return \`\${minutes}m ago\`;
|
|
109
|
+
if (hours < 24) return \`\${hours}h ago\`;
|
|
110
|
+
if (days < 7) return \`\${days}d ago\`;
|
|
111
|
+
return date.toLocaleDateString();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Truncate text with ellipsis
|
|
116
|
+
*/
|
|
117
|
+
export function truncate(text: string, max: number = 60): string {
|
|
118
|
+
if (!text || text.length <= max) return text;
|
|
119
|
+
return text.slice(0, max) + '...';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Get a Tailwind color class for a lifecycle status
|
|
124
|
+
*/
|
|
125
|
+
export function statusColor(status: string): { bg: string; text: string; dot: string } {
|
|
126
|
+
const s = status?.toLowerCase().replace(/[_-]/g, '') || '';
|
|
127
|
+
|
|
128
|
+
// Green states
|
|
129
|
+
if (['active', 'done', 'completed', 'approved', 'published', 'resolved'].includes(s)) {
|
|
130
|
+
return { bg: 'bg-green-50', text: 'text-green-700', dot: 'bg-green-500' };
|
|
131
|
+
}
|
|
132
|
+
// Blue states
|
|
133
|
+
if (['inprogress', 'processing', 'review', 'pending'].includes(s)) {
|
|
134
|
+
return { bg: 'bg-blue-50', text: 'text-blue-700', dot: 'bg-blue-500' };
|
|
135
|
+
}
|
|
136
|
+
// Yellow states
|
|
137
|
+
if (['draft', 'todo', 'planning', 'waiting', 'scheduled'].includes(s)) {
|
|
138
|
+
return { bg: 'bg-yellow-50', text: 'text-yellow-700', dot: 'bg-yellow-500' };
|
|
139
|
+
}
|
|
140
|
+
// Red states
|
|
141
|
+
if (['cancelled', 'rejected', 'failed', 'overdue', 'blocked'].includes(s)) {
|
|
142
|
+
return { bg: 'bg-red-50', text: 'text-red-700', dot: 'bg-red-500' };
|
|
143
|
+
}
|
|
144
|
+
// Gray states
|
|
145
|
+
if (['archived', 'closed', 'deprecated', 'inactive', 'disabled'].includes(s)) {
|
|
146
|
+
return { bg: 'bg-gray-50', text: 'text-gray-500', dot: 'bg-gray-400' };
|
|
147
|
+
}
|
|
148
|
+
// Default: indigo
|
|
149
|
+
return { bg: 'bg-indigo-50', text: 'text-indigo-700', dot: 'bg-indigo-500' };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* StatusBadge component \u2014 matches app-demo's lifecycle badge styling
|
|
154
|
+
*/
|
|
155
|
+
export function StatusBadge({ status, variant = 'default' }: { status: string; variant?: 'default' | 'lifecycle' }) {
|
|
156
|
+
if (!status) return null;
|
|
157
|
+
|
|
158
|
+
// Lifecycle badges use purple (matching app-demo)
|
|
159
|
+
if (variant === 'lifecycle') {
|
|
160
|
+
return (
|
|
161
|
+
<span className="px-2 py-1 bg-purple-100 text-purple-700 rounded text-xs font-medium">
|
|
162
|
+
{status.replace(/[_-]/g, ' ')}
|
|
163
|
+
</span>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const colors = statusColor(status);
|
|
168
|
+
return (
|
|
169
|
+
<span className={\`inline-flex items-center gap-1.5 px-2 py-1 rounded text-xs font-medium \${colors.bg} \${colors.text}\`}>
|
|
170
|
+
<span className={\`w-1.5 h-1.5 rounded-full \${colors.dot}\`}></span>
|
|
171
|
+
{status.replace(/[_-]/g, ' ')}
|
|
172
|
+
</span>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
}
|
|
177
|
+
export {
|
|
178
|
+
generateSharedUtils as default
|
|
179
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function generateModelTypes(context) {
|
|
2
|
+
const { model } = context;
|
|
3
|
+
if (!model) {
|
|
4
|
+
throw new Error("Model is required in template context");
|
|
5
|
+
}
|
|
6
|
+
const modelName = model.name;
|
|
7
|
+
let attributes = model.attributes || {};
|
|
8
|
+
if (Array.isArray(attributes)) {
|
|
9
|
+
const obj = {};
|
|
10
|
+
attributes.forEach((attr) => {
|
|
11
|
+
if (attr && typeof attr === "object" && attr.name) {
|
|
12
|
+
obj[attr.name] = attr;
|
|
13
|
+
} else if (Array.isArray(attr) && attr.length >= 2) {
|
|
14
|
+
obj[attr[0]] = attr[1];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
attributes = obj;
|
|
18
|
+
}
|
|
19
|
+
const properties = Object.entries(attributes).map(([name, attr]) => {
|
|
20
|
+
const tsType = mapToTypeScript(attr.type);
|
|
21
|
+
const optional = !attr.constraints?.required ? "?" : "";
|
|
22
|
+
return ` ${name}${optional}: ${tsType};`;
|
|
23
|
+
}).join("\n");
|
|
24
|
+
return `/**
|
|
25
|
+
* ${modelName} Type Definition
|
|
26
|
+
* Auto-generated from SpecVerse model
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
export interface ${modelName} {
|
|
30
|
+
${properties}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type Create${modelName}Input = Omit<${modelName}, 'id' | 'createdAt' | 'updatedAt'>;
|
|
34
|
+
export type Update${modelName}Input = Partial<Create${modelName}Input>;
|
|
35
|
+
`;
|
|
36
|
+
}
|
|
37
|
+
function mapToTypeScript(type) {
|
|
38
|
+
const typeMap = {
|
|
39
|
+
"String": "string",
|
|
40
|
+
"Integer": "number",
|
|
41
|
+
"Float": "number",
|
|
42
|
+
"Boolean": "boolean",
|
|
43
|
+
"Date": "string",
|
|
44
|
+
"DateTime": "string",
|
|
45
|
+
"Timestamp": "string",
|
|
46
|
+
"UUID": "string",
|
|
47
|
+
"Email": "string",
|
|
48
|
+
"URL": "string",
|
|
49
|
+
"JSON": "Record<string, any>",
|
|
50
|
+
"Array": "any[]"
|
|
51
|
+
};
|
|
52
|
+
return typeMap[type] || "any";
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
generateModelTypes as default
|
|
56
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function generateViewsMetadata(context) {
|
|
2
|
+
const { spec, views = [] } = context;
|
|
3
|
+
const specViews = views.length > 0 ? views : spec?.views || [];
|
|
4
|
+
const viewsArray = Array.isArray(specViews) ? specViews : Object.values(specViews);
|
|
5
|
+
const metadata = {};
|
|
6
|
+
viewsArray.forEach((viewDef) => {
|
|
7
|
+
const viewName = viewDef.name;
|
|
8
|
+
metadata[viewName] = {
|
|
9
|
+
name: viewName,
|
|
10
|
+
type: viewDef.type || "list",
|
|
11
|
+
...viewDef.description && { description: viewDef.description },
|
|
12
|
+
model: viewDef.model,
|
|
13
|
+
// Keep as-is (string or array for multi-model views)
|
|
14
|
+
...viewDef.uiComponents && { uiComponents: viewDef.uiComponents },
|
|
15
|
+
...viewDef.subscriptions && viewDef.subscriptions.length > 0 && {
|
|
16
|
+
subscriptions: viewDef.subscriptions
|
|
17
|
+
},
|
|
18
|
+
routing: viewDef.routing || {
|
|
19
|
+
path: `/${viewName.toLowerCase().replace(/view$/, "")}`
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
return JSON.stringify(metadata, null, 2);
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
generateViewsMetadata as default
|
|
27
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function generateViteConfig(context) {
|
|
2
|
+
const { backendPort = 3e3 } = context;
|
|
3
|
+
return `import { defineConfig } from 'vite';
|
|
4
|
+
import react from '@vitejs/plugin-react';
|
|
5
|
+
|
|
6
|
+
// https://vitejs.dev/config/
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
plugins: [react()],
|
|
9
|
+
server: {
|
|
10
|
+
port: 5173,
|
|
11
|
+
host: true,
|
|
12
|
+
proxy: {
|
|
13
|
+
'/api': {
|
|
14
|
+
target: 'http://localhost:${backendPort}',
|
|
15
|
+
changeOrigin: true,
|
|
16
|
+
rewrite: (path) => path
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
build: {
|
|
21
|
+
outDir: 'dist',
|
|
22
|
+
sourcemap: true
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
generateViteConfig as default
|
|
29
|
+
};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import React, { createElement, useState, useMemo } from "react";
|
|
2
|
+
import {
|
|
3
|
+
BaseComponentGenerator
|
|
4
|
+
} from "../shared/base-generator.js";
|
|
5
|
+
import { mapProperties } from "../shared/property-mapper.js";
|
|
6
|
+
import { getComponentMetadata } from "../shared/component-metadata.js";
|
|
7
|
+
class RuntimeViewRenderer extends BaseComponentGenerator {
|
|
8
|
+
runtimeConfig;
|
|
9
|
+
viewContext;
|
|
10
|
+
constructor(adapter, config) {
|
|
11
|
+
super(adapter, config);
|
|
12
|
+
this.runtimeConfig = config;
|
|
13
|
+
}
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Public API - Runtime Rendering
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Render view as React element (runtime)
|
|
19
|
+
*
|
|
20
|
+
* @param viewSpec - View specification
|
|
21
|
+
* @param context - Runtime context (state, data, handlers)
|
|
22
|
+
* @returns React element
|
|
23
|
+
*/
|
|
24
|
+
renderRuntime(viewSpec, context) {
|
|
25
|
+
this.viewContext = this.initializeContext(viewSpec, context);
|
|
26
|
+
const components = this.renderComponentsRuntime(viewSpec.components);
|
|
27
|
+
return createElement(
|
|
28
|
+
"div",
|
|
29
|
+
{ className: "specverse-runtime-view", "data-view": viewSpec.name },
|
|
30
|
+
components
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create a React component from view spec
|
|
35
|
+
*
|
|
36
|
+
* Returns a React component function that can be used directly
|
|
37
|
+
*
|
|
38
|
+
* @param viewSpec - View specification
|
|
39
|
+
* @returns React component function
|
|
40
|
+
*/
|
|
41
|
+
createRuntimeComponent(viewSpec) {
|
|
42
|
+
const renderer = this;
|
|
43
|
+
return function RuntimeViewComponent(props) {
|
|
44
|
+
const [state, setState] = useState(
|
|
45
|
+
() => renderer.initializeState(viewSpec.state)
|
|
46
|
+
);
|
|
47
|
+
const handlers = useMemo(
|
|
48
|
+
() => renderer.createEventHandlers(viewSpec.events, state, setState),
|
|
49
|
+
[state]
|
|
50
|
+
);
|
|
51
|
+
const context = {
|
|
52
|
+
state,
|
|
53
|
+
setState: (updates) => setState((prev) => ({ ...prev, ...updates })),
|
|
54
|
+
handlers,
|
|
55
|
+
data: props.data || {}
|
|
56
|
+
};
|
|
57
|
+
return renderer.renderRuntime(viewSpec, context);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// ============================================================================
|
|
61
|
+
// Abstract Method Implementations (Not Used in Runtime)
|
|
62
|
+
// ============================================================================
|
|
63
|
+
generateImports(viewSpec) {
|
|
64
|
+
return "";
|
|
65
|
+
}
|
|
66
|
+
generateComponent(parts) {
|
|
67
|
+
return "";
|
|
68
|
+
}
|
|
69
|
+
generateState(state) {
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
72
|
+
generateEvents(events) {
|
|
73
|
+
return "";
|
|
74
|
+
}
|
|
75
|
+
getFileExtension() {
|
|
76
|
+
return "";
|
|
77
|
+
}
|
|
78
|
+
getAdditionalFiles(viewSpec) {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
// ============================================================================
|
|
82
|
+
// Runtime-Specific Methods
|
|
83
|
+
// ============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* Initialize runtime context
|
|
86
|
+
*/
|
|
87
|
+
initializeContext(viewSpec, context) {
|
|
88
|
+
return {
|
|
89
|
+
state: context?.state || this.initializeState(viewSpec.state),
|
|
90
|
+
setState: context?.setState || (() => {
|
|
91
|
+
}),
|
|
92
|
+
handlers: context?.handlers || this.createEventHandlers(viewSpec.events),
|
|
93
|
+
data: context?.data || {}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Initialize state from view spec
|
|
98
|
+
*/
|
|
99
|
+
initializeState(state) {
|
|
100
|
+
if (!state) return {};
|
|
101
|
+
const initialState = {};
|
|
102
|
+
for (const [name, def] of Object.entries(state)) {
|
|
103
|
+
initialState[name] = def.initial;
|
|
104
|
+
}
|
|
105
|
+
return initialState;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create event handlers from view spec
|
|
109
|
+
*/
|
|
110
|
+
createEventHandlers(events, state, setState) {
|
|
111
|
+
if (!events) return {};
|
|
112
|
+
const handlers = {};
|
|
113
|
+
for (const [name, def] of Object.entries(events)) {
|
|
114
|
+
handlers[`handle${this.capitalize(name)}`] = (...args) => {
|
|
115
|
+
if (this.runtimeConfig.debug) {
|
|
116
|
+
console.log(`[RuntimeView] Event: ${name}`, args);
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
const fn = new Function("state", "setState", "args", def.body);
|
|
120
|
+
fn(state, setState, args);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
console.error(`[RuntimeView] Event handler error (${name}):`, error);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return handlers;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Render components as React elements
|
|
130
|
+
*/
|
|
131
|
+
renderComponentsRuntime(components) {
|
|
132
|
+
return Object.entries(components).map(
|
|
133
|
+
([name, component]) => this.renderComponentRuntime(component, {
|
|
134
|
+
depth: 0,
|
|
135
|
+
path: [name]
|
|
136
|
+
})
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Render single component as React element
|
|
141
|
+
*/
|
|
142
|
+
renderComponentRuntime(component, context) {
|
|
143
|
+
if (context.depth > this.MAX_DEPTH) {
|
|
144
|
+
if (this.runtimeConfig.debug) {
|
|
145
|
+
console.warn(`[RuntimeView] Max depth exceeded at ${context.path.join(".")}`);
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
const metadata = getComponentMetadata(component.type);
|
|
150
|
+
if (!metadata) {
|
|
151
|
+
console.warn(`[RuntimeView] Unknown component type: ${component.type}`);
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const mappedProps = component.properties ? mapProperties(component.type, component.properties, "runtime") : {};
|
|
155
|
+
const props = {
|
|
156
|
+
...mappedProps,
|
|
157
|
+
key: context.path.join("-")
|
|
158
|
+
};
|
|
159
|
+
if (component.condition && this.viewContext) {
|
|
160
|
+
const condition = this.evaluateCondition(component.condition, this.viewContext);
|
|
161
|
+
if (!condition) return null;
|
|
162
|
+
}
|
|
163
|
+
if (component.dataSource && this.viewContext) {
|
|
164
|
+
return this.renderListRuntime(component, props, context);
|
|
165
|
+
}
|
|
166
|
+
let children = null;
|
|
167
|
+
if (component.children && component.children.length > 0) {
|
|
168
|
+
children = component.children.map(
|
|
169
|
+
(child, index) => this.renderComponentRuntime(child, {
|
|
170
|
+
...context,
|
|
171
|
+
depth: context.depth + 1,
|
|
172
|
+
path: [...context.path, `child_${index}`]
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
const adapterComponent = this.adapter.components[component.type];
|
|
177
|
+
if (!adapterComponent) {
|
|
178
|
+
console.warn(`[RuntimeView] No adapter for component: ${component.type}`);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
return this.createElementFromAdapter(component.type, props, children);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Render list of items
|
|
185
|
+
*/
|
|
186
|
+
renderListRuntime(component, props, context) {
|
|
187
|
+
if (!this.viewContext) return null;
|
|
188
|
+
const dataArray = this.viewContext.data[component.dataSource];
|
|
189
|
+
if (!Array.isArray(dataArray)) {
|
|
190
|
+
console.warn(`[RuntimeView] Data source not found: ${component.dataSource}`);
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
const items = dataArray.map((item, index) => {
|
|
194
|
+
const itemProps = {
|
|
195
|
+
...props,
|
|
196
|
+
...item,
|
|
197
|
+
key: `${context.path.join("-")}-${index}`
|
|
198
|
+
};
|
|
199
|
+
return this.createElementFromAdapter(component.type, itemProps, null);
|
|
200
|
+
});
|
|
201
|
+
return createElement(React.Fragment, null, ...items);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Create React element from adapter component
|
|
205
|
+
*/
|
|
206
|
+
createElementFromAdapter(type, props, children) {
|
|
207
|
+
return createElement(
|
|
208
|
+
"div",
|
|
209
|
+
{
|
|
210
|
+
...props,
|
|
211
|
+
className: `specverse-runtime-${type} ${props.className || ""}`.trim(),
|
|
212
|
+
"data-component": type
|
|
213
|
+
},
|
|
214
|
+
children
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Evaluate condition expression
|
|
219
|
+
*/
|
|
220
|
+
evaluateCondition(condition, context) {
|
|
221
|
+
try {
|
|
222
|
+
const fn = new Function("state", "data", `return ${condition}`);
|
|
223
|
+
return fn(context.state, context.data);
|
|
224
|
+
} catch (error) {
|
|
225
|
+
console.error(`[RuntimeView] Condition evaluation error:`, error);
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Capitalize first letter
|
|
231
|
+
*/
|
|
232
|
+
capitalize(str) {
|
|
233
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function createRuntimeRenderer(adapter, config) {
|
|
237
|
+
const defaultConfig = {
|
|
238
|
+
framework: "runtime",
|
|
239
|
+
target: "runtime",
|
|
240
|
+
liveReload: false,
|
|
241
|
+
debug: false,
|
|
242
|
+
maxDepth: 3,
|
|
243
|
+
enableWarnings: true
|
|
244
|
+
};
|
|
245
|
+
const finalConfig = { ...defaultConfig, ...config };
|
|
246
|
+
return new RuntimeViewRenderer(adapter, finalConfig);
|
|
247
|
+
}
|
|
248
|
+
function renderView(viewSpec, adapter, context) {
|
|
249
|
+
const renderer = createRuntimeRenderer(adapter);
|
|
250
|
+
return renderer.renderRuntime(viewSpec, context);
|
|
251
|
+
}
|
|
252
|
+
function createViewComponent(viewSpec, adapter) {
|
|
253
|
+
const renderer = createRuntimeRenderer(adapter);
|
|
254
|
+
return renderer.createRuntimeComponent(viewSpec);
|
|
255
|
+
}
|
|
256
|
+
export {
|
|
257
|
+
RuntimeViewRenderer,
|
|
258
|
+
createRuntimeRenderer,
|
|
259
|
+
createViewComponent,
|
|
260
|
+
renderView
|
|
261
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function renderProps(props) {
|
|
2
|
+
return Object.entries(props).filter(([_, value]) => value !== void 0 && value !== null).map(([key, value]) => {
|
|
3
|
+
if (typeof value === "boolean") {
|
|
4
|
+
return value ? key : "";
|
|
5
|
+
}
|
|
6
|
+
if (typeof value === "string") {
|
|
7
|
+
return `${key}="${value}"`;
|
|
8
|
+
}
|
|
9
|
+
if (typeof value === "number") {
|
|
10
|
+
return `${key}={${value}}`;
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
return `${key}={${JSON.stringify(value)}}`;
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === "object") {
|
|
16
|
+
return `${key}={${JSON.stringify(value)}}`;
|
|
17
|
+
}
|
|
18
|
+
return `${key}={${value}}`;
|
|
19
|
+
}).filter(Boolean).join(" ");
|
|
20
|
+
}
|
|
21
|
+
function indent(code, level = 0) {
|
|
22
|
+
const spaces = " ".repeat(level);
|
|
23
|
+
return code.split("\n").map((line) => line ? spaces + line : line).join("\n");
|
|
24
|
+
}
|
|
25
|
+
function wrapWithChildren(openTag, children, closeTag, indentLevel = 0) {
|
|
26
|
+
return `${openTag}
|
|
27
|
+
${indent(children, indentLevel + 1)}
|
|
28
|
+
${indent(closeTag, indentLevel)}`;
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
indent,
|
|
32
|
+
renderProps,
|
|
33
|
+
wrapWithChildren
|
|
34
|
+
};
|