nuxt-feathers-zod 6.3.0 → 6.3.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/README.md +126 -245
- package/dist/module.json +1 -1
- package/dist/module.mjs +71 -41
- package/dist/runtime/composables/feathers.d.ts +4 -3
- package/dist/runtime/composables/feathers.js +6 -4
- package/dist/runtime/composables/useAuth.d.ts +1 -1
- package/dist/runtime/composables/useAuth.js +36 -6
- package/dist/runtime/options/authentication/index.d.ts +7 -3
- package/dist/runtime/options/authentication/index.js +63 -11
- package/dist/runtime/options/client/index.d.ts +22 -0
- package/dist/runtime/options/client/index.js +54 -6
- package/dist/runtime/options/index.d.ts +29 -4
- package/dist/runtime/options/index.js +73 -50
- package/dist/runtime/options/mode.d.ts +8 -0
- package/dist/runtime/options/mode.js +21 -0
- package/dist/runtime/options/server.d.ts +57 -3
- package/dist/runtime/options/server.js +159 -3
- package/dist/runtime/options/services.js +9 -1
- package/dist/runtime/options/templates.d.ts +28 -0
- package/dist/runtime/options/templates.js +29 -0
- package/dist/runtime/options/transports/websocket.d.ts +13 -1
- package/dist/runtime/options/transports/websocket.js +5 -3
- package/dist/runtime/plugins/feathers-auth.d.ts +3 -0
- package/dist/runtime/plugins/feathers-auth.js +14 -9
- package/dist/runtime/plugins/keycloak-sso.js +10 -5
- package/dist/runtime/server/modules/express/body-parser.d.ts +1 -0
- package/dist/runtime/server/modules/express/body-parser.js +26 -0
- package/dist/runtime/server/modules/express/compression.d.ts +1 -0
- package/dist/runtime/server/modules/express/compression.js +19 -0
- package/dist/runtime/server/modules/express/cors.d.ts +1 -0
- package/dist/runtime/server/modules/express/cors.js +19 -0
- package/dist/runtime/server/modules/express/healthcheck.d.ts +1 -0
- package/dist/runtime/server/modules/express/healthcheck.js +17 -0
- package/dist/runtime/server/modules/express/helmet.d.ts +1 -0
- package/dist/runtime/server/modules/express/helmet.js +19 -0
- package/dist/runtime/server/modules/express/rate-limit.d.ts +1 -0
- package/dist/runtime/server/modules/express/rate-limit.js +31 -0
- package/dist/runtime/server/modules/express/secure-defaults.d.ts +1 -0
- package/dist/runtime/server/modules/express/secure-defaults.js +65 -0
- package/dist/runtime/server/modules/express/serve-static.d.ts +1 -0
- package/dist/runtime/server/modules/express/serve-static.js +17 -0
- package/dist/runtime/server/modules/koa/body-parser.d.ts +1 -0
- package/dist/runtime/server/modules/koa/body-parser.js +16 -0
- package/dist/runtime/server/modules/koa/compression.d.ts +1 -0
- package/dist/runtime/server/modules/koa/compression.js +18 -0
- package/dist/runtime/server/modules/koa/cors.d.ts +1 -0
- package/dist/runtime/server/modules/koa/cors.js +18 -0
- package/dist/runtime/server/modules/koa/healthcheck.d.ts +1 -0
- package/dist/runtime/server/modules/koa/healthcheck.js +21 -0
- package/dist/runtime/server/modules/koa/helmet.d.ts +1 -0
- package/dist/runtime/server/modules/koa/helmet.js +18 -0
- package/dist/runtime/server/modules/koa/rate-limit.d.ts +1 -0
- package/dist/runtime/server/modules/koa/rate-limit.js +31 -0
- package/dist/runtime/server/modules/koa/secure-defaults.d.ts +1 -0
- package/dist/runtime/server/modules/koa/secure-defaults.js +74 -0
- package/dist/runtime/server/modules/koa/serve-static.d.ts +1 -0
- package/dist/runtime/server/modules/koa/serve-static.js +24 -0
- package/dist/runtime/services.js +0 -1
- package/dist/runtime/stores/auth.d.ts +4 -4
- package/dist/runtime/stores/auth.js +19 -9
- package/dist/runtime/templates/client/authentication.js +6 -2
- package/dist/runtime/templates/client/client.js +3 -1
- package/dist/runtime/templates/client/connection.js +90 -9
- package/dist/runtime/templates/client/index.js +7 -8
- package/dist/runtime/templates/client/plugin.js +226 -9
- package/dist/runtime/templates/overrides.d.ts +16 -0
- package/dist/runtime/templates/overrides.js +50 -0
- package/dist/runtime/templates/server/app.d.ts +2 -0
- package/dist/runtime/templates/server/app.js +67 -0
- package/dist/runtime/templates/server/authentication.js +25 -0
- package/dist/runtime/templates/server/index.js +12 -0
- package/dist/runtime/templates/server/plugin.js +39 -62
- package/dist/runtime/templates/server/secure-defaults.d.ts +2 -0
- package/dist/runtime/templates/server/secure-defaults.js +63 -0
- package/dist/runtime/templates/server/server.js +15 -1
- package/dist/runtime/utils/auth.d.ts +12 -0
- package/dist/runtime/utils/auth.js +30 -0
- package/dist/runtime/utils/config.d.ts +40 -0
- package/dist/runtime/utils/config.js +29 -0
- package/package.json +21 -7
- package/src/cli/commands/doctor.ts +356 -0
- package/src/cli/core.ts +2846 -0
- package/src/cli/index.ts +373 -1069
- package/src/runtime/server/modules/express/body-parser.ts +35 -0
- package/src/runtime/server/modules/express/compression.ts +23 -0
- package/src/runtime/server/modules/express/cors.ts +23 -0
- package/src/runtime/server/modules/express/healthcheck.ts +22 -0
- package/src/runtime/server/modules/express/helmet.ts +23 -0
- package/src/runtime/server/modules/express/rate-limit.ts +39 -0
- package/src/runtime/server/modules/express/secure-defaults.ts +80 -0
- package/src/runtime/server/modules/express/serve-static.ts +22 -0
- package/src/runtime/server/modules/koa/body-parser.ts +20 -0
- package/src/runtime/server/modules/koa/compression.ts +22 -0
- package/src/runtime/server/modules/koa/cors.ts +22 -0
- package/src/runtime/server/modules/koa/healthcheck.ts +26 -0
- package/src/runtime/server/modules/koa/helmet.ts +22 -0
- package/src/runtime/server/modules/koa/rate-limit.ts +39 -0
- package/src/runtime/server/modules/koa/secure-defaults.ts +92 -0
- package/src/runtime/server/modules/koa/serve-static.ts +29 -0
package/README.md
CHANGED
|
@@ -1,312 +1,193 @@
|
|
|
1
|
-
# nuxt-feathers-zod
|
|
2
|
-
[guide](https://vevedh.github.io/nuxt-feathers-zod/)
|
|
1
|
+
# nuxt-feathers-zod
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
[Documentation](https://vevedh.github.io/nuxt-feathers-zod/)
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
`nuxt-feathers-zod` is a Nuxt 4 module that integrates **FeathersJS v5 (Dove)** with a **CLI-first** workflow and a Zod-oriented service generation approach.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
It supports two main usage patterns:
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
- **embedded mode**: a Feathers server runs inside Nuxt/Nitro
|
|
10
|
+
- **remote mode**: a Nuxt app uses a Feathers client against an external API
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## What is already in the open source core
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
- Nuxt 4 + Nitro integration
|
|
15
|
+
- embedded and remote modes
|
|
16
|
+
- REST and Socket.IO transports
|
|
17
|
+
- embedded server with **Express** or **Koa**
|
|
18
|
+
- CLI bootstrap for `init embedded`, `init remote`, `init templates`
|
|
19
|
+
- CLI service generation with `add service`
|
|
20
|
+
- adapter-less service generation with `add service --custom`
|
|
21
|
+
- remote-service registration with `add remote-service`
|
|
22
|
+
- local/JWT auth flows
|
|
23
|
+
- Keycloak SSO bridge
|
|
24
|
+
- optional legacy Swagger support
|
|
25
|
+
- template overrides
|
|
26
|
+
- embedded server modules
|
|
27
|
+
- client-side helpers with Pinia / feathers-pinia support
|
|
15
28
|
|
|
16
|
-
|
|
17
|
-
* WebSocket (Socket.IO)
|
|
18
|
-
* Validation **Zod-first**
|
|
19
|
-
* Authentification **Local + JWT**
|
|
20
|
-
* Adapters (MongoDB, Memory, etc.)
|
|
21
|
-
* Swagger legacy (optionnel)
|
|
22
|
-
* Composables client (`useService`, `useAuth`, stores Pinia)
|
|
23
|
-
|
|
24
|
-
👉 Il **n’y a pas de backend séparé** : Feathers est monté **dans Nuxt**.
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
## 2. Pré-requis
|
|
29
|
-
|
|
30
|
-
* **Bun** (recommandé et supporté)
|
|
31
|
-
* **Node.js ≥ 18**
|
|
32
|
-
* **Nuxt 4**
|
|
33
|
-
* MongoDB (optionnel mais recommandé)
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## 3. Création du projet Nuxt 4
|
|
29
|
+
## Installation
|
|
38
30
|
|
|
39
31
|
```bash
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
bun install
|
|
43
|
-
bun run dev
|
|
32
|
+
bun add nuxt-feathers-zod feathers-pinia
|
|
33
|
+
bun add -D @pinia/nuxt
|
|
44
34
|
```
|
|
45
35
|
|
|
46
|
-
|
|
36
|
+
Optional Swagger dependencies:
|
|
47
37
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
38
|
+
```bash
|
|
39
|
+
bun add feathers-swagger swagger-ui-dist
|
|
40
|
+
```
|
|
51
41
|
|
|
52
|
-
|
|
42
|
+
## Recommended quick start — new Nuxt 4 app in embedded mode
|
|
53
43
|
|
|
54
44
|
```bash
|
|
45
|
+
bunx nuxi@latest init my-nfz-app
|
|
46
|
+
cd my-nfz-app
|
|
47
|
+
bun install
|
|
55
48
|
bun add nuxt-feathers-zod feathers-pinia
|
|
49
|
+
bun add -D @pinia/nuxt
|
|
50
|
+
bunx nuxt-feathers-zod init embedded --force
|
|
51
|
+
bunx nuxt-feathers-zod add service users
|
|
52
|
+
bun dev
|
|
56
53
|
```
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
## Embedded mode with local auth
|
|
59
56
|
|
|
60
57
|
```bash
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
> ⚠️ **Cette configuration est critique**.
|
|
71
|
-
> Une mauvaise initialisation provoque des erreurs bloquantes au démarrage.
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
export default defineNuxtConfig({
|
|
75
|
-
modules: ['nuxt-feathers-zod'],
|
|
76
|
-
|
|
77
|
-
feathers: {
|
|
78
|
-
/**
|
|
79
|
-
* RÈGLE D’OR :
|
|
80
|
-
* Le module scanne UNIQUEMENT ces dossiers
|
|
81
|
-
*/
|
|
82
|
-
servicesDirs: ['services'],
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Transports
|
|
86
|
-
*/
|
|
87
|
-
transports: {
|
|
88
|
-
rest: {
|
|
89
|
-
path: '/feathers',
|
|
90
|
-
framework: 'koa',
|
|
91
|
-
},
|
|
92
|
-
websocket: true,
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Base de données (MongoDB recommandé)
|
|
97
|
-
*/
|
|
98
|
-
database: {
|
|
99
|
-
mongo: {
|
|
100
|
-
url: 'mongodb://127.0.0.1:27017/my-site',
|
|
101
|
-
},
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Authentification
|
|
106
|
-
*/
|
|
107
|
-
auth: true,
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Swagger legacy (optionnel)
|
|
111
|
-
*/
|
|
112
|
-
swagger: false,
|
|
113
|
-
},
|
|
114
|
-
})
|
|
58
|
+
bunx nuxi@latest init my-nfz-auth
|
|
59
|
+
cd my-nfz-auth
|
|
60
|
+
bun install
|
|
61
|
+
bun add nuxt-feathers-zod feathers-pinia feathers-swagger swagger-ui-dist
|
|
62
|
+
bun add -D @pinia/nuxt
|
|
63
|
+
bunx nuxt-feathers-zod init embedded --force --auth --swagger
|
|
64
|
+
bunx nuxt-feathers-zod add service users --auth --adapter mongodb --collection users --idField _id --docs
|
|
65
|
+
bun dev
|
|
115
66
|
```
|
|
116
67
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
## 6. RÈGLE FONDAMENTALE – À NE JAMAIS VIOLER
|
|
120
|
-
|
|
121
|
-
> ❌ **Ne jamais créer un service manuellement**
|
|
122
|
-
> ✅ **Toujours utiliser la CLI officielle**
|
|
123
|
-
|
|
124
|
-
Cette règle est **imposée par le code interne du module**.
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
## 7. Création du premier service : `users` (OBLIGATOIRE)
|
|
68
|
+
## Remote mode quick start
|
|
129
69
|
|
|
130
70
|
```bash
|
|
131
|
-
bunx
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
71
|
+
bunx nuxi@latest init my-nfz-remote
|
|
72
|
+
cd my-nfz-remote
|
|
73
|
+
bun install
|
|
74
|
+
bun add nuxt-feathers-zod feathers-pinia
|
|
75
|
+
bun add -D @pinia/nuxt
|
|
76
|
+
bunx nuxt-feathers-zod init remote --url https://api.example.com --transport socketio --force
|
|
77
|
+
bunx nuxt-feathers-zod add remote-service users --path users --methods find,get,create,patch,remove
|
|
78
|
+
bun dev
|
|
136
79
|
```
|
|
137
80
|
|
|
138
|
-
|
|
81
|
+
## Canonical CLI commands
|
|
139
82
|
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
83
|
+
```bash
|
|
84
|
+
bunx nuxt-feathers-zod init embedded --force
|
|
85
|
+
bunx nuxt-feathers-zod init remote --url https://api.example.com --transport rest --force
|
|
86
|
+
bunx nuxt-feathers-zod add service users --adapter mongodb --collection users --idField _id
|
|
87
|
+
bunx nuxt-feathers-zod add service actions --custom --methods find --customMethods run,preview
|
|
88
|
+
bunx nuxt-feathers-zod add remote-service users --path users --methods find,get
|
|
89
|
+
bunx nuxt-feathers-zod doctor
|
|
146
90
|
```
|
|
147
91
|
|
|
148
|
-
|
|
92
|
+
## Open source core boundary
|
|
149
93
|
|
|
150
|
-
|
|
151
|
-
* Cette classe est **recherchée dynamiquement** dans les exports scannés
|
|
152
|
-
* Sans ce service :
|
|
94
|
+
The project is being stabilized around a predictable **standard open source core**.
|
|
153
95
|
|
|
154
|
-
|
|
155
|
-
* `Entity class User not found in services imports`
|
|
156
|
-
* **Boot impossible**
|
|
96
|
+
That core currently includes:
|
|
157
97
|
|
|
158
|
-
|
|
98
|
+
- runtime + transports
|
|
99
|
+
- auth basics
|
|
100
|
+
- CLI generation
|
|
101
|
+
- template overrides
|
|
102
|
+
- server modules
|
|
103
|
+
- docs and playground validation
|
|
159
104
|
|
|
160
|
-
|
|
105
|
+
Potential future **license-key / Pro** candidates are intentionally kept outside that frozen core, such as advanced visual consoles, premium diagnostics, builders, enterprise presets, and packaged RBAC/policy layers.
|
|
161
106
|
|
|
162
|
-
##
|
|
107
|
+
## Development commands
|
|
163
108
|
|
|
164
109
|
```bash
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
110
|
+
bun install
|
|
111
|
+
bun run build
|
|
112
|
+
bun run typecheck
|
|
113
|
+
bun run docs:dev
|
|
114
|
+
bun run docs:build
|
|
170
115
|
```
|
|
171
116
|
|
|
172
|
-
Structure :
|
|
173
117
|
|
|
174
|
-
|
|
175
|
-
services/articles/
|
|
176
|
-
articles.ts
|
|
177
|
-
articles.class.ts
|
|
178
|
-
articles.schema.ts
|
|
179
|
-
articles.shared.ts
|
|
180
|
-
```
|
|
118
|
+
## Quality gates
|
|
181
119
|
|
|
182
|
-
|
|
120
|
+
The repository includes a standard open-source CI workflow on GitHub Actions.
|
|
121
|
+
It validates the main surfaces of the module:
|
|
183
122
|
|
|
184
|
-
|
|
123
|
+
- install dependencies with Bun
|
|
124
|
+
- lint the repository
|
|
125
|
+
- run the template sanity check
|
|
126
|
+
- build the Nuxt module
|
|
127
|
+
- build the playground application
|
|
128
|
+
- build the VitePress documentation
|
|
185
129
|
|
|
186
|
-
|
|
187
|
-
bun run dev
|
|
188
|
-
```
|
|
130
|
+
The workflow file is located at `.github/workflows/ci.yml`.
|
|
189
131
|
|
|
190
|
-
|
|
132
|
+
## Release process
|
|
191
133
|
|
|
192
|
-
|
|
193
|
-
curl -X POST http://localhost:3000/feathers/users \
|
|
194
|
-
-H "Content-Type: application/json" \
|
|
195
|
-
-d '{"userId":"demo","password":"demo123"}'
|
|
196
|
-
```
|
|
134
|
+
The repository now includes two GitHub Actions workflows:
|
|
197
135
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
```bash
|
|
201
|
-
curl -X POST http://localhost:3000/feathers/authentication \
|
|
202
|
-
-H "Content-Type: application/json" \
|
|
203
|
-
-d '{"strategy":"local","userId":"demo","password":"demo123"}'
|
|
204
|
-
```
|
|
136
|
+
- `.github/workflows/ci.yml` for the standard open-source validation gates
|
|
137
|
+
- `.github/workflows/publish.yml` for validated npm publication on tag or manual trigger
|
|
205
138
|
|
|
206
|
-
|
|
139
|
+
Manual release checklist:
|
|
207
140
|
|
|
208
141
|
```bash
|
|
209
|
-
|
|
210
|
-
|
|
142
|
+
bun install
|
|
143
|
+
bun run lint
|
|
144
|
+
bun run sanity:templates
|
|
145
|
+
bun run prepare
|
|
146
|
+
bun run build
|
|
147
|
+
bun run docs:build
|
|
148
|
+
npm pack --dry-run
|
|
211
149
|
```
|
|
212
150
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
## 10. Swagger legacy (optionnel)
|
|
216
|
-
|
|
217
|
-
### 10.1 Activer Swagger
|
|
151
|
+
Then publish with either:
|
|
218
152
|
|
|
219
|
-
```
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
153
|
+
```bash
|
|
154
|
+
npm version patch
|
|
155
|
+
npm publish --access public
|
|
223
156
|
```
|
|
224
157
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
* UI :
|
|
228
|
-
`http://localhost:3000/feathers/docs/`
|
|
229
|
-
* Spec :
|
|
230
|
-
`http://localhost:3000/feathers/swagger.json`
|
|
231
|
-
|
|
232
|
-
### ⚠️ Important
|
|
233
|
-
|
|
234
|
-
Dans l’UI Swagger, la spec doit être définie manuellement à :
|
|
158
|
+
or:
|
|
235
159
|
|
|
160
|
+
```bash
|
|
161
|
+
npm version prerelease --preid beta
|
|
162
|
+
npm publish --tag beta --access public
|
|
236
163
|
```
|
|
237
|
-
../swagger.json
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
(C’est un comportement connu et assumé du module.)
|
|
241
|
-
|
|
242
|
-
---
|
|
243
164
|
|
|
244
|
-
|
|
165
|
+
Public documentation builds intentionally exclude internal guide pages such as `open-core` and `playground` in production builds.
|
|
245
166
|
|
|
246
|
-
|
|
167
|
+
## Publishing to npm
|
|
247
168
|
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
await context.app.service('users').create({
|
|
256
|
-
userId: 'admin',
|
|
257
|
-
password: 'admin123',
|
|
258
|
-
})
|
|
259
|
-
await next()
|
|
260
|
-
},
|
|
261
|
-
],
|
|
262
|
-
})
|
|
263
|
-
})
|
|
169
|
+
```bash
|
|
170
|
+
npm login
|
|
171
|
+
bun install
|
|
172
|
+
bun run build
|
|
173
|
+
npm pack --dry-run
|
|
174
|
+
npm version patch
|
|
175
|
+
npm publish --access public
|
|
264
176
|
```
|
|
265
177
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
---
|
|
269
|
-
|
|
270
|
-
## 12. Erreurs courantes et causes réelles
|
|
271
|
-
|
|
272
|
-
### ❌ `Services typeExports []`
|
|
273
|
-
|
|
274
|
-
Causes :
|
|
275
|
-
|
|
276
|
-
* `servicesDirs` incorrect
|
|
277
|
-
* services créés manuellement
|
|
278
|
-
* fichiers mal nommés (`users.ts` manquant)
|
|
279
|
-
|
|
280
|
-
### ❌ `Entity class User not found in services imports`
|
|
281
|
-
|
|
282
|
-
Cause exacte :
|
|
283
|
-
|
|
284
|
-
* le service `users` n’existe pas ou n’a pas été généré via la CLI
|
|
285
|
-
|
|
286
|
-
✅ Solution universelle :
|
|
178
|
+
For a beta release:
|
|
287
179
|
|
|
288
180
|
```bash
|
|
289
|
-
|
|
181
|
+
npm version prerelease --preid beta
|
|
182
|
+
npm publish --tag beta --access public
|
|
290
183
|
```
|
|
291
184
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
## 13. Bonnes pratiques figées
|
|
295
|
-
|
|
296
|
-
* ✅ **Toujours** générer les services avec la CLI
|
|
297
|
-
* ✅ `services/<name>/<name>.ts` obligatoire
|
|
298
|
-
* ✅ Zod-first (`*.schema.ts`)
|
|
299
|
-
* ❌ Pas de création manuelle
|
|
300
|
-
* ❌ Pas de renommage arbitraire de `User`
|
|
301
|
-
* ❌ Pas de déplacement hors `servicesDirs`
|
|
185
|
+
## Notes
|
|
302
186
|
|
|
303
|
-
|
|
187
|
+
- The recommended convention is `servicesDirs: ['services']`.
|
|
188
|
+
- The recommended path is **CLI-first**.
|
|
189
|
+
- Historical aliases may remain supported for backward compatibility, but the public docs only foreground the canonical forms.
|
|
304
190
|
|
|
305
|
-
##
|
|
191
|
+
## License
|
|
306
192
|
|
|
307
|
-
|
|
308
|
-
2. `bun add nuxt-feathers-zod feathers-pinia`
|
|
309
|
-
3. `servicesDirs: ['services']`
|
|
310
|
-
4. `bunx nuxt-feathers-zod add service users`
|
|
311
|
-
5. `bunx nuxt-feathers-zod add service <business>`
|
|
312
|
-
6. `bun run dev`
|
|
193
|
+
MIT
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { defineNuxtModule, createResolver, addImportsDir, addTemplate, addServerPlugin, addImports, addPlugin, hasNuxtModule
|
|
2
|
+
import { defineNuxtModule, createResolver, addImportsDir, addTemplate, addServerPlugin, addImports, addPlugin, hasNuxtModule } from '@nuxt/kit';
|
|
3
3
|
import { consola } from 'consola';
|
|
4
4
|
import defu from 'defu';
|
|
5
5
|
import { resolveOptions, resolveRuntimeConfig, resolvePublicRuntimeConfig } from '../dist/runtime/options/index.js';
|
|
6
|
+
import { detectResolvedMode, isResolvedServerEnabled, isResolvedRemoteAuthEnabled } from '../dist/runtime/options/mode.js';
|
|
6
7
|
import { serverDefaults } from '../dist/runtime/options/server.js';
|
|
7
8
|
import { getServicesImports, addServicesImports } from '../dist/runtime/services.js';
|
|
8
9
|
import { getClientTemplates } from '../dist/runtime/templates/client/index.js';
|
|
10
|
+
import { resolveTemplateOverrideForFilename } from '../dist/runtime/templates/overrides.js';
|
|
9
11
|
import { getServerTemplates } from '../dist/runtime/templates/server/index.js';
|
|
10
12
|
|
|
11
13
|
function setAliases(options, nuxt) {
|
|
@@ -15,7 +17,9 @@ function setAliases(options, nuxt) {
|
|
|
15
17
|
"nuxt-feathers-zod/validators": resolver.resolve("runtime/zod/validators"),
|
|
16
18
|
"nuxt-feathers-zod/query": resolver.resolve("runtime/zod/query"),
|
|
17
19
|
"nuxt-feathers-zod/zod": resolver.resolve("runtime/zod/index"),
|
|
18
|
-
"nuxt-feathers-zod/options": resolver.resolve("runtime/options")
|
|
20
|
+
"nuxt-feathers-zod/options": resolver.resolve("runtime/options"),
|
|
21
|
+
"nuxt-feathers-zod/auth-utils": resolver.resolve("runtime/utils/auth"),
|
|
22
|
+
"nuxt-feathers-zod/config-utils": resolver.resolve("runtime/utils/config")
|
|
19
23
|
};
|
|
20
24
|
nuxt.options.alias = defu(nuxt.options.alias, aliases);
|
|
21
25
|
if (options.client)
|
|
@@ -26,44 +30,56 @@ function setAliases(options, nuxt) {
|
|
|
26
30
|
}
|
|
27
31
|
function setTsIncludes(options, nuxt) {
|
|
28
32
|
const resolver = createResolver(import.meta.url);
|
|
29
|
-
const servicesDirs = options.servicesDirs.map((dir) => resolver.resolve(dir, "**/*.ts"));
|
|
33
|
+
const servicesDirs = (options.servicesDirs || []).map((dir) => resolver.resolve(dir, "**/*.ts"));
|
|
34
|
+
const serverModuleDirs = Array.isArray(options.server?.moduleDirs) ? options.server.moduleDirs : options.server?.moduleDirs ? [String(options.server.moduleDirs)] : [];
|
|
35
|
+
const serverModulesGlobs = serverModuleDirs.map((dir) => resolver.resolve(dir, "*.ts"));
|
|
36
|
+
const includeGlobs = [...servicesDirs, ...serverModulesGlobs];
|
|
30
37
|
nuxt.hook("prepare:types", async ({ tsConfig }) => {
|
|
31
|
-
tsConfig.include?.push(...
|
|
38
|
+
tsConfig.include?.push(...includeGlobs);
|
|
32
39
|
});
|
|
33
40
|
nuxt.hook("nitro:config", (nitroConfig) => {
|
|
34
|
-
nitroConfig.typescript
|
|
41
|
+
nitroConfig.typescript = nitroConfig.typescript || {};
|
|
42
|
+
nitroConfig.typescript.tsConfig = nitroConfig.typescript.tsConfig || {};
|
|
43
|
+
nitroConfig.typescript.tsConfig.include = nitroConfig.typescript.tsConfig.include || [];
|
|
44
|
+
nitroConfig.typescript.tsConfig.include.push(...includeGlobs);
|
|
35
45
|
});
|
|
36
46
|
}
|
|
37
|
-
async function
|
|
47
|
+
async function ensurePinia(client, nuxt) {
|
|
48
|
+
const piniaEnabled = client.pinia !== false && Boolean(client.pinia);
|
|
49
|
+
if (!piniaEnabled)
|
|
50
|
+
return;
|
|
51
|
+
const active = hasNuxtModule("@pinia/nuxt");
|
|
52
|
+
if (active)
|
|
53
|
+
return;
|
|
54
|
+
const require = createRequire(import.meta.url);
|
|
38
55
|
const storesDirs = client.pinia?.storesDirs;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
56
|
+
const storesHint = storesDirs?.length ? ` (storesDirs: ${JSON.stringify(storesDirs)})` : "";
|
|
57
|
+
try {
|
|
58
|
+
require.resolve("@pinia/nuxt", { paths: [nuxt.options.rootDir] });
|
|
59
|
+
nuxt.options.modules = nuxt.options.modules || [];
|
|
60
|
+
if (!nuxt.options.modules.includes("@pinia/nuxt")) {
|
|
61
|
+
nuxt.options.modules.push("@pinia/nuxt");
|
|
62
|
+
consola.info("[nuxt-feathers-zod] Added @pinia/nuxt to Nuxt modules because feathers.client.pinia is enabled.");
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
consola.warn(
|
|
66
|
+
`[nuxt-feathers-zod] feathers.client.pinia is enabled but @pinia/nuxt is not installed.${storesHint} Install it manually: bun add -D @pinia/nuxt and add '@pinia/nuxt' to your app modules.`
|
|
67
|
+
);
|
|
43
68
|
}
|
|
44
|
-
if (!hasNuxtModule("@pinia/nuxt"))
|
|
45
|
-
await installModule("@pinia/nuxt");
|
|
46
69
|
}
|
|
47
70
|
const module$1 = defineNuxtModule({
|
|
71
|
+
moduleDependencies: {},
|
|
48
72
|
meta: {
|
|
49
73
|
name: "nuxt-feathers-zod",
|
|
50
74
|
configKey: "feathers",
|
|
51
|
-
compatibility: {
|
|
52
|
-
nuxt: "^4.0.0"
|
|
53
|
-
}
|
|
75
|
+
compatibility: { nuxt: "^4.0.0" }
|
|
54
76
|
},
|
|
55
|
-
// Default configuration options of the Nuxt module
|
|
56
77
|
defaults: {
|
|
57
|
-
transports: {
|
|
58
|
-
websocket: true
|
|
59
|
-
},
|
|
78
|
+
transports: { websocket: true },
|
|
60
79
|
server: serverDefaults,
|
|
61
80
|
client: true,
|
|
62
81
|
servicesDirs: ["services"],
|
|
63
|
-
validator: {
|
|
64
|
-
formats: [],
|
|
65
|
-
extendDefaults: true
|
|
66
|
-
},
|
|
82
|
+
validator: { formats: [], extendDefaults: true },
|
|
67
83
|
loadFeathersConfig: false,
|
|
68
84
|
auth: true,
|
|
69
85
|
swagger: false
|
|
@@ -71,11 +87,13 @@ const module$1 = defineNuxtModule({
|
|
|
71
87
|
async setup(options, nuxt) {
|
|
72
88
|
const resolver = createResolver(import.meta.url);
|
|
73
89
|
const resolvedOptions = await resolveOptions(options, nuxt);
|
|
90
|
+
const mode = detectResolvedMode(resolvedOptions);
|
|
91
|
+
const serverEnabled = isResolvedServerEnabled(resolvedOptions);
|
|
74
92
|
if (resolvedOptions.swagger) {
|
|
75
93
|
const require = createRequire(import.meta.url);
|
|
76
94
|
try {
|
|
77
95
|
require.resolve("feathers-swagger", { paths: [nuxt.options.rootDir] });
|
|
78
|
-
} catch
|
|
96
|
+
} catch {
|
|
79
97
|
consola.warn(
|
|
80
98
|
"feathers.swagger is enabled but 'feathers-swagger' could not be resolved from this Nuxt project. Install it in your app (root) dependencies: bun add feathers-swagger swagger-ui-dist"
|
|
81
99
|
);
|
|
@@ -83,8 +101,6 @@ const module$1 = defineNuxtModule({
|
|
|
83
101
|
}
|
|
84
102
|
nuxt.options.runtimeConfig._feathers = resolveRuntimeConfig(resolvedOptions);
|
|
85
103
|
nuxt.options.runtimeConfig.public._feathers = resolvePublicRuntimeConfig(resolvedOptions);
|
|
86
|
-
const servicesImports = await getServicesImports(resolvedOptions.servicesDirs);
|
|
87
|
-
await addServicesImports(servicesImports);
|
|
88
104
|
setAliases(resolvedOptions, nuxt);
|
|
89
105
|
setTsIncludes(resolvedOptions, nuxt);
|
|
90
106
|
if (resolvedOptions.transports.websocket) {
|
|
@@ -93,34 +109,48 @@ const module$1 = defineNuxtModule({
|
|
|
93
109
|
});
|
|
94
110
|
}
|
|
95
111
|
addImportsDir(resolver.resolve("./runtime/composables"));
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
112
|
+
if (resolvedOptions.client) {
|
|
113
|
+
await ensurePinia(resolvedOptions.client, nuxt);
|
|
114
|
+
}
|
|
115
|
+
if (mode === "embedded" && serverEnabled) {
|
|
116
|
+
const servicesImports = await getServicesImports(resolvedOptions.servicesDirs);
|
|
117
|
+
await addServicesImports(servicesImports);
|
|
118
|
+
}
|
|
119
|
+
if (serverEnabled) {
|
|
120
|
+
let serverPluginDst;
|
|
121
|
+
for (const serverTemplate of getServerTemplates(resolvedOptions)) {
|
|
122
|
+
const ov = resolveTemplateOverrideForFilename(serverTemplate.filename, resolvedOptions);
|
|
123
|
+
const tpl = addTemplate(ov ? { filename: serverTemplate.filename, src: ov.absPath, write: true, options: resolvedOptions } : { ...serverTemplate, options: resolvedOptions });
|
|
124
|
+
if (serverTemplate.filename?.endsWith("server/plugin.ts") || serverTemplate.filename?.endsWith("server/plugin"))
|
|
125
|
+
serverPluginDst = tpl.dst;
|
|
126
|
+
}
|
|
127
|
+
addServerPlugin(serverPluginDst ?? resolver.resolve(resolvedOptions.templateDir, "server/plugin.ts"));
|
|
101
128
|
}
|
|
102
|
-
addServerPlugin(serverPluginDst ?? resolver.resolve(resolvedOptions.templateDir, "server/plugin.ts"));
|
|
103
129
|
if (resolvedOptions.client) {
|
|
104
130
|
const clientOptions = resolvedOptions.client;
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
const piniaEnabled = clientOptions.pinia !== false && Boolean(clientOptions.pinia);
|
|
132
|
+
if (piniaEnabled) {
|
|
107
133
|
nuxt.hook("vite:extendConfig", (config) => {
|
|
108
|
-
config.optimizeDeps
|
|
134
|
+
config.optimizeDeps = config.optimizeDeps || {};
|
|
135
|
+
config.optimizeDeps.include = config.optimizeDeps.include || [];
|
|
136
|
+
if (!config.optimizeDeps.include.includes("feathers-pinia"))
|
|
137
|
+
config.optimizeDeps.include.push("feathers-pinia");
|
|
109
138
|
});
|
|
110
|
-
|
|
139
|
+
const enableAuthBootstrap = Boolean(
|
|
140
|
+
resolvedOptions.auth && serverEnabled || isResolvedRemoteAuthEnabled(resolvedOptions)
|
|
141
|
+
);
|
|
142
|
+
if (enableAuthBootstrap) {
|
|
111
143
|
addImports({ from: resolver.resolve("./runtime/stores/auth"), name: "useAuthStore" });
|
|
112
144
|
addPlugin({ order: 1, src: resolver.resolve("./runtime/plugins/feathers-auth") });
|
|
113
145
|
}
|
|
114
146
|
if (resolvedOptions.keycloak) {
|
|
115
147
|
addPlugin({ order: 1, src: resolver.resolve("./runtime/plugins/keycloak-sso"), mode: "client" });
|
|
116
|
-
} else if (resolvedOptions.auth) {
|
|
117
|
-
addImports({ from: resolver.resolve("./runtime/stores/auth"), name: "useAuthStore" });
|
|
118
|
-
addPlugin({ order: 1, src: resolver.resolve("./runtime/plugins/feathers-auth") });
|
|
119
148
|
}
|
|
120
149
|
}
|
|
121
150
|
let clientPluginDst;
|
|
122
151
|
for (const clientTemplate of getClientTemplates(resolvedOptions, resolver)) {
|
|
123
|
-
const
|
|
152
|
+
const ov = resolveTemplateOverrideForFilename(clientTemplate.filename, resolvedOptions);
|
|
153
|
+
const tpl = addTemplate(ov ? { filename: clientTemplate.filename, src: ov.absPath, write: true, options: resolvedOptions } : { ...clientTemplate, options: resolvedOptions });
|
|
124
154
|
if (clientTemplate.filename?.endsWith("client/plugin.ts") || clientTemplate.filename?.endsWith("client/plugin"))
|
|
125
155
|
clientPluginDst = tpl.dst;
|
|
126
156
|
}
|
|
@@ -131,7 +161,7 @@ const module$1 = defineNuxtModule({
|
|
|
131
161
|
return {
|
|
132
162
|
content: [{
|
|
133
163
|
type: "text",
|
|
134
|
-
text: JSON.stringify(resolvedOptions, null, 2)
|
|
164
|
+
text: JSON.stringify({ mode, serverEnabled, ...resolvedOptions }, null, 2)
|
|
135
165
|
}]
|
|
136
166
|
};
|
|
137
167
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { ServiceTypes } from 'nuxt-feathers-zod/client';
|
|
1
|
+
import type { ClientApplication, ServiceTypes } from 'nuxt-feathers-zod/client';
|
|
2
2
|
export declare function useFeathers(): {
|
|
3
|
-
api:
|
|
3
|
+
api: unknown;
|
|
4
|
+
client: ClientApplication;
|
|
4
5
|
};
|
|
5
|
-
export declare function useService<L extends keyof ServiceTypes>(path: L): import("@feathersjs/feathers").FeathersService<
|
|
6
|
+
export declare function useService<L extends keyof ServiceTypes>(path: L): import("@feathersjs/feathers").FeathersService<ClientApplication, ServiceTypes[ServiceTypes[L]]>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { useNuxtApp } from "#imports";
|
|
2
2
|
export function useFeathers() {
|
|
3
|
-
const
|
|
4
|
-
|
|
3
|
+
const nuxtApp = useNuxtApp();
|
|
4
|
+
const api = nuxtApp.$api;
|
|
5
|
+
const client = nuxtApp.$client ?? nuxtApp.$api;
|
|
6
|
+
return { api, client };
|
|
5
7
|
}
|
|
6
8
|
export function useService(path) {
|
|
7
|
-
const {
|
|
8
|
-
return
|
|
9
|
+
const { client } = useFeathers();
|
|
10
|
+
return client.service(String(path));
|
|
9
11
|
}
|