@declaro/data 2.0.0-beta.62 → 2.0.0-beta.63
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/dist/browser/index.js +2 -2
- package/dist/browser/index.js.map +3 -3
- package/dist/node/index.cjs +15 -8
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.js +15 -8
- package/dist/node/index.js.map +3 -3
- package/dist/ts/domain/interfaces/repository.d.ts +7 -0
- package/dist/ts/domain/interfaces/repository.d.ts.map +1 -1
- package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts +7 -0
- package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/domain/interfaces/repository.ts +8 -0
- package/src/test/mock/repositories/mock-memory-repository.test.ts +87 -0
- package/src/test/mock/repositories/mock-memory-repository.ts +22 -8
|
@@ -53,5 +53,12 @@ export interface IRepository<TSchema extends AnyModelSchema> {
|
|
|
53
53
|
* @returns A promise resolving to the detailed updated element.
|
|
54
54
|
*/
|
|
55
55
|
update(lookup: InferLookup<TSchema>, input: InferInput<TSchema>, options?: IUpdateOptions): Promise<InferDetail<TSchema>>;
|
|
56
|
+
/**
|
|
57
|
+
* Counts the number of elements matching the provided search criteria.
|
|
58
|
+
*
|
|
59
|
+
* @param search - The search criteria to apply.
|
|
60
|
+
* @returns A promise resolving to the count of matching elements.
|
|
61
|
+
*/
|
|
62
|
+
count(search: InferFilters<TSchema>, options?: ISearchOptions<TSchema>): Promise<number>;
|
|
56
63
|
}
|
|
57
64
|
//# sourceMappingURL=repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository.d.ts","sourceRoot":"","sources":["../../../../src/domain/interfaces/repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,kBAA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AAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IAE5F;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAA;IAE7F;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;IAE3F;;;;;OAKG;IACH,MAAM,CACF,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,EAC1B,OAAO,CAAC,EAAE,cAAc,GACzB,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;IAEhC;;;;;OAKG;IACH,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAC3F"}
|
|
@@ -21,6 +21,13 @@ export declare class MockMemoryRepository<TSchema extends AnyModelSchema> implem
|
|
|
21
21
|
restore(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
|
22
22
|
create(input: InferInput<TSchema>): Promise<InferDetail<TSchema>>;
|
|
23
23
|
update(lookup: InferLookup<TSchema>, input: InferInput<TSchema>): Promise<InferDetail<TSchema>>;
|
|
24
|
+
count(search: InferFilters<TSchema>, options?: ISearchOptions<TSchema> | undefined): Promise<number>;
|
|
25
|
+
/**
|
|
26
|
+
* Apply filtering logic to all items based on the provided search criteria
|
|
27
|
+
* @param input - The search/filter criteria
|
|
28
|
+
* @returns Filtered array of items
|
|
29
|
+
*/
|
|
30
|
+
protected applyFilters(input: InferFilters<TSchema>): InferDetail<TSchema>[];
|
|
24
31
|
protected generatePrimaryKey(): Promise<string | number>;
|
|
25
32
|
}
|
|
26
33
|
//# sourceMappingURL=mock-memory-repository.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-memory-repository.d.ts","sourceRoot":"","sources":["../../../../../src/test/mock/repositories/mock-memory-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAqB,MAAM,eAAe,CAAA;AAC5F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAA;AAExE,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,YAAY,EACf,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kDAAkD,CAAA;AAEtF,MAAM,WAAW,yBAAyB,CAAC,OAAO,SAAS,cAAc;IACrE,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,OAAO,CAAA;IAC9E,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,OAAO,CAAA;CACpF;AAED,qBAAa,oBAAoB,CAAC,OAAO,SAAS,cAAc,CAAE,YAAW,WAAW,CAAC,OAAO,CAAC;IAMjF,SAAS,CAAC,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC;IAL9D,SAAS,CAAC,IAAI,oCAA0C;IACxD,SAAS,CAAC,KAAK,oCAA0C;IACzD,SAAS,CAAC,cAAc,EAAE,oBAAoB,CAAA;IAC9C,SAAS,CAAC,MAAM,EAAE,MAAM,CAAI;gBAEN,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC;IAOxD,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAevE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IAQzE,MAAM,CACR,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,EAC5B,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAClC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"mock-memory-repository.d.ts","sourceRoot":"","sources":["../../../../../src/test/mock/repositories/mock-memory-repository.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAqB,MAAM,eAAe,CAAA;AAC5F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAA;AAExE,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,YAAY,EACf,MAAM,wCAAwC,CAAA;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kDAAkD,CAAA;AAEtF,MAAM,WAAW,yBAAyB,CAAC,OAAO,SAAS,cAAc;IACrE,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,OAAO,CAAA;IAC9E,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,OAAO,CAAA;CACpF;AAED,qBAAa,oBAAoB,CAAC,OAAO,SAAS,cAAc,CAAE,YAAW,WAAW,CAAC,OAAO,CAAC;IAMjF,SAAS,CAAC,IAAI,EAAE,yBAAyB,CAAC,OAAO,CAAC;IAL9D,S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EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,EAAE;cAW5D,kBAAkB;CAcrC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@declaro/data",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.63",
|
|
4
4
|
"description": "A data-mapper framework for managing application data across integrated systems.",
|
|
5
5
|
"main": "dist/node/index.cjs",
|
|
6
6
|
"module": "dist/browser/index.js",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"crypto-browserify": "^3.12.1"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@declaro/auth": "^2.0.0-beta.
|
|
28
|
-
"@declaro/core": "^2.0.0-beta.
|
|
29
|
-
"@declaro/zod": "^2.0.0-beta.
|
|
27
|
+
"@declaro/auth": "^2.0.0-beta.63",
|
|
28
|
+
"@declaro/core": "^2.0.0-beta.63",
|
|
29
|
+
"@declaro/zod": "^2.0.0-beta.63",
|
|
30
30
|
"typescript": "^5.8.3",
|
|
31
31
|
"uuid": "^11.1.0",
|
|
32
32
|
"zod": "^3.25.67"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
},
|
|
47
47
|
"require": "./dist/node/index.cjs"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "8bbb41bb0608d29d13d5a40f315e73ea552a0bdb"
|
|
50
50
|
}
|
|
@@ -71,4 +71,12 @@ export interface IRepository<TSchema extends AnyModelSchema> {
|
|
|
71
71
|
input: InferInput<TSchema>,
|
|
72
72
|
options?: IUpdateOptions,
|
|
73
73
|
): Promise<InferDetail<TSchema>>
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Counts the number of elements matching the provided search criteria.
|
|
77
|
+
*
|
|
78
|
+
* @param search - The search criteria to apply.
|
|
79
|
+
* @returns A promise resolving to the count of matching elements.
|
|
80
|
+
*/
|
|
81
|
+
count(search: InferFilters<TSchema>, options?: ISearchOptions<TSchema>): Promise<number>
|
|
74
82
|
}
|
|
@@ -380,4 +380,91 @@ describe('MockMemoryRepository', () => {
|
|
|
380
380
|
expect(results.pagination.totalPages).toBe(2)
|
|
381
381
|
})
|
|
382
382
|
})
|
|
383
|
+
|
|
384
|
+
describe('count functionality', () => {
|
|
385
|
+
it('should count all items when no filter is provided', async () => {
|
|
386
|
+
// Create test data
|
|
387
|
+
await repository.create({ title: 'Book 1', author: 'Author 1', publishedDate: new Date() })
|
|
388
|
+
await repository.create({ title: 'Book 2', author: 'Author 2', publishedDate: new Date() })
|
|
389
|
+
await repository.create({ title: 'Book 3', author: 'Author 3', publishedDate: new Date() })
|
|
390
|
+
|
|
391
|
+
const count = await repository.count({})
|
|
392
|
+
expect(count).toBe(3)
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
it('should count filtered items when filter function is provided', async () => {
|
|
396
|
+
const repositoryWithFilter = new MockMemoryRepository({
|
|
397
|
+
schema: mockSchema,
|
|
398
|
+
filter: (data, filters) => {
|
|
399
|
+
if (filters.text) {
|
|
400
|
+
return data.title.toLowerCase().includes(filters.text.toLowerCase())
|
|
401
|
+
}
|
|
402
|
+
return true
|
|
403
|
+
},
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
// Create test data
|
|
407
|
+
await repositoryWithFilter.create({ title: 'Test Book A', author: 'Author 1', publishedDate: new Date() })
|
|
408
|
+
await repositoryWithFilter.create({ title: 'Test Book B', author: 'Author 2', publishedDate: new Date() })
|
|
409
|
+
await repositoryWithFilter.create({ title: 'Other Book', author: 'Author 3', publishedDate: new Date() })
|
|
410
|
+
await repositoryWithFilter.create({ title: 'Another Book', author: 'Author 4', publishedDate: new Date() })
|
|
411
|
+
|
|
412
|
+
// Count all items
|
|
413
|
+
const totalCount = await repositoryWithFilter.count({})
|
|
414
|
+
expect(totalCount).toBe(4)
|
|
415
|
+
|
|
416
|
+
// Count filtered items
|
|
417
|
+
const filteredCount = await repositoryWithFilter.count({ text: 'Test' })
|
|
418
|
+
expect(filteredCount).toBe(2)
|
|
419
|
+
|
|
420
|
+
// Count with no matches
|
|
421
|
+
const noMatchCount = await repositoryWithFilter.count({ text: 'Ruby' })
|
|
422
|
+
expect(noMatchCount).toBe(0)
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
it('should count items correctly after CRUD operations', async () => {
|
|
426
|
+
const repositoryWithFilter = new MockMemoryRepository({
|
|
427
|
+
schema: mockSchema,
|
|
428
|
+
filter: (data, filters) => {
|
|
429
|
+
if (filters.text) {
|
|
430
|
+
return data.title.toLowerCase().includes(filters.text.toLowerCase())
|
|
431
|
+
}
|
|
432
|
+
return true
|
|
433
|
+
},
|
|
434
|
+
})
|
|
435
|
+
|
|
436
|
+
// Initial count should be 0
|
|
437
|
+
expect(await repositoryWithFilter.count({})).toBe(0)
|
|
438
|
+
|
|
439
|
+
// Create items
|
|
440
|
+
const book1 = await repositoryWithFilter.create({
|
|
441
|
+
title: 'Test Book 1',
|
|
442
|
+
author: 'Author 1',
|
|
443
|
+
publishedDate: new Date(),
|
|
444
|
+
})
|
|
445
|
+
const book2 = await repositoryWithFilter.create({
|
|
446
|
+
title: 'Other Book',
|
|
447
|
+
author: 'Author 2',
|
|
448
|
+
publishedDate: new Date(),
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
// Count after creation
|
|
452
|
+
expect(await repositoryWithFilter.count({})).toBe(2)
|
|
453
|
+
expect(await repositoryWithFilter.count({ text: 'Test' })).toBe(1)
|
|
454
|
+
|
|
455
|
+
// Remove an item
|
|
456
|
+
await repositoryWithFilter.remove({ id: book1.id })
|
|
457
|
+
|
|
458
|
+
// Count after removal
|
|
459
|
+
expect(await repositoryWithFilter.count({})).toBe(1)
|
|
460
|
+
expect(await repositoryWithFilter.count({ text: 'Test' })).toBe(0)
|
|
461
|
+
|
|
462
|
+
// Restore the item
|
|
463
|
+
await repositoryWithFilter.restore({ id: book1.id })
|
|
464
|
+
|
|
465
|
+
// Count after restore
|
|
466
|
+
expect(await repositoryWithFilter.count({})).toBe(2)
|
|
467
|
+
expect(await repositoryWithFilter.count({ text: 'Test' })).toBe(1)
|
|
468
|
+
})
|
|
469
|
+
})
|
|
383
470
|
})
|
|
@@ -59,14 +59,7 @@ export class MockMemoryRepository<TSchema extends AnyModelSchema> implements IRe
|
|
|
59
59
|
options?: ISearchOptions<TSchema>,
|
|
60
60
|
): Promise<InferSearchResults<TSchema>> {
|
|
61
61
|
const pagination = options?.pagination || { page: 1, pageSize: 25 }
|
|
62
|
-
let items =
|
|
63
|
-
// Apply filtering logic based on the input
|
|
64
|
-
if (typeof this.args.filter === 'function') {
|
|
65
|
-
return this.args.filter(item, input)
|
|
66
|
-
} else {
|
|
67
|
-
return true
|
|
68
|
-
}
|
|
69
|
-
})
|
|
62
|
+
let items = this.applyFilters(input)
|
|
70
63
|
|
|
71
64
|
// Apply sorting if provided
|
|
72
65
|
if (options?.sort && Array.isArray(options.sort)) {
|
|
@@ -178,6 +171,27 @@ export class MockMemoryRepository<TSchema extends AnyModelSchema> implements IRe
|
|
|
178
171
|
return updatedItem
|
|
179
172
|
}
|
|
180
173
|
|
|
174
|
+
async count(search: InferFilters<TSchema>, options?: ISearchOptions<TSchema> | undefined): Promise<number> {
|
|
175
|
+
const filteredItems = this.applyFilters(search)
|
|
176
|
+
return filteredItems.length
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Apply filtering logic to all items based on the provided search criteria
|
|
181
|
+
* @param input - The search/filter criteria
|
|
182
|
+
* @returns Filtered array of items
|
|
183
|
+
*/
|
|
184
|
+
protected applyFilters(input: InferFilters<TSchema>): InferDetail<TSchema>[] {
|
|
185
|
+
return Array.from(this.data.values()).filter((item) => {
|
|
186
|
+
// Apply filtering logic based on the input
|
|
187
|
+
if (typeof this.args.filter === 'function') {
|
|
188
|
+
return this.args.filter(item, input)
|
|
189
|
+
} else {
|
|
190
|
+
return true
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
181
195
|
protected async generatePrimaryKey() {
|
|
182
196
|
const lookupModel: Model<any, any> = this.args.schema.definition.lookup
|
|
183
197
|
const lookupMeta = await lookupModel.toJSONSchema()
|