@yrest/cli 0.10.0 → 0.11.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 CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <img src="assets/yRest-banner.png" alt="yRest" width="100%" />
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
  [![CI](https://github.com/aggiovato/yRest/actions/workflows/ci.yml/badge.svg)](https://github.com/aggiovato/yRest/actions)
11
11
  [![Node](https://img.shields.io/node/v/@yrest/cli)](https://www.npmjs.com/package/@yrest/cli)
12
12
  [![TypeScript](https://img.shields.io/badge/TypeScript-ready-blue)](https://www.typescriptlang.org/)
13
- [![Socket](https://badge.socket.dev/npm/package/@yrest/cli/0.10.0)](https://socket.dev/npm/package/@yrest/cli)
13
+ [![Socket](https://badge.socket.dev/npm/package/@yrest/cli/0.11.0)](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
- type: one2one
490
- target: users
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
- type: many2many
502
- target: tags
503
- through: post_tags # pivot collection
504
- foreignKey: postId
505
- otherKey: tagId
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 `nested: true`
510
+ ### Auto-embedding with `_nested: true`
514
511
 
515
- Add `nested: true` to any relation to embed the related data automatically in every GET response, without needing `?_expand` or `?_embed`:
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
- type: many2one
522
- target: users
523
- nested: true # user object embedded in every /posts response
518
+ _type: many2one
519
+ _target: users
520
+ _nested: true # user object embedded in every /posts response
524
521
  tags:
525
- type: many2many
526
- target: tags
527
- through: post_tags
528
- foreignKey: postId
529
- otherKey: tagId
530
- nested: true # tags array embedded in every /posts response
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 `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.
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
 
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