@privateaim/server-kit 0.8.3 → 0.8.5

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 (63) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/core/index.d.ts +0 -1
  3. package/dist/core/index.d.ts.map +1 -1
  4. package/dist/domain-event/publish.d.ts +2 -2
  5. package/dist/domain-event/publish.d.ts.map +1 -1
  6. package/dist/domain-event/redis/publish.d.ts +2 -2
  7. package/dist/domain-event/redis/publish.d.ts.map +1 -1
  8. package/dist/domain-event/socket/publish.d.ts +2 -2
  9. package/dist/domain-event/socket/publish.d.ts.map +1 -1
  10. package/dist/index.cjs +259 -122
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.mjs +251 -110
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/services/cache/adapters/factory.d.ts +4 -0
  15. package/dist/services/cache/adapters/factory.d.ts.map +1 -0
  16. package/dist/services/cache/adapters/index.d.ts +5 -0
  17. package/dist/services/cache/adapters/index.d.ts.map +1 -0
  18. package/dist/services/cache/adapters/memory.d.ts +15 -0
  19. package/dist/services/cache/adapters/memory.d.ts.map +1 -0
  20. package/dist/services/cache/adapters/redis.d.ts +16 -0
  21. package/dist/services/cache/adapters/redis.d.ts.map +1 -0
  22. package/dist/services/cache/adapters/types.d.ts +10 -0
  23. package/dist/services/cache/adapters/types.d.ts.map +1 -0
  24. package/dist/services/cache/helper.d.ts +3 -0
  25. package/dist/services/cache/helper.d.ts.map +1 -0
  26. package/dist/services/cache/index.d.ts +6 -0
  27. package/dist/services/cache/index.d.ts.map +1 -0
  28. package/dist/services/cache/module.d.ts +13 -0
  29. package/dist/services/cache/module.d.ts.map +1 -0
  30. package/dist/services/cache/singleton.d.ts +3 -0
  31. package/dist/services/cache/singleton.d.ts.map +1 -0
  32. package/dist/services/cache/types.d.ts +16 -0
  33. package/dist/services/cache/types.d.ts.map +1 -0
  34. package/dist/services/index.d.ts +1 -0
  35. package/dist/services/index.d.ts.map +1 -1
  36. package/dist/services/redis/module.d.ts +2 -2
  37. package/dist/services/redis/module.d.ts.map +1 -1
  38. package/package.json +13 -13
  39. package/src/core/index.ts +0 -1
  40. package/src/domain-event/publish.ts +2 -2
  41. package/src/domain-event/redis/publish.ts +2 -2
  42. package/src/domain-event/socket/publish.ts +6 -3
  43. package/src/services/cache/adapters/factory.ts +18 -0
  44. package/src/services/cache/adapters/index.ts +11 -0
  45. package/src/services/cache/adapters/memory.ts +67 -0
  46. package/src/services/cache/adapters/redis.ts +69 -0
  47. package/src/services/cache/adapters/types.ts +22 -0
  48. package/src/services/cache/helper.ts +13 -0
  49. package/src/{core/memory-cache → services/cache}/index.ts +4 -1
  50. package/src/services/cache/module.ts +41 -0
  51. package/src/services/cache/singleton.ts +30 -0
  52. package/src/services/cache/types.ts +24 -0
  53. package/src/services/index.ts +1 -0
  54. package/src/services/redis/module.ts +0 -4
  55. package/test/unit/memory-cache.spec.ts +10 -9
  56. package/dist/core/memory-cache/index.d.ts +0 -3
  57. package/dist/core/memory-cache/index.d.ts.map +0 -1
  58. package/dist/core/memory-cache/module.d.ts +0 -15
  59. package/dist/core/memory-cache/module.d.ts.map +0 -1
  60. package/dist/core/memory-cache/singleton.d.ts +0 -3
  61. package/dist/core/memory-cache/singleton.d.ts.map +0 -1
  62. package/src/core/memory-cache/module.ts +0 -48
  63. package/src/core/memory-cache/singleton.ts +0 -18
