@apso/cli 0.34.0 → 0.35.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.
|
@@ -10,10 +10,15 @@ import { ApsorcRelationship, Relationship, RelationshipMap, RelationshipForTempl
|
|
|
10
10
|
export declare const parseOneToMany: (relationship: ApsorcRelationship) => RelationshipMap;
|
|
11
11
|
/**
|
|
12
12
|
* Parses a ManyToOne relationship definition.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* Bidirectional by default, mirroring parseOneToMany with from/to swapped:
|
|
14
|
+
* the target entity gets the inverse OneToMany collection (and with it the
|
|
15
|
+
* controller join allowlist), so `Authors?join=books` works no matter which
|
|
16
|
+
* direction the .apsorc declared the relationship in.
|
|
17
|
+
* Set `bi_directional: false` to keep the old FK-only unidirectional shape.
|
|
18
|
+
* Self-referencing relationships stay unidirectional (both sides would
|
|
19
|
+
* collide on the same RelationshipMap key).
|
|
15
20
|
* @param relationship The .apsorc relationship definition.
|
|
16
|
-
* @returns A RelationshipMap
|
|
21
|
+
* @returns A RelationshipMap with entries for both sides (or just 'from' when unidirectional).
|
|
17
22
|
*/
|
|
18
23
|
export declare const parseManytoOne: (relationship: ApsorcRelationship) => RelationshipMap;
|
|
19
24
|
/**
|
|
@@ -39,20 +39,52 @@ const parseOneToMany = (relationship) => {
|
|
|
39
39
|
exports.parseOneToMany = parseOneToMany;
|
|
40
40
|
/**
|
|
41
41
|
* Parses a ManyToOne relationship definition.
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* Bidirectional by default, mirroring parseOneToMany with from/to swapped:
|
|
43
|
+
* the target entity gets the inverse OneToMany collection (and with it the
|
|
44
|
+
* controller join allowlist), so `Authors?join=books` works no matter which
|
|
45
|
+
* direction the .apsorc declared the relationship in.
|
|
46
|
+
* Set `bi_directional: false` to keep the old FK-only unidirectional shape.
|
|
47
|
+
* Self-referencing relationships stay unidirectional (both sides would
|
|
48
|
+
* collide on the same RelationshipMap key).
|
|
44
49
|
* @param relationship The .apsorc relationship definition.
|
|
45
|
-
* @returns A RelationshipMap
|
|
50
|
+
* @returns A RelationshipMap with entries for both sides (or just 'from' when unidirectional).
|
|
46
51
|
*/
|
|
47
52
|
const parseManytoOne = (relationship) => {
|
|
53
|
+
const unidirectional = relationship.bi_directional === false ||
|
|
54
|
+
relationship.from === relationship.to;
|
|
55
|
+
if (unidirectional) {
|
|
56
|
+
return {
|
|
57
|
+
[relationship.from]: [
|
|
58
|
+
{
|
|
59
|
+
name: relationship.to,
|
|
60
|
+
type: "ManyToOne",
|
|
61
|
+
referenceName: relationship.to_name || null,
|
|
62
|
+
nullable: relationship.nullable || false,
|
|
63
|
+
index: relationship.index || false,
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
}
|
|
48
68
|
return {
|
|
49
69
|
[relationship.from]: [
|
|
50
70
|
{
|
|
51
71
|
name: relationship.to,
|
|
52
72
|
type: "ManyToOne",
|
|
53
|
-
referenceName: relationship.to_name || null,
|
|
54
73
|
nullable: relationship.nullable || false,
|
|
74
|
+
biDirectional: true,
|
|
55
75
|
index: relationship.index || false,
|
|
76
|
+
cascadeDelete: relationship.cascadeDelete || false,
|
|
77
|
+
referenceName: relationship.to_name || relationship.to,
|
|
78
|
+
inverseReferenceName: relationship.from,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
[relationship.to]: [
|
|
82
|
+
{
|
|
83
|
+
name: relationship.from,
|
|
84
|
+
type: "OneToMany",
|
|
85
|
+
biDirectional: true,
|
|
86
|
+
referenceName: relationship.from,
|
|
87
|
+
inverseReferenceName: relationship.to_name || relationship.to,
|
|
56
88
|
},
|
|
57
89
|
],
|
|
58
90
|
};
|
|
@@ -264,18 +296,52 @@ const parseRelationship = (relationship, allRelationships) => {
|
|
|
264
296
|
],
|
|
265
297
|
};
|
|
266
298
|
}
|
|
267
|
-
case "ManyToOne":
|
|
299
|
+
case "ManyToOne": {
|
|
300
|
+
// Bidirectional by default, mirroring the OneToMany case with the roles
|
|
301
|
+
// swapped: the target entity gets the inverse OneToMany collection (and
|
|
302
|
+
// with it the controller join allowlist), so the collection-side embed
|
|
303
|
+
// works no matter which direction .apsorc declared the relationship in.
|
|
304
|
+
// `bi_directional: false` keeps the old FK-only shape; self-references
|
|
305
|
+
// stay unidirectional (both sides would collide on the same map key).
|
|
306
|
+
const manySideRefName = relationship.to_name || relationship.to;
|
|
307
|
+
if (relationship.bi_directional === false ||
|
|
308
|
+
relationship.from === relationship.to) {
|
|
309
|
+
return {
|
|
310
|
+
[relationship.from]: [
|
|
311
|
+
{
|
|
312
|
+
name: relationship.to,
|
|
313
|
+
type: "ManyToOne",
|
|
314
|
+
referenceName: manySideRefName,
|
|
315
|
+
nullable: relationship.nullable || false,
|
|
316
|
+
index: relationship.index || false,
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
};
|
|
320
|
+
}
|
|
268
321
|
return {
|
|
269
322
|
[relationship.from]: [
|
|
270
323
|
{
|
|
271
324
|
name: relationship.to,
|
|
272
325
|
type: "ManyToOne",
|
|
273
|
-
referenceName: relationship.to_name || relationship.to,
|
|
274
326
|
nullable: relationship.nullable || false,
|
|
327
|
+
biDirectional: true,
|
|
275
328
|
index: relationship.index || false,
|
|
329
|
+
cascadeDelete: relationship.cascadeDelete || false,
|
|
330
|
+
referenceName: manySideRefName,
|
|
331
|
+
inverseReferenceName: relationship.from,
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
[relationship.to]: [
|
|
335
|
+
{
|
|
336
|
+
name: relationship.from,
|
|
337
|
+
type: "OneToMany",
|
|
338
|
+
biDirectional: true,
|
|
339
|
+
referenceName: relationship.from,
|
|
340
|
+
inverseReferenceName: manySideRefName,
|
|
276
341
|
},
|
|
277
342
|
],
|
|
278
343
|
};
|
|
344
|
+
}
|
|
279
345
|
case "OneToOne": {
|
|
280
346
|
const inverseOnetoOneDef = allRelationships.find((def) => def.from === relationship.to &&
|
|
281
347
|
def.to === relationship.from &&
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apso/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@apso/cli",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.35.0",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@biomejs/biome": "^1.9.4",
|
package/oclif.manifest.json
CHANGED