@apso/cli 0.4.2 → 0.6.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 +796 -6
- package/dist/commands/server/new.js +1 -1
- package/dist/commands/server/scaffold.js +20 -9
- package/dist/lib/apsorc-parser.d.ts +3 -0
- package/dist/lib/apsorc-parser.js +11 -6
- package/dist/lib/controller.js +3 -1
- package/dist/lib/dto.js +9 -9
- package/dist/lib/entity.js +6 -5
- package/dist/lib/guards.d.ts +47 -0
- package/dist/lib/guards.js +176 -0
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +5 -1
- package/dist/lib/module.js +3 -1
- package/dist/lib/templates/guards/auth.guard.eta +228 -0
- package/dist/lib/templates/guards/guards.module.eta +114 -0
- package/dist/lib/templates/guards/index.eta +22 -0
- package/dist/lib/templates/guards/scope.guard.eta +327 -0
- package/dist/lib/types/auth.d.ts +203 -0
- package/dist/lib/types/auth.js +60 -0
- package/dist/lib/types/entity.d.ts +36 -1
- package/dist/lib/types/index.d.ts +2 -1
- package/dist/lib/types/index.js +8 -0
- package/dist/lib/types/relationship.d.ts +1 -1
- package/dist/lib/utils/casing.js +5 -5
- package/dist/lib/utils/field.js +2 -1
- package/dist/lib/utils/file-system.js +1 -1
- package/dist/lib/utils/relationships/parse-v1.js +2 -1
- package/dist/lib/utils/relationships/parse.js +117 -32
- package/dist/lib/utils/relationships/parse.spec.js +168 -141
- package/dist/test-nested-relationships.js +10 -10
- package/dist/tests/templates/entities/types/array-template.spec.js +45 -45
- package/dist/tests/templates/entities/types/bigint-template.spec.js +43 -43
- package/dist/tests/templates/entities/types/boolean-template.spec.js +44 -44
- package/dist/tests/templates/entities/types/bytea-template.spec.js +35 -35
- package/dist/tests/templates/entities/types/char-template.spec.js +35 -35
- package/dist/tests/templates/entities/types/date-template.spec.js +29 -29
- package/dist/tests/templates/entities/types/decimal-field-validation.spec.js +46 -46
- package/dist/tests/templates/entities/types/decimal-template.spec.js +46 -46
- package/dist/tests/templates/entities/types/double-template.spec.js +37 -34
- package/dist/tests/templates/entities/types/enum-template.spec.js +42 -42
- package/dist/tests/templates/entities/types/float-template.spec.js +37 -34
- package/dist/tests/templates/entities/types/geometry-template.spec.js +31 -31
- package/dist/tests/templates/entities/types/inet-template.spec.js +36 -36
- package/dist/tests/templates/entities/types/int4range-template.spec.js +45 -33
- package/dist/tests/templates/entities/types/integer-template.spec.js +40 -40
- package/dist/tests/templates/entities/types/interval-template.spec.js +35 -35
- package/dist/tests/templates/entities/types/json-plain-template.spec.js +27 -27
- package/dist/tests/templates/entities/types/json-template.spec.js +19 -19
- package/dist/tests/templates/entities/types/jsonb-template.spec.js +19 -19
- package/dist/tests/templates/entities/types/money-template.spec.js +35 -35
- package/dist/tests/templates/entities/types/numeric-template.spec.js +44 -44
- package/dist/tests/templates/entities/types/point-template.spec.js +37 -31
- package/dist/tests/templates/entities/types/polygon-template.spec.js +43 -31
- package/dist/tests/templates/entities/types/real-template.spec.js +34 -34
- package/dist/tests/templates/entities/types/serial-template.spec.js +62 -62
- package/dist/tests/templates/entities/types/smallint-template.spec.js +43 -43
- package/dist/tests/templates/entities/types/string-template.spec.js +59 -59
- package/dist/tests/templates/entities/types/text-template.spec.js +37 -37
- package/dist/tests/templates/entities/types/time-template.spec.js +35 -35
- package/dist/tests/templates/entities/types/timestamp-template.spec.js +39 -39
- package/dist/tests/templates/entities/types/timetz-template.spec.js +35 -35
- package/dist/tests/templates/entities/types/tsvector-template.spec.js +28 -28
- package/dist/tests/templates/entities/types/uuid-template.spec.js +43 -43
- package/dist/tests/templates/entities/types/varchar-template.spec.js +59 -56
- package/dist/tests/templates/entities/types/xml-template.spec.js +28 -28
- package/dist/tests/templates/entities/utils/template-test-utils.d.ts +1 -1
- package/dist/tests/templates/entities/utils/template-test-utils.js +3 -3
- package/dist/tests/templates/entities/uuid-entity-template.spec.js +138 -138
- package/dist/tests/utils/relationship-deduplication.spec.js +11 -11
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
|
@@ -4,20 +4,20 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const Eta = tslib_1.__importStar(require("eta"));
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
6
|
const globals_1 = require("@jest/globals");
|
|
7
|
-
(0, globals_1.describe)(
|
|
7
|
+
(0, globals_1.describe)("UUID Entity Template Tests", () => {
|
|
8
8
|
(0, globals_1.beforeAll)(() => {
|
|
9
9
|
Eta.configure({
|
|
10
|
-
views: path.join(__dirname,
|
|
11
|
-
cache: false
|
|
10
|
+
views: path.join(__dirname, "../../../lib/templates"),
|
|
11
|
+
cache: false,
|
|
12
12
|
});
|
|
13
13
|
});
|
|
14
|
-
(0, globals_1.describe)(
|
|
15
|
-
(0, globals_1.it)(
|
|
14
|
+
(0, globals_1.describe)("UUID Primary Key", () => {
|
|
15
|
+
(0, globals_1.it)("should render entity with UUID primary key", async () => {
|
|
16
16
|
const data = {
|
|
17
|
-
name:
|
|
18
|
-
snakeCasedName:
|
|
17
|
+
name: "User",
|
|
18
|
+
snakeCasedName: "user",
|
|
19
19
|
createPrimaryKey: true,
|
|
20
|
-
primaryKeyType:
|
|
20
|
+
primaryKeyType: "uuid",
|
|
21
21
|
createdAt: true,
|
|
22
22
|
updatedAt: true,
|
|
23
23
|
columns: [],
|
|
@@ -25,25 +25,25 @@ const globals_1 = require("@jest/globals");
|
|
|
25
25
|
indexes: [],
|
|
26
26
|
uniques: [],
|
|
27
27
|
entitiesToImport: [],
|
|
28
|
-
apiType:
|
|
29
|
-
importEnums: false
|
|
28
|
+
apiType: "rest",
|
|
29
|
+
importEnums: false,
|
|
30
30
|
};
|
|
31
|
-
const rendered = await Eta.renderFileAsync(
|
|
31
|
+
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
32
32
|
// Should use @Column with uuid type
|
|
33
33
|
(0, globals_1.expect)(rendered).toContain("@Column({ type: 'uuid' })");
|
|
34
34
|
// Should use @PrimaryColumn instead of @PrimaryGeneratedColumn
|
|
35
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
36
|
-
(0, globals_1.expect)(rendered).not.toContain(
|
|
35
|
+
(0, globals_1.expect)(rendered).toContain("@PrimaryColumn()");
|
|
36
|
+
(0, globals_1.expect)(rendered).not.toContain("@PrimaryGeneratedColumn()");
|
|
37
37
|
// Should declare id as string
|
|
38
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
39
|
-
(0, globals_1.expect)(rendered).not.toContain(
|
|
38
|
+
(0, globals_1.expect)(rendered).toContain("id: string;");
|
|
39
|
+
(0, globals_1.expect)(rendered).not.toContain("id!: number;");
|
|
40
40
|
});
|
|
41
|
-
(0, globals_1.it)(
|
|
41
|
+
(0, globals_1.it)("should render entity with serial (auto-increment) primary key", async () => {
|
|
42
42
|
const data = {
|
|
43
|
-
name:
|
|
44
|
-
snakeCasedName:
|
|
43
|
+
name: "Post",
|
|
44
|
+
snakeCasedName: "post",
|
|
45
45
|
createPrimaryKey: true,
|
|
46
|
-
primaryKeyType:
|
|
46
|
+
primaryKeyType: "serial",
|
|
47
47
|
createdAt: true,
|
|
48
48
|
updatedAt: true,
|
|
49
49
|
columns: [],
|
|
@@ -51,22 +51,22 @@ const globals_1 = require("@jest/globals");
|
|
|
51
51
|
indexes: [],
|
|
52
52
|
uniques: [],
|
|
53
53
|
entitiesToImport: [],
|
|
54
|
-
apiType:
|
|
55
|
-
importEnums: false
|
|
54
|
+
apiType: "rest",
|
|
55
|
+
importEnums: false,
|
|
56
56
|
};
|
|
57
|
-
const rendered = await Eta.renderFileAsync(
|
|
57
|
+
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
58
58
|
// Should use @PrimaryGeneratedColumn
|
|
59
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
59
|
+
(0, globals_1.expect)(rendered).toContain("@PrimaryGeneratedColumn()");
|
|
60
60
|
(0, globals_1.expect)(rendered).not.toContain("@Column({ type: 'uuid' })");
|
|
61
|
-
(0, globals_1.expect)(rendered).not.toContain(
|
|
61
|
+
(0, globals_1.expect)(rendered).not.toContain("@PrimaryColumn()");
|
|
62
62
|
// Should declare id as number
|
|
63
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
64
|
-
(0, globals_1.expect)(rendered).not.toContain(
|
|
63
|
+
(0, globals_1.expect)(rendered).toContain("id!: number;");
|
|
64
|
+
(0, globals_1.expect)(rendered).not.toContain("id: string;");
|
|
65
65
|
});
|
|
66
|
-
(0, globals_1.it)(
|
|
66
|
+
(0, globals_1.it)("should default to serial primary key when primaryKeyType is not specified", async () => {
|
|
67
67
|
const data = {
|
|
68
|
-
name:
|
|
69
|
-
snakeCasedName:
|
|
68
|
+
name: "Comment",
|
|
69
|
+
snakeCasedName: "comment",
|
|
70
70
|
createPrimaryKey: true,
|
|
71
71
|
// primaryKeyType not specified
|
|
72
72
|
createdAt: true,
|
|
@@ -76,202 +76,202 @@ const globals_1 = require("@jest/globals");
|
|
|
76
76
|
indexes: [],
|
|
77
77
|
uniques: [],
|
|
78
78
|
entitiesToImport: [],
|
|
79
|
-
apiType:
|
|
80
|
-
importEnums: false
|
|
79
|
+
apiType: "rest",
|
|
80
|
+
importEnums: false,
|
|
81
81
|
};
|
|
82
|
-
const rendered = await Eta.renderFileAsync(
|
|
82
|
+
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
83
83
|
// Should default to serial (auto-increment)
|
|
84
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
85
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
84
|
+
(0, globals_1.expect)(rendered).toContain("@PrimaryGeneratedColumn()");
|
|
85
|
+
(0, globals_1.expect)(rendered).toContain("id!: number;");
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
|
-
(0, globals_1.describe)(
|
|
89
|
-
(0, globals_1.it)(
|
|
88
|
+
(0, globals_1.describe)("UUID Foreign Keys", () => {
|
|
89
|
+
(0, globals_1.it)("should render ManyToOne relationship with UUID foreign key when referenced entity has UUID primary key", async () => {
|
|
90
90
|
const data = {
|
|
91
|
-
name:
|
|
92
|
-
snakeCasedName:
|
|
91
|
+
name: "Account",
|
|
92
|
+
snakeCasedName: "account",
|
|
93
93
|
createPrimaryKey: true,
|
|
94
|
-
primaryKeyType:
|
|
94
|
+
primaryKeyType: "serial",
|
|
95
95
|
createdAt: true,
|
|
96
96
|
updatedAt: true,
|
|
97
97
|
columns: [],
|
|
98
98
|
associations: [
|
|
99
99
|
{
|
|
100
|
-
name:
|
|
101
|
-
type:
|
|
102
|
-
relationshipName:
|
|
103
|
-
pluralizedRelationshipName:
|
|
104
|
-
pluralizedName:
|
|
105
|
-
camelCasedName:
|
|
106
|
-
camelCasedId:
|
|
107
|
-
entityName:
|
|
100
|
+
name: "User",
|
|
101
|
+
type: "ManyToOne",
|
|
102
|
+
relationshipName: "user",
|
|
103
|
+
pluralizedRelationshipName: "users",
|
|
104
|
+
pluralizedName: "users",
|
|
105
|
+
camelCasedName: "user",
|
|
106
|
+
camelCasedId: "userId",
|
|
107
|
+
entityName: "account",
|
|
108
108
|
joinTable: false,
|
|
109
109
|
biDirectional: true,
|
|
110
|
-
inverseSidePropertyName:
|
|
111
|
-
referencedEntityPrimaryKeyType:
|
|
110
|
+
inverseSidePropertyName: "accounts",
|
|
111
|
+
referencedEntityPrimaryKeyType: "uuid",
|
|
112
112
|
nullable: false,
|
|
113
|
-
index: false
|
|
114
|
-
}
|
|
113
|
+
index: false,
|
|
114
|
+
},
|
|
115
115
|
],
|
|
116
116
|
indexes: [],
|
|
117
117
|
uniques: [],
|
|
118
|
-
entitiesToImport: [
|
|
119
|
-
apiType:
|
|
120
|
-
importEnums: false
|
|
118
|
+
entitiesToImport: ["User"],
|
|
119
|
+
apiType: "rest",
|
|
120
|
+
importEnums: false,
|
|
121
121
|
};
|
|
122
|
-
const rendered = await Eta.renderFileAsync(
|
|
122
|
+
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
123
123
|
// Should have ManyToOne decorator
|
|
124
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
124
|
+
(0, globals_1.expect)(rendered).toContain("@ManyToOne(() => User");
|
|
125
125
|
// Should have JoinColumn
|
|
126
126
|
(0, globals_1.expect)(rendered).toContain("@JoinColumn({ name: 'userId' })");
|
|
127
127
|
// Should declare relationship property
|
|
128
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
128
|
+
(0, globals_1.expect)(rendered).toContain("user: User;");
|
|
129
129
|
// Should have UUID foreign key column
|
|
130
130
|
(0, globals_1.expect)(rendered).toContain('@Column({ type: "uuid"');
|
|
131
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
131
|
+
(0, globals_1.expect)(rendered).toContain("userId: string;");
|
|
132
132
|
// Should NOT have integer foreign key
|
|
133
|
-
(0, globals_1.expect)(rendered).not.toContain(
|
|
133
|
+
(0, globals_1.expect)(rendered).not.toContain("userId: number;");
|
|
134
134
|
});
|
|
135
|
-
(0, globals_1.it)(
|
|
135
|
+
(0, globals_1.it)("should render ManyToOne relationship with integer foreign key when referenced entity has serial primary key", async () => {
|
|
136
136
|
const data = {
|
|
137
|
-
name:
|
|
138
|
-
snakeCasedName:
|
|
137
|
+
name: "Post",
|
|
138
|
+
snakeCasedName: "post",
|
|
139
139
|
createPrimaryKey: true,
|
|
140
|
-
primaryKeyType:
|
|
140
|
+
primaryKeyType: "serial",
|
|
141
141
|
createdAt: true,
|
|
142
142
|
updatedAt: true,
|
|
143
143
|
columns: [],
|
|
144
144
|
associations: [
|
|
145
145
|
{
|
|
146
|
-
name:
|
|
147
|
-
type:
|
|
148
|
-
relationshipName:
|
|
149
|
-
pluralizedRelationshipName:
|
|
150
|
-
pluralizedName:
|
|
151
|
-
camelCasedName:
|
|
152
|
-
camelCasedId:
|
|
153
|
-
entityName:
|
|
146
|
+
name: "User",
|
|
147
|
+
type: "ManyToOne",
|
|
148
|
+
relationshipName: "user",
|
|
149
|
+
pluralizedRelationshipName: "users",
|
|
150
|
+
pluralizedName: "users",
|
|
151
|
+
camelCasedName: "user",
|
|
152
|
+
camelCasedId: "userId",
|
|
153
|
+
entityName: "post",
|
|
154
154
|
joinTable: false,
|
|
155
155
|
biDirectional: true,
|
|
156
|
-
inverseSidePropertyName:
|
|
157
|
-
referencedEntityPrimaryKeyType:
|
|
156
|
+
inverseSidePropertyName: "posts",
|
|
157
|
+
referencedEntityPrimaryKeyType: "serial",
|
|
158
158
|
nullable: false,
|
|
159
|
-
index: true
|
|
160
|
-
}
|
|
159
|
+
index: true,
|
|
160
|
+
},
|
|
161
161
|
],
|
|
162
162
|
indexes: [],
|
|
163
163
|
uniques: [],
|
|
164
|
-
entitiesToImport: [
|
|
165
|
-
apiType:
|
|
166
|
-
importEnums: false
|
|
164
|
+
entitiesToImport: ["User"],
|
|
165
|
+
apiType: "rest",
|
|
166
|
+
importEnums: false,
|
|
167
167
|
};
|
|
168
|
-
const rendered = await Eta.renderFileAsync(
|
|
168
|
+
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
169
169
|
// Should have ManyToOne decorator
|
|
170
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
170
|
+
(0, globals_1.expect)(rendered).toContain("@ManyToOne(() => User");
|
|
171
171
|
// Should have index since index: true
|
|
172
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
172
|
+
(0, globals_1.expect)(rendered).toContain("@Index()");
|
|
173
173
|
// Should have integer foreign key column
|
|
174
174
|
(0, globals_1.expect)(rendered).toContain('@Column({ type: "integer"');
|
|
175
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
175
|
+
(0, globals_1.expect)(rendered).toContain("userId: number;");
|
|
176
176
|
// Should NOT have UUID foreign key
|
|
177
|
-
(0, globals_1.expect)(rendered).not.toContain(
|
|
177
|
+
(0, globals_1.expect)(rendered).not.toContain("userId: string;");
|
|
178
178
|
});
|
|
179
|
-
(0, globals_1.it)(
|
|
179
|
+
(0, globals_1.it)("should handle nullable UUID foreign keys", async () => {
|
|
180
180
|
const data = {
|
|
181
|
-
name:
|
|
182
|
-
snakeCasedName:
|
|
181
|
+
name: "Profile",
|
|
182
|
+
snakeCasedName: "profile",
|
|
183
183
|
createPrimaryKey: true,
|
|
184
|
-
primaryKeyType:
|
|
184
|
+
primaryKeyType: "uuid",
|
|
185
185
|
createdAt: true,
|
|
186
186
|
updatedAt: true,
|
|
187
187
|
columns: [],
|
|
188
188
|
associations: [
|
|
189
189
|
{
|
|
190
|
-
name:
|
|
191
|
-
type:
|
|
192
|
-
relationshipName:
|
|
193
|
-
pluralizedRelationshipName:
|
|
194
|
-
pluralizedName:
|
|
195
|
-
camelCasedName:
|
|
196
|
-
camelCasedId:
|
|
197
|
-
entityName:
|
|
190
|
+
name: "Organization",
|
|
191
|
+
type: "ManyToOne",
|
|
192
|
+
relationshipName: "organization",
|
|
193
|
+
pluralizedRelationshipName: "organizations",
|
|
194
|
+
pluralizedName: "organizations",
|
|
195
|
+
camelCasedName: "organization",
|
|
196
|
+
camelCasedId: "organizationId",
|
|
197
|
+
entityName: "profile",
|
|
198
198
|
joinTable: false,
|
|
199
199
|
biDirectional: false,
|
|
200
|
-
referencedEntityPrimaryKeyType:
|
|
200
|
+
referencedEntityPrimaryKeyType: "uuid",
|
|
201
201
|
nullable: true,
|
|
202
|
-
index: false
|
|
203
|
-
}
|
|
202
|
+
index: false,
|
|
203
|
+
},
|
|
204
204
|
],
|
|
205
205
|
indexes: [],
|
|
206
206
|
uniques: [],
|
|
207
|
-
entitiesToImport: [
|
|
208
|
-
apiType:
|
|
209
|
-
importEnums: false
|
|
207
|
+
entitiesToImport: ["Organization"],
|
|
208
|
+
apiType: "rest",
|
|
209
|
+
importEnums: false,
|
|
210
210
|
};
|
|
211
|
-
const rendered = await Eta.renderFileAsync(
|
|
211
|
+
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
212
212
|
// Should have nullable UUID foreign key
|
|
213
213
|
(0, globals_1.expect)(rendered).toContain('@Column({ type: "uuid", nullable: true');
|
|
214
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
214
|
+
(0, globals_1.expect)(rendered).toContain("organizationId: string;");
|
|
215
215
|
});
|
|
216
|
-
(0, globals_1.it)(
|
|
216
|
+
(0, globals_1.it)("should handle multiple relationships with mixed UUID and serial foreign keys", async () => {
|
|
217
217
|
const data = {
|
|
218
|
-
name:
|
|
219
|
-
snakeCasedName:
|
|
218
|
+
name: "Comment",
|
|
219
|
+
snakeCasedName: "comment",
|
|
220
220
|
createPrimaryKey: true,
|
|
221
|
-
primaryKeyType:
|
|
221
|
+
primaryKeyType: "serial",
|
|
222
222
|
createdAt: true,
|
|
223
223
|
updatedAt: true,
|
|
224
224
|
columns: [],
|
|
225
225
|
associations: [
|
|
226
226
|
{
|
|
227
|
-
name:
|
|
228
|
-
type:
|
|
229
|
-
relationshipName:
|
|
230
|
-
pluralizedRelationshipName:
|
|
231
|
-
pluralizedName:
|
|
232
|
-
camelCasedName:
|
|
233
|
-
camelCasedId:
|
|
234
|
-
entityName:
|
|
227
|
+
name: "User",
|
|
228
|
+
type: "ManyToOne",
|
|
229
|
+
relationshipName: "user",
|
|
230
|
+
pluralizedRelationshipName: "users",
|
|
231
|
+
pluralizedName: "users",
|
|
232
|
+
camelCasedName: "user",
|
|
233
|
+
camelCasedId: "userId",
|
|
234
|
+
entityName: "comment",
|
|
235
235
|
joinTable: false,
|
|
236
236
|
biDirectional: true,
|
|
237
|
-
inverseSidePropertyName:
|
|
238
|
-
referencedEntityPrimaryKeyType:
|
|
237
|
+
inverseSidePropertyName: "comments",
|
|
238
|
+
referencedEntityPrimaryKeyType: "uuid",
|
|
239
239
|
nullable: false,
|
|
240
|
-
index: true
|
|
240
|
+
index: true,
|
|
241
241
|
},
|
|
242
242
|
{
|
|
243
|
-
name:
|
|
244
|
-
type:
|
|
245
|
-
relationshipName:
|
|
246
|
-
pluralizedRelationshipName:
|
|
247
|
-
pluralizedName:
|
|
248
|
-
camelCasedName:
|
|
249
|
-
camelCasedId:
|
|
250
|
-
entityName:
|
|
243
|
+
name: "Post",
|
|
244
|
+
type: "ManyToOne",
|
|
245
|
+
relationshipName: "post",
|
|
246
|
+
pluralizedRelationshipName: "posts",
|
|
247
|
+
pluralizedName: "posts",
|
|
248
|
+
camelCasedName: "post",
|
|
249
|
+
camelCasedId: "postId",
|
|
250
|
+
entityName: "comment",
|
|
251
251
|
joinTable: false,
|
|
252
252
|
biDirectional: true,
|
|
253
|
-
inverseSidePropertyName:
|
|
254
|
-
referencedEntityPrimaryKeyType:
|
|
253
|
+
inverseSidePropertyName: "comments",
|
|
254
|
+
referencedEntityPrimaryKeyType: "serial",
|
|
255
255
|
nullable: false,
|
|
256
|
-
index: true
|
|
257
|
-
}
|
|
256
|
+
index: true,
|
|
257
|
+
},
|
|
258
258
|
],
|
|
259
259
|
indexes: [],
|
|
260
260
|
uniques: [],
|
|
261
|
-
entitiesToImport: [
|
|
262
|
-
apiType:
|
|
263
|
-
importEnums: false
|
|
261
|
+
entitiesToImport: ["User", "Post"],
|
|
262
|
+
apiType: "rest",
|
|
263
|
+
importEnums: false,
|
|
264
264
|
};
|
|
265
|
-
const rendered = await Eta.renderFileAsync(
|
|
265
|
+
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
266
266
|
// Should have UUID foreign key for User
|
|
267
267
|
(0, globals_1.expect)(rendered).toContain('@Column({ type: "uuid"');
|
|
268
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
268
|
+
(0, globals_1.expect)(rendered).toContain("userId: string;");
|
|
269
269
|
// Should have integer foreign key for Post
|
|
270
270
|
(0, globals_1.expect)(rendered).toContain('@Column({ type: "integer"');
|
|
271
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
271
|
+
(0, globals_1.expect)(rendered).toContain("postId: number;");
|
|
272
272
|
// Should have both relationships
|
|
273
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
274
|
-
(0, globals_1.expect)(rendered).toContain(
|
|
273
|
+
(0, globals_1.expect)(rendered).toContain("user: User;");
|
|
274
|
+
(0, globals_1.expect)(rendered).toContain("post: Post;");
|
|
275
275
|
});
|
|
276
276
|
});
|
|
277
277
|
});
|
|
@@ -6,7 +6,7 @@ const parse_1 = require("../../lib/utils/relationships/parse");
|
|
|
6
6
|
(0, globals_1.test)("should deduplicate ManyToMany relationships", () => {
|
|
7
7
|
// Mock entity name
|
|
8
8
|
const entityName = "CustomerCard";
|
|
9
|
-
// Mock relationships - simulating bidirectional ManyToMany where
|
|
9
|
+
// Mock relationships - simulating bidirectional ManyToMany where
|
|
10
10
|
// both sides are added to the relationships array for the same entity
|
|
11
11
|
const mockRelationships = [
|
|
12
12
|
// First ManyToMany relationship (non-join side)
|
|
@@ -16,7 +16,7 @@ const parse_1 = require("../../lib/utils/relationships/parse");
|
|
|
16
16
|
referenceName: "subscriptions",
|
|
17
17
|
biDirectional: true,
|
|
18
18
|
join: false,
|
|
19
|
-
inverseReferenceName: "customercards"
|
|
19
|
+
inverseReferenceName: "customercards",
|
|
20
20
|
},
|
|
21
21
|
// Duplicate relationship (join side) - similar to what happens in bidirectional ManyToMany
|
|
22
22
|
{
|
|
@@ -25,8 +25,8 @@ const parse_1 = require("../../lib/utils/relationships/parse");
|
|
|
25
25
|
referenceName: "subscriptions",
|
|
26
26
|
biDirectional: true,
|
|
27
27
|
join: true,
|
|
28
|
-
inverseReferenceName: "customercards"
|
|
29
|
-
}
|
|
28
|
+
inverseReferenceName: "customercards",
|
|
29
|
+
},
|
|
30
30
|
];
|
|
31
31
|
// Run the function
|
|
32
32
|
const result = (0, parse_1.getRelationshipForTemplate)(entityName, mockRelationships);
|
|
@@ -47,22 +47,22 @@ const parse_1 = require("../../lib/utils/relationships/parse");
|
|
|
47
47
|
type: "ManyToMany",
|
|
48
48
|
referenceName: "workspaces",
|
|
49
49
|
biDirectional: true,
|
|
50
|
-
join: true
|
|
50
|
+
join: true,
|
|
51
51
|
},
|
|
52
52
|
{
|
|
53
53
|
name: "Workspace",
|
|
54
54
|
type: "ManyToMany",
|
|
55
55
|
referenceName: "ownedWorkspaces",
|
|
56
56
|
biDirectional: true,
|
|
57
|
-
join: true
|
|
58
|
-
}
|
|
57
|
+
join: true,
|
|
58
|
+
},
|
|
59
59
|
];
|
|
60
60
|
// Run the function
|
|
61
61
|
const result = (0, parse_1.getRelationshipForTemplate)(entityName, mockRelationships);
|
|
62
62
|
// Assertions
|
|
63
63
|
// New behavior: Both relationships with different referenceName should be kept
|
|
64
64
|
(0, globals_1.expect)(result.length).toBe(2);
|
|
65
|
-
const referenceNames = result.map(r => r.relationshipName || r.referenceName);
|
|
65
|
+
const referenceNames = result.map((r) => r.relationshipName || r.referenceName);
|
|
66
66
|
(0, globals_1.expect)(referenceNames).toContain("workspaces");
|
|
67
67
|
(0, globals_1.expect)(referenceNames).toContain("ownedWorkspaces");
|
|
68
68
|
});
|
|
@@ -76,15 +76,15 @@ const parse_1 = require("../../lib/utils/relationships/parse");
|
|
|
76
76
|
type: "ManyToMany",
|
|
77
77
|
biDirectional: true,
|
|
78
78
|
join: false,
|
|
79
|
-
referenceName: "workspaceservices"
|
|
79
|
+
referenceName: "workspaceservices",
|
|
80
80
|
},
|
|
81
81
|
{
|
|
82
82
|
name: "WorkspaceService",
|
|
83
83
|
type: "ManyToMany",
|
|
84
84
|
biDirectional: true,
|
|
85
85
|
join: true,
|
|
86
|
-
referenceName: "workspaceservices"
|
|
87
|
-
}
|
|
86
|
+
referenceName: "workspaceservices",
|
|
87
|
+
},
|
|
88
88
|
];
|
|
89
89
|
// Run the function
|
|
90
90
|
const result = (0, parse_1.getRelationshipForTemplate)(entityName, mockRelationships);
|
package/oclif.manifest.json
CHANGED