package/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.5](https://github.com/PrivateAIM/hub/compare/v0.8.4...v0.8.5) (2025-01-22)
4
+
5
+
6
+ ### Features
7
+
8
+ * bump authup dependencies & adjusted code base ([90f7131](https://github.com/PrivateAIM/hub/commit/90f7131723e4e00dad04cb5ababa3e3f232e9c24))
9
+ * enhance typing for doamin entities ([9d7c516](https://github.com/PrivateAIM/hub/commit/9d7c51644b66c9361e5436e2c43f463f4f219f90))
10
+ * initial hybrid cache (redis or memory) implementation ([b1cd569](https://github.com/PrivateAIM/hub/commit/b1cd569ff52d222f61d4b87abc921cb769de8264))
11
+ * refactor http controller validation ([#880](https://github.com/PrivateAIM/hub/issues/880)) ([6e11074](https://github.com/PrivateAIM/hub/commit/6e110742f946d4d0e827f4beb497ba2612568b9a))
12
+ * refactoring of master-image workflow ([#845](https://github.com/PrivateAIM/hub/issues/845)) ([7d2b866](https://github.com/PrivateAIM/hub/commit/7d2b8662b24dcf411d3ae8232152fecf53167382))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **deps:** bump authup to v1.0.0-beta.24 ([#963](https://github.com/PrivateAIM/hub/issues/963)) ([90c40c0](https://github.com/PrivateAIM/hub/commit/90c40c0d55018557ee8bb381aad7e3cfbcd29b83))
18
+ * **deps:** bump the minorandpatch group across 1 directory with 31 updates ([#945](https://github.com/PrivateAIM/hub/issues/945)) ([448e9b8](https://github.com/PrivateAIM/hub/commit/448e9b86bf80f83c4aa8bb32ee0a75190a1d5cb8))
19
+ * **deps:** bump the minorandpatch group across 1 directory with 4 updates ([#906](https://github.com/PrivateAIM/hub/issues/906)) ([e11bc5f](https://github.com/PrivateAIM/hub/commit/e11bc5f3b565347af3180e8e29b4e3b79ace5961))
20
+ * **deps:** bump winston from 3.15.0 to 3.16.0 ([#878](https://github.com/PrivateAIM/hub/issues/878)) ([71a2fcd](https://github.com/PrivateAIM/hub/commit/71a2fcd6b507dc44543645acd9622d5d9372dd80))
21
+
22
+
23
+ ### Dependencies
24
+
25
+ * The following workspace dependencies were updated
26
+ * dependencies
27
+ * @privateaim/core-kit bumped from ^0.8.4 to ^0.8.5
28
+ * @privateaim/kit bumped from ^0.8.4 to ^0.8.5
29
+
30
+ ## [0.8.4](https://github.com/PrivateAIM/hub/compare/v0.8.3...v0.8.4) (2024-10-24)
31
+
32
+
33
+ ### Features
34
+
35
+ * bump authup & implement async policy & permission evaluation ([#807](https://github.com/PrivateAIM/hub/issues/807)) ([d065562](https://github.com/PrivateAIM/hub/commit/d065562585076e26553ad5a39f4a5789f7e18f24))
36
+ * bump authup & vuecs packages + refactored navigation ([c4db8d5](https://github.com/PrivateAIM/hub/commit/c4db8d51588b3d701815e2ba2f9b80e594f3663f))
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * **deps:** bump typeorm-extension from 3.6.1 to 3.6.2 ([#810](https://github.com/PrivateAIM/hub/issues/810)) ([c9af9ae](https://github.com/PrivateAIM/hub/commit/c9af9aea537c4a51aae13f1059c1565180045a83))
42
+
43
+
44
+ ### Dependencies
45
+
46
+ * The following workspace dependencies were updated
47
+ * dependencies
48
+ * @privateaim/core-kit bumped from ^0.8.3 to ^0.8.4
49
+ * @privateaim/kit bumped from ^0.8.3 to ^0.8.4
50
+
3
51
  ## [0.8.3](https://github.com/PrivateAIM/hub/compare/v0.8.2...v0.8.3) (2024-09-19)
4
52
 
5
53
 
@@ -1,5 +1,4 @@
1
1
  export * from './aggregator';
2
- export * from './memory-cache';
3
2
  export * from './component';
4
3
  export * from './queue';
5
4
  export * from './queue-router';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,gBAAgB,CAAC"}
@@ -1,5 +1,5 @@
1
- import type { DomainsEventContext } from '@privateaim/core-kit';
1
+ import type { DomainsEvents } from '@privateaim/core-kit';
2
2
  import type { Client } from 'redis-extension';
3
3
  import type { DomainEventDestinations } from './type';
4
- export declare function publishDomainEvent(client: Client, context: DomainsEventContext, destinations: DomainEventDestinations): Promise<void>;
4
+ export declare function publishDomainEvent(client: Client, context: DomainsEvents, destinations: DomainEventDestinations): Promise<void>;
5
5
  //# sourceMappingURL=publish.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../src/domain-event/publish.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAEtD,wBAAsB,kBAAkB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,EAC5B,YAAY,EAAE,uBAAuB,iBAIxC"}
1
+ {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../src/domain-event/publish.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,QAAQ,CAAC;AAEtD,wBAAsB,kBAAkB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,EACtB,YAAY,EAAE,uBAAuB,iBAIxC"}
@@ -1,5 +1,5 @@
1
- import type { DomainsEventContext } from '@privateaim/core-kit';
1
+ import type { DomainsEvents } from '@privateaim/core-kit';
2
2
  import type { Client } from 'redis-extension';
3
3
  import type { DomainEventDestinations } from '../type';
4
- export declare function publishDomainRedisEvent(client: Client, context: DomainsEventContext, destinations: DomainEventDestinations): Promise<any>;
4
+ export declare function publishDomainRedisEvent(client: Client, context: DomainsEvents, destinations: DomainEventDestinations): Promise<any>;
5
5
  //# sourceMappingURL=publish.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../../src/domain-event/redis/publish.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGvD,wBAAsB,uBAAuB,CACzC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,EAC5B,YAAY,EAAE,uBAAuB,GACrC,OAAO,CAAC,GAAG,CAAC,CAuBf"}
1
+ {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../../src/domain-event/redis/publish.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGvD,wBAAsB,uBAAuB,CACzC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,EACtB,YAAY,EAAE,uBAAuB,GACrC,OAAO,CAAC,GAAG,CAAC,CAuBf"}
@@ -1,5 +1,5 @@
1
- import type { DomainsEventContext } from '@privateaim/core-kit';
1
+ import type { DomainsEvents } from '@privateaim/core-kit';
2
2
  import type { Client } from 'redis-extension';
3
3
  import type { DomainEventDestinations } from '../type';
4
- export declare function publishDomainSocketEvent(client: Client, context: DomainsEventContext, destinations: DomainEventDestinations): void;
4
+ export declare function publishDomainSocketEvent(client: Client, context: DomainsEvents, destinations: DomainEventDestinations): void;
5
5
  //# sourceMappingURL=publish.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../../src/domain-event/socket/publish.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAGhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGvD,wBAAgB,wBAAwB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,mBAAmB,EAC5B,YAAY,EAAE,uBAAuB,QAuCxC"}
1
+ {"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../../../src/domain-event/socket/publish.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGvD,wBAAgB,wBAAwB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,aAAa,EACtB,YAAY,EAAE,uBAAuB,QA0CxC"}
package/dist/index.cjs CHANGED
@@ -1,78 +1,25 @@
1
1
  'use strict';
2
2
 
3
- var TTLCache = require('@isaacs/ttlcache');
4
- var singa = require('singa');
5
3
  var kit = require('@privateaim/kit');
6
4
  var amqpExtension = require('amqp-extension');
5
+ var singa = require('singa');
7
6
  var vault = require('@hapic/vault');
8
7
  var coreHttpKit = require('@authup/core-http-kit');
8
+ var redisExtension = require('redis-extension');
9
+ var TTLCache = require('@isaacs/ttlcache');
9
10
  var envix = require('envix');
10
11
  var path = require('node:path');
11
12
  var typeormExtension = require('typeorm-extension');
12
13
  var winston = require('winston');
13
- var redisExtension = require('redis-extension');
14
14
  var coreKit = require('@privateaim/core-kit');
15
15
  var redisEmitter = require('@socket.io/redis-emitter');
16
16
 
17
- /*
18
- * Copyright (c) 2024.
19
- * Author Peter Placzek (tada5hi)
20
- * For the full copyright and license information,
21
- * view the LICENSE file that was distributed with this source code.
22
- */ function _define_property$2(obj, key, value) {
23
- if (key in obj) {
24
- Object.defineProperty(obj, key, {
25
- value: value,
26
- enumerable: true,
27
- configurable: true,
28
- writable: true
29
- });
30
- } else {
31
- obj[key] = value;
32
- }
33
- return obj;
34
- }
35
- class MemoryCache {
36
- set(id, value, options) {
37
- this.cache.set(id, value, {
38
- ttl: options.ttl
39
- });
40
- }
41
- get(id) {
42
- return this.cache.get(id);
43
- }
44
- del(id) {
45
- this.cache.delete(id);
46
- }
47
- has(id) {
48
- return this.cache.has(id);
49
- }
50
- constructor(options = {}){
51
- _define_property$2(this, "options", void 0);
52
- _define_property$2(this, "cache", void 0);
53
- this.options = {
54
- // 60 seconds
55
- ttl: 1000 * 60,
56
- ...options
57
- };
58
- this.cache = new TTLCache();
59
- }
60
- }
61
-
62
- const instance$8 = singa.singa({
63
- name: 'queueRouter',
64
- factory: ()=>new MemoryCache()
65
- });
66
- function useMemoryCache() {
67
- return instance$8.use();
68
- }
69
-
70
17
  /*
71
18
  * Copyright (c) 2023-2024.
72
19
  * Author Peter Placzek (tada5hi)
73
20
  * For the full copyright and license information,
74
21
  * view the LICENSE file that was distributed with this source code.
75
- */ function _define_property$1(obj, key, value) {
22
+ */ function _define_property$4(obj, key, value) {
76
23
  if (key in obj) {
77
24
  Object.defineProperty(obj, key, {
78
25
  value: value,
@@ -89,7 +36,7 @@ class ComponentError extends Error {
89
36
  constructor(input){
90
37
  super(input.message, {
91
38
  cause: input.cause
92
- }), _define_property$1(this, "code", void 0);
39
+ }), _define_property$4(this, "code", undefined);
93
40
  this.code = input.code;
94
41
  }
95
42
  }
@@ -116,11 +63,11 @@ function isQueuePayload(input) {
116
63
  * Author Peter Placzek (tada5hi)
117
64
  * For the full copyright and license information,
118
65
  * view the LICENSE file that was distributed with this source code.
119
- */ exports.QueueRouterRoutingType = void 0;
120
- (function(QueueRouterRoutingType) {
66
+ */ var QueueRouterRoutingType = /*#__PURE__*/ function(QueueRouterRoutingType) {
121
67
  QueueRouterRoutingType["WORK"] = "work";
122
68
  QueueRouterRoutingType["PUB_SUB"] = "pubSub";
123
- })(exports.QueueRouterRoutingType || (exports.QueueRouterRoutingType = {}));
69
+ return QueueRouterRoutingType;
70
+ }({});
124
71
 
125
72
  function buildQueueRouterPublishPayload(input) {
126
73
  return {
@@ -137,30 +84,30 @@ function isQueueRouterPayload(input) {
137
84
  return kit.isObject(input) && typeof input.id === 'string' && typeof input.type === 'string' && kit.hasOwnProperty(input, 'data') && kit.isObject(input.data) && kit.hasOwnProperty(input, 'metadata') && kit.isObject(input.metadata);
138
85
  }
139
86
 
140
- const instance$7 = singa.singa({
87
+ const instance$8 = singa.singa({
141
88
  name: 'amqp'
142
89
  });
143
90
  function setAmqpClientFactory(factory) {
144
- instance$7.setFactory(factory);
91
+ instance$8.setFactory(factory);
145
92
  }
146
93
  function isAmqpClientUsable() {
147
- return instance$7.has() || instance$7.hasFactory();
94
+ return instance$8.has() || instance$8.hasFactory();
148
95
  }
149
96
  function useAmqpClient() {
150
- return instance$7.use();
97
+ return instance$8.use();
151
98
  }
152
99
 
153
- const instance$6 = singa.singa({
100
+ const instance$7 = singa.singa({
154
101
  name: 'vault'
155
102
  });
156
103
  function setVaultFactory(factory) {
157
- instance$6.setFactory(factory);
104
+ instance$7.setFactory(factory);
158
105
  }
159
106
  function isVaultClientUsable() {
160
- return instance$6.has() || instance$6.hasFactory();
107
+ return instance$7.has() || instance$7.hasFactory();
161
108
  }
162
109
  function useVaultClient() {
163
- return instance$6.use();
110
+ return instance$7.use();
164
111
  }
165
112
 
166
113
  function guessAuthupTokenCreatorOptions() {
@@ -199,18 +146,243 @@ class AuthupClient extends coreHttpKit.Client {
199
146
  }
200
147
  }
201
148
 
202
- const instance$5 = singa.singa({
149
+ const instance$6 = singa.singa({
203
150
  name: 'authup'
204
151
  });
205
152
  function useAuthupClient() {
206
- return instance$5.use();
153
+ return instance$6.use();
207
154
  }
208
155
  function isAuthupClientUsable() {
209
- return instance$5.has() || instance$5.hasFactory();
156
+ return instance$6.has() || instance$6.hasFactory();
210
157
  }
211
158
  function setAuthupClientFactory(factory) {
159
+ instance$6.setFactory(factory);
160
+ }
161
+
162
+ const instance$5 = singa.singa({
163
+ name: 'redis'
164
+ });
165
+ function setRedisFactory(factory) {
212
166
  instance$5.setFactory(factory);
213
167
  }
168
+ function isRedisClientUsable() {
169
+ return instance$5.has() || instance$5.hasFactory();
170
+ }
171
+ function setRedisClient(input) {
172
+ instance$5.set(input);
173
+ }
174
+ function useRedisClient() {
175
+ return instance$5.use();
176
+ }
177
+
178
+ const instance$4 = singa.singa({
179
+ name: 'redisPublish',
180
+ factory: ()=>useRedisClient().duplicate()
181
+ });
182
+ function useRedisPublishClient() {
183
+ return instance$4.use();
184
+ }
185
+
186
+ const instance$3 = singa.singa({
187
+ name: 'redisSubscribe',
188
+ factory: ()=>useRedisClient().duplicate()
189
+ });
190
+ function useRedisSubscribeClient() {
191
+ return instance$3.use();
192
+ }
193
+
194
+ /*
195
+ * Copyright (c) 2024-2024.
196
+ * Author Peter Placzek (tada5hi)
197
+ * For the full copyright and license information,
198
+ * view the LICENSE file that was distributed with this source code.
199
+ */ function _define_property$3(obj, key, value) {
200
+ if (key in obj) {
201
+ Object.defineProperty(obj, key, {
202
+ value: value,
203
+ enumerable: true,
204
+ configurable: true,
205
+ writable: true
206
+ });
207
+ } else {
208
+ obj[key] = value;
209
+ }
210
+ return obj;
211
+ }
212
+ class MemoryCacheAdapter {
213
+ async get(key) {
214
+ return this.instance.get(key);
215
+ }
216
+ async has(key) {
217
+ return this.instance.has(key);
218
+ }
219
+ async set(key, value, options) {
220
+ this.instance.set(key, value, {
221
+ ttl: options.ttl
222
+ });
223
+ }
224
+ async drop(key) {
225
+ this.instance.delete(key);
226
+ }
227
+ async dropMany(keys) {
228
+ for(let i = 0; i < keys.length; i++){
229
+ this.instance.delete(keys[i]);
230
+ }
231
+ }
232
+ async clear(options = {}) {
233
+ if (options.prefix) {
234
+ const keys = this.instance.keys();
235
+ let iterator = keys.next();
236
+ while(!iterator.done){
237
+ if (iterator.value.startsWith(options.prefix)) {
238
+ this.instance.delete(iterator.value);
239
+ }
240
+ iterator = keys.next();
241
+ }
242
+ return;
243
+ }
244
+ this.instance.clear();
245
+ }
246
+ constructor(options = {}){
247
+ _define_property$3(this, "instance", undefined);
248
+ this.instance = new TTLCache({
249
+ checkAgeOnGet: true,
250
+ ttl: Infinity,
251
+ ...options || {}
252
+ });
253
+ }
254
+ }
255
+
256
+ /*
257
+ * Copyright (c) 2024-2024.
258
+ * Author Peter Placzek (tada5hi)
259
+ * For the full copyright and license information,
260
+ * view the LICENSE file that was distributed with this source code.
261
+ */ function _define_property$2(obj, key, value) {
262
+ if (key in obj) {
263
+ Object.defineProperty(obj, key, {
264
+ value: value,
265
+ enumerable: true,
266
+ configurable: true,
267
+ writable: true
268
+ });
269
+ } else {
270
+ obj[key] = value;
271
+ }
272
+ return obj;
273
+ }
274
+ class RedisCacheAdapter {
275
+ async get(key) {
276
+ return this.instance.get(key);
277
+ }
278
+ async has(key) {
279
+ const exists = await this.client.exists(key);
280
+ return !!exists;
281
+ }
282
+ async set(key, value, options) {
283
+ await this.instance.set(key, value, {
284
+ milliseconds: options.ttl
285
+ });
286
+ }
287
+ async drop(key) {
288
+ await this.instance.drop(key);
289
+ }
290
+ async dropMany(keys) {
291
+ const pipeline = this.client.pipeline();
292
+ for(let i = 0; i < keys.length; i++){
293
+ pipeline.del(keys[i]);
294
+ }
295
+ await pipeline.exec();
296
+ }
297
+ async clear(options = {}) {
298
+ if (options.prefix) {
299
+ const pipeline = this.client.pipeline();
300
+ const keys = await this.client.keys(`${options.prefix}*`);
301
+ for(let i = 0; i < keys.length; i++){
302
+ pipeline.del(keys[i]);
303
+ }
304
+ await pipeline.exec();
305
+ return;
306
+ }
307
+ await this.client.flushdb();
308
+ }
309
+ constructor(){
310
+ _define_property$2(this, "client", undefined);
311
+ _define_property$2(this, "instance", undefined);
312
+ this.client = useRedisClient();
313
+ this.instance = new redisExtension.JsonAdapter(this.client);
314
+ }
315
+ }
316
+
317
+ function createCacheAdapter() {
318
+ if (isRedisClientUsable()) {
319
+ return new RedisCacheAdapter();
320
+ }
321
+ return new MemoryCacheAdapter();
322
+ }
323
+
324
+ function buildCacheKey(options) {
325
+ return redisExtension.buildKeyPath(options);
326
+ }
327
+
328
+ /*
329
+ * Copyright (c) 2024.
330
+ * Author Peter Placzek (tada5hi)
331
+ * For the full copyright and license information,
332
+ * view the LICENSE file that was distributed with this source code.
333
+ */ function _define_property$1(obj, key, value) {
334
+ if (key in obj) {
335
+ Object.defineProperty(obj, key, {
336
+ value: value,
337
+ enumerable: true,
338
+ configurable: true,
339
+ writable: true
340
+ });
341
+ } else {
342
+ obj[key] = value;
343
+ }
344
+ return obj;
345
+ }
346
+ class Cache {
347
+ async set(key, value, options = {}) {
348
+ await this.adapter.set(key, value, options);
349
+ }
350
+ async get(key) {
351
+ return this.adapter.get(key);
352
+ }
353
+ async has(key) {
354
+ return this.adapter.has(key);
355
+ }
356
+ async drop(key) {
357
+ return this.adapter.drop(key);
358
+ }
359
+ async dropMany(keys) {
360
+ return this.adapter.dropMany(keys);
361
+ }
362
+ async clear(options = {}) {
363
+ return this.adapter.clear(options);
364
+ }
365
+ constructor(adapter){
366
+ _define_property$1(this, "adapter", undefined);
367
+ this.adapter = adapter;
368
+ }
369
+ }
370
+
371
+ const instance$2 = singa.singa({
372
+ name: 'cache',
373
+ factory: ()=>{
374
+ let adapter;
375
+ if (isRedisClientUsable()) {
376
+ adapter = new RedisCacheAdapter();
377
+ } else {
378
+ adapter = new MemoryCacheAdapter();
379
+ }
380
+ return new Cache(adapter);
381
+ }
382
+ });
383
+ function useCache() {
384
+ return instance$2.use();
385
+ }
214
386
 
215
387
  function createLogger(ctx = {}) {
216
388
  const { directory, options = {} } = ctx;
@@ -251,51 +423,19 @@ function createLogger(ctx = {}) {
251
423
  });
252
424
  }
253
425
 
254
- const instance$4 = singa.singa({
426
+ const instance$1 = singa.singa({
255
427
  name: 'logger'
256
428
  });
257
429
  function setLoggerFactory(factory) {
258
- instance$4.setFactory(factory);
430
+ instance$1.setFactory(factory);
259
431
  }
260
432
  function isLoggerUsable() {
261
- return instance$4.has() || instance$4.hasFactory();
433
+ return instance$1.has() || instance$1.hasFactory();
262
434
  }
263
435
  function setLogger(input) {
264
- instance$4.set(input);
436
+ instance$1.set(input);
265
437
  }
266
438
  function useLogger() {
267
- return instance$4.use();
268
- }
269
-
270
- const instance$3 = singa.singa({
271
- name: 'redis'
272
- });
273
- function setRedisFactory(factory) {
274
- instance$3.setFactory(factory);
275
- }
276
- function isRedisClientUsable() {
277
- return instance$3.has() || instance$3.hasFactory();
278
- }
279
- function setRedisClient(input) {
280
- instance$3.set(input);
281
- }
282
- function useRedisClient() {
283
- return instance$3.use();
284
- }
285
-
286
- const instance$2 = singa.singa({
287
- name: 'redisPublish',
288
- factory: ()=>useRedisClient().duplicate()
289
- });
290
- function useRedisPublishClient() {
291
- return instance$2.use();
292
- }
293
-
294
- const instance$1 = singa.singa({
295
- name: 'redisSubscribe',
296
- factory: ()=>useRedisClient().duplicate()
297
- });
298
- function useRedisSubscribeClient() {
299
439
  return instance$1.use();
300
440
  }
301
441
 
@@ -338,7 +478,7 @@ class QueueRouter {
338
478
  return exchange.publish(message.metadata.routing.key, message, {
339
479
  type: message.type,
340
480
  messageId: message.id,
341
- persistent: message.metadata.persistent ?? message.metadata.routing.type === exports.QueueRouterRoutingType.WORK
481
+ persistent: message.metadata.persistent ?? message.metadata.routing.type === QueueRouterRoutingType.WORK
342
482
  });
343
483
  }
344
484
  consume(routing, handlers) {
@@ -355,9 +495,9 @@ class QueueRouter {
355
495
  });
356
496
  }
357
497
  return exchange.consume(routing.key, {
358
- prefetchCount: routing.type === exports.QueueRouterRoutingType.WORK ? 1 : undefined,
498
+ prefetchCount: routing.type === QueueRouterRoutingType.WORK ? 1 : undefined,
359
499
  // noAck: routing.type !== QueueRouterRoutingType.WORK,
360
- requeueOnFailure: routing.type === exports.QueueRouterRoutingType.WORK
500
+ requeueOnFailure: routing.type === QueueRouterRoutingType.WORK
361
501
  }, {
362
502
  $any: async (input)=>{
363
503
  const payload = JSON.parse(input.content.toString('utf-8'));
@@ -391,7 +531,7 @@ class QueueRouter {
391
531
  }
392
532
  //----------------------------------------------------------------
393
533
  constructor(driver){
394
- _define_property(this, "driver", void 0);
534
+ _define_property(this, "driver", undefined);
395
535
  this.driver = driver;
396
536
  }
397
537
  }
@@ -500,10 +640,6 @@ Object.defineProperty(exports, "mountAuthupClientResponseErrorTokenHook", {
500
640
  enumerable: true,
501
641
  get: function () { return coreHttpKit.mountClientResponseErrorTokenHook; }
502
642
  });
503
- Object.defineProperty(exports, "RedisCache", {
504
- enumerable: true,
505
- get: function () { return redisExtension.Cache; }
506
- });
507
643
  Object.defineProperty(exports, "RedisClient", {
508
644
  enumerable: true,
509
645
  get: function () { return redisExtension.Client; }
@@ -512,10 +648,6 @@ Object.defineProperty(exports, "RedisClientOptions", {
512
648
  enumerable: true,
513
649
  get: function () { return redisExtension.ClientOptions; }
514
650
  });
515
- Object.defineProperty(exports, "RedisKeyPathID", {
516
- enumerable: true,
517
- get: function () { return redisExtension.KeyPathID; }
518
- });
519
651
  Object.defineProperty(exports, "buildRedisKeyPath", {
520
652
  enumerable: true,
521
653
  get: function () { return redisExtension.buildKeyPath; }
@@ -525,10 +657,15 @@ Object.defineProperty(exports, "createRedisClient", {
525
657
  get: function () { return redisExtension.createClient; }
526
658
  });
527
659
  exports.AuthupClient = AuthupClient;
660
+ exports.Cache = Cache;
528
661
  exports.ComponentError = ComponentError;
529
- exports.MemoryCache = MemoryCache;
662
+ exports.MemoryCacheAdapter = MemoryCacheAdapter;
530
663
  exports.QueueRouter = QueueRouter;
664
+ exports.QueueRouterRoutingType = QueueRouterRoutingType;
665
+ exports.RedisCacheAdapter = RedisCacheAdapter;
666
+ exports.buildCacheKey = buildCacheKey;
531
667
  exports.buildQueueRouterPublishPayload = buildQueueRouterPublishPayload;
668
+ exports.createCacheAdapter = createCacheAdapter;
532
669
  exports.createLogger = createLogger;
533
670
  exports.guessAuthupTokenCreatorOptions = guessAuthupTokenCreatorOptions;
534
671
  exports.hasOwnProperty = hasOwnProperty;
@@ -553,8 +690,8 @@ exports.setRedisFactory = setRedisFactory;
553
690
  exports.setVaultFactory = setVaultFactory;
554
691
  exports.useAmqpClient = useAmqpClient;
555
692
  exports.useAuthupClient = useAuthupClient;
693
+ exports.useCache = useCache;
556
694
  exports.useLogger = useLogger;
557
- exports.useMemoryCache = useMemoryCache;
558
695
  exports.useQueueRouter = useQueueRouter;
559
696
  exports.useRedisClient = useRedisClient;
560
697
  exports.useRedisPublishClient = useRedisPublishClient;