@klerick/json-api-nestjs-typeorm 0.1.0-beta.1 → 0.1.0-beta.10
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/CHANGELOG.md +78 -1
- package/README.md +39 -0
- package/package.json +25 -38
- package/src/index.d.ts +1 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/constants/index.d.ts +6 -0
- package/src/lib/constants/index.js +10 -0
- package/src/lib/constants/index.js.map +1 -0
- package/src/lib/factory/index.d.ts +20 -0
- package/src/lib/factory/index.js +128 -0
- package/src/lib/factory/index.js.map +1 -0
- package/src/lib/index.d.ts +2 -0
- package/src/lib/index.js +6 -0
- package/src/lib/index.js.map +1 -0
- package/src/lib/orm-helper/acl-rules-to-typeorm.d.ts +36 -0
- package/src/lib/orm-helper/acl-rules-to-typeorm.js +314 -0
- package/src/lib/orm-helper/acl-rules-to-typeorm.js.map +1 -0
- package/src/lib/orm-helper/index.d.ts +13 -0
- package/src/lib/orm-helper/index.js +164 -0
- package/src/lib/orm-helper/index.js.map +1 -0
- package/src/lib/orm-methods/delete-one/delete-one.d.ts +2 -0
- package/src/lib/orm-methods/delete-one/delete-one.js +17 -0
- package/src/lib/orm-methods/delete-one/delete-one.js.map +1 -0
- package/src/lib/orm-methods/delete-relationship/delete-relationship.d.ts +4 -0
- package/src/lib/orm-methods/delete-relationship/delete-relationship.js +18 -0
- package/src/lib/orm-methods/delete-relationship/delete-relationship.js.map +1 -0
- package/src/lib/orm-methods/get-all/get-all.d.ts +7 -0
- package/src/lib/orm-methods/get-all/get-all.js +210 -0
- package/src/lib/orm-methods/get-all/get-all.js.map +1 -0
- package/src/lib/orm-methods/get-one/get-one.d.ts +4 -0
- package/src/lib/orm-methods/get-one/get-one.js +76 -0
- package/src/lib/orm-methods/get-one/get-one.js.map +1 -0
- package/src/lib/orm-methods/get-relationship/get-relationship.d.ts +3 -0
- package/src/lib/orm-methods/get-relationship/get-relationship.js +35 -0
- package/src/lib/orm-methods/get-relationship/get-relationship.js.map +1 -0
- package/src/lib/orm-methods/index.d.ts +9 -0
- package/src/lib/orm-methods/index.js +22 -0
- package/src/lib/orm-methods/index.js.map +1 -0
- package/src/lib/orm-methods/patch-one/patch-one.d.ts +4 -0
- package/src/lib/orm-methods/patch-one/patch-one.js +50 -0
- package/src/lib/orm-methods/patch-one/patch-one.js.map +1 -0
- package/src/lib/orm-methods/patch-relationship/patch-relationship.d.ts +4 -0
- package/src/lib/orm-methods/patch-relationship/patch-relationship.js +23 -0
- package/src/lib/orm-methods/patch-relationship/patch-relationship.js.map +1 -0
- package/src/lib/orm-methods/post-one/post-one.d.ts +4 -0
- package/src/lib/orm-methods/post-one/post-one.js +28 -0
- package/src/lib/orm-methods/post-one/post-one.js.map +1 -0
- package/src/lib/orm-methods/post-relationship/post-relationship.d.ts +4 -0
- package/src/lib/orm-methods/post-relationship/post-relationship.js +19 -0
- package/src/lib/orm-methods/post-relationship/post-relationship.js.map +1 -0
- package/src/lib/service/index.d.ts +3 -0
- package/src/lib/service/index.js +7 -0
- package/src/lib/service/index.js.map +1 -0
- package/src/lib/service/type-orm-format.error.service.d.ts +21 -0
- package/src/lib/service/type-orm-format.error.service.js +122 -0
- package/src/lib/service/type-orm-format.error.service.js.map +1 -0
- package/src/lib/service/type-orm.service.d.ts +25 -0
- package/src/lib/service/type-orm.service.js +73 -0
- package/src/lib/service/type-orm.service.js.map +1 -0
- package/src/lib/service/typeorm-utils.service.d.ts +66 -0
- package/src/lib/service/typeorm-utils.service.js +450 -0
- package/src/lib/service/typeorm-utils.service.js.map +1 -0
- package/src/lib/type-orm-json-api.module.d.ts +7 -0
- package/src/lib/type-orm-json-api.module.js +49 -0
- package/src/lib/type-orm-json-api.module.js.map +1 -0
- package/src/lib/type.d.ts +29 -0
- package/src/lib/type.js +29 -0
- package/src/lib/type.js.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
+
## 0.1.0-beta.10 (2026-01-23)
|
|
2
|
+
|
|
3
|
+
### 🧱 Updated Dependencies
|
|
4
|
+
|
|
5
|
+
- Updated json-api-nestjs-shared to 1.0.0-beta.5
|
|
6
|
+
- Updated json-api-nestjs to 10.0.0-beta.12
|
|
7
|
+
|
|
8
|
+
## 0.1.0-beta.9 (2026-01-22)
|
|
9
|
+
|
|
10
|
+
### 🧱 Updated Dependencies
|
|
11
|
+
|
|
12
|
+
- Updated json-api-nestjs to 10.0.0-beta.11
|
|
13
|
+
|
|
14
|
+
## 0.1.0-beta.8 (2026-01-21)
|
|
15
|
+
|
|
16
|
+
### 🧱 Updated Dependencies
|
|
17
|
+
|
|
18
|
+
- Updated json-api-nestjs to 10.0.0-beta.10
|
|
19
|
+
|
|
20
|
+
## 0.1.0-beta.7 (2026-01-20)
|
|
21
|
+
|
|
22
|
+
### 🧱 Updated Dependencies
|
|
23
|
+
|
|
24
|
+
- Updated json-api-nestjs to 10.0.0-beta.9
|
|
25
|
+
|
|
26
|
+
## 0.1.0-beta.6 (2026-01-19)
|
|
27
|
+
|
|
28
|
+
### 🚀 Features
|
|
29
|
+
|
|
30
|
+
- **json-api-nestjs,json-api-nestjs-microorm,json-api-nestjs-typeorm:** add support for automatic resource linkage in to-one relations, update FK field detection and handling ([0dd670d](https://github.com/klerick/nestjs-json-api/commit/0dd670d))
|
|
31
|
+
|
|
32
|
+
### 🧱 Updated Dependencies
|
|
33
|
+
|
|
34
|
+
- Updated json-api-nestjs to 10.0.0-beta.8
|
|
35
|
+
|
|
36
|
+
### ❤️ Thank You
|
|
37
|
+
|
|
38
|
+
- Alex H
|
|
39
|
+
|
|
40
|
+
## 0.1.0-beta.5 (2025-12-26)
|
|
41
|
+
|
|
42
|
+
### 🧱 Updated Dependencies
|
|
43
|
+
|
|
44
|
+
- Updated json-api-nestjs to 10.0.0-beta.7
|
|
45
|
+
|
|
46
|
+
## 0.1.0-beta.4 (2025-11-13)
|
|
47
|
+
|
|
48
|
+
### 🚀 Features
|
|
49
|
+
|
|
50
|
+
- **json-api-nestjs-typeorm:** add ACL rule support for query builders and enhance `getOne` and `getAll` methods with additional query params and transform toggles ([c322379](https://github.com/klerick/nestjs-json-api/commit/c322379))
|
|
51
|
+
- **json-api-nestjs-typeorm:** fix after update nx ([8f778f0](https://github.com/klerick/nestjs-json-api/commit/8f778f0))
|
|
52
|
+
- **json-api-nestjs-typeorm:** fix after update nx ([5c9bbdf](https://github.com/klerick/nestjs-json-api/commit/5c9bbdf))
|
|
53
|
+
- **json-api-nestjs-typeorm:** refine type usage, update imports, and handle relation aliases consistently ([b3e9f31](https://github.com/klerick/nestjs-json-api/commit/b3e9f31))
|
|
54
|
+
|
|
55
|
+
### 🩹 Fixes
|
|
56
|
+
|
|
57
|
+
- **json-api-nestjs-typeorm:** update type assertions and replace deprecated faker methods ([1aa21f5](https://github.com/klerick/nestjs-json-api/commit/1aa21f5))
|
|
58
|
+
|
|
59
|
+
### 🧱 Updated Dependencies
|
|
60
|
+
|
|
61
|
+
- Updated json-api-nestjs-shared to 1.0.0-beta.4
|
|
62
|
+
- Updated json-api-nestjs to 10.0.0-beta.6
|
|
63
|
+
|
|
64
|
+
### ❤️ Thank You
|
|
65
|
+
|
|
66
|
+
- Alex H
|
|
67
|
+
|
|
68
|
+
## 0.1.0-beta.3 (2025-05-23)
|
|
69
|
+
|
|
70
|
+
### 🚀 Features
|
|
71
|
+
|
|
72
|
+
- **json-api-nestjs,json-api-nestjs-microorm,json-api-nestjs-sdk,json-api-nestjs-shared,json-api-nestjs-typeorm:** up nestjs ([42b6b82](https://github.com/klerick/nestjs-json-api/commit/42b6b82))
|
|
73
|
+
|
|
74
|
+
### ❤️ Thank You
|
|
75
|
+
|
|
76
|
+
- Alex H
|
|
77
|
+
|
|
1
78
|
## 0.1.0-beta.0 (2025-05-21)
|
|
2
79
|
|
|
3
80
|
### 🚀 Features
|
|
@@ -10,4 +87,4 @@
|
|
|
10
87
|
|
|
11
88
|
### ❤️ Thank You
|
|
12
89
|
|
|
13
|
-
- Alex H
|
|
90
|
+
- Alex H
|
package/README.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
<p align='center'>
|
|
2
|
+
<a href="https://www.npmjs.com/package/@klerick/json-api-nestjs-typeorm" target="_blank"><img src="https://img.shields.io/npm/v/@klerick/json-api-nestjs-typeorm.svg" alt="NPM Version" /></a>
|
|
3
|
+
<a href="https://www.npmjs.com/package/@klerick/json-api-nestjs-typeorm" target="_blank"><img src="https://img.shields.io/npm/l/@klerick/json-api-nestjs-typeorm.svg" alt="Package License" /></a>
|
|
4
|
+
<a href="https://www.npmjs.com/package/@klerick/json-api-nestjs-typeorm" target="_blank"><img src="https://img.shields.io/npm/dm/@klerick/json-api-nestjs-typeorm.svg" alt="NPM Downloads" /></a>
|
|
5
|
+
<a href="http://commitizen.github.io/cz-cli/" target="_blank"><img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly" /></a>
|
|
6
|
+
<img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/klerick/02a4c98cf7008fea2af70dc2d50f4cb7/raw/json-api-nestjs-microorm.json" alt="Coverage Badge" />
|
|
7
|
+
</p>
|
|
8
|
+
|
|
1
9
|
# json-api-nestjs-typeorm
|
|
2
10
|
|
|
3
11
|
TypeOrm adapter for **[json-api-nestjs](https://github.com/klerick/nestjs-json-api/tree/master/libs/json-api/json-api-nestjs)**
|
|
@@ -22,3 +30,34 @@ export type TypeOrmParam = {
|
|
|
22
30
|
) => ReturnType<Func> // You can use cutom function for wrapping transaction in atomic operation, example: runInTransaction from https://github.com/Aliheym/typeorm-transactional
|
|
23
31
|
};
|
|
24
32
|
```
|
|
33
|
+
|
|
34
|
+
## Resource Linkage for To-One Relations
|
|
35
|
+
|
|
36
|
+
To enable automatic resource linkage (`data` field in relationships) for to-one relations, use the `@RelationId` decorator from TypeORM.
|
|
37
|
+
|
|
38
|
+
**Example:**
|
|
39
|
+
```typescript
|
|
40
|
+
import {
|
|
41
|
+
Entity,
|
|
42
|
+
PrimaryGeneratedColumn,
|
|
43
|
+
ManyToOne,
|
|
44
|
+
JoinColumn,
|
|
45
|
+
RelationId,
|
|
46
|
+
} from 'typeorm';
|
|
47
|
+
|
|
48
|
+
@Entity('comments')
|
|
49
|
+
export class Comments {
|
|
50
|
+
@PrimaryGeneratedColumn()
|
|
51
|
+
public id!: number;
|
|
52
|
+
|
|
53
|
+
@ManyToOne(() => Users)
|
|
54
|
+
@JoinColumn({ name: 'user_id' })
|
|
55
|
+
public user!: Users;
|
|
56
|
+
|
|
57
|
+
// This field will be used for resource linkage
|
|
58
|
+
@RelationId((comment: Comments) => comment.user)
|
|
59
|
+
public userId!: number;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The `@RelationId` decorator creates a virtual field that contains the FK value. The library automatically detects these fields and uses them to populate `relationships.{relation}.data` in API responses.
|
package/package.json
CHANGED
|
@@ -1,31 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@klerick/json-api-nestjs-typeorm",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"private": false,
|
|
6
|
-
"contributors": [
|
|
7
|
-
{
|
|
8
|
-
"email": "klerick666@gmain.com",
|
|
9
|
-
"name": "Aleksandr Kharkovey"
|
|
10
|
-
}
|
|
11
|
-
],
|
|
12
|
-
"repository": {
|
|
13
|
-
"type": "git",
|
|
14
|
-
"url": "https://github.com/klerick/nestjs-json-api.git"
|
|
15
|
-
},
|
|
16
|
-
"engines": {
|
|
17
|
-
"node": ">= 20.0.0"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"@mikro-orm/core": "^6.4.3",
|
|
21
|
-
"@nestjs/common": "^11.0.10",
|
|
22
|
-
"@nestjs/typeorm": "^11.0.0",
|
|
23
|
-
"change-case-commonjs": "^5.4.4",
|
|
24
|
-
"reflect-metadata": "^0.1.12 || ^0.2.0",
|
|
25
|
-
"rxjs": "^7.1.0",
|
|
26
|
-
"tslib": ">2.3.0",
|
|
27
|
-
"typeorm": "^0.3.20"
|
|
28
|
-
},
|
|
3
|
+
"version": "0.1.0-beta.10",
|
|
29
4
|
"type": "commonjs",
|
|
30
5
|
"main": "./src/index.js",
|
|
31
6
|
"typings": "./src/index.d.ts",
|
|
@@ -39,19 +14,11 @@
|
|
|
39
14
|
"microorm",
|
|
40
15
|
"CRUD"
|
|
41
16
|
],
|
|
42
|
-
"publishConfig": {
|
|
43
|
-
"access": "public"
|
|
44
|
-
},
|
|
45
17
|
"peerDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@klerick/json-api-nestjs-shared": "1.0.0-beta.1",
|
|
49
|
-
"@nestjs/core": "11.0.10",
|
|
50
|
-
"@nestjs/swagger": "11.0.4",
|
|
51
|
-
"ts-toolbelt": "9.6.0",
|
|
52
|
-
"zod": "3.24.1",
|
|
53
|
-
"zod-validation-error": "3.4.0"
|
|
18
|
+
"@klerick/json-api-nestjs": "^10.0.0-beta.12",
|
|
19
|
+
"@nestjs/typeorm": "^11.0.0"
|
|
54
20
|
},
|
|
21
|
+
"dependencies": {},
|
|
55
22
|
"exports": {
|
|
56
23
|
"./package.json": "./package.json",
|
|
57
24
|
".": {
|
|
@@ -59,5 +26,25 @@
|
|
|
59
26
|
"default": "./src/index.js"
|
|
60
27
|
}
|
|
61
28
|
},
|
|
62
|
-
"types": "./src/index.d.ts"
|
|
29
|
+
"types": "./src/index.d.ts",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"contributors": [
|
|
32
|
+
{
|
|
33
|
+
"email": "klerick666@gmain.com",
|
|
34
|
+
"name": "Aleksandr Kharkovey"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/klerick/nestjs-json-api.git"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">= 20.0.0"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"**/*"
|
|
46
|
+
],
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
63
50
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/type-orm-json-api.module';
|
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/json-api/json-api-nestjs-typeorm/src/index.ts"],"names":[],"mappings":";;;AAAA,yEAA+C"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const SUB_QUERY_ALIAS_FOR_PAGINATION = "subQueryWithLimitOffset";
|
|
2
|
+
export declare const ALIAS_FOR_PAGINATION = "aliasForPagination";
|
|
3
|
+
export declare const DEFAULT_CONNECTION_NAME = "default";
|
|
4
|
+
export declare const CURRENT_ENTITY_REPOSITORY: unique symbol;
|
|
5
|
+
export declare const CURRENT_DATA_SOURCE_TOKEN: unique symbol;
|
|
6
|
+
export declare const CURRENT_ENTITY_MANAGER_TOKEN: unique symbol;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CURRENT_ENTITY_MANAGER_TOKEN = exports.CURRENT_DATA_SOURCE_TOKEN = exports.CURRENT_ENTITY_REPOSITORY = exports.DEFAULT_CONNECTION_NAME = exports.ALIAS_FOR_PAGINATION = exports.SUB_QUERY_ALIAS_FOR_PAGINATION = void 0;
|
|
4
|
+
exports.SUB_QUERY_ALIAS_FOR_PAGINATION = 'subQueryWithLimitOffset';
|
|
5
|
+
exports.ALIAS_FOR_PAGINATION = 'aliasForPagination';
|
|
6
|
+
exports.DEFAULT_CONNECTION_NAME = 'default';
|
|
7
|
+
exports.CURRENT_ENTITY_REPOSITORY = Symbol('CURRENT_ENTITY_REPOSITORY');
|
|
8
|
+
exports.CURRENT_DATA_SOURCE_TOKEN = Symbol('CURRENT_DATA_SOURCE_TOKEN');
|
|
9
|
+
exports.CURRENT_ENTITY_MANAGER_TOKEN = Symbol('CURRENT_ENTITY_MANAGER_TOKEN');
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/json-api/json-api-nestjs-typeorm/src/lib/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,8BAA8B,GAAG,yBAAyB,CAAC;AAC3D,QAAA,oBAAoB,GAAG,oBAAoB,CAAC;AAC5C,QAAA,uBAAuB,GAAG,SAAS,CAAC;AACpC,QAAA,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAChE,QAAA,yBAAyB,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAChE,QAAA,4BAA4B,GAAG,MAAM,CAChD,8BAA8B,CAC/B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { FactoryProvider } from '@nestjs/common';
|
|
2
|
+
import { EntityParam, CheckRelationName, FindOneRowEntity, RunInTransaction } from '@klerick/json-api-nestjs';
|
|
3
|
+
import { DataSource, EntityManager, Repository } from 'typeorm';
|
|
4
|
+
import { TypeOrmService } from '../service';
|
|
5
|
+
import { EntityClass } from '@mikro-orm/core';
|
|
6
|
+
export declare function CurrentDataSourceProvider(connectionName?: string): FactoryProvider<DataSource>;
|
|
7
|
+
export declare function CurrentEntityManager(): FactoryProvider<EntityManager>;
|
|
8
|
+
export declare function CurrentEntityRepository<E extends object>(entity: E): FactoryProvider<Repository<E>>;
|
|
9
|
+
export declare function EntityPropsMap<E extends object>(entities: EntityClass<E>[]): {
|
|
10
|
+
provide: symbol;
|
|
11
|
+
inject: symbol[];
|
|
12
|
+
useFactory: (entityManager: EntityManager) => Map<EntityClass<E>, EntityParam<E>>;
|
|
13
|
+
};
|
|
14
|
+
export declare function FindOneRowEntityFactory<E extends object>(): FactoryProvider<FindOneRowEntity<E>>;
|
|
15
|
+
export declare function CheckRelationNameFactory<E extends object, IdKey extends string = 'id'>(): FactoryProvider<CheckRelationName<E>>;
|
|
16
|
+
export declare function RunInTransactionFactory(): FactoryProvider<RunInTransaction>;
|
|
17
|
+
export declare function OrmServiceFactory(): {
|
|
18
|
+
provide: symbol;
|
|
19
|
+
useClass: typeof TypeOrmService;
|
|
20
|
+
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentDataSourceProvider = CurrentDataSourceProvider;
|
|
4
|
+
exports.CurrentEntityManager = CurrentEntityManager;
|
|
5
|
+
exports.CurrentEntityRepository = CurrentEntityRepository;
|
|
6
|
+
exports.EntityPropsMap = EntityPropsMap;
|
|
7
|
+
exports.FindOneRowEntityFactory = FindOneRowEntityFactory;
|
|
8
|
+
exports.CheckRelationNameFactory = CheckRelationNameFactory;
|
|
9
|
+
exports.RunInTransactionFactory = RunInTransactionFactory;
|
|
10
|
+
exports.OrmServiceFactory = OrmServiceFactory;
|
|
11
|
+
const typeorm_1 = require("@nestjs/typeorm");
|
|
12
|
+
const json_api_nestjs_1 = require("@klerick/json-api-nestjs");
|
|
13
|
+
const json_api_nestjs_shared_1 = require("@klerick/json-api-nestjs-shared");
|
|
14
|
+
const change_case_commonjs_1 = require("change-case-commonjs");
|
|
15
|
+
const constants_1 = require("../constants");
|
|
16
|
+
const service_1 = require("../service");
|
|
17
|
+
const orm_helper_1 = require("../orm-helper");
|
|
18
|
+
function CurrentDataSourceProvider(connectionName) {
|
|
19
|
+
return {
|
|
20
|
+
provide: constants_1.CURRENT_DATA_SOURCE_TOKEN,
|
|
21
|
+
useFactory: (dataSource) => dataSource,
|
|
22
|
+
inject: [(0, typeorm_1.getDataSourceToken)(connectionName)],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function CurrentEntityManager() {
|
|
26
|
+
return {
|
|
27
|
+
provide: constants_1.CURRENT_ENTITY_MANAGER_TOKEN,
|
|
28
|
+
useFactory: (dataSource) => dataSource.manager,
|
|
29
|
+
inject: [constants_1.CURRENT_DATA_SOURCE_TOKEN],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function CurrentEntityRepository(entity) {
|
|
33
|
+
return {
|
|
34
|
+
provide: constants_1.CURRENT_ENTITY_REPOSITORY,
|
|
35
|
+
useFactory: (entityManager) => entityManager.getRepository(entity),
|
|
36
|
+
inject: [constants_1.CURRENT_ENTITY_MANAGER_TOKEN],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function EntityPropsMap(entities) {
|
|
40
|
+
return {
|
|
41
|
+
provide: json_api_nestjs_1.ENTITY_PARAM_MAP,
|
|
42
|
+
inject: [constants_1.CURRENT_ENTITY_MANAGER_TOKEN],
|
|
43
|
+
useFactory: (entityManager) => {
|
|
44
|
+
const mapProperty = new Map();
|
|
45
|
+
for (const item of entities) {
|
|
46
|
+
const entityRepo = entityManager.getRepository(item);
|
|
47
|
+
const className = (0, json_api_nestjs_shared_1.getEntityName)(item);
|
|
48
|
+
mapProperty.set(item, {
|
|
49
|
+
props: (0, orm_helper_1.getProps)(entityRepo),
|
|
50
|
+
propsType: (0, orm_helper_1.getPropsType)(entityRepo),
|
|
51
|
+
propsNullable: (0, orm_helper_1.getPropsNullable)(entityRepo),
|
|
52
|
+
primaryColumnName: (0, orm_helper_1.getPrimaryColumnName)(entityRepo),
|
|
53
|
+
primaryColumnType: (0, orm_helper_1.getPrimaryColumnType)(entityRepo),
|
|
54
|
+
propsArrayType: (0, orm_helper_1.getArrayType)(entityRepo),
|
|
55
|
+
typeName: (0, change_case_commonjs_1.kebabCase)(className),
|
|
56
|
+
className: className,
|
|
57
|
+
relations: (0, orm_helper_1.getRelation)(entityRepo),
|
|
58
|
+
relationProperty: (0, orm_helper_1.getRelationProperty)(entityRepo),
|
|
59
|
+
relationFkField: (0, orm_helper_1.getRelationFkField)(entityRepo),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return mapProperty;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function FindOneRowEntityFactory() {
|
|
67
|
+
return {
|
|
68
|
+
provide: json_api_nestjs_1.FIND_ONE_ROW_ENTITY,
|
|
69
|
+
inject: [constants_1.CURRENT_ENTITY_REPOSITORY, service_1.TypeormUtilsService],
|
|
70
|
+
useFactory: (repository, typeormUtilsService) => {
|
|
71
|
+
return async (entity, value) => {
|
|
72
|
+
const params = 'params';
|
|
73
|
+
return await repository
|
|
74
|
+
.createQueryBuilder(typeormUtilsService.currentAlias)
|
|
75
|
+
.where(`${typeormUtilsService.getAliasPath(typeormUtilsService.currentPrimaryColumn)} = :${params}`)
|
|
76
|
+
.setParameters({
|
|
77
|
+
[params]: value,
|
|
78
|
+
})
|
|
79
|
+
.getOne();
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function CheckRelationNameFactory() {
|
|
85
|
+
return {
|
|
86
|
+
provide: json_api_nestjs_1.CHECK_RELATION_NAME,
|
|
87
|
+
inject: [service_1.TypeormUtilsService],
|
|
88
|
+
useFactory(typeormUtilsService) {
|
|
89
|
+
return (entity, value) => !!typeormUtilsService.relationFields.find((i) => i === value);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function RunInTransactionFactory() {
|
|
94
|
+
return {
|
|
95
|
+
provide: json_api_nestjs_1.RUN_IN_TRANSACTION_FUNCTION,
|
|
96
|
+
inject: [json_api_nestjs_1.MODULE_OPTIONS_TOKEN, constants_1.CURRENT_DATA_SOURCE_TOKEN],
|
|
97
|
+
useFactory(options, dataSource) {
|
|
98
|
+
const { options: { runInTransaction }, } = options;
|
|
99
|
+
if (runInTransaction && typeof runInTransaction === 'function') {
|
|
100
|
+
return (callback) => runInTransaction('READ COMMITTED', () => callback());
|
|
101
|
+
}
|
|
102
|
+
return async (callback) => {
|
|
103
|
+
const queryRunner = dataSource.createQueryRunner();
|
|
104
|
+
await queryRunner.startTransaction('READ UNCOMMITTED');
|
|
105
|
+
let result;
|
|
106
|
+
try {
|
|
107
|
+
result = await callback();
|
|
108
|
+
await queryRunner.commitTransaction();
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
await queryRunner.rollbackTransaction();
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
await queryRunner.release();
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function OrmServiceFactory() {
|
|
123
|
+
return {
|
|
124
|
+
provide: json_api_nestjs_1.ORM_SERVICE,
|
|
125
|
+
useClass: service_1.TypeOrmService,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../libs/json-api/json-api-nestjs-typeorm/src/lib/factory/index.ts"],"names":[],"mappings":";;AA2CA,8DAQC;AAED,oDAMC;AAED,0DASC;AAED,wCA4BC;AAED,0DA0BC;AAED,4DAcC;AAED,0DA+BC;AAED,8CAKC;AAvLD,6CAAqD;AACrD,8DAYkC;AAClC,4EAAgE;AAEhE,+DAAiD;AAGjD,4CAIsB;AAEtB,wCAAiE;AAIjE,8CAUuB;AAGvB,SAAgB,yBAAyB,CACvC,cAAuB;IAEvB,OAAO;QACL,OAAO,EAAE,qCAAyB;QAClC,UAAU,EAAE,CAAC,UAAsB,EAAE,EAAE,CAAC,UAAU;QAClD,MAAM,EAAE,CAAC,IAAA,4BAAkB,EAAC,cAAc,CAAC,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED,SAAgB,oBAAoB;IAClC,OAAO;QACL,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AAU,CAAC,OAAoC,EAAE,UAAsB;YACrE,MAAM,EACJ,OAAO,EAAE,EAAE,gBAAgB,EAAE,GAC9B,GAAG,OAAO,CAAC;YAEZ,IAAI,gBAAgB,IAAI,OAAO,gBAAgB,KAAK,UAAU,EAAE,CAAC;gBAC/D,OAAO,CAAC,QAAQ,EAAE,EAAE,CAClB,gBAAgB,CAAC,gBAAgB,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;YACzD,CAAC;YAED,OAAO,KAAK,EAAE,QAAQ,EAAE,EAAE;gBACxB,MAAM,WAAW,GAAG,UAAU,CAAC,iBAAiB,EAAE,CAAC;gBACnD,MAAM,WAAW,CAAC,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;gBACvD,IAAI,MAAe,CAAC;gBACpB,IAAI,CAAC;oBACH,MAAM,GAAG,MAAM,QAAQ,EAAE,CAAC;oBAC1B,MAAM,WAAW,CAAC,iBAAiB,EAAE,CAAC;gBACxC,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,MAAM,WAAW,CAAC,mBAAmB,EAAE,CAAC;oBACxC,MAAM,CAAC,CAAC;gBACV,CAAC;wBAAS,CAAC;oBACT,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;gBAC9B,CAAC;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAgB,iBAAiB;IAC/B,OAAO;QACL,OAAO,EAAE,6BAAW;QACpB,QAAQ,EAAE,wBAAc;KACzB,CAAC;AACJ,CAAC"}
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./type-orm-json-api.module"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./type"), exports);
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../libs/json-api/json-api-nestjs-typeorm/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,qEAA2C;AAC3C,iDAAuB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Brackets } from 'typeorm';
|
|
2
|
+
import { TypeormUtilsService } from '../service';
|
|
3
|
+
/**
|
|
4
|
+
* Extract all relation field names from ACL rulesForQuery
|
|
5
|
+
* @param rules - ACL rules object
|
|
6
|
+
* @param typeormUtils - TypeORM utils service
|
|
7
|
+
* @returns Set of relation field names used in the rules
|
|
8
|
+
*/
|
|
9
|
+
export declare function extractRelationsFromRules<E extends object, IdKey extends string>(rules: Record<string, unknown>, typeormUtils: TypeormUtilsService<E, IdKey>): Set<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Converts ACL rulesForQuery (MikroORM-like format) to TypeORM QueryBuilder conditions
|
|
12
|
+
*
|
|
13
|
+
* @param rulesForQuery - MongoDB-like query object from ExtendAbility.getQueryObject()
|
|
14
|
+
* @param typeormUtils - TypeORM utils service for getting aliases and paths
|
|
15
|
+
* @param hasExistingWhere - Whether queryBuilder already has WHERE conditions
|
|
16
|
+
* @returns Callback function for queryBuilder.andWhere() or queryBuilder.where()
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // With existing WHERE
|
|
20
|
+
* const callback = applyAclRulesToQueryBuilder(
|
|
21
|
+
* { authorId: 123, profile: { isPublic: true } },
|
|
22
|
+
* typeormUtils,
|
|
23
|
+
* true
|
|
24
|
+
* );
|
|
25
|
+
* queryBuilder.andWhere(callback);
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Without existing WHERE
|
|
29
|
+
* const callback = applyAclRulesToQueryBuilder(
|
|
30
|
+
* { authorId: 123 },
|
|
31
|
+
* typeormUtils,
|
|
32
|
+
* false
|
|
33
|
+
* );
|
|
34
|
+
* callback(queryBuilder);
|
|
35
|
+
*/
|
|
36
|
+
export declare function applyAclRulesToQueryBuilder<E extends object, IdKey extends string>(rulesForQuery: Record<string, unknown>, typeormUtils: TypeormUtilsService<E, IdKey>): Brackets;
|