@hichchi/nest-crud 0.0.2 → 0.0.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.
- package/CHANGELOG.md +36 -12
- package/README.md +2475 -2085
- package/base/base-entity-extension.js +10 -6
- package/base/base-entity-extension.js.map +1 -1
- package/base/base-entity.js +47 -43
- package/base/base-entity.js.map +1 -1
- package/base/base-repository.js +16 -12
- package/base/base-repository.js.map +1 -1
- package/base/base-user.entity.js +85 -81
- package/base/base-user.entity.js.map +1 -1
- package/base/index.js +7 -4
- package/base/index.js.map +1 -1
- package/constants.js +10 -7
- package/constants.js.map +1 -1
- package/crud.module.js +29 -26
- package/crud.module.js.map +1 -1
- package/decorators/entity-extension.decorator.js +20 -17
- package/decorators/entity-extension.decorator.js.map +1 -1
- package/decorators/entity.decorator.js +30 -27
- package/decorators/entity.decorator.js.map +1 -1
- package/decorators/filter.decorator.js +8 -5
- package/decorators/filter.decorator.js.map +1 -1
- package/decorators/index.js +11 -8
- package/decorators/index.js.map +1 -1
- package/decorators/join-column.decorator.js +11 -8
- package/decorators/join-column.decorator.js.map +1 -1
- package/decorators/page.decorator.js +8 -5
- package/decorators/page.decorator.js.map +1 -1
- package/decorators/repository.decorator.js +14 -11
- package/decorators/repository.decorator.js.map +1 -1
- package/decorators/search.decorator.js +8 -5
- package/decorators/search.decorator.js.map +1 -1
- package/decorators/sort.decorator.js +8 -5
- package/decorators/sort.decorator.js.map +1 -1
- package/dtos/bulk-delete.dto.js +15 -12
- package/dtos/bulk-delete.dto.js.map +1 -1
- package/dtos/bulk-update.dto.js +18 -15
- package/dtos/bulk-update.dto.js.map +1 -1
- package/dtos/ids.dto.js +15 -12
- package/dtos/ids.dto.js.map +1 -1
- package/dtos/index.js +5 -2
- package/dtos/index.js.map +1 -1
- package/enums/crud.enums.js +7 -4
- package/enums/crud.enums.js.map +1 -1
- package/enums/index.js +4 -1
- package/enums/index.js.map +1 -1
- package/enums/metadata-keys.enum.js +5 -2
- package/enums/metadata-keys.enum.js.map +1 -1
- package/exceptions/index.js +4 -1
- package/exceptions/index.js.map +1 -1
- package/exceptions/typeorm.exception.js +9 -4
- package/exceptions/typeorm.exception.js.map +1 -1
- package/index.js +19 -12
- package/index.js.map +1 -1
- package/interfaces/connection-options.interface.js +2 -1
- package/interfaces/crud-options.interfaces.js +2 -1
- package/interfaces/index.js +5 -2
- package/interfaces/index.js.map +1 -1
- package/package.json +7 -6
- package/readme-top.md +1 -5
- package/responses/crud.error.responses.js +31 -28
- package/responses/crud.error.responses.js.map +1 -1
- package/responses/crud.success.responses.js +24 -21
- package/responses/crud.success.responses.js.map +1 -1
- package/responses/index.js +5 -2
- package/responses/index.js.map +1 -1
- package/services/crud.service.js +43 -39
- package/services/crud.service.js.map +1 -1
- package/services/index.js +4 -1
- package/services/index.js.map +1 -1
- package/tokens.js +5 -2
- package/tokens.js.map +1 -1
- package/types/database.types.d.ts +1 -1
- package/types/database.types.js +2 -1
- package/types/decorator.types.js +2 -1
- package/types/decorator.types.js.map +1 -1
- package/types/entity-option-unique.js +2 -1
- package/types/error-handler.type.js +2 -1
- package/types/filter-options.type.js +2 -1
- package/types/find-conditions.type.js +2 -1
- package/types/index.js +11 -8
- package/types/index.js.map +1 -1
- package/types/repository-decorator.type.js +2 -1
- package/types/sort-options.type.js +2 -1
- package/utils/entity.utils.js +46 -42
- package/utils/entity.utils.js.map +1 -1
- package/utils/http.utils.js +11 -6
- package/utils/http.utils.js.map +1 -1
- package/utils/index.js +5 -2
- package/utils/index.js.map +1 -1
- package/utils/repository.utils.js +12 -7
- package/utils/repository.utils.js.map +1 -1
package/utils/entity.utils.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityUtils = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const enums_1 = require("../enums");
|
|
6
|
+
const responses_1 = require("../responses");
|
|
7
|
+
const exceptions_1 = require("../exceptions");
|
|
8
|
+
const typeorm_1 = require("typeorm");
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const nest_core_1 = require("@hichchi/nest-core");
|
|
8
11
|
/**
|
|
9
12
|
* Utility class for handling entity-related operations and errors
|
|
10
13
|
*
|
|
@@ -46,7 +49,7 @@ import { LoggerService } from "@hichchi/nest-core";
|
|
|
46
49
|
* @see {@link Operation} For available operation types
|
|
47
50
|
* @see {@link isTypeormException} For TypeORM exception detection
|
|
48
51
|
*/
|
|
49
|
-
|
|
52
|
+
class EntityUtils {
|
|
50
53
|
/**
|
|
51
54
|
* Handle TypeORM errors
|
|
52
55
|
*
|
|
@@ -83,22 +86,22 @@ export class EntityUtils {
|
|
|
83
86
|
* @see {@link CrudErrorResponses} For standardized error response formats
|
|
84
87
|
*/
|
|
85
88
|
static handleError(error, entityName, uniqueFieldNames) {
|
|
86
|
-
if (error instanceof HttpException) {
|
|
89
|
+
if (error instanceof common_1.HttpException) {
|
|
87
90
|
throw error;
|
|
88
91
|
}
|
|
89
|
-
if (error instanceof EntityPropertyNotFoundError) {
|
|
90
|
-
const field = EXTRACT_INVALID_QUERY_FIELD_REGEX.exec(error.message)
|
|
91
|
-
? error.message.split(EXTRACT_INVALID_QUERY_FIELD_REGEX)[1]
|
|
92
|
+
if (error instanceof typeorm_1.EntityPropertyNotFoundError) {
|
|
93
|
+
const field = constants_1.EXTRACT_INVALID_QUERY_FIELD_REGEX.exec(error.message)
|
|
94
|
+
? error.message.split(constants_1.EXTRACT_INVALID_QUERY_FIELD_REGEX)[1]
|
|
92
95
|
: undefined;
|
|
93
|
-
throw new BadRequestException(CrudErrorResponses.E_400_QUERY(entityName, field, error.message));
|
|
96
|
+
throw new common_1.BadRequestException(responses_1.CrudErrorResponses.E_400_QUERY(entityName, field, error.message));
|
|
94
97
|
}
|
|
95
|
-
else if (isTypeormException(error)) {
|
|
98
|
+
else if ((0, exceptions_1.isTypeormException)(error)) {
|
|
96
99
|
switch (error.code) {
|
|
97
|
-
case TypeORMErrorType.ER_NO_DEFAULT_FOR_FIELD: {
|
|
100
|
+
case enums_1.TypeORMErrorType.ER_NO_DEFAULT_FOR_FIELD: {
|
|
98
101
|
const field = error.sqlMessage.split("'")[1];
|
|
99
|
-
throw new BadRequestException(CrudErrorResponses.E_400_NO_DEFAULT(entityName, field, error.sqlMessage ?? error.message));
|
|
102
|
+
throw new common_1.BadRequestException(responses_1.CrudErrorResponses.E_400_NO_DEFAULT(entityName, field, error.sqlMessage ?? error.message));
|
|
100
103
|
}
|
|
101
|
-
case TypeORMErrorType.ER_DUP_ENTRY: {
|
|
104
|
+
case enums_1.TypeORMErrorType.ER_DUP_ENTRY: {
|
|
102
105
|
const unique = error.sqlMessage
|
|
103
106
|
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
104
107
|
.split(/(for key )/)?.[2]
|
|
@@ -107,40 +110,40 @@ export class EntityUtils {
|
|
|
107
110
|
if (unique) {
|
|
108
111
|
const [, entityName, uniqueFieldName] = unique.split("_");
|
|
109
112
|
if (entityName && uniqueFieldName) {
|
|
110
|
-
throw new ConflictException(CrudErrorResponses.E_409_EXIST_U(entityName, [uniqueFieldName], error.sqlMessage ?? error.message));
|
|
113
|
+
throw new common_1.ConflictException(responses_1.CrudErrorResponses.E_409_EXIST_U(entityName, [uniqueFieldName], error.sqlMessage ?? error.message));
|
|
111
114
|
}
|
|
112
115
|
}
|
|
113
|
-
throw new ConflictException(CrudErrorResponses.E_409_EXIST_U(entityName, uniqueFieldNames || [], error.sqlMessage ?? error.message));
|
|
116
|
+
throw new common_1.ConflictException(responses_1.CrudErrorResponses.E_409_EXIST_U(entityName, uniqueFieldNames || [], error.sqlMessage ?? error.message));
|
|
114
117
|
}
|
|
115
|
-
case TypeORMErrorType.ER_NO_REFERENCED_ROW_2: {
|
|
118
|
+
case enums_1.TypeORMErrorType.ER_NO_REFERENCED_ROW_2: {
|
|
116
119
|
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
117
120
|
const fk = error.sqlMessage.split(/(CONSTRAINT `|` FOREIGN KEY)/)?.[2];
|
|
118
121
|
if (fk) {
|
|
119
122
|
const [, entityName, relationName] = fk.split("_");
|
|
120
123
|
if (entityName && relationName) {
|
|
121
|
-
throw new BadRequestException(CrudErrorResponses.E_404_RELATION(entityName, relationName, error.sqlMessage ?? error.message));
|
|
124
|
+
throw new common_1.BadRequestException(responses_1.CrudErrorResponses.E_404_RELATION(entityName, relationName, error.sqlMessage ?? error.message));
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
|
-
throw new InternalServerErrorException(CrudErrorResponses.E_500(error.sqlMessage ?? error.message));
|
|
127
|
+
throw new common_1.InternalServerErrorException(responses_1.CrudErrorResponses.E_500(error.sqlMessage ?? error.message));
|
|
125
128
|
}
|
|
126
|
-
case TypeORMErrorType.ER_BAD_FIELD_ERROR: {
|
|
127
|
-
LoggerService.error(error, EntityUtils.name);
|
|
128
|
-
const field = EXTRACT_INVALID_COLUMN_REGEX.exec(error.message)
|
|
129
|
-
? error.message.split(EXTRACT_INVALID_COLUMN_REGEX)[1]
|
|
129
|
+
case enums_1.TypeORMErrorType.ER_BAD_FIELD_ERROR: {
|
|
130
|
+
nest_core_1.LoggerService.error(error, EntityUtils.name);
|
|
131
|
+
const field = constants_1.EXTRACT_INVALID_COLUMN_REGEX.exec(error.message)
|
|
132
|
+
? error.message.split(constants_1.EXTRACT_INVALID_COLUMN_REGEX)[1]
|
|
130
133
|
: undefined;
|
|
131
|
-
throw new BadRequestException(CrudErrorResponses.E_400_QUERY(entityName, field, error.sqlMessage ?? error.message));
|
|
134
|
+
throw new common_1.BadRequestException(responses_1.CrudErrorResponses.E_400_QUERY(entityName, field, error.sqlMessage ?? error.message));
|
|
132
135
|
}
|
|
133
136
|
default:
|
|
134
|
-
LoggerService.error(error, EntityUtils.name);
|
|
135
|
-
throw new InternalServerErrorException(CrudErrorResponses.E_500(error.sqlMessage ?? error.message));
|
|
137
|
+
nest_core_1.LoggerService.error(error, EntityUtils.name);
|
|
138
|
+
throw new common_1.InternalServerErrorException(responses_1.CrudErrorResponses.E_500(error.sqlMessage ?? error.message));
|
|
136
139
|
}
|
|
137
140
|
}
|
|
138
141
|
else if (error instanceof Error) {
|
|
139
|
-
LoggerService.error(error, EntityUtils.name);
|
|
140
|
-
throw new InternalServerErrorException(CrudErrorResponses.E_500(error.message));
|
|
142
|
+
nest_core_1.LoggerService.error(error, EntityUtils.name);
|
|
143
|
+
throw new common_1.InternalServerErrorException(responses_1.CrudErrorResponses.E_500(error.message));
|
|
141
144
|
}
|
|
142
|
-
LoggerService.error(error, EntityUtils.name);
|
|
143
|
-
throw new InternalServerErrorException(CrudErrorResponses.E_500());
|
|
145
|
+
nest_core_1.LoggerService.error(error, EntityUtils.name);
|
|
146
|
+
throw new common_1.InternalServerErrorException(responses_1.CrudErrorResponses.E_500());
|
|
144
147
|
}
|
|
145
148
|
/**
|
|
146
149
|
* Handle success responses for CRUD operations
|
|
@@ -184,17 +187,18 @@ export class EntityUtils {
|
|
|
184
187
|
*/
|
|
185
188
|
static handleSuccess(entityName, operation) {
|
|
186
189
|
switch (operation) {
|
|
187
|
-
case Operation.CREATE:
|
|
188
|
-
return CrudSuccessResponses.CREATED(entityName);
|
|
189
|
-
case Operation.UPDATE:
|
|
190
|
-
return CrudSuccessResponses.UPDATE(entityName);
|
|
191
|
-
case Operation.SAVE:
|
|
192
|
-
return CrudSuccessResponses.SAVE(entityName);
|
|
193
|
-
case Operation.DELETE:
|
|
194
|
-
return CrudSuccessResponses.DELETE(entityName);
|
|
190
|
+
case enums_1.Operation.CREATE:
|
|
191
|
+
return responses_1.CrudSuccessResponses.CREATED(entityName);
|
|
192
|
+
case enums_1.Operation.UPDATE:
|
|
193
|
+
return responses_1.CrudSuccessResponses.UPDATE(entityName);
|
|
194
|
+
case enums_1.Operation.SAVE:
|
|
195
|
+
return responses_1.CrudSuccessResponses.SAVE(entityName);
|
|
196
|
+
case enums_1.Operation.DELETE:
|
|
197
|
+
return responses_1.CrudSuccessResponses.DELETE(entityName);
|
|
195
198
|
case undefined:
|
|
196
|
-
return CrudSuccessResponses.SUCCESS();
|
|
199
|
+
return responses_1.CrudSuccessResponses.SUCCESS();
|
|
197
200
|
}
|
|
198
201
|
}
|
|
199
202
|
}
|
|
203
|
+
exports.EntityUtils = EntityUtils;
|
|
200
204
|
//# sourceMappingURL=entity.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.utils.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/utils/entity.utils.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"entity.utils.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/utils/entity.utils.ts"],"names":[],"mappings":";;;AAAA,2CAAqH;AACrH,oCAAuD;AACvD,4CAAwE;AAExE,8CAAmD;AACnD,qCAAsD;AACtD,4CAA+F;AAC/F,kDAAmD;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAa,WAAW;IACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACI,MAAM,CAAC,WAAW,CAAC,KAAc,EAAE,UAAkB,EAAE,gBAA2B;QACrF,IAAI,KAAK,YAAY,sBAAa,EAAE,CAAC;YACjC,MAAM,KAAK,CAAC;QAChB,CAAC;QAED,IAAI,KAAK,YAAY,qCAA2B,EAAE,CAAC;YAC/C,MAAM,KAAK,GAAG,6CAAiC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;gBAC/D,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,6CAAiC,CAAC,CAAC,CAAC,CAAC;gBAC3D,CAAC,CAAC,SAAS,CAAC;YAChB,MAAM,IAAI,4BAAmB,CAAC,8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,9 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseSortOptions = parseSortOptions;
|
|
4
|
+
exports.parseFilterObject = parseFilterObject;
|
|
5
|
+
exports.parseSearchString = parseSearchString;
|
|
6
|
+
const utils_1 = require("@hichchi/utils");
|
|
2
7
|
/**
|
|
3
8
|
* Parse the sort options from the query string
|
|
4
9
|
*
|
|
@@ -40,7 +45,7 @@ import { dottedPathObjectToNested } from "@hichchi/utils";
|
|
|
40
45
|
* @see {@link SortOptions} For the structure of the returned object
|
|
41
46
|
* @see {@link FindOptionsOrderProperty} For TypeORM's order property type
|
|
42
47
|
*/
|
|
43
|
-
|
|
48
|
+
function parseSortOptions(sortString) {
|
|
44
49
|
const sortFields = {};
|
|
45
50
|
if (!sortString) {
|
|
46
51
|
return undefined;
|
|
@@ -111,8 +116,8 @@ export function parseSortOptions(sortString) {
|
|
|
111
116
|
* @see {@link QueryDeepPartial} For the structure of the returned object
|
|
112
117
|
* @see {@link dottedPathObjectToNested} For the underlying utility that converts dot notation to nested objects
|
|
113
118
|
*/
|
|
114
|
-
|
|
115
|
-
return dottedPathObjectToNested(filterObject);
|
|
119
|
+
function parseFilterObject(filterObject) {
|
|
120
|
+
return (0, utils_1.dottedPathObjectToNested)(filterObject);
|
|
116
121
|
}
|
|
117
122
|
/**
|
|
118
123
|
* Parse the search string and fields into filter options
|
|
@@ -165,7 +170,7 @@ export function parseFilterObject(filterObject) {
|
|
|
165
170
|
* @see {@link parseFilterObject} For a related function that handles general filtering
|
|
166
171
|
* @see {@link dottedPathObjectToNested} For the underlying utility that converts dot notation to nested objects
|
|
167
172
|
*/
|
|
168
|
-
|
|
173
|
+
function parseSearchString(value, pathsString) {
|
|
169
174
|
if (!value || !pathsString) {
|
|
170
175
|
return undefined;
|
|
171
176
|
}
|
|
@@ -177,6 +182,6 @@ export function parseSearchString(value, pathsString) {
|
|
|
177
182
|
acc[path] = value;
|
|
178
183
|
return acc;
|
|
179
184
|
}, {});
|
|
180
|
-
return dottedPathObjectToNested(filterObject);
|
|
185
|
+
return (0, utils_1.dottedPathObjectToNested)(filterObject);
|
|
181
186
|
}
|
|
182
187
|
//# sourceMappingURL=http.utils.js.map
|
package/utils/http.utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.utils.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/utils/http.utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"http.utils.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/utils/http.utils.ts"],"names":[],"mappings":";;AA8CA,4CAsBC;AAyDD,8CAEC;AAqDD,8CAeC;AAlMD,0CAAyE;AAIzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,SAAgB,gBAAgB,CAAI,UAAkB;IAClD,MAAM,UAAU,GAAmB,EAAE,CAAC;IACtC,IAAI,CAAC,UAAU,EAAE,CAAC;QACd,OAAO,SAAS,CAAC;IACrB,CAAC;IAMD,MAAM,WAAW,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE1C,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAsB,CAAC;QAChF,IAAI,KAAK,EAAE,CAAC;YACR,UAAU,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC;gBAC3C,CAAC,CAAE,KAAK,CAAC,WAAW,EAAiB;gBACrC,CAAC,CAAE,KAAoB,CAAC;QAChC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACrE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AACH,SAAgB,iBAAiB,CAAI,YAAmC;IACpE,OAAO,IAAA,gCAAwB,EAAsB,YAAY,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,SAAgB,iBAAiB,CAAI,KAAc,EAAE,WAAoB;IACrE,IAAI,CAAC,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;QACzB,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,MAAM,YAAY,GAA0B,WAAW;SAClD,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SACxB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;SAC3B,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QAClB,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;QAClB,OAAO,GAAG,CAAC;IACf,CAAC,EAAE,EAA2B,CAAC,CAAC;IAEpC,OAAO,IAAA,gCAAwB,EAAsB,YAAY,CAAC,CAAC;AACvE,CAAC"}
|
package/utils/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./entity.utils"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./http.utils"), exports);
|
|
3
6
|
//# sourceMappingURL=index.js.map
|
package/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/utils/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/utils/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,uDAA6B"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
// noinspection SuspiciousTypeOfGuard
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.toFindOptionsWhere = toFindOptionsWhere;
|
|
5
|
+
exports.toQueryDeepPartialEntity = toQueryDeepPartialEntity;
|
|
6
|
+
exports.toDeepPartial = toDeepPartial;
|
|
7
|
+
const typeorm_1 = require("typeorm");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
4
9
|
/**
|
|
5
10
|
* Converts query-deep-partial input into TypeORM `FindOptionsWhere` clauses.
|
|
6
11
|
*/
|
|
7
|
-
|
|
12
|
+
function toFindOptionsWhere(input) {
|
|
8
13
|
if (!input)
|
|
9
14
|
return {};
|
|
10
15
|
if (Array.isArray(input)) {
|
|
@@ -19,12 +24,12 @@ export function toFindOptionsWhere(input) {
|
|
|
19
24
|
continue;
|
|
20
25
|
const val = input[key];
|
|
21
26
|
if (val === null) {
|
|
22
|
-
output[key] = IsNull();
|
|
27
|
+
output[key] = (0, typeorm_1.IsNull)();
|
|
23
28
|
}
|
|
24
29
|
else if (Array.isArray(val) &&
|
|
25
30
|
val.length > 0 &&
|
|
26
31
|
val.every(v => typeof v === "string" || typeof v === "number" || typeof v === "boolean" || typeof v === "bigint")) {
|
|
27
|
-
output[key] = In(val);
|
|
32
|
+
output[key] = (0, typeorm_1.In)(val);
|
|
28
33
|
}
|
|
29
34
|
else if (!(val instanceof Date) && typeof val === "object") {
|
|
30
35
|
// TS can't guarantee this type matches exactly FindOptionsWhereProperty<...>,
|
|
@@ -74,7 +79,7 @@ export function toFindOptionsWhere(input) {
|
|
|
74
79
|
* @see {@link EntityDeepPartial} Custom type for deep partial entities
|
|
75
80
|
* @see {@link QueryDeepPartialEntity} TypeORM's type for query partial entities
|
|
76
81
|
*/
|
|
77
|
-
|
|
82
|
+
function toQueryDeepPartialEntity(input, depth = 0, maxDepth = constants_1.DEFAULT_MAX_RECURSION_DEPTH, visited = new WeakSet()) {
|
|
78
83
|
if (!input)
|
|
79
84
|
return {};
|
|
80
85
|
// Prevent deep recursion
|
|
@@ -144,7 +149,7 @@ export function toQueryDeepPartialEntity(input, depth = 0, maxDepth = DEFAULT_MA
|
|
|
144
149
|
* @see {@link EntityDeepPartial} Custom type for deep partial entities
|
|
145
150
|
* @see {@link DeepPartial} TypeORM's type for deep partial entities
|
|
146
151
|
*/
|
|
147
|
-
|
|
152
|
+
function toDeepPartial(input, depth = 0, maxDepth = constants_1.DEFAULT_MAX_RECURSION_DEPTH, visited = new WeakSet()) {
|
|
148
153
|
if (!input)
|
|
149
154
|
return {};
|
|
150
155
|
// Prevent deep recursion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.utils.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/utils/repository.utils.ts"],"names":[],"mappings":"AAAA,qCAAqC;
|
|
1
|
+
{"version":3,"file":"repository.utils.js","sourceRoot":"","sources":["../../../../libs/nest-crud/src/utils/repository.utils.ts"],"names":[],"mappings":";AAAA,qCAAqC;;AASrC,gDAwCC;AAuCD,4DA8CC;AAuCD,sCA6CC;AAxND,qCAA4F;AAE5F,4CAA2D;AAE3D;;GAEG;AACH,SAAgB,kBAAkB,CAC9B,KAAmD;IAEnD,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IAEtB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,EAAE,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAA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