@forklaunch/core 0.5.3 → 0.5.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.
@@ -1,4 +1,7 @@
1
1
  import { RedisClientOptions } from 'redis';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition } from '../openTelemetryCollector-CWrfzmmW.mjs';
3
+ import '@opentelemetry/api';
4
+ import 'pino';
2
5
 
3
6
  /**
4
7
  * Type representing a TTL (Time-To-Live) cache record.
@@ -67,6 +70,7 @@ interface TtlCache {
67
70
  */
68
71
  declare class RedisTtlCache implements TtlCache {
69
72
  private ttlMilliseconds;
73
+ private openTelemetryCollector;
70
74
  private client;
71
75
  /**
72
76
  * Creates an instance of RedisTtlCache.
@@ -74,7 +78,7 @@ declare class RedisTtlCache implements TtlCache {
74
78
  * @param {number} ttlMilliseconds - The default TTL in milliseconds.
75
79
  * @param {RedisClientOptions} [hostingOptions] - The Redis client options.
76
80
  */
77
- constructor(ttlMilliseconds: number, hostingOptions?: RedisClientOptions);
81
+ constructor(ttlMilliseconds: number, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, hostingOptions?: RedisClientOptions);
78
82
  /**
79
83
  * Puts a record into the Redis cache.
80
84
  *
@@ -1,4 +1,7 @@
1
1
  import { RedisClientOptions } from 'redis';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition } from '../openTelemetryCollector-CWrfzmmW.js';
3
+ import '@opentelemetry/api';
4
+ import 'pino';
2
5
 
3
6
  /**
4
7
  * Type representing a TTL (Time-To-Live) cache record.
@@ -67,6 +70,7 @@ interface TtlCache {
67
70
  */
68
71
  declare class RedisTtlCache implements TtlCache {
69
72
  private ttlMilliseconds;
73
+ private openTelemetryCollector;
70
74
  private client;
71
75
  /**
72
76
  * Creates an instance of RedisTtlCache.
@@ -74,7 +78,7 @@ declare class RedisTtlCache implements TtlCache {
74
78
  * @param {number} ttlMilliseconds - The default TTL in milliseconds.
75
79
  * @param {RedisClientOptions} [hostingOptions] - The Redis client options.
76
80
  */
77
- constructor(ttlMilliseconds: number, hostingOptions?: RedisClientOptions);
81
+ constructor(ttlMilliseconds: number, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>, hostingOptions?: RedisClientOptions);
78
82
  /**
79
83
  * Puts a record into the Redis cache.
80
84
  *
@@ -34,11 +34,12 @@ var RedisTtlCache = class {
34
34
  * @param {number} ttlMilliseconds - The default TTL in milliseconds.
35
35
  * @param {RedisClientOptions} [hostingOptions] - The Redis client options.
36
36
  */
37
- constructor(ttlMilliseconds, hostingOptions) {
37
+ constructor(ttlMilliseconds, openTelemetryCollector, hostingOptions) {
38
38
  this.ttlMilliseconds = ttlMilliseconds;
39
+ this.openTelemetryCollector = openTelemetryCollector;
39
40
  this.client = (0, import_redis.createClient)(hostingOptions);
40
- this.client.on("error", (err) => console.error("Redis Client Error", err));
41
- this.client.connect().catch(console.error);
41
+ this.client.on("error", (err) => openTelemetryCollector.error(err));
42
+ this.client.connect().catch(openTelemetryCollector.error);
42
43
  }
43
44
  client;
44
45
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cache/index.ts","../../src/cache/redisTtlCache.ts","../../src/cache/utils/cacheKey.ts"],"sourcesContent":["export * from './interfaces/ttlCache.interface';\nexport * from './redisTtlCache';\nexport * from './types/ttlCacheRecord.types';\nexport * from './utils/cacheKey';\n","import { RedisClientOptions, createClient } from 'redis';\nimport { TtlCache } from './interfaces/ttlCache.interface';\nimport { TtlCacheRecord } from './types/ttlCacheRecord.types';\n\n/**\n * Class representing a Redis-based TTL (Time-To-Live) cache.\n * Implements the TtlCache interface.\n */\nexport class RedisTtlCache implements TtlCache {\n private client;\n\n /**\n * Creates an instance of RedisTtlCache.\n *\n * @param {number} ttlMilliseconds - The default TTL in milliseconds.\n * @param {RedisClientOptions} [hostingOptions] - The Redis client options.\n */\n constructor(\n private ttlMilliseconds: number,\n hostingOptions?: RedisClientOptions\n ) {\n // Connects to localhost:6379 by default\n // url usage: redis[s]://[[username][:password]@][host][:port][/db-number]\n this.client = createClient(hostingOptions);\n this.client.on('error', (err) => console.error('Redis Client Error', err));\n this.client.connect().catch(console.error);\n }\n\n /**\n * Puts a record into the Redis cache.\n *\n * @param {TtlCacheRecord} param0 - The cache record to put into the cache.\n * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.\n */\n async putRecord<T>({\n key,\n value,\n ttlMilliseconds = this.ttlMilliseconds\n }: TtlCacheRecord<T>): Promise<void> {\n await this.client.set(key, JSON.stringify(value), {\n PX: ttlMilliseconds\n });\n }\n\n /**\n * Deletes a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to delete.\n * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.\n */\n async deleteRecord(cacheRecordKey: string): Promise<void> {\n await this.client.del(cacheRecordKey);\n }\n\n /**\n * Reads a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to read.\n * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.\n * @throws {Error} - Throws an error if the record is not found.\n */\n async readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>> {\n const value = await this.client.get(cacheRecordKey);\n if (value === null) {\n throw new Error(`Record not found for key: ${cacheRecordKey}`);\n }\n const ttl = await this.client.ttl(cacheRecordKey); // Fetch TTL from Redis\n return {\n key: cacheRecordKey,\n value: JSON.parse(value),\n ttlMilliseconds: ttl * 1000\n };\n }\n\n /**\n * Lists the keys in the Redis cache that match a pattern prefix.\n *\n * @param {string} pattern_prefix - The pattern prefix to match.\n * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.\n */\n async listKeys(pattern_prefix: string): Promise<string[]> {\n const keys = await this.client.keys(pattern_prefix + '*');\n return keys;\n }\n\n /**\n * Peeks at a record in the Redis cache to check if it exists.\n *\n * @param {string} cacheRecordKey - The key of the cache record to peek at.\n * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.\n */\n async peekRecord(cacheRecordKey: string): Promise<boolean> {\n const result = await this.client.exists(cacheRecordKey);\n return result === 1;\n }\n\n /**\n * Disconnects the Redis client.\n *\n * @returns {Promise<void>} - A promise that resolves when the client is disconnected.\n */\n async disconnect(): Promise<void> {\n await this.client.quit();\n }\n\n /**\n * Gets the default TTL (Time-To-Live) in milliseconds.\n *\n * @returns {number} - The TTL in milliseconds.\n */\n getTtlMilliseconds(): number {\n return this.ttlMilliseconds;\n }\n}\n","export const createCacheKey = (cacheKeyPrefix: string) => (id: string) => {\n return `${cacheKeyPrefix}:${id}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAiD;AAQ1C,IAAM,gBAAN,MAAwC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YACU,iBACR,gBACA;AAFQ;AAKR,SAAK,aAAS,2BAAa,cAAc;AACzC,SAAK,OAAO,GAAG,SAAS,CAAC,QAAQ,QAAQ,MAAM,sBAAsB,GAAG,CAAC;AACzE,SAAK,OAAO,QAAQ,EAAE,MAAM,QAAQ,KAAK;AAAA,EAC3C;AAAA,EAjBQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBR,MAAM,UAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA,kBAAkB,KAAK;AAAA,EACzB,GAAqC;AACnC,UAAM,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,GAAG;AAAA,MAChD,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aAAa,gBAAuC;AACxD,UAAM,KAAK,OAAO,IAAI,cAAc;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAc,gBAAoD;AACtE,UAAM,QAAQ,MAAM,KAAK,OAAO,IAAI,cAAc;AAClD,QAAI,UAAU,MAAM;AAClB,YAAM,IAAI,MAAM,6BAA6B,cAAc,EAAE;AAAA,IAC/D;AACA,UAAM,MAAM,MAAM,KAAK,OAAO,IAAI,cAAc;AAChD,WAAO;AAAA,MACL,KAAK;AAAA,MACL,OAAO,KAAK,MAAM,KAAK;AAAA,MACvB,iBAAiB,MAAM;AAAA,IACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,gBAA2C;AACxD,UAAM,OAAO,MAAM,KAAK,OAAO,KAAK,iBAAiB,GAAG;AACxD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,gBAA0C;AACzD,UAAM,SAAS,MAAM,KAAK,OAAO,OAAO,cAAc;AACtD,WAAO,WAAW;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAA4B;AAChC,UAAM,KAAK,OAAO,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;;;ACjHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
1
+ {"version":3,"sources":["../../src/cache/index.ts","../../src/cache/redisTtlCache.ts","../../src/cache/utils/cacheKey.ts"],"sourcesContent":["export * from './interfaces/ttlCache.interface';\nexport * from './redisTtlCache';\nexport * from './types/ttlCacheRecord.types';\nexport * from './utils/cacheKey';\n","import { RedisClientOptions, createClient } from 'redis';\nimport { TtlCache } from './interfaces/ttlCache.interface';\nimport { TtlCacheRecord } from './types/ttlCacheRecord.types';\nimport { OpenTelemetryCollector } from '../http/telemetry/openTelemetryCollector';\nimport { MetricsDefinition } from '../http';\n\n/**\n * Class representing a Redis-based TTL (Time-To-Live) cache.\n * Implements the TtlCache interface.\n */\nexport class RedisTtlCache implements TtlCache {\n private client;\n\n /**\n * Creates an instance of RedisTtlCache.\n *\n * @param {number} ttlMilliseconds - The default TTL in milliseconds.\n * @param {RedisClientOptions} [hostingOptions] - The Redis client options.\n */\n constructor(\n private ttlMilliseconds: number,\n private openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,\n hostingOptions?: RedisClientOptions\n ) {\n // Connects to localhost:6379 by default\n // url usage: redis[s]://[[username][:password]@][host][:port][/db-number]\n this.client = createClient(hostingOptions);\n this.client.on('error', (err) => openTelemetryCollector.error(err));\n this.client.connect().catch(openTelemetryCollector.error);\n }\n\n /**\n * Puts a record into the Redis cache.\n *\n * @param {TtlCacheRecord} param0 - The cache record to put into the cache.\n * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.\n */\n async putRecord<T>({\n key,\n value,\n ttlMilliseconds = this.ttlMilliseconds\n }: TtlCacheRecord<T>): Promise<void> {\n await this.client.set(key, JSON.stringify(value), {\n PX: ttlMilliseconds\n });\n }\n\n /**\n * Deletes a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to delete.\n * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.\n */\n async deleteRecord(cacheRecordKey: string): Promise<void> {\n await this.client.del(cacheRecordKey);\n }\n\n /**\n * Reads a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to read.\n * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.\n * @throws {Error} - Throws an error if the record is not found.\n */\n async readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>> {\n const value = await this.client.get(cacheRecordKey);\n if (value === null) {\n throw new Error(`Record not found for key: ${cacheRecordKey}`);\n }\n const ttl = await this.client.ttl(cacheRecordKey); // Fetch TTL from Redis\n return {\n key: cacheRecordKey,\n value: JSON.parse(value),\n ttlMilliseconds: ttl * 1000\n };\n }\n\n /**\n * Lists the keys in the Redis cache that match a pattern prefix.\n *\n * @param {string} pattern_prefix - The pattern prefix to match.\n * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.\n */\n async listKeys(pattern_prefix: string): Promise<string[]> {\n const keys = await this.client.keys(pattern_prefix + '*');\n return keys;\n }\n\n /**\n * Peeks at a record in the Redis cache to check if it exists.\n *\n * @param {string} cacheRecordKey - The key of the cache record to peek at.\n * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.\n */\n async peekRecord(cacheRecordKey: string): Promise<boolean> {\n const result = await this.client.exists(cacheRecordKey);\n return result === 1;\n }\n\n /**\n * Disconnects the Redis client.\n *\n * @returns {Promise<void>} - A promise that resolves when the client is disconnected.\n */\n async disconnect(): Promise<void> {\n await this.client.quit();\n }\n\n /**\n * Gets the default TTL (Time-To-Live) in milliseconds.\n *\n * @returns {number} - The TTL in milliseconds.\n */\n getTtlMilliseconds(): number {\n return this.ttlMilliseconds;\n }\n}\n","export const createCacheKey = (cacheKeyPrefix: string) => (id: string) => {\n return `${cacheKeyPrefix}:${id}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAiD;AAU1C,IAAM,gBAAN,MAAwC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YACU,iBACA,wBACR,gBACA;AAHQ;AACA;AAKR,SAAK,aAAS,2BAAa,cAAc;AACzC,SAAK,OAAO,GAAG,SAAS,CAAC,QAAQ,uBAAuB,MAAM,GAAG,CAAC;AAClE,SAAK,OAAO,QAAQ,EAAE,MAAM,uBAAuB,KAAK;AAAA,EAC1D;AAAA,EAlBQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BR,MAAM,UAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA,kBAAkB,KAAK;AAAA,EACzB,GAAqC;AACnC,UAAM,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,GAAG;AAAA,MAChD,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aAAa,gBAAuC;AACxD,UAAM,KAAK,OAAO,IAAI,cAAc;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAc,gBAAoD;AACtE,UAAM,QAAQ,MAAM,KAAK,OAAO,IAAI,cAAc;AAClD,QAAI,UAAU,MAAM;AAClB,YAAM,IAAI,MAAM,6BAA6B,cAAc,EAAE;AAAA,IAC/D;AACA,UAAM,MAAM,MAAM,KAAK,OAAO,IAAI,cAAc;AAChD,WAAO;AAAA,MACL,KAAK;AAAA,MACL,OAAO,KAAK,MAAM,KAAK;AAAA,MACvB,iBAAiB,MAAM;AAAA,IACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,gBAA2C;AACxD,UAAM,OAAO,MAAM,KAAK,OAAO,KAAK,iBAAiB,GAAG;AACxD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,gBAA0C;AACzD,UAAM,SAAS,MAAM,KAAK,OAAO,OAAO,cAAc;AACtD,WAAO,WAAW;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAA4B;AAChC,UAAM,KAAK,OAAO,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;;;ACpHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
@@ -7,11 +7,12 @@ var RedisTtlCache = class {
7
7
  * @param {number} ttlMilliseconds - The default TTL in milliseconds.
8
8
  * @param {RedisClientOptions} [hostingOptions] - The Redis client options.
9
9
  */
10
- constructor(ttlMilliseconds, hostingOptions) {
10
+ constructor(ttlMilliseconds, openTelemetryCollector, hostingOptions) {
11
11
  this.ttlMilliseconds = ttlMilliseconds;
12
+ this.openTelemetryCollector = openTelemetryCollector;
12
13
  this.client = createClient(hostingOptions);
13
- this.client.on("error", (err) => console.error("Redis Client Error", err));
14
- this.client.connect().catch(console.error);
14
+ this.client.on("error", (err) => openTelemetryCollector.error(err));
15
+ this.client.connect().catch(openTelemetryCollector.error);
15
16
  }
16
17
  client;
17
18
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/cache/redisTtlCache.ts","../../src/cache/utils/cacheKey.ts"],"sourcesContent":["import { RedisClientOptions, createClient } from 'redis';\nimport { TtlCache } from './interfaces/ttlCache.interface';\nimport { TtlCacheRecord } from './types/ttlCacheRecord.types';\n\n/**\n * Class representing a Redis-based TTL (Time-To-Live) cache.\n * Implements the TtlCache interface.\n */\nexport class RedisTtlCache implements TtlCache {\n private client;\n\n /**\n * Creates an instance of RedisTtlCache.\n *\n * @param {number} ttlMilliseconds - The default TTL in milliseconds.\n * @param {RedisClientOptions} [hostingOptions] - The Redis client options.\n */\n constructor(\n private ttlMilliseconds: number,\n hostingOptions?: RedisClientOptions\n ) {\n // Connects to localhost:6379 by default\n // url usage: redis[s]://[[username][:password]@][host][:port][/db-number]\n this.client = createClient(hostingOptions);\n this.client.on('error', (err) => console.error('Redis Client Error', err));\n this.client.connect().catch(console.error);\n }\n\n /**\n * Puts a record into the Redis cache.\n *\n * @param {TtlCacheRecord} param0 - The cache record to put into the cache.\n * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.\n */\n async putRecord<T>({\n key,\n value,\n ttlMilliseconds = this.ttlMilliseconds\n }: TtlCacheRecord<T>): Promise<void> {\n await this.client.set(key, JSON.stringify(value), {\n PX: ttlMilliseconds\n });\n }\n\n /**\n * Deletes a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to delete.\n * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.\n */\n async deleteRecord(cacheRecordKey: string): Promise<void> {\n await this.client.del(cacheRecordKey);\n }\n\n /**\n * Reads a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to read.\n * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.\n * @throws {Error} - Throws an error if the record is not found.\n */\n async readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>> {\n const value = await this.client.get(cacheRecordKey);\n if (value === null) {\n throw new Error(`Record not found for key: ${cacheRecordKey}`);\n }\n const ttl = await this.client.ttl(cacheRecordKey); // Fetch TTL from Redis\n return {\n key: cacheRecordKey,\n value: JSON.parse(value),\n ttlMilliseconds: ttl * 1000\n };\n }\n\n /**\n * Lists the keys in the Redis cache that match a pattern prefix.\n *\n * @param {string} pattern_prefix - The pattern prefix to match.\n * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.\n */\n async listKeys(pattern_prefix: string): Promise<string[]> {\n const keys = await this.client.keys(pattern_prefix + '*');\n return keys;\n }\n\n /**\n * Peeks at a record in the Redis cache to check if it exists.\n *\n * @param {string} cacheRecordKey - The key of the cache record to peek at.\n * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.\n */\n async peekRecord(cacheRecordKey: string): Promise<boolean> {\n const result = await this.client.exists(cacheRecordKey);\n return result === 1;\n }\n\n /**\n * Disconnects the Redis client.\n *\n * @returns {Promise<void>} - A promise that resolves when the client is disconnected.\n */\n async disconnect(): Promise<void> {\n await this.client.quit();\n }\n\n /**\n * Gets the default TTL (Time-To-Live) in milliseconds.\n *\n * @returns {number} - The TTL in milliseconds.\n */\n getTtlMilliseconds(): number {\n return this.ttlMilliseconds;\n }\n}\n","export const createCacheKey = (cacheKeyPrefix: string) => (id: string) => {\n return `${cacheKeyPrefix}:${id}`;\n};\n"],"mappings":";AAAA,SAA6B,oBAAoB;AAQ1C,IAAM,gBAAN,MAAwC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YACU,iBACR,gBACA;AAFQ;AAKR,SAAK,SAAS,aAAa,cAAc;AACzC,SAAK,OAAO,GAAG,SAAS,CAAC,QAAQ,QAAQ,MAAM,sBAAsB,GAAG,CAAC;AACzE,SAAK,OAAO,QAAQ,EAAE,MAAM,QAAQ,KAAK;AAAA,EAC3C;AAAA,EAjBQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyBR,MAAM,UAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA,kBAAkB,KAAK;AAAA,EACzB,GAAqC;AACnC,UAAM,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,GAAG;AAAA,MAChD,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aAAa,gBAAuC;AACxD,UAAM,KAAK,OAAO,IAAI,cAAc;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAc,gBAAoD;AACtE,UAAM,QAAQ,MAAM,KAAK,OAAO,IAAI,cAAc;AAClD,QAAI,UAAU,MAAM;AAClB,YAAM,IAAI,MAAM,6BAA6B,cAAc,EAAE;AAAA,IAC/D;AACA,UAAM,MAAM,MAAM,KAAK,OAAO,IAAI,cAAc;AAChD,WAAO;AAAA,MACL,KAAK;AAAA,MACL,OAAO,KAAK,MAAM,KAAK;AAAA,MACvB,iBAAiB,MAAM;AAAA,IACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,gBAA2C;AACxD,UAAM,OAAO,MAAM,KAAK,OAAO,KAAK,iBAAiB,GAAG;AACxD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,gBAA0C;AACzD,UAAM,SAAS,MAAM,KAAK,OAAO,OAAO,cAAc;AACtD,WAAO,WAAW;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAA4B;AAChC,UAAM,KAAK,OAAO,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;;;ACjHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
1
+ {"version":3,"sources":["../../src/cache/redisTtlCache.ts","../../src/cache/utils/cacheKey.ts"],"sourcesContent":["import { RedisClientOptions, createClient } from 'redis';\nimport { TtlCache } from './interfaces/ttlCache.interface';\nimport { TtlCacheRecord } from './types/ttlCacheRecord.types';\nimport { OpenTelemetryCollector } from '../http/telemetry/openTelemetryCollector';\nimport { MetricsDefinition } from '../http';\n\n/**\n * Class representing a Redis-based TTL (Time-To-Live) cache.\n * Implements the TtlCache interface.\n */\nexport class RedisTtlCache implements TtlCache {\n private client;\n\n /**\n * Creates an instance of RedisTtlCache.\n *\n * @param {number} ttlMilliseconds - The default TTL in milliseconds.\n * @param {RedisClientOptions} [hostingOptions] - The Redis client options.\n */\n constructor(\n private ttlMilliseconds: number,\n private openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,\n hostingOptions?: RedisClientOptions\n ) {\n // Connects to localhost:6379 by default\n // url usage: redis[s]://[[username][:password]@][host][:port][/db-number]\n this.client = createClient(hostingOptions);\n this.client.on('error', (err) => openTelemetryCollector.error(err));\n this.client.connect().catch(openTelemetryCollector.error);\n }\n\n /**\n * Puts a record into the Redis cache.\n *\n * @param {TtlCacheRecord} param0 - The cache record to put into the cache.\n * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.\n */\n async putRecord<T>({\n key,\n value,\n ttlMilliseconds = this.ttlMilliseconds\n }: TtlCacheRecord<T>): Promise<void> {\n await this.client.set(key, JSON.stringify(value), {\n PX: ttlMilliseconds\n });\n }\n\n /**\n * Deletes a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to delete.\n * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.\n */\n async deleteRecord(cacheRecordKey: string): Promise<void> {\n await this.client.del(cacheRecordKey);\n }\n\n /**\n * Reads a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to read.\n * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.\n * @throws {Error} - Throws an error if the record is not found.\n */\n async readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>> {\n const value = await this.client.get(cacheRecordKey);\n if (value === null) {\n throw new Error(`Record not found for key: ${cacheRecordKey}`);\n }\n const ttl = await this.client.ttl(cacheRecordKey); // Fetch TTL from Redis\n return {\n key: cacheRecordKey,\n value: JSON.parse(value),\n ttlMilliseconds: ttl * 1000\n };\n }\n\n /**\n * Lists the keys in the Redis cache that match a pattern prefix.\n *\n * @param {string} pattern_prefix - The pattern prefix to match.\n * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.\n */\n async listKeys(pattern_prefix: string): Promise<string[]> {\n const keys = await this.client.keys(pattern_prefix + '*');\n return keys;\n }\n\n /**\n * Peeks at a record in the Redis cache to check if it exists.\n *\n * @param {string} cacheRecordKey - The key of the cache record to peek at.\n * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.\n */\n async peekRecord(cacheRecordKey: string): Promise<boolean> {\n const result = await this.client.exists(cacheRecordKey);\n return result === 1;\n }\n\n /**\n * Disconnects the Redis client.\n *\n * @returns {Promise<void>} - A promise that resolves when the client is disconnected.\n */\n async disconnect(): Promise<void> {\n await this.client.quit();\n }\n\n /**\n * Gets the default TTL (Time-To-Live) in milliseconds.\n *\n * @returns {number} - The TTL in milliseconds.\n */\n getTtlMilliseconds(): number {\n return this.ttlMilliseconds;\n }\n}\n","export const createCacheKey = (cacheKeyPrefix: string) => (id: string) => {\n return `${cacheKeyPrefix}:${id}`;\n};\n"],"mappings":";AAAA,SAA6B,oBAAoB;AAU1C,IAAM,gBAAN,MAAwC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YACU,iBACA,wBACR,gBACA;AAHQ;AACA;AAKR,SAAK,SAAS,aAAa,cAAc;AACzC,SAAK,OAAO,GAAG,SAAS,CAAC,QAAQ,uBAAuB,MAAM,GAAG,CAAC;AAClE,SAAK,OAAO,QAAQ,EAAE,MAAM,uBAAuB,KAAK;AAAA,EAC1D;AAAA,EAlBQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BR,MAAM,UAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA,kBAAkB,KAAK;AAAA,EACzB,GAAqC;AACnC,UAAM,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,GAAG;AAAA,MAChD,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aAAa,gBAAuC;AACxD,UAAM,KAAK,OAAO,IAAI,cAAc;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAc,gBAAoD;AACtE,UAAM,QAAQ,MAAM,KAAK,OAAO,IAAI,cAAc;AAClD,QAAI,UAAU,MAAM;AAClB,YAAM,IAAI,MAAM,6BAA6B,cAAc,EAAE;AAAA,IAC/D;AACA,UAAM,MAAM,MAAM,KAAK,OAAO,IAAI,cAAc;AAChD,WAAO;AAAA,MACL,KAAK;AAAA,MACL,OAAO,KAAK,MAAM,KAAK;AAAA,MACvB,iBAAiB,MAAM;AAAA,IACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,gBAA2C;AACxD,UAAM,OAAO,MAAM,KAAK,OAAO,KAAK,iBAAiB,GAAG;AACxD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,gBAA0C;AACzD,UAAM,SAAS,MAAM,KAAK,OAAO,OAAO,cAAc;AACtD,WAAO,WAAW;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAA4B;AAChC,UAAM,KAAK,OAAO,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;;;ACpHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
@@ -1,10 +1,14 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../openTelemetryCollector-CWrfzmmW.mjs';
3
+ export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../openTelemetryCollector-CWrfzmmW.mjs';
2
4
  import { Prettify, RemoveTrailingSlash, MakePropertyOptionalIfChildrenOptional } from '@forklaunch/common';
3
- import { Span, Counter, Gauge, Histogram, UpDownCounter, ObservableCounter, ObservableGauge, ObservableUpDownCounter } from '@opentelemetry/api';
5
+ import { Span } from '@opentelemetry/api';
4
6
  import { ParsedQs } from 'qs';
7
+ import { Readable } from 'stream';
5
8
  import { OpenAPIObject } from 'openapi3-ts/oas31';
6
9
  import { AnyValueMap } from '@opentelemetry/api-logs';
7
10
  import { LevelWithSilentOrString, LevelWithSilent, Logger } from 'pino';
11
+ import { ApiReferenceConfiguration } from '@scalar/express-api-reference';
8
12
  export { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
9
13
 
10
14
  interface PathBasedHandler<RouterHandler> {
@@ -292,6 +296,8 @@ interface ForklaunchRequest<SV extends AnySchemaValidator, P extends ParamsDicti
292
296
  requestSchema: unknown;
293
297
  /** Original path */
294
298
  originalPath: string;
299
+ /** OpenTelemetry Collector */
300
+ openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
295
301
  }
296
302
  /**
297
303
  * Represents the types of data that can be sent in a response.
@@ -355,6 +361,18 @@ interface ForklaunchResponse<ResBodyMap extends Record<number, unknown>, ResHead
355
361
  * @param {string} value - The header value.
356
362
  */
357
363
  setHeader: <K extends keyof (ResHeaders & ForklaunchResHeaders)>(key: K, value: K extends keyof ForklaunchResHeaders ? ForklaunchResHeaders[K] : ResHeaders[K]) => void;
364
+ /**
365
+ * Adds an event listener to the response.
366
+ * @param {string} event - The event to listen for.
367
+ * @param {Function} listener - The listener function.
368
+ */
369
+ on(event: 'close', listener: () => void): this;
370
+ on(event: 'drain', listener: () => void): this;
371
+ on(event: 'error', listener: (err: Error) => void): this;
372
+ on(event: 'finish', listener: () => void): this;
373
+ on(event: 'pipe', listener: (src: Readable) => void): this;
374
+ on(event: 'unpipe', listener: (src: Readable) => void): this;
375
+ on(event: string | symbol, listener: (...args: unknown[]) => void): this;
358
376
  /**
359
377
  * Sets the status of the response.
360
378
  * @param {U} code - The status code.
@@ -370,6 +388,11 @@ interface ForklaunchResponse<ResBodyMap extends Record<number, unknown>, ResHead
370
388
  * @param {string} [data] - Optional data to send.
371
389
  */
372
390
  end: (data?: string) => void;
391
+ /**
392
+ * Sets the content type of the response.
393
+ * @param {string} type - The content type.
394
+ */
395
+ type: (type: string) => void;
373
396
  /** Local variables */
374
397
  locals: LocalsObj;
375
398
  /** Cors */
@@ -618,11 +641,12 @@ declare class ForklaunchExpressLikeRouter<SV extends AnySchemaValidator, BasePat
618
641
  #private;
619
642
  readonly schemaValidator: SV;
620
643
  readonly internal: Internal;
644
+ readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
621
645
  requestHandler: RouterHandler;
622
646
  routers: ForklaunchRouter<SV>[];
623
647
  readonly routes: ForklaunchRoute<SV>[];
624
648
  readonly basePath: BasePath;
625
- constructor(basePath: BasePath, schemaValidator: SV, internal: Internal);
649
+ constructor(basePath: BasePath, schemaValidator: SV, internal: Internal, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
626
650
  registerRoute<ContractMethod extends Method, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(method: ContractMethod, path: Path, registrationMethod: PathBasedHandler<RouterHandler>, contractDetailsOrMiddlewareOrTypedHandler: ContractDetailsOrMiddlewareOrTypedHandler<SV, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>, ...middlewareOrMiddlewareAndTypedHandler: MiddlewareOrMiddlewareWithTypedHandler<SV, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>[]): LiveTypeFunction<SV, `${BasePath}${Path}`, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders>;
627
651
  registerMiddlewareHandler<Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(registrationMethod: PathOrMiddlewareBasedHandler<RouterHandler>, pathOrContractDetailsOrMiddlewareOrTypedHandler: Path | ContractDetailsOrMiddlewareOrTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>, contractDetailsOrMiddlewareOrTypedHandler?: ContractDetailsOrMiddlewareOrTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>, ...middlewareOrMiddlewareWithTypedHandler: MiddlewareOrMiddlewareWithTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>[]): this;
628
652
  registerNestableMiddlewareHandler<Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(registrationMethod: NestableRouterBasedHandler<RouterHandler, Internal>, pathOrContractDetailsOrMiddlewareOrTypedHandler: Path | ContractDetailsOrMiddlewareOrTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction> | ConstrainedForklaunchRouter<SV, RouterHandler>, contractDetailsOrMiddlewareOrTypedHandler?: ContractDetailsOrMiddlewareOrTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction> | ConstrainedForklaunchRouter<SV, RouterHandler>, ...middlewareOrMiddlewareWithTypedHandler: (MiddlewareOrMiddlewareWithTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction> | ConstrainedForklaunchRouter<SV, RouterHandler>)[]): this;
@@ -752,12 +776,13 @@ declare class ForklaunchExpressLikeRouter<SV extends AnySchemaValidator, BasePat
752
776
  declare abstract class ForklaunchExpressLikeApplication<SV extends AnySchemaValidator, Server extends ExpressLikeRouter<RouterHandler, Server>, RouterHandler, BaseRequest, BaseResponse, NextFunction> extends ForklaunchExpressLikeRouter<SV, '/', RouterHandler, Server, BaseRequest, BaseResponse, NextFunction> {
753
777
  readonly schemaValidator: SV;
754
778
  readonly internal: Server;
779
+ readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
755
780
  /**
756
781
  * Creates an instance of the Application class.
757
782
  *
758
783
  * @param {SV} schemaValidator - The schema validator.
759
784
  */
760
- constructor(schemaValidator: SV, internal: Server);
785
+ constructor(schemaValidator: SV, internal: Server, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
761
786
  abstract listen(...args: unknown[]): void;
762
787
  }
763
788
 
@@ -914,43 +939,20 @@ declare function generateSwaggerDocument<SV extends AnySchemaValidator>(schemaVa
914
939
  declare const ATTR_API_NAME = "api.name";
915
940
  declare const ATTR_CORRELATION_ID = "correlation.id";
916
941
 
917
- type MetricType<T extends string> = T extends 'counter' ? Counter : T extends 'gauge' ? Gauge : T extends 'histogram' ? Histogram : T extends 'upDownCounter' ? UpDownCounter : T extends 'observableCounter' ? ObservableCounter : T extends 'observableGauge' ? ObservableGauge : T extends 'observableUpDownCounter' ? ObservableUpDownCounter : undefined;
918
- type MetricsDefinition = Record<string, 'counter' | 'gauge' | 'histogram' | 'upDownCounter' | 'observableCounter' | 'observableGauge' | 'observableUpDownCounter'>;
919
-
920
942
  declare function metricsDefinitions<T extends MetricsDefinition>(metrics: T): T;
921
943
 
922
- declare class OpenTelemetryCollector<AppliedMetricsDefinition extends MetricsDefinition> {
923
- private readonly serviceName;
924
- private readonly logger;
925
- private readonly metrics;
926
- constructor(serviceName: string, level?: LevelWithSilentOrString, metricDefinitions?: AppliedMetricsDefinition);
927
- log(level: LevelWithSilent, msg: string, meta?: AnyValueMap): void;
928
- info(msg: string, meta?: AnyValueMap): void;
929
- error(msg: string, meta?: AnyValueMap): void;
930
- warn(msg: string, meta?: AnyValueMap): void;
931
- debug(msg: string, meta?: AnyValueMap): void;
932
- trace(msg: string, meta?: AnyValueMap): void;
933
- getMetric<T extends keyof AppliedMetricsDefinition>(metricId: T): MetricType<AppliedMetricsDefinition[T]>;
934
- }
935
- declare const httpRequestsTotalCounter: Counter<{
936
- "service.name": string;
937
- "api.name": string;
938
- "correlation.id": string;
939
- "http.request.method": string;
940
- "http.route": string;
941
- "http.response.status_code": number;
942
- }>;
943
-
944
+ declare function meta(meta: Record<string, unknown>): LoggerMeta;
944
945
  declare class PinoLogger {
945
946
  private pinoLogger;
946
947
  private meta;
948
+ private prettyPrinter;
947
949
  constructor(level: LevelWithSilentOrString, meta?: AnyValueMap);
948
- log(level: LevelWithSilent, msg: string, meta?: AnyValueMap): void;
949
- error(msg: string, meta?: AnyValueMap): void;
950
- info(msg: string, meta?: AnyValueMap): void;
951
- debug(msg: string, meta?: AnyValueMap): void;
952
- warn(msg: string, meta?: AnyValueMap): void;
953
- trace(msg: string, meta?: AnyValueMap): void;
950
+ log(level: LevelWithSilent, ...args: (string | unknown | LoggerMeta)[]): void;
951
+ error: LogFn;
952
+ info: LogFn;
953
+ debug: LogFn;
954
+ warn: LogFn;
955
+ trace: LogFn;
954
956
  child(meta?: AnyValueMap): PinoLogger;
955
957
  getBaseLogger(): Logger;
956
958
  }
@@ -958,4 +960,10 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
958
960
 
959
961
  declare function recordMetric<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ResBodyMap extends Record<string, unknown>, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>>(req: ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, res: ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>): void;
960
962
 
961
- export { ATTR_API_NAME, ATTR_CORRELATION_ID, type ApiClient, type AuthMethods, type AuthMethodsBase, type Body, type BodyObject, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type ErrorContainer, type ExpressLikeAuthMapper, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractedParamsObject, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HttpContractDetails, type HttpMethod, type LiveTypeFunction, type LiveTypeRouteDefinition, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type Method, type MetricType, type MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, type NumberOnlyObject, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RequestContext, type ResolvedForklaunchRequest, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type SchemaAuthMethods, type StatusCode, type StringOnlyObject, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, delete_, enrichExpressLikeSend, generateSwaggerDocument, get, getCodeForStatus, head, httpRequestsTotalCounter, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedHandler };
963
+ type DocsConfiguration = ({
964
+ type: 'scalar';
965
+ } & Partial<Omit<ApiReferenceConfiguration, 'spec'>>) | {
966
+ type: 'swagger';
967
+ };
968
+
969
+ export { ATTR_API_NAME, ATTR_CORRELATION_ID, type ApiClient, type AuthMethods, type AuthMethodsBase, type Body, type BodyObject, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type DocsConfiguration, type ErrorContainer, type ExpressLikeAuthMapper, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractedParamsObject, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HttpContractDetails, type HttpMethod, type LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type Method, MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, type NumberOnlyObject, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RequestContext, type ResolvedForklaunchRequest, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type SchemaAuthMethods, type StatusCode, type StringOnlyObject, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, delete_, enrichExpressLikeSend, generateSwaggerDocument, get, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedHandler };
@@ -1,10 +1,14 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../openTelemetryCollector-CWrfzmmW.js';
3
+ export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../openTelemetryCollector-CWrfzmmW.js';
2
4
  import { Prettify, RemoveTrailingSlash, MakePropertyOptionalIfChildrenOptional } from '@forklaunch/common';
3
- import { Span, Counter, Gauge, Histogram, UpDownCounter, ObservableCounter, ObservableGauge, ObservableUpDownCounter } from '@opentelemetry/api';
5
+ import { Span } from '@opentelemetry/api';
4
6
  import { ParsedQs } from 'qs';
7
+ import { Readable } from 'stream';
5
8
  import { OpenAPIObject } from 'openapi3-ts/oas31';
6
9
  import { AnyValueMap } from '@opentelemetry/api-logs';
7
10
  import { LevelWithSilentOrString, LevelWithSilent, Logger } from 'pino';
11
+ import { ApiReferenceConfiguration } from '@scalar/express-api-reference';
8
12
  export { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
9
13
 
10
14
  interface PathBasedHandler<RouterHandler> {
@@ -292,6 +296,8 @@ interface ForklaunchRequest<SV extends AnySchemaValidator, P extends ParamsDicti
292
296
  requestSchema: unknown;
293
297
  /** Original path */
294
298
  originalPath: string;
299
+ /** OpenTelemetry Collector */
300
+ openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
295
301
  }
296
302
  /**
297
303
  * Represents the types of data that can be sent in a response.
@@ -355,6 +361,18 @@ interface ForklaunchResponse<ResBodyMap extends Record<number, unknown>, ResHead
355
361
  * @param {string} value - The header value.
356
362
  */
357
363
  setHeader: <K extends keyof (ResHeaders & ForklaunchResHeaders)>(key: K, value: K extends keyof ForklaunchResHeaders ? ForklaunchResHeaders[K] : ResHeaders[K]) => void;
364
+ /**
365
+ * Adds an event listener to the response.
366
+ * @param {string} event - The event to listen for.
367
+ * @param {Function} listener - The listener function.
368
+ */
369
+ on(event: 'close', listener: () => void): this;
370
+ on(event: 'drain', listener: () => void): this;
371
+ on(event: 'error', listener: (err: Error) => void): this;
372
+ on(event: 'finish', listener: () => void): this;
373
+ on(event: 'pipe', listener: (src: Readable) => void): this;
374
+ on(event: 'unpipe', listener: (src: Readable) => void): this;
375
+ on(event: string | symbol, listener: (...args: unknown[]) => void): this;
358
376
  /**
359
377
  * Sets the status of the response.
360
378
  * @param {U} code - The status code.
@@ -370,6 +388,11 @@ interface ForklaunchResponse<ResBodyMap extends Record<number, unknown>, ResHead
370
388
  * @param {string} [data] - Optional data to send.
371
389
  */
372
390
  end: (data?: string) => void;
391
+ /**
392
+ * Sets the content type of the response.
393
+ * @param {string} type - The content type.
394
+ */
395
+ type: (type: string) => void;
373
396
  /** Local variables */
374
397
  locals: LocalsObj;
375
398
  /** Cors */
@@ -618,11 +641,12 @@ declare class ForklaunchExpressLikeRouter<SV extends AnySchemaValidator, BasePat
618
641
  #private;
619
642
  readonly schemaValidator: SV;
620
643
  readonly internal: Internal;
644
+ readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
621
645
  requestHandler: RouterHandler;
622
646
  routers: ForklaunchRouter<SV>[];
623
647
  readonly routes: ForklaunchRoute<SV>[];
624
648
  readonly basePath: BasePath;
625
- constructor(basePath: BasePath, schemaValidator: SV, internal: Internal);
649
+ constructor(basePath: BasePath, schemaValidator: SV, internal: Internal, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
626
650
  registerRoute<ContractMethod extends Method, Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(method: ContractMethod, path: Path, registrationMethod: PathBasedHandler<RouterHandler>, contractDetailsOrMiddlewareOrTypedHandler: ContractDetailsOrMiddlewareOrTypedHandler<SV, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>, ...middlewareOrMiddlewareAndTypedHandler: MiddlewareOrMiddlewareWithTypedHandler<SV, ContractMethod, Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>[]): LiveTypeFunction<SV, `${BasePath}${Path}`, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders>;
627
651
  registerMiddlewareHandler<Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(registrationMethod: PathOrMiddlewareBasedHandler<RouterHandler>, pathOrContractDetailsOrMiddlewareOrTypedHandler: Path | ContractDetailsOrMiddlewareOrTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>, contractDetailsOrMiddlewareOrTypedHandler?: ContractDetailsOrMiddlewareOrTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>, ...middlewareOrMiddlewareWithTypedHandler: MiddlewareOrMiddlewareWithTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction>[]): this;
628
652
  registerNestableMiddlewareHandler<Path extends `/${string}`, P extends ParamsObject<SV>, ResBodyMap extends ResponsesObject<SV>, ReqBody extends Body<SV>, ReqQuery extends QueryObject<SV>, ReqHeaders extends HeadersObject<SV>, ResHeaders extends HeadersObject<SV>, LocalsObj extends Record<string, unknown>>(registrationMethod: NestableRouterBasedHandler<RouterHandler, Internal>, pathOrContractDetailsOrMiddlewareOrTypedHandler: Path | ContractDetailsOrMiddlewareOrTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction> | ConstrainedForklaunchRouter<SV, RouterHandler>, contractDetailsOrMiddlewareOrTypedHandler?: ContractDetailsOrMiddlewareOrTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction> | ConstrainedForklaunchRouter<SV, RouterHandler>, ...middlewareOrMiddlewareWithTypedHandler: (MiddlewareOrMiddlewareWithTypedHandler<SV, 'middleware', Path, P, ResBodyMap, ReqBody, ReqQuery, ReqHeaders, ResHeaders, LocalsObj, BaseRequest, BaseResponse, NextFunction> | ConstrainedForklaunchRouter<SV, RouterHandler>)[]): this;
@@ -752,12 +776,13 @@ declare class ForklaunchExpressLikeRouter<SV extends AnySchemaValidator, BasePat
752
776
  declare abstract class ForklaunchExpressLikeApplication<SV extends AnySchemaValidator, Server extends ExpressLikeRouter<RouterHandler, Server>, RouterHandler, BaseRequest, BaseResponse, NextFunction> extends ForklaunchExpressLikeRouter<SV, '/', RouterHandler, Server, BaseRequest, BaseResponse, NextFunction> {
753
777
  readonly schemaValidator: SV;
754
778
  readonly internal: Server;
779
+ readonly openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>;
755
780
  /**
756
781
  * Creates an instance of the Application class.
757
782
  *
758
783
  * @param {SV} schemaValidator - The schema validator.
759
784
  */
760
- constructor(schemaValidator: SV, internal: Server);
785
+ constructor(schemaValidator: SV, internal: Server, openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>);
761
786
  abstract listen(...args: unknown[]): void;
762
787
  }
763
788
 
@@ -914,43 +939,20 @@ declare function generateSwaggerDocument<SV extends AnySchemaValidator>(schemaVa
914
939
  declare const ATTR_API_NAME = "api.name";
915
940
  declare const ATTR_CORRELATION_ID = "correlation.id";
916
941
 
917
- type MetricType<T extends string> = T extends 'counter' ? Counter : T extends 'gauge' ? Gauge : T extends 'histogram' ? Histogram : T extends 'upDownCounter' ? UpDownCounter : T extends 'observableCounter' ? ObservableCounter : T extends 'observableGauge' ? ObservableGauge : T extends 'observableUpDownCounter' ? ObservableUpDownCounter : undefined;
918
- type MetricsDefinition = Record<string, 'counter' | 'gauge' | 'histogram' | 'upDownCounter' | 'observableCounter' | 'observableGauge' | 'observableUpDownCounter'>;
919
-
920
942
  declare function metricsDefinitions<T extends MetricsDefinition>(metrics: T): T;
921
943
 
922
- declare class OpenTelemetryCollector<AppliedMetricsDefinition extends MetricsDefinition> {
923
- private readonly serviceName;
924
- private readonly logger;
925
- private readonly metrics;
926
- constructor(serviceName: string, level?: LevelWithSilentOrString, metricDefinitions?: AppliedMetricsDefinition);
927
- log(level: LevelWithSilent, msg: string, meta?: AnyValueMap): void;
928
- info(msg: string, meta?: AnyValueMap): void;
929
- error(msg: string, meta?: AnyValueMap): void;
930
- warn(msg: string, meta?: AnyValueMap): void;
931
- debug(msg: string, meta?: AnyValueMap): void;
932
- trace(msg: string, meta?: AnyValueMap): void;
933
- getMetric<T extends keyof AppliedMetricsDefinition>(metricId: T): MetricType<AppliedMetricsDefinition[T]>;
934
- }
935
- declare const httpRequestsTotalCounter: Counter<{
936
- "service.name": string;
937
- "api.name": string;
938
- "correlation.id": string;
939
- "http.request.method": string;
940
- "http.route": string;
941
- "http.response.status_code": number;
942
- }>;
943
-
944
+ declare function meta(meta: Record<string, unknown>): LoggerMeta;
944
945
  declare class PinoLogger {
945
946
  private pinoLogger;
946
947
  private meta;
948
+ private prettyPrinter;
947
949
  constructor(level: LevelWithSilentOrString, meta?: AnyValueMap);
948
- log(level: LevelWithSilent, msg: string, meta?: AnyValueMap): void;
949
- error(msg: string, meta?: AnyValueMap): void;
950
- info(msg: string, meta?: AnyValueMap): void;
951
- debug(msg: string, meta?: AnyValueMap): void;
952
- warn(msg: string, meta?: AnyValueMap): void;
953
- trace(msg: string, meta?: AnyValueMap): void;
950
+ log(level: LevelWithSilent, ...args: (string | unknown | LoggerMeta)[]): void;
951
+ error: LogFn;
952
+ info: LogFn;
953
+ debug: LogFn;
954
+ warn: LogFn;
955
+ trace: LogFn;
954
956
  child(meta?: AnyValueMap): PinoLogger;
955
957
  getBaseLogger(): Logger;
956
958
  }
@@ -958,4 +960,10 @@ declare function logger(level: LevelWithSilentOrString, meta?: AnyValueMap): Pin
958
960
 
959
961
  declare function recordMetric<SV extends AnySchemaValidator, P extends ParamsDictionary, ReqBody extends Record<string, unknown>, ReqQuery extends ParsedQs, ResBodyMap extends Record<string, unknown>, ReqHeaders extends Record<string, string>, ResHeaders extends Record<string, string>, LocalsObj extends Record<string, unknown>>(req: ForklaunchRequest<SV, P, ReqBody, ReqQuery, ReqHeaders>, res: ForklaunchResponse<ResBodyMap, ResHeaders, LocalsObj>): void;
960
962
 
961
- export { ATTR_API_NAME, ATTR_CORRELATION_ID, type ApiClient, type AuthMethods, type AuthMethodsBase, type Body, type BodyObject, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type ErrorContainer, type ExpressLikeAuthMapper, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractedParamsObject, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HttpContractDetails, type HttpMethod, type LiveTypeFunction, type LiveTypeRouteDefinition, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type Method, type MetricType, type MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, type NumberOnlyObject, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RequestContext, type ResolvedForklaunchRequest, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type SchemaAuthMethods, type StatusCode, type StringOnlyObject, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, delete_, enrichExpressLikeSend, generateSwaggerDocument, get, getCodeForStatus, head, httpRequestsTotalCounter, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedHandler };
963
+ type DocsConfiguration = ({
964
+ type: 'scalar';
965
+ } & Partial<Omit<ApiReferenceConfiguration, 'spec'>>) | {
966
+ type: 'swagger';
967
+ };
968
+
969
+ export { ATTR_API_NAME, ATTR_CORRELATION_ID, type ApiClient, type AuthMethods, type AuthMethodsBase, type Body, type BodyObject, type ConstrainedForklaunchRouter, type ContractDetails, type ContractDetailsExpressLikeSchemaHandler, type ContractDetailsOrMiddlewareOrTypedHandler, type DocsConfiguration, type ErrorContainer, type ExpressLikeAuthMapper, type ExpressLikeHandler, type ExpressLikeRouter, type ExpressLikeSchemaAuthMapper, type ExpressLikeSchemaHandler, type ExpressLikeTypedHandler, type ExtractedParamsObject, type ForklaunchBaseRequest, ForklaunchExpressLikeApplication, ForklaunchExpressLikeRouter, type ForklaunchNextFunction, type ForklaunchRequest, type ForklaunchResErrors, type ForklaunchResHeaders, type ForklaunchResponse, type ForklaunchRoute, type ForklaunchRouter, type ForklaunchSendableData, type ForklaunchStatusResponse, HTTPStatuses, type HeadersObject, type HttpContractDetails, type HttpMethod, type LiveTypeFunction, type LiveTypeRouteDefinition, LogFn, LoggerMeta, type MapParamsSchema, type MapReqBodySchema, type MapReqHeadersSchema, type MapReqQuerySchema, type MapResBodyMapSchema, type MapResHeadersSchema, type MapSchema, type Method, MetricsDefinition, type MiddlewareContractDetails, type MiddlewareOrMiddlewareWithTypedHandler, type NestableRouterBasedHandler, type NumberOnlyObject, OpenTelemetryCollector, type ParamsDictionary, type ParamsObject, type PathBasedHandler, type PathMatch, type PathOrMiddlewareBasedHandler, type PathParamHttpContractDetails, type PathParamMethod, type QueryObject, type RequestContext, type ResolvedForklaunchRequest, type ResponseCompiledSchema, type ResponseShape, type ResponsesObject, type SchemaAuthMethods, type StatusCode, type StringOnlyObject, type TypedHandler, type TypedMiddlewareDefinition, type TypedNestableMiddlewareDefinition, delete_, enrichExpressLikeSend, generateSwaggerDocument, get, getCodeForStatus, head, isClientError, isForklaunchRequest, isForklaunchRouter, isInformational, isRedirection, isServerError, isSuccessful, isValidStatusCode, logger, meta, metricsDefinitions, middleware, options, patch, post, put, recordMetric, trace, typedHandler };