@abejarano/ts-mongodb-criteria 1.4.0 → 1.5.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 +21 -1
- package/dist/cjs/mongo/IRepository.js +2 -0
- package/dist/cjs/mongo/index.js +1 -0
- package/dist/esm/mongo/IRepository.js +1 -0
- package/dist/esm/mongo/index.js +1 -0
- package/dist/types/mongo/IRepository.d.ts +8 -0
- package/dist/types/mongo/index.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -147,19 +147,39 @@ const criteria = new Criteria(
|
|
|
147
147
|
|
|
148
148
|
// 3. Use with your MongoDB repository
|
|
149
149
|
class UserRepository extends MongoRepository<User> {
|
|
150
|
+
constructor() {
|
|
151
|
+
super(User)
|
|
152
|
+
}
|
|
153
|
+
|
|
150
154
|
collectionName(): string {
|
|
151
155
|
return "users"
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
const userRepo = new UserRepository()
|
|
156
|
-
const
|
|
160
|
+
const { results } = await userRepo.list(criteria)
|
|
157
161
|
```
|
|
158
162
|
|
|
159
163
|
MongoRepository provides ready-to-use public methods for repositories that extend it:
|
|
160
164
|
- `list(criteria, fieldsToExclude?)` for paginated queries
|
|
161
165
|
- `one(filter)` to fetch a single entity
|
|
162
166
|
- `upsert(entity)` to persist an aggregate
|
|
167
|
+
Internal helpers are private, so repositories should call these public methods
|
|
168
|
+
directly.
|
|
169
|
+
|
|
170
|
+
If you need a repository interface in your app, extend `IRepository<T>` so your
|
|
171
|
+
custom interfaces stay aligned with the library return types:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { IRepository } from "@abejarano/ts-mongodb-criteria"
|
|
175
|
+
|
|
176
|
+
export interface IUserRepository extends IRepository<User> {
|
|
177
|
+
// Add domain-specific methods here
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The goal of `IRepository` is to prevent signature drift (e.g. `upsert` returning
|
|
182
|
+
`void` in your app while the base repository returns `ObjectId | null`).
|
|
163
183
|
|
|
164
184
|
**Your First Query in 30 Seconds:**
|
|
165
185
|
|
package/dist/cjs/mongo/index.js
CHANGED
|
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./MongoCriteriaConverter"), exports);
|
|
18
18
|
__exportStar(require("./MongoRepository"), exports);
|
|
19
|
+
__exportStar(require("./IRepository"), exports);
|
|
19
20
|
__exportStar(require("./MongoClientFactory"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/mongo/index.js
CHANGED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ObjectId } from "mongodb";
|
|
2
|
+
import { Criteria, Paginate } from "../criteria";
|
|
3
|
+
import { AggregateRoot } from "../AggregateRoot";
|
|
4
|
+
export interface IRepository<T extends AggregateRoot> {
|
|
5
|
+
one(filter: object): Promise<T | null>;
|
|
6
|
+
list<D>(criteria: Criteria, fieldsToExclude?: string[]): Promise<Paginate<D>>;
|
|
7
|
+
upsert(entity: T): Promise<ObjectId | null>;
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@abejarano/ts-mongodb-criteria",
|
|
3
3
|
"author": "angel bejarano / angel.bejarano@jaspesoft.com",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.5.0",
|
|
5
5
|
"description": "Patrón Criteria para consultas MongoDB en TypeScript",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
7
7
|
"module": "dist/esm/index.js",
|