@yrest/cli 0.8.0 → 0.9.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 +96 -20
- package/dist/cli/index.js +808 -193
- package/dist/cli/index.mjs +808 -193
- package/dist/index.d.mts +47 -5
- package/dist/index.d.ts +47 -5
- package/dist/index.js +390 -172
- package/dist/index.mjs +390 -172
- package/package.json +4 -3
package/dist/index.d.mts
CHANGED
|
@@ -10,17 +10,59 @@ type Resource = Record<string, unknown>;
|
|
|
10
10
|
*/
|
|
11
11
|
type Data = Record<string, Resource[]>;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Canonical descriptor for a single relation declared under `_rel`.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
15
|
+
* The YAML accepts two forms that both normalise to this type:
|
|
16
|
+
* - **Shorthand string** — `userId: users` → `{ type: "many2one", target: "users" }`
|
|
17
|
+
* - **Object** — explicit `type` plus the fields required by that type.
|
|
18
|
+
*
|
|
19
|
+
* ### Types
|
|
20
|
+
* - `many2one` — (default) many children share one parent via a FK field.
|
|
21
|
+
* - `one2one` — one child belongs to one parent; `?_embed` returns a single object, not an array.
|
|
22
|
+
* - `many2many` — join through a pivot collection; the relation key is the embed alias.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // _rel:
|
|
26
|
+
* // posts:
|
|
27
|
+
* // userId: users ← shorthand many2one
|
|
28
|
+
* // tags:
|
|
29
|
+
* // type: many2many
|
|
30
|
+
* // through: post_tags
|
|
31
|
+
* // foreignKey: postId
|
|
32
|
+
* // otherKey: tagId
|
|
33
|
+
* // users:
|
|
34
|
+
* // profileId:
|
|
35
|
+
* // type: one2one
|
|
36
|
+
* // target: profiles
|
|
37
|
+
*/
|
|
38
|
+
type RelationDef = {
|
|
39
|
+
type: "many2one";
|
|
40
|
+
target: string;
|
|
41
|
+
nested?: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
type: "one2one";
|
|
44
|
+
target: string;
|
|
45
|
+
nested?: boolean;
|
|
46
|
+
} | {
|
|
47
|
+
type: "many2many";
|
|
48
|
+
target: string;
|
|
49
|
+
through: string;
|
|
50
|
+
foreignKey: string;
|
|
51
|
+
otherKey: string;
|
|
52
|
+
nested?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Relational mappings declared under `_rel` in the YAML file, normalised to {@link RelationDef}.
|
|
56
|
+
*
|
|
57
|
+
* - Outer key: source collection name (child for many2one/one2one; either side for many2many).
|
|
58
|
+
* - Inner key: FK field name (many2one/one2one) or embed alias (many2many).
|
|
59
|
+
* - Inner value: canonical {@link RelationDef}.
|
|
18
60
|
*
|
|
19
61
|
* @example
|
|
20
62
|
* // Given: _rel: { posts: { userId: users } }
|
|
21
63
|
* // GET /users/1/posts → returns posts where userId === "1"
|
|
22
64
|
*/
|
|
23
|
-
type Relations = Record<string, Record<string,
|
|
65
|
+
type Relations = Record<string, Record<string, RelationDef>>;
|
|
24
66
|
/**
|
|
25
67
|
* A static response block shared by {@link CustomRoute} and {@link Scenario}.
|
|
26
68
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -10,17 +10,59 @@ type Resource = Record<string, unknown>;
|
|
|
10
10
|
*/
|
|
11
11
|
type Data = Record<string, Resource[]>;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Canonical descriptor for a single relation declared under `_rel`.
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
* -
|
|
17
|
-
* -
|
|
15
|
+
* The YAML accepts two forms that both normalise to this type:
|
|
16
|
+
* - **Shorthand string** — `userId: users` → `{ type: "many2one", target: "users" }`
|
|
17
|
+
* - **Object** — explicit `type` plus the fields required by that type.
|
|
18
|
+
*
|
|
19
|
+
* ### Types
|
|
20
|
+
* - `many2one` — (default) many children share one parent via a FK field.
|
|
21
|
+
* - `one2one` — one child belongs to one parent; `?_embed` returns a single object, not an array.
|
|
22
|
+
* - `many2many` — join through a pivot collection; the relation key is the embed alias.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // _rel:
|
|
26
|
+
* // posts:
|
|
27
|
+
* // userId: users ← shorthand many2one
|
|
28
|
+
* // tags:
|
|
29
|
+
* // type: many2many
|
|
30
|
+
* // through: post_tags
|
|
31
|
+
* // foreignKey: postId
|
|
32
|
+
* // otherKey: tagId
|
|
33
|
+
* // users:
|
|
34
|
+
* // profileId:
|
|
35
|
+
* // type: one2one
|
|
36
|
+
* // target: profiles
|
|
37
|
+
*/
|
|
38
|
+
type RelationDef = {
|
|
39
|
+
type: "many2one";
|
|
40
|
+
target: string;
|
|
41
|
+
nested?: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
type: "one2one";
|
|
44
|
+
target: string;
|
|
45
|
+
nested?: boolean;
|
|
46
|
+
} | {
|
|
47
|
+
type: "many2many";
|
|
48
|
+
target: string;
|
|
49
|
+
through: string;
|
|
50
|
+
foreignKey: string;
|
|
51
|
+
otherKey: string;
|
|
52
|
+
nested?: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Relational mappings declared under `_rel` in the YAML file, normalised to {@link RelationDef}.
|
|
56
|
+
*
|
|
57
|
+
* - Outer key: source collection name (child for many2one/one2one; either side for many2many).
|
|
58
|
+
* - Inner key: FK field name (many2one/one2one) or embed alias (many2many).
|
|
59
|
+
* - Inner value: canonical {@link RelationDef}.
|
|
18
60
|
*
|
|
19
61
|
* @example
|
|
20
62
|
* // Given: _rel: { posts: { userId: users } }
|
|
21
63
|
* // GET /users/1/posts → returns posts where userId === "1"
|
|
22
64
|
*/
|
|
23
|
-
type Relations = Record<string, Record<string,
|
|
65
|
+
type Relations = Record<string, Record<string, RelationDef>>;
|
|
24
66
|
/**
|
|
25
67
|
* A static response block shared by {@link CustomRoute} and {@link Scenario}.
|
|
26
68
|
*/
|