@ingenyus/swarm-wasp 0.1.0 → 0.2.1
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/README.md +229 -21
- package/dist/.tsbuildinfo +1 -1
- package/dist/common/filesystem.d.ts +0 -14
- package/dist/common/filesystem.d.ts.map +1 -1
- package/dist/common/filesystem.js +123 -0
- package/dist/common/index.d.ts +0 -1
- package/dist/common/index.d.ts.map +1 -1
- package/dist/common/index.js +366 -0
- package/dist/common/prisma.js +140 -0
- package/dist/common/schemas.d.ts +8 -42
- package/dist/common/schemas.d.ts.map +1 -1
- package/dist/common/schemas.js +54 -0
- package/dist/common/templates.js +52 -0
- package/dist/generators/action/action-generator.d.ts +16 -29
- package/dist/generators/action/action-generator.d.ts.map +1 -1
- package/dist/generators/action/action-generator.js +1425 -0
- package/dist/generators/action/index.js +1425 -0
- package/dist/generators/action/schema.d.ts +11 -23
- package/dist/generators/action/schema.d.ts.map +1 -1
- package/dist/generators/action/schema.js +115 -0
- package/dist/generators/api/api-generator.d.ts +19 -26
- package/dist/generators/api/api-generator.d.ts.map +1 -1
- package/dist/generators/api/api-generator.js +1104 -0
- package/dist/generators/api/index.js +1104 -0
- package/dist/generators/api/schema.d.ts +13 -21
- package/dist/generators/api/schema.d.ts.map +1 -1
- package/dist/generators/api/schema.js +117 -0
- package/dist/generators/api-namespace/api-namespace-generator.d.ts +10 -17
- package/dist/generators/api-namespace/api-namespace-generator.d.ts.map +1 -1
- package/dist/generators/api-namespace/api-namespace-generator.js +1028 -0
- package/dist/generators/api-namespace/index.js +1028 -0
- package/dist/generators/api-namespace/schema.d.ts +4 -12
- package/dist/generators/api-namespace/schema.d.ts.map +1 -1
- package/dist/generators/api-namespace/schema.js +89 -0
- package/dist/generators/base/{entity-generator.base.d.ts → component-generator.base.d.ts} +9 -9
- package/dist/generators/base/component-generator.base.d.ts.map +1 -0
- package/dist/generators/base/component-generator.base.js +931 -0
- package/dist/generators/base/index.d.ts +1 -1
- package/dist/generators/base/index.d.ts.map +1 -1
- package/dist/generators/base/index.js +1330 -0
- package/dist/generators/base/operation-generator.base.d.ts +12 -3
- package/dist/generators/base/operation-generator.base.d.ts.map +1 -1
- package/dist/generators/base/operation-generator.base.js +1331 -0
- package/dist/generators/base/wasp-generator.base.d.ts +2 -1
- package/dist/generators/base/wasp-generator.base.d.ts.map +1 -1
- package/dist/generators/base/wasp-generator.base.js +706 -0
- package/dist/generators/config/config-generator.d.ts +7 -4
- package/dist/generators/config/config-generator.d.ts.map +1 -1
- package/dist/generators/config/config-generator.js +0 -0
- package/dist/generators/config/index.js +596 -0
- package/dist/generators/config/wasp-config-generator.d.ts +1 -1
- package/dist/generators/config/wasp-config-generator.d.ts.map +1 -1
- package/dist/generators/config/wasp-config-generator.js +596 -0
- package/dist/generators/crud/crud-generator.d.ts +34 -22
- package/dist/generators/crud/crud-generator.d.ts.map +1 -1
- package/dist/generators/crud/crud-generator.js +1550 -0
- package/dist/generators/crud/index.js +1550 -0
- package/dist/generators/crud/schema.d.ts +25 -18
- package/dist/generators/crud/schema.d.ts.map +1 -1
- package/dist/generators/crud/schema.js +133 -0
- package/dist/generators/feature/feature-generator.d.ts +20 -0
- package/dist/generators/feature/feature-generator.d.ts.map +1 -0
- package/dist/generators/feature/feature-generator.js +765 -0
- package/dist/generators/feature/index.d.ts +2 -0
- package/dist/generators/feature/index.d.ts.map +1 -0
- package/dist/generators/feature/index.js +765 -0
- package/dist/generators/feature/schema.d.ts +5 -0
- package/dist/generators/feature/schema.d.ts.map +1 -0
- package/dist/generators/feature/schema.js +86 -0
- package/dist/generators/index.d.ts +1 -1
- package/dist/generators/index.d.ts.map +1 -1
- package/dist/generators/index.js +2211 -0
- package/dist/generators/job/index.js +1099 -0
- package/dist/generators/job/job-generator.d.ts +12 -23
- package/dist/generators/job/job-generator.d.ts.map +1 -1
- package/dist/generators/job/job-generator.js +1099 -0
- package/dist/generators/job/schema.d.ts +6 -18
- package/dist/generators/job/schema.d.ts.map +1 -1
- package/dist/generators/job/schema.js +152 -0
- package/dist/generators/query/index.js +1425 -0
- package/dist/generators/query/query-generator.d.ts +16 -29
- package/dist/generators/query/query-generator.d.ts.map +1 -1
- package/dist/generators/query/query-generator.js +1425 -0
- package/dist/generators/query/schema.d.ts +11 -23
- package/dist/generators/query/schema.d.ts.map +1 -1
- package/dist/generators/query/schema.js +115 -0
- package/dist/generators/route/index.js +1038 -0
- package/dist/generators/route/route-generator.d.ts +11 -20
- package/dist/generators/route/route-generator.d.ts.map +1 -1
- package/dist/generators/route/route-generator.js +1038 -0
- package/dist/generators/route/schema.d.ts +5 -15
- package/dist/generators/route/schema.d.ts.map +1 -1
- package/dist/generators/route/schema.js +90 -0
- package/dist/index.d.ts +2 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1980 -2115
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/wasp.d.ts +3 -0
- package/dist/plugins/wasp.d.ts.map +1 -0
- package/dist/types/constants.d.ts +4 -22
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/constants.js +8 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +8 -2
- package/dist/wasp-config/app.d.ts +2 -1
- package/dist/wasp-config/app.d.ts.map +1 -1
- package/dist/wasp-config/app.js +357 -0
- package/dist/wasp-config/index.js +357 -0
- package/dist/wasp-config/stubs/index.js +48 -0
- package/package.json +5 -14
- package/dist/common/plugin.d.ts +0 -2
- package/dist/common/plugin.d.ts.map +0 -1
- package/dist/generators/args.types.d.ts +0 -85
- package/dist/generators/args.types.d.ts.map +0 -1
- package/dist/generators/base/entity-generator.base.d.ts.map +0 -1
- package/dist/generators/feature-directory/feature-directory-generator.d.ts +0 -18
- package/dist/generators/feature-directory/feature-directory-generator.d.ts.map +0 -1
- package/dist/generators/feature-directory/index.d.ts +0 -2
- package/dist/generators/feature-directory/index.d.ts.map +0 -1
- package/dist/generators/feature-directory/schema.d.ts +0 -8
- package/dist/generators/feature-directory/schema.d.ts.map +0 -1
- package/dist/plugin.d.ts +0 -6
- package/dist/plugin.d.ts.map +0 -1
- /package/dist/generators/{feature-directory → feature}/templates/feature.wasp.eta +0 -0
package/README.md
CHANGED
|
@@ -1,34 +1,242 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Genyus/swarm/HEAD/docs/images/swarm-logo-horizontal-dark.svg">
|
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Genyus/swarm/HEAD/docs/images/swarm-logo-horizontal.svg">
|
|
5
|
+
<img alt="Swarm - Typescript Code Generator" src="https://raw.githubusercontent.com/Genyus/swarm/HEAD/docs/images/swarm-logo-horizontal.svg" width="350" style="max-width: 100%;">
|
|
6
|
+
</picture>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
1
9
|
# @ingenyus/swarm-wasp
|
|
2
10
|
|
|
3
|
-
|
|
11
|
+
A [Swarm](../swarm/README.md) plugin that provides a set of tools for accelerated [Wasp](https://wasp.sh) app development.
|
|
12
|
+
|
|
13
|
+
## Table of Contents
|
|
14
|
+
|
|
15
|
+
- [Getting Started](#getting-started)
|
|
16
|
+
- [Features](#features)
|
|
17
|
+
- [Wasp Improvements](#wasp-improvements)
|
|
18
|
+
- [MCP Integration](#mcp-integration)
|
|
19
|
+
|
|
20
|
+
## Getting Started
|
|
21
|
+
|
|
22
|
+
This package is part of the Swarm monorepo. See the main [README](../../README.md) for development setup instructions.
|
|
23
|
+
|
|
24
|
+
Install the plugin:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @ingenyus/swarm @ingenyus/swarm-wasp
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Configuration
|
|
31
|
+
|
|
32
|
+
The plugin can be configured via the `swarm.config.json` file, or by the `swarm` block in `package.json` as follows:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"plugins": [
|
|
37
|
+
{
|
|
38
|
+
"import": "wasp",
|
|
39
|
+
"from": "@ingenyus/swarm-wasp"
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
To disable the plugin or any provided generators, set the `disabled` property (`false` by default) on the relevant object:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"plugins": [
|
|
50
|
+
{
|
|
51
|
+
"import": "wasp",
|
|
52
|
+
"from": "@ingenyus/swarm-wasp",
|
|
53
|
+
"disabled": false,
|
|
54
|
+
"generators": {
|
|
55
|
+
"api": {
|
|
56
|
+
"disabled": true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Features
|
|
65
|
+
|
|
66
|
+
### Component Generators
|
|
67
|
+
|
|
68
|
+
This plugin provides generators to create feature directories and boilerplate code for all documented Wasp components (API endpoints and namespaces, CRUD operations, Actions, Queries, Routes and Jobs). Generator output is fully type-safe and compatible with your Prisma schema and all generators are exposed by the core framework as both CLI commands and MCP tools.
|
|
69
|
+
|
|
70
|
+
For complete generator documentation including MCP tool names, CLI command syntax, and all available options, see [GENERATORS.md](./docs/GENERATORS.md).
|
|
71
|
+
|
|
72
|
+
### Custom Templates
|
|
73
|
+
|
|
74
|
+
Swarm uses a templating system built on the [Eta](https://eta.js.org/) templating engine, with access to generator context variables and support for custom overrides. To override a built-in template with a custom, simply create a .eta template under `.swarm/templates/wasp` suffixed with the same templates path used internally by the generator, e.g. to override the crud template, the override would be positioned at `.swarm/templates/wasp/crud/page.eta`:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
.swarm/templates/wasp/
|
|
78
|
+
├── api/
|
|
79
|
+
│ └── api.eta
|
|
80
|
+
├── crud/
|
|
81
|
+
│ └── crud.eta
|
|
82
|
+
└── route/
|
|
83
|
+
└── page.eta
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Wasp Improvements
|
|
87
|
+
|
|
88
|
+
The Wasp plugin provides a number of improvements to standard Wasp functionality:
|
|
89
|
+
|
|
90
|
+
### Enhanced Configuration
|
|
91
|
+
|
|
92
|
+
**Wasp:** Requires a single, monolithic `main.wasp` (or `main.wasp.ts`) file that defines all Wasp components for the application
|
|
93
|
+
|
|
94
|
+
**Swarm:** Only supports a `main.wasp.ts` file for application-level configuration, with additional `feature.wasp.ts` files that configure Wasp components for a single feature directory, positioning declarations with the relevant application features. Swarm provides an extended `App` class with fluent helper methods for more concise, readable configuration files and even sorts helper method calls for easier scanning.
|
|
95
|
+
|
|
96
|
+
`main.wasp.ts`:
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { App } from "@ingenyus/swarm-wasp";
|
|
100
|
+
|
|
101
|
+
const app = await App.create("my-app", {
|
|
102
|
+
title: "My Application",
|
|
103
|
+
wasp: { version: "^0.18.1" },
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
app
|
|
107
|
+
.auth({ method: "email" })
|
|
108
|
+
.client({
|
|
109
|
+
rootComponent: {
|
|
110
|
+
importDefault: "Layout",
|
|
111
|
+
from: "@src/shared/client/components/Layout",
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
export default app;
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
`feature.wasp.ts`:
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
import { App } from "@ingenyus/swarm-wasp";
|
|
122
|
+
|
|
123
|
+
export default function configureFeature(app: App, feature: string): void {
|
|
124
|
+
app
|
|
125
|
+
// Action definitions
|
|
126
|
+
.addAction(feature, "createTask", {
|
|
127
|
+
entities: ["Task"],
|
|
128
|
+
auth: true,
|
|
129
|
+
})
|
|
130
|
+
.addAction(feature, "updateTask", {
|
|
131
|
+
entities: ["Task"],
|
|
132
|
+
auth: true,
|
|
133
|
+
})
|
|
134
|
+
// API definitions
|
|
135
|
+
.addApi(feature, "getTasks", {
|
|
136
|
+
method: "GET",
|
|
137
|
+
route: "undefined",
|
|
138
|
+
entities: ["Task"],
|
|
139
|
+
auth: true,
|
|
140
|
+
customMiddleware: true,
|
|
141
|
+
})
|
|
142
|
+
// CRUD definitions
|
|
143
|
+
.addCrud(feature, "Tasks", {
|
|
144
|
+
entity: "Task",
|
|
145
|
+
get: {
|
|
146
|
+
isPublic: true
|
|
147
|
+
},
|
|
148
|
+
getAll: {
|
|
149
|
+
isPublic: true
|
|
150
|
+
},
|
|
151
|
+
create: {
|
|
152
|
+
override: true
|
|
153
|
+
},
|
|
154
|
+
update: {
|
|
155
|
+
override: true
|
|
156
|
+
},
|
|
157
|
+
})
|
|
158
|
+
// Query definitions
|
|
159
|
+
.addQuery(feature, "getUserTasks", {
|
|
160
|
+
entities: ["Task"],
|
|
161
|
+
auth: true,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Available Methods
|
|
167
|
+
|
|
168
|
+
- `.addRoute()` - Simplified route creation with automatic component imports
|
|
169
|
+
- `.addApi()` - API endpoint creation with middleware support
|
|
170
|
+
- `.addCrud()` - CRUD operations with custom overrides
|
|
171
|
+
- `.addAction()` - Action creation with entity access
|
|
172
|
+
- `.addQuery()` - Query creation with authentication
|
|
173
|
+
- `.addJob()` - Background job creation with cron scheduling
|
|
174
|
+
- `.addApiNamespace()` - API namespace creation with middleware
|
|
175
|
+
|
|
176
|
+
#### :warning: Typescript Configuration
|
|
177
|
+
|
|
178
|
+
By default, Wasp only supports a monolithic `main.wasp.ts` file, but Swarm enables this to be broken up into multiple files. This is preconfigured if you're using the [Swarm Wasp Starter](https://github.com/Genyus/swarm-wasp-starter), but if you're configuring Swarm in your own project, you must first make the following change to `tsconfig.wasp.json`:
|
|
179
|
+
|
|
180
|
+
```diff
|
|
181
|
+
- "include": ["main.wasp.ts"]
|
|
182
|
+
+ "include": ["main.wasp.ts", "src/**/feature.wasp.ts"]
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Clean Directory Structure
|
|
186
|
+
|
|
187
|
+
**Wasp:** Doesn't recommend any particular structure
|
|
188
|
+
|
|
189
|
+
**Swarm:** Imposes a feature-based structure, with self-contained feature directories holding client- and server-side components, plus Wasp configuration files
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
src/
|
|
193
|
+
├── features/
|
|
194
|
+
│ └── <feature-name>/
|
|
195
|
+
│ ├── feature.wasp.ts # Feature-level Wasp configuration
|
|
196
|
+
│ ├── client/
|
|
197
|
+
│ │ └── components/ # General components
|
|
198
|
+
│ │ └── pages/ # Page components
|
|
199
|
+
│ └── server/
|
|
200
|
+
│ ├── actions/ # Actions
|
|
201
|
+
│ ├── apis/ # API Endpoints
|
|
202
|
+
│ ├── cruds/ # CRUD Operations
|
|
203
|
+
│ ├── jobs/ # Background Jobs
|
|
204
|
+
│ ├── middleware/ # API Middleware
|
|
205
|
+
│ └── queries/ # Queries
|
|
206
|
+
├── shared/
|
|
207
|
+
│ ├── client/
|
|
208
|
+
│ │ ├── components/ # Shared React components
|
|
209
|
+
│ │ ├── hooks/ # Custom React hooks
|
|
210
|
+
│ │ └── lib/ # Utility functions
|
|
211
|
+
│ └── server/
|
|
212
|
+
│ └── middleware/ # Global middleware
|
|
4
213
|
|
|
5
|
-
|
|
214
|
+
├── main.wasp.ts # Application-level Wasp configuration
|
|
215
|
+
└── schema.prisma # Database schema
|
|
216
|
+
```
|
|
6
217
|
|
|
7
|
-
|
|
218
|
+
### Consistent File Structure
|
|
8
219
|
|
|
9
|
-
|
|
10
|
-
- **Command**: CLI command implementation
|
|
11
|
-
- **MCP Tools**: MCP server tools for IDE integration
|
|
12
|
-
- **Templates**: Wasp-specific templates bundled with the plugin
|
|
220
|
+
**Wasp:** Recommends monolithic files like `actions.ts` and `queries.ts` that contain multiple instances
|
|
13
221
|
|
|
14
|
-
|
|
222
|
+
**Swarm:** Maintains a component-per-file pattern for Wasp (back-end) components. This keeps component files smaller, more readable and consistent with front-end components.
|
|
15
223
|
|
|
16
|
-
|
|
17
|
-
- **API**: API endpoint generation
|
|
18
|
-
- **CRUD**: CRUD operation generation
|
|
19
|
-
- **Route**: Route generation
|
|
20
|
-
- **Job**: Background job generation
|
|
21
|
-
- **Operation**: Query and action generation
|
|
22
|
-
- **API Namespace**: API namespace and middleware generation
|
|
224
|
+
## MCP Integration
|
|
23
225
|
|
|
24
|
-
|
|
226
|
+
Swarm automatically exposes all generators as MCP tools for AI-assisted development. To configure your preferred AI tool, see the [MCP Configuration Guide](../swarm/docs/MCP_CONFIGURATION.md).
|
|
25
227
|
|
|
26
|
-
|
|
228
|
+
### Example AI Prompts
|
|
27
229
|
|
|
28
|
-
|
|
230
|
+
Once MCP is configured, you can use prompts like:
|
|
29
231
|
|
|
30
|
-
|
|
232
|
+
```
|
|
233
|
+
"Create a user management feature with a route to a dashboard page, a daily job to mark users haven't logged in for 30 days as inactive, and user CRUD operations where getting users or a single user are public operations, but without the delete operation enabled"
|
|
234
|
+
```
|
|
31
235
|
|
|
32
|
-
|
|
236
|
+
```
|
|
237
|
+
"Generate an authenticated API endpoint for getting filtered user tasks"
|
|
238
|
+
```
|
|
33
239
|
|
|
34
|
-
|
|
240
|
+
```
|
|
241
|
+
"Add a new stats page to the dashboard that will retrieve stats via the getUserStats query, requiring authentication"
|
|
242
|
+
```
|