mblabs-roccato-backend-commons 1.0.75 → 1.0.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants/{storage.d.ts → context.d.ts} +2 -2
- package/dist/constants/{storage.js → context.js} +2 -2
- package/dist/constants/index.d.ts +2 -2
- package/dist/constants/index.js +3 -3
- package/dist/services/context.d.ts +8 -0
- package/dist/services/context.js +30 -0
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +3 -1
- package/package.json +1 -1
- package/src/constants/{storage.ts → context.ts} +2 -2
- package/src/constants/index.ts +2 -2
- package/src/services/context.ts +35 -0
- package/src/services/index.ts +2 -0
package/dist/constants/index.js
CHANGED
|
@@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.CONTEXT = exports.LOCALES = exports.DATE = void 0;
|
|
7
|
+
const context_1 = __importDefault(require("./context"));
|
|
8
|
+
exports.CONTEXT = context_1.default;
|
|
7
9
|
const date_1 = __importDefault(require("./date"));
|
|
8
10
|
exports.DATE = date_1.default;
|
|
9
11
|
const locales_1 = __importDefault(require("./locales"));
|
|
10
12
|
exports.LOCALES = locales_1.default;
|
|
11
|
-
const storage_1 = __importDefault(require("./storage"));
|
|
12
|
-
exports.STORAGE = storage_1.default;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const async_hooks_1 = require("async_hooks");
|
|
4
|
+
class ContextService {
|
|
5
|
+
static storage = new async_hooks_1.AsyncLocalStorage();
|
|
6
|
+
static init() {
|
|
7
|
+
this.storage.enterWith(new Map());
|
|
8
|
+
}
|
|
9
|
+
static set(key, value) {
|
|
10
|
+
const store = this.storage.getStore();
|
|
11
|
+
if (store) {
|
|
12
|
+
store.set(key, value);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
static get(key) {
|
|
16
|
+
const store = this.storage.getStore();
|
|
17
|
+
return store?.get(key);
|
|
18
|
+
}
|
|
19
|
+
static has(key) {
|
|
20
|
+
const store = this.storage.getStore();
|
|
21
|
+
return store?.has(key) ?? false;
|
|
22
|
+
}
|
|
23
|
+
static clear() {
|
|
24
|
+
const store = this.storage.getStore();
|
|
25
|
+
if (store) {
|
|
26
|
+
store.clear();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.default = ContextService;
|
package/dist/services/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService } from './aws';
|
|
2
2
|
import { AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService } from './azure';
|
|
3
|
+
import ContextService from './context';
|
|
3
4
|
import DateService from './date';
|
|
4
5
|
import ElasticAPMService from './elastic-apm';
|
|
5
6
|
import FileService from './file';
|
|
@@ -13,4 +14,4 @@ import NodeMailerService from './nodemailer';
|
|
|
13
14
|
import RabbitMQService from './rabbit';
|
|
14
15
|
import RedisService from './redis';
|
|
15
16
|
import SendgridService from './sendgrid';
|
|
16
|
-
export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, DateService, ElasticAPMService, FileService, FirebaseService, GoogleAuthService, GoogleCalendarService, GoogleMonitorService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
|
|
17
|
+
export { AmazonCloudwatchService, AmazonPinpointService, AmazonS3Service, AmazonSecretManagerService, AmazonSQSService, AzureApplicationInsightsService, AzureAuthService, AzureCalendarService, AzureCommunicationService, AzureKeyVaultService, AzureStorageBlobService, ContextService, DateService, ElasticAPMService, FileService, FirebaseService, GoogleAuthService, GoogleCalendarService, GoogleMonitorService, GoogleSecretsService, GoogleSheetsService, GoogleStorageService, GrafanaService, I18nService, KafkaService, KeycloakService, NodeMailerService, RabbitMQService, RedisService, SendgridService, };
|
package/dist/services/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SendgridService = exports.RedisService = exports.RabbitMQService = exports.NodeMailerService = exports.KeycloakService = exports.KafkaService = exports.I18nService = exports.GrafanaService = exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleMonitorService = exports.GoogleCalendarService = exports.GoogleAuthService = exports.FirebaseService = exports.FileService = exports.ElasticAPMService = exports.DateService = exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureCalendarService = exports.AzureAuthService = exports.AzureApplicationInsightsService = exports.AmazonSQSService = exports.AmazonSecretManagerService = exports.AmazonS3Service = exports.AmazonPinpointService = exports.AmazonCloudwatchService = void 0;
|
|
6
|
+
exports.SendgridService = exports.RedisService = exports.RabbitMQService = exports.NodeMailerService = exports.KeycloakService = exports.KafkaService = exports.I18nService = exports.GrafanaService = exports.GoogleStorageService = exports.GoogleSheetsService = exports.GoogleSecretsService = exports.GoogleMonitorService = exports.GoogleCalendarService = exports.GoogleAuthService = exports.FirebaseService = exports.FileService = exports.ElasticAPMService = exports.DateService = exports.ContextService = exports.AzureStorageBlobService = exports.AzureKeyVaultService = exports.AzureCommunicationService = exports.AzureCalendarService = exports.AzureAuthService = exports.AzureApplicationInsightsService = exports.AmazonSQSService = exports.AmazonSecretManagerService = exports.AmazonS3Service = exports.AmazonPinpointService = exports.AmazonCloudwatchService = void 0;
|
|
7
7
|
const aws_1 = require("./aws");
|
|
8
8
|
Object.defineProperty(exports, "AmazonCloudwatchService", { enumerable: true, get: function () { return aws_1.AmazonCloudwatchService; } });
|
|
9
9
|
Object.defineProperty(exports, "AmazonPinpointService", { enumerable: true, get: function () { return aws_1.AmazonPinpointService; } });
|
|
@@ -17,6 +17,8 @@ Object.defineProperty(exports, "AzureCalendarService", { enumerable: true, get:
|
|
|
17
17
|
Object.defineProperty(exports, "AzureCommunicationService", { enumerable: true, get: function () { return azure_1.AzureCommunicationService; } });
|
|
18
18
|
Object.defineProperty(exports, "AzureKeyVaultService", { enumerable: true, get: function () { return azure_1.AzureKeyVaultService; } });
|
|
19
19
|
Object.defineProperty(exports, "AzureStorageBlobService", { enumerable: true, get: function () { return azure_1.AzureStorageBlobService; } });
|
|
20
|
+
const context_1 = __importDefault(require("./context"));
|
|
21
|
+
exports.ContextService = context_1.default;
|
|
20
22
|
const date_1 = __importDefault(require("./date"));
|
|
21
23
|
exports.DateService = date_1.default;
|
|
22
24
|
const elastic_apm_1 = __importDefault(require("./elastic-apm"));
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
|
|
3
|
+
export default class ContextService {
|
|
4
|
+
private static storage = new AsyncLocalStorage<Map<string, unknown>>();
|
|
5
|
+
|
|
6
|
+
public static init () {
|
|
7
|
+
this.storage.enterWith(new Map());
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
public static set<T> (key: string, value: T): void {
|
|
11
|
+
const store = this.storage.getStore();
|
|
12
|
+
|
|
13
|
+
if (store) {
|
|
14
|
+
store.set(key, value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public static get<T> (key: string): T | undefined {
|
|
19
|
+
const store = this.storage.getStore();
|
|
20
|
+
return store?.get(key) as T | undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static has (key: string): boolean {
|
|
24
|
+
const store = this.storage.getStore();
|
|
25
|
+
return store?.has(key) ?? false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static clear (): void {
|
|
29
|
+
const store = this.storage.getStore();
|
|
30
|
+
|
|
31
|
+
if (store) {
|
|
32
|
+
store.clear();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/services/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
AzureKeyVaultService,
|
|
14
14
|
AzureStorageBlobService,
|
|
15
15
|
} from './azure';
|
|
16
|
+
import ContextService from './context';
|
|
16
17
|
import DateService from './date';
|
|
17
18
|
import ElasticAPMService from './elastic-apm';
|
|
18
19
|
import FileService from './file';
|
|
@@ -46,6 +47,7 @@ export {
|
|
|
46
47
|
AzureCommunicationService,
|
|
47
48
|
AzureKeyVaultService,
|
|
48
49
|
AzureStorageBlobService,
|
|
50
|
+
ContextService,
|
|
49
51
|
DateService,
|
|
50
52
|
ElasticAPMService,
|
|
51
53
|
FileService,
|