@apso/cli 0.0.5 → 0.0.43

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.
Files changed (194) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +313 -53
  3. package/bin/dev +17 -0
  4. package/bin/dev.cmd +3 -0
  5. package/bin/run +3 -3
  6. package/dist/commands/server/new.d.ts +22 -0
  7. package/dist/commands/server/new.js +105 -0
  8. package/dist/commands/server/scaffold.d.ts +14 -0
  9. package/dist/commands/server/scaffold.js +60 -0
  10. package/dist/index.d.ts +1 -0
  11. package/{lib → dist}/index.js +3 -2
  12. package/dist/lib/apsorc-parser.d.ts +26 -0
  13. package/dist/lib/apsorc-parser.js +65 -0
  14. package/dist/lib/base-command.d.ts +4 -0
  15. package/dist/lib/base-command.js +24 -0
  16. package/dist/lib/controller.d.ts +2 -0
  17. package/dist/lib/controller.js +36 -0
  18. package/dist/lib/dto.d.ts +7 -0
  19. package/dist/lib/dto.js +49 -0
  20. package/dist/lib/entity.d.ts +2 -0
  21. package/dist/lib/entity.js +43 -0
  22. package/dist/lib/enums.d.ts +6 -0
  23. package/dist/lib/enums.js +31 -0
  24. package/dist/lib/gql-dto.d.ts +3 -0
  25. package/dist/lib/gql-dto.js +43 -0
  26. package/dist/lib/index-module.d.ts +2 -0
  27. package/dist/lib/index-module.js +18 -0
  28. package/dist/lib/index.d.ts +10 -0
  29. package/dist/lib/index.js +21 -0
  30. package/dist/lib/module.d.ts +1 -0
  31. package/dist/lib/module.js +28 -0
  32. package/dist/lib/service.d.ts +1 -0
  33. package/dist/lib/service.js +24 -0
  34. package/dist/lib/templates/entities/entity-col-array.eta +12 -0
  35. package/dist/lib/templates/entities/entity-col-bigint.eta +11 -0
  36. package/dist/lib/templates/entities/entity-col-bigserial.eta +12 -0
  37. package/dist/lib/templates/entities/entity-col-boolean.eta +11 -0
  38. package/dist/lib/templates/entities/entity-col-bytea.eta +11 -0
  39. package/dist/lib/templates/entities/entity-col-char.eta +15 -0
  40. package/dist/lib/templates/entities/entity-col-date.eta +8 -0
  41. package/dist/lib/templates/entities/entity-col-decimal.eta +11 -0
  42. package/dist/lib/templates/entities/entity-col-double.eta +11 -0
  43. package/dist/lib/templates/entities/entity-col-enum.eta +12 -0
  44. package/dist/lib/templates/entities/entity-col-float.eta +7 -0
  45. package/dist/lib/templates/entities/entity-col-inet.eta +11 -0
  46. package/dist/lib/templates/entities/entity-col-int4range.eta +34 -0
  47. package/dist/lib/templates/entities/entity-col-integer.eta +11 -0
  48. package/dist/lib/templates/entities/entity-col-interval.eta +11 -0
  49. package/dist/lib/templates/entities/entity-col-json-plain.eta +8 -0
  50. package/dist/lib/templates/entities/entity-col-json.eta +5 -0
  51. package/dist/lib/templates/entities/entity-col-jsonb.eta +5 -0
  52. package/dist/lib/templates/entities/entity-col-money.eta +11 -0
  53. package/dist/lib/templates/entities/entity-col-numeric.eta +11 -0
  54. package/dist/lib/templates/entities/entity-col-point.eta +25 -0
  55. package/dist/lib/templates/entities/entity-col-real.eta +11 -0
  56. package/dist/lib/templates/entities/entity-col-serial.eta +12 -0
  57. package/dist/lib/templates/entities/entity-col-smallint.eta +11 -0
  58. package/dist/lib/templates/entities/entity-col-smallserial.eta +12 -0
  59. package/dist/lib/templates/entities/entity-col-string.eta +23 -0
  60. package/dist/lib/templates/entities/entity-col-text.eta +23 -0
  61. package/dist/lib/templates/entities/entity-col-time.eta +11 -0
  62. package/dist/lib/templates/entities/entity-col-timestamp.eta +4 -0
  63. package/dist/lib/templates/entities/entity-col-timestamptz.eta +4 -0
  64. package/dist/lib/templates/entities/entity-col-timetz.eta +11 -0
  65. package/dist/lib/templates/entities/entity-col-tsvector.eta +11 -0
  66. package/dist/lib/templates/entities/entity-col-uuid.eta +11 -0
  67. package/dist/lib/templates/entities/entity-col-varchar.eta +18 -0
  68. package/dist/lib/templates/entities/entity-col-xml.eta +11 -0
  69. package/dist/lib/templates/entities/entity.eta +116 -0
  70. package/dist/lib/templates/graphql/dto/dto-col-array.eta +4 -0
  71. package/dist/lib/templates/graphql/dto/dto-col-boolean.eta +6 -0
  72. package/dist/lib/templates/graphql/dto/dto-col-date.eta +4 -0
  73. package/dist/lib/templates/graphql/dto/dto-col-enum.eta +5 -0
  74. package/dist/lib/templates/graphql/dto/dto-col-float.eta +4 -0
  75. package/dist/lib/templates/graphql/dto/dto-col-integer.eta +4 -0
  76. package/dist/lib/templates/graphql/dto/dto-col-json-plain.eta +5 -0
  77. package/dist/lib/templates/graphql/dto/dto-col-json.eta +5 -0
  78. package/dist/lib/templates/graphql/dto/dto-col-text.eta +11 -0
  79. package/dist/lib/templates/graphql/dto/dto-col-timestamp.eta +3 -0
  80. package/dist/lib/templates/graphql/dto/dto-col-timestamptz.eta +3 -0
  81. package/dist/lib/templates/graphql/enums-graphql.eta +12 -0
  82. package/dist/lib/templates/graphql/gql-dto-graphql.eta +67 -0
  83. package/dist/lib/templates/graphql/index-module-graphql.eta +26 -0
  84. package/dist/lib/templates/graphql/module-graphql.eta +19 -0
  85. package/dist/lib/templates/header.eta +3 -0
  86. package/dist/lib/templates/rest/controller-rest-spec.eta +77 -0
  87. package/dist/lib/templates/rest/controller-rest.eta +171 -0
  88. package/dist/lib/templates/rest/dto-rest.eta +48 -0
  89. package/dist/lib/templates/rest/enums-rest.eta +7 -0
  90. package/dist/lib/templates/rest/index-module-rest.eta +11 -0
  91. package/dist/lib/templates/rest/module-rest.eta +16 -0
  92. package/dist/lib/templates/rest/ormconfig.eta +9 -0
  93. package/dist/lib/templates/rest/service-rest.eta +25 -0
  94. package/dist/lib/types/constraints.d.ts +4 -0
  95. package/dist/lib/types/constraints.js +2 -0
  96. package/dist/lib/types/entity.d.ts +13 -0
  97. package/dist/lib/types/entity.js +2 -0
  98. package/dist/lib/types/field.d.ts +16 -0
  99. package/dist/lib/types/field.js +2 -0
  100. package/dist/lib/types/index.d.ts +5 -0
  101. package/dist/lib/types/index.js +2 -0
  102. package/dist/lib/types/indices.d.ts +4 -0
  103. package/dist/lib/types/indices.js +2 -0
  104. package/dist/lib/types/json.d.ts +3 -0
  105. package/dist/lib/types/json.js +2 -0
  106. package/dist/lib/types/relationship.d.ts +43 -0
  107. package/dist/lib/types/relationship.js +2 -0
  108. package/dist/lib/utils/casing.d.ts +2 -0
  109. package/dist/lib/utils/casing.js +16 -0
  110. package/dist/lib/utils/field.d.ts +6 -0
  111. package/dist/lib/utils/field.js +65 -0
  112. package/dist/lib/utils/file-system.d.ts +2 -0
  113. package/dist/lib/utils/file-system.js +52 -0
  114. package/dist/lib/utils/relationships/index.d.ts +2 -0
  115. package/dist/lib/utils/relationships/index.js +11 -0
  116. package/dist/lib/utils/relationships/parse-v1.d.ts +4 -0
  117. package/dist/lib/utils/relationships/parse-v1.js +86 -0
  118. package/dist/lib/utils/relationships/parse.d.ts +11 -0
  119. package/dist/lib/utils/relationships/parse.js +192 -0
  120. package/dist/tests/templates/entities/types/array-template.spec.d.ts +1 -0
  121. package/dist/tests/templates/entities/types/array-template.spec.js +82 -0
  122. package/dist/tests/templates/entities/types/bigint-template.spec.d.ts +1 -0
  123. package/dist/tests/templates/entities/types/bigint-template.spec.js +82 -0
  124. package/dist/tests/templates/entities/types/boolean-template.spec.d.ts +1 -0
  125. package/dist/tests/templates/entities/types/boolean-template.spec.js +77 -0
  126. package/dist/tests/templates/entities/types/bytea-template.spec.d.ts +1 -0
  127. package/dist/tests/templates/entities/types/bytea-template.spec.js +68 -0
  128. package/dist/tests/templates/entities/types/char-template.spec.d.ts +1 -0
  129. package/dist/tests/templates/entities/types/char-template.spec.js +68 -0
  130. package/dist/tests/templates/entities/types/date-template.spec.d.ts +1 -0
  131. package/dist/tests/templates/entities/types/date-template.spec.js +56 -0
  132. package/dist/tests/templates/entities/types/decimal-template.spec.d.ts +1 -0
  133. package/dist/tests/templates/entities/types/decimal-template.spec.js +86 -0
  134. package/dist/tests/templates/entities/types/double-template.spec.d.ts +1 -0
  135. package/dist/tests/templates/entities/types/double-template.spec.js +67 -0
  136. package/dist/tests/templates/entities/types/enum-template.spec.d.ts +1 -0
  137. package/dist/tests/templates/entities/types/enum-template.spec.js +85 -0
  138. package/dist/tests/templates/entities/types/float-template.spec.d.ts +1 -0
  139. package/dist/tests/templates/entities/types/float-template.spec.js +67 -0
  140. package/dist/tests/templates/entities/types/inet-template.spec.d.ts +1 -0
  141. package/dist/tests/templates/entities/types/inet-template.spec.js +69 -0
  142. package/dist/tests/templates/entities/types/int4range-template.spec.d.ts +1 -0
  143. package/dist/tests/templates/entities/types/int4range-template.spec.js +60 -0
  144. package/dist/tests/templates/entities/types/integer-template.spec.d.ts +1 -0
  145. package/dist/tests/templates/entities/types/integer-template.spec.js +79 -0
  146. package/dist/tests/templates/entities/types/interval-template.spec.d.ts +1 -0
  147. package/dist/tests/templates/entities/types/interval-template.spec.js +68 -0
  148. package/dist/tests/templates/entities/types/json-plain-template.spec.d.ts +1 -0
  149. package/dist/tests/templates/entities/types/json-plain-template.spec.js +54 -0
  150. package/dist/tests/templates/entities/types/json-template.spec.d.ts +1 -0
  151. package/dist/tests/templates/entities/types/json-template.spec.js +40 -0
  152. package/dist/tests/templates/entities/types/jsonb-template.spec.d.ts +1 -0
  153. package/dist/tests/templates/entities/types/jsonb-template.spec.js +40 -0
  154. package/dist/tests/templates/entities/types/money-template.spec.d.ts +1 -0
  155. package/dist/tests/templates/entities/types/money-template.spec.js +68 -0
  156. package/dist/tests/templates/entities/types/numeric-template.spec.d.ts +1 -0
  157. package/dist/tests/templates/entities/types/numeric-template.spec.js +84 -0
  158. package/dist/tests/templates/entities/types/point-template.spec.d.ts +1 -0
  159. package/dist/tests/templates/entities/types/point-template.spec.js +58 -0
  160. package/dist/tests/templates/entities/types/real-template.spec.d.ts +1 -0
  161. package/dist/tests/templates/entities/types/real-template.spec.js +67 -0
  162. package/dist/tests/templates/entities/types/serial-template.spec.d.ts +1 -0
  163. package/dist/tests/templates/entities/types/serial-template.spec.js +113 -0
  164. package/dist/tests/templates/entities/types/smallint-template.spec.d.ts +1 -0
  165. package/dist/tests/templates/entities/types/smallint-template.spec.js +82 -0
  166. package/dist/tests/templates/entities/types/string-template.spec.d.ts +1 -0
  167. package/dist/tests/templates/entities/types/string-template.spec.js +111 -0
  168. package/dist/tests/templates/entities/types/text-template.spec.d.ts +1 -0
  169. package/dist/tests/templates/entities/types/text-template.spec.js +70 -0
  170. package/dist/tests/templates/entities/types/time-template.spec.d.ts +1 -0
  171. package/dist/tests/templates/entities/types/time-template.spec.js +68 -0
  172. package/dist/tests/templates/entities/types/timestamp-template.spec.d.ts +1 -0
  173. package/dist/tests/templates/entities/types/timestamp-template.spec.js +74 -0
  174. package/dist/tests/templates/entities/types/timetz-template.spec.d.ts +1 -0
  175. package/dist/tests/templates/entities/types/timetz-template.spec.js +68 -0
  176. package/dist/tests/templates/entities/types/tsvector-template.spec.d.ts +1 -0
  177. package/dist/tests/templates/entities/types/tsvector-template.spec.js +55 -0
  178. package/dist/tests/templates/entities/types/uuid-template.spec.d.ts +1 -0
  179. package/dist/tests/templates/entities/types/uuid-template.spec.js +82 -0
  180. package/dist/tests/templates/entities/types/varchar-template.spec.d.ts +1 -0
  181. package/dist/tests/templates/entities/types/varchar-template.spec.js +102 -0
  182. package/dist/tests/templates/entities/types/xml-template.spec.d.ts +1 -0
  183. package/dist/tests/templates/entities/types/xml-template.spec.js +55 -0
  184. package/dist/tests/templates/entities/utils/template-test-utils.d.ts +31 -0
  185. package/dist/tests/templates/entities/utils/template-test-utils.js +50 -0
  186. package/oclif.manifest.json +60 -1
  187. package/package.json +84 -55
  188. package/lib/commands/new.d.ts +0 -22
  189. package/lib/commands/new.js +0 -198
  190. package/lib/commands/scaffold.d.ts +0 -18
  191. package/lib/commands/scaffold.js +0 -106
  192. package/lib/index.d.ts +0 -1
  193. package/lib/lib/scaffold.d.ts +0 -30
  194. package/lib/lib/scaffold.js +0 -566
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseV1Relationships = exports.getRelationshipIdField = exports.getNestedRelationships = exports.getRelationshipForTemplate = exports.getRelationshipsForImport = exports.parseRelationships = void 0;
4
+ var parse_1 = require("./parse");
5
+ Object.defineProperty(exports, "parseRelationships", { enumerable: true, get: function () { return parse_1.parseRelationships; } });
6
+ Object.defineProperty(exports, "getRelationshipsForImport", { enumerable: true, get: function () { return parse_1.getRelationshipsForImport; } });
7
+ Object.defineProperty(exports, "getRelationshipForTemplate", { enumerable: true, get: function () { return parse_1.getRelationshipForTemplate; } });
8
+ Object.defineProperty(exports, "getNestedRelationships", { enumerable: true, get: function () { return parse_1.getNestedRelationships; } });
9
+ Object.defineProperty(exports, "getRelationshipIdField", { enumerable: true, get: function () { return parse_1.getRelationshipIdField; } });
10
+ var parse_v1_1 = require("./parse-v1");
11
+ Object.defineProperty(exports, "parseV1Relationships", { enumerable: true, get: function () { return parse_v1_1.parseV1Relationships; } });
@@ -0,0 +1,4 @@
1
+ import { Association, Entity, RelationshipMap } from "../../types";
2
+ export declare const isInverseRelationshipDefined: (entityName: string, association: Association, entities: Entity[]) => boolean;
3
+ export declare const getInverseRelationship: (entityName: string, association: Association, entities: Entity[]) => Association | null;
4
+ export declare const parseV1Relationships: (entities: Entity[]) => RelationshipMap;
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseV1Relationships = exports.getInverseRelationship = exports.isInverseRelationshipDefined = void 0;
4
+ const parse_1 = require("./parse");
5
+ const InverseType = {
6
+ OneToOne: "OneToOne",
7
+ OneToMany: "ManyToOne",
8
+ ManyToOne: "OneToMany",
9
+ ManyToMany: "ManyToMany",
10
+ };
11
+ const isInverseRelationshipDefined = (entityName, association, entities) => {
12
+ if (entityName === association.name) {
13
+ return false;
14
+ }
15
+ return Boolean((0, exports.getInverseRelationship)(entityName, association, entities));
16
+ };
17
+ exports.isInverseRelationshipDefined = isInverseRelationshipDefined;
18
+ const getInverseRelationship = (entityName, association, entities) => {
19
+ var _a, _b;
20
+ if (entityName === association.name) {
21
+ return null;
22
+ }
23
+ const inverseAssociationType = InverseType[association.type];
24
+ const isInverse = (testAssocation) => testAssocation.name === entityName &&
25
+ testAssocation.type === inverseAssociationType;
26
+ return (((_b = (_a = entities
27
+ .find((entity) => entity.name === association.name)) === null || _a === void 0 ? void 0 : _a.associations) === null || _b === void 0 ? void 0 : _b.find(isInverse)) || null);
28
+ };
29
+ exports.getInverseRelationship = getInverseRelationship;
30
+ const convertAssociationToRelationship = (entityName, association, entities) => {
31
+ const inverseRelation = (0, exports.getInverseRelationship)(entityName, association, entities);
32
+ let biDirectional = Boolean(inverseRelation);
33
+ let index = association.index;
34
+ if (association.type === "OneToMany" && inverseRelation) {
35
+ index = inverseRelation.index || false;
36
+ }
37
+ if (association.type === "ManyToOne" && biDirectional) {
38
+ return null;
39
+ }
40
+ if (association.type === "ManyToMany" && inverseRelation) {
41
+ if (association.join_table !== true &&
42
+ inverseRelation.join_table === true) {
43
+ return null;
44
+ }
45
+ if (association.join_table === true &&
46
+ inverseRelation.join_table === true) {
47
+ // Both ManyToMany sides have join_table set to true
48
+ biDirectional = false;
49
+ }
50
+ }
51
+ const inverseNullable = (inverseRelation && inverseRelation.nullable) || false;
52
+ return {
53
+ from: entityName,
54
+ to: association.name,
55
+ type: association.type,
56
+ /* eslint-disable-next-line camelcase */
57
+ to_name: association.reference_name,
58
+ nullable: association.nullable || inverseNullable,
59
+ /* eslint-disable-next-line camelcase */
60
+ bi_directional: biDirectional,
61
+ index,
62
+ };
63
+ };
64
+ const parseV1Relationships = (entities) => {
65
+ const relationshipMap = {};
66
+ for (const entity of entities) {
67
+ if (!entity.associations) {
68
+ continue;
69
+ }
70
+ for (const association of entity.associations) {
71
+ const apsorcRelationship = convertAssociationToRelationship(entity.name, association, entities);
72
+ if (apsorcRelationship === null) {
73
+ continue;
74
+ }
75
+ const parsedResult = (0, parse_1.parseRelationship)(apsorcRelationship);
76
+ for (const key of Object.keys(parsedResult)) {
77
+ relationshipMap[key] = [
78
+ ...(relationshipMap[key] || []),
79
+ ...parsedResult[key],
80
+ ];
81
+ }
82
+ }
83
+ }
84
+ return relationshipMap;
85
+ };
86
+ exports.parseV1Relationships = parseV1Relationships;
@@ -0,0 +1,11 @@
1
+ import { ApsorcRelationship, Relationship, RelationshipMap, RelationshipForTemplate } from "../../types";
2
+ export declare const parseOneToMany: (relationship: ApsorcRelationship) => RelationshipMap;
3
+ export declare const parseManytoOne: (relationship: ApsorcRelationship) => RelationshipMap;
4
+ export declare const parseManyToMany: (relationship: ApsorcRelationship) => RelationshipMap;
5
+ export declare const parseOneToOne: (relationship: ApsorcRelationship) => RelationshipMap;
6
+ export declare const parseRelationship: (relationship: ApsorcRelationship) => RelationshipMap;
7
+ export declare const parseRelationships: (relationships: ApsorcRelationship[]) => RelationshipMap;
8
+ export declare const getRelationshipIdField: (relationship: Relationship) => string;
9
+ export declare const getRelationshipForTemplate: (entityName: string, relationships: Relationship[]) => RelationshipForTemplate[];
10
+ export declare const getNestedRelationships: (entityName: string, relationshipMap: RelationshipMap, prefix?: string, visited?: Set<string>) => string[];
11
+ export declare const getRelationshipsForImport: (entityName: string, relationships?: Relationship[]) => string[];
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRelationshipsForImport = exports.getNestedRelationships = exports.getRelationshipForTemplate = exports.getRelationshipIdField = exports.parseRelationships = exports.parseRelationship = exports.parseOneToOne = exports.parseManyToMany = exports.parseManytoOne = exports.parseOneToMany = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
6
+ const casing_1 = require("../../utils/casing");
7
+ const parseOneToMany = (relationship) => {
8
+ return {
9
+ [relationship.from]: [
10
+ {
11
+ name: relationship.to,
12
+ type: "OneToMany",
13
+ biDirectional: true
14
+ },
15
+ ],
16
+ [relationship.to]: [
17
+ {
18
+ name: relationship.from,
19
+ type: "ManyToOne",
20
+ nullable: relationship.nullable || false,
21
+ biDirectional: true,
22
+ index: relationship.index || false,
23
+ cascadeDelete: relationship.cascadeDelete || false
24
+ },
25
+ ],
26
+ };
27
+ };
28
+ exports.parseOneToMany = parseOneToMany;
29
+ const parseManytoOne = (relationship) => {
30
+ return {
31
+ [relationship.from]: [
32
+ {
33
+ name: relationship.to,
34
+ type: "ManyToOne",
35
+ referenceName: relationship.to_name || null,
36
+ nullable: relationship.nullable || false,
37
+ index: relationship.index || false,
38
+ },
39
+ ],
40
+ };
41
+ };
42
+ exports.parseManytoOne = parseManytoOne;
43
+ const parseManyToMany = (relationship) => {
44
+ const response = {
45
+ [relationship.from]: [
46
+ {
47
+ name: relationship.to,
48
+ type: "ManyToMany",
49
+ referenceName: relationship.to_name || null,
50
+ join: true,
51
+ biDirectional: relationship.bi_directional || false,
52
+ },
53
+ ],
54
+ };
55
+ if (relationship.bi_directional) {
56
+ response[relationship.to] = [
57
+ {
58
+ name: relationship.from,
59
+ type: "ManyToMany",
60
+ biDirectional: true,
61
+ },
62
+ ];
63
+ }
64
+ return response;
65
+ };
66
+ exports.parseManyToMany = parseManyToMany;
67
+ const parseOneToOne = (relationship) => {
68
+ const response = {
69
+ [relationship.from]: [
70
+ {
71
+ name: relationship.to,
72
+ type: "OneToOne",
73
+ join: true,
74
+ nullable: relationship.nullable || false,
75
+ referenceName: relationship.to_name || null,
76
+ biDirectional: relationship.bi_directional || false,
77
+ },
78
+ ],
79
+ };
80
+ if (relationship.bi_directional) {
81
+ response[relationship.to] = [
82
+ {
83
+ name: relationship.from,
84
+ type: "OneToOne",
85
+ biDirectional: true,
86
+ },
87
+ ];
88
+ }
89
+ return response;
90
+ };
91
+ exports.parseOneToOne = parseOneToOne;
92
+ const parseRelationship = (relationship) => {
93
+ switch (relationship.type) {
94
+ case "OneToMany":
95
+ return (0, exports.parseOneToMany)(relationship);
96
+ case "ManyToOne":
97
+ return (0, exports.parseManytoOne)(relationship);
98
+ case "ManyToMany":
99
+ return (0, exports.parseManyToMany)(relationship);
100
+ case "OneToOne":
101
+ return (0, exports.parseOneToOne)(relationship);
102
+ }
103
+ return {};
104
+ };
105
+ exports.parseRelationship = parseRelationship;
106
+ const parseRelationships = (relationships) => {
107
+ const response = {};
108
+ for (const rel of relationships) {
109
+ const parsedResult = (0, exports.parseRelationship)(rel);
110
+ for (const key of Object.keys(parsedResult)) {
111
+ response[key] = [...(response[key] || []), ...parsedResult[key]];
112
+ }
113
+ }
114
+ return response;
115
+ };
116
+ exports.parseRelationships = parseRelationships;
117
+ const getRelationshipName = (relationship) => {
118
+ if (relationship.referenceName) {
119
+ return (0, casing_1.camelCase)(relationship.referenceName);
120
+ }
121
+ return (0, casing_1.camelCase)(relationship.name);
122
+ };
123
+ const getRelationshipIdField = (relationship) => {
124
+ return `${getRelationshipName(relationship)}Id`;
125
+ };
126
+ exports.getRelationshipIdField = getRelationshipIdField;
127
+ const getRelationshipForTemplate = (entityName, relationships) => {
128
+ if (!relationships) {
129
+ return [];
130
+ }
131
+ return relationships.map((relationship) => {
132
+ const relationshipName = getRelationshipName(relationship);
133
+ return {
134
+ ...relationship,
135
+ relationshipName,
136
+ pluralizedRelationshipName: (0, pluralize_1.default)(relationshipName),
137
+ pluralizedName: (0, pluralize_1.default)((0, casing_1.camelCase)(relationship.name)),
138
+ camelCasedName: (0, casing_1.camelCase)(relationship.name),
139
+ camelCasedId: (0, exports.getRelationshipIdField)(relationship),
140
+ entityName: (0, casing_1.camelCase)(entityName),
141
+ joinTable: relationship.join || false,
142
+ biDirectional: relationship.biDirectional || false,
143
+ cascadeDelete: relationship.cascadeDelete || false,
144
+ };
145
+ });
146
+ };
147
+ exports.getRelationshipForTemplate = getRelationshipForTemplate;
148
+ const getNestedRelationships = (entityName, relationshipMap, prefix = "", visited = new Set()) => {
149
+ const relationships = [];
150
+ if (visited.has(entityName)) {
151
+ return relationships;
152
+ }
153
+ const currentRelationships = relationshipMap[entityName];
154
+ if (!currentRelationships)
155
+ return relationships;
156
+ visited.add(entityName);
157
+ for (const relationship of currentRelationships) {
158
+ const { name: relationshipName, type } = relationship;
159
+ const referenceName = getRelationshipName(relationship);
160
+ const formattedName = type === "ManyToOne" || type === "OneToOne"
161
+ ? (0, casing_1.camelCase)(referenceName)
162
+ : (0, pluralize_1.default)((0, casing_1.camelCase)(referenceName));
163
+ const relationshipPath = prefix
164
+ ? `${prefix}.${formattedName}`
165
+ : formattedName;
166
+ const hasChild = relationshipPath.includes(".");
167
+ const exists = prefix
168
+ .split(".")
169
+ .some((a) => a === (0, casing_1.camelCase)(referenceName) ||
170
+ a === (0, pluralize_1.default)((0, casing_1.camelCase)(referenceName)));
171
+ const deepEnough = prefix.split(".").length >= 4;
172
+ const canAdd = hasChild && !exists && !deepEnough;
173
+ if (canAdd) {
174
+ relationships.push(relationshipPath);
175
+ }
176
+ const nestedRelationships = (0, exports.getNestedRelationships)(relationshipName, relationshipMap, relationshipPath, new Set(visited));
177
+ relationships.push(...nestedRelationships);
178
+ }
179
+ return relationships;
180
+ };
181
+ exports.getNestedRelationships = getNestedRelationships;
182
+ const getRelationshipsForImport = (entityName, relationships) => {
183
+ if (relationships === undefined) {
184
+ return [];
185
+ }
186
+ return [
187
+ ...new Set(relationships
188
+ .map((relationship) => relationship.name)
189
+ .filter((relationshipName) => relationshipName !== entityName)),
190
+ ];
191
+ };
192
+ exports.getRelationshipsForImport = getRelationshipsForImport;
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const template_test_utils_1 = require("../utils/template-test-utils");
4
+ const globals_1 = require("@jest/globals");
5
+ (0, globals_1.describe)('Array Entity Template Tests', () => {
6
+ // Setup Eta configuration once before all tests
7
+ (0, globals_1.beforeAll)(() => {
8
+ (0, template_test_utils_1.configureEta)();
9
+ });
10
+ const templatePath = './entities/entity-col-array';
11
+ const testCases = [
12
+ {
13
+ name: 'should render basic text array field correctly',
14
+ field: {
15
+ name: 'tags',
16
+ dataType: 'string[]',
17
+ nullable: false
18
+ },
19
+ assertions: [
20
+ { type: 'contains', text: '@Column({' },
21
+ { type: 'contains', text: 'type: "text"' },
22
+ { type: 'contains', text: 'array: true' },
23
+ { type: 'contains', text: 'tags: string[];' },
24
+ { type: 'notContains', text: 'nullable: true' }
25
+ ]
26
+ },
27
+ {
28
+ name: 'should render nullable array field correctly',
29
+ field: {
30
+ name: 'optionalTags',
31
+ dataType: 'string[]',
32
+ nullable: true
33
+ },
34
+ assertions: [
35
+ { type: 'contains', text: 'nullable: true' },
36
+ { type: 'contains', text: 'optionalTags: string[];' }
37
+ ]
38
+ },
39
+ {
40
+ name: 'should render indexed array field correctly',
41
+ field: {
42
+ name: 'categories',
43
+ dataType: 'string[]',
44
+ nullable: false,
45
+ index: true
46
+ },
47
+ assertions: [
48
+ { type: 'contains', text: '@Index()' },
49
+ { type: 'contains', text: 'categories: string[];' }
50
+ ]
51
+ },
52
+ {
53
+ name: 'should render integer array field correctly',
54
+ field: {
55
+ name: 'scores',
56
+ dataType: 'number[]',
57
+ elementType: 'int',
58
+ nullable: false
59
+ },
60
+ assertions: [
61
+ { type: 'contains', text: 'type: "int"' },
62
+ { type: 'contains', text: 'array: true' },
63
+ { type: 'contains', text: 'scores: number[];' }
64
+ ]
65
+ },
66
+ {
67
+ name: 'should render decimal array field correctly',
68
+ field: {
69
+ name: 'amounts',
70
+ dataType: 'number[]',
71
+ elementType: 'decimal',
72
+ nullable: false
73
+ },
74
+ assertions: [
75
+ { type: 'contains', text: 'type: "decimal"' },
76
+ { type: 'contains', text: 'array: true' },
77
+ { type: 'contains', text: 'amounts: number[];' }
78
+ ]
79
+ }
80
+ ];
81
+ (0, template_test_utils_1.runTemplateTests)(templatePath, testCases);
82
+ });
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const template_test_utils_1 = require("../utils/template-test-utils");
4
+ const globals_1 = require("@jest/globals");
5
+ (0, globals_1.describe)('BigInt Entity Template Tests', () => {
6
+ // Setup Eta configuration once before all tests
7
+ (0, globals_1.beforeAll)(() => {
8
+ (0, template_test_utils_1.configureEta)();
9
+ });
10
+ const templatePath = './entities/entity-col-bigint';
11
+ const testCases = [
12
+ {
13
+ name: 'should render basic bigint field correctly',
14
+ field: {
15
+ name: 'largeCounter',
16
+ dataType: 'number',
17
+ nullable: false
18
+ },
19
+ assertions: [
20
+ { type: 'contains', text: '@Column({ "type": "bigint"' },
21
+ { type: 'contains', text: 'largeCounter: string;' },
22
+ { type: 'notContains', text: '@Index()' },
23
+ { type: 'notContains', text: '@PrimaryColumn()' }
24
+ ]
25
+ },
26
+ {
27
+ name: 'should render nullable bigint field correctly',
28
+ field: {
29
+ name: 'optionalCounter',
30
+ dataType: 'number',
31
+ nullable: true
32
+ },
33
+ assertions: [
34
+ { type: 'contains', text: '@Column({ "type": "bigint"' },
35
+ { type: 'contains', text: 'optionalCounter: string;' }
36
+ ]
37
+ },
38
+ {
39
+ name: 'should render bigint field with default value correctly',
40
+ field: {
41
+ name: 'defaultCounter',
42
+ dataType: 'number',
43
+ nullable: false,
44
+ default: 0
45
+ },
46
+ assertions: [
47
+ { type: 'contains', text: '@Column({ "type": "bigint"' },
48
+ { type: 'contains', text: 'default: 0' },
49
+ { type: 'contains', text: 'defaultCounter: string;' }
50
+ ]
51
+ },
52
+ {
53
+ name: 'should render indexed bigint field correctly',
54
+ field: {
55
+ name: 'indexedCounter',
56
+ dataType: 'number',
57
+ nullable: false,
58
+ index: true
59
+ },
60
+ assertions: [
61
+ { type: 'contains', text: '@Column({ "type": "bigint"' },
62
+ { type: 'contains', text: '@Index()' },
63
+ { type: 'contains', text: 'indexedCounter: string;' }
64
+ ]
65
+ },
66
+ {
67
+ name: 'should render primary key bigint field correctly',
68
+ field: {
69
+ name: 'id',
70
+ dataType: 'number',
71
+ nullable: false,
72
+ primary: true
73
+ },
74
+ assertions: [
75
+ { type: 'contains', text: '@Column({ "type": "bigint"' },
76
+ { type: 'contains', text: '@PrimaryColumn()' },
77
+ { type: 'contains', text: 'id: string;' }
78
+ ]
79
+ }
80
+ ];
81
+ (0, template_test_utils_1.runTemplateTests)(templatePath, testCases);
82
+ });
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const template_test_utils_1 = require("../utils/template-test-utils");
4
+ const globals_1 = require("@jest/globals");
5
+ (0, globals_1.describe)('Boolean Entity Template Tests', () => {
6
+ // Setup Eta configuration once before all tests
7
+ (0, globals_1.beforeAll)(() => {
8
+ (0, template_test_utils_1.configureEta)();
9
+ });
10
+ const templatePath = './entities/entity-col-boolean';
11
+ const testCases = [
12
+ {
13
+ name: 'should render basic boolean field correctly',
14
+ field: {
15
+ name: 'isActive',
16
+ dataType: 'boolean',
17
+ nullable: false
18
+ },
19
+ assertions: [
20
+ { type: 'contains', text: '@IsOptional({ groups: [CREATE, UPDATE] })' },
21
+ { type: 'contains', text: '@IsBoolean({ always: true })' },
22
+ { type: 'contains', text: "@Column({ type: 'boolean'" },
23
+ { type: 'contains', text: 'default: false' },
24
+ { type: 'contains', text: 'isActive!: boolean;' },
25
+ { type: 'notContains', text: '@Index()' },
26
+ { type: 'notContains', text: '@PrimaryColumn()' }
27
+ ]
28
+ },
29
+ {
30
+ name: 'should render nullable boolean field correctly',
31
+ field: {
32
+ name: 'optionalFlag',
33
+ dataType: 'boolean',
34
+ nullable: true
35
+ },
36
+ assertions: [
37
+ { type: 'contains', text: '@IsOptional({ groups: [CREATE, UPDATE] })' },
38
+ { type: 'contains', text: '@IsBoolean({ always: true })' },
39
+ { type: 'contains', text: "@Column({ type: 'boolean'" },
40
+ { type: 'contains', text: 'optionalFlag!: boolean;' }
41
+ ]
42
+ },
43
+ {
44
+ name: 'should render boolean field with default value correctly',
45
+ field: {
46
+ name: 'defaultFlag',
47
+ dataType: 'boolean',
48
+ nullable: false,
49
+ default: 'true'
50
+ },
51
+ assertions: [
52
+ { type: 'contains', text: '@IsOptional({ groups: [CREATE, UPDATE] })' },
53
+ { type: 'contains', text: '@IsBoolean({ always: true })' },
54
+ { type: 'contains', text: "@Column({ type: 'boolean'" },
55
+ { type: 'contains', text: 'default: true' },
56
+ { type: 'contains', text: 'defaultFlag!: boolean;' }
57
+ ]
58
+ },
59
+ {
60
+ name: 'should render indexed boolean field correctly',
61
+ field: {
62
+ name: 'indexedFlag',
63
+ dataType: 'boolean',
64
+ nullable: false,
65
+ index: true
66
+ },
67
+ assertions: [
68
+ { type: 'contains', text: '@IsOptional({ groups: [CREATE, UPDATE] })' },
69
+ { type: 'contains', text: '@IsBoolean({ always: true })' },
70
+ { type: 'contains', text: "@Column({ type: 'boolean'" },
71
+ { type: 'contains', text: '@Index()' },
72
+ { type: 'contains', text: 'indexedFlag!: boolean;' }
73
+ ]
74
+ }
75
+ ];
76
+ (0, template_test_utils_1.runTemplateTests)(templatePath, testCases);
77
+ });
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const template_test_utils_1 = require("../utils/template-test-utils");
4
+ const globals_1 = require("@jest/globals");
5
+ (0, globals_1.describe)('Bytea Entity Template Tests', () => {
6
+ // Setup Eta configuration once before all tests
7
+ (0, globals_1.beforeAll)(() => {
8
+ (0, template_test_utils_1.configureEta)();
9
+ });
10
+ const templatePath = './entities/entity-col-bytea';
11
+ const testCases = [
12
+ {
13
+ name: 'should render basic bytea field correctly',
14
+ field: {
15
+ name: 'binaryData',
16
+ dataType: 'Buffer',
17
+ nullable: false
18
+ },
19
+ assertions: [
20
+ { type: 'contains', text: '@Column({ "type": "bytea"' },
21
+ { type: 'contains', text: 'binaryData: Buffer;' },
22
+ { type: 'notContains', text: '@Index()' },
23
+ { type: 'notContains', text: '@PrimaryColumn()' }
24
+ ]
25
+ },
26
+ {
27
+ name: 'should render nullable bytea field correctly',
28
+ field: {
29
+ name: 'optionalData',
30
+ dataType: 'Buffer',
31
+ nullable: true
32
+ },
33
+ assertions: [
34
+ { type: 'contains', text: '@Column({ "type": "bytea"' },
35
+ { type: 'contains', text: 'optionalData: Buffer;' }
36
+ ]
37
+ },
38
+ {
39
+ name: 'should render indexed bytea field correctly',
40
+ field: {
41
+ name: 'indexedData',
42
+ dataType: 'Buffer',
43
+ nullable: false,
44
+ index: true
45
+ },
46
+ assertions: [
47
+ { type: 'contains', text: '@Column({ "type": "bytea"' },
48
+ { type: 'contains', text: '@Index()' },
49
+ { type: 'contains', text: 'indexedData: Buffer;' }
50
+ ]
51
+ },
52
+ {
53
+ name: 'should render primary key bytea field correctly',
54
+ field: {
55
+ name: 'id',
56
+ dataType: 'Buffer',
57
+ nullable: false,
58
+ primary: true
59
+ },
60
+ assertions: [
61
+ { type: 'contains', text: '@Column({ "type": "bytea"' },
62
+ { type: 'contains', text: '@PrimaryColumn()' },
63
+ { type: 'contains', text: 'id: Buffer;' }
64
+ ]
65
+ }
66
+ ];
67
+ (0, template_test_utils_1.runTemplateTests)(templatePath, testCases);
68
+ });