@introspectivelabs/nestjs-typeorm 0.1.0-beta.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 +73 -0
- package/dist/base.repository.d.ts +77 -0
- package/dist/base.repository.d.ts.map +1 -0
- package/dist/base.repository.js +125 -0
- package/dist/base.repository.js.map +1 -0
- package/dist/entity-repository.d.ts +12 -0
- package/dist/entity-repository.d.ts.map +1 -0
- package/dist/entity-repository.js +46 -0
- package/dist/entity-repository.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @introspectivelabs/nestjs-typeorm
|
|
2
|
+
|
|
3
|
+
Reusable NestJS TypeORM utilities: `BaseRepository` with pagination and `EntityRepository` factory.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @introspectivelabs/nestjs-typeorm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Peer Dependencies
|
|
12
|
+
|
|
13
|
+
- `@nestjs/common` >= 10.0.0
|
|
14
|
+
- `@nestjs/typeorm` >= 10.0.0
|
|
15
|
+
- `nestjs-typeorm-paginate` >= 4.0.0
|
|
16
|
+
- `typeorm` >= 0.3.0
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
### EntityRepository Factory
|
|
21
|
+
|
|
22
|
+
Create a typed repository class with automatic dependency injection:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { EntityRepository } from "@introspectivelabs/nestjs-typeorm";
|
|
26
|
+
import { User } from "./user.entity";
|
|
27
|
+
|
|
28
|
+
@Injectable()
|
|
29
|
+
export class UserRepository extends EntityRepository(User) {}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Register it in your module:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
@Module({
|
|
36
|
+
imports: [TypeOrmModule.forFeature([User])],
|
|
37
|
+
providers: [UserRepository],
|
|
38
|
+
exports: [UserRepository],
|
|
39
|
+
})
|
|
40
|
+
export class UserModule {}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### BaseRepository Methods
|
|
44
|
+
|
|
45
|
+
All repositories created with `EntityRepository` extend `BaseRepository`, which provides:
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Pagination
|
|
49
|
+
await repo.paginate(queryBuilder, { limit: 10, page: 1 });
|
|
50
|
+
await repo.paginateRaw(queryBuilder, options);
|
|
51
|
+
await repo.paginateRawEntities(queryBuilder, options);
|
|
52
|
+
|
|
53
|
+
// CRUD helpers
|
|
54
|
+
await repo.findOneByIdOrFail(id);
|
|
55
|
+
await repo.createOne({ name: "New Entity" });
|
|
56
|
+
await repo.createMany([{ name: "A" }, { name: "B" }]);
|
|
57
|
+
await repo.updateOneById(id, { name: "Updated" });
|
|
58
|
+
await repo.deleteOneById(id);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Default pagination options: `{ limit: 15, page: 1 }`.
|
|
62
|
+
|
|
63
|
+
### Multiple DataSources
|
|
64
|
+
|
|
65
|
+
Pass a connection name to `EntityRepository`:
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
export class AuditRepository extends EntityRepository(AuditLog, "audit-connection") {}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
Apache-2.0
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Repository, EntityTarget, DataSource, DeepPartial, ObjectLiteral, SelectQueryBuilder } from "typeorm";
|
|
2
|
+
import { IPaginationOptions, Pagination } from "nestjs-typeorm-paginate";
|
|
3
|
+
export type ID = number | string;
|
|
4
|
+
export declare const defaultPaginationOptions: {
|
|
5
|
+
limit: number;
|
|
6
|
+
page: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Generic repository with built-in pagination and CRUD helpers.
|
|
10
|
+
*/
|
|
11
|
+
export declare class BaseRepository<Entity extends ObjectLiteral> extends Repository<Entity> {
|
|
12
|
+
/**
|
|
13
|
+
* Creates a BaseRepository bound to the given entity and data source.
|
|
14
|
+
*
|
|
15
|
+
* @param target - the entity class to bind
|
|
16
|
+
* @param dataSource - the TypeORM data source
|
|
17
|
+
*/
|
|
18
|
+
constructor(target: EntityTarget<Entity>, dataSource: DataSource);
|
|
19
|
+
/**
|
|
20
|
+
* Paginate using a query builder.
|
|
21
|
+
*
|
|
22
|
+
* @returns paginated result
|
|
23
|
+
*/
|
|
24
|
+
paginate(queryBuilder: SelectQueryBuilder<Entity>, paginationOptions?: IPaginationOptions): Promise<Pagination<Entity>>;
|
|
25
|
+
/**
|
|
26
|
+
* Paginate raw query results from a query builder.
|
|
27
|
+
*
|
|
28
|
+
* @param queryBuilder - the query builder to paginate
|
|
29
|
+
* @param paginationOptions - pagination options merged with defaults
|
|
30
|
+
* @returns paginated raw result
|
|
31
|
+
*/
|
|
32
|
+
paginateRaw(queryBuilder: SelectQueryBuilder<Entity>, paginationOptions?: IPaginationOptions): Promise<Pagination<Entity>>;
|
|
33
|
+
/**
|
|
34
|
+
* Paginate raw results along with mapped entities from a query builder.
|
|
35
|
+
*
|
|
36
|
+
* @param queryBuilder - the query builder to paginate
|
|
37
|
+
* @param paginationOptions - pagination options merged with defaults
|
|
38
|
+
* @returns tuple of paginated result and partial entities
|
|
39
|
+
*/
|
|
40
|
+
paginateRawEntities(queryBuilder: SelectQueryBuilder<Entity>, paginationOptions?: IPaginationOptions): Promise<[Pagination<Entity>, Partial<Entity>[]]>;
|
|
41
|
+
/**
|
|
42
|
+
* Find a single entity by ID or throw if not found.
|
|
43
|
+
*
|
|
44
|
+
* @param id - the entity ID
|
|
45
|
+
* @returns the found entity
|
|
46
|
+
*/
|
|
47
|
+
findOneByIdOrFail(id: ID): Promise<Entity>;
|
|
48
|
+
/**
|
|
49
|
+
* Create and persist a single entity.
|
|
50
|
+
*
|
|
51
|
+
* @param data - the entity data
|
|
52
|
+
* @returns the saved entity
|
|
53
|
+
*/
|
|
54
|
+
createOne(data: DeepPartial<Entity>): Promise<Entity>;
|
|
55
|
+
/**
|
|
56
|
+
* Create and persist multiple entities.
|
|
57
|
+
*
|
|
58
|
+
* @param data - array of entity data
|
|
59
|
+
* @returns the saved entities
|
|
60
|
+
*/
|
|
61
|
+
createMany(data: DeepPartial<Entity>[]): Promise<Entity[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Update a single entity by ID using preload and save.
|
|
64
|
+
*
|
|
65
|
+
* @param id - the entity ID
|
|
66
|
+
* @param data - the partial update data
|
|
67
|
+
* @returns the updated entity
|
|
68
|
+
*/
|
|
69
|
+
updateOneById(id: ID, data: DeepPartial<Entity>): Promise<Entity>;
|
|
70
|
+
/**
|
|
71
|
+
* Delete a single entity by ID.
|
|
72
|
+
*
|
|
73
|
+
* @param id - the entity ID
|
|
74
|
+
*/
|
|
75
|
+
deleteOneById(id: ID): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=base.repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.repository.d.ts","sourceRoot":"","sources":["../src/base.repository.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,UAAU,EACV,WAAW,EAEX,aAAa,EACb,kBAAkB,EAEnB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,kBAAkB,EAIlB,UAAU,EACX,MAAM,yBAAyB,CAAC;AAEjC,MAAM,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,CAAC;AACjC,eAAO,MAAM,wBAAwB;;;CAGpC,CAAC;AAEF;;GAEG;AACH,qBAAa,cAAc,CAAC,MAAM,SAAS,aAAa,CAAE,SAAQ,UAAU,CAAC,MAAM,CAAC;IAClF;;;;;OAKG;gBACS,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,UAAU;IAIhE;;;;OAIG;IACG,QAAQ,CACZ,YAAY,EAAE,kBAAkB,CAAC,MAAM,CAAC,EACxC,iBAAiB,CAAC,EAAE,kBAAkB,GACrC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IA2C9B;;;;;;OAMG;IACG,WAAW,CACf,YAAY,EAAE,kBAAkB,CAAC,MAAM,CAAC,EACxC,iBAAiB,CAAC,EAAE,kBAAkB,GACrC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAO9B;;;;;;OAMG;IACG,mBAAmB,CACvB,YAAY,EAAE,kBAAkB,CAAC,MAAM,CAAC,EACxC,iBAAiB,CAAC,EAAE,kBAAkB,GACrC,OAAO,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAOnD;;;;;OAKG;IACG,iBAAiB,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhD;;;;;OAKG;IACG,SAAS,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAK3D;;;;;OAKG;IACG,UAAU,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAKhE;;;;;;OAMG;IACG,aAAa,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvE;;;;OAIG;IACG,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAG3C"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseRepository = exports.defaultPaginationOptions = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const nestjs_typeorm_paginate_1 = require("nestjs-typeorm-paginate");
|
|
6
|
+
exports.defaultPaginationOptions = {
|
|
7
|
+
limit: 15,
|
|
8
|
+
page: 1,
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Generic repository with built-in pagination and CRUD helpers.
|
|
12
|
+
*/
|
|
13
|
+
class BaseRepository extends typeorm_1.Repository {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a BaseRepository bound to the given entity and data source.
|
|
16
|
+
*
|
|
17
|
+
* @param target - the entity class to bind
|
|
18
|
+
* @param dataSource - the TypeORM data source
|
|
19
|
+
*/
|
|
20
|
+
constructor(target, dataSource) {
|
|
21
|
+
super(target, dataSource.createEntityManager());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Paginate a repository, query builder, or the current instance.
|
|
25
|
+
*
|
|
26
|
+
* @param target - a Repository, SelectQueryBuilder, or undefined to use self
|
|
27
|
+
* @param paginationOptions - pagination options merged with defaults
|
|
28
|
+
* @param searchOptions - optional search/filter criteria
|
|
29
|
+
* @returns paginated result
|
|
30
|
+
*/
|
|
31
|
+
async paginate(target, paginationOptions, searchOptions) {
|
|
32
|
+
if (target instanceof typeorm_1.Repository) {
|
|
33
|
+
return await (0, nestjs_typeorm_paginate_1.paginate)(target, {
|
|
34
|
+
...exports.defaultPaginationOptions,
|
|
35
|
+
...paginationOptions,
|
|
36
|
+
}, searchOptions);
|
|
37
|
+
}
|
|
38
|
+
if (target instanceof typeorm_1.SelectQueryBuilder) {
|
|
39
|
+
return await (0, nestjs_typeorm_paginate_1.paginate)(target, {
|
|
40
|
+
...exports.defaultPaginationOptions,
|
|
41
|
+
...paginationOptions,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return await (0, nestjs_typeorm_paginate_1.paginate)(this, {
|
|
45
|
+
...exports.defaultPaginationOptions,
|
|
46
|
+
...paginationOptions,
|
|
47
|
+
}, searchOptions);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Paginate raw query results from a query builder.
|
|
51
|
+
*
|
|
52
|
+
* @param queryBuilder - the query builder to paginate
|
|
53
|
+
* @param paginationOptions - pagination options merged with defaults
|
|
54
|
+
* @returns paginated raw result
|
|
55
|
+
*/
|
|
56
|
+
async paginateRaw(queryBuilder, paginationOptions) {
|
|
57
|
+
return await (0, nestjs_typeorm_paginate_1.paginateRaw)(queryBuilder, {
|
|
58
|
+
...exports.defaultPaginationOptions,
|
|
59
|
+
...paginationOptions,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Paginate raw results along with mapped entities from a query builder.
|
|
64
|
+
*
|
|
65
|
+
* @param queryBuilder - the query builder to paginate
|
|
66
|
+
* @param paginationOptions - pagination options merged with defaults
|
|
67
|
+
* @returns tuple of paginated result and partial entities
|
|
68
|
+
*/
|
|
69
|
+
async paginateRawEntities(queryBuilder, paginationOptions) {
|
|
70
|
+
return await (0, nestjs_typeorm_paginate_1.paginateRawAndEntities)(queryBuilder, {
|
|
71
|
+
...exports.defaultPaginationOptions,
|
|
72
|
+
...paginationOptions,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Find a single entity by ID or throw if not found.
|
|
77
|
+
*
|
|
78
|
+
* @param id - the entity ID
|
|
79
|
+
* @returns the found entity
|
|
80
|
+
*/
|
|
81
|
+
async findOneByIdOrFail(id) {
|
|
82
|
+
return this.findOneByOrFail({ id });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create and persist a single entity.
|
|
86
|
+
*
|
|
87
|
+
* @param data - the entity data
|
|
88
|
+
* @returns the saved entity
|
|
89
|
+
*/
|
|
90
|
+
async createOne(data) {
|
|
91
|
+
const entity = this.create(data);
|
|
92
|
+
return this.save(entity, { reload: true });
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create and persist multiple entities.
|
|
96
|
+
*
|
|
97
|
+
* @param data - array of entity data
|
|
98
|
+
* @returns the saved entities
|
|
99
|
+
*/
|
|
100
|
+
async createMany(data) {
|
|
101
|
+
const entities = data.map(item => this.create(item));
|
|
102
|
+
return this.save(entities);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Update a single entity by ID using preload and save.
|
|
106
|
+
*
|
|
107
|
+
* @param id - the entity ID
|
|
108
|
+
* @param data - the partial update data
|
|
109
|
+
* @returns the updated entity
|
|
110
|
+
*/
|
|
111
|
+
async updateOneById(id, data) {
|
|
112
|
+
const entity = await this.preload({ id, ...data });
|
|
113
|
+
return this.save(entity, { reload: true });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Delete a single entity by ID.
|
|
117
|
+
*
|
|
118
|
+
* @param id - the entity ID
|
|
119
|
+
*/
|
|
120
|
+
async deleteOneById(id) {
|
|
121
|
+
await this.delete({ id });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.BaseRepository = BaseRepository;
|
|
125
|
+
//# sourceMappingURL=base.repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.repository.js","sourceRoot":"","sources":["../src/base.repository.ts"],"names":[],"mappings":";;;AAAA,qCASiB;AACjB,qEAMiC;AAGpB,QAAA,wBAAwB,GAAG;IACtC,KAAK,EAAE,EAAE;IACT,IAAI,EAAE,CAAC;CACR,CAAC;AAEF;;GAEG;AACH,MAAa,cAA6C,SAAQ,oBAAkB;IAClF;;;;;OAKG;IACH,YAAY,MAA4B,EAAE,UAAsB;QAC9D,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAClD,CAAC;IAYD;;;;;;;OAOG;IACH,KAAK,CAAC,QAAQ,CACZ,MAAwD,EACxD,iBAAsC,EACtC,aAAkE;QAElE,IAAI,MAAM,YAAY,oBAAU,EAAE,CAAC;YACjC,OAAO,MAAM,IAAA,kCAAQ,EACnB,MAAM,EACN;gBACE,GAAG,gCAAwB;gBAC3B,GAAG,iBAAiB;aACrB,EACD,aAAa,CACd,CAAC;QACJ,CAAC;QAED,IAAI,MAAM,YAAY,4BAAkB,EAAE,CAAC;YACzC,OAAO,MAAM,IAAA,kCAAQ,EAAC,MAAM,EAAE;gBAC5B,GAAG,gCAAwB;gBAC3B,GAAG,iBAAiB;aACrB,CAAC,CAAC;QACL,CAAC;QAED,OAAO,MAAM,IAAA,kCAAQ,EACnB,IAAI,EACJ;YACE,GAAG,gCAAwB;YAC3B,GAAG,iBAAiB;SACrB,EACD,aAAa,CACd,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,WAAW,CACf,YAAwC,EACxC,iBAAsC;QAEtC,OAAO,MAAM,IAAA,qCAAW,EAAC,YAAY,EAAE;YACrC,GAAG,gCAAwB;YAC3B,GAAG,iBAAiB;SACrB,CAAC,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,mBAAmB,CACvB,YAAwC,EACxC,iBAAsC;QAEtC,OAAO,MAAM,IAAA,gDAAsB,EAAC,YAAY,EAAE;YAChD,GAAG,gCAAwB;YAC3B,GAAG,iBAAiB;SACrB,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,iBAAiB,CAAC,EAAM;QAC5B,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE,EAAE,EAAqC,CAAC,CAAC;IACzE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,SAAS,CAAC,IAAyB;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU,CAAC,IAA2B;QAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,aAAa,CAAC,EAAM,EAAE,IAAyB;QACnD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,aAAa,CAAC,EAAM;QACxB,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAgD,CAAC,CAAC;IAC1E,CAAC;CACF;AApJD,wCAoJC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DataSource, DataSourceOptions, ObjectLiteral } from "typeorm";
|
|
2
|
+
import { Type } from "@nestjs/common";
|
|
3
|
+
import { BaseRepository } from "./base.repository.js";
|
|
4
|
+
/**
|
|
5
|
+
* Factory that returns a repository class extending BaseRepository with DI wiring.
|
|
6
|
+
*
|
|
7
|
+
* @param entity - the entity class
|
|
8
|
+
* @param dataSourceOptions - optional data source or connection name
|
|
9
|
+
* @returns a repository class constructor
|
|
10
|
+
*/
|
|
11
|
+
export declare function EntityRepository<Entity extends ObjectLiteral>(entity: Type<Entity>, dataSourceOptions?: DataSource | DataSourceOptions | string): Type<BaseRepository<Entity>>;
|
|
12
|
+
//# sourceMappingURL=entity-repository.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-repository.d.ts","sourceRoot":"","sources":["../src/entity-repository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,SAAS,aAAa,EAC3D,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,EACpB,iBAAiB,CAAC,EAAE,UAAU,GAAG,iBAAiB,GAAG,MAAM,GAC1D,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAgB9B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.EntityRepository = EntityRepository;
|
|
16
|
+
const typeorm_1 = require("typeorm");
|
|
17
|
+
const typeorm_2 = require("@nestjs/typeorm");
|
|
18
|
+
const base_repository_js_1 = require("./base.repository.js");
|
|
19
|
+
/**
|
|
20
|
+
* Factory that returns a repository class extending BaseRepository with DI wiring.
|
|
21
|
+
*
|
|
22
|
+
* @param entity - the entity class
|
|
23
|
+
* @param dataSourceOptions - optional data source or connection name
|
|
24
|
+
* @returns a repository class constructor
|
|
25
|
+
*/
|
|
26
|
+
function EntityRepository(entity, dataSourceOptions) {
|
|
27
|
+
/**
|
|
28
|
+
* Internal repository class with injected data source.
|
|
29
|
+
*/
|
|
30
|
+
let Repo = class Repo extends base_repository_js_1.BaseRepository {
|
|
31
|
+
/**
|
|
32
|
+
* Creates the repository with the injected data source.
|
|
33
|
+
*
|
|
34
|
+
* @param dataSource - the injected TypeORM data source
|
|
35
|
+
*/
|
|
36
|
+
constructor(dataSource) {
|
|
37
|
+
super(entity, dataSource);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
Repo = __decorate([
|
|
41
|
+
__param(0, (0, typeorm_2.InjectDataSource)(dataSourceOptions)),
|
|
42
|
+
__metadata("design:paramtypes", [typeorm_1.DataSource])
|
|
43
|
+
], Repo);
|
|
44
|
+
return Repo;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=entity-repository.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-repository.js","sourceRoot":"","sources":["../src/entity-repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAYA,4CAmBC;AA/BD,qCAAuE;AAEvE,6CAAmD;AACnD,6DAAsD;AAEtD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAC9B,MAAoB,EACpB,iBAA2D;IAE3D;;OAEG;IACH,IAAM,IAAI,GAAV,MAAM,IAAuC,SAAQ,mCAAiB;QACpE;;;;WAIG;QACH,YAAiD,UAAsB;YACrE,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QAC5B,CAAC;KACF,CAAA;IATK,IAAI;QAMK,WAAA,IAAA,0BAAgB,EAAC,iBAAiB,CAAC,CAAA;yCAAa,oBAAU;OANnE,IAAI,CAST;IAED,OAAO,IAA+C,CAAC;AACzD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EntityRepository = exports.defaultPaginationOptions = exports.BaseRepository = void 0;
|
|
4
|
+
var base_repository_js_1 = require("./base.repository.js");
|
|
5
|
+
Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return base_repository_js_1.BaseRepository; } });
|
|
6
|
+
Object.defineProperty(exports, "defaultPaginationOptions", { enumerable: true, get: function () { return base_repository_js_1.defaultPaginationOptions; } });
|
|
7
|
+
var entity_repository_js_1 = require("./entity-repository.js");
|
|
8
|
+
Object.defineProperty(exports, "EntityRepository", { enumerable: true, get: function () { return entity_repository_js_1.EntityRepository; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAAoF;AAA3E,oHAAA,cAAc,OAAA;AAAM,8HAAA,wBAAwB,OAAA;AACrD,+DAA0D;AAAjD,wHAAA,gBAAgB,OAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@introspectivelabs/nestjs-typeorm",
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"types": "./dist/index.d.ts",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"nestjs",
|
|
8
|
+
"typeorm",
|
|
9
|
+
"repository",
|
|
10
|
+
"base-repository"
|
|
11
|
+
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"author": "Introspective Labs",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/Introspective-Labs/x402-modules.git",
|
|
17
|
+
"directory": "packages/nestjs-typeorm"
|
|
18
|
+
},
|
|
19
|
+
"description": "Reusable NestJS TypeORM utilities: BaseRepository with pagination and EntityRepository factory",
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"registry": "https://registry.npmjs.org"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@nestjs/common": ">=10.0.0",
|
|
26
|
+
"@nestjs/typeorm": ">=10.0.0",
|
|
27
|
+
"nestjs-typeorm-paginate": ">=4.0.0",
|
|
28
|
+
"typeorm": ">=0.3.0"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@eslint/js": "^9.24.0",
|
|
32
|
+
"@nestjs/common": "^11.0.1",
|
|
33
|
+
"@nestjs/core": "^11.0.1",
|
|
34
|
+
"@nestjs/testing": "^11.0.1",
|
|
35
|
+
"@nestjs/typeorm": "^11.0.0",
|
|
36
|
+
"@swc/core": "^1.15.11",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^8.29.1",
|
|
38
|
+
"@typescript-eslint/parser": "^8.29.1",
|
|
39
|
+
"eslint": "^9.24.0",
|
|
40
|
+
"eslint-plugin-import": "^2.31.0",
|
|
41
|
+
"eslint-plugin-jsdoc": "^50.6.9",
|
|
42
|
+
"eslint-plugin-prettier": "^5.2.6",
|
|
43
|
+
"nestjs-typeorm-paginate": "^4.1.0",
|
|
44
|
+
"prettier": "3.5.2",
|
|
45
|
+
"typeorm": "^0.3.27",
|
|
46
|
+
"typescript": "^5.7.3",
|
|
47
|
+
"unplugin-swc": "^1.5.9",
|
|
48
|
+
"vite": "^6.2.6",
|
|
49
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
50
|
+
"vitest": "^3.0.5"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist"
|
|
54
|
+
],
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsc",
|
|
57
|
+
"test": "vitest run",
|
|
58
|
+
"test:watch": "vitest",
|
|
59
|
+
"lint": "eslint . --ext .ts --fix",
|
|
60
|
+
"lint:check": "eslint . --ext .ts",
|
|
61
|
+
"format": "prettier -c .prettierrc --write \"**/*.{ts,js,cjs,json,md}\"",
|
|
62
|
+
"format:check": "prettier -c .prettierrc --check \"**/*.{ts,js,cjs,json,md}\"",
|
|
63
|
+
"publish:dev": "pnpm dlx yalc publish --push"
|
|
64
|
+
}
|
|
65
|
+
}
|