@apso/cli 0.0.45 → 0.1.4

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.
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const globals_1 = require("@jest/globals");
4
+ const parse_1 = require("../../lib/utils/relationships/parse");
5
+ (0, globals_1.describe)("getRelationshipForTemplate deduplication", () => {
6
+ (0, globals_1.test)("should deduplicate ManyToMany relationships", () => {
7
+ // Mock entity name
8
+ const entityName = "CustomerCard";
9
+ // Mock relationships - simulating bidirectional ManyToMany where
10
+ // both sides are added to the relationships array for the same entity
11
+ const mockRelationships = [
12
+ // First ManyToMany relationship (non-join side)
13
+ {
14
+ name: "Subscription",
15
+ type: "ManyToMany",
16
+ referenceName: "subscriptions",
17
+ biDirectional: true,
18
+ join: false,
19
+ inverseReferenceName: "customercards"
20
+ },
21
+ // Duplicate relationship (join side) - similar to what happens in bidirectional ManyToMany
22
+ {
23
+ name: "Subscription",
24
+ type: "ManyToMany",
25
+ referenceName: "subscriptions",
26
+ biDirectional: true,
27
+ join: true,
28
+ inverseReferenceName: "customercards"
29
+ }
30
+ ];
31
+ // Run the function
32
+ const result = (0, parse_1.getRelationshipForTemplate)(entityName, mockRelationships);
33
+ // Assertions
34
+ // 1. Should only have one relationship
35
+ (0, globals_1.expect)(result.length).toBe(1);
36
+ // 2. The remaining relationship should be the one with join=true
37
+ (0, globals_1.expect)(result[0].name).toBe("Subscription");
38
+ (0, globals_1.expect)(result[0].joinTable).toBe(true);
39
+ });
40
+ (0, globals_1.test)("should keep first relationship when reference names differ", () => {
41
+ // Mock entity name
42
+ const entityName = "User";
43
+ // Create mocked relationships with same target but different reference names
44
+ const mockRelationships = [
45
+ {
46
+ name: "Workspace",
47
+ type: "ManyToMany",
48
+ referenceName: "workspaces",
49
+ biDirectional: true,
50
+ join: true
51
+ },
52
+ {
53
+ name: "Workspace",
54
+ type: "ManyToMany",
55
+ referenceName: "ownedWorkspaces",
56
+ biDirectional: true,
57
+ join: true
58
+ }
59
+ ];
60
+ // Run the function
61
+ const result = (0, parse_1.getRelationshipForTemplate)(entityName, mockRelationships);
62
+ // Assertions
63
+ // Current behavior: Only one relationship is kept during name-based deduplication (second phase)
64
+ (0, globals_1.expect)(result.length).toBe(1);
65
+ // The first one is kept in the Set processing
66
+ (0, globals_1.expect)(result[0].relationshipName).toBe("workspaces");
67
+ });
68
+ (0, globals_1.test)("should prioritize owner side (join=true) when deduplicating", () => {
69
+ // Scenario based on real issue: two ManyToMany relationships to same entity
70
+ const entityName = "Tag";
71
+ // Create relationships where one has join=true and one has join=false (non-owning side)
72
+ const mockRelationships = [
73
+ {
74
+ name: "WorkspaceService",
75
+ type: "ManyToMany",
76
+ biDirectional: true,
77
+ join: false,
78
+ referenceName: "workspaceservices"
79
+ },
80
+ {
81
+ name: "WorkspaceService",
82
+ type: "ManyToMany",
83
+ biDirectional: true,
84
+ join: true,
85
+ referenceName: "workspaceservices"
86
+ }
87
+ ];
88
+ // Run the function
89
+ const result = (0, parse_1.getRelationshipForTemplate)(entityName, mockRelationships);
90
+ // Assertions
91
+ // Should only have one relationship
92
+ (0, globals_1.expect)(result.length).toBe(1);
93
+ // Should be the one with join=true
94
+ (0, globals_1.expect)(result[0].name).toBe("WorkspaceService");
95
+ (0, globals_1.expect)(result[0].joinTable).toBe(true); // joinTable corresponds to join
96
+ });
97
+ });
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.45",
2
+ "version": "0.1.4",
3
3
  "commands": {
4
4
  "server:new": {
5
5
  "id": "server:new",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.0.45",
3
+ "version": "0.1.4",
4
4
  "description": "Apso CLI",
5
5
  "author": "Apso by Mavric - @mavric",
6
6
  "bin": {
@@ -56,6 +56,7 @@
56
56
  "ts-jest": "^29.1.0",
57
57
  "ts-node": "^10.9.1",
58
58
  "tslib": "^2.5.0",
59
+ "typedoc": "^0.28.3",
59
60
  "typescript": "^5"
60
61
  },
61
62
  "oclif": {
@@ -86,6 +87,7 @@
86
87
  "test": "jest",
87
88
  "test:watch": "jest --watch",
88
89
  "test:cov": "jest --coverage",
90
+ "docs:generate": "typedoc src/lib/index.ts --out docs",
89
91
  "version": "oclif readme && git add README.md"
90
92
  },
91
93
  "engines": {