@fjell/cache 4.6.10 → 4.6.13

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.
Files changed (81) hide show
  1. package/README.md +96 -0
  2. package/dist/Aggregator.cjs.js +26 -20
  3. package/dist/Aggregator.d.ts +17 -1
  4. package/dist/Aggregator.es.js +26 -20
  5. package/dist/Cache.cjs.js +22 -345
  6. package/dist/Cache.d.ts +25 -20
  7. package/dist/Cache.es.js +22 -346
  8. package/dist/Instance.cjs.js +7 -11
  9. package/dist/Instance.d.ts +5 -8
  10. package/dist/Instance.es.js +6 -10
  11. package/dist/InstanceFactory.cjs.js +17 -5
  12. package/dist/InstanceFactory.d.ts +3 -3
  13. package/dist/InstanceFactory.es.js +17 -5
  14. package/dist/Operations.cjs.js +43 -0
  15. package/dist/Operations.d.ts +70 -0
  16. package/dist/Operations.es.js +39 -0
  17. package/dist/index.cjs +416 -369
  18. package/dist/index.cjs.js +4 -1
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.es.js +3 -2
  22. package/dist/ops/action.cjs.js +28 -0
  23. package/dist/ops/action.d.ts +4 -0
  24. package/dist/ops/action.es.js +24 -0
  25. package/dist/ops/all.cjs.js +33 -0
  26. package/dist/ops/all.d.ts +4 -0
  27. package/dist/ops/all.es.js +29 -0
  28. package/dist/ops/allAction.cjs.js +35 -0
  29. package/dist/ops/allAction.d.ts +4 -0
  30. package/dist/ops/allAction.es.js +31 -0
  31. package/dist/ops/allFacet.cjs.js +22 -0
  32. package/dist/ops/allFacet.d.ts +4 -0
  33. package/dist/ops/allFacet.es.js +18 -0
  34. package/dist/ops/create.cjs.js +23 -0
  35. package/dist/ops/create.d.ts +4 -0
  36. package/dist/ops/create.es.js +19 -0
  37. package/dist/ops/facet.cjs.js +21 -0
  38. package/dist/ops/facet.d.ts +4 -0
  39. package/dist/ops/facet.es.js +17 -0
  40. package/dist/ops/find.cjs.js +26 -0
  41. package/dist/ops/find.d.ts +4 -0
  42. package/dist/ops/find.es.js +22 -0
  43. package/dist/ops/findOne.cjs.js +24 -0
  44. package/dist/ops/findOne.d.ts +4 -0
  45. package/dist/ops/findOne.es.js +20 -0
  46. package/dist/ops/get.cjs.js +38 -0
  47. package/dist/ops/get.d.ts +4 -0
  48. package/dist/ops/get.es.js +34 -0
  49. package/dist/ops/one.cjs.js +33 -0
  50. package/dist/ops/one.d.ts +4 -0
  51. package/dist/ops/one.es.js +29 -0
  52. package/dist/ops/remove.cjs.js +30 -0
  53. package/dist/ops/remove.d.ts +4 -0
  54. package/dist/ops/remove.es.js +26 -0
  55. package/dist/ops/reset.cjs.js +15 -0
  56. package/dist/ops/reset.d.ts +4 -0
  57. package/dist/ops/reset.es.js +11 -0
  58. package/dist/ops/retrieve.cjs.js +37 -0
  59. package/dist/ops/retrieve.d.ts +4 -0
  60. package/dist/ops/retrieve.es.js +33 -0
  61. package/dist/ops/set.cjs.js +71 -0
  62. package/dist/ops/set.d.ts +3 -0
  63. package/dist/ops/set.es.js +67 -0
  64. package/dist/ops/update.cjs.js +34 -0
  65. package/dist/ops/update.d.ts +4 -0
  66. package/dist/ops/update.es.js +30 -0
  67. package/docs/docs.config.ts +75 -0
  68. package/docs/index.html +18 -0
  69. package/docs/package.json +34 -0
  70. package/docs/public/README.md +96 -0
  71. package/docs/public/examples-README.md +302 -0
  72. package/docs/public/test.txt +0 -0
  73. package/docs/src/index.css +3 -0
  74. package/docs/src/main.tsx +12 -0
  75. package/docs/src/test/setup.ts +1 -0
  76. package/docs/tsconfig.node.json +15 -0
  77. package/examples/README.md +34 -39
  78. package/examples/aggregator-example.ts +9 -14
  79. package/examples/basic-cache-example.ts +18 -21
  80. package/package.json +16 -11
  81. package/vitest.config.ts +1 -1
