archetype-engine 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,271 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * MCP Server for Archetype Engine
5
+ *
6
+ * Provides tools for Claude Desktop, Claude Code, Cursor, and other MCP clients
7
+ * to generate backends from entity descriptions.
8
+ *
9
+ * Usage:
10
+ * npx archetype-engine mcp
11
+ */
12
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ var desc = Object.getOwnPropertyDescriptor(m, k);
15
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
16
+ desc = { enumerable: true, get: function() { return m[k]; } };
17
+ }
18
+ Object.defineProperty(o, k2, desc);
19
+ }) : (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ o[k2] = m[k];
22
+ }));
23
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
24
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
25
+ }) : function(o, v) {
26
+ o["default"] = v;
27
+ });
28
+ var __importStar = (this && this.__importStar) || (function () {
29
+ var ownKeys = function(o) {
30
+ ownKeys = Object.getOwnPropertyNames || function (o) {
31
+ var ar = [];
32
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
33
+ return ar;
34
+ };
35
+ return ownKeys(o);
36
+ };
37
+ return function (mod) {
38
+ if (mod && mod.__esModule) return mod;
39
+ var result = {};
40
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
41
+ __setModuleDefault(result, mod);
42
+ return result;
43
+ };
44
+ })();
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.runMCPServer = runMCPServer;
47
+ const fs = __importStar(require("fs"));
48
+ const path = __importStar(require("path"));
49
+ const parser_1 = require("./json/parser");
50
+ const validation_1 = require("./validation");
51
+ const template_1 = require("./template");
52
+ const child_process_1 = require("child_process");
53
+ const util_1 = require("util");
54
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
55
+ /**
56
+ * Handle archetype_create_manifest tool
57
+ */
58
+ async function handleCreateManifest(args) {
59
+ const manifest = {
60
+ entities: args.entities,
61
+ database: args.database,
62
+ auth: args.auth,
63
+ template: 'nextjs-drizzle-trpc'
64
+ };
65
+ // Validate first
66
+ const validation = (0, validation_1.validateManifest)(manifest);
67
+ if (!validation.valid) {
68
+ const errors = validation.errors.map(e => `[${e.code}] ${e.path}: ${e.message}`).join('\n');
69
+ return {
70
+ content: [{
71
+ type: 'text',
72
+ text: `❌ Validation failed:\n\n${errors}\n\n${validation.errors.map(e => e.suggestion).filter(Boolean).join('\n')}`
73
+ }]
74
+ };
75
+ }
76
+ // Write manifest.json
77
+ const manifestPath = path.join(process.cwd(), 'manifest.json');
78
+ fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2));
79
+ return {
80
+ content: [{
81
+ type: 'text',
82
+ text: `✅ Created manifest.json with ${args.entities.length} entities\n\nNext steps:\n1. Review manifest.json\n2. Run: npx archetype generate manifest.json\n3. Run: npx drizzle-kit push && npm run dev`
83
+ }]
84
+ };
85
+ }
86
+ /**
87
+ * Handle archetype_validate_manifest tool
88
+ */
89
+ async function handleValidate(args) {
90
+ const manifestPath = path.resolve(args.manifestPath || 'manifest.json');
91
+ if (!fs.existsSync(manifestPath)) {
92
+ return {
93
+ content: [{
94
+ type: 'text',
95
+ text: `❌ Manifest not found: ${manifestPath}`
96
+ }]
97
+ };
98
+ }
99
+ const content = fs.readFileSync(manifestPath, 'utf-8');
100
+ const manifest = JSON.parse(content);
101
+ const validation = (0, validation_1.validateManifest)(manifest);
102
+ if (validation.valid) {
103
+ const warnings = validation.warnings.length > 0
104
+ ? `\n\nWarnings:\n${validation.warnings.map(w => ` - [${w.code}] ${w.message}`).join('\n')}`
105
+ : '';
106
+ return {
107
+ content: [{
108
+ type: 'text',
109
+ text: `✅ Manifest is valid!${warnings}\n\nReady to generate with: npx archetype generate ${manifestPath}`
110
+ }]
111
+ };
112
+ }
113
+ else {
114
+ const errors = validation.errors.map(e => ` - [${e.code}] ${e.path}: ${e.message}${e.suggestion ? `\n Fix: ${e.suggestion}` : ''}`).join('\n');
115
+ return {
116
+ content: [{
117
+ type: 'text',
118
+ text: `❌ Validation failed:\n\n${errors}`
119
+ }]
120
+ };
121
+ }
122
+ }
123
+ /**
124
+ * Handle archetype_generate tool
125
+ */
126
+ async function handleGenerate(args) {
127
+ const manifestPath = path.resolve(args.manifestPath || 'manifest.json');
128
+ if (!fs.existsSync(manifestPath)) {
129
+ return {
130
+ content: [{
131
+ type: 'text',
132
+ text: `❌ Manifest not found: ${manifestPath}`
133
+ }]
134
+ };
135
+ }
136
+ const content = fs.readFileSync(manifestPath, 'utf-8');
137
+ const manifest = JSON.parse(content);
138
+ // Validate
139
+ const validation = (0, validation_1.validateManifest)(manifest);
140
+ if (!validation.valid) {
141
+ const errors = validation.errors.map(e => `[${e.code}] ${e.message}`).join('\n');
142
+ return {
143
+ content: [{
144
+ type: 'text',
145
+ text: `❌ Validation failed:\n\n${errors}\n\nRun: npx archetype validate ${manifestPath}`
146
+ }]
147
+ };
148
+ }
149
+ // Parse and generate
150
+ const ir = (0, parser_1.parseManifestJSON)(manifest);
151
+ const template = await (0, template_1.getTemplate)('nextjs-drizzle-trpc');
152
+ if (!template) {
153
+ return {
154
+ content: [{
155
+ type: 'text',
156
+ text: '❌ Template not found'
157
+ }]
158
+ };
159
+ }
160
+ const files = await (0, template_1.runTemplate)(template, ir);
161
+ const fileList = files.map(f => f.path).join('\n - ');
162
+ return {
163
+ content: [{
164
+ type: 'text',
165
+ text: `✅ Generated ${files.length} files:\n - ${fileList}\n\nNext steps:\n1. Run: npx drizzle-kit push\n2. Run: npm run dev`
166
+ }]
167
+ };
168
+ }
169
+ /**
170
+ * Handle archetype_view_schema tool
171
+ */
172
+ async function handleViewSchema(args) {
173
+ const configPath = args.configPath || 'manifest.json';
174
+ try {
175
+ const { stdout } = await execAsync(`npx archetype view ${configPath}`);
176
+ return {
177
+ content: [{
178
+ type: 'text',
179
+ text: `✅ Opening ERD viewer in browser...\n\n${stdout}`
180
+ }]
181
+ };
182
+ }
183
+ catch (error) {
184
+ return {
185
+ content: [{
186
+ type: 'text',
187
+ text: `❌ Failed to open viewer: ${error.message}`
188
+ }]
189
+ };
190
+ }
191
+ }
192
+ /**
193
+ * Handle archetype_generate_from_description tool
194
+ * This is a convenience wrapper that uses AI to convert natural language to manifest
195
+ */
196
+ async function handleGenerateFromDescription(args) {
197
+ return {
198
+ content: [{
199
+ type: 'text',
200
+ text: `⚠️ This tool requires an AI model to convert the description to entities.\n\nInstead, I recommend:\n1. Use archetype_create_manifest to define entities explicitly\n2. Or create manifest.json manually based on: ${args.description}\n\nExample entities for "${args.description}":\n- Identify the main data types (User, Post, Product, etc.)\n- Define fields for each entity\n- Add relations between entities\n\nThen use archetype_create_manifest with the entity definitions.`
201
+ }]
202
+ };
203
+ }
204
+ /**
205
+ * Main MCP server loop
206
+ */
207
+ async function runMCPServer() {
208
+ const stdin = process.stdin;
209
+ const stdout = process.stdout;
210
+ stdin.setEncoding('utf-8');
211
+ let buffer = '';
212
+ stdin.on('data', async (chunk) => {
213
+ buffer += chunk;
214
+ // Process complete JSON messages
215
+ const lines = buffer.split('\n');
216
+ buffer = lines.pop() || '';
217
+ for (const line of lines) {
218
+ if (!line.trim())
219
+ continue;
220
+ try {
221
+ const request = JSON.parse(line);
222
+ if (request.method === 'tools/call' && request.params) {
223
+ const toolName = request.params.name;
224
+ const args = request.params.arguments || {};
225
+ let response;
226
+ switch (toolName) {
227
+ case 'archetype_create_manifest':
228
+ response = await handleCreateManifest(args);
229
+ break;
230
+ case 'archetype_validate_manifest':
231
+ response = await handleValidate(args);
232
+ break;
233
+ case 'archetype_generate':
234
+ response = await handleGenerate(args);
235
+ break;
236
+ case 'archetype_view_schema':
237
+ response = await handleViewSchema(args);
238
+ break;
239
+ case 'archetype_generate_from_description':
240
+ response = await handleGenerateFromDescription(args);
241
+ break;
242
+ default:
243
+ response = {
244
+ content: [{
245
+ type: 'text',
246
+ text: `Unknown tool: ${toolName}`
247
+ }]
248
+ };
249
+ }
250
+ stdout.write(JSON.stringify(response) + '\n');
251
+ }
252
+ }
253
+ catch (error) {
254
+ const errorResponse = {
255
+ content: [{
256
+ type: 'text',
257
+ text: `Error: ${error.message}`
258
+ }]
259
+ };
260
+ stdout.write(JSON.stringify(errorResponse) + '\n');
261
+ }
262
+ }
263
+ });
264
+ stdin.on('end', () => {
265
+ process.exit(0);
266
+ });
267
+ }
268
+ // Run if called directly
269
+ if (require.main === module) {
270
+ runMCPServer().catch(console.error);
271
+ }
@@ -5,4 +5,7 @@ export { apiGenerator } from './api';
5
5
  export { hooksGenerator } from './hooks';
