@opensaas/stack-cli 0.1.0 → 0.1.2
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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +21 -0
- package/CLAUDE.md +249 -0
- package/LICENSE +21 -0
- package/README.md +65 -5
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +6 -1
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/init.d.ts +9 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +27 -338
- package/dist/commands/init.js.map +1 -1
- package/dist/generator/context.d.ts.map +1 -1
- package/dist/generator/context.js +78 -3
- package/dist/generator/context.js.map +1 -1
- package/dist/generator/index.d.ts +1 -0
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +1 -0
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/mcp.d.ts +14 -0
- package/dist/generator/mcp.d.ts.map +1 -0
- package/dist/generator/mcp.js +193 -0
- package/dist/generator/mcp.js.map +1 -0
- package/dist/generator/types.d.ts.map +1 -1
- package/dist/generator/types.js +11 -33
- package/dist/generator/types.js.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/package.json +9 -3
- package/src/commands/__snapshots__/generate.test.ts.snap +265 -0
- package/src/commands/dev.test.ts +216 -0
- package/src/commands/generate.test.ts +272 -0
- package/src/commands/generate.ts +7 -0
- package/src/commands/init.ts +28 -361
- package/src/generator/__snapshots__/context.test.ts.snap +137 -0
- package/src/generator/__snapshots__/prisma.test.ts.snap +182 -0
- package/src/generator/__snapshots__/types.test.ts.snap +512 -0
- package/src/generator/context.test.ts +145 -0
- package/src/generator/context.ts +80 -3
- package/src/generator/index.ts +1 -0
- package/src/generator/mcp.test.ts +393 -0
- package/src/generator/mcp.ts +221 -0
- package/src/generator/prisma.test.ts +221 -0
- package/src/generator/types.test.ts +280 -0
- package/src/generator/types.ts +14 -36
- package/src/index.ts +8 -4
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +26 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP metadata generation
|
|
3
|
+
* Generates reference files for MCP configuration
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { getDbKey } from '@opensaas/stack-core';
|
|
8
|
+
/**
|
|
9
|
+
* Generate MCP metadata if MCP is enabled
|
|
10
|
+
*/
|
|
11
|
+
export function generateMcp(config, outputPath) {
|
|
12
|
+
// Skip if MCP is not enabled
|
|
13
|
+
if (!config.mcp?.enabled) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
// Ensure output directory exists
|
|
17
|
+
const mcpDir = path.join(outputPath, '.opensaas', 'mcp');
|
|
18
|
+
if (!fs.existsSync(mcpDir)) {
|
|
19
|
+
fs.mkdirSync(mcpDir, { recursive: true });
|
|
20
|
+
}
|
|
21
|
+
// Generate tool metadata for reference
|
|
22
|
+
const tools = [];
|
|
23
|
+
for (const [listKey, listConfig] of Object.entries(config.lists)) {
|
|
24
|
+
if (listConfig.mcp?.enabled === false)
|
|
25
|
+
continue;
|
|
26
|
+
const dbKey = getDbKey(listKey);
|
|
27
|
+
const defaultTools = config.mcp?.defaultTools || {
|
|
28
|
+
read: true,
|
|
29
|
+
create: true,
|
|
30
|
+
update: true,
|
|
31
|
+
delete: true,
|
|
32
|
+
};
|
|
33
|
+
const enabledTools = {
|
|
34
|
+
read: listConfig.mcp?.tools?.read ?? defaultTools.read ?? true,
|
|
35
|
+
create: listConfig.mcp?.tools?.create ?? defaultTools.create ?? true,
|
|
36
|
+
update: listConfig.mcp?.tools?.update ?? defaultTools.update ?? true,
|
|
37
|
+
delete: listConfig.mcp?.tools?.delete ?? defaultTools.delete ?? true,
|
|
38
|
+
};
|
|
39
|
+
if (enabledTools.read) {
|
|
40
|
+
tools.push({
|
|
41
|
+
name: `list_${dbKey}_query`,
|
|
42
|
+
description: `Query ${listKey} records with optional filters`,
|
|
43
|
+
listKey,
|
|
44
|
+
operation: 'query',
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (enabledTools.create) {
|
|
48
|
+
tools.push({
|
|
49
|
+
name: `list_${dbKey}_create`,
|
|
50
|
+
description: `Create a new ${listKey} record`,
|
|
51
|
+
listKey,
|
|
52
|
+
operation: 'create',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (enabledTools.update) {
|
|
56
|
+
tools.push({
|
|
57
|
+
name: `list_${dbKey}_update`,
|
|
58
|
+
description: `Update an existing ${listKey} record`,
|
|
59
|
+
listKey,
|
|
60
|
+
operation: 'update',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (enabledTools.delete) {
|
|
64
|
+
tools.push({
|
|
65
|
+
name: `list_${dbKey}_delete`,
|
|
66
|
+
description: `Delete a ${listKey} record`,
|
|
67
|
+
listKey,
|
|
68
|
+
operation: 'delete',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
// Custom tools
|
|
72
|
+
if (listConfig.mcp?.customTools) {
|
|
73
|
+
for (const customTool of listConfig.mcp.customTools) {
|
|
74
|
+
tools.push({
|
|
75
|
+
name: customTool.name,
|
|
76
|
+
description: customTool.description,
|
|
77
|
+
listKey,
|
|
78
|
+
operation: 'custom',
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Write tools.json for reference
|
|
84
|
+
const toolsPath = path.join(mcpDir, 'tools.json');
|
|
85
|
+
fs.writeFileSync(toolsPath, JSON.stringify(tools, null, 2), 'utf-8');
|
|
86
|
+
// Write README with usage instructions
|
|
87
|
+
const readmePath = path.join(mcpDir, 'README.md');
|
|
88
|
+
fs.writeFileSync(readmePath, `# MCP Tools Reference
|
|
89
|
+
|
|
90
|
+
This directory contains metadata about your MCP configuration.
|
|
91
|
+
|
|
92
|
+
## Available Tools
|
|
93
|
+
|
|
94
|
+
${tools.length} tool(s) available:
|
|
95
|
+
|
|
96
|
+
${tools
|
|
97
|
+
.map((tool) => `- **${tool.name}** (${tool.operation}): ${tool.description}
|
|
98
|
+
- List: ${tool.listKey}`)
|
|
99
|
+
.join('\n\n')}
|
|
100
|
+
|
|
101
|
+
## Usage
|
|
102
|
+
|
|
103
|
+
Create your MCP route handler:
|
|
104
|
+
|
|
105
|
+
\`\`\`typescript
|
|
106
|
+
// app/api/mcp/[[...transport]]/route.ts
|
|
107
|
+
import { createMcpHandlers } from '@opensaas/stack-mcp'
|
|
108
|
+
import config from '@/opensaas.config'
|
|
109
|
+
import { auth } from '@/lib/auth'
|
|
110
|
+
import { getContext } from '@/.opensaas/context'
|
|
111
|
+
|
|
112
|
+
const { GET, POST, DELETE } = createMcpHandlers({
|
|
113
|
+
config,
|
|
114
|
+
auth,
|
|
115
|
+
getContext
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
export { GET, POST, DELETE }
|
|
119
|
+
\`\`\`
|
|
120
|
+
|
|
121
|
+
## Connecting to Claude Desktop
|
|
122
|
+
|
|
123
|
+
### Option 1: Remote MCP Server (Recommended for Production)
|
|
124
|
+
|
|
125
|
+
For production use with OAuth authentication, add your server via **Claude Desktop > Settings > Connectors**.
|
|
126
|
+
|
|
127
|
+
Claude Desktop requires:
|
|
128
|
+
1. Your server must be publicly accessible (use ngrok/cloudflare tunnel for local testing)
|
|
129
|
+
2. OAuth authorization server at \`/.well-known/oauth-authorization-server\`
|
|
130
|
+
3. Dynamic Client Registration (DCR) support - Better Auth MCP plugin provides this
|
|
131
|
+
|
|
132
|
+
**Note:** Remote MCP servers with OAuth cannot be configured via \`claude_desktop_config.json\` - they must be added through the Claude Desktop UI.
|
|
133
|
+
|
|
134
|
+
### Option 2: Local Development (No OAuth)
|
|
135
|
+
|
|
136
|
+
For local development without OAuth, you can create a proxy MCP server script:
|
|
137
|
+
|
|
138
|
+
1. Create \`mcp-server.js\` in your project root:
|
|
139
|
+
|
|
140
|
+
\`\`\`javascript
|
|
141
|
+
#!/usr/bin/env node
|
|
142
|
+
import { spawn } from 'child_process';
|
|
143
|
+
|
|
144
|
+
// Start Next.js dev server in background
|
|
145
|
+
const server = spawn('npm', ['run', 'dev'], { stdio: 'inherit' });
|
|
146
|
+
|
|
147
|
+
// Wait for server to be ready
|
|
148
|
+
setTimeout(() => {
|
|
149
|
+
console.log('MCP server ready at http://localhost:3000${config.mcp.basePath || '/api/mcp'}');
|
|
150
|
+
}, 3000);
|
|
151
|
+
|
|
152
|
+
process.on('SIGINT', () => {
|
|
153
|
+
server.kill();
|
|
154
|
+
process.exit();
|
|
155
|
+
});
|
|
156
|
+
\`\`\`
|
|
157
|
+
|
|
158
|
+
2. Add to \`claude_desktop_config.json\`:
|
|
159
|
+
|
|
160
|
+
\`\`\`json
|
|
161
|
+
{
|
|
162
|
+
"mcpServers": {
|
|
163
|
+
"my-app": {
|
|
164
|
+
"command": "node",
|
|
165
|
+
"args": ["mcp-server.js"]
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
\`\`\`
|
|
170
|
+
|
|
171
|
+
### Option 3: Using ngrok for Local OAuth Testing
|
|
172
|
+
|
|
173
|
+
1. Start your dev server: \`npm run dev\`
|
|
174
|
+
2. Expose with ngrok: \`ngrok http 3000\`
|
|
175
|
+
3. Add to Claude Desktop via **Settings > Connectors** with your ngrok URL
|
|
176
|
+
`, 'utf-8');
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Write MCP metadata to disk
|
|
181
|
+
*/
|
|
182
|
+
export function writeMcp(config, outputPath) {
|
|
183
|
+
const generated = generateMcp(config, outputPath);
|
|
184
|
+
if (!generated) {
|
|
185
|
+
// Clean up MCP directory if MCP is disabled
|
|
186
|
+
const mcpDir = path.join(outputPath, '.opensaas', 'mcp');
|
|
187
|
+
if (fs.existsSync(mcpDir)) {
|
|
188
|
+
fs.rmSync(mcpDir, { recursive: true, force: true });
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return generated;
|
|
192
|
+
}
|
|
193
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/generator/mcp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE/C;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAAsB,EAAE,UAAkB;IACpE,6BAA6B;IAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC;QACzB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,iCAAiC;IACjC,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,CAAA;IACxD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC3C,CAAC;IAED,uCAAuC;IACvC,MAAM,KAAK,GAKN,EAAE,CAAA;IAEP,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACjE,IAAI,UAAU,CAAC,GAAG,EAAE,OAAO,KAAK,KAAK;YAAE,SAAQ;QAE/C,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;QAC/B,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,EAAE,YAAY,IAAI;YAC/C,IAAI,EAAE,IAAI;YACV,MAAM,EAAE,IAAI;YACZ,MAAM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;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAsB,EAAE,UAAkB;IACjE,MAAM,SAAS,GAAG,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAEjD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,4CAA4C;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,CAAA;QACxD,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACrD,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkC,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAkC,MAAM,sBAAsB,CAAA;AA4L1F;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAkC5D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAU3E"}
|
package/dist/generator/types.js
CHANGED
|
@@ -148,39 +148,12 @@ function generateWhereInputType(listName, fields) {
|
|
|
148
148
|
*/
|
|
149
149
|
function generateContextType(config) {
|
|
150
150
|
const lines = [];
|
|
151
|
-
lines.push('export type Context = {');
|
|
152
|
-
lines.push(' db:
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
lines.push(` where: { id: string }`);
|
|
158
|
-
lines.push(` include?: any`);
|
|
159
|
-
lines.push(` }) => Promise<${listName} | null>`);
|
|
160
|
-
lines.push(` findMany: (args?: {`);
|
|
161
|
-
lines.push(` where?: ${listName}WhereInput`);
|
|
162
|
-
lines.push(` take?: number`);
|
|
163
|
-
lines.push(` skip?: number`);
|
|
164
|
-
lines.push(` include?: any`);
|
|
165
|
-
lines.push(` }) => Promise<${listName}[]>`);
|
|
166
|
-
lines.push(` create: (args: {`);
|
|
167
|
-
lines.push(` data: ${listName}CreateInput`);
|
|
168
|
-
lines.push(` }) => Promise<${listName} | null>`);
|
|
169
|
-
lines.push(` update: (args: {`);
|
|
170
|
-
lines.push(` where: { id: string }`);
|
|
171
|
-
lines.push(` data: ${listName}UpdateInput`);
|
|
172
|
-
lines.push(` }) => Promise<${listName} | null>`);
|
|
173
|
-
lines.push(` delete: (args: {`);
|
|
174
|
-
lines.push(` where: { id: string }`);
|
|
175
|
-
lines.push(` }) => Promise<${listName} | null>`);
|
|
176
|
-
lines.push(` count: (args?: {`);
|
|
177
|
-
lines.push(` where?: ${listName}WhereInput`);
|
|
178
|
-
lines.push(` }) => Promise<number>`);
|
|
179
|
-
lines.push(` }`);
|
|
180
|
-
}
|
|
181
|
-
lines.push(' }');
|
|
182
|
-
lines.push(' session: any');
|
|
183
|
-
lines.push(' prisma: any // Your PrismaClient instance');
|
|
151
|
+
lines.push('export type Context<TSession extends OpensaasSession = OpensaasSession> = {');
|
|
152
|
+
lines.push(' db: AccessControlledDB<PrismaClient>');
|
|
153
|
+
lines.push(' session: TSession');
|
|
154
|
+
lines.push(' prisma: PrismaClient');
|
|
155
|
+
lines.push(' storage: StorageUtils');
|
|
156
|
+
lines.push(' serverAction: (props: ServerActionProps) => Promise<unknown>');
|
|
184
157
|
lines.push('}');
|
|
185
158
|
return lines.join('\n');
|
|
186
159
|
}
|
|
@@ -195,6 +168,11 @@ export function generateTypes(config) {
|
|
|
195
168
|
lines.push(' * DO NOT EDIT - This file is automatically generated');
|
|
196
169
|
lines.push(' */');
|
|
197
170
|
lines.push('');
|
|
171
|
+
// Add necessary imports
|
|
172
|
+
// Use alias for Session to avoid conflicts if user has a list named "Session"
|
|
173
|
+
lines.push("import type { Session as OpensaasSession, StorageUtils, ServerActionProps, AccessControlledDB } from '@opensaas/stack-core'");
|
|
174
|
+
lines.push("import type { PrismaClient } from './prisma-client'");
|
|
175
|
+
lines.push('');
|
|
198
176
|
// Generate types for each list
|
|
199
177
|
for (const [listName, listConfig] of Object.entries(config.lists)) {
|
|
200
178
|
lines.push(generateModelType(listName, listConfig.fields));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generator/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B;;GAEG;AACH,SAAS,wBAAwB,CAAC,KAAkB;IAClD,uCAAuC;IACvC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,yDAAyD;IACzD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,iBAAiB,EAAE,CAAA;QACxC,OAAO,MAAM,CAAC,IAAI,CAAA;IACpB,CAAC;IAED,gDAAgD;IAChD,MAAM,IAAI,KAAK,CAAC,eAAe,KAAK,CAAC,IAAI,+CAA+C,CAAC,CAAA;AAC3F,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,KAAkB;IACzC,oCAAoC;IACpC,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,yDAAyD;IACzD,IAAI,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC5B,MAAM,MAAM,GAAG,KAAK,CAAC,iBAAiB,EAAE,CAAA;QACxC,OAAO,MAAM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AAC,CAAA;QAC1D,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;QAChE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;QAChE,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACd,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAA;QAC/D,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAChB,CAAC;IAED,wBAAwB;IACxB,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAA;IAEvC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAAsB,EAAE,UAAkB;IACnE,MAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAEnC,0BAA0B;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IACpC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,EAAE,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACxC,CAAC;IAED,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;AAC9C,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -13,10 +13,16 @@ program
|
|
|
13
13
|
});
|
|
14
14
|
program
|
|
15
15
|
.command('init [project-name]')
|
|
16
|
-
.description('Create a new OpenSaas project')
|
|
17
|
-
.option('-
|
|
18
|
-
.
|
|
19
|
-
|
|
16
|
+
.description('Create a new OpenSaas project (delegates to create-opensaas-app)')
|
|
17
|
+
.option('--with-auth', 'Include authentication (Better-auth)')
|
|
18
|
+
.allowUnknownOption() // Allow passing through other options
|
|
19
|
+
.action(async (projectName, options) => {
|
|
20
|
+
const args = [];
|
|
21
|
+
if (projectName)
|
|
22
|
+
args.push(projectName);
|
|
23
|
+
if (options.withAuth)
|
|
24
|
+
args.push('--with-auth');
|
|
25
|
+
await initCommand(args);
|
|
20
26
|
});
|
|
21
27
|
program
|
|
22
28
|
.command('dev')
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAE7B,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAE3E,OAAO;KACJ,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,qEAAqE,CAAC;KAClF,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,MAAM,eAAe,EAAE,CAAA;AACzB,CAAC,CAAC,CAAA;AAEJ,OAAO;KACJ,OAAO,CAAC,qBAAqB,CAAC;KAC9B,WAAW,CAAC
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,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
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "CLI tools for OpenSaas Stack",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,16 +33,22 @@
|
|
|
33
33
|
"prompts": "^2.4.2",
|
|
34
34
|
"chokidar": "^4.0.3",
|
|
35
35
|
"jiti": "^2.6.1",
|
|
36
|
-
"@opensaas/stack-core": "0.1.
|
|
36
|
+
"@opensaas/stack-core": "0.1.2",
|
|
37
|
+
"@opensaas/stack-mcp": "0.1.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@types/node": "^24.7.2",
|
|
40
41
|
"@types/prompts": "^2.4.9",
|
|
41
|
-
"
|
|
42
|
+
"@vitest/coverage-v8": "^4.0.3",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"vitest": "^4.0.3"
|
|
42
45
|
},
|
|
43
46
|
"scripts": {
|
|
44
47
|
"build": "tsc",
|
|
45
48
|
"dev": "tsc --watch",
|
|
49
|
+
"test": "vitest",
|
|
50
|
+
"test:ui": "vitest --ui",
|
|
51
|
+
"test:coverage": "vitest --coverage",
|
|
46
52
|
"clean": "rm -rf .turbo dist tsconfig.tsbuildinfo"
|
|
47
53
|
}
|
|
48
54
|
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`Generate Command Integration > Generator Integration > should generate all files for a basic config > context 1`] = `
|
|
4
|
+
"/**
|
|
5
|
+
* Auto-generated context factory
|
|
6
|
+
*
|
|
7
|
+
* This module provides a simple API for creating OpenSaas contexts.
|
|
8
|
+
* It abstracts away Prisma client management and configuration.
|
|
9
|
+
*
|
|
10
|
+
* DO NOT EDIT - This file is automatically generated by 'pnpm generate'
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { getContext as getOpensaasContext } from '@opensaas/stack-core'
|
|
14
|
+
import type { Session as OpensaasSession } from '@opensaas/stack-core'
|
|
15
|
+
import { PrismaClient } from './prisma-client'
|
|
16
|
+
import type { Context } from './types'
|
|
17
|
+
import config from '../opensaas.config'
|
|
18
|
+
|
|
19
|
+
// Internal Prisma singleton - managed automatically
|
|
20
|
+
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined }
|
|
21
|
+
const prisma = globalForPrisma.prisma ?? new PrismaClient()
|
|
22
|
+
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Storage utilities (not configured)
|
|
26
|
+
*/
|
|
27
|
+
const storage = {
|
|
28
|
+
uploadFile: async () => {
|
|
29
|
+
throw new Error('Storage is not configured. Add storage providers to your opensaas.config.ts')
|
|
30
|
+
},
|
|
31
|
+
uploadImage: async () => {
|
|
32
|
+
throw new Error('Storage is not configured. Add storage providers to your opensaas.config.ts')
|
|
33
|
+
},
|
|
34
|
+
deleteFile: async () => {
|
|
35
|
+
throw new Error('Storage is not configured. Add storage providers to your opensaas.config.ts')
|
|
36
|
+
},
|
|
37
|
+
deleteImage: async () => {
|
|
38
|
+
throw new Error('Storage is not configured. Add storage providers to your opensaas.config.ts')
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get OpenSaas context with optional session
|
|
44
|
+
*
|
|
45
|
+
* @param session - Optional session object (structure defined by your application)
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* \`\`\`typescript
|
|
49
|
+
* // Anonymous access
|
|
50
|
+
* const context = getContext()
|
|
51
|
+
* const posts = await context.db.post.findMany()
|
|
52
|
+
*
|
|
53
|
+
* // Authenticated access
|
|
54
|
+
* const context = getContext({ userId: 'user-123' })
|
|
55
|
+
* const myPosts = await context.db.post.findMany()
|
|
56
|
+
*
|
|
57
|
+
* // With custom session type
|
|
58
|
+
* type CustomSession = { userId: string; email: string; role: string } | null
|
|
59
|
+
* const context = getContext<CustomSession>({ userId: '123', email: 'user@example.com', role: 'admin' })
|
|
60
|
+
* // context.session is now typed as CustomSession
|
|
61
|
+
* \`\`\`
|
|
62
|
+
*/
|
|
63
|
+
export function getContext<TSession extends OpensaasSession = OpensaasSession>(session?: TSession): Context<TSession> {
|
|
64
|
+
return getOpensaasContext(config, prisma, session ?? null, storage) as Context<TSession>
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const rawOpensaasContext = getContext()
|
|
68
|
+
"
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
exports[`Generate Command Integration > Generator Integration > should generate all files for a basic config > prisma-schema 1`] = `
|
|
72
|
+
"generator client {
|
|
73
|
+
provider = "prisma-client-js"
|
|
74
|
+
output = "../.opensaas/prisma-client"
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
datasource db {
|
|
78
|
+
provider = "sqlite"
|
|
79
|
+
url = env("DATABASE_URL")
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
model User {
|
|
83
|
+
id String @id @default(cuid())
|
|
84
|
+
name String
|
|
85
|
+
email String
|
|
86
|
+
createdAt DateTime @default(now())
|
|
87
|
+
updatedAt DateTime @updatedAt
|
|
88
|
+
}
|
|
89
|
+
"
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
exports[`Generate Command Integration > Generator Integration > should generate all files for a basic config > types 1`] = `
|
|
93
|
+
"/**
|
|
94
|
+
* Generated types from OpenSaas configuration
|
|
95
|
+
* DO NOT EDIT - This file is automatically generated
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
import type { Session as OpensaasSession, StorageUtils, ServerActionProps, AccessControlledDB } from '@opensaas/stack-core'
|
|
99
|
+
import type { PrismaClient } from './prisma-client'
|
|
100
|
+
|
|
101
|
+
export type User = {
|
|
102
|
+
id: string
|
|
103
|
+
name: string
|
|
104
|
+
email: string
|
|
105
|
+
createdAt: Date
|
|
106
|
+
updatedAt: Date
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type UserCreateInput = {
|
|
110
|
+
name: string
|
|
111
|
+
email: string
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type UserUpdateInput = {
|
|
115
|
+
name?: string
|
|
116
|
+
email?: string
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export type UserWhereInput = {
|
|
120
|
+
id?: string
|
|
121
|
+
AND?: Array<UserWhereInput>
|
|
122
|
+
OR?: Array<UserWhereInput>
|
|
123
|
+
NOT?: UserWhereInput
|
|
124
|
+
name?: { equals?: string, not?: string }
|
|
125
|
+
email?: { equals?: string, not?: string }
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type Context<TSession extends OpensaasSession = OpensaasSession> = {
|
|
129
|
+
db: AccessControlledDB<PrismaClient>
|
|
130
|
+
session: TSession
|
|
131
|
+
prisma: PrismaClient
|
|
132
|
+
storage: StorageUtils
|
|
133
|
+
serverAction: (props: ServerActionProps) => Promise<unknown>
|
|
134
|
+
}"
|
|
135
|
+
`;
|
|
136
|
+
|
|
137
|
+
exports[`Generate Command Integration > Generator Integration > should generate consistent output across multiple runs > consistent-output 1`] = `
|
|
138
|
+
"generator client {
|
|
139
|
+
provider = "prisma-client-js"
|
|
140
|
+
output = "../.opensaas/prisma-client"
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
datasource db {
|
|
144
|
+
provider = "sqlite"
|
|
145
|
+
url = env("DATABASE_URL")
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
model User {
|
|
149
|
+
id String @id @default(cuid())
|
|
150
|
+
name String?
|
|
151
|
+
createdAt DateTime @default(now())
|
|
152
|
+
updatedAt DateTime @updatedAt
|
|
153
|
+
}
|
|
154
|
+
"
|
|
155
|
+
`;
|
|
156
|
+
|
|
157
|
+
exports[`Generate Command Integration > Generator Integration > should handle different database providers > mysql-provider 1`] = `
|
|
158
|
+
"generator client {
|
|
159
|
+
provider = "prisma-client-js"
|
|
160
|
+
output = "../.opensaas/prisma-client"
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
datasource db {
|
|
164
|
+
provider = "mysql"
|
|
165
|
+
url = env("DATABASE_URL")
|
|
166
|
+
}
|
|
167
|
+
"
|
|
168
|
+
`;
|
|
169
|
+
|
|
170
|
+
exports[`Generate Command Integration > Generator Integration > should handle different database providers > postgresql-provider 1`] = `
|
|
171
|
+
"generator client {
|
|
172
|
+
provider = "prisma-client-js"
|
|
173
|
+
output = "../.opensaas/prisma-client"
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
datasource db {
|
|
177
|
+
provider = "postgresql"
|
|
178
|
+
url = env("DATABASE_URL")
|
|
179
|
+
}
|
|
180
|
+
"
|
|
181
|
+
`;
|
|
182
|
+
|
|
183
|
+
exports[`Generate Command Integration > Generator Integration > should handle different database providers > sqlite-provider 1`] = `
|
|
184
|
+
"generator client {
|
|
185
|
+
provider = "prisma-client-js"
|
|
186
|
+
output = "../.opensaas/prisma-client"
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
datasource db {
|
|
190
|
+
provider = "sqlite"
|
|
191
|
+
url = env("DATABASE_URL")
|
|
192
|
+
}
|
|
193
|
+
"
|
|
194
|
+
`;
|
|
195
|
+
|
|
196
|
+
exports[`Generate Command Integration > Generator Integration > should handle empty lists config > empty-lists-schema 1`] = `
|
|
197
|
+
"generator client {
|
|
198
|
+
provider = "prisma-client-js"
|
|
199
|
+
output = "../.opensaas/prisma-client"
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
datasource db {
|
|
203
|
+
provider = "sqlite"
|
|
204
|
+
url = env("DATABASE_URL")
|
|
205
|
+
}
|
|
206
|
+
"
|
|
207
|
+
`;
|
|
208
|
+
|
|
209
|
+
exports[`Generate Command Integration > Generator Integration > should handle empty lists config > empty-lists-types 1`] = `
|
|
210
|
+
"/**
|
|
211
|
+
* Generated types from OpenSaas configuration
|
|
212
|
+
* DO NOT EDIT - This file is automatically generated
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
import type { Session as OpensaasSession, StorageUtils, ServerActionProps, AccessControlledDB } from '@opensaas/stack-core'
|
|
216
|
+
import type { PrismaClient } from './prisma-client'
|
|
217
|
+
|
|
218
|
+
export type Context<TSession extends OpensaasSession = OpensaasSession> = {
|
|
219
|
+
db: AccessControlledDB<PrismaClient>
|
|
220
|
+
session: TSession
|
|
221
|
+
prisma: PrismaClient
|
|
222
|
+
storage: StorageUtils
|
|
223
|
+
serverAction: (props: ServerActionProps) => Promise<unknown>
|
|
224
|
+
}"
|
|
225
|
+
`;
|
|
226
|
+
|
|
227
|
+
exports[`Generate Command Integration > Generator Integration > should overwrite existing files > overwrite-after 1`] = `
|
|
228
|
+
"generator client {
|
|
229
|
+
provider = "prisma-client-js"
|
|
230
|
+
output = "../.opensaas/prisma-client"
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
datasource db {
|
|
234
|
+
provider = "sqlite"
|
|
235
|
+
url = env("DATABASE_URL")
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
model Post {
|
|
239
|
+
id String @id @default(cuid())
|
|
240
|
+
title String?
|
|
241
|
+
createdAt DateTime @default(now())
|
|
242
|
+
updatedAt DateTime @updatedAt
|
|
243
|
+
}
|
|
244
|
+
"
|
|
245
|
+
`;
|
|
246
|
+
|
|
247
|
+
exports[`Generate Command Integration > Generator Integration > should overwrite existing files > overwrite-before 1`] = `
|
|
248
|
+
"generator client {
|
|
249
|
+
provider = "prisma-client-js"
|
|
250
|
+
output = "../.opensaas/prisma-client"
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
datasource db {
|
|
254
|
+
provider = "sqlite"
|
|
255
|
+
url = env("DATABASE_URL")
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
model User {
|
|
259
|
+
id String @id @default(cuid())
|
|
260
|
+
name String?
|
|
261
|
+
createdAt DateTime @default(now())
|
|
262
|
+
updatedAt DateTime @updatedAt
|
|
263
|
+
}
|
|
264
|
+
"
|
|
265
|
+
`;
|