@fjell/cache 4.4.3 → 4.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/dist/src/Aggregator.d.ts +19 -0
- package/dist/src/Aggregator.js +174 -0
- package/dist/src/Aggregator.js.map +1 -0
- package/dist/src/Cache.d.ts +6 -1
- package/dist/src/Cache.js +196 -1
- package/dist/src/Cache.js.map +1 -1
- package/dist/src/CacheRegistry.d.ts +2 -3
- package/dist/src/CacheRegistry.js +1 -1
- package/dist/src/CacheRegistry.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -9
- package/src/{AItemAggregator.ts → Aggregator.ts} +115 -90
- package/src/Cache.ts +265 -2
- package/src/CacheRegistry.ts +3 -6
- package/dist/src/AItemAggregator.d.ts +0 -35
- package/dist/src/AItemAggregator.js +0 -163
- package/dist/src/AItemAggregator.js.map +0 -1
- package/dist/src/AItemCache.d.ts +0 -21
- package/dist/src/AItemCache.js +0 -189
- package/dist/src/AItemCache.js.map +0 -1
- package/dist/src/CItemCache.d.ts +0 -17
- package/dist/src/CItemCache.js +0 -58
- package/dist/src/CItemCache.js.map +0 -1
- package/dist/src/PItemCache.d.ts +0 -17
- package/dist/src/PItemCache.js +0 -50
- package/dist/src/PItemCache.js.map +0 -1
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.js +0 -7
- package/dist/src/index.js.map +0 -1
- package/src/AItemCache.ts +0 -262
- package/src/CItemCache.ts +0 -117
- package/src/PItemCache.ts +0 -99
- package/src/index.ts +0 -10
package/src/AItemCache.ts
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undefined, max-params */
|
|
2
|
-
|
|
3
|
-
import { ClientApi } from "@fjell/client-api";
|
|
4
|
-
import {
|
|
5
|
-
AItemService,
|
|
6
|
-
ComKey,
|
|
7
|
-
isValidItemKey,
|
|
8
|
-
Item,
|
|
9
|
-
ItemQuery,
|
|
10
|
-
LocKeyArray,
|
|
11
|
-
PriKey,
|
|
12
|
-
TypesProperties,
|
|
13
|
-
validatePK
|
|
14
|
-
} from "@fjell/core";
|
|
15
|
-
import { NotFoundError } from "@fjell/http-api";
|
|
16
|
-
import { Cache } from "./Cache";
|
|
17
|
-
import { CacheMap } from "./CacheMap";
|
|
18
|
-
import LibLogger from "./logger";
|
|
19
|
-
|
|
20
|
-
const logger = LibLogger.get('AItemCache');
|
|
21
|
-
|
|
22
|
-
export class AItemCache<
|
|
23
|
-
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
24
|
-
S extends string,
|
|
25
|
-
L1 extends string = never,
|
|
26
|
-
L2 extends string = never,
|
|
27
|
-
L3 extends string = never,
|
|
28
|
-
L4 extends string = never,
|
|
29
|
-
L5 extends string = never
|
|
30
|
-
> extends AItemService<S, L1, L2, L3, L4, L5> implements Cache<V, S, L1, L2, L3, L4, L5> {
|
|
31
|
-
|
|
32
|
-
protected cacheName: string;
|
|
33
|
-
protected api: ClientApi<V, S, L1, L2, L3, L4, L5>;
|
|
34
|
-
|
|
35
|
-
public cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>;
|
|
36
|
-
|
|
37
|
-
public constructor(
|
|
38
|
-
cacheName: string,
|
|
39
|
-
api: ClientApi<V, S, L1, L2, L3, L4, L5>,
|
|
40
|
-
pkType: S,
|
|
41
|
-
parentCache?: AItemCache<Item<L1, L2, L3, L4, L5>, L1, L2, L3, L4, L5>
|
|
42
|
-
) {
|
|
43
|
-
super(pkType, parentCache);
|
|
44
|
-
this.cacheName = cacheName;
|
|
45
|
-
this.api = api;
|
|
46
|
-
// TODO: I wonder if this is even going to work - can you access an instance of a class in a constructor?
|
|
47
|
-
this.cacheMap =
|
|
48
|
-
new CacheMap<V, S, L1, L2, L3, L4, L5>(this.getKeyTypes());
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public async all(
|
|
52
|
-
query: ItemQuery = {},
|
|
53
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
54
|
-
):
|
|
55
|
-
Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]> {
|
|
56
|
-
logger.default('all', { query, locations });
|
|
57
|
-
let ret: V[] = [];
|
|
58
|
-
try {
|
|
59
|
-
ret = await this.api.all(query, {}, locations);
|
|
60
|
-
ret.forEach((v) => {
|
|
61
|
-
this.cacheMap.set(v.key, v);
|
|
62
|
-
});
|
|
63
|
-
} catch (e: unknown) {
|
|
64
|
-
if (e instanceof NotFoundError) {
|
|
65
|
-
} else {
|
|
66
|
-
throw e;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
return [this.cacheMap, validatePK(ret, this.getPkType()) as V[]];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public async one(
|
|
74
|
-
query: ItemQuery = {},
|
|
75
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
76
|
-
):
|
|
77
|
-
Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]> {
|
|
78
|
-
logger.default('one', { query, locations });
|
|
79
|
-
|
|
80
|
-
let retItem: V | null = null;
|
|
81
|
-
try {
|
|
82
|
-
retItem = await this.api.one(query, {}, locations);
|
|
83
|
-
if (retItem) {
|
|
84
|
-
this.cacheMap.set(retItem.key, retItem);
|
|
85
|
-
}
|
|
86
|
-
} catch (e: unknown) {
|
|
87
|
-
if (e instanceof NotFoundError) {
|
|
88
|
-
} else {
|
|
89
|
-
throw e;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
return [
|
|
94
|
-
this.cacheMap,
|
|
95
|
-
retItem ?
|
|
96
|
-
validatePK(retItem, this.getPkType()) as V :
|
|
97
|
-
null
|
|
98
|
-
];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
public async action(
|
|
102
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
103
|
-
action: string,
|
|
104
|
-
body: any = {},
|
|
105
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> {
|
|
106
|
-
logger.default('action', { key, action, body });
|
|
107
|
-
|
|
108
|
-
if (!isValidItemKey(key)) {
|
|
109
|
-
logger.error('Key for Action is not a valid ItemKey: %j', key);
|
|
110
|
-
throw new Error('Key for Action is not a valid ItemKey');
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const updated = await this.api.action(key, action, body, {});
|
|
114
|
-
this.cacheMap.set(updated.key, updated);
|
|
115
|
-
return [this.cacheMap, validatePK(updated, this.getPkType()) as V];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
public async allAction(
|
|
119
|
-
action: string,
|
|
120
|
-
body: any = {},
|
|
121
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
122
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]> {
|
|
123
|
-
logger.default('allAction', { action, body, locations });
|
|
124
|
-
let ret: V[] = [];
|
|
125
|
-
try {
|
|
126
|
-
ret = await this.api.allAction(action, body, {}, locations);
|
|
127
|
-
ret.forEach((v) => {
|
|
128
|
-
this.cacheMap.set(v.key, v);
|
|
129
|
-
});
|
|
130
|
-
} catch (e: unknown) {
|
|
131
|
-
// istanbul ignore next
|
|
132
|
-
if (e instanceof NotFoundError) {
|
|
133
|
-
} else {
|
|
134
|
-
throw e;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
return [this.cacheMap, validatePK(ret, this.getPkType()) as V[]];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
public async create(
|
|
142
|
-
v: TypesProperties<V, S, L1, L2, L3, L4, L5>,
|
|
143
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
144
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> {
|
|
145
|
-
logger.default('create', { v, locations });
|
|
146
|
-
const created = await this.api.create(v, {}, locations);
|
|
147
|
-
this.cacheMap.set(created.key, created);
|
|
148
|
-
return [this.cacheMap, validatePK(created, this.getPkType()) as V];
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
public async get(
|
|
152
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
153
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]> {
|
|
154
|
-
logger.default('get', { key });
|
|
155
|
-
if (!isValidItemKey(key)) {
|
|
156
|
-
logger.error('Key for Get is not a valid ItemKey: %j', key);
|
|
157
|
-
throw new Error('Key for Get is not a valid ItemKey');
|
|
158
|
-
}
|
|
159
|
-
let ret: V | null;
|
|
160
|
-
try {
|
|
161
|
-
ret = await this.api.get(key, {});
|
|
162
|
-
if (ret) {
|
|
163
|
-
this.cacheMap.set(ret.key, ret);
|
|
164
|
-
}
|
|
165
|
-
} catch (e: any) {
|
|
166
|
-
logger.error("Error getting item for key", { key, message: e.message, stack: e.stack });
|
|
167
|
-
throw e;
|
|
168
|
-
}
|
|
169
|
-
return [
|
|
170
|
-
this.cacheMap,
|
|
171
|
-
ret ?
|
|
172
|
-
validatePK(ret, this.getPkType()) as V :
|
|
173
|
-
null
|
|
174
|
-
];
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public async retrieve(
|
|
178
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
179
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null]> {
|
|
180
|
-
logger.default('retrieve', { key });
|
|
181
|
-
if (!isValidItemKey(key)) {
|
|
182
|
-
logger.error('Key for Retrieve is not a valid ItemKey: %j', key);
|
|
183
|
-
throw new Error('Key for Retrieve is not a valid ItemKey');
|
|
184
|
-
}
|
|
185
|
-
const containsItemKey = this.cacheMap.includesKey(key);
|
|
186
|
-
|
|
187
|
-
let retrieved: V | null;
|
|
188
|
-
if (containsItemKey) {
|
|
189
|
-
logger.default('Looking for Object in Cache', key);
|
|
190
|
-
retrieved = this.cacheMap.get(key);
|
|
191
|
-
} else {
|
|
192
|
-
logger.default('Object Not Found in Cache, Retrieving from Server API', { key });
|
|
193
|
-
[, retrieved] = await this.get(key);
|
|
194
|
-
}
|
|
195
|
-
const retValue: [CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null] = [
|
|
196
|
-
containsItemKey ? null : this.cacheMap,
|
|
197
|
-
retrieved ?
|
|
198
|
-
validatePK(retrieved, this.getPkType()) as V:
|
|
199
|
-
null
|
|
200
|
-
];
|
|
201
|
-
// logger.debug('Returning from retrieve', { retValue });
|
|
202
|
-
return retValue;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
public async remove(
|
|
206
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
207
|
-
): Promise<CacheMap<V, S, L1, L2, L3, L4, L5>> {
|
|
208
|
-
logger.default('remove', { key });
|
|
209
|
-
if (!isValidItemKey(key)) {
|
|
210
|
-
logger.error('Key for Remove is not a valid ItemKey: %j', key);
|
|
211
|
-
throw new Error('Key for Remove is not a valid ItemKey');
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
await this.api.remove(key, {});
|
|
215
|
-
this.cacheMap.delete(key);
|
|
216
|
-
} catch (e) {
|
|
217
|
-
logger.error("Error deleting item", { error: e });
|
|
218
|
-
throw e;
|
|
219
|
-
}
|
|
220
|
-
return this.cacheMap;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
public async update(
|
|
224
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
225
|
-
v: TypesProperties<V, S, L1, L2, L3, L4, L5>,
|
|
226
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> {
|
|
227
|
-
logger.default('update', { key, v });
|
|
228
|
-
|
|
229
|
-
if (!isValidItemKey(key)) {
|
|
230
|
-
logger.error('Key for Update is not a valid ItemKey: %j', key);
|
|
231
|
-
throw new Error('Key for Update is not a valid ItemKey');
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
try {
|
|
235
|
-
const updated = await this.api.update(key, v, {});
|
|
236
|
-
// }
|
|
237
|
-
this.cacheMap.set(updated.key, updated);
|
|
238
|
-
return [this.cacheMap, validatePK(updated, this.getPkType()) as V];
|
|
239
|
-
} catch (e) {
|
|
240
|
-
logger.error("Error updating chat", { error: e });
|
|
241
|
-
throw e;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
public async find(
|
|
246
|
-
finder: string,
|
|
247
|
-
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
248
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
249
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]> {
|
|
250
|
-
logger.default('find', { finder, finderParams, locations });
|
|
251
|
-
const ret: V[] = await this.api.find(finder, finderParams, {}, locations);
|
|
252
|
-
ret.forEach((v) => {
|
|
253
|
-
this.cacheMap.set(v.key, v);
|
|
254
|
-
});
|
|
255
|
-
return [this.cacheMap, validatePK(ret, this.getPkType()) as V[]];
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
public loadCache = async (cache: CacheMap<V, S, L1, L2, L3, L4, L5>) => {
|
|
259
|
-
this.cacheMap = cache;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
}
|
package/src/CItemCache.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undefined */
|
|
2
|
-
import { ClientApi } from "@fjell/client-api";
|
|
3
|
-
import { ComKey, Item, ItemQuery, LocKeyArray, PriKey, TypesProperties } from "@fjell/core";
|
|
4
|
-
import { AItemCache } from "./AItemCache";
|
|
5
|
-
import { CacheMap } from "./CacheMap";
|
|
6
|
-
import LibLogger from "./logger";
|
|
7
|
-
|
|
8
|
-
const logger = LibLogger.get('CItemCache');
|
|
9
|
-
|
|
10
|
-
export class CItemCache<
|
|
11
|
-
V extends Item<S, L1, L2, L3, L4, L5>,
|
|
12
|
-
S extends string,
|
|
13
|
-
L1 extends string,
|
|
14
|
-
L2 extends string = never,
|
|
15
|
-
L3 extends string = never,
|
|
16
|
-
L4 extends string = never,
|
|
17
|
-
L5 extends string = never
|
|
18
|
-
> extends AItemCache<V, S, L1, L2, L3, L4, L5> {
|
|
19
|
-
|
|
20
|
-
public constructor(
|
|
21
|
-
cacheName: string,
|
|
22
|
-
api: ClientApi<V, S, L1, L2, L3, L4, L5>,
|
|
23
|
-
pkType: S,
|
|
24
|
-
parentCache: AItemCache<Item<L1, L2, L3, L4, L5, never>, L1, L2, L3, L4, L5>
|
|
25
|
-
) {
|
|
26
|
-
super(cacheName, api, pkType, parentCache);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// TODO: There's something annoying about these parameters. Location isn't option in a CItem, but query is.
|
|
30
|
-
public async all(
|
|
31
|
-
// istanbul ignore next
|
|
32
|
-
query: ItemQuery = {},
|
|
33
|
-
locations?: LocKeyArray<L1, L2, L3, L4, L5>
|
|
34
|
-
):
|
|
35
|
-
Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]> {
|
|
36
|
-
logger.default('all', { query, locations });
|
|
37
|
-
return await super.all(query, locations) as [CacheMap<V, S, L1, L2, L3, L4, L5>, V[]];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// TODO: There's something annoying about these parameters. Location isn't option in a CItem, but query is.
|
|
41
|
-
public async one(
|
|
42
|
-
// istanbul ignore next
|
|
43
|
-
query: ItemQuery = {},
|
|
44
|
-
locations?: LocKeyArray<L1, L2, L3, L4, L5>
|
|
45
|
-
):
|
|
46
|
-
Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]> {
|
|
47
|
-
logger.default('one', { query, locations });
|
|
48
|
-
return await super.one(query, locations) as [CacheMap<V, S, L1, L2, L3, L4, L5>, V | null];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public async action(
|
|
52
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
53
|
-
action: string,
|
|
54
|
-
body: any = {}
|
|
55
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> {
|
|
56
|
-
logger.default('action', { key, action, body });
|
|
57
|
-
return await super.action(key, action, body) as [CacheMap<V, S, L1, L2, L3, L4, L5>, V];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// TODO: There's something annoying about these parameters. Location isn't option in a CItem, but query is.
|
|
61
|
-
public async allAction(
|
|
62
|
-
action: string,
|
|
63
|
-
// istanbul ignore next
|
|
64
|
-
body: any = {},
|
|
65
|
-
locations?: LocKeyArray<L1, L2, L3, L4, L5>
|
|
66
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]> {
|
|
67
|
-
logger.default('action', { action, body, locations });
|
|
68
|
-
return await super.allAction(action, body, locations) as [CacheMap<V, S, L1, L2, L3, L4, L5>, V[]];
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public async create(
|
|
72
|
-
v: TypesProperties<V, S, L1, L2, L3, L4, L5>,
|
|
73
|
-
locations?: LocKeyArray<L1, L2, L3, L4, L5>
|
|
74
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> {
|
|
75
|
-
logger.default('create', { v });
|
|
76
|
-
return await super.create(v, locations) as [CacheMap<V, S, L1, L2, L3, L4, L5>, V];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
public async get(
|
|
80
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
81
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]> {
|
|
82
|
-
logger.default('get', { key });
|
|
83
|
-
return await super.get(key) as [CacheMap<V, S, L1, L2, L3, L4, L5>, V | null];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public async retrieve(
|
|
87
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
88
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null]> {
|
|
89
|
-
logger.default('retrieve', { key });
|
|
90
|
-
return await super.retrieve(key) as [CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public async remove(
|
|
94
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>
|
|
95
|
-
): Promise<CacheMap<V, S, L1, L2, L3, L4, L5>> {
|
|
96
|
-
logger.default('remove', { key });
|
|
97
|
-
return await super.remove(key) as CacheMap<V, S, L1, L2, L3, L4, L5>;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public async update(
|
|
101
|
-
key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>,
|
|
102
|
-
v: TypesProperties<V, S, L1, L2, L3, L4, L5>
|
|
103
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]> {
|
|
104
|
-
logger.default('update', { key, v });
|
|
105
|
-
return await super.update(key, v) as [CacheMap<V, S, L1, L2, L3, L4, L5>, V];
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public async find(
|
|
109
|
-
finder: string,
|
|
110
|
-
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
111
|
-
locations: LocKeyArray<L1, L2, L3, L4, L5> | [] = []
|
|
112
|
-
): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]> {
|
|
113
|
-
logger.default('find', { finder, finderParams, locations });
|
|
114
|
-
return await super.find(finder, finderParams, locations) as [CacheMap<V, S, L1, L2, L3, L4, L5>, V[]];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
}
|
package/src/PItemCache.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undefined, max-params */
|
|
2
|
-
|
|
3
|
-
import { ClientApi } from "@fjell/client-api";
|
|
4
|
-
import { Item, ItemQuery, PriKey, TypesProperties } from "@fjell/core";
|
|
5
|
-
import { AItemCache } from "./AItemCache";
|
|
6
|
-
import { CacheMap } from "./CacheMap";
|
|
7
|
-
import LibLogger from './logger';
|
|
8
|
-
|
|
9
|
-
const logger = LibLogger.get('PItemCache');
|
|
10
|
-
export class PItemCache<
|
|
11
|
-
V extends Item<S>,
|
|
12
|
-
S extends string
|
|
13
|
-
> extends AItemCache<V,S> {
|
|
14
|
-
|
|
15
|
-
public constructor(
|
|
16
|
-
cacheName: string,
|
|
17
|
-
api: ClientApi<V, S>,
|
|
18
|
-
pkType: S,
|
|
19
|
-
) {
|
|
20
|
-
super(cacheName, api, pkType);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public async all(
|
|
24
|
-
query: ItemQuery = {},
|
|
25
|
-
):
|
|
26
|
-
Promise<[CacheMap<V, S>, V[]]> {
|
|
27
|
-
logger.default('all', { query });
|
|
28
|
-
return await super.all(query) as [CacheMap<V, S>, V[]];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public async one(
|
|
32
|
-
query: ItemQuery = {},
|
|
33
|
-
):
|
|
34
|
-
Promise<[CacheMap<V, S>, V | null]> {
|
|
35
|
-
logger.default('one', { query });
|
|
36
|
-
return await super.one(query) as [CacheMap<V, S>, V | null];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public async action(
|
|
40
|
-
key: PriKey<S>,
|
|
41
|
-
action: string,
|
|
42
|
-
body: any = {}
|
|
43
|
-
): Promise<[CacheMap<V, S>, V]> {
|
|
44
|
-
logger.default('action', { key, action, body });
|
|
45
|
-
return await super.action(key, action, body) as [CacheMap<V, S>, V];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public async allAction(
|
|
49
|
-
action: string,
|
|
50
|
-
body: any = {}
|
|
51
|
-
): Promise<[CacheMap<V, S>, V[]]> {
|
|
52
|
-
logger.default('action', { action, body });
|
|
53
|
-
return await super.allAction(action, body) as [CacheMap<V, S>, V[]];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public async create(
|
|
57
|
-
v: TypesProperties<V, S, never, never, never, never, never>,
|
|
58
|
-
): Promise<[CacheMap<V, S>, V]> {
|
|
59
|
-
logger.default('create', { v });
|
|
60
|
-
return await super.create(v) as [CacheMap<V, S>, V];
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public async get(key: PriKey<S>,
|
|
64
|
-
): Promise<[CacheMap<V, S>, V | null]> {
|
|
65
|
-
logger.default('get', { key });
|
|
66
|
-
return await super.get(key) as [CacheMap<V, S>, V | null];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public async retrieve(
|
|
70
|
-
key: PriKey<S>,
|
|
71
|
-
): Promise<[CacheMap<V, S> | null, V | null]> {
|
|
72
|
-
logger.default('retrieve', { key });
|
|
73
|
-
return await super.retrieve(key) as [CacheMap<V, S> | null, V | null];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public async remove(
|
|
77
|
-
key: PriKey<S>
|
|
78
|
-
): Promise<CacheMap<V, S>> {
|
|
79
|
-
logger.default('remove', { key });
|
|
80
|
-
return await super.remove(key) as CacheMap<V, S>;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
public async update(
|
|
84
|
-
key: PriKey<S>,
|
|
85
|
-
v: TypesProperties<V, S>
|
|
86
|
-
): Promise<[CacheMap<V, S>, V]> {
|
|
87
|
-
logger.default('update', { key, v });
|
|
88
|
-
return await super.update(key, v) as [CacheMap<V, S>, V];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
public async find(
|
|
92
|
-
finder: string,
|
|
93
|
-
finderParams: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>,
|
|
94
|
-
): Promise<[CacheMap<V, S>, V[]]> {
|
|
95
|
-
logger.default('find', { finder, finderParams });
|
|
96
|
-
return await super.find(finder, finderParams) as [CacheMap<V, S>, V[]];
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export { Cache } from "./Cache";
|
|
3
|
-
export { CacheMap } from "./CacheMap";
|
|
4
|
-
export { CacheRegistry } from "./CacheRegistry";
|
|
5
|
-
|
|
6
|
-
export { AggregateConfig, AItemAggregator } from "./AItemAggregator";
|
|
7
|
-
|
|
8
|
-
export { AItemCache } from "./AItemCache";
|
|
9
|
-
export { CItemCache } from "./CItemCache";
|
|
10
|
-
export { PItemCache } from "./PItemCache";
|