@privateaim/server-kit 0.7.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.
Files changed (154) hide show
  1. package/CHANGELOG.md +205 -0
  2. package/LICENSE +202 -0
  3. package/dist/core/aggregator/index.d.ts +2 -0
  4. package/dist/core/aggregator/index.d.ts.map +1 -0
  5. package/dist/core/aggregator/type.d.ts +4 -0
  6. package/dist/core/aggregator/type.d.ts.map +1 -0
  7. package/dist/core/component/error.d.ts +6 -0
  8. package/dist/core/component/error.d.ts.map +1 -0
  9. package/dist/core/component/helper.d.ts +3 -0
  10. package/dist/core/component/helper.d.ts.map +1 -0
  11. package/dist/core/component/index.d.ts +4 -0
  12. package/dist/core/component/index.d.ts.map +1 -0
  13. package/dist/core/component/type.d.ts +17 -0
  14. package/dist/core/component/type.d.ts.map +1 -0
  15. package/dist/core/index.d.ts +5 -0
  16. package/dist/core/index.d.ts.map +1 -0
  17. package/dist/core/queue/index.d.ts +3 -0
  18. package/dist/core/queue/index.d.ts.map +1 -0
  19. package/dist/core/queue/type.d.ts +12 -0
  20. package/dist/core/queue/type.d.ts.map +1 -0
  21. package/dist/core/queue/utils.d.ts +3 -0
  22. package/dist/core/queue/utils.d.ts.map +1 -0
  23. package/dist/core/queue-router/constants.d.ts +5 -0
  24. package/dist/core/queue-router/constants.d.ts.map +1 -0
  25. package/dist/core/queue-router/helpers.d.ts +4 -0
  26. package/dist/core/queue-router/helpers.d.ts.map +1 -0
  27. package/dist/core/queue-router/index.d.ts +6 -0
  28. package/dist/core/queue-router/index.d.ts.map +1 -0
  29. package/dist/core/queue-router/module.d.ts +9 -0
  30. package/dist/core/queue-router/module.d.ts.map +1 -0
  31. package/dist/core/queue-router/singleton.d.ts +4 -0
  32. package/dist/core/queue-router/singleton.d.ts.map +1 -0
  33. package/dist/core/queue-router/types.d.ts +31 -0
  34. package/dist/core/queue-router/types.d.ts.map +1 -0
  35. package/dist/domain-event/index.d.ts +5 -0
  36. package/dist/domain-event/index.d.ts.map +1 -0
  37. package/dist/domain-event/publish.d.ts +5 -0
  38. package/dist/domain-event/publish.d.ts.map +1 -0
  39. package/dist/domain-event/redis/index.d.ts +2 -0
  40. package/dist/domain-event/redis/index.d.ts.map +1 -0
  41. package/dist/domain-event/redis/publish.d.ts +5 -0
  42. package/dist/domain-event/redis/publish.d.ts.map +1 -0
  43. package/dist/domain-event/socket/index.d.ts +2 -0
  44. package/dist/domain-event/socket/index.d.ts.map +1 -0
  45. package/dist/domain-event/socket/publish.d.ts +5 -0
  46. package/dist/domain-event/socket/publish.d.ts.map +1 -0
  47. package/dist/domain-event/type.d.ts +7 -0
  48. package/dist/domain-event/type.d.ts.map +1 -0
  49. package/dist/domain-event/utils.d.ts +4 -0
  50. package/dist/domain-event/utils.d.ts.map +1 -0
  51. package/dist/index.cjs +492 -0
  52. package/dist/index.cjs.map +1 -0
  53. package/dist/index.d.ts +6 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.mjs +422 -0
  56. package/dist/index.mjs.map +1 -0
  57. package/dist/services/amqp/index.d.ts +2 -0
  58. package/dist/services/amqp/index.d.ts.map +1 -0
  59. package/dist/services/amqp/module.d.ts +6 -0
  60. package/dist/services/amqp/module.d.ts.map +1 -0
  61. package/dist/services/authup/helpers.d.ts +3 -0
  62. package/dist/services/authup/helpers.d.ts.map +1 -0
  63. package/dist/services/authup/index.d.ts +4 -0
  64. package/dist/services/authup/index.d.ts.map +1 -0
  65. package/dist/services/authup/module.d.ts +7 -0
  66. package/dist/services/authup/module.d.ts.map +1 -0
  67. package/dist/services/authup/singleton.d.ts +6 -0
  68. package/dist/services/authup/singleton.d.ts.map +1 -0
  69. package/dist/services/index.d.ts +6 -0
  70. package/dist/services/index.d.ts.map +1 -0
  71. package/dist/services/logger/index.d.ts +4 -0
  72. package/dist/services/logger/index.d.ts.map +1 -0
  73. package/dist/services/logger/module.d.ts +4 -0
  74. package/dist/services/logger/module.d.ts.map +1 -0
  75. package/dist/services/logger/singleton.d.ts +7 -0
  76. package/dist/services/logger/singleton.d.ts.map +1 -0
  77. package/dist/services/logger/types.d.ts +8 -0
  78. package/dist/services/logger/types.d.ts.map +1 -0
  79. package/dist/services/redis/helpers.d.ts +3 -0
  80. package/dist/services/redis/helpers.d.ts.map +1 -0
  81. package/dist/services/redis/index.d.ts +6 -0
  82. package/dist/services/redis/index.d.ts.map +1 -0
  83. package/dist/services/redis/module.d.ts +3 -0
  84. package/dist/services/redis/module.d.ts.map +1 -0
  85. package/dist/services/redis/singleton-publish.d.ts +3 -0
  86. package/dist/services/redis/singleton-publish.d.ts.map +1 -0
  87. package/dist/services/redis/singleton-subscribe.d.ts +3 -0
  88. package/dist/services/redis/singleton-subscribe.d.ts.map +1 -0
  89. package/dist/services/redis/singleton.d.ts +7 -0
  90. package/dist/services/redis/singleton.d.ts.map +1 -0
  91. package/dist/services/vault/index.d.ts +3 -0
  92. package/dist/services/vault/index.d.ts.map +1 -0
  93. package/dist/services/vault/module.d.ts +3 -0
  94. package/dist/services/vault/module.d.ts.map +1 -0
  95. package/dist/services/vault/singleton.d.ts +6 -0
  96. package/dist/services/vault/singleton.d.ts.map +1 -0
  97. package/dist/type.d.ts +2 -0
  98. package/dist/type.d.ts.map +1 -0
  99. package/dist/utils/has-property.d.ts +2 -0
  100. package/dist/utils/has-property.d.ts.map +1 -0
  101. package/dist/utils/index.d.ts +2 -0
  102. package/dist/utils/index.d.ts.map +1 -0
  103. package/package.json +54 -0
  104. package/rollup.config.mjs +14 -0
  105. package/src/core/aggregator/index.ts +8 -0
  106. package/src/core/aggregator/type.ts +10 -0
  107. package/src/core/component/error.ts +18 -0
  108. package/src/core/component/helper.ts +28 -0
  109. package/src/core/component/index.ts +10 -0
  110. package/src/core/component/type.ts +32 -0
  111. package/src/core/index.ts +11 -0
  112. package/src/core/queue/index.ts +9 -0
  113. package/src/core/queue/type.ts +23 -0
  114. package/src/core/queue/utils.ts +17 -0
  115. package/src/core/queue-router/constants.ts +11 -0
  116. package/src/core/queue-router/helpers.ts +33 -0
  117. package/src/core/queue-router/index.ts +12 -0
  118. package/src/core/queue-router/module.ts +111 -0
  119. package/src/core/queue-router/singleton.ts +27 -0
  120. package/src/core/queue-router/types.ts +58 -0
  121. package/src/domain-event/index.ts +11 -0
  122. package/src/domain-event/publish.ts +21 -0
  123. package/src/domain-event/redis/index.ts +8 -0
  124. package/src/domain-event/redis/publish.ts +41 -0
  125. package/src/domain-event/socket/index.ts +8 -0
  126. package/src/domain-event/socket/publish.ts +57 -0
  127. package/src/domain-event/type.ts +14 -0
  128. package/src/domain-event/utils.ts +34 -0
  129. package/src/index.ts +12 -0
  130. package/src/services/amqp/index.ts +8 -0
  131. package/src/services/amqp/module.ts +26 -0
  132. package/src/services/authup/helpers.ts +28 -0
  133. package/src/services/authup/index.ts +10 -0
  134. package/src/services/authup/module.ts +28 -0
  135. package/src/services/authup/singleton.ts +26 -0
  136. package/src/services/index.ts +12 -0
  137. package/src/services/logger/index.ts +10 -0
  138. package/src/services/logger/module.ts +56 -0
  139. package/src/services/logger/singleton.ts +29 -0
  140. package/src/services/logger/types.ts +19 -0
  141. package/src/services/redis/helpers.ts +12 -0
  142. package/src/services/redis/index.ts +12 -0
  143. package/src/services/redis/module.ts +22 -0
  144. package/src/services/redis/singleton-publish.ts +19 -0
  145. package/src/services/redis/singleton-subscribe.ts +19 -0
  146. package/src/services/redis/singleton.ts +30 -0
  147. package/src/services/vault/index.ts +9 -0
  148. package/src/services/vault/module.ts +13 -0
  149. package/src/services/vault/singleton.ts +26 -0
  150. package/src/type.ts +8 -0
  151. package/src/utils/has-property.ts +13 -0
  152. package/src/utils/index.ts +8 -0
  153. package/tsconfig.build.json +11 -0
  154. package/tsconfig.json +9 -0
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { DomainEventName } from '@privateaim/core-kit';
9
+ import type { DomainsEventContext } from '@privateaim/core-kit';
10
+ import type { Client } from 'redis-extension';
11
+ import type { DomainEventDestinations } from '../type';
12
+ import { buildDomainEventChannelName, transformDomainEventData } from '../utils';
13
+
14
+ export async function publishDomainRedisEvent(
15
+ client: Client,
16
+ context: DomainsEventContext,
17
+ destinations: DomainEventDestinations,
18
+ ) : Promise<any> {
19
+ context = transformDomainEventData(context);
20
+
21
+ const json = JSON.stringify(context);
22
+
23
+ const pipeline = client.pipeline();
24
+ for (let i = 0; i < destinations.length; i++) {
25
+ const { namespace } = destinations[i];
26
+ const keyPrefix = (namespace ? `${namespace}:` : '');
27
+
28
+ let key = keyPrefix + buildDomainEventChannelName(destinations[i].channel);
29
+ pipeline.publish(key, json);
30
+
31
+ if (
32
+ context.event !== DomainEventName.CREATED &&
33
+ typeof destinations[i].channel === 'function'
34
+ ) {
35
+ key = keyPrefix + buildDomainEventChannelName(destinations[i].channel, context.data.id);
36
+ pipeline.publish(key, json);
37
+ }
38
+ }
39
+
40
+ return pipeline.exec();
41
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2021-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './publish';
@@ -0,0 +1,57 @@
1
+ /*
2
+ * Copyright (c) 2022-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { DomainsEventContext } from '@privateaim/core-kit';
9
+ import { DomainEventName, buildDomainEventFullName } from '@privateaim/core-kit';
10
+ import { Emitter } from '@socket.io/redis-emitter';
11
+ import type { Client } from 'redis-extension';
12
+ import type { DomainEventDestinations } from '../type';
13
+ import { buildDomainEventChannelName, transformDomainEventData } from '../utils';
14
+
15
+ export function publishDomainSocketEvent(
16
+ client: Client,
17
+ context: DomainsEventContext,
18
+ destinations: DomainEventDestinations,
19
+ ) {
20
+ context = transformDomainEventData(context);
21
+
22
+ for (let i = 0; i < destinations.length; i++) {
23
+ let emitter = new Emitter(client);
24
+ if (destinations[i].namespace) {
25
+ emitter = emitter.of(destinations[i].namespace);
26
+ }
27
+
28
+ let roomName = buildDomainEventChannelName(destinations[i].channel);
29
+
30
+ const fullEventName = buildDomainEventFullName(context.type, context.event);
31
+
32
+ emitter
33
+ .in(roomName)
34
+ .emit(fullEventName, {
35
+ ...context,
36
+ meta: {
37
+ roomName,
38
+ },
39
+ });
40
+
41
+ if (
42
+ context.event !== DomainEventName.CREATED &&
43
+ typeof destinations[i].channel === 'function'
44
+ ) {
45
+ roomName = buildDomainEventChannelName(destinations[i].channel, context.data.id);
46
+ emitter
47
+ .in(roomName)
48
+ .emit(fullEventName, {
49
+ ...context,
50
+ meta: {
51
+ roomName,
52
+ roomId: context.data.id,
53
+ },
54
+ });
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright (c) 2022-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export type DomainEventChannelName = string | ((id?: string | number) => string);
9
+ export type DomainEventDestination = {
10
+ namespace?: string,
11
+ channel: DomainEventChannelName
12
+ };
13
+
14
+ export type DomainEventDestinations = DomainEventDestination[];
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { isObject } from '@privateaim/kit';
9
+ import type { DomainEventChannelName } from './type';
10
+
11
+ export function transformDomainEventData<T>(input: T) : T {
12
+ if (isObject(input)) {
13
+ const keys = Object.keys(input);
14
+ for (let i = 0; i < keys.length; i++) {
15
+ const value = input[keys[i]];
16
+ if (value instanceof Date) {
17
+ input[keys[i]] = value.toISOString();
18
+ }
19
+ }
20
+ }
21
+
22
+ return input;
23
+ }
24
+
25
+ export function buildDomainEventChannelName(
26
+ input: DomainEventChannelName,
27
+ id?: string | number,
28
+ ) : string {
29
+ if (typeof input === 'string') {
30
+ return input;
31
+ }
32
+
33
+ return input(id);
34
+ }
package/src/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './core';
9
+ export * from './services';
10
+ export * from './domain-event';
11
+ export * from './type';
12
+ export * from './utils';
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Client } from 'amqp-extension';
9
+ import type { Factory } from 'singa';
10
+ import { singa } from 'singa';
11
+
12
+ const instance = singa<Client>({
13
+ name: 'amqp',
14
+ });
15
+
16
+ export function setAmqpClientFactory(factory: Factory<Client>) {
17
+ instance.setFactory(factory);
18
+ }
19
+
20
+ export function isAmqpClientUsable() {
21
+ return instance.has() || instance.hasFactory();
22
+ }
23
+
24
+ export function useAmqpClient() {
25
+ return instance.use();
26
+ }
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { TokenCreatorOptions } from '@authup/core-http-kit';
9
+ import { isVaultClientUsable, useVaultClient } from '../vault';
10
+
11
+ export function guessAuthupTokenCreatorOptions() : TokenCreatorOptions {
12
+ let options : TokenCreatorOptions;
13
+ if (isVaultClientUsable()) {
14
+ options = {
15
+ type: 'robotInVault',
16
+ name: 'system',
17
+ vault: useVaultClient(),
18
+ };
19
+ } else {
20
+ options = {
21
+ type: 'user',
22
+ name: 'admin',
23
+ password: 'start123',
24
+ };
25
+ }
26
+
27
+ return options;
28
+ }
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './helpers';
9
+ export * from './module';
10
+ export * from './singleton';
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { ClientOptions } from '@authup/core-http-kit';
9
+ import {
10
+ Client, mountClientResponseErrorTokenHook as mountAuthupClientResponseErrorTokenHook,
11
+ mountClientResponseErrorTokenHook,
12
+ } from '@authup/core-http-kit';
13
+ import { guessAuthupTokenCreatorOptions } from './helpers';
14
+
15
+ export {
16
+ mountAuthupClientResponseErrorTokenHook,
17
+ };
18
+
19
+ export class AuthupClient extends Client {
20
+ constructor(options: ClientOptions = {}) {
21
+ super(options);
22
+
23
+ mountClientResponseErrorTokenHook(this, {
24
+ baseURL: options.baseURL,
25
+ tokenCreator: guessAuthupTokenCreatorOptions(),
26
+ });
27
+ }
28
+ }
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Client } from '@authup/core-http-kit';
9
+ import type { Factory } from 'singa';
10
+ import { singa } from 'singa';
11
+
12
+ const instance = singa<Client>({
13
+ name: 'authup',
14
+ });
15
+
16
+ export function useAuthupClient() {
17
+ return instance.use();
18
+ }
19
+
20
+ export function isAuthupClientUsable() {
21
+ return instance.has() || instance.hasFactory();
22
+ }
23
+
24
+ export function setAuthupClientFactory(factory: Factory<Client>) {
25
+ instance.setFactory(factory);
26
+ }
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './amqp';
9
+ export * from './authup';
10
+ export * from './logger';
11
+ export * from './redis';
12
+ export * from './vault';
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
9
+ export * from './types';
10
+ export * from './singleton';
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { read } from 'envix';
9
+ import path from 'node:path';
10
+ import { EnvironmentName } from 'typeorm-extension';
11
+ import type { Logger } from 'winston';
12
+ import { createLogger as create, format, transports } from 'winston';
13
+ import type { LoggerCreateContext, LoggerTransports } from './types';
14
+
15
+ export function createLogger(ctx: LoggerCreateContext = {}) : Logger {
16
+ const { directory, options = {} } = ctx;
17
+
18
+ let loggerTransports : LoggerTransports;
19
+ if (read('env') === EnvironmentName.PRODUCTION) {
20
+ loggerTransports = [
21
+ new transports.Console({
22
+ level: 'info',
23
+ }),
24
+ new transports.File({
25
+ filename: path.join(directory || process.cwd(), 'access.log'),
26
+ level: 'http',
27
+ maxsize: 10 * 1024 * 1024, // 10MB
28
+ maxFiles: 5,
29
+ }),
30
+ new transports.File({
31
+ filename: path.join(directory || process.cwd(), 'error.log'),
32
+ level: 'warn',
33
+ maxsize: 10 * 1024 * 1024, // 10MB
34
+ maxFiles: 5,
35
+ }),
36
+ ];
37
+ } else {
38
+ loggerTransports = [
39
+ new transports.Console({
40
+ level: 'debug',
41
+ }),
42
+ ];
43
+ }
44
+
45
+ return create({
46
+ format: format.combine(
47
+ format.timestamp(),
48
+ format.colorize(),
49
+ format.simple(),
50
+ ),
51
+ level: 'debug',
52
+ transports: loggerTransports,
53
+ // todo: deeply merge options
54
+ ...(options || {}),
55
+ });
56
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright (c) 2023.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { type Factory, singa } from 'singa';
9
+ import type { Logger } from 'winston';
10
+
11
+ const instance = singa<Logger>({
12
+ name: 'logger',
13
+ });
14
+
15
+ export function setLoggerFactory(factory: Factory<Logger>) {
16
+ instance.setFactory(factory);
17
+ }
18
+
19
+ export function isLoggerUsable() {
20
+ return instance.has() || instance.hasFactory();
21
+ }
22
+
23
+ export function setLogger(input: Logger) {
24
+ instance.set(input);
25
+ }
26
+
27
+ export function useLogger() {
28
+ return instance.use();
29
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Logger, LoggerOptions } from 'winston';
9
+
10
+ export type LoggerCreateContext = {
11
+ directory?: string,
12
+ options?: Partial<LoggerOptions>
13
+ };
14
+
15
+ export type LoggerTransports = LoggerOptions['transports'];
16
+
17
+ export type {
18
+ Logger,
19
+ };
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { buildKeyPath as buildRedisKeyPath } from 'redis-extension';
9
+
10
+ export {
11
+ buildRedisKeyPath,
12
+ };
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './helpers';
9
+ export * from './module';
10
+ export * from './singleton';
11
+ export * from './singleton-publish';
12
+ export * from './singleton-subscribe';
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import {
9
+ Cache as RedisCache,
10
+ Client as RedisClient,
11
+ ClientOptions as RedisClientOptions,
12
+ KeyPathID as RedisKeyPathID,
13
+ createClient as createRedisClient,
14
+ } from 'redis-extension';
15
+
16
+ export {
17
+ createRedisClient,
18
+ RedisClient,
19
+ RedisClientOptions,
20
+ RedisKeyPathID,
21
+ RedisCache,
22
+ };
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Client } from 'redis-extension';
9
+ import { singa } from 'singa';
10
+ import { useRedisClient } from './singleton';
11
+
12
+ const instance = singa<Client>({
13
+ name: 'redisPublish',
14
+ factory: () => useRedisClient().duplicate(),
15
+ });
16
+
17
+ export function useRedisPublishClient() {
18
+ return instance.use();
19
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Client } from 'redis-extension';
9
+ import { singa } from 'singa';
10
+ import { useRedisClient } from './singleton';
11
+
12
+ const instance = singa<Client>({
13
+ name: 'redisSubscribe',
14
+ factory: () => useRedisClient().duplicate(),
15
+ });
16
+
17
+ export function useRedisSubscribeClient() {
18
+ return instance.use();
19
+ }
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Client } from 'redis-extension';
9
+ import type { Factory } from 'singa';
10
+ import { singa } from 'singa';
11
+
12
+ const instance = singa<Client>({
13
+ name: 'redis',
14
+ });
15
+
16
+ export function setRedisFactory(factory: Factory<Client>) {
17
+ instance.setFactory(factory);
18
+ }
19
+
20
+ export function isRedisClientUsable() {
21
+ return instance.has() || instance.hasFactory();
22
+ }
23
+
24
+ export function setRedisClient(input: Client) {
25
+ instance.set(input);
26
+ }
27
+
28
+ export function useRedisClient() {
29
+ return instance.use();
30
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './module';
9
+ export * from './singleton';
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { VaultClient, createClient as createVaultClient } from '@hapic/vault';
9
+
10
+ export {
11
+ VaultClient,
12
+ createVaultClient,
13
+ };
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import type { Factory } from 'singa';
9
+ import { singa } from 'singa';
10
+ import type { VaultClient } from '@hapic/vault';
11
+
12
+ const instance = singa<VaultClient>({
13
+ name: 'vault',
14
+ });
15
+
16
+ export function setVaultFactory(factory: Factory<VaultClient>) {
17
+ instance.setFactory(factory);
18
+ }
19
+
20
+ export function isVaultClientUsable() {
21
+ return instance.has() || instance.hasFactory();
22
+ }
23
+
24
+ export function useVaultClient() {
25
+ return instance.use();
26
+ }
package/src/type.ts ADDED
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export type ObjectLiteral = Record<string, any>;
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright (c) 2022-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export function hasOwnProperty<X extends Record<string, any>, Y extends PropertyKey>(
9
+ obj: X,
10
+ prop: Y,
11
+ ): obj is X & Record<Y, unknown> {
12
+ return Object.prototype.hasOwnProperty.call(obj, prop);
13
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2022-2024.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './has-property';
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+
4
+ "compilerOptions": {
5
+ "outDir": "./dist"
6
+ },
7
+
8
+ "include": [
9
+ "src/**/*.ts"
10
+ ]
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "paths": {
5
+ "@privateaim/core-kit": ["./packages/core-kit/src"],
6
+ "@privateaim/kit": ["./packages/kit/src"]
7
+ }
8
+ }
9
+ }