@artenc/nest-orm 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -6
- package/dist/decorators/binary-uuid-column.js +25 -22
- package/dist/decorators/binary-uuid-column.js.map +1 -1
- package/dist/entities/abstract-orm.entity.js +13 -17
- package/dist/entities/abstract-orm.entity.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.js +6 -14
- package/dist/index.js.map +1 -1
- package/dist/lib/constructor.js +1 -2
- package/dist/lib/transaction-context.js +2 -5
- package/dist/lib/transaction-context.js.map +1 -1
- package/dist/lib/utc-data-source.d.ts +12 -0
- package/dist/lib/utc-data-source.js +51 -0
- package/dist/lib/utc-data-source.js.map +1 -0
- package/dist/orm.module.d.ts +30 -0
- package/dist/orm.module.js +56 -11
- package/dist/orm.module.js.map +1 -1
- package/dist/services/abstract-orm.service.d.ts +3 -4
- package/dist/services/abstract-orm.service.js +7 -10
- package/dist/services/abstract-orm.service.js.map +1 -1
- package/dist/services/transaction.service.js +9 -12
- package/dist/services/transaction.service.js.map +1 -1
- package/dist/utils/generated-column.util.d.ts +1 -1
- package/dist/utils/generated-column.util.js +6 -11
- package/dist/utils/generated-column.util.js.map +1 -1
- package/package.json +35 -44
package/README.md
CHANGED
|
@@ -17,22 +17,47 @@ npm install @artenc/nest-orm
|
|
|
17
17
|
|
|
18
18
|
`@nestjs/common`, `@nestjs/typeorm`, and `typeorm` are peer dependencies — install them in your app if you haven't already (any NestJS + TypeORM project already has them).
|
|
19
19
|
|
|
20
|
+
It needs NestJS 12, `@nestjs/typeorm` 12 and TypeORM 1.x. The package is ESM only, as NestJS 12 is: a CommonJS application loads it through `require(esm)`, which needs Node.js 20.19+, 22.13+ or 24.11+, as TypeORM 1.x does.
|
|
21
|
+
|
|
20
22
|
## Usage
|
|
21
23
|
|
|
22
24
|
### `OrmModule`
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
The application imports `OrmModule.forRoot()` or `OrmModule.forRootAsync()` once. They take the same options as `TypeOrmModule.forRoot()`/`forRootAsync()` and set up the TypeORM connection, so the application doesn't import `TypeOrmModule.forRoot*()` itself:
|
|
25
27
|
|
|
26
28
|
```ts
|
|
27
29
|
import { Module } from '@nestjs/common'
|
|
30
|
+
import { ConfigModule, ConfigService } from '@nestjs/config'
|
|
28
31
|
import { OrmModule } from '@artenc/nest-orm'
|
|
29
32
|
|
|
30
33
|
@Module({
|
|
31
|
-
imports: [
|
|
34
|
+
imports: [
|
|
35
|
+
OrmModule.forRootAsync({
|
|
36
|
+
imports: [ConfigModule],
|
|
37
|
+
inject: [ConfigService],
|
|
38
|
+
useFactory: (configService: ConfigService) => ({
|
|
39
|
+
type: 'mysql',
|
|
40
|
+
host: configService.getOrThrow<string>('db.host'),
|
|
41
|
+
// ...
|
|
42
|
+
autoLoadEntities: true,
|
|
43
|
+
}),
|
|
44
|
+
utc: true,
|
|
45
|
+
}),
|
|
46
|
+
],
|
|
32
47
|
})
|
|
33
48
|
export class AppModule {}
|
|
34
49
|
```
|
|
35
50
|
|
|
51
|
+
Feature modules and libraries that need `TransactionService` import `OrmModule` itself, without options. `OrmModule.forRoot*()` re-exports that same module, so the application and all libraries share one `TransactionService`.
|
|
52
|
+
|
|
53
|
+
With `utc: true`, the connection uses a [`UtcDataSource`](#utcdatasource). `utc` can't be combined with a custom `dataSourceFactory`.
|
|
54
|
+
|
|
55
|
+
### `UtcDataSource`
|
|
56
|
+
|
|
57
|
+
A `DataSource` that stores and reads dates as UTC (`timezone: 'Z'`), and fails to initialize unless the database server runs in UTC too. The server fills `DEFAULT CURRENT_TIMESTAMP` columns such as `@CreateDateColumn()` in its own time zone, so the server and the driver must agree; otherwise those dates are off by the server's offset. Configure the server with `default-time-zone = '+00:00'`.
|
|
58
|
+
|
|
59
|
+
Supports MySQL and MariaDB; other databases are refused. `OrmModule.forRootAsync({ utc: true })` uses it for the application, and the [DataSource file](#datasource-file-example) can use it for TypeORM's CLI.
|
|
60
|
+
|
|
36
61
|
### `AbstractOrmEntity`
|
|
37
62
|
|
|
38
63
|
An entity loaded or created through `AbstractOrmService` doesn't know, from the caller's side, whether it came from its repository or from an active `TransactionService` transaction — it's just an entity. `AbstractOrmEntity` is what makes that transparent: every entity gets a `save()` method that checks, at the moment it's called, whether a transaction is currently active and writes through it if so — joining whatever transaction is running *then*, regardless of whether one was active when the entity was originally loaded or created. If nothing is active at that moment, it falls back to a plain write through the entity's repository instead. Either way, there's no `EntityManager` to pass around by hand.
|
|
@@ -144,6 +169,16 @@ export class UserModule {}
|
|
|
144
169
|
|
|
145
170
|
Every method takes an optional trailing `enforceEntityManager` argument to run against a specific `EntityManager` instead of the entity's default repository — useful outside of `TransactionService` (e.g. a manually managed `QueryRunner`).
|
|
146
171
|
|
|
172
|
+
A `null` or `undefined` in a condition throws, as TypeORM 1.x refuses them in `find`, `findOne`, `count`, `exists`, `update` and `remove`, rather than dropping the condition: `remove({ id: undefined })` fails instead of deleting every row. Match a `NULL` with `IsNull()`:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
import { IsNull } from 'typeorm'
|
|
176
|
+
|
|
177
|
+
await userOrmService.find({ where: { deletedAt: IsNull() } })
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
A query builder's `where()` isn't checked: `{ deletedAt: null }` there compares with `= NULL`, which matches nothing, so use `IsNull()` there too. TypeORM's `invalidWhereValuesBehavior` option, given to `OrmModule.forRoot*()`, changes how conditions are checked.
|
|
181
|
+
|
|
147
182
|
### `TransactionService`
|
|
148
183
|
|
|
149
184
|
Wraps a block of work in a real database transaction and makes the transaction's `EntityManager` ambiently available (via `AsyncLocalStorage`) to every `AbstractOrmService`/`AbstractOrmEntity` call made inside it — no need to thread an `EntityManager` through every method call by hand:
|
|
@@ -200,7 +235,7 @@ Typical TypeORM CLI scripts for a project consuming this library:
|
|
|
200
235
|
|
|
201
236
|
## DataSource file example
|
|
202
237
|
|
|
203
|
-
The `-d dist/data-source.js` flag in the scripts above points TypeORM's CLI at this file: a plain, standalone `DataSource` instance the CLI can import and connect with directly. It's separate from the `DataSource` your NestJS app builds via `
|
|
238
|
+
The `-d dist/data-source.js` flag in the scripts above points TypeORM's CLI at this file: a plain, standalone `DataSource` instance the CLI can import and connect with directly. It's separate from the `DataSource` your NestJS app builds via `OrmModule.forRoot(...)` because the CLI runs as its own process outside Nest's DI container — `migration:generate`/`migration:run`/`migration:revert`/`query` have no other way to reach the same database connection your app uses at runtime.
|
|
204
239
|
|
|
205
240
|
orm-imports.ts — glob paths TypeORM expands at runtime to every compiled entity/migration file, so `data-source.ts` doesn't need to list them by hand:
|
|
206
241
|
```ts
|
|
@@ -210,13 +245,13 @@ export const entities = [path.join(__dirname, 'entities/*')]
|
|
|
210
245
|
export const migrations = [path.join(__dirname, 'migrations/*')]
|
|
211
246
|
```
|
|
212
247
|
|
|
213
|
-
data-source.ts:
|
|
248
|
+
data-source.ts (with `utc: true` in the application, use `UtcDataSource` here too, so migrations run with the same time zone handling):
|
|
214
249
|
```ts
|
|
215
250
|
import 'dotenv/config'
|
|
216
|
-
import {
|
|
251
|
+
import { UtcDataSource } from '@artenc/nest-orm'
|
|
217
252
|
import { entities, migrations } from './orm-imports'
|
|
218
253
|
|
|
219
|
-
export default new
|
|
254
|
+
export default new UtcDataSource({
|
|
220
255
|
type: 'mysql',
|
|
221
256
|
host: process.env.DB_HOST,
|
|
222
257
|
port: Number(process.env.DB_PORT),
|
|
@@ -228,6 +263,12 @@ export default new DataSource({
|
|
|
228
263
|
})
|
|
229
264
|
```
|
|
230
265
|
|
|
266
|
+
## Development
|
|
267
|
+
|
|
268
|
+
The tests include ones against a real MySQL, which needs nothing set up beyond Docker: `npm test` runs a throwaway MySQL 8.4 container, in UTC, on port 3307, and removes it afterwards. To keep one running across test runs, start it with `npm run test:mysql:start`, and remove it with `npm run test:mysql:stop`.
|
|
269
|
+
|
|
270
|
+
The settings are in `.env.example`; a `.env` overrides any of them. With `DB_CONTAINER=false`, the tests use the MySQL at `DB_HOST` instead, which must run in UTC; they drop and create its tables.
|
|
271
|
+
|
|
231
272
|
## License
|
|
232
273
|
|
|
233
274
|
MIT
|
|
@@ -1,59 +1,62 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const typeorm_1 = require("typeorm");
|
|
7
|
-
const uuid_1 = require("uuid");
|
|
8
|
-
const generated_column_util_1 = require("../utils/generated-column.util");
|
|
9
|
-
function BinaryUuidColumn(options) {
|
|
1
|
+
import { randomUUID as randomUUIDv4 } from 'crypto';
|
|
2
|
+
import { Column } from 'typeorm';
|
|
3
|
+
import { v7 as randomUUIDv7 } from 'uuid';
|
|
4
|
+
import { addGeneratedColumn } from '../utils/generated-column.util.js';
|
|
5
|
+
export function BinaryUuidColumn(options) {
|
|
10
6
|
const { generated = false, version = 'v7', ...rest } = options ?? {};
|
|
11
7
|
return (target, propertyKey) => {
|
|
12
8
|
// Always registered (even when generated is false) so that a subclass redeclaring this
|
|
13
9
|
// column without `generated: true` can explicitly opt out of an ancestor's auto-generation,
|
|
14
10
|
// rather than silently inheriting it because the subclass "said nothing" about the property.
|
|
15
|
-
|
|
11
|
+
addGeneratedColumn(target.constructor, {
|
|
16
12
|
propertyKey: String(propertyKey),
|
|
17
13
|
generator: generated
|
|
18
14
|
? () => {
|
|
19
15
|
switch (version) {
|
|
20
16
|
case 'v4':
|
|
21
|
-
return (
|
|
17
|
+
return randomUUIDv4();
|
|
22
18
|
case 'v7':
|
|
23
|
-
return (
|
|
19
|
+
return randomUUIDv7();
|
|
24
20
|
default:
|
|
25
21
|
throw new Error(`Unsupported BinaryUuidColumn version: ${String(version)}`);
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
24
|
: null,
|
|
29
25
|
});
|
|
30
|
-
|
|
26
|
+
Column({
|
|
31
27
|
...rest,
|
|
32
28
|
type: 'binary',
|
|
33
29
|
length: 16,
|
|
34
|
-
transformer:
|
|
30
|
+
transformer: binaryUuidTransformer,
|
|
35
31
|
})(target, propertyKey);
|
|
36
32
|
};
|
|
37
33
|
}
|
|
38
|
-
|
|
34
|
+
export const binaryUuidTransformer = {
|
|
39
35
|
to(value) {
|
|
40
36
|
if (value == null) {
|
|
41
37
|
return null;
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
if (!/^[0-9a-f]{32}$/.test(compact)) {
|
|
45
|
-
throw new Error(`Invalid UUID: ${value}`);
|
|
46
|
-
}
|
|
47
|
-
return Buffer.from(compact, 'hex');
|
|
39
|
+
return Buffer.from(compactUuid(value), 'hex');
|
|
48
40
|
},
|
|
49
41
|
from(value) {
|
|
50
42
|
if (value == null) {
|
|
51
43
|
return null;
|
|
52
44
|
}
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
// TypeORM also passes it the UUID an insert saved, still a string, as it reads back the values the database
|
|
46
|
+
// filled in, e.g. a CreateDateColumn's
|
|
47
|
+
if (typeof value === 'string') {
|
|
48
|
+
return formatUuid(compactUuid(value));
|
|
49
|
+
}
|
|
50
|
+
return formatUuid(value.toString('hex'));
|
|
55
51
|
},
|
|
56
52
|
};
|
|
53
|
+
function compactUuid(value) {
|
|
54
|
+
const compact = value.toLowerCase().replace(/-/g, '');
|
|
55
|
+
if (!/^[0-9a-f]{32}$/.test(compact)) {
|
|
56
|
+
throw new Error(`Invalid UUID: ${value}`);
|
|
57
|
+
}
|
|
58
|
+
return compact;
|
|
59
|
+
}
|
|
57
60
|
function formatUuid(hex) {
|
|
58
61
|
return [hex.slice(0, 8), hex.slice(8, 12), hex.slice(12, 16), hex.slice(16, 20), hex.slice(20, 32)].join('-');
|
|
59
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binary-uuid-column.js","sourceRoot":"","sources":["../../src/decorators/binary-uuid-column.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"binary-uuid-column.js","sourceRoot":"","sources":["../../src/decorators/binary-uuid-column.ts"],"names":[],"m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var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,16 +7,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const transaction_context_1 = require("../lib/transaction-context");
|
|
16
|
-
const generated_column_util_1 = require("../utils/generated-column.util");
|
|
10
|
+
import { Exclude } from 'class-transformer';
|
|
11
|
+
import { BeforeInsert, EntityManager, Repository } from 'typeorm';
|
|
12
|
+
import { txStorage } from '../lib/transaction-context.js';
|
|
13
|
+
import { getGeneratedColumns } from '../utils/generated-column.util.js';
|
|
17
14
|
// Blocked unconditionally in apply(), regardless of fillable(), to prevent prototype pollution
|
|
18
15
|
// if a fillable() override ever lists one of these by mistake.
|
|
19
16
|
const UNSAFE_APPLY_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
20
|
-
class AbstractOrmEntity {
|
|
17
|
+
export class AbstractOrmEntity {
|
|
21
18
|
repository;
|
|
22
19
|
entityManager;
|
|
23
20
|
setRepository(repository) {
|
|
@@ -63,12 +60,12 @@ class AbstractOrmEntity {
|
|
|
63
60
|
throw new Error('No repository or entity manager available');
|
|
64
61
|
}
|
|
65
62
|
get contextEntityManager() {
|
|
66
|
-
const store =
|
|
63
|
+
const store = txStorage.getStore();
|
|
67
64
|
if (!store) {
|
|
68
65
|
return undefined;
|
|
69
66
|
}
|
|
70
67
|
if (this.repository) {
|
|
71
|
-
return store.get(this.repository.manager.
|
|
68
|
+
return store.get(this.repository.manager.dataSource);
|
|
72
69
|
}
|
|
73
70
|
// No pinned repository to key the lookup by — e.g. a plain `new Entity()` never
|
|
74
71
|
// routed through AbstractOrmService, or one loaded via a raw EntityManager/Repository
|
|
@@ -84,7 +81,7 @@ class AbstractOrmEntity {
|
|
|
84
81
|
return store.values().next().value;
|
|
85
82
|
}
|
|
86
83
|
generateBinaryUuidColumns() {
|
|
87
|
-
const generatedColumns =
|
|
84
|
+
const generatedColumns = getGeneratedColumns(this.constructor);
|
|
88
85
|
for (const column of generatedColumns) {
|
|
89
86
|
if (!column.generator) {
|
|
90
87
|
continue;
|
|
@@ -97,17 +94,16 @@ class AbstractOrmEntity {
|
|
|
97
94
|
}
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
|
-
exports.AbstractOrmEntity = AbstractOrmEntity;
|
|
101
97
|
__decorate([
|
|
102
|
-
|
|
103
|
-
__metadata("design:type",
|
|
98
|
+
Exclude(),
|
|
99
|
+
__metadata("design:type", Repository)
|
|
104
100
|
], AbstractOrmEntity.prototype, "repository", void 0);
|
|
105
101
|
__decorate([
|
|
106
|
-
|
|
107
|
-
__metadata("design:type",
|
|
102
|
+
Exclude(),
|
|
103
|
+
__metadata("design:type", EntityManager)
|
|
108
104
|
], AbstractOrmEntity.prototype, "entityManager", void 0);
|
|
109
105
|
__decorate([
|
|
110
|
-
|
|
106
|
+
BeforeInsert(),
|
|
111
107
|
__metadata("design:type", Function),
|
|
112
108
|
__metadata("design:paramtypes", []),
|
|
113
109
|
__metadata("design:returntype", void 0)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-orm.entity.js","sourceRoot":"","sources":["../../src/entities/abstract-orm.entity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"abstract-orm.entity.js","sourceRoot":"","sources":["../../src/entities/abstract-orm.entity.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC3C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;A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AAS,EAAE,CAAC;gBACpB,SAAQ;YACZ,CAAC;YACD,MAAM,YAAY,GAAI,IAAgC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YAC1E,IAAI,YAAY,KAAK,IAAI,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;gBACtD,CAAC;gBAAC,IAAgC,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;YAC/E,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AA1FW;IADP,OAAO,EAAE;8BACW,UAAU;qDAAM;AAE7B;IADP,OAAO,EAAE;8BACc,aAAa;wDAAA;AA2E3B;IADT,YAAY,EAAE;;;;kEAad"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export { BinaryUuidColumn,
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
1
|
+
export { BinaryUuidColumn, binaryUuidTransformer } from './decorators/binary-uuid-column.js';
|
|
2
|
+
export type { BinaryUuidOptions, BinaryUuidVersion } from './decorators/binary-uuid-column.js';
|
|
3
|
+
export { AbstractOrmEntity } from './entities/abstract-orm.entity.js';
|
|
4
|
+
export { AbstractOrmService } from './services/abstract-orm.service.js';
|
|
5
|
+
export type { IOrmService } from './services/abstract-orm.service.js';
|
|
6
|
+
export { TransactionService } from './services/transaction.service.js';
|
|
7
|
+
export { UtcDataSource } from './lib/utc-data-source.js';
|
|
8
|
+
export { OrmModule } from './orm.module.js';
|
|
9
|
+
export type { OrmModuleAsyncOptions, OrmModuleOptions, OrmUtcOptions } from './orm.module.js';
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var abstract_orm_entity_1 = require("./entities/abstract-orm.entity");
|
|
8
|
-
Object.defineProperty(exports, "AbstractOrmEntity", { enumerable: true, get: function () { return abstract_orm_entity_1.AbstractOrmEntity; } });
|
|
9
|
-
var abstract_orm_service_1 = require("./services/abstract-orm.service");
|
|
10
|
-
Object.defineProperty(exports, "AbstractOrmService", { enumerable: true, get: function () { return abstract_orm_service_1.AbstractOrmService; } });
|
|
11
|
-
var transaction_service_1 = require("./services/transaction.service");
|
|
12
|
-
Object.defineProperty(exports, "TransactionService", { enumerable: true, get: function () { return transaction_service_1.TransactionService; } });
|
|
13
|
-
var orm_module_1 = require("./orm.module");
|
|
14
|
-
Object.defineProperty(exports, "OrmModule", { enumerable: true, get: function () { return orm_module_1.OrmModule; } });
|
|
1
|
+
export { BinaryUuidColumn, binaryUuidTransformer } from './decorators/binary-uuid-column.js';
|
|
2
|
+
export { AbstractOrmEntity } from './entities/abstract-orm.entity.js';
|
|
3
|
+
export { AbstractOrmService } from './services/abstract-orm.service.js';
|
|
4
|
+
export { TransactionService } from './services/transaction.service.js';
|
|
5
|
+
export { UtcDataSource } from './lib/utc-data-source.js';
|
|
6
|
+
export { OrmModule } from './orm.module.js';
|
|
15
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAG5F,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AAErE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAEtE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA"}
|
package/dist/lib/constructor.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.txStorage = void 0;
|
|
4
|
-
const node_async_hooks_1 = require("node:async_hooks");
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
2
|
// Keyed by DataSource so a multi-connection app can have more than one ambient transaction
|
|
6
3
|
// active at once (e.g. one DataSource's transaction nested inside another's) without one
|
|
7
4
|
// overwriting or being mistaken for the other's.
|
|
8
|
-
|
|
5
|
+
export const txStorage = new AsyncLocalStorage();
|
|
9
6
|
//# sourceMappingURL=transaction-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-context.js","sourceRoot":"","sources":["../../src/lib/transaction-context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction-context.js","sourceRoot":"","sources":["../../src/lib/transaction-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AAGpD,2FAA2F;AAC3F,yFAAyF;AACzF,iDAAiD;AACjD,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,iBAAiB,EAAkC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DataSource, DataSourceOptions } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* A data source that stores and reads dates as UTC, and fails to initialize unless the database server runs in UTC
|
|
4
|
+
* too: the server fills `DEFAULT CURRENT_TIMESTAMP` columns in its own time zone, so both must agree.
|
|
5
|
+
* Databases without UTC handling here are refused.
|
|
6
|
+
*/
|
|
7
|
+
export declare class UtcDataSource extends DataSource {
|
|
8
|
+
constructor(options: DataSourceOptions);
|
|
9
|
+
initialize(): Promise<this>;
|
|
10
|
+
private static utcOptions;
|
|
11
|
+
private assertUtcServer;
|
|
12
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { DataSource } from 'typeorm';
|
|
2
|
+
/**
|
|
3
|
+
* A data source that stores and reads dates as UTC, and fails to initialize unless the database server runs in UTC
|
|
4
|
+
* too: the server fills `DEFAULT CURRENT_TIMESTAMP` columns in its own time zone, so both must agree.
|
|
5
|
+
* Databases without UTC handling here are refused.
|
|
6
|
+
*/
|
|
7
|
+
export class UtcDataSource extends DataSource {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(UtcDataSource.utcOptions(options));
|
|
10
|
+
}
|
|
11
|
+
async initialize() {
|
|
12
|
+
await super.initialize();
|
|
13
|
+
try {
|
|
14
|
+
await this.assertUtcServer();
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
// Closed, so a refused server keeps no connections open, e.g. as TypeOrmModule retries with a new one; the
|
|
18
|
+
// refusal is what's thrown
|
|
19
|
+
if (this.isInitialized) {
|
|
20
|
+
await this.destroy().catch(() => undefined);
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
static utcOptions(options) {
|
|
27
|
+
switch (options.type) {
|
|
28
|
+
case 'mysql':
|
|
29
|
+
case 'mariadb':
|
|
30
|
+
return { ...options, timezone: 'Z' };
|
|
31
|
+
default:
|
|
32
|
+
throw new Error(`UtcDataSource doesn't support ${options.type}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async assertUtcServer() {
|
|
36
|
+
switch (this.options.type) {
|
|
37
|
+
case 'mysql':
|
|
38
|
+
case 'mariadb': {
|
|
39
|
+
const [{ offsetSeconds }] = await this.query('SELECT TIMESTAMPDIFF(SECOND, UTC_TIMESTAMP(), NOW()) AS offsetSeconds');
|
|
40
|
+
const offsetMinutes = Math.round(Number(offsetSeconds) / 60);
|
|
41
|
+
if (offsetMinutes !== 0) {
|
|
42
|
+
throw new Error(`The MySQL server's time zone is ${offsetMinutes / 60} hours off UTC; set default-time-zone = '+00:00' in its configuration`);
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
default:
|
|
47
|
+
throw new Error(`UtcDataSource doesn't support ${this.options.type}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=utc-data-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utc-data-source.js","sourceRoot":"","sources":["../../src/lib/utc-data-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,SAAS,CAAA;AAEvD;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IACzC,YAAY,OAA0B;QAClC,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;IAC5C,CAAC;IAEe,KAAK,CAAC,UAAU;QAC5B,MAAM,KAAK,CAAC,UAAU,EAAE,CAAA;QACxB,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,eAAe,EAAE,CAAA;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,2GAA2G;YAC3G,2BAA2B;YAC3B,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBACrB,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;YAC/C,CAAC;YACD,MAAM,KAAK,CAAA;QACf,CAAC;QACD,OAAO,IAAI,CAAA;IACf,CAAC;IAEO,MAAM,CAAC,UAAU,CAAC,OAA0B;QAChD,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,OAAO,CAAC;YACb,KAAK,SAAS;gBACV,OAAO,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAA;YACxC;gBACI,MAAM,IAAI,KAAK,CAAC,iCAAiC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QACxE,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,eAAe;QACzB,QAAQ,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACxB,KAAK,OAAO,CAAC;YACb,KAAK,SAAS,CAAC,CAAC,CAAC;gBACb,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CACxC,uEAAuE,CAC1E,CAAA;gBACD,MAAM,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,CAAA;gBAC5D,IAAI,aAAa,KAAK,CAAC,EAAE,CAAC;oBACtB,MAAM,IAAI,KAAK,CACX,mCAAmC,aAAa,GAAG,EAAE,uEAAuE,CAC/H,CAAA;gBACL,CAAC;gBACD,OAAM;YACV,CAAC;YACD;gBACI,MAAM,IAAI,KAAK,CAAC,iCAAiC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QAC7E,CAAC;IACL,CAAC;CACJ"}
|
package/dist/orm.module.d.ts
CHANGED
|
@@ -1,2 +1,32 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { TypeOrmModuleAsyncOptions, TypeOrmModuleOptions } from '@nestjs/typeorm';
|
|
3
|
+
export interface OrmUtcOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Stores and reads dates as UTC, and refuses to start unless the database server runs in UTC too
|
|
6
|
+
* (see `UtcDataSource`). Off by default.
|
|
7
|
+
*/
|
|
8
|
+
utc?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type OrmModuleOptions = TypeOrmModuleOptions & OrmUtcOptions;
|
|
11
|
+
export type OrmModuleAsyncOptions = TypeOrmModuleAsyncOptions & OrmUtcOptions;
|
|
12
|
+
/**
|
|
13
|
+
* Sets up the TypeORM connection for `OrmModule.forRoot*()` and re-exports the plain `OrmModule`, so the application
|
|
14
|
+
* and every library share one `OrmModule` and one `TransactionService`.
|
|
15
|
+
*/
|
|
16
|
+
export declare class OrmCoreModule {
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Provides `TransactionService`. It's imported in one of two ways:
|
|
20
|
+
*
|
|
21
|
+
* - The application imports `OrmModule.forRoot()` or `OrmModule.forRootAsync()` once, typically in its root or a
|
|
22
|
+
* shared database module. This also sets up the TypeORM connection, in place of `TypeOrmModule.forRoot*()`, and can
|
|
23
|
+
* enforce UTC dates with `utc: true`.
|
|
24
|
+
* - Feature modules and libraries import `OrmModule` itself, without options, next to `TypeOrmModule.forFeature()`.
|
|
25
|
+
* They must not call `forRoot*()`: that would open a second connection, with settings only the application has.
|
|
26
|
+
*
|
|
27
|
+
* Both ways resolve to the same module, so the application and every library share one `TransactionService`.
|
|
28
|
+
*/
|
|
1
29
|
export declare class OrmModule {
|
|
30
|
+
static forRoot(options?: OrmModuleOptions): DynamicModule;
|
|
31
|
+
static forRootAsync(options: OrmModuleAsyncOptions): DynamicModule;
|
|
2
32
|
}
|
package/dist/orm.module.js
CHANGED
|
@@ -1,21 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
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
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
var OrmModule_1;
|
|
8
|
+
import { Module } from '@nestjs/common';
|
|
9
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
10
|
+
import { UtcDataSource } from './lib/utc-data-source.js';
|
|
11
|
+
import { TransactionService } from './services/transaction.service.js';
|
|
12
|
+
/**
|
|
13
|
+
* Sets up the TypeORM connection for `OrmModule.forRoot*()` and re-exports the plain `OrmModule`, so the application
|
|
14
|
+
* and every library share one `OrmModule` and one `TransactionService`.
|
|
15
|
+
*/
|
|
16
|
+
let OrmCoreModule = class OrmCoreModule {
|
|
13
17
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
OrmCoreModule = __decorate([
|
|
19
|
+
Module({})
|
|
20
|
+
], OrmCoreModule);
|
|
21
|
+
export { OrmCoreModule };
|
|
22
|
+
/**
|
|
23
|
+
* Provides `TransactionService`. It's imported in one of two ways:
|
|
24
|
+
*
|
|
25
|
+
* - The application imports `OrmModule.forRoot()` or `OrmModule.forRootAsync()` once, typically in its root or a
|
|
26
|
+
* shared database module. This also sets up the TypeORM connection, in place of `TypeOrmModule.forRoot*()`, and can
|
|
27
|
+
* enforce UTC dates with `utc: true`.
|
|
28
|
+
* - Feature modules and libraries import `OrmModule` itself, without options, next to `TypeOrmModule.forFeature()`.
|
|
29
|
+
* They must not call `forRoot*()`: that would open a second connection, with settings only the application has.
|
|
30
|
+
*
|
|
31
|
+
* Both ways resolve to the same module, so the application and every library share one `TransactionService`.
|
|
32
|
+
*/
|
|
33
|
+
let OrmModule = OrmModule_1 = class OrmModule {
|
|
34
|
+
static forRoot(options = {}) {
|
|
35
|
+
const { utc, ...typeOrmOptions } = options;
|
|
36
|
+
return OrmModule_1.forRootAsync({ utc, name: typeOrmOptions.name, useFactory: () => typeOrmOptions });
|
|
37
|
+
}
|
|
38
|
+
static forRootAsync(options) {
|
|
39
|
+
const { utc, ...typeOrmOptions } = options;
|
|
40
|
+
if (utc && typeOrmOptions.dataSourceFactory) {
|
|
41
|
+
throw new Error("OrmModule: `utc` provides the data source, so it can't be combined with `dataSourceFactory`");
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
module: OrmCoreModule,
|
|
45
|
+
imports: [
|
|
46
|
+
OrmModule_1,
|
|
47
|
+
TypeOrmModule.forRootAsync({
|
|
48
|
+
...typeOrmOptions,
|
|
49
|
+
// TypeORM's module initializes the returned data source, which runs its UTC check
|
|
50
|
+
...(utc && {
|
|
51
|
+
dataSourceFactory: (dataSourceOptions) => Promise.resolve(new UtcDataSource(dataSourceOptions)),
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
],
|
|
55
|
+
exports: [OrmModule_1],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
OrmModule = OrmModule_1 = __decorate([
|
|
60
|
+
Module({
|
|
61
|
+
providers: [TransactionService],
|
|
62
|
+
exports: [TransactionService],
|
|
19
63
|
})
|
|
20
64
|
], OrmModule);
|
|
65
|
+
export { OrmModule };
|
|
21
66
|
//# sourceMappingURL=orm.module.js.map
|
package/dist/orm.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orm.module.js","sourceRoot":"","sources":["../src/orm.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"orm.module.js","sourceRoot":"","sources":["../src/orm.module.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACtD,OAAO,EAAE,aAAa,EAAmD,MAAM,iBAAiB,CAAA;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAatE;;;GAGG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;CAAG,CAAA;AAAhB,aAAa;IADzB,MAAM,CAAC,EAAE,CAAC;GACE,aAAa,CAAG;;AAE7B;;;;;;;;;;GAUG;AAMI,IAAM,SAAS,iBAAf,MAAM,SAAS;IACX,MAAM,CAAC,OAAO,CAAC,UAA4B,EAAE;QAChD,MAAM,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,CAAA;QAC1C,OAAO,WAAS,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAA;IACvG,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,OAA8B;QACrD,MAAM,EAAE,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,CAAA;QAC1C,IAAI,GAAG,IAAI,cAAc,CAAC,iBAAiB,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CACX,6FAA6F,CAChG,CAAA;QACL,CAAC;QAED,OAAO;YACH,MAAM,EAAE,aAAa;YACrB,OAAO,EAAE;gBACL,WAAS;gBACT,aAAa,CAAC,YAAY,CAAC;oBACvB,GAAG,cAAc;oBACjB,kFAAkF;oBAClF,GAAG,CAAC,GAAG,IAAI;wBACP,iBAAiB,EAAE,CAAC,iBAAiB,EAAE,EAAE,CACrC,OAAO,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC,iBAAkB,CAAC,CAAC;qBAC7D,CAAC;iBACL,CAAC;aACL;YACD,OAAO,EAAE,CAAC,WAAS,CAAC;SACvB,CAAA;IACL,CAAC;CACJ,CAAA;AA9BY,SAAS;IALrB,MAAM,CAAC;QACJ,SAAS,EAAE,CAAC,kBAAkB,CAAC;QAE/B,OAAO,EAAE,CAAC,kBAAkB,CAAC;KAChC,CAAC;GACW,SAAS,CA8BrB"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { DeepPartial, DeleteResult, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, Repository, SelectQueryBuilder, UpdateResult } from 'typeorm';
|
|
2
|
-
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';
|
|
1
|
+
import { DeepPartial, DeleteResult, EntityManager, FindManyOptions, FindOneOptions, FindOptionsWhere, QueryDeepPartialEntity, Repository, SelectQueryBuilder, UpdateResult } from 'typeorm';
|
|
3
2
|
import { Type } from '@nestjs/common';
|
|
4
|
-
import { AbstractOrmEntity } from '../entities/abstract-orm.entity';
|
|
5
|
-
import { Constructor } from '../lib/constructor';
|
|
3
|
+
import { AbstractOrmEntity } from '../entities/abstract-orm.entity.js';
|
|
4
|
+
import { Constructor } from '../lib/constructor.js';
|
|
6
5
|
export interface IOrmService<T extends AbstractOrmEntity> {
|
|
7
6
|
readonly repository: Repository<T>;
|
|
8
7
|
create(props: DeepPartial<T>, enforceEntityManager?: EntityManager): Promise<T>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,12 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const transaction_context_1 = require("../lib/transaction-context");
|
|
16
|
-
function AbstractOrmService(entity) {
|
|
10
|
+
import { Repository, } from 'typeorm';
|
|
11
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
12
|
+
import { txStorage } from '../lib/transaction-context.js';
|
|
13
|
+
export function AbstractOrmService(entity) {
|
|
17
14
|
class AbstractOrmServiceHost {
|
|
18
15
|
repository;
|
|
19
16
|
async create(props, enforceEntityManager) {
|
|
@@ -72,12 +69,12 @@ function AbstractOrmService(entity) {
|
|
|
72
69
|
return enforceEntityManager ?? this.contextEntityManager;
|
|
73
70
|
}
|
|
74
71
|
get contextEntityManager() {
|
|
75
|
-
return
|
|
72
|
+
return txStorage.getStore()?.get(this.repository.manager.dataSource);
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
__decorate([
|
|
79
|
-
|
|
80
|
-
__metadata("design:type",
|
|
76
|
+
InjectRepository(entity),
|
|
77
|
+
__metadata("design:type", Repository)
|
|
81
78
|
], AbstractOrmServiceHost.prototype, "repository", void 0);
|
|
82
79
|
return AbstractOrmServiceHost;
|
|
83
80
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"abstract-orm.service.js","sourceRoot":"","sources":["../../src/services/abstract-orm.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"abstract-orm.service.js","sourceRoot":"","sources":["../../src/services/abstract-orm.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAQH,UAAU,GAGb,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAoBzD,MAAM,UAAU,kBAAkB,CAA8B,MAAsB;IAClF,MAAM,sBAAsB;QAExB,UAAU,CAAgB;QAEnB,KAAK,CAAC,MAAM,CAAC,KAAqB,EAAE,oBAAoC;YAC3E,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAA;YAE3D,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;YACtC,MAAM,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YAE5B,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,EAAE,oBAAoB,CAAC,CAAA;YAE7C,OAAO,KAAK,CAAA;QAChB,CAAC;QAEM,MAAM,CAAC,SAA4B,EAAE,oBAAoC;YAC5E,OAAO,IAAI,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;QACrE,CAAC;QAEM,KAAK,CAAC,IAAI,CAAC,UAA8B,EAAE,oBAAoC;YAClF,MAAM,MAAM,GAAG,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yF;YACzF,iEAAiE;YACjE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAA;YAEvD,IAAI,oBAAoB,EAAE,CAAC;gBACvB,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAA;YACnE,CAAC;QACL,CAAC;QAEO,aAAa,CAAC,oBAAoC;YACtD,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAA;YACjE,OAAO,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAA;QAChF,CAAC;QAEO,gBAAgB,CAAC,oBAAoC;YACzD,OAAO,oBAAoB,IAAI,IAAI,CAAC,oBAAoB,CAAA;QAC5D,CAAC;QAED,IAAY,oBAAoB;YAC5B,OAAO,SAAS,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QACxE,CAAC;KACJ;IAnFG;QADC,gBAAgB,CAAC,MAAM,CAAC;kCACZ,UAAU;8DAAG;IAoF9B,OAAO,sBAAsB,CAAA;AACjC,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,18 +7,16 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const common_1 = require("@nestjs/common");
|
|
15
|
-
const transaction_context_1 = require("../lib/transaction-context");
|
|
10
|
+
import { DataSource } from 'typeorm';
|
|
11
|
+
import { Injectable } from '@nestjs/common';
|
|
12
|
+
import { txStorage } from '../lib/transaction-context.js';
|
|
16
13
|
let TransactionService = class TransactionService {
|
|
17
14
|
dataSource;
|
|
18
15
|
constructor(dataSource) {
|
|
19
16
|
this.dataSource = dataSource;
|
|
20
17
|
}
|
|
21
18
|
async transaction(fn) {
|
|
22
|
-
const currentStore =
|
|
19
|
+
const currentStore = txStorage.getStore();
|
|
23
20
|
const manager = currentStore?.get(this.dataSource) ?? this.dataSource.manager;
|
|
24
21
|
return manager.transaction(async (txManager) => {
|
|
25
22
|
// Copy rather than mutate: the current store may still be referenced by sibling
|
|
@@ -27,13 +24,13 @@ let TransactionService = class TransactionService {
|
|
|
27
24
|
// this call), which must not see this DataSource's entry appear underneath them.
|
|
28
25
|
const nextStore = new Map(currentStore);
|
|
29
26
|
nextStore.set(this.dataSource, txManager);
|
|
30
|
-
return
|
|
27
|
+
return txStorage.run(nextStore, () => fn(txManager));
|
|
31
28
|
});
|
|
32
29
|
}
|
|
33
30
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
(
|
|
37
|
-
__metadata("design:paramtypes", [typeorm_1.DataSource])
|
|
31
|
+
TransactionService = __decorate([
|
|
32
|
+
Injectable(),
|
|
33
|
+
__metadata("design:paramtypes", [DataSource])
|
|
38
34
|
], TransactionService);
|
|
35
|
+
export { TransactionService };
|
|
39
36
|
//# sourceMappingURL=transaction.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.service.js","sourceRoot":"","sources":["../../src/services/transaction.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transaction.service.js","sourceRoot":"","sources":["../../src/services/transaction.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,UAAU,EAAiB,MAAM,SAAS,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAGlD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACE;IAA7B,YAA6B,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAEhD,KAAK,CAAC,WAAW,CAAI,EAA0C;QAClE,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAA;QACzC,MAAM,OAAO,GAAG,YAAY,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAA;QAE7E,OAAO,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,SAAwB,EAAE,EAAE;YAC1D,gFAAgF;YAChF,mFAAmF;YACnF,iFAAiF;YACjF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,CAAA;YACvC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,SAAS,CAAC,CAAA;YACzC,OAAO,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;QACxD,CAAC,CAAC,CAAA;IACN,CAAC;CACJ,CAAA;AAhBY,kBAAkB;IAD9B,UAAU,EAAE;qCAEgC,UAAU;GAD1C,kBAAkB,CAgB9B"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constructor } from '../lib/constructor';
|
|
1
|
+
import { Constructor } from '../lib/constructor.js';
|
|
2
2
|
export declare const GENERATED_COLUMNS: unique symbol;
|
|
3
3
|
export declare function addGeneratedColumn(constructor: Constructor, column: GeneratedColumnMetadata): void;
|
|
4
4
|
export declare function getGeneratedColumns(constructor: Constructor): GeneratedColumnMetadata[];
|
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GENERATED_COLUMNS = void 0;
|
|
4
|
-
exports.addGeneratedColumn = addGeneratedColumn;
|
|
5
|
-
exports.getGeneratedColumns = getGeneratedColumns;
|
|
6
|
-
exports.GENERATED_COLUMNS = Symbol('GENERATED_COLUMNS');
|
|
1
|
+
export const GENERATED_COLUMNS = Symbol('GENERATED_COLUMNS');
|
|
7
2
|
// Recorded per-class as OWN metadata only (never merged with an ancestor's at write time), so a
|
|
8
3
|
// subclass redeclaring a column always shadows its parent's entry for that property instead of
|
|
9
4
|
// stacking alongside it. `generator: null` explicitly opts a property out of an ancestor's
|
|
10
5
|
// auto-generation, distinct from a subclass saying nothing about the property at all.
|
|
11
|
-
function addGeneratedColumn(constructor, column) {
|
|
12
|
-
const existing = (Reflect.getOwnMetadata(
|
|
13
|
-
Reflect.defineMetadata(
|
|
6
|
+
export function addGeneratedColumn(constructor, column) {
|
|
7
|
+
const existing = (Reflect.getOwnMetadata(GENERATED_COLUMNS, constructor) ?? []);
|
|
8
|
+
Reflect.defineMetadata(GENERATED_COLUMNS, [...existing, column], constructor);
|
|
14
9
|
}
|
|
15
10
|
// Walks the prototype chain from the topmost ancestor down to `constructor`, merging each class's
|
|
16
11
|
// OWN entries by propertyKey so a more-derived class's declaration always wins over an inherited one.
|
|
17
|
-
function getGeneratedColumns(constructor) {
|
|
12
|
+
export function getGeneratedColumns(constructor) {
|
|
18
13
|
const chain = [];
|
|
19
14
|
for (let current = constructor; current; current = Object.getPrototypeOf(current)) {
|
|
20
15
|
chain.unshift(current);
|
|
21
16
|
}
|
|
22
17
|
const byPropertyKey = new Map();
|
|
23
18
|
for (const ctor of chain) {
|
|
24
|
-
const ownColumns = (Reflect.getOwnMetadata(
|
|
19
|
+
const ownColumns = (Reflect.getOwnMetadata(GENERATED_COLUMNS, ctor) ?? []);
|
|
25
20
|
for (const column of ownColumns) {
|
|
26
21
|
byPropertyKey.set(column.propertyKey, column);
|
|
27
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generated-column.util.js","sourceRoot":"","sources":["../../src/utils/generated-column.util.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generated-column.util.js","sourceRoot":"","sources":["../../src/utils/generated-column.util.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAA;AAE5D,gGAAgG;AAChG,+FAA+F;AAC/F,2FAA2F;AAC3F,sFAAsF;AACtF,MAAM,UAAU,kBAAkB,CAAC,WAAwB,EAAE,MAA+B;IACxF,MAAM,QAAQ,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,WAAW,CAAC,IAAI,EAAE,CAA8B,CAAA;IAC5G,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,CAAC,GAAG,QAAQ,EAAE,MAAM,CAAC,EAAE,WAAW,CAAC,CAAA;AACjF,CAAC;AAED,kGAAkG;AAClG,sGAAsG;AACtG,MAAM,UAAU,mBAAmB,CAAC,WAAwB;IACxD,MAAM,KAAK,GAAkB,EAAE,CAAA;IAC/B,KACI,IAAI,OAAO,GAAuB,WAAW,EAC7C,OAAO,EACP,OAAO,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAuB,EAChE,CAAC;QACC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC1B,CAAC;IAED,MAAM,aAAa,GAAG,IAAI,GAAG,EAAmC,CAAA;IAChE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,UAAU,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,iBAAiB,EAAE,IAAI,CAAC,IAAI,EAAE,CAA8B,CAAA;QACvG,KAAK,MAAM,MAAM,IAAI,UAAU,EAAE,CAAC;YAC9B,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAA;QACjD,CAAC;IACL,CAAC;IAED,OAAO,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,CAAA;AACtC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@artenc/nest-orm",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Helper utility to work with TypeORM",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nestjs",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"author": "artenc",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"private": false,
|
|
22
|
+
"type": "module",
|
|
22
23
|
"repository": {
|
|
23
24
|
"type": "git",
|
|
24
25
|
"url": "git+https://gitlab.com/nestjs-utility-modules/nest-orm.git"
|
|
@@ -35,67 +36,57 @@
|
|
|
35
36
|
"exports": {
|
|
36
37
|
".": {
|
|
37
38
|
"types": "./dist/index.d.ts",
|
|
38
|
-
"
|
|
39
|
-
"import": "./dist/index.js"
|
|
39
|
+
"default": "./dist/index.js"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"sideEffects": false,
|
|
43
43
|
"files": [
|
|
44
44
|
"dist"
|
|
45
45
|
],
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": "^20.19.0 || ^22.13.0 || >=24.11.0"
|
|
48
|
+
},
|
|
46
49
|
"scripts": {
|
|
47
50
|
"build": "nest build",
|
|
48
51
|
"prepack": "npm test && npm run build",
|
|
49
52
|
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
50
53
|
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
|
51
|
-
"test": "
|
|
52
|
-
"
|
|
53
|
-
"test:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
"<rootDir>/test"
|
|
58
|
-
],
|
|
59
|
-
"testRegex": ".*\\.spec\\.ts$",
|
|
60
|
-
"transform": {
|
|
61
|
-
"^.+\\.ts$": "ts-jest"
|
|
62
|
-
},
|
|
63
|
-
"setupFiles": [
|
|
64
|
-
"reflect-metadata"
|
|
65
|
-
],
|
|
66
|
-
"testEnvironment": "node",
|
|
67
|
-
"collectCoverageFrom": [
|
|
68
|
-
"src/**/*.ts"
|
|
69
|
-
],
|
|
70
|
-
"coverageDirectory": "coverage"
|
|
54
|
+
"test": "npm run typecheck && vitest run",
|
|
55
|
+
"typecheck": "tsc --noEmit -p tsconfig.json",
|
|
56
|
+
"test:watch": "vitest",
|
|
57
|
+
"test:cov": "vitest run --coverage",
|
|
58
|
+
"test:mysql:start": "node test/support/mysql-server.ts start",
|
|
59
|
+
"test:mysql:stop": "node test/support/mysql-server.ts stop"
|
|
71
60
|
},
|
|
72
61
|
"dependencies": {
|
|
73
62
|
"class-transformer": "^0.5.1",
|
|
74
|
-
"uuid": "^
|
|
63
|
+
"uuid": "^14.0.3"
|
|
75
64
|
},
|
|
76
65
|
"peerDependencies": {
|
|
77
|
-
"@nestjs/common": "^
|
|
78
|
-
"@nestjs/typeorm": "^
|
|
79
|
-
"typeorm": "^
|
|
66
|
+
"@nestjs/common": "^12.0.0",
|
|
67
|
+
"@nestjs/typeorm": "^12.0.0",
|
|
68
|
+
"typeorm": "^1.1.3"
|
|
80
69
|
},
|
|
81
70
|
"devDependencies": {
|
|
82
|
-
"@eslint/js": "^
|
|
83
|
-
"@nestjs/cli": "^
|
|
84
|
-
"@nestjs/common": "^
|
|
85
|
-
"@nestjs/
|
|
86
|
-
"@nestjs/
|
|
87
|
-
"@
|
|
88
|
-
"@types/node": "^22.
|
|
89
|
-
"
|
|
90
|
-
"eslint
|
|
91
|
-
"eslint-
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
71
|
+
"@eslint/js": "^10.0.1",
|
|
72
|
+
"@nestjs/cli": "^12.0.15",
|
|
73
|
+
"@nestjs/common": "^12.6.3",
|
|
74
|
+
"@nestjs/core": "^12.6.3",
|
|
75
|
+
"@nestjs/schematics": "^12.0.17",
|
|
76
|
+
"@nestjs/typeorm": "^12.0.3",
|
|
77
|
+
"@types/node": "^22.20.7",
|
|
78
|
+
"@vitest/coverage-v8": "^5.1.2",
|
|
79
|
+
"eslint": "^10.16.0",
|
|
80
|
+
"eslint-config-prettier": "^10.1.9",
|
|
81
|
+
"eslint-plugin-prettier": "^5.5.7",
|
|
82
|
+
"globals": "^17.14.0",
|
|
83
|
+
"mysql2": "^3.26.0",
|
|
84
|
+
"prettier": "^3.10.1",
|
|
95
85
|
"reflect-metadata": "^0.2.2",
|
|
96
|
-
"
|
|
97
|
-
"typeorm": "^
|
|
98
|
-
"typescript": "
|
|
99
|
-
"typescript-eslint": "^8.
|
|
86
|
+
"rxjs": "^7.8.2",
|
|
87
|
+
"typeorm": "^1.1.3",
|
|
88
|
+
"typescript": "~6.0.3",
|
|
89
|
+
"typescript-eslint": "^8.74.0",
|
|
90
|
+
"vitest": "^5.1.2"
|
|
100
91
|
}
|
|
101
92
|
}
|