@yrest/cli 0.11.0 → 0.11.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 +96 -24
- package/assets/svg/0..1.svg +3 -0
- package/assets/svg/0..n.svg +3 -0
- package/assets/svg/1..1.svg +3 -0
- package/assets/svg/1..n.svg +3 -0
- package/assets/svg/n.svg +3 -0
- package/dist/cli/index.js +226 -83
- package/dist/cli/index.mjs +226 -83
- package/dist/index.d.mts +69 -3
- package/dist/index.d.ts +69 -3
- package/dist/index.js +228 -78
- package/dist/index.mjs +228 -78
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
[](https://github.com/aggiovato/yRest/actions)
|
|
11
11
|
[](https://www.npmjs.com/package/@yrest/cli)
|
|
12
12
|
[](https://www.typescriptlang.org/)
|
|
13
|
-
[](https://socket.dev/npm/package/@yrest/cli)
|
|
14
14
|
|
|
15
15
|
YAML-powered json-server alternative. Zero-config REST API mock server with full CRUD, relations, filters and snapshots from a `db.yml` file.
|
|
16
16
|
|
|
@@ -241,26 +241,59 @@ posts:
|
|
|
241
241
|
|
|
242
242
|
Each top-level key becomes a resource with full CRUD endpoints.
|
|
243
243
|
|
|
244
|
+
Alternatively, collections can be grouped under a `_data` block:
|
|
245
|
+
|
|
246
|
+
```yaml
|
|
247
|
+
_data:
|
|
248
|
+
users:
|
|
249
|
+
- id: 1
|
|
250
|
+
name: Ana
|
|
251
|
+
posts:
|
|
252
|
+
- id: 1
|
|
253
|
+
title: First post
|
|
254
|
+
userId: 1
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Both formats are equivalent. You can also mix them — if the same collection name appears both inside `_data` and at the root level, the root-level entry wins. The file is persisted in whichever format it was originally written.
|
|
258
|
+
|
|
244
259
|
---
|
|
245
260
|
|
|
246
261
|
## Field annotations (`_schema`)
|
|
247
262
|
|
|
248
263
|
Add a `_schema` block to `db.yml` to declare field-level metadata per collection. Used by the OpenAPI generator to produce accurate schemas — has no effect on runtime CRUD behavior.
|
|
249
264
|
|
|
265
|
+
All keys inside `_schema` field objects use the `_` prefix convention. Two shorthand strings are also accepted at the field level:
|
|
266
|
+
|
|
250
267
|
```yaml
|
|
251
268
|
_schema:
|
|
252
269
|
users:
|
|
253
|
-
name: required # shorthand
|
|
270
|
+
name: required # shorthand → { _required: true }
|
|
254
271
|
email:
|
|
255
|
-
|
|
256
|
-
|
|
272
|
+
_required: true
|
|
273
|
+
_type: string
|
|
274
|
+
_format: email
|
|
275
|
+
_minLength: 5
|
|
276
|
+
_maxLength: 100
|
|
257
277
|
age:
|
|
258
|
-
|
|
278
|
+
_type: integer
|
|
279
|
+
_minimum: 0
|
|
280
|
+
_maximum: 150
|
|
281
|
+
_nullable: true
|
|
259
282
|
role:
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
283
|
+
_type: string
|
|
284
|
+
_enum: [admin, editor, viewer]
|
|
285
|
+
_default: viewer
|
|
286
|
+
_description: User role
|
|
287
|
+
tags:
|
|
288
|
+
_type: array
|
|
289
|
+
_items:
|
|
290
|
+
_type: string
|
|
291
|
+
_minItems: 1
|
|
292
|
+
_uniqueItems: true
|
|
293
|
+
createdAt:
|
|
294
|
+
_type: string
|
|
295
|
+
_format: date-time
|
|
296
|
+
_readOnly: true
|
|
264
297
|
|
|
265
298
|
users:
|
|
266
299
|
- id: 1
|
|
@@ -270,14 +303,53 @@ users:
|
|
|
270
303
|
role: admin
|
|
271
304
|
```
|
|
272
305
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
|
276
|
-
|
|
|
277
|
-
| `
|
|
278
|
-
| `
|
|
279
|
-
| `
|
|
280
|
-
| `
|
|
306
|
+
**Core**
|
|
307
|
+
|
|
308
|
+
| Key | Type | Description |
|
|
309
|
+
| -------------- | --------- | ----------------------------------------------------------------------------------------- |
|
|
310
|
+
| `_required` | `boolean` | Marks the field as required in the OpenAPI schema |
|
|
311
|
+
| `_type` | `string` | Overrides the inferred type (`string`, `integer`, `number`, `boolean`, `array`, `object`) |
|
|
312
|
+
| `_format` | `string` | OpenAPI format hint (`email`, `date`, `date-time`, `uuid`, `uri`, …) |
|
|
313
|
+
| `_enum` | `array` | Restricts the field to a fixed set of values |
|
|
314
|
+
| `_description` | `string` | Field description included in the OpenAPI schema |
|
|
315
|
+
| `_default` | `any` | Default value shown in the OpenAPI schema |
|
|
316
|
+
| `_example` | `any` | Example value shown in the OpenAPI schema |
|
|
317
|
+
| `_nullable` | `boolean` | Allows the field to be `null` |
|
|
318
|
+
|
|
319
|
+
**String constraints**
|
|
320
|
+
|
|
321
|
+
| Key | Type | Description |
|
|
322
|
+
| ------------ | -------- | ------------------------------------ |
|
|
323
|
+
| `_minLength` | `number` | Minimum string length |
|
|
324
|
+
| `_maxLength` | `number` | Maximum string length |
|
|
325
|
+
| `_pattern` | `string` | Regex pattern the value must satisfy |
|
|
326
|
+
|
|
327
|
+
**Number / integer constraints**
|
|
328
|
+
|
|
329
|
+
| Key | Type | Description |
|
|
330
|
+
| ------------------- | -------- | ----------------------------- |
|
|
331
|
+
| `_minimum` | `number` | Inclusive lower bound |
|
|
332
|
+
| `_maximum` | `number` | Inclusive upper bound |
|
|
333
|
+
| `_exclusiveMinimum` | `number` | Exclusive lower bound |
|
|
334
|
+
| `_exclusiveMaximum` | `number` | Exclusive upper bound |
|
|
335
|
+
| `_multipleOf` | `number` | Value must be a multiple of N |
|
|
336
|
+
|
|
337
|
+
**Array constraints**
|
|
338
|
+
|
|
339
|
+
| Key | Type | Description |
|
|
340
|
+
| -------------- | --------- | ------------------------------------------------------------ |
|
|
341
|
+
| `_minItems` | `number` | Minimum number of array items |
|
|
342
|
+
| `_maxItems` | `number` | Maximum number of array items |
|
|
343
|
+
| `_uniqueItems` | `boolean` | All items must be unique |
|
|
344
|
+
| `_items` | `object` | Schema for array items — accepts `_type`, `_format`, `_enum` |
|
|
345
|
+
|
|
346
|
+
**OpenAPI meta**
|
|
347
|
+
|
|
348
|
+
| Key | Type | Description |
|
|
349
|
+
| ------------- | --------- | --------------------------------------- |
|
|
350
|
+
| `_deprecated` | `boolean` | Marks the field as deprecated |
|
|
351
|
+
| `_readOnly` | `boolean` | Field is read-only (excluded from POST) |
|
|
352
|
+
| `_writeOnly` | `boolean` | Field is write-only (excluded from GET) |
|
|
281
353
|
|
|
282
354
|
Fields not listed in `_schema` are inferred from the first items in the collection and treated as optional. `_schema` itself is excluded from the generated REST resources.
|
|
283
355
|
|
|
@@ -722,14 +794,14 @@ when:
|
|
|
722
794
|
- body.role: superadmin
|
|
723
795
|
```
|
|
724
796
|
|
|
725
|
-
Condition keys use dot-notation to address request data:
|
|
797
|
+
Condition keys use dot-notation to address request data. Both bare and `_`-prefixed forms are accepted:
|
|
726
798
|
|
|
727
|
-
| Prefix
|
|
728
|
-
|
|
|
729
|
-
| `body.X`
|
|
730
|
-
| `params.X`
|
|
731
|
-
| `query.X`
|
|
732
|
-
| `headers.X` | `headers.x-api-key` | `req.headers["x-api-key"]` |
|
|
799
|
+
| Prefix | Example | Resolves to |
|
|
800
|
+
| -------------------------- | ------------------- | -------------------------- |
|
|
801
|
+
| `body.X` / `_body.X` | `body.email` | `req.body.email` |
|
|
802
|
+
| `params.X` / `_params.X` | `params.id` | `req.params.id` |
|
|
803
|
+
| `query.X` / `_query.X` | `query.page` | `req.query.page` |
|
|
804
|
+
| `headers.X` / `_headers.X` | `headers.x-api-key` | `req.headers["x-api-key"]` |
|
|
733
805
|
|
|
734
806
|
Field operator suffixes (`_ne`, `_like`, `_start`, `_regex`, `_gte`, `_lte`) work on condition keys exactly as they do on query params:
|
|
735
807
|
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="80" height="80" viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M75 40C75 59.33 59.33 75 40 75C20.67 75 5 59.33 5 40C5 20.67 20.67 5 40 5C59.33 5 75 20.67 75 40ZM23 57C24.6569 57 26 55.6569 26 54V43H33.3781C34.7102 48.1757 39.4085 52 45 52C50.5915 52 55.2898 48.1757 56.6219 43H66C67.6569 43 69 41.6569 69 40C69 38.3431 67.6569 37 66 37H56.6219C55.2898 31.8243 50.5915 28 45 28C39.4085 28 34.7102 31.8243 33.3781 37H26V26C26 24.3431 24.6569 23 23 23C21.3431 23 20 24.3431 20 26V37H15C13.3431 37 12 38.3431 12 40C12 41.6569 13.3431 43 15 43H20V54C20 55.6569 21.3431 57 23 57ZM51 40C51 41.0929 50.7078 42.1175 50.1973 43C49.1599 44.7934 47.2208 46 45 46C42.7792 46 40.8401 44.7934 39.8027 43C39.2922 42.1175 39 41.0929 39 40C39 38.9071 39.2922 37.8825 39.8027 37C40.8401 35.2066 42.7792 34 45 34C47.2208 34 49.1599 35.2066 50.1973 37C50.7078 37.8825 51 38.9071 51 40Z" fill="black"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="80" height="80" viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM17 42.9025C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025H32.9862L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L45.4091 36.8818L45.4036 36.9025H45.445L45.4091 36.8818C46.7819 31.7662 51.4511 28 57 28C62.579 28 67.2687 31.8072 68.6129 36.9652C69.9758 37.2481 71 38.4557 71 39.9025C71 41.331 70.0017 42.5262 68.6647 42.8286C67.3931 48.091 62.6531 52 57 52C51.3734 52 46.6513 48.1276 45.3534 42.9025H44.9862L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17ZM62.1397 36.9025C61.0891 35.163 59.1804 34 57 34C54.8196 34 52.9109 35.163 51.8603 36.9025C51.3142 37.8067 51 38.8667 51 40C51 41.0529 51.2712 42.0424 51.7475 42.9025C52.7704 44.7496 54.7392 46 57 46C59.2608 46 61.2296 44.7496 62.2525 42.9025C62.7288 42.0424 63 41.0529 63 40C63 38.8667 62.6858 37.8067 62.1397 36.9025Z" fill="black"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="80" height="80" viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M75 40C75 59.33 59.33 75 40 75C20.67 75 5 59.33 5 40C5 20.67 20.67 5 40 5C59.33 5 75 20.67 75 40ZM41 26C41 24.3431 39.6569 23 38 23C36.3431 23 35 24.3431 35 26V37H26V26C26 24.3431 24.6569 23 23 23C21.3431 23 20 24.3431 20 26V37H15C13.3431 37 12 38.3431 12 40C12 41.6569 13.3431 43 15 43H20V54C20 55.6569 21.3431 57 23 57C24.6569 57 26 55.6569 26 54V43H35V54C35 55.6569 36.3431 57 38 57C39.6569 57 41 55.6569 41 54V43H66C67.6569 43 69 41.6569 69 40C69 38.3431 67.6569 37 66 37H41V26Z" fill="black"/>
|
|
3
|
+
</svg>
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="80" height="80" viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM44.9862 42.9025L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025H32.9862L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L44.9862 36.9025H46V26C46 24.3431 47.3431 23 49 23C50.6569 23 52 24.3431 52 26V36.9025H68C69.6569 36.9025 71 38.2457 71 39.9025C71 41.5594 69.6569 42.9025 68 42.9025H52V53C52 54.6569 50.6569 56 49 56C47.3431 56 46 54.6569 46 53V42.9025H44.9862Z" fill="black"/>
|
|
3
|
+
</svg>
|
package/assets/svg/n.svg
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<svg width="80" height="80" viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path fill-rule="evenodd" clip-rule="evenodd" d="M40 75C59.33 75 75 59.33 75 40C75 20.67 59.33 5 40 5C20.67 5 5 20.67 5 40C5 59.33 20.67 75 40 75ZM17 36.9025H33.0677L15.5981 26.5986C14.1632 25.7702 13.6716 23.9354 14.5 22.5005C15.3284 21.0656 17.1632 20.574 18.5981 21.4024L44.9862 36.9025H68C69.6569 36.9025 71 38.2457 71 39.9025C71 41.5594 69.6569 42.9025 68 42.9025H44.9862L18.6801 58.0904C17.2452 58.9188 15.4105 58.4272 14.582 56.9923C13.7536 55.5574 14.2452 53.7227 15.6801 52.8942L32.9862 42.9025H17C15.3431 42.9025 14 41.5594 14 39.9025C14 38.2457 15.3431 36.9025 17 36.9025Z" fill="black"/>
|
|
3
|
+
</svg>
|