@nest-batch/typeorm 0.2.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/LICENSE +21 -0
- package/README.md +263 -0
- package/dist/src/adapters/index.d.ts +18 -0
- package/dist/src/adapters/index.d.ts.map +1 -0
- package/dist/src/adapters/index.js +35 -0
- package/dist/src/adapters/index.js.map +1 -0
- package/dist/src/adapters/typeorm.adapter.d.ts +42 -0
- package/dist/src/adapters/typeorm.adapter.d.ts.map +1 -0
- package/dist/src/adapters/typeorm.adapter.js +85 -0
- package/dist/src/adapters/typeorm.adapter.js.map +1 -0
- package/dist/src/entities/index.d.ts +2 -0
- package/dist/src/entities/index.d.ts.map +1 -0
- package/dist/src/entities/index.js +20 -0
- package/dist/src/entities/index.js.map +1 -0
- package/dist/src/entities/job-meta.entities.d.ts +96 -0
- package/dist/src/entities/job-meta.entities.d.ts.map +1 -0
- package/dist/src/entities/job-meta.entities.js +357 -0
- package/dist/src/entities/job-meta.entities.js.map +1 -0
- package/dist/src/index.d.ts +6 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +74 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/migrations/1700000000000-CreateBatchMeta.d.ts +28 -0
- package/dist/src/migrations/1700000000000-CreateBatchMeta.d.ts.map +1 -0
- package/dist/src/migrations/1700000000000-CreateBatchMeta.js +83 -0
- package/dist/src/migrations/1700000000000-CreateBatchMeta.js.map +1 -0
- package/dist/src/repository/typeorm-job-repository.d.ts +57 -0
- package/dist/src/repository/typeorm-job-repository.d.ts.map +1 -0
- package/dist/src/repository/typeorm-job-repository.js +489 -0
- package/dist/src/repository/typeorm-job-repository.js.map +1 -0
- package/dist/src/transaction/typeorm-transaction-manager.d.ts +24 -0
- package/dist/src/transaction/typeorm-transaction-manager.d.ts.map +1 -0
- package/dist/src/transaction/typeorm-transaction-manager.js +55 -0
- package/dist/src/transaction/typeorm-transaction-manager.js.map +1 -0
- package/dist/src/typeorm.driver-provider.d.ts +22 -0
- package/dist/src/typeorm.driver-provider.d.ts.map +1 -0
- package/dist/src/typeorm.driver-provider.js +32 -0
- package/dist/src/typeorm.driver-provider.js.map +1 -0
- package/package.json +69 -0
- package/src/adapters/index.ts +17 -0
- package/src/adapters/typeorm.adapter.ts +82 -0
- package/src/entities/index.ts +1 -0
- package/src/entities/job-meta.entities.ts +184 -0
- package/src/index.ts +42 -0
- package/src/migrations/1700000000000-CreateBatchMeta.ts +100 -0
- package/src/repository/typeorm-job-repository.ts +548 -0
- package/src/transaction/typeorm-transaction-manager.ts +47 -0
- package/src/typeorm.driver-provider.ts +23 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 easdkr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
# `@nest-batch/typeorm`
|
|
2
|
+
|
|
3
|
+
The TypeORM 1.0.0 adapter for [`@nest-batch/core`](../core). It owns
|
|
4
|
+
the same six Spring Batch-compatible batch meta-tables that
|
|
5
|
+
`@nest-batch/mikro-orm` ships, expressed as TypeORM 1.0 entities plus
|
|
6
|
+
a bundled migration. It exposes `TypeOrmJobRepository` and
|
|
7
|
+
`TypeOrmTransactionManager` and runs the shared core contract suite
|
|
8
|
+
against a real TypeORM `DataSource`.
|
|
9
|
+
|
|
10
|
+
The package is a **sibling**, not a replacement. The dependency
|
|
11
|
+
direction is strict and one-way:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
@nest-batch/typeorm ──▶ @nest-batch/core
|
|
15
|
+
│
|
|
16
|
+
└──────▶ typeorm (peer, ^1.0.0)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`@nest-batch/core` does not know this package exists. The boundary is
|
|
20
|
+
enforced by a core test that fails the build if any `typeorm` import
|
|
21
|
+
shows up in core.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## TypeORM 1.0.0-only policy
|
|
26
|
+
|
|
27
|
+
This adapter targets **TypeORM 1.0.0 only**. The peer range is
|
|
28
|
+
`typeorm: ^1.0.0` and intentionally excludes `0.3.x`.
|
|
29
|
+
|
|
30
|
+
Why 1.0.0 and not 0.3? Two reasons:
|
|
31
|
+
|
|
32
|
+
1. The `Connection` → `DataSource` rename. TypeORM 1.0.0 finished the
|
|
33
|
+
rename that 0.3 started; the API now exposes `DataSource`,
|
|
34
|
+
`DataSourceOptions`, and `DataSource.transaction()` instead of
|
|
35
|
+
`Connection`, `ConnectionOptions`, and `Connection.transaction()`.
|
|
36
|
+
Maintaining 0.3 support would mean running the full codebase
|
|
37
|
+
through `Connection → DataSource` shims, which is a waste of
|
|
38
|
+
effort when 0.3 is on a separate support track.
|
|
39
|
+
2. The entity / migration surface. A few decorators and migration
|
|
40
|
+
helpers moved between 0.3 and 1.0. Supporting both means
|
|
41
|
+
conditional entity definitions, which is a smell.
|
|
42
|
+
|
|
43
|
+
The peer range is `^1.0.0`, so any 1.x release works. The boundary
|
|
44
|
+
test in core and a dedicated peer-range test in this package
|
|
45
|
+
together ensure 0.3 does not silently sneak back in.
|
|
46
|
+
|
|
47
|
+
If you're on TypeORM 0.3, stay on the previous
|
|
48
|
+
`@nest-batch/nest-batch` package (pre-rename) or upgrade TypeORM
|
|
49
|
+
first. There's no compatibility shim in this release.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Install
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
pnpm add @nest-batch/typeorm
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Peer dependencies the host must already provide:
|
|
60
|
+
|
|
61
|
+
| Package | Range |
|
|
62
|
+
| ------------------ | ------------- |
|
|
63
|
+
| `@nest-batch/core` | `workspace:*` |
|
|
64
|
+
| `typeorm` | `^1.0.0` |
|
|
65
|
+
|
|
66
|
+
`typeorm` is a hard peer (declared in `peerDependencies` with
|
|
67
|
+
`optional: false`). The `package.json` also lists it as a
|
|
68
|
+
`devDependency` so the package's own test suite can resolve it
|
|
69
|
+
without the host.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Schema ownership
|
|
74
|
+
|
|
75
|
+
This package owns the same six batch meta tables as
|
|
76
|
+
`@nest-batch/mikro-orm`:
|
|
77
|
+
|
|
78
|
+
| Table | Purpose |
|
|
79
|
+
| ------------------------------ | ---------------------------------------------------------------------------------- |
|
|
80
|
+
| `batch_job_instance` | One row per logical job (unique on `job_name`+`job_key`). |
|
|
81
|
+
| `batch_job_execution` | One row per job run. Holds status, start/end, exit code/message. |
|
|
82
|
+
| `batch_job_execution_params` | Composite-keyed params (one row per param name). |
|
|
83
|
+
| `batch_step_execution` | One row per step run. Holds step status, exit code/message, last-chunk checkpoint. |
|
|
84
|
+
| `batch_job_execution_context` | JSON checkpoint + execution context (job-scoped). |
|
|
85
|
+
| `batch_step_execution_context` | JSON checkpoint + execution context (step-scoped). |
|
|
86
|
+
|
|
87
|
+
The bundled migration lives at
|
|
88
|
+
`src/migrations/1700000000000-CreateBatchMeta.ts` and is exported
|
|
89
|
+
as `CreateBatchMeta1700000000000` from the package root. Apps that
|
|
90
|
+
already have a TypeORM migration directory should copy the file in
|
|
91
|
+
and renumber it to fit their own migration sequence.
|
|
92
|
+
|
|
93
|
+
> **Note:** The six batch meta entities are also exported as a
|
|
94
|
+
> single tuple under `batchMetaEntities` from the package root.
|
|
95
|
+
> Because the adapter no longer bootstraps the `DataSource` (the
|
|
96
|
+
> host owns the `TypeOrmModule.forRoot()` call), spreading
|
|
97
|
+
> `batchMetaEntities` into your own `entities` array is the only
|
|
98
|
+
> way the meta tables are registered with TypeORM's metadata
|
|
99
|
+
> system. Forgetting the spread means `Repository<Entity>` lookups
|
|
100
|
+
> for the meta tables fail silently and the repository throws at
|
|
101
|
+
> first call.
|
|
102
|
+
|
|
103
|
+
> The migration uses `datetime` (not `timestamptz`) on the SQLite
|
|
104
|
+
> test driver and `timestamptz` on PostgreSQL production. The
|
|
105
|
+
> entities declare `datetime` for portability, and the migration
|
|
106
|
+
> handler emits the right per-driver type. This is intentional:
|
|
107
|
+
> the test suite runs against `better-sqlite3` for speed, and the
|
|
108
|
+
> production driver is PostgreSQL.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Wiring
|
|
113
|
+
|
|
114
|
+
Wire the adapter with two imports in `AppModule.imports`: a host-
|
|
115
|
+
owned `TypeOrmModule.forRoot()` call (which builds the
|
|
116
|
+
`DataSource` and registers the meta entities) and a
|
|
117
|
+
`TypeOrmAdapter.forRoot()` carrier passed to
|
|
118
|
+
`NestBatchModule.forRoot({ adapters: { persistence, ... } })`.
|
|
119
|
+
|
|
120
|
+
### Bring-your-own `DataSource` (recommended)
|
|
121
|
+
|
|
122
|
+
If your app already uses `@nestjs/typeorm` (the typical case for a
|
|
123
|
+
Nest app with user-domain entities), call
|
|
124
|
+
`TypeOrmModule.forRoot()` yourself, spread `batchMetaEntities()`
|
|
125
|
+
into its `entities` array, and pass the adapter's no-arg
|
|
126
|
+
`TypeOrmAdapter.forRoot()` to `NestBatchModule.forRoot()` under
|
|
127
|
+
`adapters.persistence`:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { Module } from '@nestjs/common';
|
|
131
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
132
|
+
import { NestBatchModule } from '@nest-batch/core';
|
|
133
|
+
import {
|
|
134
|
+
batchMetaEntities,
|
|
135
|
+
CreateBatchMeta1700000000000,
|
|
136
|
+
TypeOrmAdapter,
|
|
137
|
+
} from '@nest-batch/typeorm';
|
|
138
|
+
import { ProductEntity } from './entities/product.entity';
|
|
139
|
+
|
|
140
|
+
@Module({
|
|
141
|
+
imports: [
|
|
142
|
+
TypeOrmModule.forRoot({
|
|
143
|
+
type: 'postgres',
|
|
144
|
+
host: '127.0.0.1',
|
|
145
|
+
port: 5434,
|
|
146
|
+
username: 'demo',
|
|
147
|
+
password: 'demo',
|
|
148
|
+
database: 'nest_batch_demo',
|
|
149
|
+
entities: [ProductEntity, ...batchMetaEntities()],
|
|
150
|
+
migrations: [CreateBatchMeta1700000000000 /* your other migrations */],
|
|
151
|
+
migrationsRun: true,
|
|
152
|
+
}),
|
|
153
|
+
NestBatchModule.forRoot({
|
|
154
|
+
adapters: { persistence: TypeOrmAdapter.forRoot() },
|
|
155
|
+
}),
|
|
156
|
+
],
|
|
157
|
+
})
|
|
158
|
+
export class AppModule {}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`TypeOrmAdapter.forRoot()` takes no arguments on purpose. The host
|
|
162
|
+
already owns the `TypeOrmModule.forRoot()` call; the adapter only
|
|
163
|
+
declares its own provider and export surface. The
|
|
164
|
+
`JOB_REPOSITORY_TOKEN` and `TRANSACTION_MANAGER_TOKEN` bindings are
|
|
165
|
+
registered globally by the adapter, so you do **not** list
|
|
166
|
+
`TypeOrmJobRepository` / `TypeOrmTransactionManager` in the
|
|
167
|
+
`providers` array — they're already wired.
|
|
168
|
+
|
|
169
|
+
> **Warning:** The adapter does **not** call `TypeOrmModule.forRoot()`
|
|
170
|
+
> and does **not** create a `DataSource`. If you forget the
|
|
171
|
+
> `TypeOrmModule.forRoot()` import, the app boots cleanly and the
|
|
172
|
+
> batch module compiles, but the repository throws at first call
|
|
173
|
+
> because `Repository<Entity>` resolution has nothing to bind to.
|
|
174
|
+
> The two pieces are decoupled by design — the adapter is a
|
|
175
|
+
> binding-only carrier, and the connection is the host's.
|
|
176
|
+
|
|
177
|
+
> **Note:** `@nestjs/typeorm` defaults to `isGlobal: true`, which
|
|
178
|
+
> is what the adapter assumes. Setting `isGlobal: false` breaks
|
|
179
|
+
> `EntityManager` injection inside the adapter's own module: the
|
|
180
|
+
> `DataSource` is registered on the host's `TypeOrmModule.forRoot()`
|
|
181
|
+
> but the adapter module is `global: true`, so the `EntityManager`
|
|
182
|
+
> token it needs is not exported across the boundary. Leave it at
|
|
183
|
+
> the default unless you've wired an alternative.
|
|
184
|
+
|
|
185
|
+
`forRootAsync` is the right call when the connection comes from a
|
|
186
|
+
config service or a secret manager. Pass the standard `useFactory`
|
|
187
|
+
plus `inject` list to `TypeOrmModule.forRootAsync()` and keep
|
|
188
|
+
`TypeOrmAdapter.forRoot()` unchanged — the adapter doesn't care
|
|
189
|
+
how the `DataSource` is built.
|
|
190
|
+
|
|
191
|
+
### DataSource, not Connection
|
|
192
|
+
|
|
193
|
+
TypeORM 1.0.0 calls it `DataSource`. The old `Connection` type is
|
|
194
|
+
gone, and so is `getConnection()` / `getRepository()` on the
|
|
195
|
+
connection. Every example in this README uses `DataSource`. If
|
|
196
|
+
you're migrating from a 0.3 codebase, the rename touches every
|
|
197
|
+
test file, every import, and every import path — there is no
|
|
198
|
+
`@typeorm/0.3-compat` shim.
|
|
199
|
+
|
|
200
|
+
The `TypeOrmTransactionManager` accepts a `DataSource` and uses
|
|
201
|
+
`dataSource.transaction()` to start a real DB transaction. The
|
|
202
|
+
callback receives a transactional `EntityManager`; use that one,
|
|
203
|
+
not a globally-injected one, so all reads and writes are part of
|
|
204
|
+
the same transaction.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## DB-first semantics
|
|
209
|
+
|
|
210
|
+
The repository is the durable source of truth for execution state.
|
|
211
|
+
Same model as the MikroORM adapter, same invariants:
|
|
212
|
+
|
|
213
|
+
1. **The DB is canonical.** A BullMQ job is a correlation stamp, not
|
|
214
|
+
a state row. The `JobExecution` row carries the actual
|
|
215
|
+
`status`, `startTime`, `endTime`, `exitCode`, and `exitMessage`.
|
|
216
|
+
2. **Atomic launches are enforced by the row lock.** The
|
|
217
|
+
`createExecutionAtomic` flow uses a transactional
|
|
218
|
+
`SELECT ... FOR UPDATE SKIP LOCKED` (on PostgreSQL) to serialize
|
|
219
|
+
concurrent launches. Two callers racing to launch the same
|
|
220
|
+
`jobName + jobKey` get one winner; the loser sees a thrown
|
|
221
|
+
`JobExecutionAlreadyRunningError`.
|
|
222
|
+
3. **Restart and checkpoint go through the DB.** `findLatestStepExecution`
|
|
223
|
+
returns the most recent `StepExecution` for `(jobExecutionId, stepName)`
|
|
224
|
+
regardless of status, so the executor can load the
|
|
225
|
+
last-committed chunk index from
|
|
226
|
+
`batch_step_execution_context` and resume from there.
|
|
227
|
+
|
|
228
|
+
The contract suite is the same one `@nest-batch/mikro-orm` runs. If
|
|
229
|
+
you change the repository or transaction manager, run the suite to
|
|
230
|
+
confirm you haven't broken the contract.
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## What is NOT in this package
|
|
235
|
+
|
|
236
|
+
- A TypeORM 0.3 adapter. Use 1.0.0 or stay on the previous package.
|
|
237
|
+
- A Drizzle adapter. Drizzle is explicitly excluded from this
|
|
238
|
+
release. See `MIGRATION.md`.
|
|
239
|
+
- A MikroORM adapter. Use `@nest-batch/mikro-orm` if you want
|
|
240
|
+
MikroORM 6; the two packages expose the same six-table schema.
|
|
241
|
+
- A transport. Use `@nest-batch/bullmq` to wire BullMQ as the
|
|
242
|
+
execution strategy; the transport layer reads the same
|
|
243
|
+
`JobExecution` rows.
|
|
244
|
+
- An admin UI, metrics, tracing, webhook, or job visualization
|
|
245
|
+
surface. Out of scope for the whole `@nest-batch/*` family.
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Scripts
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
pnpm --filter @nest-batch/typeorm build # SWC transpile + tsc declarations
|
|
253
|
+
pnpm --filter @nest-batch/typeorm test # vitest run (uses better-sqlite3 by default)
|
|
254
|
+
pnpm --filter @nest-batch/typeorm test:watch # vitest watch
|
|
255
|
+
pnpm --filter @nest-batch/typeorm typecheck # tsc --noEmit
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
The contract suite runs against an in-memory SQLite database by
|
|
259
|
+
default. The test driver is `better-sqlite3` because it gives
|
|
260
|
+
sub-millisecond setup and teardown, and the contract tests are
|
|
261
|
+
database-agnostic enough to not need a full PostgreSQL harness.
|
|
262
|
+
For an end-to-end Postgres run, point the suite at your own
|
|
263
|
+
`DataSource` via the documented test harness hook.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface for the `adapters/` package directory.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the `TypeOrmAdapter` factory so consumers can
|
|
5
|
+
* import it via `@nest-batch/typeorm` (the root barrel pulls
|
|
6
|
+
* this file in) without having to know the internal directory
|
|
7
|
+
* layout.
|
|
8
|
+
*
|
|
9
|
+
* The factory is the recommended entry point for wiring
|
|
10
|
+
* TypeORM 1.0.0 as the `@nest-batch/core` persistence backend.
|
|
11
|
+
* The legacy `NestBatchTypeOrmModule` (mentioned in
|
|
12
|
+
* `packages/typeorm/README.md`) was never actually implemented
|
|
13
|
+
* in code; this adapter is the canonical replacement and the
|
|
14
|
+
* shape that lines up with the new factory-pattern API
|
|
15
|
+
* (`NestBatchModule.forRoot({ adapters: { persistence, ... } })`).
|
|
16
|
+
*/
|
|
17
|
+
export * from './typeorm.adapter';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface for the `adapters/` package directory.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the `TypeOrmAdapter` factory so consumers can
|
|
5
|
+
* import it via `@nest-batch/typeorm` (the root barrel pulls
|
|
6
|
+
* this file in) without having to know the internal directory
|
|
7
|
+
* layout.
|
|
8
|
+
*
|
|
9
|
+
* The factory is the recommended entry point for wiring
|
|
10
|
+
* TypeORM 1.0.0 as the `@nest-batch/core` persistence backend.
|
|
11
|
+
* The legacy `NestBatchTypeOrmModule` (mentioned in
|
|
12
|
+
* `packages/typeorm/README.md`) was never actually implemented
|
|
13
|
+
* in code; this adapter is the canonical replacement and the
|
|
14
|
+
* shape that lines up with the new factory-pattern API
|
|
15
|
+
* (`NestBatchModule.forRoot({ adapters: { persistence, ... } })`).
|
|
16
|
+
*/ "use strict";
|
|
17
|
+
Object.defineProperty(exports, "__esModule", {
|
|
18
|
+
value: true
|
|
19
|
+
});
|
|
20
|
+
_export_star(require("./typeorm.adapter"), exports);
|
|
21
|
+
function _export_star(from, to) {
|
|
22
|
+
Object.keys(from).forEach(function(k) {
|
|
23
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
24
|
+
Object.defineProperty(to, k, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function() {
|
|
27
|
+
return from[k];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
return from;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/index.ts"],"sourcesContent":["/**\n * Public surface for the `adapters/` package directory.\n *\n * Re-exports the `TypeOrmAdapter` factory so consumers can\n * import it via `@nest-batch/typeorm` (the root barrel pulls\n * this file in) without having to know the internal directory\n * layout.\n *\n * The factory is the recommended entry point for wiring\n * TypeORM 1.0.0 as the `@nest-batch/core` persistence backend.\n * The legacy `NestBatchTypeOrmModule` (mentioned in\n * `packages/typeorm/README.md`) was never actually implemented\n * in code; this adapter is the canonical replacement and the\n * shape that lines up with the new factory-pattern API\n * (`NestBatchModule.forRoot({ adapters: { persistence, ... } })`).\n */\nexport * from './typeorm.adapter';\n"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;;;;qBACa"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type BatchAdapter } from '@nest-batch/core';
|
|
2
|
+
/**
|
|
3
|
+
* Empty Nest module class that owns the TypeORM batch adapter
|
|
4
|
+
* providers.
|
|
5
|
+
*
|
|
6
|
+
* The class has no body on purpose: it is purely a `DynamicModule`
|
|
7
|
+
* carrier for the `forRoot()` factory below. Nest's module system
|
|
8
|
+
* requires *some* class to identify the module — the empty class
|
|
9
|
+
* is the minimum possible surface and keeps the runtime allocation
|
|
10
|
+
* at one class (no decorators, no lifecycle hooks, no metadata).
|
|
11
|
+
*/
|
|
12
|
+
export declare class TypeOrmBatchModule {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* `TypeOrmAdapter` — the TypeORM 1.0.0 persistence adapter for
|
|
16
|
+
* `@nest-batch/core`.
|
|
17
|
+
*
|
|
18
|
+
* It owns the `JOB_REPOSITORY_TOKEN` and `TRANSACTION_MANAGER_TOKEN`
|
|
19
|
+
* bindings to the TypeORM-backed `TypeOrmJobRepository` /
|
|
20
|
+
* `TypeOrmTransactionManager` implementations. This adapter does
|
|
21
|
+
* not call `TypeOrmModule.forRoot()` — the host must call it in
|
|
22
|
+
* `AppModule.imports` (and register the six batch meta entities
|
|
23
|
+
* on the resulting `DataSource`).
|
|
24
|
+
*/
|
|
25
|
+
export declare class TypeOrmAdapter {
|
|
26
|
+
/**
|
|
27
|
+
* Build the `BatchAdapter` value the new factory-pattern
|
|
28
|
+
* `NestBatchModule.forRoot({ adapters: { persistence, ... } })`
|
|
29
|
+
* expects.
|
|
30
|
+
*
|
|
31
|
+
* No options are accepted on purpose — the host already owns
|
|
32
|
+
* the `TypeOrmModule.forRoot(...)` call. The adapter only needs
|
|
33
|
+
* to declare its own provider / export / `globalProviders`
|
|
34
|
+
* surface; the `DataSource` itself is the host's responsibility.
|
|
35
|
+
*
|
|
36
|
+
* @returns A `BatchAdapter` whose `module` is a `global: true`
|
|
37
|
+
* `DynamicModule` exposing `JOB_REPOSITORY_TOKEN` and
|
|
38
|
+
* `TRANSACTION_MANAGER_TOKEN` to the host application.
|
|
39
|
+
*/
|
|
40
|
+
static forRoot(): BatchAdapter;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=typeorm.adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeorm.adapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/typeorm.adapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,kBAAkB,CAAC;AAK1B;;;;;;;;;GASG;AACH,qBACa,kBAAkB;CAAG;AAElC;;;;;;;;;;GAUG;AACH,qBAAa,cAAc;IACzB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,OAAO,IAAI,YAAY;CA6B/B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get TypeOrmAdapter () {
|
|
13
|
+
return TypeOrmAdapter;
|
|
14
|
+
},
|
|
15
|
+
get TypeOrmBatchModule () {
|
|
16
|
+
return TypeOrmBatchModule;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _common = require("@nestjs/common");
|
|
20
|
+
const _core = require("@nest-batch/core");
|
|
21
|
+
const _typeormjobrepository = require("../repository/typeorm-job-repository");
|
|
22
|
+
const _typeormtransactionmanager = require("../transaction/typeorm-transaction-manager");
|
|
23
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
24
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
25
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
26
|
+
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;
|
|
27
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
28
|
+
}
|
|
29
|
+
let TypeOrmBatchModule = class TypeOrmBatchModule {
|
|
30
|
+
};
|
|
31
|
+
TypeOrmBatchModule = _ts_decorate([
|
|
32
|
+
(0, _common.Module)({})
|
|
33
|
+
], TypeOrmBatchModule);
|
|
34
|
+
let TypeOrmAdapter = class TypeOrmAdapter {
|
|
35
|
+
/**
|
|
36
|
+
* Build the `BatchAdapter` value the new factory-pattern
|
|
37
|
+
* `NestBatchModule.forRoot({ adapters: { persistence, ... } })`
|
|
38
|
+
* expects.
|
|
39
|
+
*
|
|
40
|
+
* No options are accepted on purpose — the host already owns
|
|
41
|
+
* the `TypeOrmModule.forRoot(...)` call. The adapter only needs
|
|
42
|
+
* to declare its own provider / export / `globalProviders`
|
|
43
|
+
* surface; the `DataSource` itself is the host's responsibility.
|
|
44
|
+
*
|
|
45
|
+
* @returns A `BatchAdapter` whose `module` is a `global: true`
|
|
46
|
+
* `DynamicModule` exposing `JOB_REPOSITORY_TOKEN` and
|
|
47
|
+
* `TRANSACTION_MANAGER_TOKEN` to the host application.
|
|
48
|
+
*/ static forRoot() {
|
|
49
|
+
return {
|
|
50
|
+
name: 'typeorm',
|
|
51
|
+
module: {
|
|
52
|
+
module: TypeOrmBatchModule,
|
|
53
|
+
global: true,
|
|
54
|
+
providers: [
|
|
55
|
+
_typeormjobrepository.TypeOrmJobRepository,
|
|
56
|
+
_typeormtransactionmanager.TypeOrmTransactionManager,
|
|
57
|
+
{
|
|
58
|
+
provide: _core.JOB_REPOSITORY_TOKEN,
|
|
59
|
+
useExisting: _typeormjobrepository.TypeOrmJobRepository
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
provide: _core.TRANSACTION_MANAGER_TOKEN,
|
|
63
|
+
useExisting: _typeormtransactionmanager.TypeOrmTransactionManager
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
exports: [
|
|
67
|
+
_core.JOB_REPOSITORY_TOKEN,
|
|
68
|
+
_core.TRANSACTION_MANAGER_TOKEN
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
globalProviders: [
|
|
72
|
+
{
|
|
73
|
+
provide: _core.JOB_REPOSITORY_TOKEN,
|
|
74
|
+
useClass: _typeormjobrepository.TypeOrmJobRepository
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
provide: _core.TRANSACTION_MANAGER_TOKEN,
|
|
78
|
+
useClass: _typeormtransactionmanager.TypeOrmTransactionManager
|
|
79
|
+
}
|
|
80
|
+
]
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=typeorm.adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/typeorm.adapter.ts"],"sourcesContent":["import { Module } from '@nestjs/common';\n\nimport {\n JOB_REPOSITORY_TOKEN,\n TRANSACTION_MANAGER_TOKEN,\n type BatchAdapter,\n} from '@nest-batch/core';\n\nimport { TypeOrmJobRepository } from '../repository/typeorm-job-repository';\nimport { TypeOrmTransactionManager } from '../transaction/typeorm-transaction-manager';\n\n/**\n * Empty Nest module class that owns the TypeORM batch adapter\n * providers.\n *\n * The class has no body on purpose: it is purely a `DynamicModule`\n * carrier for the `forRoot()` factory below. Nest's module system\n * requires *some* class to identify the module — the empty class\n * is the minimum possible surface and keeps the runtime allocation\n * at one class (no decorators, no lifecycle hooks, no metadata).\n */\n@Module({})\nexport class TypeOrmBatchModule {}\n\n/**\n * `TypeOrmAdapter` — the TypeORM 1.0.0 persistence adapter for\n * `@nest-batch/core`.\n *\n * It owns the `JOB_REPOSITORY_TOKEN` and `TRANSACTION_MANAGER_TOKEN`\n * bindings to the TypeORM-backed `TypeOrmJobRepository` /\n * `TypeOrmTransactionManager` implementations. This adapter does\n * not call `TypeOrmModule.forRoot()` — the host must call it in\n * `AppModule.imports` (and register the six batch meta entities\n * on the resulting `DataSource`).\n */\nexport class TypeOrmAdapter {\n /**\n * Build the `BatchAdapter` value the new factory-pattern\n * `NestBatchModule.forRoot({ adapters: { persistence, ... } })`\n * expects.\n *\n * No options are accepted on purpose — the host already owns\n * the `TypeOrmModule.forRoot(...)` call. The adapter only needs\n * to declare its own provider / export / `globalProviders`\n * surface; the `DataSource` itself is the host's responsibility.\n *\n * @returns A `BatchAdapter` whose `module` is a `global: true`\n * `DynamicModule` exposing `JOB_REPOSITORY_TOKEN` and\n * `TRANSACTION_MANAGER_TOKEN` to the host application.\n */\n static forRoot(): BatchAdapter {\n return {\n name: 'typeorm',\n module: {\n module: TypeOrmBatchModule,\n global: true,\n providers: [\n TypeOrmJobRepository,\n TypeOrmTransactionManager,\n {\n provide: JOB_REPOSITORY_TOKEN,\n useExisting: TypeOrmJobRepository,\n },\n {\n provide: TRANSACTION_MANAGER_TOKEN,\n useExisting: TypeOrmTransactionManager,\n },\n ],\n exports: [JOB_REPOSITORY_TOKEN, TRANSACTION_MANAGER_TOKEN],\n },\n globalProviders: [\n { provide: JOB_REPOSITORY_TOKEN, useClass: TypeOrmJobRepository },\n {\n provide: TRANSACTION_MANAGER_TOKEN,\n useClass: TypeOrmTransactionManager,\n },\n ],\n };\n }\n}\n\n\n"],"names":["TypeOrmAdapter","TypeOrmBatchModule","forRoot","name","module","global","providers","TypeOrmJobRepository","TypeOrmTransactionManager","provide","JOB_REPOSITORY_TOKEN","useExisting","TRANSACTION_MANAGER_TOKEN","exports","globalProviders","useClass"],"mappings":";;;;;;;;;;;QAmCaA;eAAAA;;QAbAC;eAAAA;;;wBAtBU;sBAMhB;sCAE8B;2CACK;;;;;;;AAanC,IAAA,AAAMA,qBAAN,MAAMA;AAAoB;;;;AAa1B,IAAA,AAAMD,iBAAN,MAAMA;IACX;;;;;;;;;;;;;GAaC,GACD,OAAOE,UAAwB;QAC7B,OAAO;YACLC,MAAM;YACNC,QAAQ;gBACNA,QAAQH;gBACRI,QAAQ;gBACRC,WAAW;oBACTC,0CAAoB;oBACpBC,oDAAyB;oBACzB;wBACEC,SAASC,0BAAoB;wBAC7BC,aAAaJ,0CAAoB;oBACnC;oBACA;wBACEE,SAASG,+BAAyB;wBAClCD,aAAaH,oDAAyB;oBACxC;iBACD;gBACDK,SAAS;oBAACH,0BAAoB;oBAAEE,+BAAyB;iBAAC;YAC5D;YACAE,iBAAiB;gBACf;oBAAEL,SAASC,0BAAoB;oBAAEK,UAAUR,0CAAoB;gBAAC;gBAChE;oBACEE,SAASG,+BAAyB;oBAClCG,UAAUP,oDAAyB;gBACrC;aACD;QACH;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/entities/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./job-meta.entities"), exports);
|
|
6
|
+
function _export_star(from, to) {
|
|
7
|
+
Object.keys(from).forEach(function(k) {
|
|
8
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
9
|
+
Object.defineProperty(to, k, {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return from[k];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return from;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/entities/index.ts"],"sourcesContent":["export * from './job-meta.entities';\n"],"names":[],"mappings":";;;;qBAAc"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `batch_job_instance` metadata row.
|
|
3
|
+
*
|
|
4
|
+
* One row per logical job instance. Uniqueness is enforced on
|
|
5
|
+
* (jobName, jobKey) so that the same canonical key resolves to the
|
|
6
|
+
* same instance across restarts. The composite unique index is
|
|
7
|
+
* declared on the entity and is also reified in the bundled
|
|
8
|
+
* migration under the same name.
|
|
9
|
+
*/
|
|
10
|
+
export declare class JobInstanceEntity {
|
|
11
|
+
id: string;
|
|
12
|
+
jobName: string;
|
|
13
|
+
jobKey: string;
|
|
14
|
+
createdAt: Date;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* `batch_job_execution` metadata row.
|
|
18
|
+
*
|
|
19
|
+
* One row per job run. `status` is the stringified JobStatus enum
|
|
20
|
+
* (kept as a plain varchar — TypeORM enum support varies across
|
|
21
|
+
* drivers and v1.0.0 dropped a few columns we don't need). The
|
|
22
|
+
* `jobInstanceId` column is indexed because every contract lookup
|
|
23
|
+
* ("is this instance running?") scans by it.
|
|
24
|
+
*/
|
|
25
|
+
export declare class JobExecutionEntity {
|
|
26
|
+
id: string;
|
|
27
|
+
jobInstanceId: string;
|
|
28
|
+
status: string;
|
|
29
|
+
startTime: Date | null;
|
|
30
|
+
endTime: Date | null;
|
|
31
|
+
exitCode: string;
|
|
32
|
+
exitMessage: string;
|
|
33
|
+
/**
|
|
34
|
+
* JSON-serialized `JobParameters` snapshot. Stored as `text` (not
|
|
35
|
+
* native `jsonb`) so the adapter works uniformly across SQLite (used
|
|
36
|
+
* in unit tests) and PostgreSQL/MySQL — the column is always a
|
|
37
|
+
* serialized payload, never queried by the ORM.
|
|
38
|
+
*/
|
|
39
|
+
params: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* `batch_step_execution` metadata row.
|
|
43
|
+
*
|
|
44
|
+
* One row per step run. Counters default to 0 so the entity can
|
|
45
|
+
* be persisted immediately upon creation, before any items are
|
|
46
|
+
* processed. `createdAt` is stamped on insert and used by
|
|
47
|
+
* `findLatestStepExecution` to resolve the most recently created
|
|
48
|
+
* step for a given `(jobExecutionId, stepName)` pair — a v4 UUID
|
|
49
|
+
* primary key does not preserve insertion order, so an explicit
|
|
50
|
+
* monotonic column is required.
|
|
51
|
+
*/
|
|
52
|
+
export declare class StepExecutionEntity {
|
|
53
|
+
id: string;
|
|
54
|
+
jobExecutionId: string;
|
|
55
|
+
stepName: string;
|
|
56
|
+
status: string;
|
|
57
|
+
readCount: number;
|
|
58
|
+
writeCount: number;
|
|
59
|
+
skipCount: number;
|
|
60
|
+
rollbackCount: number;
|
|
61
|
+
commitCount: number;
|
|
62
|
+
exitCode: string;
|
|
63
|
+
exitMessage: string;
|
|
64
|
+
createdAt: Date;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* `batch_job_execution_context` metadata row.
|
|
68
|
+
*
|
|
69
|
+
* `data` is a JSON-serialized ExecutionContext payload. `version`
|
|
70
|
+
* guards against lost updates during concurrent writers.
|
|
71
|
+
*/
|
|
72
|
+
export declare class JobExecutionContextEntity {
|
|
73
|
+
jobExecutionId: string;
|
|
74
|
+
data: string;
|
|
75
|
+
version: number;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* `batch_step_execution_context` metadata row.
|
|
79
|
+
*
|
|
80
|
+
* Mirrors the job-level context table but scoped to a single
|
|
81
|
+
* step execution. There is intentionally no params sibling table
|
|
82
|
+
* for steps — step parameters are derivable from the parent job
|
|
83
|
+
* execution params + the step execution context.
|
|
84
|
+
*/
|
|
85
|
+
export declare class StepExecutionContextEntity {
|
|
86
|
+
stepExecutionId: string;
|
|
87
|
+
data: string;
|
|
88
|
+
version: number;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* All batch meta entities owned by this package. Hand to
|
|
92
|
+
* `DataSource#entityMetadatas` (or `entities:`) so TypeORM
|
|
93
|
+
* discovers them through the standard decorator scan.
|
|
94
|
+
*/
|
|
95
|
+
export declare const BATCH_META_ENTITIES: readonly [typeof JobInstanceEntity, typeof JobExecutionEntity, typeof StepExecutionEntity, typeof JobExecutionContextEntity, typeof StepExecutionContextEntity];
|
|
96
|
+
//# sourceMappingURL=job-meta.entities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"job-meta.entities.d.ts","sourceRoot":"","sources":["../../../src/entities/job-meta.entities.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,qBAEa,iBAAiB;IAE5B,EAAE,EAAG,MAAM,CAAC;IAGZ,OAAO,EAAG,MAAM,CAAC;IAGjB,MAAM,EAAG,MAAM,CAAC;IAYhB,SAAS,EAAE,IAAI,CAAc;CAC9B;AAED;;;;;;;;GAQG;AACH,qBAEa,kBAAkB;IAE7B,EAAE,EAAG,MAAM,CAAC;IAGZ,aAAa,EAAG,MAAM,CAAC;IAGvB,MAAM,EAAG,MAAM,CAAC;IAGhB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAQ;IAG9B,OAAO,EAAE,IAAI,GAAG,IAAI,CAAQ;IAG5B,QAAQ,EAAG,MAAM,CAAC;IAGlB,WAAW,EAAG,MAAM,CAAC;IAErB;;;;;OAKG;IAEH,MAAM,EAAG,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,qBAEa,mBAAmB;IAE9B,EAAE,EAAG,MAAM,CAAC;IAGZ,cAAc,EAAG,MAAM,CAAC;IAGxB,QAAQ,EAAG,MAAM,CAAC;IAGlB,MAAM,EAAG,MAAM,CAAC;IAGhB,SAAS,EAAG,MAAM,CAAC;IAGnB,UAAU,EAAG,MAAM,CAAC;IAGpB,SAAS,EAAG,MAAM,CAAC;IAGnB,aAAa,EAAG,MAAM,CAAC;IAGvB,WAAW,EAAG,MAAM,CAAC;IAGrB,QAAQ,EAAG,MAAM,CAAC;IAGlB,WAAW,EAAG,MAAM,CAAC;IAOrB,SAAS,EAAE,IAAI,CAAc;CAC9B;AAED;;;;;GAKG;AACH,qBACa,yBAAyB;IAEpC,cAAc,EAAG,MAAM,CAAC;IAGxB,IAAI,EAAG,MAAM,CAAC;IAGd,OAAO,EAAG,MAAM,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,qBACa,0BAA0B;IAErC,eAAe,EAAG,MAAM,CAAC;IAGzB,IAAI,EAAG,MAAM,CAAC;IAGd,OAAO,EAAG,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,iKAMtB,CAAC"}
|