@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.
Files changed (82) hide show
  1. package/CLAUDE.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +4 -0
  4. package/dist/decorator/date-column.decorator.d.ts +7 -0
  5. package/dist/decorator/date-column.decorator.js +54 -0
  6. package/dist/decorator/date-column.decorator.js.map +1 -0
  7. package/dist/decorator/index.d.ts +4 -0
  8. package/dist/decorator/index.js +15 -0
  9. package/dist/decorator/index.js.map +1 -0
  10. package/dist/decorator/readonly-column.decorator.d.ts +1 -0
  11. package/dist/decorator/readonly-column.decorator.js +14 -0
  12. package/dist/decorator/readonly-column.decorator.js.map +1 -0
  13. package/dist/decorator/typeorm-ex.decorator.d.ts +2 -0
  14. package/dist/decorator/typeorm-ex.decorator.js +10 -0
  15. package/dist/decorator/typeorm-ex.decorator.js.map +1 -0
  16. package/dist/entities/index.d.ts +1 -0
  17. package/dist/entities/index.js +6 -0
  18. package/dist/entities/index.js.map +1 -0
  19. package/dist/errors/database-error.mapper.d.ts +5 -0
  20. package/dist/errors/database-error.mapper.js +37 -0
  21. package/dist/errors/database-error.mapper.js.map +1 -0
  22. package/dist/errors/index.d.ts +1 -0
  23. package/dist/errors/index.js +18 -0
  24. package/dist/errors/index.js.map +1 -0
  25. package/dist/filter/index.d.ts +1 -0
  26. package/dist/filter/index.js +6 -0
  27. package/dist/filter/index.js.map +1 -0
  28. package/dist/filter/typeorm-exception.filter.d.ts +9 -0
  29. package/dist/filter/typeorm-exception.filter.js +81 -0
  30. package/dist/filter/typeorm-exception.filter.js.map +1 -0
  31. package/dist/index.d.ts +9 -0
  32. package/dist/index.js +26 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/pagination/index.d.ts +3 -0
  35. package/dist/pagination/index.js +11 -0
  36. package/dist/pagination/index.js.map +1 -0
  37. package/dist/pagination/paginate.d.ts +4 -0
  38. package/dist/pagination/paginate.js +41 -0
  39. package/dist/pagination/paginate.js.map +1 -0
  40. package/dist/repository/base.repository.d.ts +19 -0
  41. package/dist/repository/base.repository.js +175 -0
  42. package/dist/repository/base.repository.js.map +1 -0
  43. package/dist/repository/index.d.ts +2 -0
  44. package/dist/repository/index.js +7 -0
  45. package/dist/repository/index.js.map +1 -0
  46. package/dist/testing/index.d.ts +2 -0
  47. package/dist/testing/index.js +11 -0
  48. package/dist/testing/index.js.map +1 -0
  49. package/dist/testing/testing-utils.d.ts +56 -0
  50. package/dist/testing/testing-utils.js +44 -0
  51. package/dist/testing/testing-utils.js.map +1 -0
  52. package/dist/transaction/index.d.ts +2 -0
  53. package/dist/transaction/index.js +19 -0
  54. package/dist/transaction/index.js.map +1 -0
  55. package/dist/transaction/transaction.service.d.ts +7 -0
  56. package/dist/transaction/transaction.service.js +73 -0
  57. package/dist/transaction/transaction.service.js.map +1 -0
  58. package/dist/transaction/transactional.decorator.d.ts +5 -0
  59. package/dist/transaction/transactional.decorator.js +45 -0
  60. package/dist/transaction/transactional.decorator.js.map +1 -0
  61. package/dist/typeorm/base-typeorm-options-factory.d.ts +18 -0
  62. package/dist/typeorm/base-typeorm-options-factory.js +42 -0
  63. package/dist/typeorm/base-typeorm-options-factory.js.map +1 -0
  64. package/dist/typeorm/constants.d.ts +13 -0
  65. package/dist/typeorm/constants.js +17 -0
  66. package/dist/typeorm/constants.js.map +1 -0
  67. package/dist/typeorm/index.d.ts +7 -0
  68. package/dist/typeorm/index.js +16 -0
  69. package/dist/typeorm/index.js.map +1 -0
  70. package/dist/typeorm/typeorm-ex.module.d.ts +13 -0
  71. package/dist/typeorm/typeorm-ex.module.js +75 -0
  72. package/dist/typeorm/typeorm-ex.module.js.map +1 -0
  73. package/dist/typeorm/typeorm-utils.d.ts +12 -0
  74. package/dist/typeorm/typeorm-utils.js +16 -0
  75. package/dist/typeorm/typeorm-utils.js.map +1 -0
  76. package/docs/20260214-coverage-plan.md +45 -0
  77. package/docs/20260215-fix-plan-typeorm.md +46 -0
  78. package/docs/20260215-review-typeorm.md +594 -0
  79. package/docs/20260216-fix-plan-typeorm-exception.md +48 -0
  80. package/index.d.ts +1 -0
  81. package/index.js +6 -0
  82. package/package.json +43 -0
