@gzl10/nexus-sdk 0.4.0 → 0.5.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.
- package/README.md +73 -5
- package/dist/chunk-XEPNN6IG.js +806 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +180 -0
- package/dist/index.d.ts +76 -31
- package/dist/index.js +20 -650
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -21,7 +21,6 @@ import type { ModuleManifest, PluginAuthRequest } from '@gzl10/nexus-sdk'
|
|
|
21
21
|
|
|
22
22
|
export const tasksModule: ModuleManifest = {
|
|
23
23
|
name: 'tasks',
|
|
24
|
-
code: 'TSK',
|
|
25
24
|
label: 'Tasks',
|
|
26
25
|
icon: 'mdi:checkbox-marked-outline',
|
|
27
26
|
description: 'Task management',
|
|
@@ -88,7 +87,6 @@ import { projectsModule } from './modules/projects'
|
|
|
88
87
|
|
|
89
88
|
export const projectPlugin: PluginManifest = {
|
|
90
89
|
name: '@myorg/nexus-projects',
|
|
91
|
-
code: 'PRJ',
|
|
92
90
|
label: 'Projects',
|
|
93
91
|
icon: 'mdi:folder-outline',
|
|
94
92
|
category: 'content',
|
|
@@ -188,6 +186,77 @@ const permissions = generateCaslPermissions(postEntity)
|
|
|
188
186
|
// Returns: Array<{ role, action, subject, conditions, fields, inverted }>
|
|
189
187
|
```
|
|
190
188
|
|
|
189
|
+
## CLI (v0.5.0+)
|
|
190
|
+
|
|
191
|
+
Auto-generate code from EntityDefinitions in your modules:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
# Install globally or use npx
|
|
195
|
+
npx @gzl10/nexus-sdk generate
|
|
196
|
+
|
|
197
|
+
# Generate for all modules in src/modules
|
|
198
|
+
nexus-sdk generate --path src/modules
|
|
199
|
+
|
|
200
|
+
# Generate for specific module
|
|
201
|
+
nexus-sdk generate --module users
|
|
202
|
+
|
|
203
|
+
# Watch mode for development
|
|
204
|
+
nexus-sdk generate --watch
|
|
205
|
+
|
|
206
|
+
# Dry run (preview without writing)
|
|
207
|
+
nexus-sdk generate --dry-run --verbose
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### CLI Options
|
|
211
|
+
|
|
212
|
+
| Option | Default | Description |
|
|
213
|
+
|--------|---------|-------------|
|
|
214
|
+
| `-p, --path <dir>` | `src/modules` | Base modules directory |
|
|
215
|
+
| `-m, --module <name>` | - | Generate only specific module |
|
|
216
|
+
| `-o, --output <dir>` | `__generated__` | Output directory name |
|
|
217
|
+
| `-w, --watch` | - | Watch for changes and regenerate |
|
|
218
|
+
| `--dry-run` | - | Show what would be generated |
|
|
219
|
+
| `--skip-schemas` | - | Skip `.schemas.ts` generation |
|
|
220
|
+
| `--skip-models` | - | Skip `.models.ts` generation |
|
|
221
|
+
| `--skip-migrations` | - | Skip `.migrate.ts` generation |
|
|
222
|
+
| `--skip-casl` | - | Skip `.casl.ts` generation |
|
|
223
|
+
| `--verbose` | - | Show detailed logs |
|
|
224
|
+
|
|
225
|
+
### Generated Files
|
|
226
|
+
|
|
227
|
+
For each module with `definitions`, the CLI generates:
|
|
228
|
+
|
|
229
|
+
```text
|
|
230
|
+
src/modules/posts/
|
|
231
|
+
├── index.ts # Module manifest with definitions
|
|
232
|
+
└── __generated__/
|
|
233
|
+
├── posts.schemas.ts # Zod validation schemas
|
|
234
|
+
├── posts.models.ts # TypeScript interfaces
|
|
235
|
+
├── posts.migrate.ts # Knex migration function
|
|
236
|
+
└── posts.casl.ts # CASL permission seeds
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Module Structure
|
|
240
|
+
|
|
241
|
+
The CLI discovers modules by looking for `index.ts` files that export a `ModuleManifest` with `definitions`:
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
// src/modules/posts/index.ts
|
|
245
|
+
import type { ModuleManifest, EntityDefinition } from '@gzl10/nexus-sdk'
|
|
246
|
+
|
|
247
|
+
const postEntity: EntityDefinition = {
|
|
248
|
+
type: 'collection',
|
|
249
|
+
table: 'posts',
|
|
250
|
+
// ...
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export const postsModule: ModuleManifest = {
|
|
254
|
+
name: 'posts',
|
|
255
|
+
label: 'Posts',
|
|
256
|
+
definitions: [postEntity]
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
191
260
|
## Main Types
|
|
192
261
|
|
|
193
262
|
### Manifests & Context
|
|
@@ -237,8 +306,7 @@ const permissions = generateCaslPermissions(postEntity)
|
|
|
237
306
|
|
|
238
307
|
| Type | Description |
|
|
239
308
|
|------|-------------|
|
|
240
|
-
| `
|
|
241
|
-
| `UsersResolver` | User lookup service (`findById`, `findByIds`) |
|
|
309
|
+
| `EntityType` | Union of all entity type strings |
|
|
242
310
|
| `PaginationParams` | Pagination input (`page`, `limit`) |
|
|
243
311
|
| `PaginatedResult<T>` | Paginated response with metadata |
|
|
244
312
|
| `ValidationSchema` | Generic Zod-compatible schema interface |
|
|
@@ -254,7 +322,7 @@ The context provides access to:
|
|
|
254
322
|
- `middleware.validate()` - Request validation with Zod schemas
|
|
255
323
|
- `errors` - Error classes (`AppError`, `NotFoundError`, `UnauthorizedError`, etc.)
|
|
256
324
|
- `abilities` - CASL helpers (`subject`, `ForbiddenError`)
|
|
257
|
-
- `services` -
|
|
325
|
+
- `services` - Registered services (extensible)
|
|
258
326
|
- `events` - EventEmitter for inter-module communication
|
|
259
327
|
- `mail` - Email sending service
|
|
260
328
|
|