@declaro/data 2.0.0-beta.49 → 2.0.0-beta.50
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 +2 -5
- package/dist/node/index.cjs.map +3 -3
- package/dist/node/index.js +2 -5
- package/dist/node/index.js.map +3 -3
- package/dist/ts/domain/interfaces/repository.d.ts +2 -2
- package/dist/ts/test/mock/repositories/mock-memory-repository.d.ts +1 -1
- package/package.json +4 -4
- package/src/domain/interfaces/repository.ts +2 -2
- package/src/domain/services/model-service.test.ts +10 -1
- package/src/domain/services/read-only-model-service.test.ts +4 -2
- package/src/test/mock/repositories/mock-memory-repository.test.ts +7 -1
- package/src/test/mock/repositories/mock-memory-repository.ts +2 -6
|
@@ -6,9 +6,9 @@ export interface IRepository<TSchema extends AnyModelSchema> {
|
|
|
6
6
|
* Loads a single element based on the provided lookup.
|
|
7
7
|
*
|
|
8
8
|
* @param input - The lookup criteria for the element.
|
|
9
|
-
* @returns A promise resolving to the detailed element.
|
|
9
|
+
* @returns A promise resolving to the detailed element or null if not found.
|
|
10
10
|
*/
|
|
11
|
-
load(input: InferLookup<TSchema>): Promise<InferDetail<TSchema
|
|
11
|
+
load(input: InferLookup<TSchema>): Promise<InferDetail<TSchema> | null>;
|
|
12
12
|
/**
|
|
13
13
|
* Loads multiple elements based on the provided lookups.
|
|
14
14
|
*
|
|
@@ -12,7 +12,7 @@ export declare class MockMemoryRepository<TSchema extends AnyModelSchema> implem
|
|
|
12
12
|
protected entityMetadata: IModelEntityMetadata<any>;
|
|
13
13
|
protected nextId: number;
|
|
14
14
|
constructor(args: IMockMemoryRepositoryArgs<TSchema>);
|
|
15
|
-
load(input: InferLookup<TSchema>): Promise<InferDetail<TSchema
|
|
15
|
+
load(input: InferLookup<TSchema>): Promise<InferDetail<TSchema> | null>;
|
|
16
16
|
loadMany(inputs: InferLookup<TSchema>[]): Promise<InferDetail<TSchema>[]>;
|
|
17
17
|
search(input: InferFilters<TSchema>, pagination?: IPaginationInput): Promise<InferSearchResults<TSchema>>;
|
|
18
18
|
remove(lookup: InferLookup<TSchema>): Promise<InferSummary<TSchema>>;
|
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.50",
|
|
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",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"@declaro/core": "^2.0.0-beta.46"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@declaro/auth": "^2.0.0-beta.
|
|
24
|
-
"@declaro/core": "^2.0.0-beta.
|
|
23
|
+
"@declaro/auth": "^2.0.0-beta.50",
|
|
24
|
+
"@declaro/core": "^2.0.0-beta.50",
|
|
25
25
|
"typescript": "^5.8.3",
|
|
26
26
|
"uuid": "^11.1.0",
|
|
27
27
|
"zod": "^3.25.67"
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
},
|
|
42
42
|
"require": "./dist/node/index.cjs"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "b112b03419fd64dd882c114fd88c8928224d2649"
|
|
45
45
|
}
|
|
@@ -14,9 +14,9 @@ export interface IRepository<TSchema extends AnyModelSchema> {
|
|
|
14
14
|
* Loads a single element based on the provided lookup.
|
|
15
15
|
*
|
|
16
16
|
* @param input - The lookup criteria for the element.
|
|
17
|
-
* @returns A promise resolving to the detailed element.
|
|
17
|
+
* @returns A promise resolving to the detailed element or null if not found.
|
|
18
18
|
*/
|
|
19
|
-
load(input: InferLookup<TSchema>): Promise<InferDetail<TSchema
|
|
19
|
+
load(input: InferLookup<TSchema>): Promise<InferDetail<TSchema> | null>
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Loads multiple elements based on the provided lookups.
|
|
@@ -72,7 +72,7 @@ describe('ModelService', () => {
|
|
|
72
72
|
const removedRecord = await service.remove({ id: 42 })
|
|
73
73
|
|
|
74
74
|
expect(removedRecord).toEqual(input)
|
|
75
|
-
await
|
|
75
|
+
expect(await repository.load({ id: 42 })).toBeNull()
|
|
76
76
|
})
|
|
77
77
|
|
|
78
78
|
it('should restore a record', async () => {
|
|
@@ -137,4 +137,13 @@ describe('ModelService', () => {
|
|
|
137
137
|
expect(afterRestoreSpy).toHaveBeenCalledTimes(1)
|
|
138
138
|
expect(afterRestoreSpy).toHaveBeenCalledWith(expect.objectContaining({ type: 'books::book.afterRestore' }))
|
|
139
139
|
})
|
|
140
|
+
|
|
141
|
+
it('should throw an error when attempting to remove a non-existent record', async () => {
|
|
142
|
+
await expect(service.remove({ id: 999 })).rejects.toThrow('Item not found')
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('should throw an error when attempting to update a non-existent record', async () => {
|
|
146
|
+
const updatedInput = { title: 'Updated Book', author: 'Updated Author', publishedDate: new Date() }
|
|
147
|
+
await expect(service.update({ id: 999 }, updatedInput)).rejects.toThrow('Item not found')
|
|
148
|
+
})
|
|
140
149
|
})
|
|
@@ -83,8 +83,10 @@ describe('ReadOnlyModelService', () => {
|
|
|
83
83
|
expect(record).toEqual(input)
|
|
84
84
|
})
|
|
85
85
|
|
|
86
|
-
it('should
|
|
87
|
-
await
|
|
86
|
+
it('should return null when loading a non-existent record', async () => {
|
|
87
|
+
const record = await service.load({ id: 999 })
|
|
88
|
+
|
|
89
|
+
expect(record).toBeNull()
|
|
88
90
|
})
|
|
89
91
|
|
|
90
92
|
it('should load multiple records', async () => {
|
|
@@ -52,7 +52,8 @@ describe('MockMemoryRepository', () => {
|
|
|
52
52
|
const removedItem = await repository.remove({ id: createdItem.id })
|
|
53
53
|
|
|
54
54
|
expect(removedItem).toEqual(input)
|
|
55
|
-
await
|
|
55
|
+
const loadedItem = await repository.load({ id: createdItem.id })
|
|
56
|
+
expect(loadedItem).toBeNull()
|
|
56
57
|
})
|
|
57
58
|
|
|
58
59
|
it('should restore a removed item', async () => {
|
|
@@ -92,4 +93,9 @@ describe('MockMemoryRepository', () => {
|
|
|
92
93
|
expect(await repository.load({ id: createdItem1.id })).toEqual(createdItem1)
|
|
93
94
|
expect(await repository.load({ id: createdItem2.id })).toEqual(createdItem2)
|
|
94
95
|
})
|
|
96
|
+
|
|
97
|
+
it('should return null when loading a non-existent item', async () => {
|
|
98
|
+
const result = await repository.load({ id: 999 })
|
|
99
|
+
expect(result).toBeNull()
|
|
100
|
+
})
|
|
95
101
|
})
|
|
@@ -28,17 +28,13 @@ export class MockMemoryRepository<TSchema extends AnyModelSchema> implements IRe
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
async load(input: InferLookup<TSchema>): Promise<InferDetail<TSchema
|
|
31
|
+
async load(input: InferLookup<TSchema>): Promise<InferDetail<TSchema> | null> {
|
|
32
32
|
if (!this.entityMetadata?.primaryKey) {
|
|
33
33
|
throw new Error('Primary key is not defined in the schema metadata')
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const item = await this.data.get(input[this.entityMetadata.primaryKey])
|
|
37
|
-
|
|
38
|
-
throw new Error('Item not found')
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return item
|
|
37
|
+
return item || null
|
|
42
38
|
}
|
|
43
39
|
async loadMany(inputs: InferLookup<TSchema>[]): Promise<InferDetail<TSchema>[]> {
|
|
44
40
|
if (!this.entityMetadata?.primaryKey) {
|