@yrest/cli 0.10.0 → 0.11.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 +56 -25
- 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/assets/yrest-banner.png +0 -0
- package/assets/yrest-lockup.png +0 -0
- package/assets/yrest-lockup.svg +20 -0
- package/assets/yrest-logo.png +0 -0
- package/assets/yrest-monochrome.png +0 -0
- package/dist/cli/index.js +904 -131
- package/dist/cli/index.mjs +904 -131
- package/dist/index.d.mts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +864 -81
- package/dist/index.mjs +864 -81
- package/package.json +1 -1
- package/assets/logo-color.png +0 -0
- package/assets/logo-figure.png +0 -0
- package/assets/logo-text.png +0 -0
- package/assets/logo-white.png +0 -0
- package/assets/yRest-banner.png +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="assets/
|
|
2
|
+
<img src="assets/yrest-banner.png" alt="yRest" width="100%" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
<br/>
|
|
@@ -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
|
|
|
@@ -74,6 +74,7 @@ A YAML-first alternative to json-server for frontend development.
|
|
|
74
74
|
| Programmatic API for test frameworks | ✅ | ❌ |
|
|
75
75
|
| OpenAPI 3.0 spec (`GET /_openapi`, `yrest openapi`) | ✅ | ❌ |
|
|
76
76
|
| Field annotations (`_schema`) | ✅ | ❌ |
|
|
77
|
+
| Compact relation DSL (`m2o:target@fk[card]+nested`) | ✅ | ❌ |
|
|
77
78
|
|
|
78
79
|
---
|
|
79
80
|
|
|
@@ -472,10 +473,6 @@ A child record holds a foreign key pointing to a parent. The string shorthand im
|
|
|
472
473
|
_rel:
|
|
473
474
|
posts:
|
|
474
475
|
userId: users # shorthand: many2one
|
|
475
|
-
# equivalent to:
|
|
476
|
-
# userId:
|
|
477
|
-
# type: many2one
|
|
478
|
-
# target: users
|
|
479
476
|
```
|
|
480
477
|
|
|
481
478
|
### `one2one`
|
|
@@ -486,8 +483,8 @@ One child record belongs to exactly one parent, and a parent has at most one chi
|
|
|
486
483
|
_rel:
|
|
487
484
|
profiles:
|
|
488
485
|
userId:
|
|
489
|
-
|
|
490
|
-
|
|
486
|
+
_type: one2one
|
|
487
|
+
_target: users
|
|
491
488
|
```
|
|
492
489
|
|
|
493
490
|
### `many2many`
|
|
@@ -498,11 +495,11 @@ Two collections are linked through a pivot (join) table:
|
|
|
498
495
|
_rel:
|
|
499
496
|
posts:
|
|
500
497
|
tags:
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
498
|
+
_type: many2many
|
|
499
|
+
_target: tags
|
|
500
|
+
_through: post_tags # pivot collection
|
|
501
|
+
_foreignKey: postId
|
|
502
|
+
_otherKey: tagId
|
|
506
503
|
|
|
507
504
|
post_tags:
|
|
508
505
|
- id: 1
|
|
@@ -510,31 +507,65 @@ post_tags:
|
|
|
510
507
|
tagId: 2
|
|
511
508
|
```
|
|
512
509
|
|
|
513
|
-
### Auto-embedding with `
|
|
510
|
+
### Auto-embedding with `_nested: true`
|
|
514
511
|
|
|
515
|
-
Add `
|
|
512
|
+
Add `_nested: true` to any relation to embed the related data automatically in every GET response, without needing `?_expand` or `?_embed`:
|
|
516
513
|
|
|
517
514
|
```yaml
|
|
518
515
|
_rel:
|
|
519
516
|
posts:
|
|
520
517
|
userId:
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
518
|
+
_type: many2one
|
|
519
|
+
_target: users
|
|
520
|
+
_nested: true # user object embedded in every /posts response
|
|
524
521
|
tags:
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
522
|
+
_type: many2many
|
|
523
|
+
_target: tags
|
|
524
|
+
_through: post_tags
|
|
525
|
+
_foreignKey: postId
|
|
526
|
+
_otherKey: tagId
|
|
527
|
+
_nested: true # tags array embedded in every /posts response
|
|
531
528
|
```
|
|
532
529
|
|
|
533
530
|
```
|
|
534
531
|
GET /posts/1 → { id: 1, title: "...", userId: 1, user: { ... }, tags: [...] }
|
|
535
532
|
```
|
|
536
533
|
|
|
537
|
-
`many2one` / `one2one` with `
|
|
534
|
+
`many2one` / `one2one` with `_nested: true` embed the parent object under the derived key (`userId` → `user`). The original FK field is preserved. `many2many` with `_nested: true` embeds the resolved target array under the alias key.
|
|
535
|
+
|
|
536
|
+
### Compact DSL syntax
|
|
537
|
+
|
|
538
|
+
Relations can also be declared using a compact string format — useful when you want to express type, target, foreign key and cardinality in a single line:
|
|
539
|
+
|
|
540
|
+
```yaml
|
|
541
|
+
_rel:
|
|
542
|
+
payments:
|
|
543
|
+
bookingId: "m2o:bookings[1..1->0..n]" # type:target[carDirect->carInverse]
|
|
544
|
+
userId: "m2o:users[1..1->0..n]+nested" # +nested flag auto-embeds on every GET
|
|
545
|
+
|
|
546
|
+
profiles:
|
|
547
|
+
userId: "o2o:users[1..1->1..1]"
|
|
548
|
+
|
|
549
|
+
posts:
|
|
550
|
+
authorId: "m2o:users@userId[1..1->0..n]" # @foreignKey when field name ≠ FK column
|
|
551
|
+
|
|
552
|
+
tags:
|
|
553
|
+
posts: "m2m:posts@post_tags(postId,tagId)[0..n->0..n]" # m2m with pivot
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
**Type aliases:**
|
|
557
|
+
|
|
558
|
+
| Alias | Full name |
|
|
559
|
+
| ----- | ----------- |
|
|
560
|
+
| `m2o` | `many2one` |
|
|
561
|
+
| `o2o` | `one2one` |
|
|
562
|
+
| `m2m` | `many2many` |
|
|
563
|
+
|
|
564
|
+
**Cardinality notation:** `[carDirect->carInverse]` — format `min..max` where min is `0` or `1` and max is `1` or `n`. Both segments are optional: omitting them applies defaults (`1..1->1..n` for `m2o`, `1..1->1..1` for `o2o`, `0..n->0..n` for `m2m`).
|
|
565
|
+
|
|
566
|
+
**`+nested` flag:** appended at the end of any DSL string, equivalent to `_nested: true`.
|
|
567
|
+
|
|
568
|
+
The three forms — shorthand string, compact DSL, and verbose object — are fully interchangeable and can be mixed freely within the same `_rel` block.
|
|
538
569
|
|
|
539
570
|
### What relations enable
|
|
540
571
|
|
|
@@ -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>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<svg width="314" height="123" viewBox="0 0 314 123" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
2
|
+
<path d="M0 33.1934H18.9219L41.8701 76.3274L56.5276 47.3956C56.5276 47.3956 59.2983 42.4043 61.6658 38.9502C65.6116 33.1934 69.0931 33.1934 70.0205 33.1934H89.3125C89.3125 33.1934 85.3404 33.1934 81.3936 38.2593C78.8415 41.0227 73.7342 50.4639 73.7342 50.4639L51.122 92.2745C51.122 92.2745 41.6427 111.825 30.5083 118.269C19.0562 124.896 4.49836 122.624 4.49836 122.624L4.58083 107.992C4.58083 107.992 16.0023 109.128 21.5375 105.151C27.3964 100.942 32.8293 92.2745 32.8293 92.2745L0 33.1934Z" fill="white"/>
|
|
3
|
+
<path d="M130.727 47.206C130.727 47.206 140.011 48.1271 140.011 32.9291C140.011 17.731 130.727 17.731 130.727 17.731H87.3238L67.595 17.731V0L130.727 0C130.727 0 159.74 -1.90735e-05 159.74 32.9291C159.74 65.8581 130.727 64.4765 130.727 64.4765L157.651 110.761H132.12L105.892 64.4765L83.8898 64.2463C83.8898 64.2463 87.3997 54.8052 89.9518 52.0418C93.8986 46.9759 97.4065 46.9759 97.4065 46.9759L130.727 47.206Z" fill="url(#paint0_linear_393_1348)"/>
|
|
4
|
+
<path d="M188.11 113.342C183.382 113.342 179.197 112.351 175.555 110.371C171.976 108.326 169.165 105.483 167.12 101.841C165.139 98.1345 164.149 93.7896 164.149 88.8057V87.6556C164.149 82.6717 165.139 78.3587 167.12 74.7166C169.101 71.0107 171.88 68.1673 175.459 66.1865C179.037 64.1418 183.19 63.1195 187.918 63.1195C192.583 63.1195 196.64 64.1738 200.091 66.2823C203.541 68.327 206.225 71.2023 208.142 74.9083C210.058 78.5504 211.017 82.7995 211.017 87.6556V91.7769H176.417C176.545 95.0356 177.759 97.6873 180.059 99.7319C182.359 101.777 185.171 102.799 188.493 102.799C191.88 102.799 194.372 102.064 195.969 100.595C197.567 99.1249 198.781 97.4956 199.611 95.7065L209.483 100.882C208.589 102.543 207.279 104.364 205.554 106.345C203.892 108.262 201.656 109.923 198.845 111.329C196.033 112.671 192.455 113.342 188.11 113.342ZM176.513 82.7675H198.749C198.493 80.02 197.375 77.8156 195.394 76.1543C193.477 74.493 190.953 73.6623 187.823 73.6623C184.564 73.6623 181.976 74.493 180.059 76.1543C178.142 77.8156 176.96 80.02 176.513 82.7675ZM241.51 113.342C235.312 113.342 230.232 112 226.27 109.316C222.309 106.633 219.913 102.799 219.082 97.8151L230.2 94.9397C230.647 97.1761 231.382 98.9332 232.404 100.211C233.491 101.489 234.8 102.416 236.334 102.991C237.931 103.502 239.657 103.757 241.51 103.757C244.321 103.757 246.398 103.278 247.739 102.32C249.081 101.297 249.752 100.051 249.752 98.5818C249.752 97.1122 249.113 95.994 247.835 95.2273C246.557 94.3966 244.513 93.7257 241.701 93.2145L239.018 92.7353C235.695 92.0964 232.66 91.2338 229.912 90.1475C227.165 88.9974 224.96 87.4319 223.299 85.4512C221.638 83.4704 220.807 80.9145 220.807 77.7836C220.807 73.0553 222.532 69.4452 225.983 66.9532C229.433 64.3974 233.97 63.1195 239.593 63.1195C244.896 63.1195 249.305 64.3016 252.819 66.6657C256.333 69.0299 258.634 72.1288 259.72 75.9626L248.506 79.413C247.995 76.9849 246.941 75.2597 245.343 74.2374C243.81 73.2151 241.893 72.7039 239.593 72.7039C237.292 72.7039 235.535 73.1192 234.321 73.9499C233.107 74.7166 232.5 75.8029 232.5 77.2086C232.5 78.7421 233.139 79.8922 234.417 80.659C235.695 81.3618 237.42 81.9049 239.593 82.2883L242.276 82.7675C245.854 83.4065 249.081 84.2691 251.957 85.3553C254.896 86.3777 257.196 87.8792 258.857 89.86C260.583 91.7769 261.445 94.3966 261.445 97.7192C261.445 102.703 259.624 106.569 255.982 109.316C252.404 112 247.58 113.342 241.51 113.342ZM289.302 112C286.171 112 283.615 111.042 281.635 109.125C279.718 107.144 278.759 104.524 278.759 101.265V74.4291H266.875V64.4613H278.759V49.7013H290.836V64.4613H303.87V74.4291H290.836V99.1569C290.836 101.074 291.73 102.032 293.519 102.032H302.72V112H289.302Z" fill="#1F72F5"/>
|
|
5
|
+
<path d="M71.2803 33.5454C70.3529 33.5454 66.8714 33.5454 62.9256 39.3022C60.5581 42.7563 57.7874 47.7476 57.7874 47.7476L43.1299 76.6794M71.2803 33.5454C82.6534 33.5454 119.805 33.5454 119.805 33.5454H71.2803Z" stroke="url(#paint1_linear_393_1348)" stroke-width="3.99351" stroke-linecap="round"/>
|
|
6
|
+
<circle cx="86.26" cy="33.5456" r="4.79221" fill="#3480F6"/>
|
|
7
|
+
<path d="M46.3246 78.2727C46.3246 80.9193 44.1791 83.0649 41.5324 83.0649C38.8858 83.0649 36.7402 80.9193 36.7402 78.2727C36.7402 75.626 38.8858 73.4805 41.5324 73.4805C44.1791 73.4805 46.3246 75.626 46.3246 78.2727Z" fill="#12438F"/>
|
|
8
|
+
<circle cx="119.805" cy="33.5456" r="4.79221" fill="#C9DCFB"/>
|
|
9
|
+
<defs>
|
|
10
|
+
<linearGradient id="paint0_linear_393_1348" x1="79.8701" y1="0" x2="79.8701" y2="123" gradientUnits="userSpaceOnUse">
|
|
11
|
+
<stop stop-color="#0A4EBA"/>
|
|
12
|
+
<stop offset="0.399038" stop-color="#1F72F5"/>
|
|
13
|
+
</linearGradient>
|
|
14
|
+
<linearGradient id="paint1_linear_393_1348" x1="125.396" y1="32.7467" x2="44.7273" y2="75.0779" gradientUnits="userSpaceOnUse">
|
|
15
|
+
<stop stop-color="#C9DCFB"/>
|
|
16
|
+
<stop offset="0.5" stop-color="#1F72F5"/>
|
|
17
|
+
<stop offset="1" stop-color="#12438F"/>
|
|
18
|
+
</linearGradient>
|
|
19
|
+
</defs>
|
|
20
|
+
</svg>
|
|
Binary file
|
|
Binary file
|