@apso/cli 0.0.4 → 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.
- package/LICENSE +21 -0
- package/README.md +313 -53
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +3 -3
- package/dist/commands/server/new.d.ts +22 -0
- package/dist/commands/server/new.js +105 -0
- package/dist/commands/server/scaffold.d.ts +14 -0
- package/dist/commands/server/scaffold.js +60 -0
- package/dist/index.d.ts +1 -0
- package/{lib → dist}/index.js +3 -2
- package/dist/lib/apsorc-parser.d.ts +26 -0
- package/dist/lib/apsorc-parser.js +65 -0
- package/dist/lib/base-command.d.ts +4 -0
- package/dist/lib/base-command.js +24 -0
- package/dist/lib/controller.d.ts +2 -0
- package/dist/lib/controller.js +36 -0
- package/dist/lib/dto.d.ts +7 -0
- package/dist/lib/dto.js +49 -0
- package/dist/lib/entity.d.ts +2 -0
- package/dist/lib/entity.js +43 -0
- package/dist/lib/enums.d.ts +6 -0
- package/dist/lib/enums.js +31 -0
- package/dist/lib/gql-dto.d.ts +3 -0
- package/dist/lib/gql-dto.js +43 -0
- package/dist/lib/index-module.d.ts +2 -0
- package/dist/lib/index-module.js +18 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.js +21 -0
- package/dist/lib/module.d.ts +1 -0
- package/dist/lib/module.js +28 -0
- package/dist/lib/service.d.ts +1 -0
- package/dist/lib/service.js +24 -0
- package/dist/lib/templates/entities/entity-col-array.eta +12 -0
- package/dist/lib/templates/entities/entity-col-bigint.eta +11 -0
- package/dist/lib/templates/entities/entity-col-bigserial.eta +12 -0
- package/dist/lib/templates/entities/entity-col-boolean.eta +11 -0
- package/dist/lib/templates/entities/entity-col-bytea.eta +11 -0
- package/dist/lib/templates/entities/entity-col-char.eta +15 -0
- package/dist/lib/templates/entities/entity-col-date.eta +8 -0
- package/dist/lib/templates/entities/entity-col-decimal.eta +11 -0
- package/dist/lib/templates/entities/entity-col-double.eta +11 -0
- package/dist/lib/templates/entities/entity-col-enum.eta +12 -0
- package/dist/lib/templates/entities/entity-col-float.eta +7 -0
- package/dist/lib/templates/entities/entity-col-inet.eta +11 -0
- package/dist/lib/templates/entities/entity-col-int4range.eta +34 -0
- package/dist/lib/templates/entities/entity-col-integer.eta +11 -0
- package/dist/lib/templates/entities/entity-col-interval.eta +11 -0
- package/dist/lib/templates/entities/entity-col-json-plain.eta +8 -0
- package/dist/lib/templates/entities/entity-col-json.eta +5 -0
- package/dist/lib/templates/entities/entity-col-jsonb.eta +5 -0
- package/dist/lib/templates/entities/entity-col-money.eta +11 -0
- package/dist/lib/templates/entities/entity-col-numeric.eta +11 -0
- package/dist/lib/templates/entities/entity-col-point.eta +25 -0
- package/dist/lib/templates/entities/entity-col-real.eta +11 -0
- package/dist/lib/templates/entities/entity-col-serial.eta +12 -0
- package/dist/lib/templates/entities/entity-col-smallint.eta +11 -0
- package/dist/lib/templates/entities/entity-col-smallserial.eta +12 -0
- package/dist/lib/templates/entities/entity-col-string.eta +23 -0
- package/dist/lib/templates/entities/entity-col-text.eta +23 -0
- package/dist/lib/templates/entities/entity-col-time.eta +11 -0
- package/dist/lib/templates/entities/entity-col-timestamp.eta +4 -0
- package/dist/lib/templates/entities/entity-col-timestamptz.eta +4 -0
- package/dist/lib/templates/entities/entity-col-timetz.eta +11 -0
- package/dist/lib/templates/entities/entity-col-tsvector.eta +11 -0
- package/dist/lib/templates/entities/entity-col-uuid.eta +11 -0
- package/dist/lib/templates/entities/entity-col-varchar.eta +18 -0
- package/dist/lib/templates/entities/entity-col-xml.eta +11 -0
- package/dist/lib/templates/entities/entity.eta +116 -0
- package/dist/lib/templates/graphql/dto/dto-col-array.eta +4 -0
- package/dist/lib/templates/graphql/dto/dto-col-boolean.eta +6 -0
- package/dist/lib/templates/graphql/dto/dto-col-date.eta +4 -0
- package/dist/lib/templates/graphql/dto/dto-col-enum.eta +5 -0
- package/dist/lib/templates/graphql/dto/dto-col-float.eta +4 -0
- package/dist/lib/templates/graphql/dto/dto-col-integer.eta +4 -0
- package/dist/lib/templates/graphql/dto/dto-col-json-plain.eta +5 -0
- package/dist/lib/templates/graphql/dto/dto-col-json.eta +5 -0
- package/dist/lib/templates/graphql/dto/dto-col-text.eta +11 -0
- package/dist/lib/templates/graphql/dto/dto-col-timestamp.eta +3 -0
- package/dist/lib/templates/graphql/dto/dto-col-timestamptz.eta +3 -0
- package/dist/lib/templates/graphql/enums-graphql.eta +12 -0
- package/dist/lib/templates/graphql/gql-dto-graphql.eta +67 -0
- package/dist/lib/templates/graphql/index-module-graphql.eta +26 -0
- package/dist/lib/templates/graphql/module-graphql.eta +19 -0
- package/dist/lib/templates/header.eta +3 -0
- package/dist/lib/templates/rest/controller-rest-spec.eta +77 -0
- package/dist/lib/templates/rest/controller-rest.eta +171 -0
- package/dist/lib/templates/rest/dto-rest.eta +48 -0
- package/dist/lib/templates/rest/enums-rest.eta +7 -0
- package/dist/lib/templates/rest/index-module-rest.eta +11 -0
- package/dist/lib/templates/rest/module-rest.eta +16 -0
- package/dist/lib/templates/rest/ormconfig.eta +9 -0
- package/dist/lib/templates/rest/service-rest.eta +25 -0
- package/dist/lib/types/constraints.d.ts +4 -0
- package/dist/lib/types/constraints.js +2 -0
- package/dist/lib/types/entity.d.ts +13 -0
- package/dist/lib/types/entity.js +2 -0
- package/dist/lib/types/field.d.ts +16 -0
- package/dist/lib/types/field.js +2 -0
- package/dist/lib/types/index.d.ts +5 -0
- package/dist/lib/types/index.js +2 -0
- package/dist/lib/types/indices.d.ts +4 -0
- package/dist/lib/types/indices.js +2 -0
- package/dist/lib/types/json.d.ts +3 -0
- package/dist/lib/types/json.js +2 -0
- package/dist/lib/types/relationship.d.ts +43 -0
- package/dist/lib/types/relationship.js +2 -0
- package/dist/lib/utils/casing.d.ts +2 -0
- package/dist/lib/utils/casing.js +16 -0
- package/dist/lib/utils/field.d.ts +6 -0
- package/dist/lib/utils/field.js +65 -0
- package/dist/lib/utils/file-system.d.ts +2 -0
- package/dist/lib/utils/file-system.js +52 -0
- package/dist/lib/utils/relationships/index.d.ts +2 -0
- package/dist/lib/utils/relationships/index.js +11 -0
- package/dist/lib/utils/relationships/parse-v1.d.ts +4 -0
- package/dist/lib/utils/relationships/parse-v1.js +86 -0
- package/dist/lib/utils/relationships/parse.d.ts +11 -0
- package/dist/lib/utils/relationships/parse.js +192 -0
- package/dist/tests/templates/entities/types/array-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/array-template.spec.js +82 -0
- package/dist/tests/templates/entities/types/bigint-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/bigint-template.spec.js +82 -0
- package/dist/tests/templates/entities/types/boolean-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/boolean-template.spec.js +77 -0
- package/dist/tests/templates/entities/types/bytea-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/bytea-template.spec.js +68 -0
- package/dist/tests/templates/entities/types/char-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/char-template.spec.js +68 -0
- package/dist/tests/templates/entities/types/date-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/date-template.spec.js +56 -0
- package/dist/tests/templates/entities/types/decimal-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/decimal-template.spec.js +86 -0
- package/dist/tests/templates/entities/types/double-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/double-template.spec.js +67 -0
- package/dist/tests/templates/entities/types/enum-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/enum-template.spec.js +85 -0
- package/dist/tests/templates/entities/types/float-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/float-template.spec.js +67 -0
- package/dist/tests/templates/entities/types/inet-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/inet-template.spec.js +69 -0
- package/dist/tests/templates/entities/types/int4range-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/int4range-template.spec.js +60 -0
- package/dist/tests/templates/entities/types/integer-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/integer-template.spec.js +79 -0
- package/dist/tests/templates/entities/types/interval-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/interval-template.spec.js +68 -0
- package/dist/tests/templates/entities/types/json-plain-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/json-plain-template.spec.js +54 -0
- package/dist/tests/templates/entities/types/json-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/json-template.spec.js +40 -0
- package/dist/tests/templates/entities/types/jsonb-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/jsonb-template.spec.js +40 -0
- package/dist/tests/templates/entities/types/money-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/money-template.spec.js +68 -0
- package/dist/tests/templates/entities/types/numeric-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/numeric-template.spec.js +84 -0
- package/dist/tests/templates/entities/types/point-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/point-template.spec.js +58 -0
- package/dist/tests/templates/entities/types/real-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/real-template.spec.js +67 -0
- package/dist/tests/templates/entities/types/serial-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/serial-template.spec.js +113 -0
- package/dist/tests/templates/entities/types/smallint-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/smallint-template.spec.js +82 -0
- package/dist/tests/templates/entities/types/string-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/string-template.spec.js +111 -0
- package/dist/tests/templates/entities/types/text-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/text-template.spec.js +70 -0
- package/dist/tests/templates/entities/types/time-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/time-template.spec.js +68 -0
- package/dist/tests/templates/entities/types/timestamp-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/timestamp-template.spec.js +74 -0
- package/dist/tests/templates/entities/types/timetz-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/timetz-template.spec.js +68 -0
- package/dist/tests/templates/entities/types/tsvector-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/tsvector-template.spec.js +55 -0
- package/dist/tests/templates/entities/types/uuid-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/uuid-template.spec.js +82 -0
- package/dist/tests/templates/entities/types/varchar-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/varchar-template.spec.js +102 -0
- package/dist/tests/templates/entities/types/xml-template.spec.d.ts +1 -0
- package/dist/tests/templates/entities/types/xml-template.spec.js +55 -0
- package/dist/tests/templates/entities/utils/template-test-utils.d.ts +31 -0
- package/dist/tests/templates/entities/utils/template-test-utils.js +50 -0
- package/oclif.manifest.json +60 -1
- package/package.json +84 -55
- package/lib/commands/new.d.ts +0 -22
- package/lib/commands/new.js +0 -198
- package/lib/commands/scaffold.d.ts +0 -18
- package/lib/commands/scaffold.js +0 -106
- package/lib/index.d.ts +0 -1
- package/lib/lib/scaffold.d.ts +0 -30
- 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,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,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,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,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": "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,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,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,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
|
+
|