@hexaijs/core 0.2.0 → 0.3.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 +30 -0
- package/dist/unit-of-work.d.ts +3 -0
- package/dist/unit-of-work.d.ts.map +1 -1
- package/package.json +49 -57
package/README.md
CHANGED
|
@@ -190,6 +190,35 @@ Propagation.EXISTING // Use existing transaction (error if none)
|
|
|
190
190
|
Propagation.NESTED // Nested transaction (savepoint)
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
+
### QueryableUnitOfWork
|
|
194
|
+
|
|
195
|
+
Extends `UnitOfWork` with a `query()` method for executing read operations without transaction overhead.
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
import { QueryableUnitOfWork } from "@hexaijs/core";
|
|
199
|
+
|
|
200
|
+
interface OrderApplicationContext {
|
|
201
|
+
getUnitOfWork(): QueryableUnitOfWork;
|
|
202
|
+
getOrderRepository(): OrderRepository;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Execute a query without transaction overhead
|
|
206
|
+
const user = await unitOfWork.query(async (client) => {
|
|
207
|
+
return await userRepo.findById(client, userId);
|
|
208
|
+
});
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**When to use `wrap()` vs `query()`:**
|
|
212
|
+
|
|
213
|
+
| Method | Transaction | Use Case |
|
|
214
|
+
|--------|-------------|----------|
|
|
215
|
+
| `wrap()` | Yes (BEGIN/COMMIT) | Commands that modify state |
|
|
216
|
+
| `query()` | No (autocommit) | Read-only queries |
|
|
217
|
+
|
|
218
|
+
The `query()` method is context-aware:
|
|
219
|
+
- **Outside transaction**: Acquires a new connection, executes, then releases
|
|
220
|
+
- **Inside transaction**: Reuses the existing transaction's client
|
|
221
|
+
|
|
193
222
|
### EventStore
|
|
194
223
|
|
|
195
224
|
Interface for event sourcing scenarios. Stores and retrieves events by position.
|
|
@@ -263,6 +292,7 @@ throw new DuplicateObjectError("Order with this ID already exists");
|
|
|
263
292
|
| `Identifiable<T>` | Interface for entities with identity |
|
|
264
293
|
| `Repository<T>` | Interface for aggregate persistence |
|
|
265
294
|
| `UnitOfWork` | Interface for transaction management |
|
|
295
|
+
| `QueryableUnitOfWork` | UnitOfWork with `query()` for non-transactional reads |
|
|
266
296
|
| `Propagation` | Enum for transaction propagation modes |
|
|
267
297
|
| `EventStore` | Interface for event store implementations |
|
|
268
298
|
|
package/dist/unit-of-work.d.ts
CHANGED
|
@@ -10,4 +10,7 @@ export interface UnitOfWork<Client = unknown, Options extends BaseUnitOfWorkOpti
|
|
|
10
10
|
getClient(): Client;
|
|
11
11
|
wrap<T>(fn: (client: Client) => Promise<T>, options?: Partial<Options>): Promise<T>;
|
|
12
12
|
}
|
|
13
|
+
export interface QueryableUnitOfWork<Client = unknown, Options extends BaseUnitOfWorkOptions = BaseUnitOfWorkOptions> extends UnitOfWork<Client, Options> {
|
|
14
|
+
query<T>(fn: (client: Client) => Promise<T>): Promise<T>;
|
|
15
|
+
}
|
|
13
16
|
//# sourceMappingURL=unit-of-work.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unit-of-work.d.ts","sourceRoot":"","sources":["../src/unit-of-work.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACnB,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,MAAM,WAAW;CACpB;AAED,MAAM,WAAW,qBAAqB;IAClC,WAAW,EAAE,WAAW,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU,CACvB,MAAM,GAAG,OAAO,EAChB,OAAO,SAAS,qBAAqB,GAAG,qBAAqB;IAE7D,SAAS,IAAI,MAAM,CAAC;IACpB,IAAI,CAAC,CAAC,EACF,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC,CAAC;CACjB"}
|
|
1
|
+
{"version":3,"file":"unit-of-work.d.ts","sourceRoot":"","sources":["../src/unit-of-work.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACnB,GAAG,QAAQ;IACX,QAAQ,aAAa;IACrB,MAAM,WAAW;CACpB;AAED,MAAM,WAAW,qBAAqB;IAClC,WAAW,EAAE,WAAW,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU,CACvB,MAAM,GAAG,OAAO,EAChB,OAAO,SAAS,qBAAqB,GAAG,qBAAqB;IAE7D,SAAS,IAAI,MAAM,CAAC;IACpB,IAAI,CAAC,CAAC,EACF,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAC3B,OAAO,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,MAAM,WAAW,mBAAmB,CAChC,MAAM,GAAG,OAAO,EAChB,OAAO,SAAS,qBAAqB,GAAG,qBAAqB,CAC/D,SAAQ,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC;IACjC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC5D"}
|
package/package.json
CHANGED
|
@@ -1,60 +1,52 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
},
|
|
6
|
-
"version": "0.2.0",
|
|
7
|
-
"description": "Core utilities/types/base classes for hexai projects",
|
|
8
|
-
"license": "MIT",
|
|
9
|
-
"author": "Sangwoo Hyun <wkdny.hyun@gmail.com>",
|
|
10
|
-
"contributors": [
|
|
11
|
-
"Seungcheol Baek <victoryiron.baek@gmail.com>",
|
|
12
|
-
"Donghyun Lee <edonghyun@naver.com>"
|
|
13
|
-
],
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/workingdanny911/hexai.git",
|
|
17
|
-
"directory": "packages/core"
|
|
18
|
-
},
|
|
19
|
-
"homepage": "https://github.com/workingdanny911/hexai#readme",
|
|
20
|
-
"bugs": {
|
|
21
|
-
"url": "https://github.com/workingdanny911/hexai/issues"
|
|
22
|
-
},
|
|
23
|
-
"keywords": [
|
|
24
|
-
"hexai",
|
|
25
|
-
"hexagonal",
|
|
26
|
-
"clean-architecture",
|
|
27
|
-
"ddd",
|
|
28
|
-
"cqrs",
|
|
29
|
-
"typescript",
|
|
30
|
-
"event-sourcing"
|
|
31
|
-
],
|
|
32
|
-
"files": [
|
|
33
|
-
"dist",
|
|
34
|
-
"LICENSE"
|
|
35
|
-
],
|
|
36
|
-
"exports": {
|
|
37
|
-
".": {
|
|
38
|
-
"types": "./dist/index.d.ts",
|
|
39
|
-
"import": "./dist/index.js",
|
|
40
|
-
"require": "./dist/index.js"
|
|
2
|
+
"name": "@hexaijs/core",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
41
5
|
},
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
"version": "0.3.0",
|
|
7
|
+
"description": "Core utilities/types/base classes for hexai projects",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "Sangwoo Hyun <wkdny.hyun@gmail.com>",
|
|
10
|
+
"contributors": [
|
|
11
|
+
"Seungcheol Baek <victoryiron.baek@gmail.com>",
|
|
12
|
+
"Donghyun Lee <edonghyun@naver.com>"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/workingdanny911/hexai.git",
|
|
17
|
+
"directory": "packages/core"
|
|
46
18
|
},
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
19
|
+
"homepage": "https://github.com/workingdanny911/hexai#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/workingdanny911/hexai/issues"
|
|
22
|
+
},
|
|
23
|
+
"keywords": ["hexai", "hexagonal", "clean-architecture", "ddd", "cqrs", "typescript", "event-sourcing"],
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js",
|
|
32
|
+
"require": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./test": {
|
|
35
|
+
"types": "./dist/test/index.d.ts",
|
|
36
|
+
"import": "./dist/test/index.js",
|
|
37
|
+
"require": "./dist/test/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"test": "vitest run",
|
|
43
|
+
"build": "tsc -p ./tsconfig.build.json && tsc-alias"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"lodash": "^4.17.21",
|
|
47
|
+
"uuid": "^9.0.1"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/uuid": "^9.0.8"
|
|
51
|
+
}
|
|
52
|
+
}
|