@declaro/data 2.0.0-beta.139 → 2.0.0-beta.140
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.map +2 -2
- package/dist/node/index.cjs.map +2 -2
- package/dist/node/index.js.map +2 -2
- package/dist/ts/domain/services/read-only-model-service.d.ts +6 -0
- package/dist/ts/domain/services/read-only-model-service.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/domain/services/read-only-model-service.test.ts +66 -0
- package/src/domain/services/read-only-model-service.ts +7 -0
|
@@ -18,6 +18,12 @@ export interface ILoadOptions extends IActionOptions {
|
|
|
18
18
|
* If true, skips dispatching events for this action.
|
|
19
19
|
*/
|
|
20
20
|
doNotDispatchEvents?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* If true, bypasses any caching mechanism and forces fresh data retrieval from the repository.
|
|
23
|
+
*
|
|
24
|
+
* Use with caution, as this may have performance implications. This option is typically used in scenarios where data consistency is critical and the latest data must be retrieved, such as after a known update or in real-time applications.
|
|
25
|
+
*/
|
|
26
|
+
noCache?: boolean;
|
|
21
27
|
}
|
|
22
28
|
export interface ISearchOptions<TSchema extends AnyModelSchema> extends IActionOptions {
|
|
23
29
|
pagination?: IPaginationInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read-only-model-service.d.ts","sourceRoot":"","sources":["../../../../src/domain/services/read-only-model-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,YAAY,EACf,MAAM,qCAAqC,CAAA;AAG5C,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,cAAc;IAChD;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"read-only-model-service.d.ts","sourceRoot":"","sources":["../../../../src/domain/services/read-only-model-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,eAAe,CAAA;AAC1D,OAAO,KAAK,EACR,WAAW,EACX,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,YAAY,EACf,MAAM,qCAAqC,CAAA;AAG5C,OAAO,EAAE,gBAAgB,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D;;GAEG;AACH,MAAM,WAAW,YAAa,SAAQ,cAAc;IAChD;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAE7B;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB;AACD,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,cAAc,CAAE,SAAQ,cAAc;IAClF,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,IAAI,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAA;IACzB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAA;CAChC;AAED,qBAAa,oBAAoB,CAAC,OAAO,SAAS,cAAc,CAAE,SAAQ,gBAAgB,CAAC,OAAO,CAAC;IAC/F;;;;;;OAMG;IACG,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAIlF;;;;;;;OAOG;IACG,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAItF;;;;;OAKG;IACG,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAyB/F;;;;;OAKG;IACG,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IAyBxG;;;;;OAKG;IACG,MAAM,CACR,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAClC,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IA6BvC;;;;OAIG;IACG,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAyBlG"}
|
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.140",
|
|
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/node/index.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"@declaro/zod": "^2.0.0-beta.51"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@declaro/auth": "^2.0.0-beta.
|
|
26
|
-
"@declaro/core": "^2.0.0-beta.
|
|
27
|
-
"@declaro/zod": "^2.0.0-beta.
|
|
25
|
+
"@declaro/auth": "^2.0.0-beta.140",
|
|
26
|
+
"@declaro/core": "^2.0.0-beta.140",
|
|
27
|
+
"@declaro/zod": "^2.0.0-beta.140",
|
|
28
28
|
"crypto-browserify": "^3.12.1",
|
|
29
29
|
"typescript": "^5.8.3",
|
|
30
30
|
"uuid": "^11.1.0",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"browser": "./dist/browser/index.js",
|
|
45
45
|
"default": "./dist/node/index.js"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "46a7be1901c8712407f804a753f7e296343d9bce"
|
|
48
48
|
}
|
|
@@ -1061,4 +1061,70 @@ describe('ReadOnlyModelService', () => {
|
|
|
1061
1061
|
})
|
|
1062
1062
|
})
|
|
1063
1063
|
})
|
|
1064
|
+
|
|
1065
|
+
describe('noCache Option', () => {
|
|
1066
|
+
beforeEach(() => {
|
|
1067
|
+
repository = new MockMemoryRepository({ schema: mockSchema })
|
|
1068
|
+
emitter = new EventManager()
|
|
1069
|
+
service = new ReadOnlyModelService({ repository, emitter, schema: mockSchema, namespace })
|
|
1070
|
+
})
|
|
1071
|
+
|
|
1072
|
+
describe('load', () => {
|
|
1073
|
+
it('should return the correct result when noCache is true', async () => {
|
|
1074
|
+
const input = { id: 1, title: 'Test Book', author: 'Author', publishedDate: new Date() }
|
|
1075
|
+
await repository.create(input)
|
|
1076
|
+
|
|
1077
|
+
const result = await service.load({ id: 1 }, { noCache: true })
|
|
1078
|
+
|
|
1079
|
+
expect(result).toEqual(input)
|
|
1080
|
+
})
|
|
1081
|
+
|
|
1082
|
+
it('should return the correct result when noCache is false', async () => {
|
|
1083
|
+
const input = { id: 2, title: 'Test Book 2', author: 'Author', publishedDate: new Date() }
|
|
1084
|
+
await repository.create(input)
|
|
1085
|
+
|
|
1086
|
+
const result = await service.load({ id: 2 }, { noCache: false })
|
|
1087
|
+
|
|
1088
|
+
expect(result).toEqual(input)
|
|
1089
|
+
})
|
|
1090
|
+
|
|
1091
|
+
it('should forward noCache: true to the repository', async () => {
|
|
1092
|
+
const input = { id: 3, title: 'Test Book 3', author: 'Author', publishedDate: new Date() }
|
|
1093
|
+
await repository.create(input)
|
|
1094
|
+
|
|
1095
|
+
const loadSpy = spyOn(repository, 'load')
|
|
1096
|
+
await service.load({ id: 3 }, { noCache: true })
|
|
1097
|
+
|
|
1098
|
+
expect(loadSpy).toHaveBeenCalledWith({ id: 3 }, expect.objectContaining({ noCache: true }))
|
|
1099
|
+
})
|
|
1100
|
+
})
|
|
1101
|
+
|
|
1102
|
+
describe('loadMany', () => {
|
|
1103
|
+
it('should return the correct results when noCache is true', async () => {
|
|
1104
|
+
const input1 = { id: 1, title: 'Test Book 1', author: 'Author 1', publishedDate: new Date() }
|
|
1105
|
+
const input2 = { id: 2, title: 'Test Book 2', author: 'Author 2', publishedDate: new Date() }
|
|
1106
|
+
await repository.create(input1)
|
|
1107
|
+
await repository.create(input2)
|
|
1108
|
+
|
|
1109
|
+
const result = await service.loadMany([{ id: 1 }, { id: 2 }], { noCache: true })
|
|
1110
|
+
|
|
1111
|
+
expect(result).toEqual([input1, input2])
|
|
1112
|
+
})
|
|
1113
|
+
|
|
1114
|
+
it('should forward noCache: true to the repository', async () => {
|
|
1115
|
+
const input1 = { id: 3, title: 'Test Book 3', author: 'Author 3', publishedDate: new Date() }
|
|
1116
|
+
const input2 = { id: 4, title: 'Test Book 4', author: 'Author 4', publishedDate: new Date() }
|
|
1117
|
+
await repository.create(input1)
|
|
1118
|
+
await repository.create(input2)
|
|
1119
|
+
|
|
1120
|
+
const loadManySpy = spyOn(repository, 'loadMany')
|
|
1121
|
+
await service.loadMany([{ id: 3 }, { id: 4 }], { noCache: true })
|
|
1122
|
+
|
|
1123
|
+
expect(loadManySpy).toHaveBeenCalledWith(
|
|
1124
|
+
[{ id: 3 }, { id: 4 }],
|
|
1125
|
+
expect.objectContaining({ noCache: true }),
|
|
1126
|
+
)
|
|
1127
|
+
})
|
|
1128
|
+
})
|
|
1129
|
+
})
|
|
1064
1130
|
})
|
|
@@ -29,6 +29,13 @@ export interface ILoadOptions extends IActionOptions {
|
|
|
29
29
|
* If true, skips dispatching events for this action.
|
|
30
30
|
*/
|
|
31
31
|
doNotDispatchEvents?: boolean
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* If true, bypasses any caching mechanism and forces fresh data retrieval from the repository.
|
|
35
|
+
*
|
|
36
|
+
* Use with caution, as this may have performance implications. This option is typically used in scenarios where data consistency is critical and the latest data must be retrieved, such as after a known update or in real-time applications.
|
|
37
|
+
*/
|
|
38
|
+
noCache?: boolean
|
|
32
39
|
}
|
|
33
40
|
export interface ISearchOptions<TSchema extends AnyModelSchema> extends IActionOptions {
|
|
34
41
|
pagination?: IPaginationInput
|