@apso/cli 0.7.3 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autogen/index.d.ts +2 -0
- package/dist/autogen/index.js +3 -0
- package/dist/commands/server/new.d.ts +4 -1
- package/dist/commands/server/new.js +115 -22
- package/dist/commands/server/scaffold.d.ts +11 -0
- package/dist/commands/server/scaffold.js +213 -12
- package/dist/lib/api/client.d.ts +65 -0
- package/dist/lib/api/client.js +305 -0
- package/dist/lib/api/index.d.ts +8 -0
- package/dist/lib/api/index.js +22 -0
- package/dist/lib/api/services.d.ts +166 -0
- package/dist/lib/api/services.js +202 -0
- package/dist/lib/api/types.d.ts +212 -0
- package/dist/lib/api/types.js +7 -0
- package/dist/lib/apsorc-parser.d.ts +3 -0
- package/dist/lib/apsorc-parser.js +4 -0
- package/dist/lib/config/index.d.ts +8 -0
- package/dist/lib/config/index.js +17 -0
- package/dist/lib/config/manager.d.ts +127 -0
- package/dist/lib/config/manager.js +304 -0
- package/dist/lib/config/paths.d.ts +65 -0
- package/dist/lib/config/paths.js +127 -0
- package/dist/lib/config/types.d.ts +230 -0
- package/dist/lib/config/types.js +30 -0
- package/dist/lib/generators/base.d.ts +93 -0
- package/dist/lib/generators/base.js +90 -0
- package/dist/lib/generators/go.d.ts +37 -0
- package/dist/lib/generators/go.js +340 -0
- package/dist/lib/generators/index.d.ts +21 -0
- package/dist/lib/generators/index.js +51 -0
- package/dist/lib/generators/python.d.ts +21 -0
- package/dist/lib/generators/python.js +253 -0
- package/dist/lib/generators/typescript.d.ts +25 -0
- package/dist/lib/generators/typescript.js +373 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +9 -1
- package/dist/lib/templates/entities/entity-col-timestamp.eta +9 -2
- package/dist/lib/templates/entities/entity-col-timestamptz.eta +9 -2
- package/dist/lib/templates/entities/entity.eta +18 -5
- package/dist/lib/templates/go/dto/dto-col-array.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-boolean.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-date.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-decimal.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-enum.eta +8 -0
- package/dist/lib/templates/go/dto/dto-col-float.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-integer.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-json.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-jsonb.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-numeric.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-string.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-text.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-timestamp.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-timestamptz.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-uuid.eta +7 -0
- package/dist/lib/templates/go/dto/dto-col-varchar.eta +7 -0
- package/dist/lib/templates/go/dto/dto.eta +78 -0
- package/dist/lib/templates/go/enums.eta +44 -0
- package/dist/lib/templates/go/handlers/handler.eta +212 -0
- package/dist/lib/templates/go/header.eta +3 -0
- package/dist/lib/templates/go/index-module.eta +53 -0
- package/dist/lib/templates/go/middleware/auth.eta +101 -0
- package/dist/lib/templates/go/models/model-col-array.eta +1 -0
- package/dist/lib/templates/go/models/model-col-boolean.eta +1 -0
- package/dist/lib/templates/go/models/model-col-date.eta +1 -0
- package/dist/lib/templates/go/models/model-col-decimal.eta +1 -0
- package/dist/lib/templates/go/models/model-col-enum.eta +2 -0
- package/dist/lib/templates/go/models/model-col-float.eta +1 -0
- package/dist/lib/templates/go/models/model-col-integer.eta +1 -0
- package/dist/lib/templates/go/models/model-col-json.eta +1 -0
- package/dist/lib/templates/go/models/model-col-jsonb.eta +1 -0
- package/dist/lib/templates/go/models/model-col-numeric.eta +1 -0
- package/dist/lib/templates/go/models/model-col-string.eta +1 -0
- package/dist/lib/templates/go/models/model-col-text.eta +1 -0
- package/dist/lib/templates/go/models/model-col-timestamp.eta +1 -0
- package/dist/lib/templates/go/models/model-col-timestamptz.eta +1 -0
- package/dist/lib/templates/go/models/model-col-uuid.eta +1 -0
- package/dist/lib/templates/go/models/model-col-varchar.eta +1 -0
- package/dist/lib/templates/go/models/model.eta +53 -0
- package/dist/lib/templates/go/services/service.eta +190 -0
- package/dist/lib/templates/python/enums.eta +10 -0
- package/dist/lib/templates/python/header.eta +6 -0
- package/dist/lib/templates/python/index-module.eta +18 -0
- package/dist/lib/templates/python/models/model-col-array.eta +4 -0
- package/dist/lib/templates/python/models/model-col-boolean.eta +5 -0
- package/dist/lib/templates/python/models/model-col-date.eta +4 -0
- package/dist/lib/templates/python/models/model-col-decimal.eta +4 -0
- package/dist/lib/templates/python/models/model-col-enum.eta +16 -0
- package/dist/lib/templates/python/models/model-col-float.eta +5 -0
- package/dist/lib/templates/python/models/model-col-integer.eta +6 -0
- package/dist/lib/templates/python/models/model-col-json.eta +4 -0
- package/dist/lib/templates/python/models/model-col-jsonb.eta +4 -0
- package/dist/lib/templates/python/models/model-col-numeric.eta +4 -0
- package/dist/lib/templates/python/models/model-col-string.eta +6 -0
- package/dist/lib/templates/python/models/model-col-text.eta +6 -0
- package/dist/lib/templates/python/models/model-col-timestamp.eta +11 -0
- package/dist/lib/templates/python/models/model-col-timestamptz.eta +11 -0
- package/dist/lib/templates/python/models/model-col-uuid.eta +5 -0
- package/dist/lib/templates/python/models/model-col-varchar.eta +6 -0
- package/dist/lib/templates/python/models/model.eta +124 -0
- package/dist/lib/templates/python/routers/router.eta +206 -0
- package/dist/lib/templates/python/schemas/schema-col-array.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-boolean.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-date.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-decimal.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-enum.eta +6 -0
- package/dist/lib/templates/python/schemas/schema-col-float.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-integer.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-json.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-jsonb.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-numeric.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-string.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-text.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-timestamp.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-timestamptz.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-uuid.eta +1 -0
- package/dist/lib/templates/python/schemas/schema-col-varchar.eta +1 -0
- package/dist/lib/templates/python/schemas/schema.eta +87 -0
- package/dist/lib/templates/python/services/service.eta +163 -0
- package/dist/lib/templates/rest/controller-rest.eta +13 -12
- package/dist/lib/templates/rest/dto-rest.eta +173 -59
- package/dist/lib/templates/rest/service-rest.eta +50 -10
- package/dist/lib/types/generator.d.ts +241 -0
- package/dist/lib/types/generator.js +2 -0
- package/dist/lib/types/index.d.ts +1 -0
- package/dist/lib/utils/casing.d.ts +1 -0
- package/dist/lib/utils/casing.js +11 -1
- package/oclif.manifest.json +39 -3
- package/package.json +4 -2
- package/dist/lib/utils/relationships/parse.spec.d.ts +0 -1
- package/dist/lib/utils/relationships/parse.spec.js +0 -402
- package/dist/tests/templates/entities/types/array-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/array-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/bigint-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/bigint-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/boolean-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/boolean-template.spec.js +0 -77
- package/dist/tests/templates/entities/types/bytea-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/bytea-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/char-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/char-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/date-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/date-template.spec.js +0 -56
- package/dist/tests/templates/entities/types/decimal-field-validation.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/decimal-field-validation.spec.js +0 -100
- package/dist/tests/templates/entities/types/decimal-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/decimal-template.spec.js +0 -86
- package/dist/tests/templates/entities/types/double-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/double-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/enum-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/enum-template.spec.js +0 -85
- package/dist/tests/templates/entities/types/float-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/float-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/geometry-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/geometry-template.spec.js +0 -58
- package/dist/tests/templates/entities/types/inet-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/inet-template.spec.js +0 -69
- package/dist/tests/templates/entities/types/int4range-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/int4range-template.spec.js +0 -72
- package/dist/tests/templates/entities/types/integer-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/integer-template.spec.js +0 -79
- package/dist/tests/templates/entities/types/interval-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/interval-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/json-plain-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/json-plain-template.spec.js +0 -54
- package/dist/tests/templates/entities/types/json-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/json-template.spec.js +0 -40
- package/dist/tests/templates/entities/types/jsonb-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/jsonb-template.spec.js +0 -40
- package/dist/tests/templates/entities/types/money-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/money-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/numeric-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/numeric-template.spec.js +0 -84
- package/dist/tests/templates/entities/types/point-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/point-template.spec.js +0 -64
- package/dist/tests/templates/entities/types/polygon-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/polygon-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/real-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/real-template.spec.js +0 -67
- package/dist/tests/templates/entities/types/serial-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/serial-template.spec.js +0 -113
- package/dist/tests/templates/entities/types/smallint-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/smallint-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/string-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/string-template.spec.js +0 -111
- package/dist/tests/templates/entities/types/text-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/text-template.spec.js +0 -70
- package/dist/tests/templates/entities/types/time-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/time-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/timestamp-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/timestamp-template.spec.js +0 -74
- package/dist/tests/templates/entities/types/timetz-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/timetz-template.spec.js +0 -68
- package/dist/tests/templates/entities/types/tsvector-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/tsvector-template.spec.js +0 -55
- package/dist/tests/templates/entities/types/uuid-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/uuid-template.spec.js +0 -82
- package/dist/tests/templates/entities/types/varchar-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/varchar-template.spec.js +0 -105
- package/dist/tests/templates/entities/types/xml-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/types/xml-template.spec.js +0 -55
- package/dist/tests/templates/entities/uuid-entity-template.spec.d.ts +0 -1
- package/dist/tests/templates/entities/uuid-entity-template.spec.js +0 -277
- package/dist/tests/utils/relationship-deduplication.spec.d.ts +0 -1
- package/dist/tests/utils/relationship-deduplication.spec.js +0 -98
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BaseGenerator } from "./base";
|
|
2
|
+
import { TargetLanguage, GeneratedFile, ValidationResult, GeneratorConfig, EntityGenerationOptions, ControllerGenerationOptions, ServiceGenerationOptions, DtoGenerationOptions, MigrationGenerationOptions, Entity, AuthConfig } from "../types";
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript/NestJS generator that wraps the existing generation functions.
|
|
5
|
+
* This generator produces TypeORM entities, NestJS controllers, services, and DTOs.
|
|
6
|
+
*/
|
|
7
|
+
export declare class TypeScriptGenerator extends BaseGenerator {
|
|
8
|
+
constructor(config: GeneratorConfig);
|
|
9
|
+
getLanguage(): TargetLanguage;
|
|
10
|
+
getFileExtension(): string;
|
|
11
|
+
validateConfig(config: GeneratorConfig): ValidationResult;
|
|
12
|
+
generateEntity(options: EntityGenerationOptions): Promise<GeneratedFile[]>;
|
|
13
|
+
generateController(options: ControllerGenerationOptions): Promise<GeneratedFile[]>;
|
|
14
|
+
generateService(options: ServiceGenerationOptions): Promise<GeneratedFile[]>;
|
|
15
|
+
generateDto(options: DtoGenerationOptions): Promise<GeneratedFile[]>;
|
|
16
|
+
generateModule(options: EntityGenerationOptions): Promise<GeneratedFile[]>;
|
|
17
|
+
generateMigration(_options: MigrationGenerationOptions): Promise<GeneratedFile[]>;
|
|
18
|
+
generateEnums(entities: Entity[], apiType: string): Promise<GeneratedFile[]>;
|
|
19
|
+
generateIndexModule(entities: Entity[], apiType: string): Promise<GeneratedFile[]>;
|
|
20
|
+
generateGuards(entities: Entity[], auth?: AuthConfig): Promise<GeneratedFile[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Normalizes auth config by applying defaults for DB session providers
|
|
23
|
+
*/
|
|
24
|
+
private normalizeAuthConfig;
|
|
25
|
+
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeScriptGenerator = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const path = tslib_1.__importStar(require("path"));
|
|
6
|
+
const Eta = tslib_1.__importStar(require("eta"));
|
|
7
|
+
const base_1 = require("./base");
|
|
8
|
+
// Utilities available for future use: createFile, withGeneratedMeta from "../utils/file-system"
|
|
9
|
+
const field_1 = require("../utils/field");
|
|
10
|
+
const relationships_1 = require("../utils/relationships");
|
|
11
|
+
const parse_1 = require("../utils/relationships/parse");
|
|
12
|
+
const casing_1 = require("../utils/casing");
|
|
13
|
+
const pluralize_1 = tslib_1.__importDefault(require("pluralize"));
|
|
14
|
+
const fs = tslib_1.__importStar(require("fs"));
|
|
15
|
+
const os = tslib_1.__importStar(require("os"));
|
|
16
|
+
const util_1 = require("util");
|
|
17
|
+
const guards_1 = require("../guards");
|
|
18
|
+
const auth_1 = require("../types/auth");
|
|
19
|
+
const unlinkAsync = (0, util_1.promisify)(fs.unlink);
|
|
20
|
+
/**
|
|
21
|
+
* TypeScript/NestJS generator that wraps the existing generation functions.
|
|
22
|
+
* This generator produces TypeORM entities, NestJS controllers, services, and DTOs.
|
|
23
|
+
*/
|
|
24
|
+
class TypeScriptGenerator extends base_1.BaseGenerator {
|
|
25
|
+
constructor(config) {
|
|
26
|
+
super(config);
|
|
27
|
+
// Override template path for TypeScript - use root templates directory
|
|
28
|
+
// since TypeScript templates are the existing ones in entities/, rest/, graphql/
|
|
29
|
+
this.templateBasePath = path.join(__dirname, "../templates");
|
|
30
|
+
Eta.configure({
|
|
31
|
+
views: this.templateBasePath,
|
|
32
|
+
cache: false,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
getLanguage() {
|
|
36
|
+
return "typescript";
|
|
37
|
+
}
|
|
38
|
+
getFileExtension() {
|
|
39
|
+
return ".ts";
|
|
40
|
+
}
|
|
41
|
+
validateConfig(config) {
|
|
42
|
+
var _a;
|
|
43
|
+
const errors = [];
|
|
44
|
+
const warnings = [];
|
|
45
|
+
// Validate that entities are provided
|
|
46
|
+
if (!config.entities || config.entities.length === 0) {
|
|
47
|
+
errors.push("No entities defined in configuration");
|
|
48
|
+
}
|
|
49
|
+
// Validate each entity
|
|
50
|
+
for (const entity of config.entities) {
|
|
51
|
+
if (!entity.name) {
|
|
52
|
+
errors.push("Entity missing required 'name' property");
|
|
53
|
+
}
|
|
54
|
+
// Validate field types
|
|
55
|
+
for (const field of (_a = entity.fields) !== null && _a !== void 0 ? _a : []) {
|
|
56
|
+
if (!field.name) {
|
|
57
|
+
errors.push(`Entity '${entity.name}' has a field without a name`);
|
|
58
|
+
}
|
|
59
|
+
if (!field.type) {
|
|
60
|
+
errors.push(`Entity '${entity.name}' field '${field.name}' missing type`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Validate API type
|
|
65
|
+
if (config.apiType && !["rest", "graphql"].includes(config.apiType)) {
|
|
66
|
+
errors.push(`Invalid API type: '${config.apiType}'. Must be 'rest' or 'graphql'`);
|
|
67
|
+
}
|
|
68
|
+
return this.createValidationResult(errors, warnings);
|
|
69
|
+
}
|
|
70
|
+
async generateEntity(options) {
|
|
71
|
+
const { entity, relationships, allEntities, apiType } = options;
|
|
72
|
+
const { name, fields = [], indexes, uniques } = entity;
|
|
73
|
+
const columns = (0, field_1.getFieldForTemplate)(fields, name);
|
|
74
|
+
const createPrimaryKey = columns.filter((column) => column.primary === true).length === 0;
|
|
75
|
+
const createdAt = entity.created_at;
|
|
76
|
+
const updatedAt = entity.updated_at;
|
|
77
|
+
const primaryKeyType = entity.primaryKeyType || "serial";
|
|
78
|
+
const relationshipsForTemplate = (0, relationships_1.getRelationshipForTemplate)(name, relationships, allEntities);
|
|
79
|
+
const entitiesToImport = (0, relationships_1.getRelationshipsForImport)(name, relationshipsForTemplate);
|
|
80
|
+
const data = {
|
|
81
|
+
name,
|
|
82
|
+
indexes: indexes || [],
|
|
83
|
+
uniques: uniques || [],
|
|
84
|
+
createPrimaryKey,
|
|
85
|
+
primaryKeyType,
|
|
86
|
+
snakeCasedName: (0, casing_1.snakeCase)(name),
|
|
87
|
+
createdAt,
|
|
88
|
+
updatedAt,
|
|
89
|
+
pluralizedName: (0, casing_1.camelCase)((0, pluralize_1.default)(name)),
|
|
90
|
+
columns,
|
|
91
|
+
associations: [...new Set(relationshipsForTemplate)],
|
|
92
|
+
entitiesToImport,
|
|
93
|
+
importEnums: (0, field_1.typeExistsInEntity)(entity, "enum") !== -1,
|
|
94
|
+
apiType,
|
|
95
|
+
};
|
|
96
|
+
const templatePath = apiType === "graphql"
|
|
97
|
+
? "./graphql/gql-entity-graphql"
|
|
98
|
+
: "./entities/entity";
|
|
99
|
+
const content = await this.renderTemplate(templatePath, data);
|
|
100
|
+
return [
|
|
101
|
+
{
|
|
102
|
+
path: `${name}/${name}.entity.ts`,
|
|
103
|
+
content,
|
|
104
|
+
},
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
async generateController(options) {
|
|
108
|
+
const { entity, relationships, relationshipMap } = options;
|
|
109
|
+
const { name: entityName } = entity;
|
|
110
|
+
const relationshipsForTemplate = (0, relationships_1.getRelationshipForTemplate)(entityName, relationships);
|
|
111
|
+
// Handle nested relationships for joins
|
|
112
|
+
const tmpDir = os.tmpdir();
|
|
113
|
+
const nestedJoinsFile = path.join(tmpDir, `apso-nested-joins-${entityName}-${Date.now()}.eta`);
|
|
114
|
+
const nestedJoinsStream = fs.createWriteStream(nestedJoinsFile, {
|
|
115
|
+
encoding: "utf8",
|
|
116
|
+
});
|
|
117
|
+
await (0, parse_1.streamNestedRelationships)(entityName, relationshipMap, nestedJoinsStream);
|
|
118
|
+
nestedJoinsStream.end();
|
|
119
|
+
await new Promise((resolve) => {
|
|
120
|
+
nestedJoinsStream.on("finish", resolve);
|
|
121
|
+
});
|
|
122
|
+
const svcName = `${entityName}Service`;
|
|
123
|
+
const ctrlName = `${entityName}Controller`;
|
|
124
|
+
const pluralEntityName = (0, pluralize_1.default)(entityName);
|
|
125
|
+
const primaryKeyType = entity.primaryKeyType || "serial";
|
|
126
|
+
const data = {
|
|
127
|
+
svcName,
|
|
128
|
+
ctrlName,
|
|
129
|
+
entityName,
|
|
130
|
+
pluralEntityName,
|
|
131
|
+
primaryKeyType,
|
|
132
|
+
associations: [...new Set(relationshipsForTemplate)],
|
|
133
|
+
nestedJoinsFile,
|
|
134
|
+
};
|
|
135
|
+
const controllerContent = await this.renderTemplate("./rest/controller-rest", data);
|
|
136
|
+
const specContent = await this.renderTemplate("./rest/controller-rest-spec", data);
|
|
137
|
+
// Clean up temp file
|
|
138
|
+
try {
|
|
139
|
+
await unlinkAsync(nestedJoinsFile);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
// Ignore cleanup errors
|
|
143
|
+
}
|
|
144
|
+
return [
|
|
145
|
+
{
|
|
146
|
+
path: `${entityName}/${entityName}.controller.ts`,
|
|
147
|
+
content: controllerContent,
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
path: `${entityName}/${entityName}.controller.spec.ts`,
|
|
151
|
+
content: specContent,
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
async generateService(options) {
|
|
156
|
+
const { entity, relationshipMap } = options;
|
|
157
|
+
const { name: entityName } = entity;
|
|
158
|
+
const svcName = `${entityName}Service`;
|
|
159
|
+
const repoName = `${entityName}Repository`;
|
|
160
|
+
// Collect all related entities for the test file
|
|
161
|
+
let allRelatedEntities = [entityName];
|
|
162
|
+
if (relationshipMap && relationshipMap[entityName]) {
|
|
163
|
+
const visited = new Set();
|
|
164
|
+
const collect = (entName) => {
|
|
165
|
+
if (visited.has(entName))
|
|
166
|
+
return;
|
|
167
|
+
visited.add(entName);
|
|
168
|
+
allRelatedEntities.push(entName);
|
|
169
|
+
const rels = relationshipMap[entName] || [];
|
|
170
|
+
for (const rel of rels) {
|
|
171
|
+
if (!visited.has(rel.name)) {
|
|
172
|
+
collect(rel.name);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
allRelatedEntities = [];
|
|
177
|
+
collect(entityName);
|
|
178
|
+
allRelatedEntities = [...new Set(allRelatedEntities)];
|
|
179
|
+
}
|
|
180
|
+
const data = {
|
|
181
|
+
svcName,
|
|
182
|
+
repoName,
|
|
183
|
+
entityName,
|
|
184
|
+
allRelatedEntities,
|
|
185
|
+
};
|
|
186
|
+
const serviceContent = await this.renderTemplate("./rest/service-rest", data);
|
|
187
|
+
const specContent = await this.renderTemplate("./rest/service-rest-spec", data);
|
|
188
|
+
return [
|
|
189
|
+
{
|
|
190
|
+
path: `${entityName}/${entityName}.service.ts`,
|
|
191
|
+
content: serviceContent,
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
path: `${entityName}/${entityName}.service.spec.ts`,
|
|
195
|
+
content: specContent,
|
|
196
|
+
},
|
|
197
|
+
];
|
|
198
|
+
}
|
|
199
|
+
async generateDto(options) {
|
|
200
|
+
const { entity, relationships, allEntities, apiType } = options;
|
|
201
|
+
const { name: entityName, fields = [] } = entity;
|
|
202
|
+
const columns = (0, field_1.getFieldForTemplate)(fields, entityName);
|
|
203
|
+
const relationshipsTemplate = (0, relationships_1.getRelationshipForTemplate)(entityName, relationships);
|
|
204
|
+
// Add foreign key columns for ManyToOne relationships
|
|
205
|
+
relationshipsTemplate.forEach((rel) => {
|
|
206
|
+
if (rel.type === "ManyToOne") {
|
|
207
|
+
const fkName = (0, casing_1.camelCase)(rel.referenceName || rel.name) + "Id";
|
|
208
|
+
const referencedEntity = allEntities === null || allEntities === void 0 ? void 0 : allEntities.find((e) => e.name === rel.name);
|
|
209
|
+
const referencedPrimaryKeyType = (referencedEntity === null || referencedEntity === void 0 ? void 0 : referencedEntity.primaryKeyType) || "serial";
|
|
210
|
+
const fkDataType = referencedPrimaryKeyType === "uuid" ? "string" : "number";
|
|
211
|
+
const fkType = referencedPrimaryKeyType === "uuid" ? "text" : "integer";
|
|
212
|
+
if (!columns.some((col) => col.name === fkName)) {
|
|
213
|
+
columns.push({
|
|
214
|
+
name: fkName,
|
|
215
|
+
dataType: fkDataType,
|
|
216
|
+
type: fkType,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
const primaryKeyColumns = columns.filter((column) => column.primary === true);
|
|
222
|
+
const addDefaultPKProperty = primaryKeyColumns.length === 0;
|
|
223
|
+
const createdAt = entity.created_at;
|
|
224
|
+
const updatedAt = entity.updated_at;
|
|
225
|
+
const primaryKeyType = entity.primaryKeyType || "serial";
|
|
226
|
+
const dtoColumns = columns.filter((col) => !["id", "createdAt", "updatedAt"].includes(col.name));
|
|
227
|
+
const createDtoName = `Create${(0, casing_1.pascalCase)(entityName)}Dto`;
|
|
228
|
+
const updateDtoName = `Update${(0, casing_1.pascalCase)(entityName)}Dto`;
|
|
229
|
+
const data = {
|
|
230
|
+
entityName,
|
|
231
|
+
addDefaultPKProperty,
|
|
232
|
+
primaryKeyType,
|
|
233
|
+
createdAt,
|
|
234
|
+
updatedAt,
|
|
235
|
+
columns: dtoColumns,
|
|
236
|
+
associations: relationshipsTemplate,
|
|
237
|
+
createDtoName,
|
|
238
|
+
updateDtoName,
|
|
239
|
+
apiType: apiType !== null && apiType !== void 0 ? apiType : "rest",
|
|
240
|
+
importEnums: (0, field_1.typeExistsInEntity)(entity, "enum") !== -1,
|
|
241
|
+
};
|
|
242
|
+
const dtoContent = await this.renderTemplate("./rest/dto-rest", data);
|
|
243
|
+
return [
|
|
244
|
+
{
|
|
245
|
+
path: `${entityName}/dtos/${entityName}.dto.ts`,
|
|
246
|
+
content: dtoContent,
|
|
247
|
+
},
|
|
248
|
+
];
|
|
249
|
+
}
|
|
250
|
+
async generateModule(options) {
|
|
251
|
+
const { entity, apiType } = options;
|
|
252
|
+
const { name: entityName } = entity;
|
|
253
|
+
const moduleName = `${entityName}Module`;
|
|
254
|
+
const svcName = `${entityName}Service`;
|
|
255
|
+
const ctrlName = `${entityName}Controller`;
|
|
256
|
+
const resolverName = `${entityName}Resolver`;
|
|
257
|
+
const data = {
|
|
258
|
+
moduleName,
|
|
259
|
+
svcName,
|
|
260
|
+
ctrlName,
|
|
261
|
+
resolverName,
|
|
262
|
+
entityName,
|
|
263
|
+
};
|
|
264
|
+
const templatePath = apiType === "graphql"
|
|
265
|
+
? "./graphql/gql-module-graphql"
|
|
266
|
+
: "./rest/module-rest";
|
|
267
|
+
const content = await this.renderTemplate(templatePath, data);
|
|
268
|
+
return [
|
|
269
|
+
{
|
|
270
|
+
path: `${entityName}/${entityName}.module.ts`,
|
|
271
|
+
content,
|
|
272
|
+
},
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
async generateMigration(_options) {
|
|
276
|
+
// TypeORM handles migrations differently - typically via CLI
|
|
277
|
+
// This is a placeholder for future migration template generation
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
async generateEnums(entities, apiType) {
|
|
281
|
+
if (entities.length === 0) {
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
284
|
+
const allEnumsFields = entities
|
|
285
|
+
.flatMap((entity) => (entity.fields || []).map((field) => {
|
|
286
|
+
if (field.type === "enum") {
|
|
287
|
+
return { ...field, name: (0, field_1.fieldToEnumType)(field.name, entity.name) };
|
|
288
|
+
}
|
|
289
|
+
return null;
|
|
290
|
+
}))
|
|
291
|
+
.filter(Boolean);
|
|
292
|
+
if (allEnumsFields.length === 0) {
|
|
293
|
+
return [];
|
|
294
|
+
}
|
|
295
|
+
const content = await this.renderTemplate(`./${apiType}/enums-${apiType}`, {
|
|
296
|
+
allEnumsFields,
|
|
297
|
+
});
|
|
298
|
+
return [
|
|
299
|
+
{
|
|
300
|
+
path: "enums.ts",
|
|
301
|
+
content,
|
|
302
|
+
},
|
|
303
|
+
];
|
|
304
|
+
}
|
|
305
|
+
async generateIndexModule(entities, apiType) {
|
|
306
|
+
const content = await this.renderTemplate(`./${apiType}/index-module-${apiType}`, { entities });
|
|
307
|
+
return [
|
|
308
|
+
{
|
|
309
|
+
path: "index.ts",
|
|
310
|
+
content,
|
|
311
|
+
},
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
async generateGuards(entities, auth) {
|
|
315
|
+
const hasScopes = (0, guards_1.hasScopedEntities)(entities);
|
|
316
|
+
const normalizedAuth = this.normalizeAuthConfig(auth);
|
|
317
|
+
if (!hasScopes && !normalizedAuth) {
|
|
318
|
+
return [];
|
|
319
|
+
}
|
|
320
|
+
const scopedEntities = (0, guards_1.getScopedEntities)(entities);
|
|
321
|
+
const files = [];
|
|
322
|
+
const templateData = {
|
|
323
|
+
scopedEntities,
|
|
324
|
+
authConfig: normalizedAuth,
|
|
325
|
+
generatedAt: new Date().toISOString(),
|
|
326
|
+
generatedBy: "Apso CLI",
|
|
327
|
+
};
|
|
328
|
+
// Generate auth.guard.ts if auth is configured
|
|
329
|
+
if (normalizedAuth) {
|
|
330
|
+
const authGuardContent = await this.renderTemplate("./guards/auth.guard.eta", templateData);
|
|
331
|
+
files.push({
|
|
332
|
+
path: "guards/auth.guard.ts",
|
|
333
|
+
content: authGuardContent,
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
// Generate scope.guard.ts if there are scoped entities
|
|
337
|
+
if (hasScopes) {
|
|
338
|
+
const scopeGuardContent = await this.renderTemplate("./guards/scope.guard.eta", templateData);
|
|
339
|
+
files.push({
|
|
340
|
+
path: "guards/scope.guard.ts",
|
|
341
|
+
content: scopeGuardContent,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
// Generate guards.module.ts
|
|
345
|
+
const guardsModuleContent = await this.renderTemplate("./guards/guards.module.eta", templateData);
|
|
346
|
+
files.push({
|
|
347
|
+
path: "guards/guards.module.ts",
|
|
348
|
+
content: guardsModuleContent,
|
|
349
|
+
});
|
|
350
|
+
// Generate index.ts
|
|
351
|
+
const indexContent = await this.renderTemplate("./guards/index.eta", templateData);
|
|
352
|
+
files.push({
|
|
353
|
+
path: "guards/index.ts",
|
|
354
|
+
content: indexContent,
|
|
355
|
+
});
|
|
356
|
+
return files;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Normalizes auth config by applying defaults for DB session providers
|
|
360
|
+
*/
|
|
361
|
+
normalizeAuthConfig(auth) {
|
|
362
|
+
if (!auth)
|
|
363
|
+
return undefined;
|
|
364
|
+
if ((0, auth_1.isDbSessionAuth)(auth)) {
|
|
365
|
+
return {
|
|
366
|
+
...auth_1.DB_SESSION_AUTH_DEFAULTS,
|
|
367
|
+
...auth,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
return undefined;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
exports.TypeScriptGenerator = TypeScriptGenerator;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -9,3 +9,5 @@ export { createDto } from "./dto";
|
|
|
9
9
|
export { createEnums } from "./enums";
|
|
10
10
|
export { createGqlDTO } from "./gql-dto";
|
|
11
11
|
export { createGuards, hasScopedEntities, getScopedEntities } from "./guards";
|
|
12
|
+
export { BaseGenerator, TypeScriptGenerator, createGenerator, isLanguageSupported, getSupportedLanguages, getImplementedLanguages, } from "./generators";
|
|
13
|
+
export type { TargetLanguage, GeneratedFile, ValidationResult, GeneratorConfig, LanguageGenerator, } from "./types";
|
package/dist/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getScopedEntities = exports.hasScopedEntities = exports.createGuards = exports.createGqlDTO = exports.createEnums = exports.createDto = exports.createIndexAppModule = exports.createModule = exports.createService = exports.createController = exports.createEntity = exports.parseApsorc = void 0;
|
|
3
|
+
exports.getImplementedLanguages = exports.getSupportedLanguages = exports.isLanguageSupported = exports.createGenerator = exports.TypeScriptGenerator = exports.BaseGenerator = exports.getScopedEntities = exports.hasScopedEntities = exports.createGuards = exports.createGqlDTO = exports.createEnums = exports.createDto = exports.createIndexAppModule = exports.createModule = exports.createService = exports.createController = exports.createEntity = exports.parseApsorc = void 0;
|
|
4
4
|
var apsorc_parser_1 = require("./apsorc-parser");
|
|
5
5
|
Object.defineProperty(exports, "parseApsorc", { enumerable: true, get: function () { return apsorc_parser_1.parseApsorc; } });
|
|
6
6
|
var entity_1 = require("./entity");
|
|
@@ -23,3 +23,11 @@ var guards_1 = require("./guards");
|
|
|
23
23
|
Object.defineProperty(exports, "createGuards", { enumerable: true, get: function () { return guards_1.createGuards; } });
|
|
24
24
|
Object.defineProperty(exports, "hasScopedEntities", { enumerable: true, get: function () { return guards_1.hasScopedEntities; } });
|
|
25
25
|
Object.defineProperty(exports, "getScopedEntities", { enumerable: true, get: function () { return guards_1.getScopedEntities; } });
|
|
26
|
+
// Generator exports
|
|
27
|
+
var generators_1 = require("./generators");
|
|
28
|
+
Object.defineProperty(exports, "BaseGenerator", { enumerable: true, get: function () { return generators_1.BaseGenerator; } });
|
|
29
|
+
Object.defineProperty(exports, "TypeScriptGenerator", { enumerable: true, get: function () { return generators_1.TypeScriptGenerator; } });
|
|
30
|
+
Object.defineProperty(exports, "createGenerator", { enumerable: true, get: function () { return generators_1.createGenerator; } });
|
|
31
|
+
Object.defineProperty(exports, "isLanguageSupported", { enumerable: true, get: function () { return generators_1.isLanguageSupported; } });
|
|
32
|
+
Object.defineProperty(exports, "getSupportedLanguages", { enumerable: true, get: function () { return generators_1.getSupportedLanguages; } });
|
|
33
|
+
Object.defineProperty(exports, "getImplementedLanguages", { enumerable: true, get: function () { return generators_1.getImplementedLanguages; } });
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
<% const {field} = it; %>
|
|
2
|
-
|
|
2
|
+
<% if (field.name === 'createdAt') { %>
|
|
3
|
+
@CreateDateColumn()
|
|
4
|
+
createdAt: Date;
|
|
5
|
+
<% } else if (field.name === 'updatedAt') { %>
|
|
6
|
+
@UpdateDateColumn()
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
<% } else { %>
|
|
3
9
|
@Column({ type: 'timestamp', nullable: <%= Boolean(field.nullable) %> })
|
|
4
|
-
<%= field.name %>: Date;
|
|
10
|
+
<%= field.name %>: Date;
|
|
11
|
+
<% } %>
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
<% const {field} = it; %>
|
|
2
|
-
|
|
2
|
+
<% if (field.name === 'createdAt') { %>
|
|
3
|
+
@CreateDateColumn()
|
|
4
|
+
createdAt: Date;
|
|
5
|
+
<% } else if (field.name === 'updatedAt') { %>
|
|
6
|
+
@UpdateDateColumn()
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
<% } else { %>
|
|
3
9
|
@Column({ type: 'timestamptz', nullable: <%= Boolean(field.nullable) %> })
|
|
4
|
-
<%= field.name %>: Date;
|
|
10
|
+
<%= field.name %>: Date;
|
|
11
|
+
<% } %>
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
<%~ includeFile('./header.eta') %>
|
|
2
2
|
/* eslint @typescript-eslint/no-unused-vars: "off" */
|
|
3
3
|
|
|
4
|
+
<%
|
|
5
|
+
// Check if any columns are named createdAt or updatedAt
|
|
6
|
+
const hasCreatedAt = it.createdAt || it.columns.some(c => c.name === 'createdAt');
|
|
7
|
+
const hasUpdatedAt = it.updatedAt || it.columns.some(c => c.name === 'updatedAt');
|
|
8
|
+
%>
|
|
4
9
|
import {
|
|
5
10
|
Column,
|
|
6
11
|
Entity,
|
|
7
12
|
<%~ it.associations.map((assoc) => `${assoc.type},`).filter((v, i, s) => s.indexOf(v) === i).join("\r\n") %>
|
|
8
|
-
<% if (
|
|
13
|
+
<% if (hasCreatedAt) { %>
|
|
9
14
|
CreateDateColumn,
|
|
10
15
|
<% } %>
|
|
11
|
-
<% if (
|
|
16
|
+
<% if (hasUpdatedAt) { %>
|
|
12
17
|
UpdateDateColumn,
|
|
13
18
|
<% } %>
|
|
14
19
|
PrimaryGeneratedColumn,
|
|
@@ -68,15 +73,23 @@ export class <%= it.name %> {
|
|
|
68
73
|
|
|
69
74
|
<% if (it.createdAt) { %>
|
|
70
75
|
@CreateDateColumn()
|
|
71
|
-
|
|
76
|
+
createdAt: Date;
|
|
72
77
|
<% } %>
|
|
73
78
|
|
|
74
79
|
<% if (it.updatedAt) { %>
|
|
75
80
|
@UpdateDateColumn()
|
|
76
|
-
|
|
81
|
+
updatedAt: Date;
|
|
77
82
|
<% } %>
|
|
78
83
|
|
|
79
|
-
<%
|
|
84
|
+
<%
|
|
85
|
+
// Filter out id (if createPrimaryKey), createdAt, and updatedAt since they're handled separately
|
|
86
|
+
const columnsToProcess = it.columns.filter(c => {
|
|
87
|
+
if (it.createPrimaryKey && c.name === 'id') return false;
|
|
88
|
+
if (it.createdAt && c.name === 'createdAt') return false;
|
|
89
|
+
if (it.updatedAt && c.name === 'updatedAt') return false;
|
|
90
|
+
return true;
|
|
91
|
+
});
|
|
92
|
+
columnsToProcess.forEach((field) => { %>
|
|
80
93
|
|
|
81
94
|
<%~ includeFile(`./entities/entity-col-${field.type}`, { field }) %>
|
|
82
95
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> []<%= it.column.arrayItemGoType || 'string' %> `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> []<%= it.column.arrayItemGoType || 'string' %> `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> []<%= it.column.arrayItemGoType || 'string' %> `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>bool `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>bool `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *bool `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *time.Time `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *float64 `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<% const enumTypeName = it.column.enumType || (it.column.pascalName + 'Enum'); %>
|
|
2
|
+
<% if (it.mode === 'response') { %>
|
|
3
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>enums.<%= enumTypeName %> `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
4
|
+
<% } else if (it.mode === 'create') { %>
|
|
5
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>enums.<%= enumTypeName %> `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
6
|
+
<% } else { %>
|
|
7
|
+
<%= it.column.pascalName %> *enums.<%= enumTypeName %> `json:"<%= it.column.name %>,omitempty"`
|
|
8
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *float64 `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>int `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>int `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *int `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> map[string]interface{} `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> map[string]interface{} `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> map[string]interface{} `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> map[string]interface{} `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> map[string]interface{} `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> map[string]interface{} `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>float64 `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *float64 `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required<% if (it.column.length) { %>,max=<%= it.column.length %><% } %>"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *string `json:"<%= it.column.name %>,omitempty"<% if (it.column.length) { %> validate:"omitempty,max=<%= it.column.length %>"<% } %>`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *string `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *time.Time `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>time.Time `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *time.Time `json:"<%= it.column.name %>,omitempty"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required,uuid"<% } else { %> validate:"omitempty,uuid"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *string `json:"<%= it.column.name %>,omitempty" validate:"omitempty,uuid"`
|
|
7
|
+
<% } %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<% if (it.mode === 'response') { %>
|
|
2
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"`
|
|
3
|
+
<% } else if (it.mode === 'create') { %>
|
|
4
|
+
<%= it.column.pascalName %> <% if (!it.column.required) { %>*<% } %>string `json:"<%= it.column.name %><% if (!it.column.required) { %>,omitempty<% } %>"<% if (it.column.required) { %> validate:"required<% if (it.column.length) { %>,max=<%= it.column.length %><% } %>"<% } %>`
|
|
5
|
+
<% } else { %>
|
|
6
|
+
<%= it.column.pascalName %> *string `json:"<%= it.column.name %>,omitempty"<% if (it.column.length) { %> validate:"omitempty,max=<%= it.column.length %>"<% } %>`
|
|
7
|
+
<% } %>
|