@@ -0,0 +1,175 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseSpRepository = exports.BaseRepository = void 0;
4
+ const common_1 = require("@nathapp/common");
5
+ const database_error_mapper_1 = require("../errors/database-error.mapper");
6
+ const transactional_decorator_1 = require("../transaction/transactional.decorator");
7
+ class BaseRepository {
8
+ constructor(dataSource) {
9
+ this.dataSource = dataSource;
10
+ }
11
+ }
12
+ exports.BaseRepository = BaseRepository;
13
+ class BaseSpRepository extends BaseRepository {
14
+ constructor(dataSource, executeCommand) {
15
+ super(dataSource);
16
+ this.executeCommand = executeCommand || 'call';
17
+ }
18
+ async callQuery(spName, formatOrValue, params, rename, objectifyForSignleRecord = false) {
19
+ this.validateSpName(spName);
20
+ const { formattedSP, parameters } = await this.prepare(spName, formatOrValue, params);
21
+ let results;
22
+ try {
23
+ const activeQueryRunner = (0, transactional_decorator_1.getActiveQueryRunner)();
24
+ if (activeQueryRunner) {
25
+ results = await activeQueryRunner.query(formattedSP, parameters);
26
+ }
27
+ else {
28
+ results = await this.dataSource.query(formattedSP, parameters);
29
+ }
30
+ }
31
+ catch (error) {
32
+ throw database_error_mapper_1.DatabaseErrorMapper.mapToAppException(error);
33
+ }
34
+ return this.resolveRecordsets(results, rename, objectifyForSignleRecord);
35
+ }
36
+ resolveRecordsets(results, rename, objectifyForSignleRecord = false) {
37
+ if (!Array.isArray(results)) {
38
+ if (objectifyForSignleRecord) {
39
+ return {};
40
+ }
41
+ return [];
42
+ }
43
+ const status = results.pop();
44
+ if (1 < results.length) {
45
+ const recordsets = [];
46
+ for (let i = 0; results.length > i; i++) {
47
+ const recordset = results[i];
48
+ if (!rename) {
49
+ recordsets.push(recordset);
50
+ }
51
+ else {
52
+ const result = [];
53
+ for (let i = 0; recordset.length > i; i++) {
54
+ const record = recordset[i];
55
+ result.push(this.renameKey(record, rename));
56
+ }
57
+ recordsets.push(result);
58
+ }
59
+ }
60
+ return recordsets;
61
+ }
62
+ const recordset = results[0];
63
+ if (objectifyForSignleRecord) {
64
+ if (1 == recordset.length) {
65
+ if (rename) {
66
+ return this.renameKey(recordset[0], rename);
67
+ }
68
+ return recordset[0];
69
+ }
70
+ }
71
+ if (rename) {
72
+ const result = [];
73
+ for (let i = 0; recordset.length > i; i++) {
74
+ result.push(this.renameKey(recordset[i], rename));
75
+ }
76
+ return result;
77
+ }
78
+ return recordset;
79
+ }
80
+ validateSpName(spName) {
81
+ const validSpNamePattern = /^[a-zA-Z_][a-zA-Z0-9_.]*$/;
82
+ if (!spName || typeof spName !== 'string') {
83
+ throw new Error('Invalid stored procedure name: must be a non-empty string');
84
+ }
85
+ const trimmedName = spName.trim();
86
+ if (trimmedName.length === 0) {
87
+ throw new Error('Invalid stored procedure name: cannot be empty or whitespace');
88
+ }
89
+ if (!validSpNamePattern.test(trimmedName)) {
90
+ throw new Error(`Invalid stored procedure name: "${spName}" contains disallowed characters. ` +
91
+ 'Only alphanumeric characters, underscores, and dots are allowed.');
92
+ }
93
+ if (trimmedName !== spName) {
94
+ throw new Error('Invalid stored procedure name: cannot contain leading or trailing whitespace');
95
+ }
96
+ }
97
+ async prepare(spName, formatOrValue, params) {
98
+ this.validateSpName(spName);
99
+ let parameters = [];
100
+ if (!(0, common_1.isUndefinedOrNullOrEmpty)(formatOrValue) &&
101
+ Array.isArray(formatOrValue)) {
102
+ parameters = formatOrValue;
103
+ }
104
+ else {
105
+ if (!(0, common_1.isUndefinedOrNullOrEmpty)(params)) {
106
+ if (!(0, common_1.isUndefinedOrNullOrEmpty)(formatOrValue)) {
107
+ params = (0, common_1.checkFormat)(formatOrValue, params);
108
+ for (const key of Object.keys(params)) {
109
+ parameters.push(params[key]);
110
+ }
111
+ }
112
+ }
113
+ }
114
+ let qm;
115
+ if (0 >= parameters.length) {
116
+ qm = '';
117
+ }
118
+ else {
119
+ qm = '?';
120
+ if (1 < parameters.length) {
121
+ qm += ',?'.repeat(parameters.length - 1);
122
+ }
123
+ }
124
+ return {
125
+ formattedSP: `${this.executeCommand} ${spName}(${qm})`,
126
+ parameters,
127
+ };
128
+ }
129
+ renameKey(object, rename, depth) {
130
+ for (const key in object) {
131
+ try {
132
+ if (undefined == depth) {
133
+ depth = 0;
134
+ }
135
+ if (object[key] && 'object' === typeof object[key]) {
136
+ const type = object[key].constructor
137
+ ? object[key].constructor.name
138
+ : '';
139
+ switch (type) {
140
+ case 'Object':
141
+ case 'Array':
142
+ this.renameKey(object[key], rename, depth + 1);
143
+ }
144
+ }
145
+ const newKey = rename(key, depth, object);
146
+ this.changeKey(object, key, newKey);
147
+ }
148
+ catch (error) {
149
+ if (error && typeof error === 'object') {
150
+ error.checkKey = key;
151
+ error.checkValue = object[key];
152
+ }
153
+ throw error;
154
+ }
155
+ }
156
+ return object;
157
+ }
158
+ changeKey(object, name, newName) {
159
+ if (!object || name == newName) {
160
+ return;
161
+ }
162
+ if ('object' === typeof object) {
163
+ const item = Object.getOwnPropertyDescriptor(object, name);
164
+ if (item) {
165
+ Object.defineProperty(object, newName, item);
166
+ }
167
+ }
168
+ else {
169
+ object[newName] = object[name];
170
+ }
171
+ delete object[name];
172
+ }
173
+ }
174
+ exports.BaseSpRepository = BaseSpRepository;
175
+ //# sourceMappingURL=base.repository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.repository.js","sourceRoot":"","sources":["../../lib/repository/base.repository.ts"],"names":[],"mappings":";;;AAAA,4CAAwE;AAExE,2EAAsE;AACtE,oFAA8E;AAO9E,MAAsB,cAAc;IAElC,YAAY,UAAsB;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AALD,wCAKC;AAED,MAAsB,gBAAiB,SAAQ,cAAc;IAG3D,YAAY,UAAsB,EAAE,cAAuB;Q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@
1
+ import { BaseRepository, BaseSpRepository } from "./base.repository";
2
+ export { BaseRepository, BaseSpRepository, };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseSpRepository = exports.BaseRepository = void 0;
4
+ const base_repository_1 = require("./base.repository");
5
+ Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repository_1.BaseRepository; } });
6
+ Object.defineProperty(exports, "BaseSpRepository", { enumerable: true, get: function () { return base_repository_1.BaseSpRepository; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/repository/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqE;AAGnE,+FAHO,gCAAc,OAGP;AACd,iGAJuB,kCAAgB,OAIvB"}
@@ -0,0 +1,2 @@
1
+ import { sqlQueryResult, resolveQuerySingleResult, resolveQueryArrayResult, resolveEmptySingleResult, createInMemorySqliteDataSource, createInMemoryPgDataSource } from "./testing-utils";
2
+ export { sqlQueryResult, resolveQuerySingleResult, resolveQueryArrayResult, resolveEmptySingleResult, createInMemorySqliteDataSource, createInMemoryPgDataSource, };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInMemoryPgDataSource = exports.createInMemorySqliteDataSource = exports.resolveEmptySingleResult = exports.resolveQueryArrayResult = exports.resolveQuerySingleResult = exports.sqlQueryResult = void 0;
4
+ const testing_utils_1 = require("./testing-utils");
5
+ Object.defineProperty(exports, "sqlQueryResult", { enumerable: true, get: function () { return testing_utils_1.sqlQueryResult; } });
6
+ Object.defineProperty(exports, "resolveQuerySingleResult", { enumerable: true, get: function () { return testing_utils_1.resolveQuerySingleResult; } });
7
+ Object.defineProperty(exports, "resolveQueryArrayResult", { enumerable: true, get: function () { return testing_utils_1.resolveQueryArrayResult; } });
8
+ Object.defineProperty(exports, "resolveEmptySingleResult", { enumerable: true, get: function () { return testing_utils_1.resolveEmptySingleResult; } });
9
+ Object.defineProperty(exports, "createInMemorySqliteDataSource", { enumerable: true, get: function () { return testing_utils_1.createInMemorySqliteDataSource; } });
10
+ Object.defineProperty(exports, "createInMemoryPgDataSource", { enumerable: true, get: function () { return testing_utils_1.createInMemoryPgDataSource; } });
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/testing/index.ts"],"names":[],"mappings":";;;AAAA,mDAA0L;AAGxL,+FAHO,8BAAc,OAGP;AACd,yGAJuB,wCAAwB,OAIvB;AACxB,wGALiD,uCAAuB,OAKjD;AACvB,yGAN0E,wCAAwB,OAM1E;AACxB,+GAPoG,8CAA8B,OAOpG;AAC9B,2GARoI,0CAA0B,OAQpI"}
@@ -0,0 +1,56 @@
1
+ import { DataSource, DataSourceOptions } from "typeorm";
2
+ export declare const sqlQueryResult: {
3
+ fieldCount: number;
4
+ affectedRows: number;
5
+ insertId: number;
6
+ info: string;
7
+ serverStatus: number;
8
+ warningStatus: number;
9
+ };
10
+ export declare const resolveQuerySingleResult: (result: any, statusQueryResult?: {
11
+ fieldCount: number;
12
+ affectedRows: number;
13
+ insertId: number;
14
+ info: string;
15
+ serverStatus: number;
16
+ warningStatus: number;
17
+ }) => (any[] | {
18
+ fieldCount: number;
19
+ affectedRows: number;
20
+ insertId: number;
21
+ info: string;
22
+ serverStatus: number;
23
+ warningStatus: number;
24
+ })[];
25
+ export declare const resolveQueryArrayResult: (results: any[], statusQueryResult?: {
26
+ fieldCount: number;
27
+ affectedRows: number;
28
+ insertId: number;
29
+ info: string;
30
+ serverStatus: number;
31
+ warningStatus: number;
32
+ }) => (any[] | {
33
+ fieldCount: number;
34
+ affectedRows: number;
35
+ insertId: number;
36
+ info: string;
37
+ serverStatus: number;
38
+ warningStatus: number;
39
+ })[];
40
+ export declare const resolveEmptySingleResult: (statusQueryResult?: {
41
+ fieldCount: number;
42
+ affectedRows: number;
43
+ insertId: number;
44
+ info: string;
45
+ serverStatus: number;
46
+ warningStatus: number;
47
+ }) => (never[] | {
48
+ fieldCount: number;
49
+ affectedRows: number;
50
+ insertId: number;
51
+ info: string;
52
+ serverStatus: number;
53
+ warningStatus: number;
54
+ })[];
55
+ export declare const createInMemorySqliteDataSource: (options?: DataSourceOptions) => Promise<DataSource>;
56
+ export declare const createInMemoryPgDataSource: (options?: DataSourceOptions) => Promise<DataSource>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createInMemoryPgDataSource = exports.createInMemorySqliteDataSource = exports.resolveEmptySingleResult = exports.resolveQueryArrayResult = exports.resolveQuerySingleResult = exports.sqlQueryResult = void 0;
4
+ const typeorm_1 = require("typeorm");
5
+ const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
6
+ exports.sqlQueryResult = {
7
+ fieldCount: 0,
8
+ affectedRows: 0,
9
+ insertId: 0,
10
+ info: '',
11
+ serverStatus: 34,
12
+ warningStatus: 0,
13
+ };
14
+ const resolveQuerySingleResult = (result, statusQueryResult = exports.sqlQueryResult) => {
15
+ return [[result], statusQueryResult];
16
+ };
17
+ exports.resolveQuerySingleResult = resolveQuerySingleResult;
18
+ const resolveQueryArrayResult = (results, statusQueryResult = exports.sqlQueryResult) => {
19
+ return [results, statusQueryResult];
20
+ };
21
+ exports.resolveQueryArrayResult = resolveQueryArrayResult;
22
+ const resolveEmptySingleResult = (statusQueryResult = exports.sqlQueryResult) => {
23
+ return [[], statusQueryResult];
24
+ };
25
+ exports.resolveEmptySingleResult = resolveEmptySingleResult;
26
+ const createInMemorySqliteDataSource = async (options) => {
27
+ const dbOptions = Object.assign({}, { type: "sqlite", database: ":memory:", }, options);
28
+ return new typeorm_1.DataSource(dbOptions);
29
+ };
30
+ exports.createInMemorySqliteDataSource = createInMemorySqliteDataSource;
31
+ const createInMemoryPgDataSource = (options) => {
32
+ const dbOptions = Object.assign({}, { type: "postgres", synchronize: true, }, options);
33
+ const pgMem = (0, load_package_util_1.loadPackage)('pg-mem', 'createInMemoryPgDataSource', () => require('pg-mem'));
34
+ const db = pgMem.newDb();
35
+ db.public.registerFunction({
36
+ name: 'current_database',
37
+ args: [],
38
+ returns: pgMem.DataType.text,
39
+ implementation: (x) => `hello world ${x}`,
40
+ });
41
+ return db.adapters.createTypeormDataSource(dbOptions);
42
+ };
43
+ exports.createInMemoryPgDataSource = createInMemoryPgDataSource;
44
+ //# sourceMappingURL=testing-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing-utils.js","sourceRoot":"","sources":["../../lib/testing/testing-utils.ts"],"names":[],"mappings":";;;AAAA,qCAAwD;AACxD,8EAAqE;AAExD,QAAA,cAAc,GAAG;IAC5B,UAAU,EAAE,CAAC;IACb,YAAY,EAAE,CAAC;IACf,QAAQ,EAAE,CAAC;IACX,IAAI,EAAE,EAAE;IACR,YAAY,EAAE,EAAE;IAChB,aAAa,EAAE,CAAC;CACjB,CAAC;AAEK,MAAM,wBAAwB,GAAG,CACtC,MAAW,EACX,iBAAiB,GAAG,sBAAc,EAClC,EAAE;IACF,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC;AACvC,CAAC,CAAC;AALW,QAAA,wBAAwB,4BAKnC;AAEK,MAAM,uBAAuB,GAAG,CACrC,OAAc,EACd,iBAAiB,GAAG,sBAAc,EAClC,EAAE;IACF,OAAO,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACtC,CAAC,CAAC;AALW,QAAA,uBAAuB,2BAKlC;AAEK,MAAM,wBAAwB,GAAG,CACtC,iBAAiB,GAAG,sBAAc,EAClC,EAAE;IACF,OAAO,CAAC,EAAE,EAAE,iBAAiB,CAAC,CAAC;AACjC,CAAC,CAAC;AAJW,QAAA,wBAAwB,4BAInC;AAEK,MAAM,8BAA8B,GAAG,KAAK,EAAE,OAA2B,EAAuB,EAAE;IACvG,MAAM,SAAS,GAAsB,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,GAAG,EAAE,OAAO,CAAC,CAAC;IAC3G,OAAO,IAAI,oBAAU,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,CAAA;AAHY,QAAA,8BAA8B,kCAG1C;AAEM,MAAM,0BAA0B,GAAG,CAAC,OAA2B,EAAuB,EAAE;IAC7F,MAAM,SAAS,GAAsB,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1G,MAAM,KAAK,GAAG,IAAA,+BAAW,EAAC,QAAQ,EAAE,4BAA4B,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3F,MAAM,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IACzB,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC;QACzB,IAAI,EAAE,kBAAkB;QACxB,IAAI,EAAE,EAAE;QACR,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI;QAC5B,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE;KAC1C,CAAC,CAAC;IAEH,OAAO,EAAE,CAAC,QAAQ,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;AACxD,CAAC,CAAA;AAZY,QAAA,0BAA0B,8BAYtC"}
@@ -0,0 +1,2 @@
1
+ export * from './transactional.decorator';
2
+ export * from './transaction.service';
@@ -0,0 +1,19 @@
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("./transactional.decorator"), exports);
18
+ __exportStar(require("./transaction.service"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/transaction/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,wDAAsC"}
@@ -0,0 +1,7 @@
1
+ import { DataSource, QueryRunner } from 'typeorm';
2
+ export declare class TransactionService {
3
+ private readonly dataSource;
4
+ constructor(dataSource: DataSource);
5
+ withTransaction<T>(callback: (queryRunner: QueryRunner) => Promise<T>): Promise<T>;
6
+ private isDatabaseError;
7
+ }
@@ -0,0 +1,73 @@
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
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.TransactionService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const typeorm_1 = require("typeorm");
15
+ const database_error_mapper_1 = require("../errors/database-error.mapper");
16
+ const transactional_decorator_1 = require("./transactional.decorator");
17
+ let TransactionService = class TransactionService {
18
+ constructor(dataSource) {
19
+ this.dataSource = dataSource;
20
+ }
21
+ async withTransaction(callback) {
22
+ const queryRunner = this.dataSource.createQueryRunner();
23
+ await queryRunner.connect();
24
+ await queryRunner.startTransaction();
25
+ try {
26
+ const result = await transactional_decorator_1.transactionContext.run(queryRunner, async () => {
27
+ return callback(queryRunner);
28
+ });
29
+ await queryRunner.commitTransaction();
30
+ return result;
31
+ }
32
+ catch (error) {
33
+ await queryRunner.rollbackTransaction();
34
+ if (this.isDatabaseError(error)) {
35
+ throw database_error_mapper_1.DatabaseErrorMapper.mapToAppException(error);
36
+ }
37
+ throw error;
38
+ }
39
+ finally {
40
+ await queryRunner.release();
41
+ }
42
+ }
43
+ isDatabaseError(error) {
44
+ if (!error || typeof error !== 'object') {
45
+ return false;
46
+ }
47
+ const err = error;
48
+ if (err.name === 'QueryFailedError') {
49
+ return true;
50
+ }
51
+ if (err.errno !== undefined || err.code !== undefined) {
52
+ const dbErrorCodes = [
53
+ 'ER_DUP_ENTRY', 'ER_NO_REFERENCED_ROW', 'ER_NO_REFERENCED_ROW_2',
54
+ 'ER_ROW_IS_REFERENCED', 'ER_ROW_IS_REFERENCED_2', 'ER_ACCESS_DENIED_ERROR',
55
+ 'ER_PARSE_ERROR', 'ER_NO_SUCH_TABLE', 'ER_LOCK_DEADLOCK', 'ER_LOCK_WAIT_TIMEOUT',
56
+ 'ETIMEDOUT', 'ECONNREFUSED', 'ECONNRESET'
57
+ ];
58
+ if (err.code && dbErrorCodes.includes(err.code)) {
59
+ return true;
60
+ }
61
+ if (typeof err.errno === 'number') {
62
+ return true;
63
+ }
64
+ }
65
+ return false;
66
+ }
67
+ };
68
+ exports.TransactionService = TransactionService;
69
+ exports.TransactionService = TransactionService = __decorate([
70
+ (0, common_1.Injectable)(),
71
+ __metadata("design:paramtypes", [typeorm_1.DataSource])
72
+ ], TransactionService);
73
+ //# sourceMappingURL=transaction.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.service.js","sourceRoot":"","sources":["../../lib/transaction/transaction.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAAkD;AAClD,2EAAsE;AACtE,uEAA+D;AAcxD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAC7B,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAUvD,KAAK,CAAC,eAAe,CACnB,QAAkD;QAElD,MAAM,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,CAAC;QACxD,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;QAC5B,MAAM,WAAW,CAAC,gBAAgB,EAAE,CAAC;QAErC,IAAI,CAAC;YAEH,MAAM,MAAM,GAAG,MAAM,4CAAkB,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;gBAClE,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;YACH,MAAM,WAAW,CAAC,iBAAiB,EAAE,CAAC;YACtC,OAAO,MAAM,CAAC;QAChB,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,WAAW,CAAC,mBAAmB,EAAE,CAAC;YAIxC,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;gBAChC,MAAM,2CAAmB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;YACrD,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAKO,eAAe,CAAC,KAAc;QACpC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACxC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,GAAG,GAAG,KAAY,CAAC;QAGzB,IAAI,GAAG,CAAC,IAAI,KAAK,kBAAkB,EAAE,CAAC;YACpC,OAAO,IAAI,CAAC;QACd,CAAC;QAGD,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,GAAG,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAEtD,MAAM,YAAY,GAAG;gBACnB,cAAc,EAAE,sBAAsB,EAAE,wBAAwB;gBAChE,sBAAsB,EAAE,wBAAwB,EAAE,wBAAwB;gBAC1E,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,sBAAsB;gBAChF,WAAW,EAAE,cAAc,EAAE,YAAY;aAC1C,CAAC;YAEF,IAAI,GAAG,CAAC,IAAI,IAAI,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBAChD,OAAO,IAAI,CAAC;YACd,CAAC;YAED,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAClC,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF,CAAA;AA5EY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;qCAE8B,oBAAU;GADxC,kBAAkB,CA4E9B"}
@@ -0,0 +1,5 @@
1
+ import { AsyncLocalStorage } from 'async_hooks';
2
+ import { QueryRunner } from 'typeorm';
3
+ export declare const transactionContext: AsyncLocalStorage<QueryRunner>;
4
+ export declare function Transactional(): MethodDecorator;
5
+ export declare function getActiveQueryRunner(): QueryRunner | undefined;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transactionContext = void 0;
4
+ exports.Transactional = Transactional;
5
+ exports.getActiveQueryRunner = getActiveQueryRunner;
6
+ const async_hooks_1 = require("async_hooks");
7
+ exports.transactionContext = new async_hooks_1.AsyncLocalStorage();
8
+ function Transactional() {
9
+ return function (target, propertyKey, descriptor) {
10
+ const originalMethod = descriptor.value;
11
+ descriptor.value = async function (...args) {
12
+ var _a;
13
+ const existingQueryRunner = exports.transactionContext.getStore();
14
+ if (existingQueryRunner) {
15
+ return originalMethod.apply(this, args);
16
+ }
17
+ const dataSource = this.dataSource || ((_a = this.repo) === null || _a === void 0 ? void 0 : _a.dataSource);
18
+ if (!dataSource) {
19
+ throw new Error('@Transactional requires the class to have a "dataSource" property or a "repo.dataSource" property');
20
+ }
21
+ const queryRunner = dataSource.createQueryRunner();
22
+ await queryRunner.connect();
23
+ await queryRunner.startTransaction();
24
+ try {
25
+ const result = await exports.transactionContext.run(queryRunner, async () => {
26
+ return originalMethod.apply(this, args);
27
+ });
28
+ await queryRunner.commitTransaction();
29
+ return result;
30
+ }
31
+ catch (error) {
32
+ await queryRunner.rollbackTransaction();
33
+ throw error;
34
+ }
35
+ finally {
36
+ await queryRunner.release();
37
+ }
38
+ };
39
+ return descriptor;
40
+ };
41
+ }
42
+ function getActiveQueryRunner() {
43
+ return exports.transactionContext.getStore();
44
+ }
45
+ //# sourceMappingURL=transactional.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactional.decorator.js","sourceRoot":"","sources":["../../lib/transaction/transactional.decorator.ts"],"names":[],"mappings":";;;AA0BA,sCAgDC;AAMD,oDAEC;AAlFD,6CAAgD;AAInC,QAAA,kBAAkB,GAAG,IAAI,+BAAiB,EAAe,CAAC;AAsBvE,SAAgB,aAAa;IAC3B,OAAO,UACL,MAAW,EACX,WAA4B,EAC5B,UAA8B;QAE9B,MAAM,cAAc,GAAG,UAAU,CAAC,KAAK,CAAC;QAExC,UAAU,CAAC,KAAK,GAAG,KAAK,WAAW,GAAG,IAAW;;YAE/C,MAAM,mBAAmB,GAAG,0BAAkB,CAAC,QAAQ,EAAE,CAAC;YAE1D,IAAI,mBAAmB,EAAE,CAAC;gBAExB,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC1C,CAAC;YAGD,MAAM,UAAU,GAAI,IAAY,CAAC,UAAU,KAAI,MAAC,IAAY,CAAC,IAAI,0CAAE,UAAU,CAAA,CAAC;YAE9E,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CACb,mGAAmG,CACpG,CAAC;YACJ,CAAC;YAED,MAAM,WAAW,GAAG,UAAU,CAAC,iBAAiB,EAAE,CAAC;YACnD,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,WAAW,CAAC,gBAAgB,EAAE,CAAC;YAErC,IAAI,CAAC;gBAEH,MAAM,MAAM,GAAG,MAAM,0BAAkB,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE;oBAClE,OAAO,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;gBAC1C,CAAC,CAAC,CAAC;gBAEH,MAAM,WAAW,CAAC,iBAAiB,EAAE,CAAC;gBACtC,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,WAAW,CAAC,mBAAmB,EAAE,CAAC;gBACxC,MAAM,KAAK,CAAC;YACd,CAAC;oBAAS,CAAC;gBACT,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;YAC9B,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC;AACJ,CAAC;AAMD,SAAgB,oBAAoB;IAClC,OAAO,0BAAkB,CAAC,QAAQ,EAAE,CAAC;AACvC,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { TypeOrmModuleOptions, TypeOrmOptionsFactory } from "@nestjs/typeorm";
2
+ import { EntitySchema, MixedList } from "typeorm";
3
+ import { BaseDataSourceOptions } from "typeorm/data-source/BaseDataSourceOptions";
4
+ import { MysqlConnectionOptions } from "typeorm/driver/mysql/MysqlConnectionOptions";
5
+ import { MongoConnectionOptions } from "typeorm/driver/mongodb/MongoConnectionOptions";
6
+ import { PostgresConnectionOptions } from "typeorm/driver/postgres/PostgresConnectionOptions";
7
+ export type OptionWithoutEntities = Omit<Partial<BaseDataSourceOptions>, "entities" | "type"> | Omit<Partial<MysqlConnectionOptions>, "entities" | "type"> | Omit<Partial<MongoConnectionOptions>, "entities" | "type"> | Omit<Partial<PostgresConnectionOptions>, "entities" | "type">;
8
+ export declare class BaseTypeOrmModuleOptionFactory implements TypeOrmOptionsFactory {
9
+ private readonly connectionString;
10
+ private readonly entities?;
11
+ private readonly options?;
12
+ private connectionType;
13
+ constructor(connectionString: string, entities?: MixedList<Function | string | EntitySchema> | undefined, options?: OptionWithoutEntities | undefined);
14
+ createTypeOrmOptions(connectionName?: string): TypeOrmModuleOptions | Promise<TypeOrmModuleOptions>;
15
+ }
16
+ export declare class DefaultTypeOrmModuleOptionFactory extends BaseTypeOrmModuleOptionFactory {
17
+ constructor(entities?: MixedList<Function | string | EntitySchema>, options?: OptionWithoutEntities);
18
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultTypeOrmModuleOptionFactory = exports.BaseTypeOrmModuleOptionFactory = void 0;
4
+ const typeorm_utils_1 = require("./typeorm-utils");
5
+ class BaseTypeOrmModuleOptionFactory {
6
+ constructor(connectionString, entities, options) {
7
+ this.connectionString = connectionString;
8
+ this.entities = entities;
9
+ this.options = options;
10
+ if (!connectionString || connectionString == "") {
11
+ throw new Error("connectionString is missing");
12
+ }
13
+ const isPresent = connectionString && connectionString != "";
14
+ this.connectionType = isPresent ? this.connectionString.split(":").shift() : "mysql";
15
+ }
16
+ createTypeOrmOptions(connectionName) {
17
+ const options = (0, typeorm_utils_1.sanitizeTypeOrmOptions)(this.connectionType, this.options || {});
18
+ switch (this.connectionType) {
19
+ case "mysql":
20
+ case "mariadb":
21
+ case "mongodb":
22
+ case "postgres":
23
+ return {
24
+ ...options,
25
+ name: connectionName,
26
+ type: this.connectionType,
27
+ url: this.connectionString,
28
+ entities: this.entities || [],
29
+ };
30
+ default:
31
+ throw new Error("Connection Not Supported");
32
+ }
33
+ }
34
+ }
35
+ exports.BaseTypeOrmModuleOptionFactory = BaseTypeOrmModuleOptionFactory;
36
+ class DefaultTypeOrmModuleOptionFactory extends BaseTypeOrmModuleOptionFactory {
37
+ constructor(entities, options) {
38
+ super(process.env.MYSQL_URL || "", entities, options);
39
+ }
40
+ }
41
+ exports.DefaultTypeOrmModuleOptionFactory = DefaultTypeOrmModuleOptionFactory;
42
+ //# sourceMappingURL=base-typeorm-options-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-typeorm-options-factory.js","sourceRoot":"","sources":["../../lib/typeorm/base-typeorm-options-factory.ts"],"names":[],"mappings":";;;AAIA,mDAAyD;AAQzD,MAAa,8BAA8B;IAGzC,YAA6B,gBAAwB,EAClC,QAAsD,EACtD,OAA+B;QAFrB,qBAAgB,GAAhB,gBAAgB,CAAQ;QAClC,aAAQ,GAAR,QAAQ,CAA8C;QACtD,YAAO,GAAP,OAAO,CAAwB;QAEhD,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,IAAI,EAAE,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QAED,MAAM,SAAS,GAAG,gBAAgB,IAAI,gBAAgB,IAAI,EAAE,CAAC;QAC7D,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,EAA6B,CAAC,CAAC,CAAC,OAAO,CAAC;IAClH,CAAC;IAED,oBAAoB,CAAC,cAAuB;QAC1C,MAAM,OAAO,GAAG,IAAA,sCAAsB,EAAC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;QAChF,QAAQ,IAAI,CAAC,cAAc,EAAE,CAAC;YAC5B,KAAK,OAAO,CAAC;YACb,KAAK,SAAS,CAAC;YACf,KAAK,SAAS,CAAC;YACf,KAAK,UAAU;gBACb,OAAO;oBACL,GAAG,OAAO;oBACV,IAAI,EAAE,cAAc;oBACpB,IAAI,EAAE,IAAI,CAAC,cAAc;oBACzB,GAAG,EAAE,IAAI,CAAC,gBAAgB;oBAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ,IAAI,EAAE;iBAC9B,CAAA;YACH;gBACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;CACF;AAjCD,wEAiCC;AAED,MAAa,iCAAkC,SAAQ,8BAA8B;IACnF,YAAY,QAAsD,EAC/D,OAA+B;QAC9B,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;CACF;AALD,8EAKC"}
@@ -0,0 +1,13 @@
1
+ import { SnakeNamingStrategy } from "typeorm-naming-strategies";
2
+ export declare const defaultExtraOptions: {
3
+ entities: never[];
4
+ logging: boolean;
5
+ synchronize: boolean;
6
+ autoLoadEntities: boolean;
7
+ namingStrategy: SnakeNamingStrategy;
8
+ };
9
+ export declare const defaultMysqlExtraOptions: {
10
+ supportBigNumbers: boolean;
11
+ bigNumberStrings: boolean;
12
+ };
13
+ export declare const defaultMongoExtraOptions: {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultMongoExtraOptions = exports.defaultMysqlExtraOptions = exports.defaultExtraOptions = void 0;
4
+ const typeorm_naming_strategies_1 = require("typeorm-naming-strategies");
5
+ exports.defaultExtraOptions = {
6
+ entities: [],
7
+ logging: false,
8
+ synchronize: false,
9
+ autoLoadEntities: true,
10
+ namingStrategy: new typeorm_naming_strategies_1.SnakeNamingStrategy(),
11
+ };
12
+ exports.defaultMysqlExtraOptions = {
13
+ supportBigNumbers: true,
14
+ bigNumberStrings: true,
15
+ };
16
+ exports.defaultMongoExtraOptions = {};
17
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../lib/typeorm/constants.ts"],"names":[],"mappings":";;;AAAA,yEAA+D;AAElD,QAAA,mBAAmB,GAAG;IACjC,QAAQ,EAAE,EAAE;IACZ,OAAO,EAAE,KAAK;IACd,WAAW,EAAE,KAAK;IAClB,gBAAgB,EAAE,IAAI;IACtB,cAAc,EAAE,IAAI,+CAAmB,EAAE;CAC1C,CAAA;AAEY,QAAA,wBAAwB,GAAG;IACtC,iBAAiB,EAAE,IAAI;IACvB,gBAAgB,EAAE,IAAI;CACvB,CAAA;AAEY,QAAA,wBAAwB,GAAG,EAEvC,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { BaseTypeOrmModuleOptionFactory, DefaultTypeOrmModuleOptionFactory } from "./base-typeorm-options-factory";
2
+ import { defaultExtraOptions, defaultMongoExtraOptions, defaultMysqlExtraOptions } from "./constants";
3
+ import { DEFAULT_DATA_SOURCE_NAME, TypeOrmExModule } from "./typeorm-ex.module";
4
+ import { sanitizeTypeOrmOptions } from "./typeorm-utils";
5
+ export { TypeOrmExModule, DEFAULT_DATA_SOURCE_NAME, defaultExtraOptions, defaultMysqlExtraOptions, defaultMongoExtraOptions, sanitizeTypeOrmOptions, BaseTypeOrmModuleOptionFactory, DefaultTypeOrmModuleOptionFactory, };
6
+ export type { SupportedConnectionType } from "./typeorm-ex.module";
7
+ export type { OptionWithoutEntities } from "./base-typeorm-options-factory";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DefaultTypeOrmModuleOptionFactory = exports.BaseTypeOrmModuleOptionFactory = exports.sanitizeTypeOrmOptions = exports.defaultMongoExtraOptions = exports.defaultMysqlExtraOptions = exports.defaultExtraOptions = exports.DEFAULT_DATA_SOURCE_NAME = exports.TypeOrmExModule = void 0;
4
+ const base_typeorm_options_factory_1 = require("./base-typeorm-options-factory");
5
+ Object.defineProperty(exports, "BaseTypeOrmModuleOptionFactory", { enumerable: true, get: function () { return base_typeorm_options_factory_1.BaseTypeOrmModuleOptionFactory; } });
6
+ Object.defineProperty(exports, "DefaultTypeOrmModuleOptionFactory", { enumerable: true, get: function () { return base_typeorm_options_factory_1.DefaultTypeOrmModuleOptionFactory; } });
7
+ const constants_1 = require("./constants");
8
+ Object.defineProperty(exports, "defaultExtraOptions", { enumerable: true, get: function () { return constants_1.defaultExtraOptions; } });
9
+ Object.defineProperty(exports, "defaultMongoExtraOptions", { enumerable: true, get: function () { return constants_1.defaultMongoExtraOptions; } });
10
+ Object.defineProperty(exports, "defaultMysqlExtraOptions", { enumerable: true, get: function () { return constants_1.defaultMysqlExtraOptions; } });
11
+ const typeorm_ex_module_1 = require("./typeorm-ex.module");
12
+ Object.defineProperty(exports, "DEFAULT_DATA_SOURCE_NAME", { enumerable: true, get: function () { return typeorm_ex_module_1.DEFAULT_DATA_SOURCE_NAME; } });
13
+ Object.defineProperty(exports, "TypeOrmExModule", { enumerable: true, get: function () { return typeorm_ex_module_1.TypeOrmExModule; } });
14
+ const typeorm_utils_1 = require("./typeorm-utils");
15
+ Object.defineProperty(exports, "sanitizeTypeOrmOptions", { enumerable: true, get: function () { return typeorm_utils_1.sanitizeTypeOrmOptions; } });
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/typeorm/index.ts"],"names":[],"mappings":";;;AAAA,iFAAmH;AAYjH,+GAZO,6DAA8B,OAYP;AAC9B,kHAbuC,gEAAiC,OAavC;AAZnC,2CAAsG;AAOpG,oGAPO,+BAAmB,OAOP;AAEnB,yGAT4B,oCAAwB,OAS5B;AADxB,yGARsD,oCAAwB,OAQtD;AAP1B,2DAAgF;AAK9E,yGALO,4CAAwB,OAKP;AADxB,gGAJiC,mCAAe,OAIjC;AAHjB,mDAAyD;AAQvD,uGARO,sCAAsB,OAQP"}