nicot 1.2.11 → 1.2.13
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/README.md +408 -0
- package/dist/index.cjs +774 -32
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +797 -32
- package/dist/index.mjs.map +4 -4
- package/dist/src/transactional-typeorm.module.d.ts +20 -0
- package/dist/src/utility/create-dynamic-fetcher-proxy.d.ts +1 -0
- package/dist/src/utility/create-inject-from-token-factory.d.ts +4 -0
- package/index.ts +1 -0
- package/package.json +5 -2
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
7
10
|
var __export = (target, all) => {
|
|
8
11
|
for (var name in all)
|
|
9
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -35,6 +38,539 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
35
38
|
return result;
|
|
36
39
|
};
|
|
37
40
|
|
|
41
|
+
// node_modules/@nestjs/typeorm/dist/typeorm.constants.js
|
|
42
|
+
var require_typeorm_constants = __commonJS({
|
|
43
|
+
"node_modules/@nestjs/typeorm/dist/typeorm.constants.js"(exports2) {
|
|
44
|
+
"use strict";
|
|
45
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
46
|
+
exports2.DEFAULT_DATA_SOURCE_NAME = exports2.TYPEORM_MODULE_ID = exports2.TYPEORM_MODULE_OPTIONS = void 0;
|
|
47
|
+
exports2.TYPEORM_MODULE_OPTIONS = "TypeOrmModuleOptions";
|
|
48
|
+
exports2.TYPEORM_MODULE_ID = "TypeOrmModuleId";
|
|
49
|
+
exports2.DEFAULT_DATA_SOURCE_NAME = "default";
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// node_modules/@nestjs/typeorm/dist/exceptions/circular-dependency.exception.js
|
|
54
|
+
var require_circular_dependency_exception = __commonJS({
|
|
55
|
+
"node_modules/@nestjs/typeorm/dist/exceptions/circular-dependency.exception.js"(exports2) {
|
|
56
|
+
"use strict";
|
|
57
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
58
|
+
exports2.CircularDependencyException = void 0;
|
|
59
|
+
var CircularDependencyException = class extends Error {
|
|
60
|
+
constructor(context) {
|
|
61
|
+
const ctx = context ? ` inside ${context}` : ``;
|
|
62
|
+
super(`A circular dependency has been detected${ctx}. Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()". Also, try to eliminate barrel files because they can lead to an unexpected behavior too.`);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
exports2.CircularDependencyException = CircularDependencyException;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// node_modules/@nestjs/typeorm/dist/common/typeorm.utils.js
|
|
70
|
+
var require_typeorm_utils = __commonJS({
|
|
71
|
+
"node_modules/@nestjs/typeorm/dist/common/typeorm.utils.js"(exports2) {
|
|
72
|
+
"use strict";
|
|
73
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
74
|
+
exports2.generateString = exports2.getConnectionToken = void 0;
|
|
75
|
+
exports2.getRepositoryToken = getRepositoryToken;
|
|
76
|
+
exports2.getCustomRepositoryToken = getCustomRepositoryToken;
|
|
77
|
+
exports2.getDataSourceToken = getDataSourceToken;
|
|
78
|
+
exports2.getDataSourcePrefix = getDataSourcePrefix;
|
|
79
|
+
exports2.getEntityManagerToken = getEntityManagerToken2;
|
|
80
|
+
exports2.handleRetry = handleRetry;
|
|
81
|
+
exports2.getDataSourceName = getDataSourceName;
|
|
82
|
+
var common_1 = require("@nestjs/common");
|
|
83
|
+
var operators_1 = require("rxjs/operators");
|
|
84
|
+
var typeorm_1 = require("typeorm");
|
|
85
|
+
var circular_dependency_exception_1 = require_circular_dependency_exception();
|
|
86
|
+
var typeorm_constants_1 = require_typeorm_constants();
|
|
87
|
+
var logger = new common_1.Logger("TypeOrmModule");
|
|
88
|
+
function getRepositoryToken(entity, dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
89
|
+
if (entity === null || entity === void 0) {
|
|
90
|
+
throw new circular_dependency_exception_1.CircularDependencyException("@InjectRepository()");
|
|
91
|
+
}
|
|
92
|
+
const dataSourcePrefix = getDataSourcePrefix(dataSource);
|
|
93
|
+
if (entity instanceof Function && (entity.prototype instanceof typeorm_1.Repository || entity.prototype instanceof typeorm_1.AbstractRepository)) {
|
|
94
|
+
if (!dataSourcePrefix) {
|
|
95
|
+
return entity;
|
|
96
|
+
}
|
|
97
|
+
return `${dataSourcePrefix}${getCustomRepositoryToken(entity)}`;
|
|
98
|
+
}
|
|
99
|
+
if (entity instanceof typeorm_1.EntitySchema) {
|
|
100
|
+
return `${dataSourcePrefix}${entity.options.target ? entity.options.target.name : entity.options.name}Repository`;
|
|
101
|
+
}
|
|
102
|
+
return `${dataSourcePrefix}${entity.name}Repository`;
|
|
103
|
+
}
|
|
104
|
+
function getCustomRepositoryToken(repository) {
|
|
105
|
+
if (repository === null || repository === void 0) {
|
|
106
|
+
throw new circular_dependency_exception_1.CircularDependencyException("@InjectRepository()");
|
|
107
|
+
}
|
|
108
|
+
return repository.name;
|
|
109
|
+
}
|
|
110
|
+
function getDataSourceToken(dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
111
|
+
return typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource ? typeorm_1.DataSource ?? typeorm_1.Connection : "string" === typeof dataSource ? `${dataSource}DataSource` : typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource.name || !dataSource.name ? typeorm_1.DataSource ?? typeorm_1.Connection : `${dataSource.name}DataSource`;
|
|
112
|
+
}
|
|
113
|
+
exports2.getConnectionToken = getDataSourceToken;
|
|
114
|
+
function getDataSourcePrefix(dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
115
|
+
if (dataSource === typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
116
|
+
return "";
|
|
117
|
+
}
|
|
118
|
+
if (typeof dataSource === "string") {
|
|
119
|
+
return dataSource + "_";
|
|
120
|
+
}
|
|
121
|
+
if (dataSource.name === typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME || !dataSource.name) {
|
|
122
|
+
return "";
|
|
123
|
+
}
|
|
124
|
+
return dataSource.name + "_";
|
|
125
|
+
}
|
|
126
|
+
function getEntityManagerToken2(dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
127
|
+
return typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource ? typeorm_1.EntityManager : "string" === typeof dataSource ? `${dataSource}EntityManager` : typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME === dataSource.name || !dataSource.name ? typeorm_1.EntityManager : `${dataSource.name}EntityManager`;
|
|
128
|
+
}
|
|
129
|
+
function handleRetry(retryAttempts = 9, retryDelay = 3e3, dataSourceName = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME, verboseRetryLog = false, toRetry) {
|
|
130
|
+
return (source) => source.pipe((0, operators_1.retryWhen)((e) => e.pipe((0, operators_1.scan)((errorCount, error) => {
|
|
131
|
+
if (toRetry && !toRetry(error)) {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
const dataSourceInfo = dataSourceName === typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME ? "" : ` (${dataSourceName})`;
|
|
135
|
+
const verboseMessage = verboseRetryLog ? ` Message: ${error.message}.` : "";
|
|
136
|
+
logger.error(`Unable to connect to the database${dataSourceInfo}.${verboseMessage} Retrying (${errorCount + 1})...`, error.stack);
|
|
137
|
+
if (errorCount + 1 >= retryAttempts) {
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
return errorCount + 1;
|
|
141
|
+
}, 0), (0, operators_1.delay)(retryDelay))));
|
|
142
|
+
}
|
|
143
|
+
function getDataSourceName(options) {
|
|
144
|
+
return options && options.name ? options.name : typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME;
|
|
145
|
+
}
|
|
146
|
+
var generateString = () => crypto.randomUUID();
|
|
147
|
+
exports2.generateString = generateString;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// node_modules/@nestjs/typeorm/dist/common/typeorm.decorators.js
|
|
152
|
+
var require_typeorm_decorators = __commonJS({
|
|
153
|
+
"node_modules/@nestjs/typeorm/dist/common/typeorm.decorators.js"(exports2) {
|
|
154
|
+
"use strict";
|
|
155
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
156
|
+
exports2.InjectEntityManager = exports2.InjectConnection = exports2.InjectDataSource = exports2.InjectRepository = void 0;
|
|
157
|
+
var common_1 = require("@nestjs/common");
|
|
158
|
+
var typeorm_constants_1 = require_typeorm_constants();
|
|
159
|
+
var typeorm_utils_1 = require_typeorm_utils();
|
|
160
|
+
var InjectRepository = (entity, dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) => (0, common_1.Inject)((0, typeorm_utils_1.getRepositoryToken)(entity, dataSource));
|
|
161
|
+
exports2.InjectRepository = InjectRepository;
|
|
162
|
+
var InjectDataSource = (dataSource) => (0, common_1.Inject)((0, typeorm_utils_1.getDataSourceToken)(dataSource));
|
|
163
|
+
exports2.InjectDataSource = InjectDataSource;
|
|
164
|
+
exports2.InjectConnection = exports2.InjectDataSource;
|
|
165
|
+
var InjectEntityManager = (dataSource) => (0, common_1.Inject)((0, typeorm_utils_1.getEntityManagerToken)(dataSource));
|
|
166
|
+
exports2.InjectEntityManager = InjectEntityManager;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// node_modules/@nestjs/typeorm/dist/common/index.js
|
|
171
|
+
var require_common = __commonJS({
|
|
172
|
+
"node_modules/@nestjs/typeorm/dist/common/index.js"(exports2) {
|
|
173
|
+
"use strict";
|
|
174
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
175
|
+
if (k2 === void 0) k2 = k;
|
|
176
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
177
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
178
|
+
desc = { enumerable: true, get: function() {
|
|
179
|
+
return m[k];
|
|
180
|
+
} };
|
|
181
|
+
}
|
|
182
|
+
Object.defineProperty(o, k2, desc);
|
|
183
|
+
}) : (function(o, m, k, k2) {
|
|
184
|
+
if (k2 === void 0) k2 = k;
|
|
185
|
+
o[k2] = m[k];
|
|
186
|
+
}));
|
|
187
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
188
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
189
|
+
};
|
|
190
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
191
|
+
__exportStar(require_typeorm_decorators(), exports2);
|
|
192
|
+
__exportStar(require_typeorm_utils(), exports2);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// node_modules/@nestjs/typeorm/dist/interfaces/typeorm-options.interface.js
|
|
197
|
+
var require_typeorm_options_interface = __commonJS({
|
|
198
|
+
"node_modules/@nestjs/typeorm/dist/interfaces/typeorm-options.interface.js"(exports2) {
|
|
199
|
+
"use strict";
|
|
200
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// node_modules/@nestjs/typeorm/dist/interfaces/index.js
|
|
205
|
+
var require_interfaces = __commonJS({
|
|
206
|
+
"node_modules/@nestjs/typeorm/dist/interfaces/index.js"(exports2) {
|
|
207
|
+
"use strict";
|
|
208
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
209
|
+
if (k2 === void 0) k2 = k;
|
|
210
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
211
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
212
|
+
desc = { enumerable: true, get: function() {
|
|
213
|
+
return m[k];
|
|
214
|
+
} };
|
|
215
|
+
}
|
|
216
|
+
Object.defineProperty(o, k2, desc);
|
|
217
|
+
}) : (function(o, m, k, k2) {
|
|
218
|
+
if (k2 === void 0) k2 = k;
|
|
219
|
+
o[k2] = m[k];
|
|
220
|
+
}));
|
|
221
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
222
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
223
|
+
};
|
|
224
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
225
|
+
__exportStar(require_typeorm_options_interface(), exports2);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// node_modules/@nestjs/typeorm/dist/entities-metadata.storage.js
|
|
230
|
+
var require_entities_metadata_storage = __commonJS({
|
|
231
|
+
"node_modules/@nestjs/typeorm/dist/entities-metadata.storage.js"(exports2) {
|
|
232
|
+
"use strict";
|
|
233
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
234
|
+
exports2.EntitiesMetadataStorage = void 0;
|
|
235
|
+
var EntitiesMetadataStorage = class {
|
|
236
|
+
static addEntitiesByDataSource(dataSource, entities) {
|
|
237
|
+
const dataSourceToken = typeof dataSource === "string" ? dataSource : dataSource.name;
|
|
238
|
+
if (!dataSourceToken) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
let collection = this.storage.get(dataSourceToken);
|
|
242
|
+
if (!collection) {
|
|
243
|
+
collection = [];
|
|
244
|
+
this.storage.set(dataSourceToken, collection);
|
|
245
|
+
}
|
|
246
|
+
entities.forEach((entity) => {
|
|
247
|
+
if (collection.includes(entity)) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
collection.push(entity);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
static getEntitiesByDataSource(dataSource) {
|
|
254
|
+
const dataSourceToken = typeof dataSource === "string" ? dataSource : dataSource.name;
|
|
255
|
+
if (!dataSourceToken) {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
return this.storage.get(dataSourceToken) || [];
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
exports2.EntitiesMetadataStorage = EntitiesMetadataStorage;
|
|
262
|
+
EntitiesMetadataStorage.storage = /* @__PURE__ */ new Map();
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// node_modules/@nestjs/typeorm/dist/typeorm-core.module.js
|
|
267
|
+
var require_typeorm_core_module = __commonJS({
|
|
268
|
+
"node_modules/@nestjs/typeorm/dist/typeorm-core.module.js"(exports2) {
|
|
269
|
+
"use strict";
|
|
270
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
271
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
272
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
273
|
+
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;
|
|
274
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
275
|
+
};
|
|
276
|
+
var __metadata = exports2 && exports2.__metadata || function(k, v) {
|
|
277
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
278
|
+
};
|
|
279
|
+
var __param = exports2 && exports2.__param || function(paramIndex, decorator) {
|
|
280
|
+
return function(target, key) {
|
|
281
|
+
decorator(target, key, paramIndex);
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
var TypeOrmCoreModule_1;
|
|
285
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
286
|
+
exports2.TypeOrmCoreModule = void 0;
|
|
287
|
+
var common_1 = require("@nestjs/common");
|
|
288
|
+
var core_1 = require("@nestjs/core");
|
|
289
|
+
var rxjs_1 = require("rxjs");
|
|
290
|
+
var typeorm_1 = require("typeorm");
|
|
291
|
+
var typeorm_utils_1 = require_typeorm_utils();
|
|
292
|
+
var entities_metadata_storage_1 = require_entities_metadata_storage();
|
|
293
|
+
var typeorm_constants_1 = require_typeorm_constants();
|
|
294
|
+
var TypeOrmCoreModule = TypeOrmCoreModule_1 = class TypeOrmCoreModule {
|
|
295
|
+
constructor(options, moduleRef) {
|
|
296
|
+
this.options = options;
|
|
297
|
+
this.moduleRef = moduleRef;
|
|
298
|
+
this.logger = new common_1.Logger("TypeOrmModule");
|
|
299
|
+
}
|
|
300
|
+
static forRoot(options = {}) {
|
|
301
|
+
const typeOrmModuleOptions = {
|
|
302
|
+
provide: typeorm_constants_1.TYPEORM_MODULE_OPTIONS,
|
|
303
|
+
useValue: options
|
|
304
|
+
};
|
|
305
|
+
const dataSourceProvider = {
|
|
306
|
+
provide: (0, typeorm_utils_1.getDataSourceToken)(options),
|
|
307
|
+
useFactory: async () => await this.createDataSourceFactory(options)
|
|
308
|
+
};
|
|
309
|
+
const entityManagerProvider = this.createEntityManagerProvider(options);
|
|
310
|
+
const providers = [
|
|
311
|
+
entityManagerProvider,
|
|
312
|
+
dataSourceProvider,
|
|
313
|
+
typeOrmModuleOptions
|
|
314
|
+
];
|
|
315
|
+
const exports3 = [entityManagerProvider, dataSourceProvider];
|
|
316
|
+
if (dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
317
|
+
providers.push({
|
|
318
|
+
provide: typeorm_1.Connection,
|
|
319
|
+
useExisting: typeorm_1.DataSource
|
|
320
|
+
});
|
|
321
|
+
exports3.push(typeorm_1.Connection);
|
|
322
|
+
}
|
|
323
|
+
return {
|
|
324
|
+
module: TypeOrmCoreModule_1,
|
|
325
|
+
providers,
|
|
326
|
+
exports: exports3
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
static forRootAsync(options) {
|
|
330
|
+
const dataSourceProvider = {
|
|
331
|
+
provide: (0, typeorm_utils_1.getDataSourceToken)(options),
|
|
332
|
+
useFactory: async (typeOrmOptions) => {
|
|
333
|
+
if (options.name) {
|
|
334
|
+
return await this.createDataSourceFactory({
|
|
335
|
+
...typeOrmOptions,
|
|
336
|
+
name: options.name
|
|
337
|
+
}, options.dataSourceFactory);
|
|
338
|
+
}
|
|
339
|
+
return await this.createDataSourceFactory(typeOrmOptions, options.dataSourceFactory);
|
|
340
|
+
},
|
|
341
|
+
inject: [typeorm_constants_1.TYPEORM_MODULE_OPTIONS]
|
|
342
|
+
};
|
|
343
|
+
const entityManagerProvider = {
|
|
344
|
+
provide: (0, typeorm_utils_1.getEntityManagerToken)(options),
|
|
345
|
+
useFactory: (dataSource) => dataSource.manager,
|
|
346
|
+
inject: [(0, typeorm_utils_1.getDataSourceToken)(options)]
|
|
347
|
+
};
|
|
348
|
+
const asyncProviders = this.createAsyncProviders(options);
|
|
349
|
+
const providers = [
|
|
350
|
+
...asyncProviders,
|
|
351
|
+
entityManagerProvider,
|
|
352
|
+
dataSourceProvider,
|
|
353
|
+
{
|
|
354
|
+
provide: typeorm_constants_1.TYPEORM_MODULE_ID,
|
|
355
|
+
useValue: (0, typeorm_utils_1.generateString)()
|
|
356
|
+
},
|
|
357
|
+
...options.extraProviders || []
|
|
358
|
+
];
|
|
359
|
+
const exports3 = [
|
|
360
|
+
entityManagerProvider,
|
|
361
|
+
dataSourceProvider
|
|
362
|
+
];
|
|
363
|
+
if (dataSourceProvider.provide === typeorm_1.DataSource) {
|
|
364
|
+
providers.push({
|
|
365
|
+
provide: typeorm_1.Connection,
|
|
366
|
+
useExisting: typeorm_1.DataSource
|
|
367
|
+
});
|
|
368
|
+
exports3.push(typeorm_1.Connection);
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
module: TypeOrmCoreModule_1,
|
|
372
|
+
imports: options.imports,
|
|
373
|
+
providers,
|
|
374
|
+
exports: exports3
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
async onApplicationShutdown() {
|
|
378
|
+
const dataSource = this.moduleRef.get((0, typeorm_utils_1.getDataSourceToken)(this.options));
|
|
379
|
+
try {
|
|
380
|
+
if (dataSource && dataSource.isInitialized) {
|
|
381
|
+
await dataSource.destroy();
|
|
382
|
+
}
|
|
383
|
+
} catch (e) {
|
|
384
|
+
this.logger.error(e?.message);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
static createAsyncProviders(options) {
|
|
388
|
+
if (options.useExisting || options.useFactory) {
|
|
389
|
+
return [this.createAsyncOptionsProvider(options)];
|
|
390
|
+
}
|
|
391
|
+
const useClass = options.useClass;
|
|
392
|
+
return [
|
|
393
|
+
this.createAsyncOptionsProvider(options),
|
|
394
|
+
{
|
|
395
|
+
provide: useClass,
|
|
396
|
+
useClass
|
|
397
|
+
}
|
|
398
|
+
];
|
|
399
|
+
}
|
|
400
|
+
static createAsyncOptionsProvider(options) {
|
|
401
|
+
if (options.useFactory) {
|
|
402
|
+
return {
|
|
403
|
+
provide: typeorm_constants_1.TYPEORM_MODULE_OPTIONS,
|
|
404
|
+
useFactory: options.useFactory,
|
|
405
|
+
inject: options.inject || []
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
const inject = [
|
|
409
|
+
options.useClass || options.useExisting
|
|
410
|
+
];
|
|
411
|
+
return {
|
|
412
|
+
provide: typeorm_constants_1.TYPEORM_MODULE_OPTIONS,
|
|
413
|
+
useFactory: async (optionsFactory) => await optionsFactory.createTypeOrmOptions(options.name),
|
|
414
|
+
inject
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
static createEntityManagerProvider(options) {
|
|
418
|
+
return {
|
|
419
|
+
provide: (0, typeorm_utils_1.getEntityManagerToken)(options),
|
|
420
|
+
useFactory: (dataSource) => dataSource.manager,
|
|
421
|
+
inject: [(0, typeorm_utils_1.getDataSourceToken)(options)]
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
static async createDataSourceFactory(options, dataSourceFactory) {
|
|
425
|
+
const dataSourceToken = (0, typeorm_utils_1.getDataSourceName)(options);
|
|
426
|
+
const createTypeormDataSource = dataSourceFactory ?? ((options2) => {
|
|
427
|
+
return typeorm_1.DataSource === void 0 ? (0, typeorm_1.createConnection)(options2) : new typeorm_1.DataSource(options2);
|
|
428
|
+
});
|
|
429
|
+
return await (0, rxjs_1.lastValueFrom)((0, rxjs_1.defer)(async () => {
|
|
430
|
+
let dataSource;
|
|
431
|
+
if (!options.autoLoadEntities) {
|
|
432
|
+
dataSource = await createTypeormDataSource(options);
|
|
433
|
+
} else {
|
|
434
|
+
let entities = options.entities;
|
|
435
|
+
if (Array.isArray(entities)) {
|
|
436
|
+
entities = entities.concat(entities_metadata_storage_1.EntitiesMetadataStorage.getEntitiesByDataSource(dataSourceToken));
|
|
437
|
+
} else {
|
|
438
|
+
entities = entities_metadata_storage_1.EntitiesMetadataStorage.getEntitiesByDataSource(dataSourceToken);
|
|
439
|
+
}
|
|
440
|
+
dataSource = await createTypeormDataSource({
|
|
441
|
+
...options,
|
|
442
|
+
entities
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
return dataSource.initialize && !dataSource.isInitialized && !options.manualInitialization ? dataSource.initialize() : dataSource;
|
|
446
|
+
}).pipe((0, typeorm_utils_1.handleRetry)(options.retryAttempts, options.retryDelay, dataSourceToken, options.verboseRetryLog, options.toRetry)));
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
exports2.TypeOrmCoreModule = TypeOrmCoreModule;
|
|
450
|
+
exports2.TypeOrmCoreModule = TypeOrmCoreModule = TypeOrmCoreModule_1 = __decorate([
|
|
451
|
+
(0, common_1.Global)(),
|
|
452
|
+
(0, common_1.Module)({}),
|
|
453
|
+
__param(0, (0, common_1.Inject)(typeorm_constants_1.TYPEORM_MODULE_OPTIONS)),
|
|
454
|
+
__metadata("design:paramtypes", [Object, core_1.ModuleRef])
|
|
455
|
+
], TypeOrmCoreModule);
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
// node_modules/@nestjs/typeorm/dist/typeorm.providers.js
|
|
460
|
+
var require_typeorm_providers = __commonJS({
|
|
461
|
+
"node_modules/@nestjs/typeorm/dist/typeorm.providers.js"(exports2) {
|
|
462
|
+
"use strict";
|
|
463
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
464
|
+
exports2.createTypeOrmProviders = createTypeOrmProviders;
|
|
465
|
+
var typeorm_1 = require("typeorm");
|
|
466
|
+
var typeorm_utils_1 = require_typeorm_utils();
|
|
467
|
+
function createTypeOrmProviders(entities, dataSource) {
|
|
468
|
+
return (entities || []).map((entity) => ({
|
|
469
|
+
provide: (0, typeorm_utils_1.getRepositoryToken)(entity, dataSource),
|
|
470
|
+
useFactory: (dataSource2) => {
|
|
471
|
+
const entityMetadata = dataSource2.entityMetadatas.find((meta) => meta.target === entity);
|
|
472
|
+
const isTreeEntity = typeof entityMetadata?.treeType !== "undefined";
|
|
473
|
+
return isTreeEntity ? dataSource2.getTreeRepository(entity) : dataSource2.options.type === "mongodb" ? dataSource2.getMongoRepository(entity) : dataSource2.getRepository(entity);
|
|
474
|
+
},
|
|
475
|
+
inject: [(0, typeorm_utils_1.getDataSourceToken)(dataSource)],
|
|
476
|
+
/**
|
|
477
|
+
* Extra property to workaround dynamic modules serialisation issue
|
|
478
|
+
* that occurs when "TypeOrm#forFeature()" method is called with the same number
|
|
479
|
+
* of arguments and all entities share the same class names.
|
|
480
|
+
*/
|
|
481
|
+
targetEntitySchema: (0, typeorm_1.getMetadataArgsStorage)().tables.find((item) => item.target === entity)
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
// node_modules/@nestjs/typeorm/dist/typeorm.module.js
|
|
488
|
+
var require_typeorm_module = __commonJS({
|
|
489
|
+
"node_modules/@nestjs/typeorm/dist/typeorm.module.js"(exports2) {
|
|
490
|
+
"use strict";
|
|
491
|
+
var __decorate = exports2 && exports2.__decorate || function(decorators, target, key, desc) {
|
|
492
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
493
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
494
|
+
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;
|
|
495
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
496
|
+
};
|
|
497
|
+
var TypeOrmModule_1;
|
|
498
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
499
|
+
exports2.TypeOrmModule = void 0;
|
|
500
|
+
var common_1 = require("@nestjs/common");
|
|
501
|
+
var entities_metadata_storage_1 = require_entities_metadata_storage();
|
|
502
|
+
var typeorm_core_module_1 = require_typeorm_core_module();
|
|
503
|
+
var typeorm_constants_1 = require_typeorm_constants();
|
|
504
|
+
var typeorm_providers_1 = require_typeorm_providers();
|
|
505
|
+
var TypeOrmModule2 = TypeOrmModule_1 = class TypeOrmModule {
|
|
506
|
+
static forRoot(options) {
|
|
507
|
+
return {
|
|
508
|
+
module: TypeOrmModule_1,
|
|
509
|
+
imports: [typeorm_core_module_1.TypeOrmCoreModule.forRoot(options)]
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
static forFeature(entities = [], dataSource = typeorm_constants_1.DEFAULT_DATA_SOURCE_NAME) {
|
|
513
|
+
const providers = (0, typeorm_providers_1.createTypeOrmProviders)(entities, dataSource);
|
|
514
|
+
entities_metadata_storage_1.EntitiesMetadataStorage.addEntitiesByDataSource(dataSource, [...entities]);
|
|
515
|
+
return {
|
|
516
|
+
module: TypeOrmModule_1,
|
|
517
|
+
providers,
|
|
518
|
+
exports: providers
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
static forRootAsync(options) {
|
|
522
|
+
return {
|
|
523
|
+
module: TypeOrmModule_1,
|
|
524
|
+
imports: [typeorm_core_module_1.TypeOrmCoreModule.forRootAsync(options)]
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
exports2.TypeOrmModule = TypeOrmModule2;
|
|
529
|
+
exports2.TypeOrmModule = TypeOrmModule2 = TypeOrmModule_1 = __decorate([
|
|
530
|
+
(0, common_1.Module)({})
|
|
531
|
+
], TypeOrmModule2);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
// node_modules/@nestjs/typeorm/dist/index.js
|
|
536
|
+
var require_dist = __commonJS({
|
|
537
|
+
"node_modules/@nestjs/typeorm/dist/index.js"(exports2) {
|
|
538
|
+
"use strict";
|
|
539
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
540
|
+
if (k2 === void 0) k2 = k;
|
|
541
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
542
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
543
|
+
desc = { enumerable: true, get: function() {
|
|
544
|
+
return m[k];
|
|
545
|
+
} };
|
|
546
|
+
}
|
|
547
|
+
Object.defineProperty(o, k2, desc);
|
|
548
|
+
}) : (function(o, m, k, k2) {
|
|
549
|
+
if (k2 === void 0) k2 = k;
|
|
550
|
+
o[k2] = m[k];
|
|
551
|
+
}));
|
|
552
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
553
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
554
|
+
};
|
|
555
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
556
|
+
__exportStar(require_common(), exports2);
|
|
557
|
+
__exportStar(require_interfaces(), exports2);
|
|
558
|
+
__exportStar(require_typeorm_module(), exports2);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
// node_modules/@nestjs/typeorm/index.js
|
|
563
|
+
var require_typeorm = __commonJS({
|
|
564
|
+
"node_modules/@nestjs/typeorm/index.js"(exports2) {
|
|
565
|
+
"use strict";
|
|
566
|
+
function __export2(m) {
|
|
567
|
+
for (var p in m) if (!exports2.hasOwnProperty(p)) exports2[p] = m[p];
|
|
568
|
+
}
|
|
569
|
+
exports2.__esModule = true;
|
|
570
|
+
__export2(require_dist());
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
|
|
38
574
|
// index.ts
|
|
39
575
|
var index_exports = {};
|
|
40
576
|
__export(index_exports, {
|
|
@@ -65,6 +601,8 @@ __export(index_exports, {
|
|
|
65
601
|
ImportDataDto: () => ImportDataDto,
|
|
66
602
|
ImportEntryBaseDto: () => ImportEntryBaseDto,
|
|
67
603
|
ImportEntryDto: () => ImportEntryDto,
|
|
604
|
+
InjectTransactionalEntityManager: () => InjectTransactionalEntityManager,
|
|
605
|
+
InjectTransactionalRepository: () => InjectTransactionalRepository,
|
|
68
606
|
Inner: () => Inner,
|
|
69
607
|
IntColumn: () => IntColumn,
|
|
70
608
|
InternalColumn: () => InternalColumn,
|
|
@@ -112,6 +650,8 @@ __export(index_exports, {
|
|
|
112
650
|
StringJsonColumn: () => StringJsonColumn,
|
|
113
651
|
TextColumn: () => TextColumn,
|
|
114
652
|
TimeBase: () => TimeBase,
|
|
653
|
+
TransactionalTypeOrmInterceptor: () => TransactionalTypeOrmInterceptor,
|
|
654
|
+
TransactionalTypeOrmModule: () => TransactionalTypeOrmModule,
|
|
115
655
|
UuidColumn: () => UuidColumn,
|
|
116
656
|
applyQueryMatchBoolean: () => applyQueryMatchBoolean,
|
|
117
657
|
applyQueryMatchBooleanMySQL: () => applyQueryMatchBooleanMySQL,
|
|
@@ -124,7 +664,11 @@ __export(index_exports, {
|
|
|
124
664
|
createQueryCondition: () => createQueryCondition,
|
|
125
665
|
createQueryOperator: () => createQueryOperator,
|
|
126
666
|
createQueryOperatorArrayify: () => createQueryOperatorArrayify,
|
|
127
|
-
createQueryWrap: () => createQueryWrap
|
|
667
|
+
createQueryWrap: () => createQueryWrap,
|
|
668
|
+
getTransactionalEntityManagerProvider: () => getTransactionalEntityManagerProvider,
|
|
669
|
+
getTransactionalEntityManagerToken: () => getTransactionalEntityManagerToken,
|
|
670
|
+
getTransactionalRepositoryProvider: () => getTransactionalRepositoryProvider,
|
|
671
|
+
getTransactionalRepositoryToken: () => getTransactionalRepositoryToken
|
|
128
672
|
});
|
|
129
673
|
module.exports = __toCommonJS(index_exports);
|
|
130
674
|
__reExport(index_exports, require("nesties"), module.exports);
|
|
@@ -1782,7 +2326,11 @@ var CrudBase = class {
|
|
|
1782
2326
|
const existingEnt = await repo.findOne({
|
|
1783
2327
|
where: { id: ent.id },
|
|
1784
2328
|
select: this.crudOptions.createOrUpdate ? void 0 : ["id", "deleteTime"],
|
|
1785
|
-
withDeleted: true
|
|
2329
|
+
withDeleted: true,
|
|
2330
|
+
lock: {
|
|
2331
|
+
mode: "pessimistic_write",
|
|
2332
|
+
tables: [repo.metadata.tableName]
|
|
2333
|
+
}
|
|
1786
2334
|
});
|
|
1787
2335
|
if (existingEnt) {
|
|
1788
2336
|
if (existingEnt.deleteTime) {
|
|
@@ -2106,29 +2654,33 @@ var CrudBase = class {
|
|
|
2106
2654
|
if (!await this.repo.exists({ where })) {
|
|
2107
2655
|
throw404();
|
|
2108
2656
|
}
|
|
2109
|
-
const
|
|
2110
|
-
if (!v || typeof v !== "object") return
|
|
2111
|
-
|
|
2112
|
-
|
|
2657
|
+
const isAtomicObject = (v) => {
|
|
2658
|
+
if (!v || typeof v !== "object") return true;
|
|
2659
|
+
if (v instanceof Date) return true;
|
|
2660
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(v)) return true;
|
|
2661
|
+
if (ArrayBuffer.isView(v) || v instanceof ArrayBuffer) return true;
|
|
2662
|
+
return false;
|
|
2113
2663
|
};
|
|
2114
|
-
const
|
|
2664
|
+
const cloneForSnapshot = (v) => {
|
|
2115
2665
|
if (v == null) return v;
|
|
2116
2666
|
if (typeof v !== "object") return v;
|
|
2117
2667
|
if (v instanceof Date) return new Date(v.getTime());
|
|
2118
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer(v))
|
|
2668
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(v))
|
|
2119
2669
|
return Buffer.from(v);
|
|
2120
|
-
|
|
2121
|
-
if (ArrayBuffer.isView(v)) {
|
|
2122
|
-
const ctor = v.constructor;
|
|
2123
|
-
return new ctor(v.slice?.() ?? v);
|
|
2124
|
-
}
|
|
2670
|
+
if (ArrayBuffer.isView(v)) return v.slice?.() ?? v;
|
|
2125
2671
|
if (v instanceof ArrayBuffer) return v.slice(0);
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2672
|
+
const sc = globalThis.structuredClone;
|
|
2673
|
+
if (typeof sc === "function") {
|
|
2674
|
+
try {
|
|
2675
|
+
return sc(v);
|
|
2676
|
+
} catch {
|
|
2677
|
+
}
|
|
2130
2678
|
}
|
|
2131
|
-
return v;
|
|
2679
|
+
if (Array.isArray(v)) return v.map(cloneForSnapshot);
|
|
2680
|
+
const out = {};
|
|
2681
|
+
for (const k of Object.keys(v))
|
|
2682
|
+
out[k] = cloneForSnapshot(v[k]);
|
|
2683
|
+
return out;
|
|
2132
2684
|
};
|
|
2133
2685
|
const deepEqual = (a, b) => {
|
|
2134
2686
|
if (a === b) return true;
|
|
@@ -2152,14 +2704,14 @@ var CrudBase = class {
|
|
|
2152
2704
|
for (let i = 0; i < ua.length; i++) if (ua[i] !== ub[i]) return false;
|
|
2153
2705
|
return true;
|
|
2154
2706
|
}
|
|
2155
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
2156
|
-
if (!Array.isArray(a) || !Array.isArray(b)) return false;
|
|
2157
|
-
if (a.length !== b.length) return false;
|
|
2158
|
-
for (let i = 0; i < a.length; i++)
|
|
2159
|
-
if (!deepEqual(a[i], b[i])) return false;
|
|
2160
|
-
return true;
|
|
2161
|
-
}
|
|
2162
2707
|
if (typeof a === "object" && typeof b === "object") {
|
|
2708
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
2709
|
+
if (!Array.isArray(a) || !Array.isArray(b)) return false;
|
|
2710
|
+
if (a.length !== b.length) return false;
|
|
2711
|
+
for (let i = 0; i < a.length; i++)
|
|
2712
|
+
if (!deepEqual(a[i], b[i])) return false;
|
|
2713
|
+
return true;
|
|
2714
|
+
}
|
|
2163
2715
|
const keys = /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
2164
2716
|
for (const k of keys) {
|
|
2165
2717
|
if (!deepEqual(a[k], b[k])) return false;
|
|
@@ -2181,11 +2733,8 @@ var CrudBase = class {
|
|
|
2181
2733
|
const snapshot = {};
|
|
2182
2734
|
const snapshotHasKey = {};
|
|
2183
2735
|
for (const key of columns) {
|
|
2184
|
-
snapshotHasKey[key] = Object.prototype.hasOwnProperty.call(
|
|
2185
|
-
|
|
2186
|
-
key
|
|
2187
|
-
);
|
|
2188
|
-
snapshot[key] = cloneAtomicOrJson(ent[key]);
|
|
2736
|
+
snapshotHasKey[key] = Object.prototype.hasOwnProperty.call(ent, key);
|
|
2737
|
+
snapshot[key] = cloneForSnapshot(ent[key]);
|
|
2189
2738
|
}
|
|
2190
2739
|
const flush = async () => {
|
|
2191
2740
|
const patch = {};
|
|
@@ -2204,7 +2753,7 @@ var CrudBase = class {
|
|
|
2204
2753
|
if (!deepEqual(before, current)) {
|
|
2205
2754
|
patch[key] = current;
|
|
2206
2755
|
snapshotHasKey[key] = true;
|
|
2207
|
-
snapshot[key] =
|
|
2756
|
+
snapshot[key] = cloneForSnapshot(current);
|
|
2208
2757
|
}
|
|
2209
2758
|
}
|
|
2210
2759
|
if (Object.keys(patch).length) {
|
|
@@ -2215,7 +2764,8 @@ var CrudBase = class {
|
|
|
2215
2764
|
await flush();
|
|
2216
2765
|
return result;
|
|
2217
2766
|
};
|
|
2218
|
-
const
|
|
2767
|
+
const hasActiveTx = !!this.repo.manager.queryRunner?.isTransactionActive;
|
|
2768
|
+
const res = await (options.repo ? op(options.repo) : hasActiveTx ? op(this.repo) : this.repo.manager.transaction(
|
|
2219
2769
|
(tdb) => op(tdb.getRepository(this.entityClass))
|
|
2220
2770
|
));
|
|
2221
2771
|
return res == null ? new import_nesties8.BlankReturnMessageDto(200, "success") : new import_nesties8.GenericReturnMessageDto(200, "success", res);
|
|
@@ -3151,6 +3701,190 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
|
3151
3701
|
}
|
|
3152
3702
|
}
|
|
3153
3703
|
);
|
|
3704
|
+
|
|
3705
|
+
// src/transactional-typeorm.module.ts
|
|
3706
|
+
var import_typeorm8 = __toESM(require_typeorm());
|
|
3707
|
+
var import_typeorm9 = require("typeorm");
|
|
3708
|
+
var import_common5 = require("@nestjs/common");
|
|
3709
|
+
var import_nesties12 = require("nesties");
|
|
3710
|
+
var import_core = require("@nestjs/core");
|
|
3711
|
+
|
|
3712
|
+
// src/utility/create-dynamic-fetcher-proxy.ts
|
|
3713
|
+
var createDynamicFetcherProxy = (initial, fetcher) => {
|
|
3714
|
+
return new Proxy(initial, {
|
|
3715
|
+
get(_target, prop, receiver) {
|
|
3716
|
+
const current = fetcher();
|
|
3717
|
+
const value = Reflect.get(current, prop, receiver);
|
|
3718
|
+
if (typeof value === "function") {
|
|
3719
|
+
return value.bind(current);
|
|
3720
|
+
}
|
|
3721
|
+
return value;
|
|
3722
|
+
},
|
|
3723
|
+
set(_target, prop, value, receiver) {
|
|
3724
|
+
const current = fetcher();
|
|
3725
|
+
return Reflect.set(current, prop, value, receiver);
|
|
3726
|
+
},
|
|
3727
|
+
has(_target, prop) {
|
|
3728
|
+
const current = fetcher();
|
|
3729
|
+
return Reflect.has(current, prop);
|
|
3730
|
+
},
|
|
3731
|
+
ownKeys(_target) {
|
|
3732
|
+
const current = fetcher();
|
|
3733
|
+
return Reflect.ownKeys(current);
|
|
3734
|
+
},
|
|
3735
|
+
getOwnPropertyDescriptor(_target, prop) {
|
|
3736
|
+
const current = fetcher();
|
|
3737
|
+
return Reflect.getOwnPropertyDescriptor(current, prop);
|
|
3738
|
+
},
|
|
3739
|
+
defineProperty(_target, prop, descriptor) {
|
|
3740
|
+
const current = fetcher();
|
|
3741
|
+
return Reflect.defineProperty(current, prop, descriptor);
|
|
3742
|
+
},
|
|
3743
|
+
deleteProperty(_target, prop) {
|
|
3744
|
+
const current = fetcher();
|
|
3745
|
+
return Reflect.deleteProperty(current, prop);
|
|
3746
|
+
}
|
|
3747
|
+
});
|
|
3748
|
+
};
|
|
3749
|
+
|
|
3750
|
+
// src/utility/create-inject-from-token-factory.ts
|
|
3751
|
+
var import_common4 = require("@nestjs/common");
|
|
3752
|
+
var createInjectFromTokenFactory = (factory) => (...params) => (0, import_common4.Inject)(factory(...params));
|
|
3753
|
+
|
|
3754
|
+
// src/transactional-typeorm.module.ts
|
|
3755
|
+
var import_rxjs = require("rxjs");
|
|
3756
|
+
var requestWeakMap = /* @__PURE__ */ new WeakMap();
|
|
3757
|
+
var normalizeDataSourceToken = (token) => typeof token === "string" ? token : token.name || token.toString();
|
|
3758
|
+
var TransactionalTypeOrmInterceptor = (dataSource) => {
|
|
3759
|
+
const token = (0, import_typeorm8.getEntityManagerToken)(dataSource);
|
|
3760
|
+
const interceptorClass = class SpecificTransactionalTypeOrmInterceptor {
|
|
3761
|
+
constructor(entityManager) {
|
|
3762
|
+
this.entityManager = entityManager;
|
|
3763
|
+
}
|
|
3764
|
+
intercept(context, next) {
|
|
3765
|
+
const request = context.switchToHttp().getRequest();
|
|
3766
|
+
return new import_rxjs.Observable((observer) => {
|
|
3767
|
+
let innerSub = null;
|
|
3768
|
+
let finished = false;
|
|
3769
|
+
let abort;
|
|
3770
|
+
const aborted = new Promise((_6, reject) => {
|
|
3771
|
+
abort = reject;
|
|
3772
|
+
});
|
|
3773
|
+
const run = this.entityManager.transaction(async (txEm) => {
|
|
3774
|
+
requestWeakMap.set(request, txEm);
|
|
3775
|
+
const completion = new Promise((resolve, reject) => {
|
|
3776
|
+
innerSub = next.handle().subscribe({
|
|
3777
|
+
next: (v) => observer.next(v),
|
|
3778
|
+
error: (err) => {
|
|
3779
|
+
finished = true;
|
|
3780
|
+
observer.error(err);
|
|
3781
|
+
reject(err);
|
|
3782
|
+
},
|
|
3783
|
+
complete: () => {
|
|
3784
|
+
finished = true;
|
|
3785
|
+
observer.complete();
|
|
3786
|
+
resolve();
|
|
3787
|
+
}
|
|
3788
|
+
});
|
|
3789
|
+
});
|
|
3790
|
+
await Promise.race([completion, aborted]);
|
|
3791
|
+
}).finally(() => {
|
|
3792
|
+
requestWeakMap.delete(request);
|
|
3793
|
+
}).catch((err) => {
|
|
3794
|
+
if (!finished) observer.error(err);
|
|
3795
|
+
});
|
|
3796
|
+
return () => {
|
|
3797
|
+
try {
|
|
3798
|
+
innerSub?.unsubscribe();
|
|
3799
|
+
} finally {
|
|
3800
|
+
if (!finished) {
|
|
3801
|
+
abort(new Error("Request aborted / subscription unsubscribed"));
|
|
3802
|
+
}
|
|
3803
|
+
}
|
|
3804
|
+
};
|
|
3805
|
+
});
|
|
3806
|
+
}
|
|
3807
|
+
};
|
|
3808
|
+
Object.defineProperty(interceptorClass, "name", {
|
|
3809
|
+
value: `TransactionalTypeOrmInterceptor_${normalizeDataSourceToken(token)}`
|
|
3810
|
+
});
|
|
3811
|
+
Reflect.defineMetadata(
|
|
3812
|
+
"design:paramtypes",
|
|
3813
|
+
[import_typeorm9.EntityManager],
|
|
3814
|
+
interceptorClass
|
|
3815
|
+
);
|
|
3816
|
+
(0, import_common5.Inject)(token)(interceptorClass.prototype, void 0, 0);
|
|
3817
|
+
(0, import_common5.Injectable)()(interceptorClass);
|
|
3818
|
+
return interceptorClass;
|
|
3819
|
+
};
|
|
3820
|
+
var getTransactionalEntityManagerToken = (dataSource) => `Transactional${normalizeDataSourceToken((0, import_typeorm8.getEntityManagerToken)(dataSource))}`;
|
|
3821
|
+
var getTransactionalEntityManagerProvider = (dataSource) => (0, import_nesties12.createProvider)(
|
|
3822
|
+
{
|
|
3823
|
+
provide: getTransactionalEntityManagerToken(dataSource),
|
|
3824
|
+
inject: [(0, import_typeorm8.getEntityManagerToken)(dataSource), import_core.REQUEST],
|
|
3825
|
+
scope: import_common5.Scope.REQUEST
|
|
3826
|
+
},
|
|
3827
|
+
(entityManager, request) => {
|
|
3828
|
+
if (requestWeakMap.has(request)) {
|
|
3829
|
+
return requestWeakMap.get(request);
|
|
3830
|
+
}
|
|
3831
|
+
return createDynamicFetcherProxy(
|
|
3832
|
+
entityManager,
|
|
3833
|
+
() => requestWeakMap.get(request) || entityManager
|
|
3834
|
+
);
|
|
3835
|
+
}
|
|
3836
|
+
);
|
|
3837
|
+
var InjectTransactionalEntityManager = createInjectFromTokenFactory(
|
|
3838
|
+
getTransactionalEntityManagerToken
|
|
3839
|
+
);
|
|
3840
|
+
var getTransactionalRepositoryToken = (entity, dataSource) => `Transactional${normalizeDataSourceToken(
|
|
3841
|
+
(0, import_typeorm8.getEntityManagerToken)(dataSource)
|
|
3842
|
+
)}Repository_${entity.name || entity.toString()}`;
|
|
3843
|
+
var getTransactionalRepositoryProvider = (entity, dataSource) => (0, import_nesties12.createProvider)(
|
|
3844
|
+
{
|
|
3845
|
+
provide: getTransactionalRepositoryToken(entity, dataSource),
|
|
3846
|
+
inject: [(0, import_typeorm8.getEntityManagerToken)(dataSource), import_core.REQUEST],
|
|
3847
|
+
scope: import_common5.Scope.REQUEST
|
|
3848
|
+
},
|
|
3849
|
+
(entityManager, req) => {
|
|
3850
|
+
if (requestWeakMap.has(req)) {
|
|
3851
|
+
const transactionalEntityManager = requestWeakMap.get(req);
|
|
3852
|
+
return transactionalEntityManager.getRepository(entity);
|
|
3853
|
+
}
|
|
3854
|
+
return createDynamicFetcherProxy(
|
|
3855
|
+
entityManager.getRepository(entity),
|
|
3856
|
+
() => {
|
|
3857
|
+
const transactionalEntityManager = requestWeakMap.get(req) || entityManager;
|
|
3858
|
+
return transactionalEntityManager.getRepository(entity);
|
|
3859
|
+
}
|
|
3860
|
+
);
|
|
3861
|
+
}
|
|
3862
|
+
);
|
|
3863
|
+
var InjectTransactionalRepository = createInjectFromTokenFactory(
|
|
3864
|
+
getTransactionalRepositoryToken
|
|
3865
|
+
);
|
|
3866
|
+
var TransactionalTypeOrmModule = class {
|
|
3867
|
+
static forFeature(entities, dataSource) {
|
|
3868
|
+
const entityArray = Array.isArray(entities) ? entities : [entities];
|
|
3869
|
+
const providers = [
|
|
3870
|
+
getTransactionalEntityManagerProvider(dataSource),
|
|
3871
|
+
...entityArray.map(
|
|
3872
|
+
(entity) => getTransactionalRepositoryProvider(entity, dataSource)
|
|
3873
|
+
)
|
|
3874
|
+
];
|
|
3875
|
+
const moduleImports = entityArray.length ? [import_typeorm8.TypeOrmModule.forFeature(entityArray, dataSource)] : [];
|
|
3876
|
+
const moduleExports = [...providers, ...moduleImports];
|
|
3877
|
+
return {
|
|
3878
|
+
module: TransactionalTypeOrmModule,
|
|
3879
|
+
imports: moduleImports,
|
|
3880
|
+
providers,
|
|
3881
|
+
exports: moduleExports
|
|
3882
|
+
};
|
|
3883
|
+
}
|
|
3884
|
+
};
|
|
3885
|
+
TransactionalTypeOrmModule = __decorateClass([
|
|
3886
|
+
(0, import_common5.Module)({})
|
|
3887
|
+
], TransactionalTypeOrmModule);
|
|
3154
3888
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3155
3889
|
0 && (module.exports = {
|
|
3156
3890
|
BindingColumn,
|
|
@@ -3180,6 +3914,8 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
|
3180
3914
|
ImportDataDto,
|
|
3181
3915
|
ImportEntryBaseDto,
|
|
3182
3916
|
ImportEntryDto,
|
|
3917
|
+
InjectTransactionalEntityManager,
|
|
3918
|
+
InjectTransactionalRepository,
|
|
3183
3919
|
Inner,
|
|
3184
3920
|
IntColumn,
|
|
3185
3921
|
InternalColumn,
|
|
@@ -3227,6 +3963,8 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
|
3227
3963
|
StringJsonColumn,
|
|
3228
3964
|
TextColumn,
|
|
3229
3965
|
TimeBase,
|
|
3966
|
+
TransactionalTypeOrmInterceptor,
|
|
3967
|
+
TransactionalTypeOrmModule,
|
|
3230
3968
|
UuidColumn,
|
|
3231
3969
|
applyQueryMatchBoolean,
|
|
3232
3970
|
applyQueryMatchBooleanMySQL,
|
|
@@ -3240,6 +3978,10 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
|
|
|
3240
3978
|
createQueryOperator,
|
|
3241
3979
|
createQueryOperatorArrayify,
|
|
3242
3980
|
createQueryWrap,
|
|
3981
|
+
getTransactionalEntityManagerProvider,
|
|
3982
|
+
getTransactionalEntityManagerToken,
|
|
3983
|
+
getTransactionalRepositoryProvider,
|
|
3984
|
+
getTransactionalRepositoryToken,
|
|
3243
3985
|
...require("nesties")
|
|
3244
3986
|
});
|
|
3245
3987
|
//# sourceMappingURL=index.cjs.map
|