package/dist/Cache.es.js CHANGED
@@ -1,354 +1,30 @@
1
- import { isValidItemKey, validatePK, isItemKeyEqual } from '@fjell/core';
2
1
  import { CacheMap } from './CacheMap.es.js';
2
+ import { createOperations } from './Operations.es.js';
3
3
  import LibLogger from './logger.es.js';
4
- import { NotFoundError } from '@fjell/http-api';
5
4
 
6
5
  const logger = LibLogger.get('Cache');
7
- // Normalize a key value to string for consistent comparison
8
- const normalizeKeyValue = (value)=>{
9
- return String(value);
10
- };
11
- // Normalized key comparison function that handles string/number differences
12
- const isItemKeyEqualNormalized = (a, b)=>{
13
- // For now, just normalize the keys to strings and use the original comparison
14
- const normalizedA = normalizeKey(a);
15
- const normalizedB = normalizeKey(b);
16
- return isItemKeyEqual(normalizedA, normalizedB);
17
- };
18
- // Helper function to normalize a key
19
- const normalizeKey = (key)=>{
20
- if (typeof key === 'object' && key !== null) {
21
- const normalizedKey = JSON.parse(JSON.stringify(key));
22
- // Normalize pk values
23
- if ('pk' in normalizedKey && normalizedKey.pk !== null) {
24
- normalizedKey.pk = normalizeKeyValue(normalizedKey.pk);
25
- }
26
- // Normalize lk values
27
- if ('lk' in normalizedKey && normalizedKey.lk !== null) {
28
- normalizedKey.lk = normalizeKeyValue(normalizedKey.lk);
29
- }
30
- // Normalize loc array lk values
31
- if ('loc' in normalizedKey && Array.isArray(normalizedKey.loc)) {
32
- normalizedKey.loc = normalizedKey.loc.map((locItem)=>{
33
- if (locItem && 'lk' in locItem && locItem.lk !== null) {
34
- return {
35
- ...locItem,
36
- lk: normalizeKeyValue(locItem.lk)
37
- };
38
- }
39
- return locItem;
40
- });
41
- }
42
- return normalizedKey;
43
- }
44
- return key;
45
- };
46
- const createCache = async (api, pkType, parentCache)=>{
47
- let pkTypes = [
48
- pkType
49
- ];
50
- if (parentCache) {
51
- pkTypes = pkTypes.concat(parentCache.pkTypes);
52
- }
53
- let cacheMap = new CacheMap(pkTypes);
54
- const all = async (query = {}, locations = [])=>{
55
- logger.default('all', {
56
- query,
57
- locations
58
- });
59
- let ret = [];
60
- try {
61
- ret = await api.all(query, locations);
62
- ret.forEach((v)=>{
63
- cacheMap.set(v.key, v);
64
- });
65
- } catch (e) {
66
- if (e instanceof NotFoundError) ; else {
67
- throw e;
68
- }
69
- }
70
- return [
71
- cacheMap,
72
- validatePK(ret, pkType)
73
- ];
74
- };
75
- const one = async (query = {}, locations = [])=>{
76
- logger.default('one', {
77
- query,
78
- locations
79
- });
80
- let retItem = null;
81
- try {
82
- retItem = await api.one(query, locations);
83
- if (retItem) {
84
- cacheMap.set(retItem.key, retItem);
85
- }
86
- } catch (e) {
87
- if (e instanceof NotFoundError) ; else {
88
- throw e;
89
- }
90
- }
91
- return [
92
- cacheMap,
93
- retItem ? validatePK(retItem, pkType) : null
94
- ];
95
- };
96
- const action = async (key, action, body = {})=>{
97
- logger.default('action', {
98
- key,
99
- action,
100
- body
101
- });
102
- // TODO: This is validating the key, but it doesn't have knowledge of the pkType
103
- // This should be looking at the parentCaches and calculating an array of pkTypes
104
- if (!isValidItemKey(key)) {
105
- logger.error('Key for Action is not a valid ItemKey: %j', key);
106
- throw new Error('Key for Action is not a valid ItemKey');
107
- }
108
- const updated = await api.action(key, action, body);
109
- cacheMap.set(updated.key, updated);
110
- return [
111
- cacheMap,
112
- validatePK(updated, pkType)
113
- ];
114
- };
115
- const allAction = async (action, body = {}, locations = [])=>{
116
- logger.default('allAction', {
117
- action,
118
- body,
119
- locations
120
- });
121
- let ret = [];
122
- try {
123
- ret = await api.allAction(action, body, locations);
124
- ret.forEach((v)=>{
125
- cacheMap.set(v.key, v);
126
- });
127
- } catch (e) {
128
- // istanbul ignore next
129
- if (e instanceof NotFoundError) ; else {
130
- throw e;
131
- }
132
- }
133
- return [
134
- cacheMap,
135
- validatePK(ret, pkType)
136
- ];
137
- };
138
- const allFacet = async (facet, params = {}, locations = [])=>{
139
- logger.default('allFacet', {
140
- facet,
141
- params,
142
- locations
143
- });
144
- const ret = await api.allFacet(facet, params, locations);
145
- return [
146
- cacheMap,
147
- ret
148
- ];
149
- };
150
- const create = async (v, locations = [])=>{
151
- logger.default('create', {
152
- v,
153
- locations
154
- });
155
- const created = await api.create(v, locations);
156
- cacheMap.set(created.key, created);
157
- return [
158
- cacheMap,
159
- validatePK(created, pkType)
160
- ];
161
- };
162
- const get = async (key)=>{
163
- logger.default('get', {
164
- key
165
- });
166
- // TODO: This is validating the key, but it doesn't have knowledge of the pkType
167
- // This should be looking at the parentCaches and calculating an array of pkTypes
168
- if (!isValidItemKey(key)) {
169
- logger.error('Key for Get is not a valid ItemKey: %j', key);
170
- throw new Error('Key for Get is not a valid ItemKey');
171
- }
172
- let ret;
173
- try {
174
- ret = await api.get(key);
175
- if (ret) {
176
- cacheMap.set(ret.key, ret);
177
- }
178
- } catch (e) {
179
- logger.error("Error getting item for key", {
180
- key,
181
- message: e.message,
182
- stack: e.stack
183
- });
184
- throw e;
185
- }
186
- return [
187
- cacheMap,
188
- ret ? validatePK(ret, pkType) : null
189
- ];
190
- };
191
- const retrieve = async (key)=>{
192
- logger.default('retrieve', {
193
- key
194
- });
195
- if (!isValidItemKey(key)) {
196
- logger.error('Key for Retrieve is not a valid ItemKey: %j', key);
197
- throw new Error('Key for Retrieve is not a valid ItemKey');
198
- }
199
- const containsItemKey = cacheMap.includesKey(key);
200
- let retrieved;
201
- if (containsItemKey) {
202
- logger.default('Looking for Object in Cache', key);
203
- retrieved = cacheMap.get(key);
204
- } else {
205
- logger.default('Object Not Found in Cache, Retrieving from Server API', {
206
- key
207
- });
208
- [, retrieved] = await get(key);
209
- }
210
- const retValue = [
211
- containsItemKey ? null : cacheMap,
212
- retrieved ? validatePK(retrieved, pkType) : null
213
- ];
214
- // logger.debug('Returning from retrieve', { retValue });
215
- return retValue;
216
- };
217
- const remove = async (key)=>{
218
- logger.default('remove', {
219
- key
220
- });
221
- // TODO: This is validating the key, but it doesn't have knowledge of the pkType
222
- // This should be looking at the parentCaches and calculating an array of pkTypes
223
- if (!isValidItemKey(key)) {
224
- logger.error('Key for Remove is not a valid ItemKey: %j', key);
225
- throw new Error('Key for Remove is not a valid ItemKey');
226
- }
227
- try {
228
- await api.remove(key);
229
- cacheMap.delete(key);
230
- } catch (e) {
231
- logger.error("Error deleting item", {
232
- error: e
233
- });
234
- throw e;
235
- }
236
- return cacheMap;
237
- };
238
- const update = async (key, v)=>{
239
- logger.default('update', {
240
- key,
241
- v
242
- });
243
- // TODO: This is validating the key, but it doesn't have knowledge of the pkType
244
- // This should be looking at the parentCaches and calculating an array of pkTypes
245
- if (!isValidItemKey(key)) {
246
- logger.error('Key for Update is not a valid ItemKey: %j', key);
247
- throw new Error('Key for Update is not a valid ItemKey');
248
- }
249
- try {
250
- const updated = await api.update(key, v);
251
- cacheMap.set(updated.key, updated);
252
- return [
253
- cacheMap,
254
- validatePK(updated, pkType)
255
- ];
256
- } catch (e) {
257
- logger.error("Error updating chat", {
258
- error: e
259
- });
260
- throw e;
261
- }
262
- };
263
- // Facets are a pass-thru for caches
264
- const facet = async (key, facet, params = {})=>{
265
- logger.default('facet', {
266
- key,
267
- facet
268
- });
269
- const ret = await api.facet(key, facet, params);
270
- return [
271
- cacheMap,
272
- ret
273
- ];
274
- };
275
- const find = async (finder, params = {}, locations = [])=>{
276
- logger.default('find', {
277
- finder,
278
- params,
279
- locations
280
- });
281
- const ret = await api.find(finder, params, locations);
282
- ret.forEach((v)=>{
283
- cacheMap.set(v.key, v);
284
- });
285
- return [
286
- cacheMap,
287
- validatePK(ret, pkType)
288
- ];
289
- };
290
- const findOne = async (finder, finderParams = {}, locations = [])=>{
291
- logger.default('findOne', {
292
- finder,
293
- finderParams,
294
- locations
295
- });
296
- const ret = await api.findOne(finder, finderParams, locations);
297
- cacheMap.set(ret.key, ret);
298
- return [
299
- cacheMap,
300
- validatePK(ret, pkType)
301
- ];
302
- };
303
- const reset = async ()=>{
304
- cacheMap = new CacheMap(pkTypes);
305
- return [
306
- cacheMap
307
- ];
308
- };
309
- const set = async (key, v)=>{
310
- logger.default('set', {
311
- key,
312
- v
313
- });
314
- // TODO: This is validating the key, but it doesn't have knowledge of the pkType
315
- // This should be looking at the parentCaches and calculating an array of pkTypes
316
- if (!isValidItemKey(key)) {
317
- logger.error('Key for Update is not a valid ItemKey: %j', key);
318
- throw new Error('Key for Update is not a valid ItemKey');
319
- }
320
- // TODO: This could be merged with the isValidItemKey check, later.
321
- validatePK(v, pkType);
322
- if (!isItemKeyEqualNormalized(key, v.key)) {
323
- logger.error('Key does not match item key: %j != %j', key, v.key);
324
- throw new Error('Key does not match item key');
325
- }
326
- cacheMap.set(key, v);
327
- return [
328
- cacheMap,
329
- validatePK(v, pkType)
330
- ];
331
- };
6
+ const createCache = async (api, coordinate, registry)=>{
7
+ logger.debug('createCache', {
8
+ coordinate,
9
+ registry
10
+ });
11
+ // Create the cache map using the coordinate's key type array
12
+ const cacheMap = new CacheMap(coordinate.kta);
13
+ // Get the primary key type from the coordinate
14
+ const pkType = coordinate.kta[0];
15
+ // Create operations
16
+ const operations = createOperations(api, coordinate, cacheMap, pkType);
332
17
  return {
333
- all,
334
- one,
335
- action,
336
- allAction,
337
- allFacet,
338
- create,
339
- get,
340
- retrieve,
341
- remove,
342
- update,
343
- facet,
344
- find,
345
- findOne,
346
- reset,
347
- set,
348
- pkTypes,
349
- cacheMap
18
+ coordinate,
19
+ registry,
20
+ api,
21
+ cacheMap,
22
+ operations
350
23
  };
351
24
  };
25
+ const isCache = (cache)=>{
26
+ return cache !== null && typeof cache === 'object' && 'coordinate' in cache && 'registry' in cache && 'api' in cache && 'cacheMap' in cache && 'operations' in cache;
27
+ };
352
28
 
353
- export { createCache };
354
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGUuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
29
+ export { createCache, isCache };
30
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FjaGUuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -3,25 +3,21 @@
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const logger$1 = require('./logger.cjs.js');
6
- const registry = require('@fjell/registry');
6
+ const Cache = require('./Cache.cjs.js');
7
7
 
8
8
  const logger = logger$1.default.get("Instance");
9
- const createInstance = (registry$1, coordinate, cache)=>{
9
+ const createInstance = async (registry, coordinate, api)=>{
10
10
  logger.debug("createInstance", {
11
11
  coordinate,
12
- cache,
13
- registry: registry$1
12
+ api,
13
+ registry
14
14
  });
15
- const baseInstance = registry.createInstance(registry$1, coordinate);
16
- return {
17
- ...baseInstance,
18
- cache
19
- };
15
+ return await Cache.createCache(api, coordinate, registry);
20
16
  };
21
17
  const isInstance = (instance)=>{
22
- return instance !== null && instance !== undefined && instance.coordinate !== undefined && instance.cache !== undefined && instance.registry !== undefined;
18
+ return instance !== null && typeof instance === 'object' && 'coordinate' in instance && 'registry' in instance && 'api' in instance && 'cacheMap' in instance && 'operations' in instance;
23
19
  };
24
20
 
25
21
  exports.createInstance = createInstance;
26
22
  exports.isInstance = isInstance;
27
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
23
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuY2pzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -1,20 +1,17 @@
1
1
  import { Item } from '@fjell/core';
2
- import { Instance as BaseInstance, Coordinate, Registry } from '@fjell/registry';
2
+ import { Coordinate, Registry } from '@fjell/registry';
3
+ import { ClientApi } from '@fjell/client-api';
3
4
  import { Cache } from './Cache';
4
5
  /**
5
6
  * The Cache Instance interface represents a cache model instance that extends the base Instance
6
7
  * from @fjell/registry and adds cache operations for interacting with cached data.
7
8
  *
8
- * The interface extends the base Instance (which provides coordinate and registry) with:
9
- * - cache: Provides methods for interacting with cached data (get, set, all, etc.)
9
+ * This is an alias for the Cache interface since Cache now extends Instance directly.
10
10
  *
11
11
  * @template V - The type of the data model item, extending Item
12
12
  * @template S - The string literal type representing the model's key type
13
13
  * @template L1-L5 - Optional string literal types for location hierarchy levels
14
14
  */
15
- export interface Instance<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> extends BaseInstance<S, L1, L2, L3, L4, L5> {
16
- /** The cache object that provides methods for interacting with cached data */
17
- cache: Cache<V, S, L1, L2, L3, L4, L5>;
18
- }
19
- export declare const createInstance: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(registry: Registry, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, cache: Cache<V, S, L1, L2, L3, L4, L5>) => Instance<V, S, L1, L2, L3, L4, L5>;
15
+ export type Instance<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = Cache<V, S, L1, L2, L3, L4, L5>;
16
+ export declare const createInstance: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(registry: Registry, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, api: ClientApi<V, S, L1, L2, L3, L4, L5>) => Promise<Instance<V, S, L1, L2, L3, L4, L5>>;
20
17
  export declare const isInstance: (instance: any) => instance is Instance<any, any, any, any, any, any, any>;
@@ -1,22 +1,18 @@
1
1
  import LibLogger from './logger.es.js';
2
- import { createInstance as createInstance$1 } from '@fjell/registry';
2
+ import { createCache } from './Cache.es.js';
3
3
 
4
4
  const logger = LibLogger.get("Instance");
5
- const createInstance = (registry, coordinate, cache)=>{
5
+ const createInstance = async (registry, coordinate, api)=>{
6
6
  logger.debug("createInstance", {
7
7
  coordinate,
8
- cache,
8
+ api,
9
9
  registry
10
10
  });
11
- const baseInstance = createInstance$1(registry, coordinate);
12
- return {
13
- ...baseInstance,
14
- cache
15
- };
11
+ return await createCache(api, coordinate, registry);
16
12
  };
17
13
  const isInstance = (instance)=>{
18
- return instance !== null && instance !== undefined && instance.coordinate !== undefined && instance.cache !== undefined && instance.registry !== undefined;
14
+ return instance !== null && typeof instance === 'object' && 'coordinate' in instance && 'registry' in instance && 'api' in instance && 'cacheMap' in instance && 'operations' in instance;
19
15
  };
20
16
 
21
17
  export { createInstance, isInstance };
22
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
18
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2UuZXMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7In0=
@@ -2,22 +2,34 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const Instance = require('./Instance.cjs.js');
5
+ const CacheMap = require('./CacheMap.cjs.js');
6
+ const Operations = require('./Operations.cjs.js');
6
7
  const logger$1 = require('./logger.cjs.js');
7
8
 
8
9
  const logger = logger$1.default.get("InstanceFactory");
9
10
  /**
10
11
  * Factory function for creating cache instances
11
- */ const createInstanceFactory = (cache)=>{
12
+ */ const createInstanceFactory = (api)=>{
12
13
  return (coordinate, context)=>{
13
14
  logger.debug("Creating cache instance", {
14
15
  coordinate,
15
16
  registry: context.registry,
16
- cache
17
+ api
17
18
  });
18
- return Instance.createInstance(context.registry, coordinate, cache);
19
+ // Since InstanceFactory must be synchronous but our createInstance is async,
20
+ // we need to create a special cache instance synchronously and defer the async initialization
21
+ const cacheMap = new CacheMap.CacheMap(coordinate.kta);
22
+ const pkType = coordinate.kta[0];
23
+ const operations = Operations.createOperations(api, coordinate, cacheMap, pkType);
24
+ return {
25
+ coordinate,
26
+ registry: context.registry,
27
+ api,
28
+ cacheMap,
29
+ operations
30
+ };
19
31
  };
20
32
  };
21
33
 
22
34
  exports.createInstanceFactory = createInstanceFactory;
23
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2VGYWN0b3J5LmNqcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
35
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2VGYWN0b3J5LmNqcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9
@@ -1,8 +1,8 @@
1
1
  import { Item } from '@fjell/core';
2
- import { Cache } from './Cache';
2
+ import { ClientApi } from '@fjell/client-api';
3
3
  import { InstanceFactory as BaseInstanceFactory } from '@fjell/registry';
4
- export type InstanceFactory<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = (cache: Cache<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
4
+ export type InstanceFactory<V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never> = (api: ClientApi<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
5
5
  /**
6
6
  * Factory function for creating cache instances
7
7
  */
8
- export declare const createInstanceFactory: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(cache: Cache<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
8
+ export declare const createInstanceFactory: <V extends Item<S, L1, L2, L3, L4, L5>, S extends string, L1 extends string = never, L2 extends string = never, L3 extends string = never, L4 extends string = never, L5 extends string = never>(api: ClientApi<V, S, L1, L2, L3, L4, L5>) => BaseInstanceFactory<S, L1, L2, L3, L4, L5>;
@@ -1,19 +1,31 @@
1
- import { createInstance } from './Instance.es.js';
1
+ import { CacheMap } from './CacheMap.es.js';
2
+ import { createOperations } from './Operations.es.js';
2
3
  import LibLogger from './logger.es.js';
3
4
 
4
5
  const logger = LibLogger.get("InstanceFactory");
5
6
  /**
6
7
  * Factory function for creating cache instances
7
- */ const createInstanceFactory = (cache)=>{
8
+ */ const createInstanceFactory = (api)=>{
8
9
  return (coordinate, context)=>{
9
10
  logger.debug("Creating cache instance", {
10
11
  coordinate,
11
12
  registry: context.registry,
12
- cache
13
+ api
13
14
  });
14
- return createInstance(context.registry, coordinate, cache);
15
+ // Since InstanceFactory must be synchronous but our createInstance is async,
16
+ // we need to create a special cache instance synchronously and defer the async initialization
17
+ const cacheMap = new CacheMap(coordinate.kta);
18
+ const pkType = coordinate.kta[0];
19
+ const operations = createOperations(api, coordinate, cacheMap, pkType);
20
+ return {
21
+ coordinate,
22
+ registry: context.registry,
23
+ api,
24
+ cacheMap,
25
+ operations
26
+ };
15
27
  };
16
28
  };
17
29
 
18
30
  export { createInstanceFactory };
19
- //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2VGYWN0b3J5LmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
31
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW5zdGFuY2VGYWN0b3J5LmVzLmpzIiwic291cmNlcyI6W10sInNvdXJjZXNDb250ZW50IjpbXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const all = require('./ops/all.cjs.js');
6
+ const one = require('./ops/one.cjs.js');
7
+ const create = require('./ops/create.cjs.js');
8
+ const get = require('./ops/get.cjs.js');
9
+ const retrieve = require('./ops/retrieve.cjs.js');
10
+ const remove = require('./ops/remove.cjs.js');
11
+ const update = require('./ops/update.cjs.js');
12
+ const action = require('./ops/action.cjs.js');
13
+ const allAction = require('./ops/allAction.cjs.js');
14
+ const facet = require('./ops/facet.cjs.js');
15
+ const allFacet = require('./ops/allFacet.cjs.js');
16
+ const find = require('./ops/find.cjs.js');
17
+ const findOne = require('./ops/findOne.cjs.js');
18
+ const set = require('./ops/set.cjs.js');
19
+ const reset = require('./ops/reset.cjs.js');
20
+
21
+ // Import all operation functions
22
+ const createOperations = (api, coordinate, cacheMap, pkType)=>{
23
+ return {
24
+ all: (query, locations)=>all.all(api, cacheMap, pkType, query, locations),
25
+ one: (query, locations)=>one.one(api, cacheMap, pkType, query, locations),
26
+ create: (item, locations)=>create.create(api, cacheMap, pkType, item, locations),
27
+ get: (key)=>get.get(api, cacheMap, pkType, key),
28
+ retrieve: (key)=>retrieve.retrieve(api, cacheMap, pkType, key),
29
+ remove: (key)=>remove.remove(api, cacheMap, key),
30
+ update: (key, item)=>update.update(api, cacheMap, pkType, key, item),
31
+ action: (key, actionName, body)=>action.action(api, cacheMap, pkType, key, actionName, body),
32
+ allAction: (actionName, body, locations)=>allAction.allAction(api, cacheMap, pkType, actionName, body, locations),
33
+ facet: (key, facetName, params)=>facet.facet(api, cacheMap, key, facetName, params),
34
+ allFacet: (facetName, params, locations)=>allFacet.allFacet(api, cacheMap, facetName, params, locations),
35
+ find: (finder, params, locations)=>find.find(api, cacheMap, pkType, finder, params, locations),
36
+ findOne: (finder, params, locations)=>findOne.findOne(api, cacheMap, pkType, finder, params, locations),
37
+ set: (key, item)=>set.set(cacheMap, pkType, key, item),
38
+ reset: ()=>reset.reset(coordinate)
39
+ };
40
+ };
41
+
42
+ exports.createOperations = createOperations;
43
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3BlcmF0aW9ucy5janMuanMiLCJzb3VyY2VzIjpbXSwic291cmNlc0NvbnRlbnQiOltdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OyJ9