6
6
  export { crudHooksGenerator } from './crud-hooks';
7
7
  export { i18nGenerator } from './i18n';
8
+ export { testGenerator } from './test';
9
+ export { openapiGenerator } from './openapi';
10
+ export { seedGenerator } from './seed';
8
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/templates/nextjs-drizzle-trpc/generators/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/templates/nextjs-drizzle-trpc/generators/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA"}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  // Export all generators for the nextjs-drizzle-trpc template
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.i18nGenerator = exports.crudHooksGenerator = exports.hooksGenerator = exports.apiGenerator = exports.validationGenerator = exports.authGenerator = exports.schemaGenerator = void 0;
4
+ exports.seedGenerator = exports.openapiGenerator = exports.testGenerator = exports.i18nGenerator = exports.crudHooksGenerator = exports.hooksGenerator = exports.apiGenerator = exports.validationGenerator = exports.authGenerator = exports.schemaGenerator = void 0;
5
5
  var schema_1 = require("./schema");
6
6
  Object.defineProperty(exports, "schemaGenerator", { enumerable: true, get: function () { return schema_1.schemaGenerator; } });
7
7
  var auth_1 = require("./auth");
@@ -16,3 +16,9 @@ var crud_hooks_1 = require("./crud-hooks");
16
16
  Object.defineProperty(exports, "crudHooksGenerator", { enumerable: true, get: function () { return crud_hooks_1.crudHooksGenerator; } });
