@apso/cli 0.7.4 → 0.8.3
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/dist/autogen/index.d.ts +2 -0
- package/dist/autogen/index.js +3 -0
- package/dist/commands/server/new.d.ts +4 -1
- package/dist/commands/server/new.js +115 -22
- package/dist/commands/server/scaffold.d.ts +10 -0
- package/dist/commands/server/scaffold.js +200 -10
- package/dist/lib/api/client.d.ts +65 -0
- package/dist/lib/api/client.js +305 -0
- package/dist/lib/api/index.d.ts +8 -0
- package/dist/lib/api/index.js +22 -0
- package/dist/lib/api/services.d.ts +166 -0
- package/dist/lib/api/services.js +202 -0
- package/dist/lib/api/types.d.ts +212 -0
- package/dist/lib/api/types.js +7 -0
- package/dist/lib/apsorc-parser.d.ts +3 -0
- package/dist/lib/apsorc-parser.js +4 -0
- package/dist/lib/config/index.d.ts +8 -0
- package/dist/lib/config/index.js +17 -0
- package/dist/lib/config/manager.d.ts +127 -0
- package/dist/lib/config/manager.js +304 -0
- package/dist/lib/config/paths.d.ts +65 -0
- package/dist/lib/config/paths.js +127 -0
- package/dist/lib/config/types.d.ts +230 -0
- package/dist/lib/config/types.js +30 -0
- package/dist/lib/generators/base.d.ts +93 -0
- package/dist/lib/generators/base.js +90 -0
- package/dist/lib/generators/go.d.ts +37 -0
- package/dist/lib/generators/go.js +340 -0
- package/dist/lib/generators/index.d.ts +21 -0
- package/dist/lib/generators/index.js +51 -0
- package/dist/lib/generators/python.d.ts +21 -0
- package/dist/lib/generators/python.js +253 -0
- package/dist/lib/generators/typescript.d.ts +25 -0
- package/dist/lib/generators/typescript.js +373 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +9 -1
- package/dist/lib/templates/entities/entity-col-timestamp.eta +9 -2
- package/dist/lib/templates/entities/entity-col-timestamptz.eta +9 -2
- package/dist/lib/templates/entities/entity.eta +16 -3
- package/dist/lib/templates/go/dto/dto-col-array.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-boolean.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-date.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-decimal.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-enum.eta +8 -0
- package/dist/lib/templates/go/dto/dto-col-float.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-integer.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-json.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-jsonb.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-numeric.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-string.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-text.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-timestamp.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-timestamptz.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-uuid.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-varchar.eta +7 -0
- package/dist/lib/templates/go/dto/dto.eta +78 -0
- package/dist/lib/templates/go/enums.eta +44 -0
- package/dist/lib/templates/go/handlers/handler.eta +212 -0
- package/dist/lib/templates/go/header.eta +3 -0
- package/dist/lib/templates/go/index-module.eta +53 -0
- package/dist/lib/templates/go/middleware/auth.eta +101 -0
- package/dist/lib/templates/go/models/model-col-array.eta +1 -0
- package/dist/lib/templates/go/models/model-col-boolean.eta +1 -0
- package/dist/lib/templates/go/models/model-col-date.eta +1 -0
- package/dist/lib/templates/go/models/model-col-decimal.eta +1 -0
- package/dist/lib/templates/go/models/model-col-enum.eta +2 -0
- package/dist/lib/templates/go/models/model-col-float.eta +1 -0
- package/dist/lib/templates/go/models/model-col-integer.eta +1 -0
- package/dist/lib/templates/go/models/model-col-json.eta +1 -0
- package/dist/lib/templates/go/models/model-col-jsonb.eta +1 -0
- package/dist/lib/templates/go/models/model-col-numeric.eta +1 -0
- package/dist/lib/templates/go/models/model-col-string.eta +1 -0
- package/dist/lib/templates/go/models/model-col-text.eta +1 -0
- package/dist/lib/templates/go/models/model-col-timestamp.eta +1 -0
- package/dist/lib/templates/go/models/model-col-timestamptz.eta +1 -0
- package/dist/lib/templates/go/models/model-col-uuid.eta +1 -0
- package/dist/lib/templates/go/models/model-col-varchar.eta +1 -0
- package/dist/lib/templates/go/models/model.eta +53 -0
- package/dist/lib/templates/go/services/service.eta +190 -0
- package/dist/lib/templates/python/enums.eta +10 -0
- package/dist/lib/templates/python/header.eta +6 -0
- package/dist/lib/templates/python/index-module.eta +18 -0
- package/dist/lib/templates/python/models/model-col-array.eta +4 -0
- package/dist/lib/templates/python/models/model-col-boolean.eta +5 -0
- package/dist/lib/templates/python/models/model-col-date.eta +4 -0
- package/dist/lib/templates/python/models/model-col-decimal.eta +4 -0
- package/dist/lib/templates/python/models/model-col-enum.eta +16 -0
- package/dist/lib/templates/python/models/model-col-float.eta +5 -0
- package/dist/lib/templates/python/models/model-col-integer.eta +6 -0
- package/dist/lib/templates/python/models/model-col-json.eta +4 -0
- package/dist/lib/templates/python/models/model-col-jsonb.eta +4 -0
- package/dist/lib/templates/python/models/model-col-numeric.eta +4 -0
- package/dist/lib/templates/python/models/model-col-string.eta +6 -0
- package/dist/lib/templates/python/models/model-col-text.eta +6 -0
- package/dist/lib/templates/python/models/model-col-timestamp.eta +11 -0
- package/dist/lib/templates/python/models/model-col-timestamptz.eta +11 -0
- package/dist/lib/templates/python/models/model-col-uuid.eta +5 -0
- package/dist/lib/templates/python/models/model-col-varchar.eta +6 -0
- package/dist/lib/templates/python/models/model.eta +124 -0
- package/dist/lib/templates/python/routers/router.eta +206 -0
- package/dist/lib/templates/python/schemas/schema-col-array.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-boolean.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-date.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-decimal.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-enum.eta +6 -0
- package/dist/lib/templates/python/schemas/schema-col-float.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-integer.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-json.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-jsonb.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-numeric.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-string.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-text.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-timestamp.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-timestamptz.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-uuid.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-varchar.eta +1 -0
- package/dist/lib/templates/python/schemas/schema.eta +87 -0
- package/dist/lib/templates/python/services/service.eta +163 -0
- package/dist/lib/templates/rest/controller-rest.eta +13 -12
- package/dist/lib/templates/rest/dto-rest.eta +173 -59
- package/dist/lib/types/generator.d.ts +241 -0
- package/dist/lib/types/generator.js +2 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/utils/casing.d.ts +1 -0
- package/dist/lib/utils/casing.js +11 -1
- package/oclif.manifest.json +32 -3
- package/package.json +4 -2
- package/dist/lib/utils/relationships/parse.spec.d.ts +0 -1
- package/dist/lib/utils/relationships/parse.spec.js +0 -402
- package/dist/tests/templates/entities/types/array-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/array-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/bigint-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/bigint-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/boolean-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/boolean-template.spec.js +0 -77
- package/dist/tests/templates/entities/types/bytea-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/bytea-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/char-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/char-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/date-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/date-template.spec.js +0 -56
- package/dist/tests/templates/entities/types/decimal-field-validation.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/decimal-field-validation.spec.js +0 -100
- package/dist/tests/templates/entities/types/decimal-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/decimal-template.spec.js +0 -86
- package/dist/tests/templates/entities/types/double-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/double-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/enum-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/enum-template.spec.js +0 -85
- package/dist/tests/templates/entities/types/float-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/float-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/geometry-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/geometry-template.spec.js +0 -58
- package/dist/tests/templates/entities/types/inet-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/inet-template.spec.js +0 -69
- package/dist/tests/templates/entities/types/int4range-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/int4range-template.spec.js +0 -72
- package/dist/tests/templates/entities/types/integer-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/integer-template.spec.js +0 -79
- package/dist/tests/templates/entities/types/interval-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/interval-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/json-plain-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/json-plain-template.spec.js +0 -54
- package/dist/tests/templates/entities/types/json-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/json-template.spec.js +0 -40
- package/dist/tests/templates/entities/types/jsonb-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/jsonb-template.spec.js +0 -40
- package/dist/tests/templates/entities/types/money-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/money-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/numeric-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/numeric-template.spec.js +0 -84
- package/dist/tests/templates/entities/types/point-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/point-template.spec.js +0 -64
- package/dist/tests/templates/entities/types/polygon-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/polygon-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/real-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/real-template.spec.js +0 -67
- package/dist/tests/templates/entities/types/serial-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/serial-template.spec.js +0 -113
- package/dist/tests/templates/entities/types/smallint-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/smallint-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/string-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/string-template.spec.js +0 -111
- package/dist/tests/templates/entities/types/text-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/text-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/time-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/time-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/timestamp-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/timestamp-template.spec.js +0 -74
- package/dist/tests/templates/entities/types/timetz-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/timetz-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/tsvector-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/tsvector-template.spec.js +0 -55
- package/dist/tests/templates/entities/types/uuid-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/uuid-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/varchar-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/varchar-template.spec.js +0 -105
- package/dist/tests/templates/entities/types/xml-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/xml-template.spec.js +0 -55
- package/dist/tests/templates/entities/uuid-entity-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/uuid-entity-template.spec.js +0 -277
- package/dist/tests/utils/relationship-deduplication.spec.d.ts +0 -1
- package/dist/tests/utils/relationship-deduplication.spec.js +0 -98
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const Eta = tslib_1.__importStar(require("eta"));
|
|
5
|
-
const path = tslib_1.__importStar(require("path"));
|
|
6
|
-
const globals_1 = require("@jest/globals");
|
|
7
|
-
(0, globals_1.describe)("UUID Entity Template Tests", () => {
|
|
8
|
-
(0, globals_1.beforeAll)(() => {
|
|
9
|
-
Eta.configure({
|
|
10
|
-
views: path.join(__dirname, "../../../lib/templates"),
|
|
11
|
-
cache: false,
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
(0, globals_1.describe)("UUID Primary Key", () => {
|
|
15
|
-
(0, globals_1.it)("should render entity with UUID primary key", async () => {
|
|
16
|
-
const data = {
|
|
17
|
-
name: "User",
|
|
18
|
-
snakeCasedName: "user",
|
|
19
|
-
createPrimaryKey: true,
|
|
20
|
-
primaryKeyType: "uuid",
|
|
21
|
-
createdAt: true,
|
|
22
|
-
updatedAt: true,
|
|
23
|
-
columns: [],
|
|
24
|
-
associations: [],
|
|
25
|
-
indexes: [],
|
|
26
|
-
uniques: [],
|
|
27
|
-
entitiesToImport: [],
|
|
28
|
-
apiType: "rest",
|
|
29
|
-
importEnums: false,
|
|
30
|
-
};
|
|
31
|
-
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
32
|
-
// Should use @Column with uuid type
|
|
33
|
-
(0, globals_1.expect)(rendered).toContain("@Column({ type: 'uuid' })");
|
|
34
|
-
// Should use @PrimaryColumn instead of @PrimaryGeneratedColumn
|
|
35
|
-
(0, globals_1.expect)(rendered).toContain("@PrimaryColumn()");
|
|
36
|
-
(0, globals_1.expect)(rendered).not.toContain("@PrimaryGeneratedColumn()");
|
|
37
|
-
// Should declare id as string
|
|
38
|
-
(0, globals_1.expect)(rendered).toContain("id: string;");
|
|
39
|
-
(0, globals_1.expect)(rendered).not.toContain("id!: number;");
|
|
40
|
-
});
|
|
41
|
-
(0, globals_1.it)("should render entity with serial (auto-increment) primary key", async () => {
|
|
42
|
-
const data = {
|
|
43
|
-
name: "Post",
|
|
44
|
-
snakeCasedName: "post",
|
|
45
|
-
createPrimaryKey: true,
|
|
46
|
-
primaryKeyType: "serial",
|
|
47
|
-
createdAt: true,
|
|
48
|
-
updatedAt: true,
|
|
49
|
-
columns: [],
|
|
50
|
-
associations: [],
|
|
51
|
-
indexes: [],
|
|
52
|
-
uniques: [],
|
|
53
|
-
entitiesToImport: [],
|
|
54
|
-
apiType: "rest",
|
|
55
|
-
importEnums: false,
|
|
56
|
-
};
|
|
57
|
-
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
58
|
-
// Should use @PrimaryGeneratedColumn
|
|
59
|
-
(0, globals_1.expect)(rendered).toContain("@PrimaryGeneratedColumn()");
|
|
60
|
-
(0, globals_1.expect)(rendered).not.toContain("@Column({ type: 'uuid' })");
|
|
61
|
-
(0, globals_1.expect)(rendered).not.toContain("@PrimaryColumn()");
|
|
62
|
-
// Should declare id as number
|
|
63
|
-
(0, globals_1.expect)(rendered).toContain("id!: number;");
|
|
64
|
-
(0, globals_1.expect)(rendered).not.toContain("id: string;");
|
|
65
|
-
});
|
|
66
|
-
(0, globals_1.it)("should default to serial primary key when primaryKeyType is not specified", async () => {
|
|
67
|
-
const data = {
|
|
68
|
-
name: "Comment",
|
|
69
|
-
snakeCasedName: "comment",
|
|
70
|
-
createPrimaryKey: true,
|
|
71
|
-
// primaryKeyType not specified
|
|
72
|
-
createdAt: true,
|
|
73
|
-
updatedAt: true,
|
|
74
|
-
columns: [],
|
|
75
|
-
associations: [],
|
|
76
|
-
indexes: [],
|
|
77
|
-
uniques: [],
|
|
78
|
-
entitiesToImport: [],
|
|
79
|
-
apiType: "rest",
|
|
80
|
-
importEnums: false,
|
|
81
|
-
};
|
|
82
|
-
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
83
|
-
// Should default to serial (auto-increment)
|
|
84
|
-
(0, globals_1.expect)(rendered).toContain("@PrimaryGeneratedColumn()");
|
|
85
|
-
(0, globals_1.expect)(rendered).toContain("id!: number;");
|
|
86
|
-
});
|
|
87
|
-
});
|
|
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
|
-
const data = {
|
|
91
|
-
name: "Account",
|
|
92
|
-
snakeCasedName: "account",
|
|
93
|
-
createPrimaryKey: true,
|
|
94
|
-
primaryKeyType: "serial",
|
|
95
|
-
createdAt: true,
|
|
96
|
-
updatedAt: true,
|
|
97
|
-
columns: [],
|
|
98
|
-
associations: [
|
|
99
|
-
{
|
|
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
|
-
joinTable: false,
|
|
109
|
-
biDirectional: true,
|
|
110
|
-
inverseSidePropertyName: "accounts",
|
|
111
|
-
referencedEntityPrimaryKeyType: "uuid",
|
|
112
|
-
nullable: false,
|
|
113
|
-
index: false,
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
indexes: [],
|
|
117
|
-
uniques: [],
|
|
118
|
-
entitiesToImport: ["User"],
|
|
119
|
-
apiType: "rest",
|
|
120
|
-
importEnums: false,
|
|
121
|
-
};
|
|
122
|
-
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
123
|
-
// Should have ManyToOne decorator
|
|
124
|
-
(0, globals_1.expect)(rendered).toContain("@ManyToOne(() => User");
|
|
125
|
-
// Should have JoinColumn
|
|
126
|
-
(0, globals_1.expect)(rendered).toContain("@JoinColumn({ name: 'userId' })");
|
|
127
|
-
// Should declare relationship property
|
|
128
|
-
(0, globals_1.expect)(rendered).toContain("user: User;");
|
|
129
|
-
// Should have UUID foreign key column
|
|
130
|
-
(0, globals_1.expect)(rendered).toContain('@Column({ type: "uuid"');
|
|
131
|
-
(0, globals_1.expect)(rendered).toContain("userId: string;");
|
|
132
|
-
// Should NOT have integer foreign key
|
|
133
|
-
(0, globals_1.expect)(rendered).not.toContain("userId: number;");
|
|
134
|
-
});
|
|
135
|
-
(0, globals_1.it)("should render ManyToOne relationship with integer foreign key when referenced entity has serial primary key", async () => {
|
|
136
|
-
const data = {
|
|
137
|
-
name: "Post",
|
|
138
|
-
snakeCasedName: "post",
|
|
139
|
-
createPrimaryKey: true,
|
|
140
|
-
primaryKeyType: "serial",
|
|
141
|
-
createdAt: true,
|
|
142
|
-
updatedAt: true,
|
|
143
|
-
columns: [],
|
|
144
|
-
associations: [
|
|
145
|
-
{
|
|
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
|
-
joinTable: false,
|
|
155
|
-
biDirectional: true,
|
|
156
|
-
inverseSidePropertyName: "posts",
|
|
157
|
-
referencedEntityPrimaryKeyType: "serial",
|
|
158
|
-
nullable: false,
|
|
159
|
-
index: true,
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
indexes: [],
|
|
163
|
-
uniques: [],
|
|
164
|
-
entitiesToImport: ["User"],
|
|
165
|
-
apiType: "rest",
|
|
166
|
-
importEnums: false,
|
|
167
|
-
};
|
|
168
|
-
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
169
|
-
// Should have ManyToOne decorator
|
|
170
|
-
(0, globals_1.expect)(rendered).toContain("@ManyToOne(() => User");
|
|
171
|
-
// Should have index since index: true
|
|
172
|
-
(0, globals_1.expect)(rendered).toContain("@Index()");
|
|
173
|
-
// Should have integer foreign key column
|
|
174
|
-
(0, globals_1.expect)(rendered).toContain('@Column({ type: "integer"');
|
|
175
|
-
(0, globals_1.expect)(rendered).toContain("userId: number;");
|
|
176
|
-
// Should NOT have UUID foreign key
|
|
177
|
-
(0, globals_1.expect)(rendered).not.toContain("userId: string;");
|
|
178
|
-
});
|
|
179
|
-
(0, globals_1.it)("should handle nullable UUID foreign keys", async () => {
|
|
180
|
-
const data = {
|
|
181
|
-
name: "Profile",
|
|
182
|
-
snakeCasedName: "profile",
|
|
183
|
-
createPrimaryKey: true,
|
|
184
|
-
primaryKeyType: "uuid",
|
|
185
|
-
createdAt: true,
|
|
186
|
-
updatedAt: true,
|
|
187
|
-
columns: [],
|
|
188
|
-
associations: [
|
|
189
|
-
{
|
|
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
|
-
joinTable: false,
|
|
199
|
-
biDirectional: false,
|
|
200
|
-
referencedEntityPrimaryKeyType: "uuid",
|
|
201
|
-
nullable: true,
|
|
202
|
-
index: false,
|
|
203
|
-
},
|
|
204
|
-
],
|
|
205
|
-
indexes: [],
|
|
206
|
-
uniques: [],
|
|
207
|
-
entitiesToImport: ["Organization"],
|
|
208
|
-
apiType: "rest",
|
|
209
|
-
importEnums: false,
|
|
210
|
-
};
|
|
211
|
-
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
212
|
-
// Should have nullable UUID foreign key
|
|
213
|
-
(0, globals_1.expect)(rendered).toContain('@Column({ type: "uuid", nullable: true');
|
|
214
|
-
(0, globals_1.expect)(rendered).toContain("organizationId: string;");
|
|
215
|
-
});
|
|
216
|
-
(0, globals_1.it)("should handle multiple relationships with mixed UUID and serial foreign keys", async () => {
|
|
217
|
-
const data = {
|
|
218
|
-
name: "Comment",
|
|
219
|
-
snakeCasedName: "comment",
|
|
220
|
-
createPrimaryKey: true,
|
|
221
|
-
primaryKeyType: "serial",
|
|
222
|
-
createdAt: true,
|
|
223
|
-
updatedAt: true,
|
|
224
|
-
columns: [],
|
|
225
|
-
associations: [
|
|
226
|
-
{
|
|
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
|
-
joinTable: false,
|
|
236
|
-
biDirectional: true,
|
|
237
|
-
inverseSidePropertyName: "comments",
|
|
238
|
-
referencedEntityPrimaryKeyType: "uuid",
|
|
239
|
-
nullable: false,
|
|
240
|
-
index: true,
|
|
241
|
-
},
|
|
242
|
-
{
|
|
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
|
-
joinTable: false,
|
|
252
|
-
biDirectional: true,
|
|
253
|
-
inverseSidePropertyName: "comments",
|
|
254
|
-
referencedEntityPrimaryKeyType: "serial",
|
|
255
|
-
nullable: false,
|
|
256
|
-
index: true,
|
|
257
|
-
},
|
|
258
|
-
],
|
|
259
|
-
indexes: [],
|
|
260
|
-
uniques: [],
|
|
261
|
-
entitiesToImport: ["User", "Post"],
|
|
262
|
-
apiType: "rest",
|
|
263
|
-
importEnums: false,
|
|
264
|
-
};
|
|
265
|
-
const rendered = await Eta.renderFileAsync("./entities/entity", data);
|
|
266
|
-
// Should have UUID foreign key for User
|
|
267
|
-
(0, globals_1.expect)(rendered).toContain('@Column({ type: "uuid"');
|
|
268
|
-
(0, globals_1.expect)(rendered).toContain("userId: string;");
|
|
269
|
-
// Should have integer foreign key for Post
|
|
270
|
-
(0, globals_1.expect)(rendered).toContain('@Column({ type: "integer"');
|
|
271
|
-
(0, globals_1.expect)(rendered).toContain("postId: number;");
|
|
272
|
-
// Should have both relationships
|
|
273
|
-
(0, globals_1.expect)(rendered).toContain("user: User;");
|
|
274
|
-
(0, globals_1.expect)(rendered).toContain("post: Post;");
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,98 +0,0 @@
|
|
|
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
|
-
// New behavior: Both relationships with different referenceName should be kept
|
|
64
|
-
(0, globals_1.expect)(result.length).toBe(2);
|
|
65
|
-
const referenceNames = result.map((r) => r.relationshipName || r.referenceName);
|
|
66
|
-
(0, globals_1.expect)(referenceNames).toContain("workspaces");
|
|
67
|
-
(0, globals_1.expect)(referenceNames).toContain("ownedWorkspaces");
|
|
68
|
-
});
|
|
69
|
-
(0, globals_1.test)("should prioritize owner side (join=true) when deduplicating", () => {
|
|
70
|
-
// Scenario based on real issue: two ManyToMany relationships to same entity
|
|
71
|
-
const entityName = "Tag";
|
|
72
|
-
// Create relationships where one has join=true and one has join=false (non-owning side)
|
|
73
|
-
const mockRelationships = [
|
|
74
|
-
{
|
|
75
|
-
name: "WorkspaceService",
|
|
76
|
-
type: "ManyToMany",
|
|
77
|
-
biDirectional: true,
|
|
78
|
-
join: false,
|
|
79
|
-
referenceName: "workspaceservices",
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
name: "WorkspaceService",
|
|
83
|
-
type: "ManyToMany",
|
|
84
|
-
biDirectional: true,
|
|
85
|
-
join: true,
|
|
86
|
-
referenceName: "workspaceservices",
|
|
87
|
-
},
|
|
88
|
-
];
|
|
89
|
-
// Run the function
|
|
90
|
-
const result = (0, parse_1.getRelationshipForTemplate)(entityName, mockRelationships);
|
|
91
|
-
// Assertions
|
|
92
|
-
// Should only have one relationship
|
|
93
|
-
(0, globals_1.expect)(result.length).toBe(1);
|
|
94
|
-
// Should be the one with join=true
|
|
95
|
-
(0, globals_1.expect)(result[0].name).toBe("WorkspaceService");
|
|
96
|
-
(0, globals_1.expect)(result[0].joinTable).toBe(true); // joinTable corresponds to join
|
|
97
|
-
});
|
|
98
|
-
});
|