@nathapp/nestjs-typeorm 3.0.0-rc.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/CLAUDE.md +17 -0
- package/LICENSE +21 -0
- package/README.md +4 -0
- package/dist/decorator/date-column.decorator.d.ts +7 -0
- package/dist/decorator/date-column.decorator.js +54 -0
- package/dist/decorator/date-column.decorator.js.map +1 -0
- package/dist/decorator/index.d.ts +4 -0
- package/dist/decorator/index.js +15 -0
- package/dist/decorator/index.js.map +1 -0
- package/dist/decorator/readonly-column.decorator.d.ts +1 -0
- package/dist/decorator/readonly-column.decorator.js +14 -0
- package/dist/decorator/readonly-column.decorator.js.map +1 -0
- package/dist/decorator/typeorm-ex.decorator.d.ts +2 -0
- package/dist/decorator/typeorm-ex.decorator.js +10 -0
- package/dist/decorator/typeorm-ex.decorator.js.map +1 -0
- package/dist/entities/index.d.ts +1 -0
- package/dist/entities/index.js +6 -0
- package/dist/entities/index.js.map +1 -0
- package/dist/errors/database-error.mapper.d.ts +5 -0
- package/dist/errors/database-error.mapper.js +37 -0
- package/dist/errors/database-error.mapper.js.map +1 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +18 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/filter/index.d.ts +1 -0
- package/dist/filter/index.js +6 -0
- package/dist/filter/index.js.map +1 -0
- package/dist/filter/typeorm-exception.filter.d.ts +9 -0
- package/dist/filter/typeorm-exception.filter.js +81 -0
- package/dist/filter/typeorm-exception.filter.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/pagination/index.d.ts +3 -0
- package/dist/pagination/index.js +11 -0
- package/dist/pagination/index.js.map +1 -0
- package/dist/pagination/paginate.d.ts +4 -0
- package/dist/pagination/paginate.js +41 -0
- package/dist/pagination/paginate.js.map +1 -0
- package/dist/repository/base.repository.d.ts +19 -0
- package/dist/repository/base.repository.js +175 -0
- package/dist/repository/base.repository.js.map +1 -0
- package/dist/repository/index.d.ts +2 -0
- package/dist/repository/index.js +7 -0
- package/dist/repository/index.js.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/testing-utils.d.ts +56 -0
- package/dist/testing/testing-utils.js +44 -0
- package/dist/testing/testing-utils.js.map +1 -0
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.js +19 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction/transaction.service.d.ts +7 -0
- package/dist/transaction/transaction.service.js +73 -0
- package/dist/transaction/transaction.service.js.map +1 -0
- package/dist/transaction/transactional.decorator.d.ts +5 -0
- package/dist/transaction/transactional.decorator.js +45 -0
- package/dist/transaction/transactional.decorator.js.map +1 -0
- package/dist/typeorm/base-typeorm-options-factory.d.ts +18 -0
- package/dist/typeorm/base-typeorm-options-factory.js +42 -0
- package/dist/typeorm/base-typeorm-options-factory.js.map +1 -0
- package/dist/typeorm/constants.d.ts +13 -0
- package/dist/typeorm/constants.js +17 -0
- package/dist/typeorm/constants.js.map +1 -0
- package/dist/typeorm/index.d.ts +7 -0
- package/dist/typeorm/index.js +16 -0
- package/dist/typeorm/index.js.map +1 -0
- package/dist/typeorm/typeorm-ex.module.d.ts +13 -0
- package/dist/typeorm/typeorm-ex.module.js +75 -0
- package/dist/typeorm/typeorm-ex.module.js.map +1 -0
- package/dist/typeorm/typeorm-utils.d.ts +12 -0
- package/dist/typeorm/typeorm-utils.js +16 -0
- package/dist/typeorm/typeorm-utils.js.map +1 -0
- package/docs/20260214-coverage-plan.md +45 -0
- package/docs/20260215-fix-plan-typeorm.md +46 -0
- package/docs/20260215-review-typeorm.md +594 -0
- package/docs/20260216-fix-plan-typeorm-exception.md +48 -0
- package/index.d.ts +1 -0
- package/index.js +6 -0
- package/package.json +43 -0
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @nathapp/nestjs-typeorm
|
|
2
|
+
|
|
3
|
+
TypeORM integration (renamed from `@nathapp/nestjs-data`).
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
- Test: `npx jest --config test/jest-test.json --no-coverage`
|
|
7
|
+
- Build: `npx tsc`
|
|
8
|
+
|
|
9
|
+
## Key Classes
|
|
10
|
+
- `BaseSpRepository` — stored procedure helper with `callQuery()`, recordset mapping.
|
|
11
|
+
- `TypeOrmExModule` — custom repository registration via `@CustomRepository()` decorator.
|
|
12
|
+
- `BaseTypeOrmModuleOptionFactory` — abstract factory for TypeORM connection options.
|
|
13
|
+
|
|
14
|
+
## Gotchas
|
|
15
|
+
- Pagination types (`Page`, `PageOption`) moved to `@nathapp/nestjs-common` — import from there.
|
|
16
|
+
- Uses `import * as dayjs` (NOT default import) — do NOT add `esModuleInterop` to this package's tsconfig.
|
|
17
|
+
- Jest config omits `esModuleInterop` intentionally (unlike other packages).
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 KnowYourself
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ColumnOptions } from "typeorm";
|
|
2
|
+
import { TransformOptions } from "class-transformer";
|
|
3
|
+
export declare const toDateString: (value: Date, format?: string) => string;
|
|
4
|
+
export declare const NullableDateString: (options?: TransformOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
5
|
+
export declare const CreateDate: (format?: string, options?: ColumnOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
6
|
+
export declare const UpdateDate: (format?: string, options?: ColumnOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
7
|
+
export declare const DateColumn: (format?: string, options?: ColumnOptions) => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
@@ -0,0 +1,54 @@
|
|
|
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.DateColumn = exports.UpdateDate = exports.CreateDate = exports.NullableDateString = exports.toDateString = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const typeorm_1 = require("typeorm");
|
|
9
|
+
const common_1 = require("@nestjs/common");
|
|
10
|
+
const class_transformer_1 = require("class-transformer");
|
|
11
|
+
const DEFAULT_DATE_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
|
12
|
+
const toDateString = (value, format) => {
|
|
13
|
+
return value ? (0, dayjs_1.default)(value).format(format || DEFAULT_DATE_FORMAT) : value;
|
|
14
|
+
};
|
|
15
|
+
exports.toDateString = toDateString;
|
|
16
|
+
const NullableDateString = (options = { toPlainOnly: true }) => {
|
|
17
|
+
return applyDateDecorators((0, class_transformer_1.Transform)(({ value }) => (value ? (0, exports.toDateString)(value) : null), options));
|
|
18
|
+
};
|
|
19
|
+
exports.NullableDateString = NullableDateString;
|
|
20
|
+
const applyDateDecorators = (decorator) => {
|
|
21
|
+
return (0, common_1.applyDecorators)((0, class_transformer_1.Transform)(({ value, type }) => (0, exports.toDateString)(value)), decorator);
|
|
22
|
+
};
|
|
23
|
+
const CreateDate = (format, options) => {
|
|
24
|
+
return applyDateDecorators((0, typeorm_1.CreateDateColumn)({
|
|
25
|
+
transformer: {
|
|
26
|
+
to: (value) => (0, exports.toDateString)(value, format),
|
|
27
|
+
from: (value) => new Date(value),
|
|
28
|
+
},
|
|
29
|
+
...options,
|
|
30
|
+
}));
|
|
31
|
+
};
|
|
32
|
+
exports.CreateDate = CreateDate;
|
|
33
|
+
const UpdateDate = (format, options) => {
|
|
34
|
+
return applyDateDecorators((0, typeorm_1.UpdateDateColumn)({
|
|
35
|
+
transformer: {
|
|
36
|
+
to: (value) => (0, exports.toDateString)(value, format),
|
|
37
|
+
from: (value) => new Date(value),
|
|
38
|
+
},
|
|
39
|
+
...options,
|
|
40
|
+
}));
|
|
41
|
+
};
|
|
42
|
+
exports.UpdateDate = UpdateDate;
|
|
43
|
+
const DateColumn = (format, options) => {
|
|
44
|
+
return applyDateDecorators((0, typeorm_1.Column)({
|
|
45
|
+
transformer: {
|
|
46
|
+
to: (value) => (0, exports.toDateString)(value, format),
|
|
47
|
+
from: (value) => new Date(value),
|
|
48
|
+
},
|
|
49
|
+
...options,
|
|
50
|
+
type: "datetime",
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
exports.DateColumn = DateColumn;
|
|
54
|
+
//# sourceMappingURL=date-column.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date-column.decorator.js","sourceRoot":"","sources":["../../lib/decorator/date-column.decorator.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,qCAAoF;AACpF,2CAAiD;AACjD,yDAAgE;AAEhE,MAAM,mBAAmB,GAAG,qBAAqB,CAAC;AAE3C,MAAM,YAAY,GAAG,CAAC,KAAW,EAAE,MAAe,EAAE,EAAE;IAC3D,OAAO,KAAK,CAAC,CAAC,CAAC,IAAA,eAAK,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,mBAAmB,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC5E,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB;AAEK,MAAM,kBAAkB,GAAG,CAAC,UAA4B,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,EAAE;IACtF,OAAO,mBAAmB,CACxB,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CACxE,CAAA;AACH,CAAC,CAAA;AAJY,QAAA,kBAAkB,sBAI9B;AAED,MAAM,mBAAmB,GAAG,CAC1B,SAA+D,EAC/D,EAAE;IACF,OAAO,IAAA,wBAAe,EACpB,IAAA,6BAAS,EAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAA,oBAAY,EAAC,KAAK,CAAC,CAAC,EACnD,SAAS,CACV,CAAC;AACJ,CAAC,CAAC;AAQK,MAAM,UAAU,GAAG,CAAC,MAAe,EAA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+
import { ReadOnlyColumn } from "./readonly-column.decorator";
|
|
3
|
+
import { CustomRepository, TYPEORM_EX_CUSTOM_REPOSITORY } from "./typeorm-ex.decorator";
|
|
4
|
+
export { DateColumn, CreateDate, UpdateDate, ReadOnlyColumn, CustomRepository, TYPEORM_EX_CUSTOM_REPOSITORY, toDateString, NullableDateString, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NullableDateString = exports.toDateString = exports.TYPEORM_EX_CUSTOM_REPOSITORY = exports.CustomRepository = exports.ReadOnlyColumn = exports.UpdateDate = exports.CreateDate = exports.DateColumn = void 0;
|
|
4
|
+
const date_column_decorator_1 = require("./date-column.decorator");
|
|
5
|
+
Object.defineProperty(exports, "CreateDate", { enumerable: true, get: function () { return date_column_decorator_1.CreateDate; } });
|
|
6
|
+
Object.defineProperty(exports, "DateColumn", { enumerable: true, get: function () { return date_column_decorator_1.DateColumn; } });
|
|
7
|
+
Object.defineProperty(exports, "NullableDateString", { enumerable: true, get: function () { return date_column_decorator_1.NullableDateString; } });
|
|
8
|
+
Object.defineProperty(exports, "toDateString", { enumerable: true, get: function () { return date_column_decorator_1.toDateString; } });
|
|
9
|
+
Object.defineProperty(exports, "UpdateDate", { enumerable: true, get: function () { return date_column_decorator_1.UpdateDate; } });
|
|
10
|
+
const readonly_column_decorator_1 = require("./readonly-column.decorator");
|
|
11
|
+
Object.defineProperty(exports, "ReadOnlyColumn", { enumerable: true, get: function () { return readonly_column_decorator_1.ReadOnlyColumn; } });
|
|
12
|
+
const typeorm_ex_decorator_1 = require("./typeorm-ex.decorator");
|
|
13
|
+
Object.defineProperty(exports, "CustomRepository", { enumerable: true, get: function () { return typeorm_ex_decorator_1.CustomRepository; } });
|
|
14
|
+
Object.defineProperty(exports, "TYPEORM_EX_CUSTOM_REPOSITORY", { enumerable: true, get: function () { return typeorm_ex_decorator_1.TYPEORM_EX_CUSTOM_REPOSITORY; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/decorator/index.ts"],"names":[],"mappings":";;;AAAA,mEAA+G;AAM7G,2FANO,kCAAU,OAMP;AADV,2FALmB,kCAAU,OAKnB;AAOV,mGAZ+B,0CAAkB,OAY/B;AADlB,6FAXmD,oCAAY,OAWnD;AAJZ,2FAPiE,kCAAU,OAOjE;AANZ,2EAA6D;AAO3D,+FAPO,0CAAc,OAOP;AANhB,iEAAwF;AAOtF,iGAPO,uCAAgB,OAOP;AAChB,6GARyB,mDAA4B,OAQzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ReadOnlyColumn: () => PropertyDecorator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReadOnlyColumn = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const ReadOnlyColumn = () => {
|
|
6
|
+
return (0, typeorm_1.Column)({
|
|
7
|
+
select: false,
|
|
8
|
+
insert: false,
|
|
9
|
+
readonly: true,
|
|
10
|
+
nullable: true,
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
exports.ReadOnlyColumn = ReadOnlyColumn;
|
|
14
|
+
//# sourceMappingURL=readonly-column.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readonly-column.decorator.js","sourceRoot":"","sources":["../../lib/decorator/readonly-column.decorator.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AAE1B,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,IAAA,gBAAM,EAAC;QACZ,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;AACL,CAAC,CAAC;AAPW,QAAA,cAAc,kBAOzB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TYPEORM_EX_CUSTOM_REPOSITORY = void 0;
|
|
4
|
+
exports.CustomRepository = CustomRepository;
|
|
5
|
+
const common_1 = require("@nestjs/common");
|
|
6
|
+
exports.TYPEORM_EX_CUSTOM_REPOSITORY = "TYPEORM_EX_CUSTOM_REPOSITORY";
|
|
7
|
+
function CustomRepository(entity) {
|
|
8
|
+
return (0, common_1.SetMetadata)(exports.TYPEORM_EX_CUSTOM_REPOSITORY, entity);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=typeorm-ex.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm-ex.decorator.js","sourceRoot":"","sources":["../../lib/decorator/typeorm-ex.decorator.ts"],"names":[],"mappings":";;;AAIA,4CAEC;AAND,2CAA6C;AAEhC,QAAA,4BAA4B,GAAG,8BAA8B,CAAC;AAE3E,SAAgB,gBAAgB,CAAC,MAAgB;IAC/C,OAAO,IAAA,oBAAW,EAAC,oCAA4B,EAAE,MAAM,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { BaseEntity } from '@nathapp/nestjs-common';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEntity = void 0;
|
|
4
|
+
var nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
5
|
+
Object.defineProperty(exports, "BaseEntity", { enumerable: true, get: function () { return nestjs_common_1.BaseEntity; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/entities/index.ts"],"names":[],"mappings":";;;AACA,wDAAoD;AAA3C,2GAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseErrorMapper = void 0;
|
|
4
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
5
|
+
class DatabaseErrorMapper {
|
|
6
|
+
static mapToAppException(error) {
|
|
7
|
+
const errorCode = error.code;
|
|
8
|
+
const errorNumber = error.errno;
|
|
9
|
+
const errorMessage = error.message || 'Unknown database error';
|
|
10
|
+
const mapping = errorCode ? this.ERROR_MAPPINGS[errorCode] : undefined;
|
|
11
|
+
const httpStatus = (mapping === null || mapping === void 0 ? void 0 : mapping.httpStatus) || 500;
|
|
12
|
+
const appExceptionCode = errorNumber || 9999;
|
|
13
|
+
const args = {
|
|
14
|
+
originalError: errorMessage,
|
|
15
|
+
dbCode: errorCode,
|
|
16
|
+
dbErrno: errorNumber,
|
|
17
|
+
};
|
|
18
|
+
return new nestjs_common_1.AppException(appExceptionCode, args, 'database', httpStatus);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.DatabaseErrorMapper = DatabaseErrorMapper;
|
|
22
|
+
DatabaseErrorMapper.ERROR_MAPPINGS = {
|
|
23
|
+
'ER_DUP_ENTRY': { httpStatus: 409, message: 'Duplicate entry detected' },
|
|
24
|
+
'ER_NO_REFERENCED_ROW_2': { httpStatus: 400, message: 'Foreign key constraint violation' },
|
|
25
|
+
'ER_ROW_IS_REFERENCED_2': { httpStatus: 400, message: 'Cannot delete referenced record' },
|
|
26
|
+
'ETIMEDOUT': { httpStatus: 503, message: 'Database connection timeout' },
|
|
27
|
+
'ECONNREFUSED': { httpStatus: 503, message: 'Database connection refused' },
|
|
28
|
+
'ENOTFOUND': { httpStatus: 503, message: 'Database host not found' },
|
|
29
|
+
'ER_ACCESS_DENIED_ERROR': { httpStatus: 500, message: 'Database access denied' },
|
|
30
|
+
'ER_DBACCESS_DENIED_ERROR': { httpStatus: 500, message: 'Database access denied' },
|
|
31
|
+
'ER_PARSE_ERROR': { httpStatus: 500, message: 'SQL syntax error' },
|
|
32
|
+
'ER_NO_SUCH_TABLE': { httpStatus: 500, message: 'Table does not exist' },
|
|
33
|
+
'ER_BAD_FIELD_ERROR': { httpStatus: 500, message: 'Unknown column' },
|
|
34
|
+
'ER_LOCK_DEADLOCK': { httpStatus: 500, message: 'Database deadlock detected' },
|
|
35
|
+
'ER_LOCK_WAIT_TIMEOUT': { httpStatus: 500, message: 'Lock wait timeout exceeded' },
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=database-error.mapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database-error.mapper.js","sourceRoot":"","sources":["../../lib/errors/database-error.mapper.ts"],"names":[],"mappings":";;;AAAA,0DAAsD;AAetD,MAAa,mBAAmB;IAiC9B,MAAM,CAAC,iBAAiB,CAAC,KAAU;QACjC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC;QAC7B,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC;QAChC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,IAAI,wBAAwB,CAAC;QAG/D,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAGvE,MAAM,UAAU,GAAG,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,KAAI,GAAG,CAAC;QAG9C,MAAM,gBAAgB,GAAG,WAAW,IAAI,IAAI,CAAC;QAG7C,MAAM,IAAI,GAAG;YACX,aAAa,EAAE,YAAY;YAC3B,MAAM,EAAE,SAAS;YACjB,OAAO,EAAE,WAAW;SACrB,CAAC;QAEF,OAAO,IAAI,4BAAY,CACrB,gBAAgB,EAChB,IAAI,EACJ,UAAU,EACV,UAAU,CACX,CAAC;IACJ,CAAC;;AA5DH,kDA6DC;AA5DyB,kCAAc,GAAiC;IAErE,cAAc,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,0BAA0B,EAAE;IAGxE,wBAAwB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,kCAAkC,EAAE;IAC1F,wBAAwB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,iCAAiC,EAAE;IAGzF,WAAW,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,6BAA6B,EAAE;IACxE,cAAc,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,6BAA6B,EAAE;IAC3E,WAAW,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,yBAAyB,EAAE;IAGpE,wBAAwB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,wBAAwB,EAAE;IAChF,0BAA0B,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,wBAAwB,EAAE;IAGlF,gBAAgB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,EAAE;IAClE,kBAAkB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,sBAAsB,EAAE;IACxE,oBAAoB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,gBAAgB,EAAE;IAGpE,kBAAkB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,4BAA4B,EAAE;IAC9E,sBAAsB,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,4BAA4B,EAAE;CACnF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './database-error.mapper';
|
|
@@ -0,0 +1,18 @@
|
|
|
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("./database-error.mapper"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/errors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TypeOrmExceptionFilter } from "./typeorm-exception.filter";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeOrmExceptionFilter = void 0;
|
|
4
|
+
var typeorm_exception_filter_1 = require("./typeorm-exception.filter");
|
|
5
|
+
Object.defineProperty(exports, "TypeOrmExceptionFilter", { enumerable: true, get: function () { return typeorm_exception_filter_1.TypeOrmExceptionFilter; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/filter/index.ts"],"names":[],"mappings":";;;AAAA,uEAAoE;AAA3D,kIAAA,sBAAsB,OAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter } from "@nestjs/common";
|
|
2
|
+
import { EntityNotFoundError, QueryFailedError } from "typeorm";
|
|
3
|
+
export declare class TypeOrmExceptionFilter implements ExceptionFilter {
|
|
4
|
+
catch(exception: QueryFailedError | EntityNotFoundError, host: ArgumentsHost): void;
|
|
5
|
+
private mapQueryFailedError;
|
|
6
|
+
private isUniqueConstraintViolation;
|
|
7
|
+
private isForeignKeyViolation;
|
|
8
|
+
private isNotNullViolation;
|
|
9
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TypeOrmExceptionFilter = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
12
|
+
const typeorm_1 = require("typeorm");
|
|
13
|
+
let TypeOrmExceptionFilter = class TypeOrmExceptionFilter {
|
|
14
|
+
catch(exception, host) {
|
|
15
|
+
const ctx = host.switchToHttp();
|
|
16
|
+
const response = ctx.getResponse();
|
|
17
|
+
let appException;
|
|
18
|
+
if (exception instanceof typeorm_1.EntityNotFoundError) {
|
|
19
|
+
appException = new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.NOT_FOUND, { message: "Resource not found" }, "typeorm", common_1.HttpStatus.NOT_FOUND);
|
|
20
|
+
}
|
|
21
|
+
else if (exception instanceof typeorm_1.QueryFailedError) {
|
|
22
|
+
appException = this.mapQueryFailedError(exception);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
appException = new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.INTERNAL_ERROR, { message: "An unexpected database error occurred" }, "typeorm", common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
26
|
+
}
|
|
27
|
+
response.status(appException.httpStatus || common_1.HttpStatus.INTERNAL_SERVER_ERROR).json({
|
|
28
|
+
code: appException.code,
|
|
29
|
+
args: appException.args,
|
|
30
|
+
prefix: appException.prefix,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
mapQueryFailedError(error) {
|
|
34
|
+
const driverError = error.driverError;
|
|
35
|
+
const errorCode = (driverError === null || driverError === void 0 ? void 0 : driverError.code) || (driverError === null || driverError === void 0 ? void 0 : driverError.errno);
|
|
36
|
+
if (this.isUniqueConstraintViolation(errorCode)) {
|
|
37
|
+
return new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.REQUEST_INVALID, { message: "A record with the same value already exists" }, "typeorm", common_1.HttpStatus.CONFLICT);
|
|
38
|
+
}
|
|
39
|
+
if (this.isForeignKeyViolation(errorCode)) {
|
|
40
|
+
return new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.REQUEST_INVALID, { message: "Referenced record does not exist" }, "typeorm", common_1.HttpStatus.BAD_REQUEST);
|
|
41
|
+
}
|
|
42
|
+
if (this.isNotNullViolation(errorCode)) {
|
|
43
|
+
return new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.REQUEST_PARAMETER_ERROR, { message: "Required field is missing" }, "typeorm", common_1.HttpStatus.BAD_REQUEST);
|
|
44
|
+
}
|
|
45
|
+
return new nestjs_common_1.AppException(nestjs_common_1.CommonExceptionCode.INTERNAL_ERROR, { message: "An unexpected database error occurred" }, "typeorm", common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
46
|
+
}
|
|
47
|
+
isUniqueConstraintViolation(code) {
|
|
48
|
+
if (code === "23505" || code === 23505)
|
|
49
|
+
return true;
|
|
50
|
+
if (code === "1062" || code === 1062)
|
|
51
|
+
return true;
|
|
52
|
+
if (code === "SQLITE_CONSTRAINT" || code === 19)
|
|
53
|
+
return true;
|
|
54
|
+
if (typeof code === "string" && code.includes("UNIQUE constraint failed"))
|
|
55
|
+
return true;
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
isForeignKeyViolation(code) {
|
|
59
|
+
if (code === "23503" || code === 23503)
|
|
60
|
+
return true;
|
|
61
|
+
if (code === "1451" || code === 1451 || code === "1452" || code === 1452)
|
|
62
|
+
return true;
|
|
63
|
+
if (code === "SQLITE_CONSTRAINT_FOREIGNKEY")
|
|
64
|
+
return true;
|
|
65
|
+
if (typeof code === "string" && code.includes("FOREIGN KEY constraint failed"))
|
|
66
|
+
return true;
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
isNotNullViolation(code) {
|
|
70
|
+
if (code === "23502" || code === 23502)
|
|
71
|
+
return true;
|
|
72
|
+
if (code === "1048" || code === 1048)
|
|
73
|
+
return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
exports.TypeOrmExceptionFilter = TypeOrmExceptionFilter;
|
|
78
|
+
exports.TypeOrmExceptionFilter = TypeOrmExceptionFilter = __decorate([
|
|
79
|
+
(0, common_1.Catch)(typeorm_1.QueryFailedError, typeorm_1.EntityNotFoundError)
|
|
80
|
+
], TypeOrmExceptionFilter);
|
|
81
|
+
//# sourceMappingURL=typeorm-exception.filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm-exception.filter.js","sourceRoot":"","sources":["../../lib/filter/typeorm-exception.filter.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAmF;AACnF,0DAA2E;AAC3E,qCAAgE;AA0BzD,IAAM,sBAAsB,GAA5B,M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,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QACtF,IAAI,IAAI,KAAK,8BAA8B;YAAE,OAAO,IAAI,CAAC;QACzD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,+BAA+B,CAAC;YAAE,OAAO,IAAI,CAAC;QAC5F,OAAO,KAAK,CAAC;IACf,CAAC;IAQO,kBAAkB,CAAC,IAAqB;QAC9C,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,KAAK;YAAE,OAAO,IAAI,CAAC;QACpD,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AAzHY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,cAAK,EAAC,0BAAgB,EAAE,6BAAmB,CAAC;GAChC,sBAAsB,CAyHlC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./decorator";
|
|
2
|
+
export * from "./entities";
|
|
3
|
+
export * from "./errors";
|
|
4
|
+
export * from "./filter";
|
|
5
|
+
export * from "./repository";
|
|
6
|
+
export * from "./pagination";
|
|
7
|
+
export * from "./testing";
|
|
8
|
+
export * from "./transaction";
|
|
9
|
+
export * from "./typeorm";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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("./decorator"), exports);
|
|
18
|
+
__exportStar(require("./entities"), exports);
|
|
19
|
+
__exportStar(require("./errors"), exports);
|
|
20
|
+
__exportStar(require("./filter"), exports);
|
|
21
|
+
__exportStar(require("./repository"), exports);
|
|
22
|
+
__exportStar(require("./pagination"), exports);
|
|
23
|
+
__exportStar(require("./testing"), exports);
|
|
24
|
+
__exportStar(require("./transaction"), exports);
|
|
25
|
+
__exportStar(require("./typeorm"), exports);
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,6CAA2B;AAC3B,2CAAyB;AACzB,2CAAyB;AACzB,+CAA6B;AAC7B,+CAA6B;AAC7B,4CAA0B;AAC1B,gDAA8B;AAC9B,4CAA0B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Paginate = exports.resolvePageOption = exports.Page = exports.PageOption = exports.TransformOptions = void 0;
|
|
4
|
+
var nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
5
|
+
Object.defineProperty(exports, "TransformOptions", { enumerable: true, get: function () { return nestjs_common_1.TransformOptions; } });
|
|
6
|
+
Object.defineProperty(exports, "PageOption", { enumerable: true, get: function () { return nestjs_common_1.PageOption; } });
|
|
7
|
+
Object.defineProperty(exports, "Page", { enumerable: true, get: function () { return nestjs_common_1.Page; } });
|
|
8
|
+
Object.defineProperty(exports, "resolvePageOption", { enumerable: true, get: function () { return nestjs_common_1.resolvePageOption; } });
|
|
9
|
+
var paginate_1 = require("./paginate");
|
|
10
|
+
Object.defineProperty(exports, "Paginate", { enumerable: true, get: function () { return paginate_1.Paginate; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/pagination/index.ts"],"names":[],"mappings":";;;AACA,wDAKgC;AAJ9B,iHAAA,gBAAgB,OAAA;AAChB,2GAAA,UAAU,OAAA;AACV,qGAAA,IAAI,OAAA;AACJ,kHAAA,iBAAiB,OAAA;AAKnB,uCAAsC;AAA7B,oGAAA,QAAQ,OAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Page, TransformOptions } from "@nathapp/nestjs-common";
|
|
2
|
+
import type { IPageOption } from "@nathapp/nestjs-common";
|
|
3
|
+
import { FindManyOptions, MongoRepository, ObjectLiteral, Repository, SelectQueryBuilder } from "typeorm";
|
|
4
|
+
export declare function Paginate<T extends ObjectLiteral>(repositoryOrQueryBuilder: Repository<T> | MongoRepository<T> | SelectQueryBuilder<T>, options: IPageOption, searchOptions?: FindManyOptions<T>, transformOptions?: TransformOptions<T>): Promise<Page<T, any>>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Paginate = Paginate;
|
|
4
|
+
const nestjs_common_1 = require("@nathapp/nestjs-common");
|
|
5
|
+
const typeorm_1 = require("typeorm");
|
|
6
|
+
async function Paginate(repositoryOrQueryBuilder, options, searchOptions, transformOptions) {
|
|
7
|
+
if (repositoryOrQueryBuilder instanceof typeorm_1.MongoRepository) {
|
|
8
|
+
return paginateMongoRepository(repositoryOrQueryBuilder, options, searchOptions, transformOptions);
|
|
9
|
+
}
|
|
10
|
+
else if (repositoryOrQueryBuilder instanceof typeorm_1.Repository) {
|
|
11
|
+
return paginateRepository(repositoryOrQueryBuilder, options, searchOptions, transformOptions);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return paginateQueryBuilder(repositoryOrQueryBuilder, options, transformOptions);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function paginateRepository(repository, options, searchOptions, transformOptions) {
|
|
18
|
+
const { take, skip } = (0, nestjs_common_1.resolvePageOption)(options);
|
|
19
|
+
const [result, total] = await repository.findAndCount({
|
|
20
|
+
skip,
|
|
21
|
+
take,
|
|
22
|
+
...searchOptions,
|
|
23
|
+
});
|
|
24
|
+
return new nestjs_common_1.Page(options, total, result, transformOptions);
|
|
25
|
+
}
|
|
26
|
+
async function paginateQueryBuilder(queryBuilder, options, transformOptions) {
|
|
27
|
+
const { take, skip } = (0, nestjs_common_1.resolvePageOption)(options);
|
|
28
|
+
const total = await queryBuilder.getCount();
|
|
29
|
+
const result = await queryBuilder.skip(skip).take(take).getMany();
|
|
30
|
+
return new nestjs_common_1.Page(options, total, result, transformOptions);
|
|
31
|
+
}
|
|
32
|
+
async function paginateMongoRepository(repository, options, searchOptions, transformOptions) {
|
|
33
|
+
const { take, skip } = (0, nestjs_common_1.resolvePageOption)(options);
|
|
34
|
+
const [result, total] = await repository.findAndCount({
|
|
35
|
+
skip,
|
|
36
|
+
take,
|
|
37
|
+
...searchOptions,
|
|
38
|
+
});
|
|
39
|
+
return new nestjs_common_1.Page(options, total, result, transformOptions);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=paginate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../../lib/pagination/paginate.ts"],"names":[],"mappings":";;AAcA,4BA8BC;AA5CD,0DAIgC;AAEhC,qCAMiB;AAEV,KAAK,UAAU,QAAQ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AAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAC/D,CAAC;AAED,KAAK,UAAU,uBAAuB,CACpC,UAA8B,EAC9B,OAAoB,EACpB,aAAkC,EAClC,gBAAsC;IAEtC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,IAAA,iCAAiB,EAAC,OAAO,CAAC,CAAC;IAClD,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,MAAM,UAAU,CAAC,YAAY,CAAC;QACpD,IAAI;QACJ,IAAI;QACJ,GAAG,aAAa;KACjB,CAAC,CAAC;IAEH,OAAO,IAAI,oBAAI,CAAI,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
export interface PrepareResult {
|
|
3
|
+
formattedSP: string;
|
|
4
|
+
parameters?: any[];
|
|
5
|
+
}
|
|
6
|
+
export declare abstract class BaseRepository {
|
|
7
|
+
readonly dataSource: DataSource;
|
|
8
|
+
constructor(dataSource: DataSource);
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class BaseSpRepository extends BaseRepository {
|
|
11
|
+
readonly executeCommand: string;
|
|
12
|
+
constructor(dataSource: DataSource, executeCommand?: string);
|
|
13
|
+
callQuery(spName: string, formatOrValue?: any, params?: any, rename?: (key: string, depth: number, object: any) => string, objectifyForSignleRecord?: boolean): Promise<any>;
|
|
14
|
+
private resolveRecordsets;
|
|
15
|
+
private validateSpName;
|
|
16
|
+
private prepare;
|
|
17
|
+
private renameKey;
|
|
18
|
+
private changeKey;
|
|
19
|
+
}
|