nicot 1.0.0
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/.eslintignore +4 -0
- package/.eslintrc.js +24 -0
- package/.prettierrc +4 -0
- package/LICENSE +22 -0
- package/README.md +3 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/src/bases/id-base.d.ts +46 -0
- package/dist/src/bases/id-base.js +57 -0
- package/dist/src/bases/id-base.js.map +1 -0
- package/dist/src/bases/index.d.ts +2 -0
- package/dist/src/bases/index.js +19 -0
- package/dist/src/bases/index.js.map +1 -0
- package/dist/src/bases/time-base.d.ts +19 -0
- package/dist/src/bases/time-base.js +47 -0
- package/dist/src/bases/time-base.js.map +1 -0
- package/dist/src/crud-base.d.ts +103 -0
- package/dist/src/crud-base.js +262 -0
- package/dist/src/crud-base.js.map +1 -0
- package/dist/src/decorators/access.d.ts +2 -0
- package/dist/src/decorators/access.js +11 -0
- package/dist/src/decorators/access.js.map +1 -0
- package/dist/src/decorators/index.d.ts +5 -0
- package/dist/src/decorators/index.js +22 -0
- package/dist/src/decorators/index.js.map +1 -0
- package/dist/src/decorators/merge.d.ts +4 -0
- package/dist/src/decorators/merge.js +36 -0
- package/dist/src/decorators/merge.js.map +1 -0
- package/dist/src/decorators/pipes.d.ts +4 -0
- package/dist/src/decorators/pipes.js +23 -0
- package/dist/src/decorators/pipes.js.map +1 -0
- package/dist/src/decorators/property.d.ts +25 -0
- package/dist/src/decorators/property.js +110 -0
- package/dist/src/decorators/property.js.map +1 -0
- package/dist/src/decorators/restful.d.ts +28 -0
- package/dist/src/decorators/restful.js +86 -0
- package/dist/src/decorators/restful.js.map +1 -0
- package/dist/src/dto/import-entry.d.ts +11 -0
- package/dist/src/dto/import-entry.js +28 -0
- package/dist/src/dto/import-entry.js.map +1 -0
- package/dist/src/dto/index.d.ts +2 -0
- package/dist/src/dto/index.js +19 -0
- package/dist/src/dto/index.js.map +1 -0
- package/dist/src/dto/page-settings.d.ts +20 -0
- package/dist/src/dto/page-settings.js +61 -0
- package/dist/src/dto/page-settings.js.map +1 -0
- package/dist/src/dto/return-message.d.ts +42 -0
- package/dist/src/dto/return-message.js +110 -0
- package/dist/src/dto/return-message.js.map +1 -0
- package/dist/src/utility/bigint.d.ts +5 -0
- package/dist/src/utility/bigint.js +16 -0
- package/dist/src/utility/bigint.js.map +1 -0
- package/dist/src/utility/index.d.ts +1 -0
- package/dist/src/utility/index.js +18 -0
- package/dist/src/utility/index.js.map +1 -0
- package/dist/src/utility/insert-field.d.ts +17 -0
- package/dist/src/utility/insert-field.js +24 -0
- package/dist/src/utility/insert-field.js.map +1 -0
- package/dist/src/utility/query.d.ts +5 -0
- package/dist/src/utility/query.js +35 -0
- package/dist/src/utility/query.js.map +1 -0
- package/index.ts +5 -0
- package/package.json +66 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CrudService = exports.CrudBase = exports.Inner = void 0;
|
|
7
|
+
const dto_1 = require("./dto");
|
|
8
|
+
const common_1 = require("@nestjs/common");
|
|
9
|
+
const StringUtils_1 = require("typeorm/util/StringUtils");
|
|
10
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
11
|
+
const Inner = (name) => {
|
|
12
|
+
return { name, inner: true };
|
|
13
|
+
};
|
|
14
|
+
exports.Inner = Inner;
|
|
15
|
+
class CrudBase {
|
|
16
|
+
constructor(entityClass, repo, crudOptions) {
|
|
17
|
+
this.entityClass = entityClass;
|
|
18
|
+
this.repo = repo;
|
|
19
|
+
this.crudOptions = crudOptions;
|
|
20
|
+
this.entityName = this.entityClass.name;
|
|
21
|
+
this.entityReturnMessageDto = (0, dto_1.ReturnMessageDto)(this.entityClass);
|
|
22
|
+
this.entityPaginatedReturnMessageDto = (0, dto_1.PaginatedReturnMessageDto)(this.entityClass);
|
|
23
|
+
this.log = new common_1.ConsoleLogger(`${this.entityClass.name}Service`);
|
|
24
|
+
this.entityRelations = crudOptions.relations || [];
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
26
|
+
this.extraGetQuery = crudOptions.extraGetQuery || ((qb) => { });
|
|
27
|
+
}
|
|
28
|
+
async batchCreate(ents, beforeCreate, skipErrors = false) {
|
|
29
|
+
const entsWithId = ents.filter((ent) => ent.id != null);
|
|
30
|
+
return await this.repo.manager.transaction(async (mdb) => {
|
|
31
|
+
let skipped = [];
|
|
32
|
+
const repo = mdb.getRepository(this.entityClass);
|
|
33
|
+
if (entsWithId.length) {
|
|
34
|
+
const existingEnts = await repo.find({
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
where: { id: In(entsWithId.map((ent) => ent.id)) },
|
|
38
|
+
select: ['id', 'deleteTime'],
|
|
39
|
+
withDeleted: true,
|
|
40
|
+
});
|
|
41
|
+
if (existingEnts.length) {
|
|
42
|
+
const existingEntsWithoutDeleteTime = existingEnts.filter((ent) => ent.deleteTime == null);
|
|
43
|
+
const existingEntsWithDeleteTime = existingEnts.filter((ent) => ent.deleteTime != null);
|
|
44
|
+
if (existingEntsWithoutDeleteTime.length) {
|
|
45
|
+
if (!skipErrors) {
|
|
46
|
+
throw new dto_1.BlankReturnMessageDto(404, `${this.entityName} ID ${existingEntsWithoutDeleteTime.join(',')} already exists`).toException();
|
|
47
|
+
}
|
|
48
|
+
const skippedEnts = ents.filter((ent) => existingEntsWithoutDeleteTime.some((e) => e.id === ent.id));
|
|
49
|
+
skipped = skippedEnts.map((ent) => ({
|
|
50
|
+
result: 'Already exists',
|
|
51
|
+
entry: ent,
|
|
52
|
+
}));
|
|
53
|
+
const skippedEntsSet = new Set(skippedEnts);
|
|
54
|
+
ents = ents.filter((ent) => !skippedEntsSet.has(ent));
|
|
55
|
+
}
|
|
56
|
+
if (existingEntsWithDeleteTime.length) {
|
|
57
|
+
await repo.delete(existingEntsWithDeleteTime.map((ent) => ent.id));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (beforeCreate) {
|
|
62
|
+
await beforeCreate(repo);
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const results = await repo.save(ents);
|
|
66
|
+
return {
|
|
67
|
+
results,
|
|
68
|
+
skipped,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
this.log.error(`Failed to create entity ${JSON.stringify(ents)}: ${e.toString()}`);
|
|
73
|
+
throw new dto_1.BlankReturnMessageDto(500, 'internal error').toException();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
async create(ent, beforeCreate) {
|
|
78
|
+
const savedEnt = await this.repo.manager.transaction(async (mdb) => {
|
|
79
|
+
const repo = mdb.getRepository(this.entityClass);
|
|
80
|
+
if (ent.id != null) {
|
|
81
|
+
const existingEnt = await repo.findOne({
|
|
82
|
+
where: { id: ent.id },
|
|
83
|
+
select: ['id', 'deleteTime'],
|
|
84
|
+
withDeleted: true,
|
|
85
|
+
});
|
|
86
|
+
if (existingEnt) {
|
|
87
|
+
if (existingEnt.deleteTime) {
|
|
88
|
+
await repo.delete(existingEnt.id);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new dto_1.BlankReturnMessageDto(404, `${this.entityName} ID ${ent.id} already exists`).toException();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (beforeCreate) {
|
|
96
|
+
await beforeCreate(repo);
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
return await repo.save(ent);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
this.log.error(`Failed to create entity ${JSON.stringify(ent)}: ${e.toString()}`);
|
|
103
|
+
throw new dto_1.BlankReturnMessageDto(500, 'internal error').toException();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
return new this.entityReturnMessageDto(201, 'success', savedEnt);
|
|
107
|
+
}
|
|
108
|
+
get entityAliasName() {
|
|
109
|
+
return (0, StringUtils_1.camelCase)(this.entityName);
|
|
110
|
+
}
|
|
111
|
+
applyRelationToQuery(qb, relation) {
|
|
112
|
+
const { name } = relation;
|
|
113
|
+
const relationUnit = name.split('.');
|
|
114
|
+
const base = relationUnit.length === 1
|
|
115
|
+
? this.entityAliasName
|
|
116
|
+
: relationUnit.slice(0, relationUnit.length - 1).join('_');
|
|
117
|
+
const property = relationUnit[relationUnit.length - 1];
|
|
118
|
+
const properyAlias = relationUnit.join('_');
|
|
119
|
+
const methodName = relation.inner
|
|
120
|
+
? 'innerJoinAndSelect'
|
|
121
|
+
: 'leftJoinAndSelect';
|
|
122
|
+
qb[methodName](`${base}.${property}`, properyAlias);
|
|
123
|
+
}
|
|
124
|
+
applyRelationsToQuery(qb) {
|
|
125
|
+
for (const relation of this.entityRelations) {
|
|
126
|
+
if (typeof relation === 'string') {
|
|
127
|
+
this.applyRelationToQuery(qb, { name: relation });
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
this.applyRelationToQuery(qb, relation);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
queryBuilder() {
|
|
135
|
+
return this.repo.createQueryBuilder(this.entityAliasName);
|
|
136
|
+
}
|
|
137
|
+
async findOne(id,
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
139
|
+
extraQuery = () => { }) {
|
|
140
|
+
const query = this.queryBuilder()
|
|
141
|
+
.where(`${this.entityAliasName}.id = :id`, { id })
|
|
142
|
+
.take(1);
|
|
143
|
+
this.applyRelationsToQuery(query);
|
|
144
|
+
this.extraGetQuery(query);
|
|
145
|
+
extraQuery(query);
|
|
146
|
+
query.take(1);
|
|
147
|
+
let ent;
|
|
148
|
+
try {
|
|
149
|
+
ent = await query.getOne();
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
const [sql, params] = query.getQueryAndParameters();
|
|
153
|
+
this.log.error(`Failed to read entity ID ${id} with SQL ${sql} param ${params.join(',')}: ${e.toString()}`);
|
|
154
|
+
throw new dto_1.BlankReturnMessageDto(500, 'internal error').toException();
|
|
155
|
+
}
|
|
156
|
+
if (!ent) {
|
|
157
|
+
throw new dto_1.BlankReturnMessageDto(404, `${this.entityName} ID ${id} not found.`).toException();
|
|
158
|
+
}
|
|
159
|
+
return new this.entityReturnMessageDto(200, 'success', ent);
|
|
160
|
+
}
|
|
161
|
+
async findAll(ent,
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
163
|
+
extraQuery = () => { }) {
|
|
164
|
+
const query = this.queryBuilder();
|
|
165
|
+
if (ent) {
|
|
166
|
+
const newEnt = new this.entityClass();
|
|
167
|
+
Object.assign(newEnt, ent);
|
|
168
|
+
newEnt.applyQuery(query, this.entityAliasName);
|
|
169
|
+
}
|
|
170
|
+
this.applyRelationsToQuery(query);
|
|
171
|
+
this.extraGetQuery(query);
|
|
172
|
+
extraQuery(query);
|
|
173
|
+
try {
|
|
174
|
+
const [ents, count] = await query.getManyAndCount();
|
|
175
|
+
return new this.entityPaginatedReturnMessageDto(200, 'success', ents, count, ent.getActualPageSettings());
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
const [sql, params] = query.getQueryAndParameters();
|
|
179
|
+
this.log.error(`Failed to read entity cond ${JSON.stringify(ent)} with SQL ${sql} param ${params.join(',')}: ${e.toString()}`);
|
|
180
|
+
throw new dto_1.BlankReturnMessageDto(500, 'internal error').toException();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
async update(id, entPart, cond = {}) {
|
|
184
|
+
let result;
|
|
185
|
+
try {
|
|
186
|
+
result = await this.repo.update({
|
|
187
|
+
id,
|
|
188
|
+
...cond,
|
|
189
|
+
}, entPart);
|
|
190
|
+
}
|
|
191
|
+
catch (e) {
|
|
192
|
+
this.log.error(`Failed to update entity ID ${id} to ${JSON.stringify(entPart)}: ${e.toString()}`);
|
|
193
|
+
throw new dto_1.BlankReturnMessageDto(500, 'internal error').toException();
|
|
194
|
+
}
|
|
195
|
+
if (!result.affected) {
|
|
196
|
+
throw new dto_1.BlankReturnMessageDto(404, `${this.entityName} ID ${id} not found.`).toException();
|
|
197
|
+
}
|
|
198
|
+
return new dto_1.BlankReturnMessageDto(200, 'success');
|
|
199
|
+
}
|
|
200
|
+
async remove(id, cond = {}) {
|
|
201
|
+
let result;
|
|
202
|
+
const searchCond = {
|
|
203
|
+
id,
|
|
204
|
+
...cond,
|
|
205
|
+
};
|
|
206
|
+
try {
|
|
207
|
+
result = await (this.crudOptions.hardDelete
|
|
208
|
+
? this.repo.delete(searchCond)
|
|
209
|
+
: this.repo.softDelete(searchCond));
|
|
210
|
+
}
|
|
211
|
+
catch (e) {
|
|
212
|
+
this.log.error(`Failed to delete entity ID ${id}: ${e.toString()}`);
|
|
213
|
+
throw new dto_1.BlankReturnMessageDto(500, 'internal error').toException();
|
|
214
|
+
}
|
|
215
|
+
if (!result.affected) {
|
|
216
|
+
throw new dto_1.BlankReturnMessageDto(404, `${this.entityName} ID ${id} not found.`).toException();
|
|
217
|
+
}
|
|
218
|
+
return new dto_1.BlankReturnMessageDto(204, 'success');
|
|
219
|
+
}
|
|
220
|
+
async importEntities(ents, extraChecking) {
|
|
221
|
+
const invalidResults = lodash_1.default.compact(await Promise.all(ents.map(async (ent) => {
|
|
222
|
+
const reason = ent.isValidInCreation();
|
|
223
|
+
if (reason) {
|
|
224
|
+
return { entry: ent, result: reason };
|
|
225
|
+
}
|
|
226
|
+
if (extraChecking) {
|
|
227
|
+
const reason = await extraChecking(ent);
|
|
228
|
+
if (reason) {
|
|
229
|
+
return { entry: ent, result: reason };
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
})));
|
|
233
|
+
const remainingEnts = ents.filter((ent) => !invalidResults.find((result) => result.entry === ent));
|
|
234
|
+
await Promise.all(remainingEnts.map((ent) => ent.prepareForSaving()));
|
|
235
|
+
const data = await this.batchCreate(remainingEnts, undefined, true);
|
|
236
|
+
data.results.forEach((e) => {
|
|
237
|
+
if (e.afterSaving) {
|
|
238
|
+
e.afterSaving();
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
const results = [
|
|
242
|
+
...invalidResults,
|
|
243
|
+
...data.skipped,
|
|
244
|
+
...data.results.map((e) => ({ entry: e, result: 'OK' })),
|
|
245
|
+
];
|
|
246
|
+
return results;
|
|
247
|
+
}
|
|
248
|
+
async exists(id) {
|
|
249
|
+
const ent = await this.repo.findOne({ where: { id }, select: ['id'] });
|
|
250
|
+
return !!ent;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
exports.CrudBase = CrudBase;
|
|
254
|
+
function CrudService(entityClass, crudOptions) {
|
|
255
|
+
return class CrudServiceImpl extends CrudBase {
|
|
256
|
+
constructor(repo) {
|
|
257
|
+
super(entityClass, repo, crudOptions);
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
exports.CrudService = CrudService;
|
|
262
|
+
//# sourceMappingURL=crud-base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud-base.js","sourceRoot":"","sources":["../../src/crud-base.ts"],"names":[],"mappings":";;;;;;AAAA,+BAMe;AAWf,2CAA+C;AAC/C,0DAAqD;AACrD,oDAAuB;AAShB,MAAM,KAAK,GAAG,CAAC,IAAY,EAAe,EAAE;IACjD,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC/B,CAAC,CAAC;AAFW,QAAA,KAAK,SAEhB;AAeF,MAAa,QAAQ;IAUnB,YACS,WAAyB,EACzB,IAAmB,EACnB,WAA2B;QAF3B,gBAAW,GAAX,WAA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,SAAgB,WAAW,CACzB,WAAyB,EACzB,WAA2B;IAE3B,OAAO,MAAM,eAAgB,SAAQ,QAAW;QAC9C,YAAY,IAAmB;YAC7B,KAAK,CAAC,WAAW,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QACxC,CAAC;KACF,CAAC;AACJ,CAAC;AATD,kCASC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotChangeable = exports.NotWritable = void 0;
|
|
4
|
+
const class_transformer_1 = require("class-transformer");
|
|
5
|
+
const class_validator_1 = require("class-validator");
|
|
6
|
+
const merge_1 = require("./merge");
|
|
7
|
+
const NotWritable = () => (0, merge_1.MergePropertyDecorators)([(0, class_transformer_1.Expose)({ groups: ['r'] }), (0, class_validator_1.IsOptional)()]);
|
|
8
|
+
exports.NotWritable = NotWritable;
|
|
9
|
+
const NotChangeable = () => (0, class_transformer_1.Expose)({ groups: ['r', 'c'] });
|
|
10
|
+
exports.NotChangeable = NotChangeable;
|
|
11
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.js","sourceRoot":"","sources":["../../../src/decorators/access.ts"],"names":[],"mappings":";;;AAAA,yDAA2C;AAC3C,qDAA6C;AAC7C,mCAAkD;AAE3C,MAAM,WAAW,GAAG,GAAG,EAAE,CAC9B,IAAA,+BAAuB,EAAC,CAAC,IAAA,0BAAM,EAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,IAAA,4BAAU,GAAE,CAAC,CAAC,CAAC;AADxD,QAAA,WAAW,eAC6C;AAC9D,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,IAAA,0BAAM,EAAC,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;AAArD,QAAA,aAAa,iBAAwC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./access"), exports);
|
|
18
|
+
__exportStar(require("./merge"), exports);
|
|
19
|
+
__exportStar(require("./property"), exports);
|
|
20
|
+
__exportStar(require("./restful"), exports);
|
|
21
|
+
__exportStar(require("./pipes"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,4CAA0B;AAC1B,0CAAwB"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function MergePropertyDecorators(decs: PropertyDecorator[]): PropertyDecorator;
|
|
2
|
+
export declare function MergeMethodDecorators(decs: MethodDecorator[]): MethodDecorator;
|
|
3
|
+
export declare function MergeClassDecorators(decs: ClassDecorator[]): ClassDecorator;
|
|
4
|
+
export declare function MergeParameterDecorators(decs: ParameterDecorator[]): ParameterDecorator;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MergeParameterDecorators = exports.MergeClassDecorators = exports.MergeMethodDecorators = exports.MergePropertyDecorators = void 0;
|
|
4
|
+
function MergePropertyDecorators(decs) {
|
|
5
|
+
return (obj, key) => {
|
|
6
|
+
for (const dec of decs) {
|
|
7
|
+
dec(obj, key);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
exports.MergePropertyDecorators = MergePropertyDecorators;
|
|
12
|
+
function MergeMethodDecorators(decs) {
|
|
13
|
+
return (obj, key, descriptor) => {
|
|
14
|
+
for (const dec of decs) {
|
|
15
|
+
dec(obj, key, descriptor);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
exports.MergeMethodDecorators = MergeMethodDecorators;
|
|
20
|
+
function MergeClassDecorators(decs) {
|
|
21
|
+
return (obj) => {
|
|
22
|
+
for (const dec of decs) {
|
|
23
|
+
dec(obj);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.MergeClassDecorators = MergeClassDecorators;
|
|
28
|
+
function MergeParameterDecorators(decs) {
|
|
29
|
+
return (obj, key, index) => {
|
|
30
|
+
for (const dec of decs) {
|
|
31
|
+
dec(obj, key, index);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.MergeParameterDecorators = MergeParameterDecorators;
|
|
36
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../../src/decorators/merge.ts"],"names":[],"mappings":";;;AAAA,SAAgB,uBAAuB,CACrC,IAAyB;IAEzB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAClB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;SACf;IACH,CAAC,CAAC;AACJ,CAAC;AARD,0DAQC;AAED,SAAgB,qBAAqB,CACnC,IAAuB;IAEvB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE;QAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;SAC3B;IACH,CAAC,CAAC;AACJ,CAAC;AARD,sDAQC;AAED,SAAgB,oBAAoB,CAAC,IAAsB;IACzD,OAAO,CAAC,GAAG,EAAE,EAAE;QACb,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,GAAG,CAAC,GAAG,CAAC,CAAC;SACV;IACH,CAAC,CAAC;AACJ,CAAC;AAND,oDAMC;AAED,SAAgB,wBAAwB,CACtC,IAA0B;IAE1B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACzB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;SACtB;IACH,CAAC,CAAC;AACJ,CAAC;AARD,4DAQC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpdatePipe = exports.GetPipe = exports.CreatePipe = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.CreatePipe = new common_1.ValidationPipe({
|
|
6
|
+
transform: true,
|
|
7
|
+
transformOptions: { groups: ['c'], enableImplicitConversion: true },
|
|
8
|
+
});
|
|
9
|
+
exports.GetPipe = new common_1.ValidationPipe({
|
|
10
|
+
transform: true,
|
|
11
|
+
transformOptions: { groups: ['r'], enableImplicitConversion: true },
|
|
12
|
+
skipMissingProperties: true,
|
|
13
|
+
skipNullProperties: true,
|
|
14
|
+
skipUndefinedProperties: true,
|
|
15
|
+
});
|
|
16
|
+
exports.UpdatePipe = new common_1.ValidationPipe({
|
|
17
|
+
transform: true,
|
|
18
|
+
transformOptions: { groups: ['u'], enableImplicitConversion: true },
|
|
19
|
+
skipMissingProperties: true,
|
|
20
|
+
skipNullProperties: true,
|
|
21
|
+
skipUndefinedProperties: true,
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=pipes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipes.js","sourceRoot":"","sources":["../../../src/decorators/pipes.ts"],"names":[],"mappings":";;;AAAA,2CAAgD;AAEnC,QAAA,UAAU,GAAG,IAAI,uBAAc,CAAC;IAC3C,SAAS,EAAE,IAAI;IACf,gBAAgB,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE;CACpE,CAAC,CAAC;AAEU,QAAA,OAAO,GAAG,IAAI,uBAAc,CAAC;IACxC,SAAS,EAAE,IAAI;IACf,gBAAgB,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE;IACnE,qBAAqB,EAAE,IAAI;IAC3B,kBAAkB,EAAE,IAAI;IACxB,uBAAuB,EAAE,IAAI;CAC9B,CAAC,CAAC;AAEU,QAAA,UAAU,GAAG,IAAI,uBAAc,CAAC;IAC3C,SAAS,EAAE,IAAI;IACf,gBAAgB,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,wBAAwB,EAAE,IAAI,EAAE;IACnE,qBAAqB,EAAE,IAAI;IAC3B,kBAAkB,EAAE,IAAI;IACxB,uBAAuB,EAAE,IAAI;CAC9B,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ColumnCommonOptions } from 'typeorm/decorator/options/ColumnCommonOptions';
|
|
2
|
+
import { ApiPropertyOptions } from '@nestjs/swagger';
|
|
3
|
+
import { ColumnWithLengthOptions } from 'typeorm/decorator/options/ColumnWithLengthOptions';
|
|
4
|
+
import { WithPrecisionColumnType, WithWidthColumnType } from 'typeorm/driver/types/ColumnTypes';
|
|
5
|
+
import { ColumnWithWidthOptions } from 'typeorm/decorator/options/ColumnWithWidthOptions';
|
|
6
|
+
import { ColumnNumericOptions } from 'typeorm/decorator/options/ColumnNumericOptions';
|
|
7
|
+
export interface OpenAPIOptions<T> {
|
|
8
|
+
description?: string;
|
|
9
|
+
propertyExtras?: ApiPropertyOptions;
|
|
10
|
+
default?: T;
|
|
11
|
+
required?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export interface PropertyOptions<T, ColumnEx = unknown> extends OpenAPIOptions<T> {
|
|
14
|
+
columnExtras?: ColumnCommonOptions & ColumnEx;
|
|
15
|
+
}
|
|
16
|
+
export declare const StringColumn: (length: number, options?: PropertyOptions<string, ColumnWithLengthOptions>) => PropertyDecorator;
|
|
17
|
+
export declare const IntColumn: (type: WithWidthColumnType, options?: PropertyOptions<string, ColumnWithWidthOptions> & {
|
|
18
|
+
unsigned?: boolean;
|
|
19
|
+
}) => PropertyDecorator;
|
|
20
|
+
export declare const FloatColumn: (type: WithPrecisionColumnType, options?: PropertyOptions<string, ColumnNumericOptions> & {
|
|
21
|
+
unsigned?: boolean;
|
|
22
|
+
}) => PropertyDecorator;
|
|
23
|
+
export declare const DateColumn: (options?: PropertyOptions<Date>) => PropertyDecorator;
|
|
24
|
+
export declare const EnumColumn: <T>(targetEnum: Record<string, T>, options?: PropertyOptions<T, unknown>) => PropertyDecorator;
|
|
25
|
+
export declare const NotColumn: (options?: OpenAPIOptions<any>) => PropertyDecorator;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NotColumn = exports.EnumColumn = exports.DateColumn = exports.FloatColumn = exports.IntColumn = exports.StringColumn = void 0;
|
|
4
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
5
|
+
const merge_1 = require("./merge");
|
|
6
|
+
const typeorm_1 = require("typeorm");
|
|
7
|
+
const class_validator_1 = require("class-validator");
|
|
8
|
+
const class_transformer_1 = require("class-transformer");
|
|
9
|
+
const bigint_1 = require("../utility/bigint");
|
|
10
|
+
function swaggerDecorator(options, injected = {}) {
|
|
11
|
+
return (0, swagger_1.ApiProperty)({
|
|
12
|
+
default: options.default,
|
|
13
|
+
required: options.required && options.default == null,
|
|
14
|
+
example: options.default,
|
|
15
|
+
description: options.description,
|
|
16
|
+
...injected,
|
|
17
|
+
...(options.propertyExtras || {}),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function validatorDecorator(options) {
|
|
21
|
+
const decs = [];
|
|
22
|
+
if (!options.required) {
|
|
23
|
+
decs.push((0, class_validator_1.IsOptional)());
|
|
24
|
+
}
|
|
25
|
+
return (0, merge_1.MergePropertyDecorators)(decs);
|
|
26
|
+
}
|
|
27
|
+
function columnDecoratorOptions(options) {
|
|
28
|
+
return {
|
|
29
|
+
default: options.default,
|
|
30
|
+
nullable: !options.required && options.default == null,
|
|
31
|
+
comment: options.description,
|
|
32
|
+
...options.columnExtras,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const StringColumn = (length, options = {}) => {
|
|
36
|
+
return (0, merge_1.MergePropertyDecorators)([
|
|
37
|
+
(0, typeorm_1.Column)('varchar', { length, ...columnDecoratorOptions(options) }),
|
|
38
|
+
(0, class_validator_1.IsString)(),
|
|
39
|
+
(0, class_validator_1.MaxLength)(length),
|
|
40
|
+
validatorDecorator(options),
|
|
41
|
+
swaggerDecorator(options, { type: String, maxLength: length }),
|
|
42
|
+
]);
|
|
43
|
+
};
|
|
44
|
+
exports.StringColumn = StringColumn;
|
|
45
|
+
const IntColumn = (type, options = {}) => {
|
|
46
|
+
const decs = [
|
|
47
|
+
(0, typeorm_1.Column)(type, {
|
|
48
|
+
default: options.default,
|
|
49
|
+
unsigned: options.unsigned,
|
|
50
|
+
...(type === 'bigint' ? { transformer: new bigint_1.BigintTransformer() } : {}),
|
|
51
|
+
...columnDecoratorOptions(options),
|
|
52
|
+
}),
|
|
53
|
+
(0, class_validator_1.IsInt)(),
|
|
54
|
+
validatorDecorator(options),
|
|
55
|
+
swaggerDecorator(options, {
|
|
56
|
+
type: Number,
|
|
57
|
+
minimum: options.unsigned ? 0 : undefined,
|
|
58
|
+
}),
|
|
59
|
+
];
|
|
60
|
+
if (options.unsigned) {
|
|
61
|
+
decs.push((0, class_validator_1.Min)(0));
|
|
62
|
+
}
|
|
63
|
+
return (0, merge_1.MergePropertyDecorators)(decs);
|
|
64
|
+
};
|
|
65
|
+
exports.IntColumn = IntColumn;
|
|
66
|
+
const FloatColumn = (type, options = {}) => {
|
|
67
|
+
const decs = [
|
|
68
|
+
(0, typeorm_1.Column)(type, {
|
|
69
|
+
default: options.default,
|
|
70
|
+
unsigned: options.unsigned,
|
|
71
|
+
...columnDecoratorOptions(options),
|
|
72
|
+
}),
|
|
73
|
+
(0, class_validator_1.IsNumber)(),
|
|
74
|
+
validatorDecorator(options),
|
|
75
|
+
swaggerDecorator(options, {
|
|
76
|
+
type: Number,
|
|
77
|
+
minimum: options.unsigned ? 0 : undefined,
|
|
78
|
+
}),
|
|
79
|
+
];
|
|
80
|
+
if (options.unsigned) {
|
|
81
|
+
decs.push((0, class_validator_1.Min)(0));
|
|
82
|
+
}
|
|
83
|
+
return (0, merge_1.MergePropertyDecorators)(decs);
|
|
84
|
+
};
|
|
85
|
+
exports.FloatColumn = FloatColumn;
|
|
86
|
+
const DateColumn = (options = {}) => {
|
|
87
|
+
return (0, merge_1.MergePropertyDecorators)([
|
|
88
|
+
(0, typeorm_1.Column)('timestamp', columnDecoratorOptions(options)),
|
|
89
|
+
(0, class_validator_1.IsDate)(),
|
|
90
|
+
validatorDecorator(options),
|
|
91
|
+
swaggerDecorator(options, { type: Date }),
|
|
92
|
+
]);
|
|
93
|
+
};
|
|
94
|
+
exports.DateColumn = DateColumn;
|
|
95
|
+
const EnumColumn = (targetEnum, options = {}) => {
|
|
96
|
+
return (0, merge_1.MergePropertyDecorators)([
|
|
97
|
+
(0, typeorm_1.Index)(),
|
|
98
|
+
(0, typeorm_1.Column)('enum', {
|
|
99
|
+
enum: targetEnum,
|
|
100
|
+
...columnDecoratorOptions(options),
|
|
101
|
+
}),
|
|
102
|
+
(0, class_validator_1.IsEnum)(targetEnum),
|
|
103
|
+
validatorDecorator(options),
|
|
104
|
+
swaggerDecorator(options, { type: 'enum', enum: targetEnum }),
|
|
105
|
+
]);
|
|
106
|
+
};
|
|
107
|
+
exports.EnumColumn = EnumColumn;
|
|
108
|
+
const NotColumn = (options = {}) => (0, merge_1.MergePropertyDecorators)([(0, class_transformer_1.Exclude)(), swaggerDecorator(options)]);
|
|
109
|
+
exports.NotColumn = NotColumn;
|
|
110
|
+
//# sourceMappingURL=property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"property.js","sourceRoot":"","sources":["../../../src/decorators/property.ts"],"names":[],"mappings":";;;AACA,6CAAkE;AAElE,mCAAkD;AAClD,qCAAwC;AACxC,qDASyB;AAOzB,yDAA4C;AAC5C,8CAAsD;AAStD,SAAS,gBAAgB,CACvB,OAA4B,EAC5B,WAA+B,EAAE;IAEjC,OAAO,IAAA,qBAAW,EAAC;QACjB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,OAAO,IAAI,IAAI;QACrD,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,QAAQ;QACX,GAAG,CAAC,OAAO,CAAC,cAAc,IAAI,EAAE,CAAC;KAClC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CAAC,OAA4B;IACtD,MAAM,IAAI,GAAwB,EAAE,CAAC;IACrC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;QACrB,IAAI,CAAC,IAAI,CA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,CAAC;QACpD,IAAA,wBAAM,GAAE;QACR,kBAAkB,CAAC,OAAO,CAAC;QAC3B,gBAAgB,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC,CAAC;AATW,QAAA,UAAU,cASrB;AAEK,MAAM,UAAU,GAAG,CACxB,UAA6B,EAC7B,UAA8B,EAAE,EACb,EAAE;IACrB,OAAO,IAAA,+BAAuB,EAAC;QAC7B,IAAA,eAAK,GAAE;QACP,IAAA,gBAAM,EAAC,MAAM,EAAE;YACb,IAAI,EAAE,UAAU;YAChB,GAAG,sBAAsB,CAAC,OAAO,CAAC;SACnC,CAAC;QACF,IAAA,wBAAM,EAAC,UAAU,CAAC;QAClB,kBAAkB,CAAC,OAAO,CAAC;QAC3B,gBAAgB,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;KAC9D,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,UAAU,cAcrB;AAEK,MAAM,SAAS,GAAG,CACvB,UAA+B,EAAE,EACd,EAAE,CACrB,IAAA,+BAAuB,EAAC,CAAC,IAAA,2BAAO,GAAE,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAHrD,QAAA,SAAS,aAG4C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ClassType } from '../utility/insert-field';
|
|
2
|
+
import { TimeBase } from '../bases';
|
|
3
|
+
import { OperationObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';
|
|
4
|
+
export interface CrudFactoryOptions<T extends TimeBase> {
|
|
5
|
+
fieldsToOmit?: (keyof T)[];
|
|
6
|
+
}
|
|
7
|
+
export declare class RestfulFactory<T extends TimeBase> {
|
|
8
|
+
readonly entityClass: ClassType<T>;
|
|
9
|
+
private options;
|
|
10
|
+
readonly createDto: ClassType<Omit<T, keyof T>>;
|
|
11
|
+
readonly updateDto: ClassType<Partial<Omit<T, keyof T>>>;
|
|
12
|
+
readonly entityReturnMessageDto: new (statusCode: number, message?: string, data?: unknown) => import("../dto").GenericReturnMessageDto<unknown> & {
|
|
13
|
+
data: T;
|
|
14
|
+
};
|
|
15
|
+
readonly entityArrayReturnMessageDto: new (statusCode: number, message: string, data: unknown[], total: number, pageSettings: import("../dto").PageSettingsWise) => import("../dto").GenericPaginatedReturnMessageDto<unknown> & {
|
|
16
|
+
data: T[];
|
|
17
|
+
};
|
|
18
|
+
readonly idType: Function;
|
|
19
|
+
constructor(entityClass: ClassType<T>, options?: CrudFactoryOptions<T>);
|
|
20
|
+
create(extras?: Partial<OperationObject>): MethodDecorator;
|
|
21
|
+
createParam(): ParameterDecorator;
|
|
22
|
+
findOne(extras?: Partial<OperationObject>): MethodDecorator;
|
|
23
|
+
findAll(extras?: Partial<OperationObject>): MethodDecorator;
|
|
24
|
+
findAllParam(): ParameterDecorator;
|
|
25
|
+
update(extras?: Partial<OperationObject>): MethodDecorator;
|
|
26
|
+
updateParam(): ParameterDecorator;
|
|
27
|
+
delete(extras?: Partial<OperationObject>): MethodDecorator;
|
|
28
|
+
}
|