@apso/cli 0.7.3 → 0.7.4
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.
|
@@ -5,6 +5,7 @@ export default class Scaffold extends BaseCommand {
|
|
|
5
5
|
static examples: string[];
|
|
6
6
|
static flags: {
|
|
7
7
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
8
|
+
"skip-format": import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
8
9
|
};
|
|
9
10
|
static args: {};
|
|
10
11
|
scaffoldServer(options: {
|
|
@@ -77,6 +77,8 @@ class Scaffold extends base_command_1.default {
|
|
|
77
77
|
await (0, lib_1.createGqlDTO)(filePath, entity, entityRelationships);
|
|
78
78
|
}
|
|
79
79
|
async run() {
|
|
80
|
+
const { flags } = await this.parse(Scaffold);
|
|
81
|
+
const skipFormat = flags["skip-format"];
|
|
80
82
|
const totalBuildStart = perf_hooks_1.performance.now();
|
|
81
83
|
const { rootFolder, entities, relationshipMap, apiType, auth } = (0, lib_1.parseApsorc)();
|
|
82
84
|
const rootPath = path.join(process.cwd(), rootFolder);
|
|
@@ -104,17 +106,26 @@ class Scaffold extends base_command_1.default {
|
|
|
104
106
|
await (0, lib_1.createIndexAppModule)(autogenPath, entities, lowerCaseApiType);
|
|
105
107
|
const totalBuildTime = perf_hooks_1.performance.now() - totalBuildStart;
|
|
106
108
|
console.log(`[apso] Finished building all entities in ${totalBuildTime.toFixed(2)} ms`);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
if (!skipFormat) {
|
|
110
|
+
const formatStart = perf_hooks_1.performance.now();
|
|
111
|
+
console.log("[apso] Formatting files...");
|
|
112
|
+
await this.runNpmCommand(["run", "format", "src/autogen/**/*.ts", "src/guards/**/*.ts"], true);
|
|
113
|
+
const formatTime = perf_hooks_1.performance.now() - formatStart;
|
|
114
|
+
console.log(`[apso] Finished formatting in ${formatTime.toFixed(2)} ms`);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.log("[apso] Skipping formatting (--skip-format flag set)");
|
|
118
|
+
}
|
|
112
119
|
}
|
|
113
120
|
}
|
|
114
121
|
Scaffold.description = "Setup new entities and interfaces for an Apso Server";
|
|
115
|
-
Scaffold.examples = [`$ apso server scaffold`];
|
|
122
|
+
Scaffold.examples = [`$ apso server scaffold`, `$ apso server scaffold --skip-format`];
|
|
116
123
|
Scaffold.flags = {
|
|
117
124
|
help: core_1.Flags.help({ char: "h" }),
|
|
125
|
+
"skip-format": core_1.Flags.boolean({
|
|
126
|
+
description: "Skip the formatting step (useful when prettier is not available)",
|
|
127
|
+
default: false,
|
|
128
|
+
}),
|
|
118
129
|
};
|
|
119
130
|
Scaffold.args = {};
|
|
120
131
|
exports.default = Scaffold;
|
|
@@ -1,25 +1,65 @@
|
|
|
1
1
|
<%~ includeFile('./header.eta') %>
|
|
2
2
|
|
|
3
|
-
import { Injectable } from "@nestjs/common";
|
|
3
|
+
import { Injectable, NotFoundException } from "@nestjs/common";
|
|
4
4
|
import { InjectRepository } from "@nestjs/typeorm";
|
|
5
5
|
import { TypeOrmCrudService } from "@nestjsx/crud-typeorm";
|
|
6
|
-
import { QueryOptions } from '@nestjsx/crud';
|
|
6
|
+
import { QueryOptions, CrudRequest } from '@nestjsx/crud';
|
|
7
7
|
import { ParsedRequestParams } from '@nestjsx/crud-request';
|
|
8
|
+
import { Repository, DeepPartial } from 'typeorm';
|
|
8
9
|
|
|
9
10
|
import {<%= it.entityName %>} from './<%= it.entityName%>.entity'
|
|
10
11
|
|
|
11
12
|
@Injectable()
|
|
12
13
|
export class <%= it.svcName %> extends TypeOrmCrudService<<%= it.entityName %>> {
|
|
13
|
-
constructor(@InjectRepository(<%= it.entityName %>) repo) {
|
|
14
|
+
constructor(@InjectRepository(<%= it.entityName %>) repo: Repository<<%= it.entityName %>>) {
|
|
14
15
|
super(repo);
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Solves https://github.com/nestjsx/crud/issues/777
|
|
20
|
+
*/
|
|
21
|
+
getSelect(query: ParsedRequestParams, options: QueryOptions) {
|
|
22
|
+
return [...new Set(super.getSelect(query, options))]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Override updateOne to fix NestJS CRUD bug where PATCH causes INSERT instead of UPDATE.
|
|
27
|
+
* This properly fetches the existing entity, merges with the DTO, then saves.
|
|
28
|
+
*/
|
|
29
|
+
async updateOne(req: CrudRequest, dto: DeepPartial<<%= it.entityName %>>): Promise<<%= it.entityName %>> {
|
|
30
|
+
const id = req.parsed.paramsFilter?.find(f => f.field === 'id')?.value;
|
|
31
|
+
if (!id) {
|
|
32
|
+
throw new NotFoundException('<%= it.entityName %> ID not provided');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const existing = await this.repo.findOne({ where: { id } as any });
|
|
36
|
+
if (!existing) {
|
|
37
|
+
throw new NotFoundException('<%= it.entityName %> not found');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Merge existing entity with DTO and save
|
|
41
|
+
const merged = this.repo.merge(existing, dto as any);
|
|
42
|
+
return this.repo.save(merged);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Override replaceOne to fix NestJS CRUD bug where PUT causes INSERT instead of UPDATE.
|
|
47
|
+
* This properly fetches the existing entity, replaces it with the DTO, then saves.
|
|
48
|
+
*/
|
|
49
|
+
async replaceOne(req: CrudRequest, dto: DeepPartial<<%= it.entityName %>>): Promise<<%= it.entityName %>> {
|
|
50
|
+
const id = req.parsed.paramsFilter?.find(f => f.field === 'id')?.value;
|
|
51
|
+
if (!id) {
|
|
52
|
+
throw new NotFoundException('<%= it.entityName %> ID not provided');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const existing = await this.repo.findOne({ where: { id } as any });
|
|
56
|
+
if (!existing) {
|
|
57
|
+
throw new NotFoundException('<%= it.entityName %> not found');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Replace with DTO (keeping the ID) and save
|
|
61
|
+
const replaced = { ...dto, id: existing.id } as <%= it.entityName %>;
|
|
62
|
+
return this.repo.save(replaced);
|
|
63
|
+
}
|
|
24
64
|
}
|
|
25
65
|
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.7.
|
|
2
|
+
"version": "0.7.4",
|
|
3
3
|
"commands": {
|
|
4
4
|
"server:new": {
|
|
5
5
|
"id": "server:new",
|
|
@@ -43,7 +43,8 @@
|
|
|
43
43
|
"pluginType": "core",
|
|
44
44
|
"aliases": [],
|
|
45
45
|
"examples": [
|
|
46
|
-
"$ apso server scaffold"
|
|
46
|
+
"$ apso server scaffold",
|
|
47
|
+
"$ apso server scaffold --skip-format"
|
|
47
48
|
],
|
|
48
49
|
"flags": {
|
|
49
50
|
"help": {
|
|
@@ -52,6 +53,12 @@
|
|
|
52
53
|
"char": "h",
|
|
53
54
|
"description": "Show CLI help.",
|
|
54
55
|
"allowNo": false
|
|
56
|
+
},
|
|
57
|
+
"skip-format": {
|
|
58
|
+
"name": "skip-format",
|
|
59
|
+
"type": "boolean",
|
|
60
|
+
"description": "Skip the formatting step (useful when prettier is not available)",
|
|
61
|
+
"allowNo": false
|
|
55
62
|
}
|
|
56
63
|
},
|
|
57
64
|
"args": {}
|