@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,34 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({
4
+ "type": "int4range",
5
+ transformer: {
6
+ to: (range: {lower: number, upper: number, lowerInclusive: boolean, upperInclusive: boolean} | null) => {
7
+ if (!range) return null;
8
+ const lowerBracket = range.lowerInclusive ? '[' : '(';
9
+ const upperBracket = range.upperInclusive ? ']' : ')';
10
+ return `${lowerBracket}${range.lower},${range.upper}${upperBracket}`;
11
+ },
12
+ from: (pgRange: string | null) => {
13
+ if (!pgRange) return null;
14
+ const lowerInclusive = pgRange.startsWith('[');
15
+ const upperInclusive = pgRange.endsWith(']');
16
+ const values = pgRange.substring(1, pgRange.length - 1).split(',');
17
+ return {
18
+ lower: parseInt(values[0]),
19
+ upper: parseInt(values[1]),
20
+ lowerInclusive,
21
+ upperInclusive
22
+ };
23
+ }
24
+ }<% if (field.nullable) {%>,
25
+ nullable: true<% } %>
26
+ })
27
+ <% if (field.index ) {%>
28
+ @Index()
29
+ <% } %>
30
+ <% if (field.primary ) {%>
31
+ @PrimaryColumn()
32
+ <% } %>
33
+
34
+ <%= field.name %>: {lower: number, upper: number, lowerInclusive: boolean, upperInclusive: boolean};
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "int"<% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: <%= field.dataType %>;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "interval"<% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: string;
@@ -0,0 +1,8 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column('json',{ nullable: <%= Boolean(field.nullable) %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+
8
+ <%= field.name %>: JSON;
@@ -0,0 +1,5 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column('json', { nullable: <%= Boolean(field.nullable) %> })
4
+
5
+ <%= field.name %>: JSON;
@@ -0,0 +1,5 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column('jsonb', { nullable: <%= Boolean(field.nullable) %> })
4
+
5
+ <%= field.name %>: any;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "money"<% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: string;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "numeric", precision: <%= field.precision || 10 %>, scale: <%= field.scale || 2 %><% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: number;
@@ -0,0 +1,25 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({
4
+ "type": "point",
5
+ transformer: {
6
+ to: (point: {x: number, y: number} | null) => {
7
+ if (!point) return null;
8
+ return `(${point.x},${point.y})`;
9
+ },
10
+ from: (pgPoint: string | null) => {
11
+ if (!pgPoint) return null;
12
+ const [x, y] = pgPoint.substring(1, pgPoint.length - 1).split(',');
13
+ return { x: parseFloat(x), y: parseFloat(y) };
14
+ }
15
+ }<% if (field.nullable) {%>,
16
+ nullable: true<% } %>
17
+ })
18
+ <% if (field.index ) {%>
19
+ @Index()
20
+ <% } %>
21
+ <% if (field.primary ) {%>
22
+ @PrimaryColumn()
23
+ <% } %>
24
+
25
+ <%= field.name %>: { x: number, y: number };
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "real"<% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: number;
@@ -0,0 +1,12 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "int" })
4
+ @Generated("increment")
5
+ <% if (field.index ) {%>
6
+ @Index()
7
+ <% } %>
8
+ <% if (field.primary ) {%>
9
+ @PrimaryColumn()
10
+ <% } %>
11
+
12
+ <%= field.name %>: number;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "smallint"<% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: number;
@@ -0,0 +1,12 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "smallint" })
4
+ @Generated("increment")
5
+ <% if (field.index ) {%>
6
+ @Index()
7
+ <% } %>
8
+ <% if (field.primary ) {%>
9
+ @PrimaryColumn()
10
+ <% } %>
11
+
12
+ <%= field.name %>: number;
@@ -0,0 +1,23 @@
1
+ <% const {field} = it; %>
2
+
3
+ @IsOptional({ groups: [UPDATE] })
4
+ <% if (!field.nullable && !field.auto) { %>
5
+ @IsNotEmpty({ groups: [CREATE] })
6
+ <% } %>
7
+ <% if (field.is_email) { %>
8
+ @IsEmail({ require_tld: false }, { always: true })
9
+ <% } %>
10
+
11
+ <% if (field.auto) { %>
12
+ <% /* https://github.com/birkir/prime/issues/126 */ %>
13
+ @Generated('increment')
14
+ <% }%>
15
+ <% if (field.index ) {%>
16
+ @Index()
17
+ <% } %>
18
+ @Column({ type: "text", nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %> })
19
+ <% if (field.primary ) {%>
20
+ @PrimaryColumn()
21
+ <% } %>
22
+
23
+ <%= field.name %>: <%= field.dataType %>;
@@ -0,0 +1,23 @@
1
+ <% const {field} = it; %>
2
+
3
+ @IsOptional({ groups: [UPDATE] })
4
+ <% if (!field.nullable && !field.auto) { %>
5
+ @IsNotEmpty({ groups: [CREATE] })
6
+ <% } %>
7
+ <% if (field.is_email) { %>
8
+ @IsEmail({ require_tld: false }, { always: true })
9
+ <% } %>
10
+
11
+ <% if (field.auto) { %>
12
+ <% /* https://github.com/birkir/prime/issues/126 */ %>
13
+ @Generated('increment')
14
+ <% }%>
15
+ <% if (field.index ) {%>
16
+ @Index()
17
+ <% } %>
18
+ @Column({ type: "text", nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %> })
19
+ <% if (field.primary ) {%>
20
+ @PrimaryColumn()
21
+ <% } %>
22
+
23
+ <%= field.name %>: <%= field.dataType %>;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "time"<% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: string;
@@ -0,0 +1,4 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ type: 'timestamp', nullable: <%= Boolean(field.nullable) %> })
4
+ <%= field.name %>: Date;
@@ -0,0 +1,4 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ type: 'timestamptz', nullable: <%= Boolean(field.nullable) %> })
4
+ <%= field.name %>: Date;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "timetz"<% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: string;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "tsvector"<% if (field.nullable) {%>, nullable: true<% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: string;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "uuid"<% if (field.default !== null) {%>, default: <%= field.default %><% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: string;
@@ -0,0 +1,18 @@
1
+ <% const {field} = it; %>
2
+
3
+ @IsOptional({ groups: [UPDATE] })
4
+ <% if (!field.nullable && !field.auto) { %>
5
+ @IsNotEmpty({ groups: [CREATE] })
6
+ <% } %>
7
+ <% if (field.is_email) { %>
8
+ @IsEmail({ require_tld: false }, { always: true })
9
+ <% } %>
10
+ <% if (field.index ) {%>
11
+ @Index()
12
+ <% } %>
13
+ @Column({ type: "varchar", length: <%= field.length || 255 %>, nullable: <%= Boolean(field.nullable) %><% if (field.unique) {%>, unique: true <% } %><% if (field.default !== null) {%>, default: '<%= field.default %>'<% } %> })
14
+ <% if (field.primary ) {%>
15
+ @PrimaryColumn()
16
+ <% } %>
17
+
18
+ <%= field.name %>: string;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Column({ "type": "xml"<% if (field.nullable) {%>, nullable: true<% } %> })
4
+ <% if (field.index ) {%>
5
+ @Index()
6
+ <% } %>
7
+ <% if (field.primary ) {%>
8
+ @PrimaryColumn()
9
+ <% } %>
10
+
11
+ <%= field.name %>: string;
@@ -0,0 +1,116 @@
1
+ <%~ includeFile('./header.eta') %>
2
+ /* eslint @typescript-eslint/no-unused-vars: "off" */
3
+
4
+ import {
5
+ Column,
6
+ Entity,
7
+ <%~ it.associations.map((assoc) => `${assoc.type},`).filter((v, i, s) => s.indexOf(v) === i).join("\r\n") %>
8
+ <% if (it.createdAt) { %>
9
+ CreateDateColumn,
10
+ <% } %>
11
+ <% if (it.updatedAt) { %>
12
+ UpdateDateColumn,
13
+ <% } %>
14
+ PrimaryGeneratedColumn,
15
+ Generated,
16
+ JoinColumn,
17
+ JoinTable,
18
+ Index,
19
+ Unique,
20
+ PrimaryColumn
21
+ } from "typeorm";
22
+ import {
23
+ IsOptional,
24
+ IsString,
25
+ MaxLength,
26
+ IsNotEmpty,
27
+ IsEmail,
28
+ IsBoolean,
29
+ ValidateNested,
30
+ } from 'class-validator';
31
+ <% if (it.apiType === "graphql") { %>
32
+ import { JSONResolver } from 'graphql-scalars';
33
+ <% } %>
34
+ import { Type } from 'class-transformer';
35
+ import { CrudValidationGroups } from '@nestjsx/crud';
36
+ <% if (it.importEnums) { %>
37
+ import * as enums from '../enums';
38
+ <% } %>
39
+ <% it.entitiesToImport.forEach((assocName) => { %>
40
+ import {<%= assocName %>} from '../<%= assocName %>/<%= assocName %>.entity';
41
+ <% }) %>
42
+
43
+ const { CREATE, UPDATE } = CrudValidationGroups;
44
+
45
+ @Entity('<%= it.snakeCasedName %>')
46
+ <% it.indexes.forEach((index) => { %>
47
+ @Index([<%~ index.fields.map((field) => `"${field}"`).join(', ') %>]<% if (index.unique) { %>, { unique: true } <% } %>)
48
+ <% }) %>
49
+ <% it.uniques.forEach((unique) => { %>
50
+ @Unique(<% if (unique.name) {%> "<%= unique.name %>", <%} %>[<%~ unique.fields.map((field) => `"${field}"`).join(', ') %>])
51
+ <% }) %>
52
+ export class <%= it.name %> {
53
+ <% if (it.createPrimaryKey) { %>
54
+ // Fields
55
+ @PrimaryGeneratedColumn()
56
+ id!: number;
57
+ <% } %>
58
+
59
+ <% if (it.createdAt) { %>
60
+ @CreateDateColumn()
61
+ created_at: Date;
62
+ <% } %>
63
+
64
+ <% if (it.updatedAt) { %>
65
+ @UpdateDateColumn()
66
+ updated_at: Date;
67
+ <% } %>
68
+
69
+ <% it.columns.forEach((field) => { %>
70
+
71
+ <%~ includeFile(`./entities/entity-col-${field.type}`, { field }) %>
72
+
73
+ <% }); %>
74
+
75
+ // Associations
76
+ <% it.associations.forEach((assoc) => { %>
77
+ <% if (assoc.type === 'OneToMany') { %>
78
+
79
+ @OneToMany(
80
+ () => <%= assoc.name %>,
81
+ <%= assoc.camelCasedName %> => <%= assoc.camelCasedName %>.<%= assoc.entityName %>
82
+ )
83
+ <%= assoc.pluralizedName %>: <%= assoc.name %>[]
84
+
85
+ <% } else if (assoc.type === 'ManyToOne') { %>
86
+ <% if (assoc.index) { %>
87
+ @Index()
88
+ <% } %>
89
+ @ManyToOne(() => <%= assoc.name %><% if (assoc.biDirectional) { %>, <%= assoc.camelCasedName %> => <%= assoc.camelCasedName %>.<%= it.pluralizedName %><% } %><% if (assoc.cascadeDelete) { %>, { onDelete: "CASCADE" }<% } %>)
90
+ @JoinColumn({ name: '<%= assoc.camelCasedId %>' })
91
+ <%= assoc.relationshipName %>: <%= assoc.name %>
92
+
93
+ @Column({ type: "integer", <% if (assoc.nullable) { %> nullable: true <% } %>})
94
+ <%= assoc.camelCasedId %>: number;
95
+
96
+ <% } else if (assoc.type === 'ManyToMany') { %>
97
+
98
+ @ManyToMany(() => <%= assoc.name %><% if (assoc.biDirectional) { %>, <%= assoc.camelCasedName %> => <%= assoc.camelCasedName %>.<%= it.pluralizedName %><% } %>)
99
+ <% if (assoc.joinTable) { %>@JoinTable()<% } %>
100
+ <%= assoc.pluralizedRelationshipName %>: <%= assoc.name %>[]
101
+
102
+ <% } else if (assoc.type === 'OneToOne') { %>
103
+
104
+ @OneToOne(
105
+ (type: any) => <%= assoc.name%>,
106
+ <% if (assoc.biDirectional) { %>(p) => p.<%= assoc.entityName %>,<% } %>
107
+ {
108
+ onDelete: "CASCADE",
109
+ cascade: ["insert", "update"],
110
+ })
111
+ @JoinColumn()
112
+ <%= assoc.relationshipName %>: <%= assoc.name %>
113
+
114
+ <% } %>
115
+ <% }) %>
116
+ }
@@ -0,0 +1,4 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Field(() => [String], { nullable: <%= Boolean(field.nullable) %> })
4
+ <%= field.name %>!: <%= field.dataType %>;
@@ -0,0 +1,6 @@
1
+ <% const {field} = it; %>
2
+
3
+ @IsOptional({ groups: [CREATE, UPDATE] })
4
+ @IsBoolean({ always: true })
5
+ @Field(() => Boolean)
6
+ <%= field.name %>!: <%= field.dataType %>;
@@ -0,0 +1,4 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Field(() => Date)
4
+ <%= field.name %>: string;
@@ -0,0 +1,5 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Field(() => enums.<%= field.dataType%>)
4
+
5
+ <%= field.name %>!: enums.<%= field.dataType%>;
@@ -0,0 +1,4 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Field(() => Number <% if (field.default !== null) {%>, { nullable: true } <% }%>)
4
+ <%= field.name %>: <%= field.dataType %>;
@@ -0,0 +1,4 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Field(() => Number <% if (field.default !== null) {%>, { nullable: true } <% }%>)
4
+ <%= field.name %>: <%= field.dataType %>;
@@ -0,0 +1,5 @@
1
+ <% const {field, isGql} = it; %>
2
+
3
+ @Field(() => JSONResolver, { nullable: <%= Boolean(field.nullable) %> })
4
+
5
+ <%= field.name %>: JSON;
@@ -0,0 +1,5 @@
1
+ <% const {field} = it; %>
2
+
3
+ @Field(() => JSONResolver, { nullable: <%= Boolean(field.nullable) %> })
4
+
5
+ <%= field.name %>: JSON;
@@ -0,0 +1,11 @@
1
+ <% const {field} = it; %>
2
+
3
+ @IsOptional({ groups: [UPDATE] })
4
+ <% if (!field.nullable && !field.auto) { %>
5
+ @IsNotEmpty({ groups: [CREATE] })
6
+ <% } %>
7
+ <% if (field.is_email) { %>
8
+ @IsEmail({ require_tld: false }, { always: true })
9
+ <% } %>
10
+ @Field(() => String, { nullable: <%= Boolean(field.nullable) %> })
11
+ <%= field.name %>: <%= field.dataType %>;
@@ -0,0 +1,3 @@
1
+ <% const {field} = it; %>
2
+ @Field(() => Date)
3
+ <%= field.name %>: Date;
@@ -0,0 +1,3 @@
1
+ <% const {field} = it; %>
2
+ @Field(() => Date)
3
+ <%= field.name %>: Date;
@@ -0,0 +1,12 @@
1
+ <%~ includeFile('./header.eta') %>
2
+ import { registerEnumType } from '@nestjs/graphql';
3
+
4
+ <% it.allEnumsFields.forEach((enumType) => { %>
5
+ export enum <%= enumType.name %> {
6
+ <%~ enumType.values.map((enumValue) => `${enumValue} = '${enumValue}'`).join(', ') %>
7
+ }
8
+ <% }) %>
9
+
10
+ <% it.allEnumsFields.forEach((enumType) => { %>
11
+ registerEnumType(<%= enumType.name %>, {name: '<%= enumType.name %>'});
12
+ <% }) %>
@@ -0,0 +1,67 @@
1
+ <%~ includeFile('./header.eta') %>
2
+ /* eslint @typescript-eslint/no-unused-vars: "off" */
3
+
4
+ import {
5
+ Column,
6
+ Entity,
7
+ <%~ it.associations.map((assoc) => `${assoc.type},`).filter((v, i, s) => s.indexOf(v) === i).join("\r\n") %>
8
+ PrimaryColumn
9
+ } from "typeorm";
10
+
11
+ import {
12
+ IsOptional,
13
+ IsString,
14
+ MaxLength,
15
+ IsNotEmpty,
16
+ IsEmail,
17
+ IsBoolean,
18
+ ValidateNested,
19
+ } from 'class-validator';
20
+ import { Type } from 'class-transformer';
21
+
22
+ import { ObjectType, Field, Int, GraphQLISODateTime, ID } from '@nestjs/graphql';
23
+ import { JSONResolver } from 'graphql-scalars';
24
+ import { CrudValidationGroups } from '@nestjsx/crud';
25
+ <% if (it.importEnums) { %>
26
+ import * as enums from '../../enums';
27
+ <% } %>
28
+
29
+ <% it.entitiesToImport.forEach((assocName) => { %>
30
+ import {<%= assocName %>DTO} from '../../<%= assocName %>/dtos/<%= assocName %>.dto';
31
+ <% }) %>
32
+
33
+ import { FilterableField, IDField, Relation, UnPagedRelation} from '@nestjs-query/query-graphql';
34
+
35
+ const { CREATE, UPDATE } = CrudValidationGroups;
36
+
37
+ @ObjectType()
38
+ <% it.associations.forEach((assoc) => { %>
39
+ <% if (assoc.type === 'OneToMany' || assoc.type === 'OneToOne') { %>
40
+ @Relation('<%= assoc.name %>', () => <%= assoc.name %>DTO, { disableRemove: true })
41
+ <% } else if (assoc.type === 'ManyToOne' || assoc.type === 'ManyToMany') { %>
42
+ @UnPagedRelation('<%= assoc.name %>', () => <%= assoc.name %>DTO, { disableRemove: true })
43
+ <% } %>
44
+ <% }) %>
45
+ export class <%= it.name %>DTO {
46
+
47
+ <% if (it.createPrimaryKey) { %>
48
+ @IDField(() => Int)
49
+ id!: number;
50
+ <% } %>
51
+
52
+ <% if (it.createdAt) { %>
53
+ @Field(() => GraphQLISODateTime)
54
+ created_at: Date;
55
+ <% } %>
56
+
57
+ <% if (it.updatedAt) { %>
58
+ @Field(() => GraphQLISODateTime)
59
+ updated_at: Date;
60
+ <% } %>
61
+
62
+ <% it.columns.forEach((field) => { %>
63
+
64
+ <%~ includeFile(`./graphql/dto/dto-col-${field.type}`, { field, isGql: true }) %>
65
+
66
+ <% }); %>
67
+ }
@@ -0,0 +1,26 @@
1
+ <%~ includeFile('./header.eta') %>
2
+
3
+ <% it.entities.forEach((entity) => { %>
4
+ import {<%= entity.name %>Module} from './<%= entity.name %>/<%= entity.name %>.module'
5
+ <%}) %>
6
+ import { JSONResolver } from 'graphql-scalars';
7
+
8
+ <% const scalars = [] %>
9
+
10
+ export const extendedScalarResolvers = {
11
+ <% it.entities.forEach((entity) => { %>
12
+ <% entity.fields.forEach((field) => { %>
13
+ <%if (field.type === "json" && !scalars.includes(field.type)) {
14
+ scalars.push(field.type)
15
+ %>
16
+ "JSON": JSONResolver
17
+ <%} %>
18
+ <%}) %>
19
+ <%}) %>
20
+ }
21
+
22
+ export default [
23
+ <% it.entities.forEach((entity) => { %>
24
+ <%= entity.name %>Module,
25
+ <%}) %>
26
+ ]
@@ -0,0 +1,19 @@
1
+ <%~ includeFile('./header.eta') %>
2
+
3
+ import { Module } from "@nestjs/common";
4
+ import {<%= it.entityName %>} from './<%= it.entityName%>.entity'
5
+ import { NestjsQueryGraphQLModule } from '@nestjs-query/query-graphql';
6
+ import { NestjsQueryTypeOrmModule } from '@nestjs-query/query-typeorm';
7
+ import {<%= it.entityName %>DTO} from './dtos/<%= it.entityName%>.dto'
8
+
9
+ @Module({
10
+ imports: [
11
+ NestjsQueryGraphQLModule.forFeature({
12
+ imports: [NestjsQueryTypeOrmModule.forFeature([<%= it.entityName %>])],
13
+ resolvers: [{ DTOClass: <%= it.entityName %>DTO, EntityClass: <%= it.entityName %> }],
14
+ }),
15
+ ],
16
+ })
17
+ export class <%= it.modName %> {}
18
+
19
+
@@ -0,0 +1,3 @@
1
+ /**
2
+ * This file generated by Apso.
3
+ */