@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
@@ -0,0 +1,70 @@
1
+ import { ComKey, Item, ItemQuery, LocKeyArray, PriKey } from '@fjell/core';
2
+ import { ClientApi } from '@fjell/client-api';
3
+ import { Coordinate } from '@fjell/registry';
4
+ import { CacheMap } from './CacheMap';
5
+ export interface Operations<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> {
6
+ /**
7
+ * Retrieves all the items that match the query from cache or API.
8
+ * Items are cached automatically after retrieval.
9
+ */
10
+ all(query?: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
11
+ /**
12
+ * Retrieves the first item that matches the query from cache or API.
13
+ * Item is cached automatically after retrieval.
14
+ */
15
+ one(query?: ItemQuery, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]>;
16
+ /**
17
+ * Creates a new item via API and caches it.
18
+ */
19
+ create(item: Partial<Item<S, L1, L2, L3, L4, L5>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
20
+ /**
21
+ * Gets an item by key from cache or API and caches it.
22
+ */
23
+ get(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V | null]>;
24
+ /**
25
+ * Retrieves an item from cache if available, otherwise from API.
26
+ * Returns null as first element if item was already in cache.
27
+ */
28
+ retrieve(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5> | null, V | null]>;
29
+ /**
30
+ * Removes an item via API and from cache.
31
+ */
32
+ remove(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>): Promise<CacheMap<V, S, L1, L2, L3, L4, L5>>;
33
+ /**
34
+ * Updates an item via API and caches the result.
35
+ */
36
+ update(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, item: Partial<Item<S, L1, L2, L3, L4, L5>>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
37
+ /**
38
+ * Executes an action on an item via API and caches the result.
39
+ */
40
+ action(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, action: string, body?: any): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
41
+ /**
42
+ * Executes an action on all items matching criteria via API and caches results.
43
+ */
44
+ allAction(action: string, body?: any, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
45
+ /**
46
+ * Executes a facet query on an item via API (pass-through, no caching).
47
+ */
48
+ facet(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, facet: string, params?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, any]>;
49
+ /**
50
+ * Executes a facet query on all items matching criteria via API (pass-through, no caching).
51
+ */
52
+ allFacet(facet: string, params?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, any]>;
53
+ /**
54
+ * Finds items using a finder method via API and caches results.
55
+ */
56
+ find(finder: string, params?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V[]]>;
57
+ /**
58
+ * Finds a single item using a finder method via API and caches result.
59
+ */
60
+ findOne(finder: string, params?: Record<string, string | number | boolean | Date | Array<string | number | boolean | Date>>, locations?: LocKeyArray<L1, L2, L3, L4, L5> | []): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
61
+ /**
62
+ * Sets an item directly in cache without API call.
63
+ */
64
+ set(key: ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>, item: Item<S, L1, L2, L3, L4, L5>): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>, V]>;
65
+ /**
66
+ * Resets the cache, clearing all cached items.
67
+ */
68
+ reset(): Promise<[CacheMap<V, S, L1, L2, L3, L4, L5>]>;
69
+ }
70
+ export declare const createOperations: <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>, coordinate: Coordinate<S, L1, L2, L3, L4, L5>, cacheMap: CacheMap<V, S, L1, L2, L3, L4, L5>, pkType: S) => Operations<V, S, L1, L2, L3, L4, L5>;
@@ -0,0 +1,39 @@
1
+ import { all } from './ops/all.es.js';
2
+ import { one } from './ops/one.es.js';
3
+ import { create } from './ops/create.es.js';
4
+ import { get } from './ops/get.es.js';
5
+ import { retrieve } from './ops/retrieve.es.js';
6
+ import { remove } from './ops/remove.es.js';
7
+ import { update } from './ops/update.es.js';
8
+ import { action } from './ops/action.es.js';
9
+ import { allAction } from './ops/allAction.es.js';
10
+ import { facet } from './ops/facet.es.js';
11
+ import { allFacet } from './ops/allFacet.es.js';
12
+ import { find } from './ops/find.es.js';
13
+ import { findOne } from './ops/findOne.es.js';
14
+ import { set } from './ops/set.es.js';
15
+ import { reset } from './ops/reset.es.js';
16
+
17
+ // Import all operation functions
18
+ const createOperations = (api, coordinate, cacheMap, pkType)=>{
19
+ return {
20
+ all: (query, locations)=>all(api, cacheMap, pkType, query, locations),
21
+ one: (query, locations)=>one(api, cacheMap, pkType, query, locations),
22
+ create: (item, locations)=>create(api, cacheMap, pkType, item, locations),
23
+ get: (key)=>get(api, cacheMap, pkType, key),
24
+ retrieve: (key)=>retrieve(api, cacheMap, pkType, key),
25
+ remove: (key)=>remove(api, cacheMap, key),
26
+ update: (key, item)=>update(api, cacheMap, pkType, key, item),
27
+ action: (key, actionName, body)=>action(api, cacheMap, pkType, key, actionName, body),
28
+ allAction: (actionName, body, locations)=>allAction(api, cacheMap, pkType, actionName, body, locations),
29
+ facet: (key, facetName, params)=>facet(api, cacheMap, key, facetName, params),
30
+ allFacet: (facetName, params, locations)=>allFacet(api, cacheMap, facetName, params, locations),
31
+ find: (finder, params, locations)=>find(api, cacheMap, pkType, finder, params, locations),
32
+ findOne: (finder, params, locations)=>findOne(api, cacheMap, pkType, finder, params, locations),
33
+ set: (key, item)=>set(cacheMap, pkType, key, item),
34
+ reset: ()=>reset(coordinate)
35
+ };
36
+ };
37
+
38
+ export { createOperations };
39
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiT3BlcmF0aW9ucy5lcy5qcyIsInNvdXJjZXMiOltdLCJzb3VyY2VzQ29udGVudCI6W10sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OzsifQ==