17
17
  var i18n_1 = require("./i18n");
18
18
  Object.defineProperty(exports, "i18nGenerator", { enumerable: true, get: function () { return i18n_1.i18nGenerator; } });
19
+ var test_1 = require("./test");
20
+ Object.defineProperty(exports, "testGenerator", { enumerable: true, get: function () { return test_1.testGenerator; } });
21
+ var openapi_1 = require("./openapi");
22
+ Object.defineProperty(exports, "openapiGenerator", { enumerable: true, get: function () { return openapi_1.openapiGenerator; } });
23
+ var seed_1 = require("./seed");
24
+ Object.defineProperty(exports, "seedGenerator", { enumerable: true, get: function () { return seed_1.seedGenerator; } });
@@ -0,0 +1,26 @@
1
+ /**
2
+ * OpenAPI/Swagger Documentation Generator
3
+ *
4
+ * Generates OpenAPI 3.0 specification from entity definitions and tRPC routers.
5
+ * Provides interactive API documentation via Swagger UI.
6
+ *
7
+ * Generated files:
8
+ * - docs/openapi.json - OpenAPI 3.0 specification
9
+ * - docs/swagger.html - Interactive Swagger UI
10
+ *
11
+ * Features:
12
+ * - Complete API documentation for all CRUD endpoints
13
+ * - Request/response schemas derived from Zod validation
14
+ * - Authentication/authorization documentation
15
+ * - Filter, search, and pagination parameter docs
16
+ * - Batch operation endpoints
17
+ * - Interactive testing via Swagger UI
18
+ *
19
+ * @module generators/openapi
20
+ */
21
+ import type { Generator } from '../../../template/types';
22
+ /**
23
+ * OpenAPI documentation generator
24
+ */
25
+ export declare const openapiGenerator: Generator;
26
+ //# sourceMappingURL=openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../../../../src/templates/nextjs-drizzle-trpc/generators/openapi.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,yBAAyB,CAAA;AA+sBvE;;GAEG;AACH,eAAO,MAAM,gBAAgB,EAAE,SA4B9B,CAAA"}