@adalo/metrics 0.1.107 → 0.1.109
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/lib/redisUtils.d.ts +17 -12
- package/lib/redisUtils.d.ts.map +1 -1
- package/lib/redisUtils.js +26 -17
- package/lib/redisUtils.js.map +1 -1
- package/package.json +1 -1
- package/src/redisUtils.js +17 -17
package/lib/redisUtils.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Creates a configured setClientName function for node-redis v3.
|
|
3
3
|
*
|
|
4
|
-
* @param {string} [
|
|
4
|
+
* @param {string} [appName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.
|
|
5
5
|
* @returns {(client: any, name: string) => void}
|
|
6
6
|
*/
|
|
7
|
-
export function createSetClientNameForRedisV3(
|
|
7
|
+
export function createSetClientNameForRedisV3(appName?: string | undefined): (client: any, name: string) => void;
|
|
8
8
|
/**
|
|
9
9
|
* Creates a function to set Redis client name for node-redis v4.
|
|
10
10
|
*
|
|
11
|
-
* @param {string} [
|
|
11
|
+
* @param {string} [appName='undefined-app']
|
|
12
12
|
* @returns {(client: any, name: string) => void}
|
|
13
13
|
*/
|
|
14
|
-
export function createSetClientNameForRedisV4(
|
|
14
|
+
export function createSetClientNameForRedisV4(appName?: string | undefined): (client: any, name: string) => void;
|
|
15
15
|
/**
|
|
16
16
|
* Creates a function to set Redis client name for ioredis.
|
|
17
17
|
*
|
|
18
|
-
* @param {string} [
|
|
18
|
+
* @param {string} [appName='undefined-app']
|
|
19
19
|
* @returns {(client: any, name: string) => void}
|
|
20
20
|
*/
|
|
21
|
-
export function createSetClientNameForIoredis(
|
|
21
|
+
export function createSetClientNameForIoredis(appName?: string | undefined): (client: any, name: string) => void;
|
|
22
22
|
/**
|
|
23
23
|
* Check if a Redis client is an ioredis instance
|
|
24
24
|
*
|
|
@@ -37,12 +37,17 @@ export const REDIS_V4: "REDIS_V4";
|
|
|
37
37
|
export const REDIS_V3: "REDIS_V3";
|
|
38
38
|
export const IOREDIS: "IOREDIS";
|
|
39
39
|
/**
|
|
40
|
-
* Get default
|
|
40
|
+
* Get the default Redis client name.
|
|
41
41
|
*
|
|
42
|
-
* @param {
|
|
43
|
-
* @param {string} [
|
|
44
|
-
* @param
|
|
45
|
-
* @
|
|
42
|
+
* @param {Object} options - Options for generating Redis name.
|
|
43
|
+
* @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
|
|
44
|
+
* @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
|
|
45
|
+
* @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
|
|
46
|
+
* @returns {string} The generated Redis client name.
|
|
46
47
|
*/
|
|
47
|
-
export function getRedisName({ name, appName, processName }
|
|
48
|
+
export function getRedisName({ name, appName, processName }: {
|
|
49
|
+
name?: string | undefined;
|
|
50
|
+
appName?: string | undefined;
|
|
51
|
+
processName?: string | undefined;
|
|
52
|
+
}): string;
|
|
48
53
|
//# sourceMappingURL=redisUtils.d.ts.map
|
package/lib/redisUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redisUtils.d.ts","sourceRoot":"","sources":["../src/redisUtils.js"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"redisUtils.d.ts","sourceRoot":"","sources":["../src/redisUtils.js"],"names":[],"mappings":"AAoBA;;;;;GAKG;AACH,sFAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA4BD;;;;;GAKG;AACH,sFAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAmB/C;AAjDD;;;;;GAKG;AACH,sFAFsB,GAAG,QAAQ,MAAM,KAAK,IAAI,CAoB/C;AA2BD;;;;;GAKG;AACH,kCAHW,GAAG,GACD,OAAO,CASnB;AAED;;;;;GAKG;AACH,2CAHW,GAAG,GACD,MAAM,CAiBlB;AArID,kCAA2B;AAC3B,kCAA2B;AAC3B,gCAAyB;AAKzB;;;;;;;;GAQG;AACH;IAL4B,IAAI;IACJ,OAAO;IACP,WAAW;IAC1B,MAAM,CAIlB"}
|
package/lib/redisUtils.js
CHANGED
|
@@ -4,36 +4,39 @@ const REDIS_V4 = 'REDIS_V4';
|
|
|
4
4
|
const REDIS_V3 = 'REDIS_V3';
|
|
5
5
|
const IOREDIS = 'IOREDIS';
|
|
6
6
|
const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno';
|
|
7
|
-
const defaultAppName = process.env.BUILD_APP_NAME
|
|
7
|
+
const defaultAppName = process.env.BUILD_APP_NAME;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Get default
|
|
10
|
+
* Get the default Redis client name.
|
|
11
11
|
*
|
|
12
|
-
* @param {
|
|
13
|
-
* @param {string} [
|
|
14
|
-
* @param
|
|
15
|
-
* @
|
|
12
|
+
* @param {Object} options - Options for generating Redis name.
|
|
13
|
+
* @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
|
|
14
|
+
* @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
|
|
15
|
+
* @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
|
|
16
|
+
* @returns {string} The generated Redis client name.
|
|
16
17
|
*/
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/default-param-last
|
|
18
18
|
const getRedisName = ({
|
|
19
19
|
name = 'undefined-name',
|
|
20
20
|
appName,
|
|
21
21
|
processName
|
|
22
22
|
}) => {
|
|
23
|
-
return `${appName || defaultAppName}:${processName || dyno}:${name}`;
|
|
23
|
+
return `${appName || defaultAppName || 'undefined-app'}:${processName || dyno}:${name}`;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Creates a configured setClientName function for node-redis v3.
|
|
28
28
|
*
|
|
29
|
-
* @param {string} [
|
|
29
|
+
* @param {string} [appName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.
|
|
30
30
|
* @returns {(client: any, name: string) => void}
|
|
31
31
|
*/
|
|
32
|
-
const createSetClientNameForRedisV3 = (
|
|
32
|
+
const createSetClientNameForRedisV3 = (appName = 'undefined-app') => {
|
|
33
33
|
return (client, name) => {
|
|
34
34
|
if (process.env.NODE_ENV !== 'test') {
|
|
35
35
|
client.on('connect', () => {
|
|
36
|
-
client.send_command('CLIENT', ['SETNAME', getRedisName(
|
|
36
|
+
client.send_command('CLIENT', ['SETNAME', getRedisName({
|
|
37
|
+
name,
|
|
38
|
+
appName: defaultAppName || appName
|
|
39
|
+
})], err => {
|
|
37
40
|
if (err) {
|
|
38
41
|
console.error(`Failed to set client name for ${name}:`, err);
|
|
39
42
|
} else {
|
|
@@ -48,14 +51,17 @@ const createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {
|
|
|
48
51
|
/**
|
|
49
52
|
* Creates a function to set Redis client name for ioredis.
|
|
50
53
|
*
|
|
51
|
-
* @param {string} [
|
|
54
|
+
* @param {string} [appName='undefined-app']
|
|
52
55
|
* @returns {(client: any, name: string) => void}
|
|
53
56
|
*/
|
|
54
|
-
const createSetClientNameForIoredis = (
|
|
57
|
+
const createSetClientNameForIoredis = (appName = 'undefined-app') => {
|
|
55
58
|
return (client, name) => {
|
|
56
59
|
if (process.env.NODE_ENV !== 'test') {
|
|
57
60
|
client.once('connect', () => {
|
|
58
|
-
client.call('CLIENT', ['SETNAME', getRedisName(
|
|
61
|
+
client.call('CLIENT', ['SETNAME', getRedisName({
|
|
62
|
+
name,
|
|
63
|
+
appName: defaultAppName || appName
|
|
64
|
+
})]).then(() => {
|
|
59
65
|
console.log(`Connected to Redis for pid:${process.pid} (${name})`);
|
|
60
66
|
}).catch(err => {
|
|
61
67
|
console.error(`Failed to set client name for ${name}:`, err);
|
|
@@ -68,15 +74,18 @@ const createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {
|
|
|
68
74
|
/**
|
|
69
75
|
* Creates a function to set Redis client name for node-redis v4.
|
|
70
76
|
*
|
|
71
|
-
* @param {string} [
|
|
77
|
+
* @param {string} [appName='undefined-app']
|
|
72
78
|
* @returns {(client: any, name: string) => void}
|
|
73
79
|
*/
|
|
74
|
-
const createSetClientNameForRedisV4 = (
|
|
80
|
+
const createSetClientNameForRedisV4 = (appName = 'undefined-app') => {
|
|
75
81
|
return (client, name) => {
|
|
76
82
|
if (process.env.NODE_ENV !== 'test') {
|
|
77
83
|
client.on('ready', async () => {
|
|
78
84
|
try {
|
|
79
|
-
await client.sendCommand(['CLIENT', 'SETNAME', getRedisName(
|
|
85
|
+
await client.sendCommand(['CLIENT', 'SETNAME', getRedisName({
|
|
86
|
+
name,
|
|
87
|
+
appName: defaultAppName || appName
|
|
88
|
+
})]);
|
|
80
89
|
console.log(`Connected to Redis for pid:${process.pid} (${name})`);
|
|
81
90
|
} catch (err) {
|
|
82
91
|
console.error(`Failed to set client name for ${name}:`, err);
|
package/lib/redisUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redisUtils.js","names":["REDIS_V4","REDIS_V3","IOREDIS","dyno","process","env","BUILD_DYNO_PROCESS_TYPE","defaultAppName","BUILD_APP_NAME","getRedisName","name","appName","processName","createSetClientNameForRedisV3","client","NODE_ENV","on","send_command","err","console","error","log","pid","createSetClientNameForIoredis","once","call","then","catch","createSetClientNameForRedisV4","sendCommand","isIORedis","disconnect","options","undefined","getRedisClientType","info","Error","module","exports"],"sources":["../src/redisUtils.js"],"sourcesContent":["const REDIS_V4 = 'REDIS_V4'\nconst REDIS_V3 = 'REDIS_V3'\nconst IOREDIS = 'IOREDIS'\n\nconst dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\nconst defaultAppName = process.env.BUILD_APP_NAME
|
|
1
|
+
{"version":3,"file":"redisUtils.js","names":["REDIS_V4","REDIS_V3","IOREDIS","dyno","process","env","BUILD_DYNO_PROCESS_TYPE","defaultAppName","BUILD_APP_NAME","getRedisName","name","appName","processName","createSetClientNameForRedisV3","client","NODE_ENV","on","send_command","err","console","error","log","pid","createSetClientNameForIoredis","once","call","then","catch","createSetClientNameForRedisV4","sendCommand","isIORedis","disconnect","options","undefined","getRedisClientType","info","Error","module","exports"],"sources":["../src/redisUtils.js"],"sourcesContent":["const REDIS_V4 = 'REDIS_V4'\nconst REDIS_V3 = 'REDIS_V3'\nconst IOREDIS = 'IOREDIS'\n\nconst dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'\nconst defaultAppName = process.env.BUILD_APP_NAME\n\n/**\n * Get the default Redis client name.\n *\n * @param {Object} options - Options for generating Redis name.\n * @param {string} [options.name='undefined-name'] - Fallback name if none is provided.\n * @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.\n * @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.\n * @returns {string} The generated Redis client name.\n */\nconst getRedisName = ({ name = 'undefined-name', appName, processName }) => {\n return `${appName || defaultAppName || 'undefined-app'}:${processName || dyno}:${name}`\n}\n\n/**\n * Creates a configured setClientName function for node-redis v3.\n *\n * @param {string} [appName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV3 = (appName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('connect', () => {\n client.send_command(\n 'CLIENT',\n ['SETNAME', getRedisName({ name, appName: defaultAppName || appName })],\n err => {\n if (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n } else {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n }\n }\n )\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for ioredis.\n *\n * @param {string} [appName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForIoredis = (appName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.once('connect', () => {\n client\n .call('CLIENT', [\n 'SETNAME',\n getRedisName({ name, appName: defaultAppName || appName }),\n ])\n .then(() => {\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n })\n .catch(err => {\n console.error(`Failed to set client name for ${name}:`, err)\n })\n })\n }\n }\n}\n\n/**\n * Creates a function to set Redis client name for node-redis v4.\n *\n * @param {string} [appName='undefined-app']\n * @returns {(client: any, name: string) => void}\n */\nconst createSetClientNameForRedisV4 = (appName = 'undefined-app') => {\n return (client, name) => {\n if (process.env.NODE_ENV !== 'test') {\n client.on('ready', async () => {\n try {\n await client.sendCommand([\n 'CLIENT',\n 'SETNAME',\n getRedisName({ name, appName: defaultAppName || appName }),\n ])\n console.log(`Connected to Redis for pid:${process.pid} (${name})`)\n } catch (err) {\n console.error(`Failed to set client name for ${name}:`, err)\n }\n })\n }\n }\n}\n\n/**\n * Check if a Redis client is an ioredis instance\n *\n * @param {any} client - Redis client instance\n * @returns {boolean} True if the client is ioredis\n */\nconst isIORedis = client => {\n return (\n client &&\n typeof client.sendCommand === 'function' &&\n typeof client.disconnect === 'function' &&\n client.options !== undefined\n )\n}\n\n/**\n * Get Redis client type\n *\n * @param {any} client - Redis client instance\n * @returns {string} One of IOREDIS, REDIS_V3, REDIS_V4\n */\nconst getRedisClientType = client => {\n if (isIORedis(client)) {\n console.log('Detected node-redis ioredis')\n return IOREDIS\n }\n if (typeof client?.send_command === 'function') {\n console.log('Detected node-redis redis_v3')\n return REDIS_V3\n }\n if (typeof client.info === 'function') {\n console.log('Detected node-redis redis_v4')\n return REDIS_V4\n }\n\n throw new Error(`Failed to get Redis client type`)\n}\n\nmodule.exports = {\n createSetClientNameForRedisV3,\n createSetClientNameForRedisV4,\n createSetClientNameForIoredis,\n isIORedis,\n getRedisClientType,\n REDIS_V4,\n REDIS_V3,\n IOREDIS,\n getRedisName,\n}\n"],"mappings":";;AAAA,MAAMA,QAAQ,GAAG,UAAU;AAC3B,MAAMC,QAAQ,GAAG,UAAU;AAC3B,MAAMC,OAAO,GAAG,SAAS;AAEzB,MAAMC,IAAI,GAAGC,OAAO,CAACC,GAAG,CAACC,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ACN,OAAOA,MAAM,CAACe,WAAW,KAAK,UAAU,IACxC,OAAOf,MAAM,CAACiB,UAAU,KAAK,UAAU,IACvCjB,MAAM,CAACkB,OAAO,KAAKC,SAAS;AAEhC,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAGpB,MAAM,IAAI;EACnC,IAAIgB,SAAS,CAAChB,MAAM,CAAC,EAAE;IACrBK,OAAO,CAACE,GAAG,CAAC,6BAA6B,CAAC;IAC1C,OAAOnB,OAAO;EAChB;EACA,IAAI,OAAOY,MAAM,EAAEG,YAAY,KAAK,UAAU,EAAE;IAC9CE,OAAO,CAACE,GAAG,CAAC,8BAA8B,CAAC;IAC3C,OAAOpB,QAAQ;EACjB;EACA,IAAI,OAAOa,MAAM,CAACqB,IAAI,KAAK,UAAU,EAAE;IACrChB,OAAO,CAACE,GAAG,CAAC,8BAA8B,CAAC;IAC3C,OAAOrB,QAAQ;EACjB;EAEA,MAAM,IAAIoC,KAAK,CAAC,iCAAiC,CAAC;AACpD,CAAC;AAEDC,MAAM,CAACC,OAAO,GAAG;EACfzB,6BAA6B;EAC7Be,6BAA6B;EAC7BL,6BAA6B;EAC7BO,SAAS;EACTI,kBAAkB;EAClBlC,QAAQ;EACRC,QAAQ;EACRC,OAAO;EACPO;AACF,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
package/src/redisUtils.js
CHANGED
|
@@ -3,34 +3,34 @@ const REDIS_V3 = 'REDIS_V3'
|
|
|
3
3
|
const IOREDIS = 'IOREDIS'
|
|
4
4
|
|
|
5
5
|
const dyno = process.env.BUILD_DYNO_PROCESS_TYPE || 'undefined-dyno'
|
|
6
|
-
const defaultAppName = process.env.BUILD_APP_NAME
|
|
6
|
+
const defaultAppName = process.env.BUILD_APP_NAME
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Get default
|
|
9
|
+
* Get the default Redis client name.
|
|
10
10
|
*
|
|
11
|
-
* @param {
|
|
12
|
-
* @param {string} [
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
11
|
+
* @param {Object} options - Options for generating Redis name.
|
|
12
|
+
* @param {string} [options.name='undefined-name'] - Fallback name if none is provided.
|
|
13
|
+
* @param {string} [options.appName] - Application name. Defaults to `defaultAppName` if not set.
|
|
14
|
+
* @param {string} [options.processName] - Process name. Defaults to `dyno` if not set.
|
|
15
|
+
* @returns {string} The generated Redis client name.
|
|
15
16
|
*/
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/default-param-last
|
|
17
17
|
const getRedisName = ({ name = 'undefined-name', appName, processName }) => {
|
|
18
|
-
return `${appName || defaultAppName}:${processName || dyno}:${name}`
|
|
18
|
+
return `${appName || defaultAppName || 'undefined-app'}:${processName || dyno}:${name}`
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Creates a configured setClientName function for node-redis v3.
|
|
23
23
|
*
|
|
24
|
-
* @param {string} [
|
|
24
|
+
* @param {string} [appName='undefined-app'] - Fallback app name if BUILD_APP_NAME is not set.
|
|
25
25
|
* @returns {(client: any, name: string) => void}
|
|
26
26
|
*/
|
|
27
|
-
const createSetClientNameForRedisV3 = (
|
|
27
|
+
const createSetClientNameForRedisV3 = (appName = 'undefined-app') => {
|
|
28
28
|
return (client, name) => {
|
|
29
29
|
if (process.env.NODE_ENV !== 'test') {
|
|
30
30
|
client.on('connect', () => {
|
|
31
31
|
client.send_command(
|
|
32
32
|
'CLIENT',
|
|
33
|
-
['SETNAME', getRedisName(name, defaultAppName)],
|
|
33
|
+
['SETNAME', getRedisName({ name, appName: defaultAppName || appName })],
|
|
34
34
|
err => {
|
|
35
35
|
if (err) {
|
|
36
36
|
console.error(`Failed to set client name for ${name}:`, err)
|
|
@@ -47,17 +47,17 @@ const createSetClientNameForRedisV3 = (defaultAppName = 'undefined-app') => {
|
|
|
47
47
|
/**
|
|
48
48
|
* Creates a function to set Redis client name for ioredis.
|
|
49
49
|
*
|
|
50
|
-
* @param {string} [
|
|
50
|
+
* @param {string} [appName='undefined-app']
|
|
51
51
|
* @returns {(client: any, name: string) => void}
|
|
52
52
|
*/
|
|
53
|
-
const createSetClientNameForIoredis = (
|
|
53
|
+
const createSetClientNameForIoredis = (appName = 'undefined-app') => {
|
|
54
54
|
return (client, name) => {
|
|
55
55
|
if (process.env.NODE_ENV !== 'test') {
|
|
56
56
|
client.once('connect', () => {
|
|
57
57
|
client
|
|
58
58
|
.call('CLIENT', [
|
|
59
59
|
'SETNAME',
|
|
60
|
-
getRedisName(name, defaultAppName),
|
|
60
|
+
getRedisName({ name, appName: defaultAppName || appName }),
|
|
61
61
|
])
|
|
62
62
|
.then(() => {
|
|
63
63
|
console.log(`Connected to Redis for pid:${process.pid} (${name})`)
|
|
@@ -73,10 +73,10 @@ const createSetClientNameForIoredis = (defaultAppName = 'undefined-app') => {
|
|
|
73
73
|
/**
|
|
74
74
|
* Creates a function to set Redis client name for node-redis v4.
|
|
75
75
|
*
|
|
76
|
-
* @param {string} [
|
|
76
|
+
* @param {string} [appName='undefined-app']
|
|
77
77
|
* @returns {(client: any, name: string) => void}
|
|
78
78
|
*/
|
|
79
|
-
const createSetClientNameForRedisV4 = (
|
|
79
|
+
const createSetClientNameForRedisV4 = (appName = 'undefined-app') => {
|
|
80
80
|
return (client, name) => {
|
|
81
81
|
if (process.env.NODE_ENV !== 'test') {
|
|
82
82
|
client.on('ready', async () => {
|
|
@@ -84,7 +84,7 @@ const createSetClientNameForRedisV4 = (defaultAppName = 'undefined-app') => {
|
|
|
84
84
|
await client.sendCommand([
|
|
85
85
|
'CLIENT',
|
|
86
86
|
'SETNAME',
|
|
87
|
-
getRedisName(name, defaultAppName),
|
|
87
|
+
getRedisName({ name, appName: defaultAppName || appName }),
|
|
88
88
|
])
|
|
89
89
|
console.log(`Connected to Redis for pid:${process.pid} (${name})`)
|
|
90
90
|
} catch (err) {
|