@venizia/ignis-helpers 0.4.1 → 0.4.3
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/cjs/common/constants/duration.d.ts +4 -1
- package/dist/cjs/common/constants/duration.d.ts.map +1 -1
- package/dist/cjs/common/constants/duration.js +13 -8
- package/dist/cjs/common/constants/duration.js.map +1 -1
- package/dist/cjs/common/types/field-mapping.d.ts +13 -1
- package/dist/cjs/common/types/field-mapping.d.ts.map +1 -1
- package/dist/cjs/common/types/field-mapping.js +20 -0
- package/dist/cjs/common/types/field-mapping.js.map +1 -1
- package/dist/cjs/core.d.ts +2 -1
- package/dist/cjs/core.d.ts.map +1 -1
- package/dist/cjs/core.js +6 -1
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.d.ts +2 -2
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.d.ts.map +1 -1
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.js +3 -1
- package/dist/cjs/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/cjs/modules/crypto/algorithms/aes.constants.d.ts +11 -0
- package/dist/cjs/modules/crypto/algorithms/aes.constants.d.ts.map +1 -0
- package/dist/cjs/modules/crypto/algorithms/aes.constants.js +14 -0
- package/dist/cjs/modules/crypto/algorithms/aes.constants.js.map +1 -0
- package/dist/cjs/modules/env/app-env.d.ts.map +1 -1
- package/dist/cjs/modules/env/app-env.js +1 -1
- package/dist/cjs/modules/env/app-env.js.map +1 -1
- package/dist/cjs/modules/error/index.d.ts +1 -1
- package/dist/cjs/modules/error/index.d.ts.map +1 -1
- package/dist/cjs/modules/error/index.js +2 -1
- package/dist/cjs/modules/error/index.js.map +1 -1
- package/dist/cjs/modules/logger/hf/common/types.d.ts +3 -1
- package/dist/cjs/modules/logger/hf/common/types.d.ts.map +1 -1
- package/dist/cjs/modules/logger/hf/common/types.js.map +1 -1
- package/dist/cjs/modules/logger/hf/logger.d.ts.map +1 -1
- package/dist/cjs/modules/logger/hf/logger.js +3 -1
- package/dist/cjs/modules/logger/hf/logger.js.map +1 -1
- package/dist/cjs/modules/logger/pino/common/constants.d.ts +10 -1
- package/dist/cjs/modules/logger/pino/common/constants.d.ts.map +1 -1
- package/dist/cjs/modules/logger/pino/common/constants.js +11 -1
- package/dist/cjs/modules/logger/pino/common/constants.js.map +1 -1
- package/dist/cjs/modules/logger/pino/destination.d.ts.map +1 -1
- package/dist/cjs/modules/logger/pino/destination.js +4 -3
- package/dist/cjs/modules/logger/pino/destination.js.map +1 -1
- package/dist/cjs/modules/network/http-request/common/constants.d.ts +11 -0
- package/dist/cjs/modules/network/http-request/common/constants.d.ts.map +1 -0
- package/dist/cjs/modules/network/http-request/common/constants.js +14 -0
- package/dist/cjs/modules/network/http-request/common/constants.js.map +1 -0
- package/dist/cjs/modules/network/http-request/common/index.d.ts +1 -0
- package/dist/cjs/modules/network/http-request/common/index.d.ts.map +1 -1
- package/dist/cjs/modules/network/http-request/common/index.js +1 -0
- package/dist/cjs/modules/network/http-request/common/index.js.map +1 -1
- package/dist/cjs/modules/network/http-request/common/types.d.ts +1 -1
- package/dist/cjs/modules/network/http-request/common/types.d.ts.map +1 -1
- package/dist/cjs/modules/network/http-request/common/types.js.map +1 -1
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.d.ts +13 -2
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.d.ts.map +1 -1
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.js +26 -8
- package/dist/cjs/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/cjs/modules/queue/common/constants.d.ts +11 -0
- package/dist/cjs/modules/queue/common/constants.d.ts.map +1 -0
- package/dist/cjs/modules/queue/common/constants.js +14 -0
- package/dist/cjs/modules/queue/common/constants.js.map +1 -0
- package/dist/cjs/modules/queue/common/index.d.ts +1 -0
- package/dist/cjs/modules/queue/common/index.d.ts.map +1 -1
- package/dist/cjs/modules/queue/common/index.js +1 -0
- package/dist/cjs/modules/queue/common/index.js.map +1 -1
- package/dist/cjs/modules/queue/common/types.d.ts +1 -1
- package/dist/cjs/modules/queue/common/types.d.ts.map +1 -1
- package/dist/cjs/modules/queue/common/types.js.map +1 -1
- package/dist/cjs/modules/queue/kafka/common/constants.d.ts +9 -0
- package/dist/cjs/modules/queue/kafka/common/constants.d.ts.map +1 -1
- package/dist/cjs/modules/queue/kafka/common/constants.js +11 -1
- package/dist/cjs/modules/queue/kafka/common/constants.js.map +1 -1
- package/dist/cjs/modules/queue/kafka/consumer.d.ts +2 -1
- package/dist/cjs/modules/queue/kafka/consumer.d.ts.map +1 -1
- package/dist/cjs/modules/queue/kafka/consumer.js +2 -2
- package/dist/cjs/modules/queue/kafka/consumer.js.map +1 -1
- package/dist/cjs/modules/secrets/base/abstract.helper.d.ts.map +1 -1
- package/dist/cjs/modules/secrets/base/abstract.helper.js +5 -1
- package/dist/cjs/modules/secrets/base/abstract.helper.js.map +1 -1
- package/dist/cjs/modules/temporal/common/constants.d.ts +21 -0
- package/dist/cjs/modules/temporal/common/constants.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/common/constants.js +22 -1
- package/dist/cjs/modules/temporal/common/constants.js.map +1 -1
- package/dist/cjs/modules/temporal/locale/locale.d.ts +4 -3
- package/dist/cjs/modules/temporal/locale/locale.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/locale/locale.js +2 -1
- package/dist/cjs/modules/temporal/locale/locale.js.map +1 -1
- package/dist/cjs/modules/temporal/pattern/common/constants.d.ts +43 -0
- package/dist/cjs/modules/temporal/pattern/common/constants.d.ts.map +1 -0
- package/dist/cjs/modules/temporal/pattern/common/constants.js +74 -0
- package/dist/cjs/modules/temporal/pattern/common/constants.js.map +1 -0
- package/dist/cjs/modules/temporal/pattern/common/index.d.ts +1 -0
- package/dist/cjs/modules/temporal/pattern/common/index.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/pattern/common/index.js +1 -0
- package/dist/cjs/modules/temporal/pattern/common/index.js.map +1 -1
- package/dist/cjs/modules/temporal/pattern/common/types.d.ts +2 -11
- package/dist/cjs/modules/temporal/pattern/common/types.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/pattern/common/types.js.map +1 -1
- package/dist/cjs/modules/temporal/pattern/tokens.d.ts +2 -1
- package/dist/cjs/modules/temporal/pattern/tokens.d.ts.map +1 -1
- package/dist/cjs/modules/temporal/pattern/tokens.js +2 -14
- package/dist/cjs/modules/temporal/pattern/tokens.js.map +1 -1
- package/dist/cjs/modules/worker-thread/thread/base.js +2 -2
- package/dist/cjs/modules/worker-thread/thread/base.js.map +1 -1
- package/dist/cjs/utilities/request.utility.d.ts +21 -2
- package/dist/cjs/utilities/request.utility.d.ts.map +1 -1
- package/dist/cjs/utilities/request.utility.js +25 -5
- package/dist/cjs/utilities/request.utility.js.map +1 -1
- package/dist/esm/common/constants/duration.d.ts +4 -1
- package/dist/esm/common/constants/duration.d.ts.map +1 -1
- package/dist/esm/common/constants/duration.js +13 -8
- package/dist/esm/common/constants/duration.js.map +1 -1
- package/dist/esm/common/types/field-mapping.d.ts +13 -1
- package/dist/esm/common/types/field-mapping.d.ts.map +1 -1
- package/dist/esm/common/types/field-mapping.js +18 -1
- package/dist/esm/common/types/field-mapping.js.map +1 -1
- package/dist/esm/core.d.ts +2 -1
- package/dist/esm/core.d.ts.map +1 -1
- package/dist/esm/core.js +4 -0
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts +2 -2
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.d.ts.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js +2 -0
- package/dist/esm/modules/crypto/algorithms/aes.algorithm.js.map +1 -1
- package/dist/esm/modules/crypto/algorithms/aes.constants.d.ts +11 -0
- package/dist/esm/modules/crypto/algorithms/aes.constants.d.ts.map +1 -0
- package/dist/esm/modules/crypto/algorithms/aes.constants.js +10 -0
- package/dist/esm/modules/crypto/algorithms/aes.constants.js.map +1 -0
- package/dist/esm/modules/env/app-env.d.ts.map +1 -1
- package/dist/esm/modules/env/app-env.js +1 -1
- package/dist/esm/modules/env/app-env.js.map +1 -1
- package/dist/esm/modules/error/index.d.ts +1 -1
- package/dist/esm/modules/error/index.d.ts.map +1 -1
- package/dist/esm/modules/error/index.js +1 -1
- package/dist/esm/modules/error/index.js.map +1 -1
- package/dist/esm/modules/logger/hf/common/types.d.ts +3 -1
- package/dist/esm/modules/logger/hf/common/types.d.ts.map +1 -1
- package/dist/esm/modules/logger/hf/common/types.js.map +1 -1
- package/dist/esm/modules/logger/hf/logger.d.ts.map +1 -1
- package/dist/esm/modules/logger/hf/logger.js +3 -1
- package/dist/esm/modules/logger/hf/logger.js.map +1 -1
- package/dist/esm/modules/logger/pino/common/constants.d.ts +10 -1
- package/dist/esm/modules/logger/pino/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/logger/pino/common/constants.js +9 -0
- package/dist/esm/modules/logger/pino/common/constants.js.map +1 -1
- package/dist/esm/modules/logger/pino/destination.d.ts.map +1 -1
- package/dist/esm/modules/logger/pino/destination.js +4 -3
- package/dist/esm/modules/logger/pino/destination.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/constants.d.ts +11 -0
- package/dist/esm/modules/network/http-request/common/constants.d.ts.map +1 -0
- package/dist/esm/modules/network/http-request/common/constants.js +10 -0
- package/dist/esm/modules/network/http-request/common/constants.js.map +1 -0
- package/dist/esm/modules/network/http-request/common/index.d.ts +1 -0
- package/dist/esm/modules/network/http-request/common/index.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/common/index.js +1 -0
- package/dist/esm/modules/network/http-request/common/index.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/types.d.ts +1 -1
- package/dist/esm/modules/network/http-request/common/types.d.ts.map +1 -1
- package/dist/esm/modules/network/http-request/common/types.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts +13 -2
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +24 -7
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/queue/common/constants.d.ts +11 -0
- package/dist/esm/modules/queue/common/constants.d.ts.map +1 -0
- package/dist/esm/modules/queue/common/constants.js +10 -0
- package/dist/esm/modules/queue/common/constants.js.map +1 -0
- package/dist/esm/modules/queue/common/index.d.ts +1 -0
- package/dist/esm/modules/queue/common/index.d.ts.map +1 -1
- package/dist/esm/modules/queue/common/index.js +1 -0
- package/dist/esm/modules/queue/common/index.js.map +1 -1
- package/dist/esm/modules/queue/common/types.d.ts +1 -1
- package/dist/esm/modules/queue/common/types.d.ts.map +1 -1
- package/dist/esm/modules/queue/common/types.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/constants.d.ts +9 -0
- package/dist/esm/modules/queue/kafka/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/common/constants.js +9 -0
- package/dist/esm/modules/queue/kafka/common/constants.js.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.d.ts +2 -1
- package/dist/esm/modules/queue/kafka/consumer.d.ts.map +1 -1
- package/dist/esm/modules/queue/kafka/consumer.js +3 -3
- package/dist/esm/modules/queue/kafka/consumer.js.map +1 -1
- package/dist/esm/modules/secrets/base/abstract.helper.d.ts.map +1 -1
- package/dist/esm/modules/secrets/base/abstract.helper.js +5 -1
- package/dist/esm/modules/secrets/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/temporal/common/constants.d.ts +21 -0
- package/dist/esm/modules/temporal/common/constants.d.ts.map +1 -1
- package/dist/esm/modules/temporal/common/constants.js +19 -0
- package/dist/esm/modules/temporal/common/constants.js.map +1 -1
- package/dist/esm/modules/temporal/locale/locale.d.ts +4 -3
- package/dist/esm/modules/temporal/locale/locale.d.ts.map +1 -1
- package/dist/esm/modules/temporal/locale/locale.js +2 -1
- package/dist/esm/modules/temporal/locale/locale.js.map +1 -1
- package/dist/esm/modules/temporal/pattern/common/constants.d.ts +43 -0
- package/dist/esm/modules/temporal/pattern/common/constants.d.ts.map +1 -0
- package/dist/esm/modules/temporal/pattern/common/constants.js +70 -0
- package/dist/esm/modules/temporal/pattern/common/constants.js.map +1 -0
- package/dist/esm/modules/temporal/pattern/common/index.d.ts +1 -0
- package/dist/esm/modules/temporal/pattern/common/index.d.ts.map +1 -1
- package/dist/esm/modules/temporal/pattern/common/index.js +1 -0
- package/dist/esm/modules/temporal/pattern/common/index.js.map +1 -1
- package/dist/esm/modules/temporal/pattern/common/types.d.ts +2 -11
- package/dist/esm/modules/temporal/pattern/common/types.d.ts.map +1 -1
- package/dist/esm/modules/temporal/pattern/common/types.js.map +1 -1
- package/dist/esm/modules/temporal/pattern/tokens.d.ts +2 -1
- package/dist/esm/modules/temporal/pattern/tokens.d.ts.map +1 -1
- package/dist/esm/modules/temporal/pattern/tokens.js +2 -14
- package/dist/esm/modules/temporal/pattern/tokens.js.map +1 -1
- package/dist/esm/modules/worker-thread/thread/base.js +2 -2
- package/dist/esm/modules/worker-thread/thread/base.js.map +1 -1
- package/dist/esm/utilities/request.utility.d.ts +21 -2
- package/dist/esm/utilities/request.utility.d.ts.map +1 -1
- package/dist/esm/utilities/request.utility.js +22 -4
- package/dist/esm/utilities/request.utility.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../../../src/modules/logger/hf/logger.ts"],"names":[],"mappings":";;;AACA,kCAAyC;AACzC,sCAAsF;AACtF,8CAAiD;AACjD,qCAakB;AAClB,iCAAmC;AAEnC,4KAA4K;AAC5K,MAAa,QAAS,SAAQ,qBAAc;aAClB,gBAAW,GAAG,IAAI,WAAW,EAAE,CAAC;aAChC,eAAU,GAAG,IAAI,GAAG,EAAsB,CAAC;aACpD,UAAK,GAAG,IAAI,GAAG,EAAoB,CA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KAAK,IAAI,CAAC,yBAAgB,EAAE,CAAC;YACnD,OAAO;QACT,CAAC;QACD,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAc,EAAE,KAAK,CAAC;YACpD,CAAC,CAAC,uBAAc,CAAC,KAAK,CAAC;YACvB,CAAC,CAAC,uBAAc,CAAC,IAAI,CAAC;QACxB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YAC3C,OAAO;QACT,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED,GAAG,CAAC,UAAkB;QACpB,OAAO,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,UAAU,EAAE,CAAC,CAAC;IACrD,CAAC;;AAnIH,4BAoIC","sourcesContent":["import { type AnyType } from '@/common/types';\nimport { AbstractLogger } from '../base';\nimport { type ILogger, LogLevels, SHOULD_LOG_DEBUG, type TLogLevel } from '../common';\nimport { formatLogMessage } from '../formatting';\nimport {\n BUFFER_SIZE,\n ENTRY_SIZE,\n HF_LEVEL_CODES,\n HF_MESSAGE_MAX_BYTES,\n HF_SCOPE_MAX_BYTES,\n MESSAGE_CACHE_CAP,\n OFFSET_LEVEL,\n OFFSET_MESSAGE,\n OFFSET_MESSAGE_LENGTH,\n OFFSET_SCOPE,\n OFFSET_SCOPE_LENGTH,\n type TRingState,\n} from './common';\nimport { HfLogRing } from './ring';\n\n/** Ring-buffer logger for hot paths; extends AbstractLogger, NOT BaseLogger - BaseLogger's string-sink plumbing is exactly the cost this implementation exists to avoid. */\nexport class HfLogger extends AbstractLogger {\n private static readonly textEncoder = new TextEncoder();\n private static readonly scopeCache = new Map<string, Uint8Array>();\n private static cache = new Map<string, HfLogger>();\n private static messageCache = new Map<string, Uint8Array>();\n\n private readonly scope: string;\n private readonly scopeBytes: Uint8Array;\n private readonly scopeLength: number;\n // Resolved once at construction (get() has already allocated the ring): saves a call and a null-check per log on a path budgeted in nanoseconds.\n private readonly ring: TRingState;\n\n private constructor(scope: string) {\n super();\n this.scope = scope;\n this.scopeBytes = HfLogger.encodeScope(scope);\n this.scopeLength = this.scopeBytes.length;\n this.ring = HfLogRing.get();\n }\n\n private static encodeScope(scope: string): Uint8Array {\n let bytes = HfLogger.scopeCache.get(scope);\n if (!bytes) {\n bytes = HfLogger.textEncoder.encode(scope).subarray(0, HF_SCOPE_MAX_BYTES);\n HfLogger.scopeCache.set(scope, bytes);\n }\n return bytes;\n }\n\n static get(scope: string): HfLogger {\n let logger = this.cache.get(scope);\n if (!logger) {\n logger = new HfLogger(scope); // first logger allocates the ring - never at import\n this.cache.set(scope, logger);\n }\n return logger;\n }\n\n /** Pre-encode a message at initialization time; the cache is FIFO-bounded so dynamic strings can't grow it without limit. */\n static encodeMessage(message: string): Uint8Array {\n const cached = this.messageCache.get(message);\n if (cached) {\n return cached;\n }\n\n const bytes = HfLogger.textEncoder.encode(message);\n if (this.messageCache.size >= MESSAGE_CACHE_CAP) {\n this.evictOldestMessage();\n }\n this.messageCache.set(message, bytes);\n return bytes;\n }\n\n private static evictOldestMessage(): void {\n const oldest = this.messageCache.keys().next().value;\n if (oldest === undefined) {\n return;\n }\n this.messageCache.delete(oldest);\n }\n\n private writeEntry(levelCode: number, messageBytes: Uint8Array): void {\n const ring = this.ring;\n const slot = ring.writeIndex++ & (BUFFER_SIZE - 1);\n const offset = slot * ENTRY_SIZE;\n ring.f64[offset >> 3] = performance.timeOrigin + performance.now();\n const bytes = ring.bytes;\n bytes[offset + OFFSET_LEVEL] = levelCode;\n bytes[offset + OFFSET_SCOPE_LENGTH] = this.scopeLength;\n bytes.set(this.scopeBytes, offset + OFFSET_SCOPE);\n const messageLength =\n messageBytes.length < HF_MESSAGE_MAX_BYTES ? messageBytes.length : HF_MESSAGE_MAX_BYTES;\n bytes[offset + OFFSET_MESSAGE_LENGTH] = messageLength;\n bytes.set(\n messageLength === messageBytes.length\n ? messageBytes\n : messageBytes.subarray(0, messageLength),\n offset + OFFSET_MESSAGE,\n );\n }\n\n private writeString(levelCode: number, message: string, args: Array<AnyType>): void {\n if (args.length > 0) {\n // Slow path, documented: args are formatted (deep inspection + redaction) - never dropped.\n this.writeEntry(levelCode, HfLogger.textEncoder.encode(formatLogMessage({ message, args })));\n return;\n }\n this.writeEntry(levelCode, HfLogger.encodeMessage(message));\n }\n\n debug(message: string, ...args: AnyType[]): void {\n if (!SHOULD_LOG_DEBUG) {\n return;\n }\n this.writeString(HF_LEVEL_CODES.debug, message, args);\n }\n\n info(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.info, message, args);\n }\n\n warn(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.warn, message, args);\n }\n\n error(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.error, message, args);\n }\n\n emerg(message: string, ...args: AnyType[]): void {\n this.writeString(HF_LEVEL_CODES.emerg, message, args);\n }\n\n log(level: TLogLevel, message: string, ...args: AnyType[]): void;\n log(level: TLogLevel, messageBytes: Uint8Array): void;\n log(level: TLogLevel, message: string | Uint8Array, ...args: AnyType[]): void {\n if (level === LogLevels.DEBUG && !SHOULD_LOG_DEBUG) {\n return;\n }\n const levelCode = Object.hasOwn(HF_LEVEL_CODES, level)\n ? HF_LEVEL_CODES[level]\n : HF_LEVEL_CODES.info;\n if (typeof message === 'string') {\n this.writeString(levelCode, message, args);\n return;\n }\n this.writeEntry(levelCode, message);\n }\n\n for(methodName: string): ILogger {\n return HfLogger.get(`${this.scope}-${methodName}`);\n }\n}\n"]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import type { TConstValue } from '../../../../common/types';
|
|
1
2
|
import { type TPinoCustomLevelName } from './types';
|
|
2
3
|
/** pino levels are ASCENDING severity (error 50 > warn 40 > info 30 > debug 20); `emerg`(70) extends above error. NORMATIVE - do not renumber without updating the spec. */
|
|
3
4
|
export declare const PINO_CUSTOM_LEVELS: Record<TPinoCustomLevelName, number>;
|
|
4
|
-
|
|
5
|
+
/** How often the file destination rolls (pino-roll's `frequency`). */
|
|
6
|
+
export declare class PinoFrequencies {
|
|
7
|
+
static readonly HOURLY = "hourly";
|
|
8
|
+
static readonly DAILY = "daily";
|
|
9
|
+
static readonly SCHEME_SET: Set<string>;
|
|
10
|
+
static isValid(value: string): boolean;
|
|
11
|
+
}
|
|
12
|
+
/** Valid pino roll frequency values. */
|
|
13
|
+
export type TFrequency = TConstValue<typeof PinoFrequencies>;
|
|
5
14
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/logger/pino/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,4KAA4K;AAC5K,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,oBAAoB,EAAE,MAAM,CAEnE,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/logger/pino/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEpD,4KAA4K;AAC5K,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,oBAAoB,EAAE,MAAM,CAEnE,CAAC;AAEF,sEAAsE;AACtE,qBAAa,eAAe;IAC1B,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW;IAEhC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAA8C;IAExE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,wCAAwC;AACxC,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PINO_CUSTOM_LEVELS = void 0;
|
|
3
|
+
exports.PinoFrequencies = exports.PINO_CUSTOM_LEVELS = void 0;
|
|
4
4
|
/** pino levels are ASCENDING severity (error 50 > warn 40 > info 30 > debug 20); `emerg`(70) extends above error. NORMATIVE - do not renumber without updating the spec. */
|
|
5
5
|
exports.PINO_CUSTOM_LEVELS = {
|
|
6
6
|
emerg: 70,
|
|
7
7
|
};
|
|
8
|
+
/** How often the file destination rolls (pino-roll's `frequency`). */
|
|
9
|
+
class PinoFrequencies {
|
|
10
|
+
static { this.HOURLY = 'hourly'; }
|
|
11
|
+
static { this.DAILY = 'daily'; }
|
|
12
|
+
static { this.SCHEME_SET = new Set([this.HOURLY, this.DAILY]); }
|
|
13
|
+
static isValid(value) {
|
|
14
|
+
return this.SCHEME_SET.has(value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.PinoFrequencies = PinoFrequencies;
|
|
8
18
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../src/modules/logger/pino/common/constants.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../src/modules/logger/pino/common/constants.ts"],"names":[],"mappings":";;;AAGA,4KAA4K;AAC/J,QAAA,kBAAkB,GAAyC;IACtE,KAAK,EAAE,EAAE;CACV,CAAC;AAEF,sEAAsE;AACtE,MAAa,eAAe;aACV,WAAM,GAAG,QAAQ,CAAC;aAClB,UAAK,GAAG,OAAO,CAAC;aAEhB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAExE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AARH,0CASC","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { type TPinoCustomLevelName } from './types';\n\n/** pino levels are ASCENDING severity (error 50 > warn 40 > info 30 > debug 20); `emerg`(70) extends above error. NORMATIVE - do not renumber without updating the spec. */\nexport const PINO_CUSTOM_LEVELS: Record<TPinoCustomLevelName, number> = {\n emerg: 70,\n};\n\n/** How often the file destination rolls (pino-roll's `frequency`). */\nexport class PinoFrequencies {\n static readonly HOURLY = 'hourly';\n static readonly DAILY = 'daily';\n\n static readonly SCHEME_SET = new Set<string>([this.HOURLY, this.DAILY]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid pino roll frequency values. */\nexport type TFrequency = TConstValue<typeof PinoFrequencies>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/pino/destination.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,
|
|
1
|
+
{"version":3,"file":"destination.d.ts","sourceRoot":"","sources":["../../../../../src/modules/logger/pino/destination.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAE5D,mIAAmI;AACnI,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IACE,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,UAAU,CAAC;QACtB,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE;YAAE,KAAK,EAAE,MAAM,CAAA;SAAE,CAAC;QACzB,KAAK,EAAE,IAAI,CAAC;KACb,CAAC;CACH,CAAC;AAEN,2MAA2M;AAC3M,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAsC;IAC/E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAQ;IAEjD,2JAA2J;IAC3J,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU;IAsB/C,+FAA+F;IAC/F,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAejC,0LAA0L;IAC1L,MAAM,CAAC,kBAAkB,CAAC,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,UAAU,CAAA;KAAE,GAAG,MAAM;IA0BlF,yKAAyK;IACzK,MAAM,CAAC,WAAW,IAAI,gBAAgB;IA8BtC,sRAAsR;IACtR,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC,iBAAiB,GAAG,SAAS;CAyBzE;AAID,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,UAAiD,CAAC;AAEhG,eAAO,MAAM,kBAAkB,GAAI,MAAM;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,UAAU,CAAA;CAAE,KAAG,MAC3C,CAAC;AAE3C,eAAO,MAAM,sBAAsB,QAAO,gBAAiD,CAAC;AAE5F,eAAO,MAAM,gBAAgB,GAAI,MAAM,gBAAgB,KAAG,IAAI,CAAC,iBAAiB,GAAG,SACtD,CAAC"}
|
|
@@ -10,20 +10,21 @@ const module_utility_1 = require("../../../utilities/module.utility");
|
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
11
|
const pino_1 = __importDefault(require("pino"));
|
|
12
12
|
const common_1 = require("../common");
|
|
13
|
+
const common_2 = require("./common");
|
|
13
14
|
/** Reads `APP_ENV_LOGGER_*` and turns it into a destination. Warning prefixes name the operation, not the class - the tests and the published API still call these `mapFrequency`/`mapMaxFilesToCount`. */
|
|
14
15
|
class PinoDestination {
|
|
15
|
-
static { this.DEFAULT_FREQUENCY =
|
|
16
|
+
static { this.DEFAULT_FREQUENCY = common_2.PinoFrequencies.HOURLY; }
|
|
16
17
|
static { this.DEFAULT_MAX_FILES = '5d'; }
|
|
17
18
|
/** `APP_ENV_LOGGER_FILE_FREQUENCY` -> pino-roll's `frequency`; an unrecognized value warns and falls back rather than throwing, so the app still boots. */
|
|
18
19
|
static mapFrequency(value) {
|
|
19
20
|
const normalized = (value ?? '1h').trim().toLowerCase();
|
|
20
21
|
switch (normalized) {
|
|
21
22
|
case '1h': {
|
|
22
|
-
return
|
|
23
|
+
return common_2.PinoFrequencies.HOURLY;
|
|
23
24
|
}
|
|
24
25
|
case '1d':
|
|
25
26
|
case '24h': {
|
|
26
|
-
return
|
|
27
|
+
return common_2.PinoFrequencies.DAILY;
|
|
27
28
|
}
|
|
28
29
|
default: {
|
|
29
30
|
console.warn('[mapFrequency] Invalid logger file frequency | value: %s | fallback: %s', value, PinoDestination.DEFAULT_FREQUENCY);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../../../src/modules/logger/pino/destination.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA8C;AAC9C,6DAA6D;AAC7D,+DAA2D;AAC3D,0DAA6B;AAC7B,gDAAwB;AACxB,sCAAiE;AAmBjE,2MAA2M;AAC3M,MAAa,eAAe;aACF,sBAAiB,GAAe,QAAQ,CAAC;aACzC,sBAAiB,GAAG,IAAI,CAAC;IAEjD,2JAA2J;IAC3J,MAAM,CAAC,YAAY,CAAC,KAAc;QAChC,MAAM,UAAU,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,WA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CAAC,CAAC;AAAnF,QAAA,YAAY,gBAAuE;AAEzF,MAAM,kBAAkB,GAAG,CAAC,IAA+C,EAAU,EAAE,CAC5F,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAD9B,QAAA,kBAAkB,sBACY;AAEpC,MAAM,sBAAsB,GAAG,GAAqB,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;AAA/E,QAAA,sBAAsB,0BAAyD;AAErF,MAAM,gBAAgB,GAAG,CAAC,IAAsB,EAAsC,EAAE,CAC7F,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AADjB,QAAA,gBAAgB,oBACC","sourcesContent":["import { Defaults } from '@/common/constants';\nimport { blankToUndefined } from '@/utilities/parse.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport path from 'node:path';\nimport pino from 'pino';\nimport { LoggerFormats, resolveLoggerColorize } from '../common';\n\nimport { type TFrequency } from './common';\n\n/** Pure description of where pino should write, derived from env; `PinoDestination.build()` is the impure half that acts on it. */\nexport type TDestinationPlan =\n | { kind: 'stdout' }\n | { kind: 'pretty' }\n | {\n kind: 'roll';\n options: {\n file: string;\n frequency: TFrequency;\n size: string;\n limit: { count: number };\n mkdir: true;\n };\n };\n\n/** Reads `APP_ENV_LOGGER_*` and turns it into a destination. Warning prefixes name the operation, not the class - the tests and the published API still call these `mapFrequency`/`mapMaxFilesToCount`. */\nexport class PinoDestination {\n private static readonly DEFAULT_FREQUENCY: TFrequency = 'hourly';\n private static readonly DEFAULT_MAX_FILES = '5d';\n\n /** `APP_ENV_LOGGER_FILE_FREQUENCY` -> pino-roll's `frequency`; an unrecognized value warns and falls back rather than throwing, so the app still boots. */\n static mapFrequency(value?: string): TFrequency {\n const normalized = (value ?? '1h').trim().toLowerCase();\n\n switch (normalized) {\n case '1h': {\n return 'hourly';\n }\n case '1d':\n case '24h': {\n return 'daily';\n }\n default: {\n console.warn(\n '[mapFrequency] Invalid logger file frequency | value: %s | fallback: %s',\n value,\n PinoDestination.DEFAULT_FREQUENCY,\n );\n return PinoDestination.DEFAULT_FREQUENCY;\n }\n }\n }\n\n /** `null` means \"not a recognized shape\" - the caller decides what default to fall back to. */\n private static parseMaxFilesValue(value: string, frequency: TFrequency): number | null {\n const dayMatch = /^(\\d+)d$/i.exec(value);\n if (dayMatch) {\n const days = Number.parseInt(dayMatch[1], 10);\n return frequency === 'hourly' ? days * 24 : days;\n }\n\n const bareMatch = /^\\d+$/.exec(value);\n if (bareMatch) {\n return Number.parseInt(value, 10);\n }\n\n return null;\n }\n\n /** `APP_ENV_LOGGER_FILE_MAX_FILES` -> pino-roll's `limit.count`: `'<n>d'` scales by frequency (hourly: days*24), a bare integer is a literal count, unrecognized falls back to `'5d'`. */\n static mapMaxFilesToCount(opts: { value?: string; frequency: TFrequency }): number {\n const { value, frequency } = opts;\n const normalized = value?.trim();\n\n if (normalized) {\n const parsed = PinoDestination.parseMaxFilesValue(normalized, frequency);\n if (parsed !== null) {\n return parsed;\n }\n }\n\n // Unset is a normal configuration (mirror the sibling defaults) - only a PROVIDED value that failed to parse deserves a warning.\n if (normalized && normalized !== PinoDestination.DEFAULT_MAX_FILES) {\n console.warn(\n '[mapMaxFilesToCount] Invalid logger file max files value | value: %s | fallback: %s',\n value,\n PinoDestination.DEFAULT_MAX_FILES,\n );\n }\n\n return PinoDestination.parseMaxFilesValue(\n PinoDestination.DEFAULT_MAX_FILES,\n frequency,\n ) as number;\n }\n\n /** Pure: which destination pino should write to, derived from `APP_ENV_LOGGER_*` at CALL time. `DATE_PATTERN` is deliberately not read - pino-roll has no equivalent. */\n static resolvePlan(): TDestinationPlan {\n const folderPath = process.env.APP_ENV_LOGGER_FOLDER_PATH;\n\n if (folderPath && folderPath.trim() !== '') {\n const frequency = PinoDestination.mapFrequency(process.env.APP_ENV_LOGGER_FILE_FREQUENCY);\n const count = PinoDestination.mapMaxFilesToCount({\n value: process.env.APP_ENV_LOGGER_FILE_MAX_FILES,\n frequency,\n });\n\n return {\n kind: 'roll',\n options: {\n file: path.join(folderPath, Defaults.APPLICATION_NAME),\n frequency,\n size: blankToUndefined(process.env.APP_ENV_LOGGER_FILE_MAX_SIZE) ?? '100m',\n limit: { count },\n mkdir: true,\n },\n };\n }\n\n // UNSET means NDJSON to stdout, the locked default for this provider; only an EXPLICIT `text` opts into pino-pretty, and falling back to TEXT here (winston's default) would make the documented minimal install (pino only, no pino-pretty) crash on its first log line.\n if (process.env.APP_ENV_LOGGER_FORMAT === LoggerFormats.TEXT) {\n return { kind: 'pretty' };\n }\n\n return { kind: 'stdout' };\n }\n\n /** `pino.transport()` is SYNCHRONOUS - it returns a `ThreadStream` that BUFFERS writes until its worker thread loads, so no async gating is needed; `ModuleUtility.assertInstalled` runs first so a missing optional peer fails loudly here, not as an opaque worker-thread crash. */\n static build(plan: TDestinationPlan): pino.DestinationStream | undefined {\n switch (plan.kind) {\n case 'stdout': {\n return undefined;\n }\n case 'pretty': {\n ModuleUtility.assertInstalled({ scope: 'PinoLogger', modules: ['pino-pretty'] });\n\n // Only a decision is forwarded. Left alone, pino-pretty's own `isColorSupported` still\n // suppresses color when stdout is not a terminal - a check winston has no equivalent of.\n const colorize = resolveLoggerColorize();\n return pino.transport({\n target: 'pino-pretty',\n ...(colorize === undefined ? {} : { options: { colorize } }),\n });\n }\n case 'roll': {\n ModuleUtility.assertInstalled({ scope: 'PinoLogger', modules: ['pino-roll'] });\n return pino.transport({ target: 'pino-roll', options: plan.options });\n }\n default: {\n return undefined;\n }\n }\n }\n}\n\n// Published names, kept so `@venizia/ignis-helpers/pino` consumers do not have to move; the class\n// above is the implementation and the entry point for new code.\nexport const mapFrequency = (value?: string): TFrequency => PinoDestination.mapFrequency(value);\n\nexport const mapMaxFilesToCount = (opts: { value?: string; frequency: TFrequency }): number =>\n PinoDestination.mapMaxFilesToCount(opts);\n\nexport const resolveDestinationPlan = (): TDestinationPlan => PinoDestination.resolvePlan();\n\nexport const buildDestination = (plan: TDestinationPlan): pino.DestinationStream | undefined =>\n PinoDestination.build(plan);\n"]}
|
|
1
|
+
{"version":3,"file":"destination.js","sourceRoot":"","sources":["../../../../../src/modules/logger/pino/destination.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA8C;AAC9C,6DAA6D;AAC7D,+DAA2D;AAC3D,0DAA6B;AAC7B,gDAAwB;AACxB,sCAAiE;AAEjE,qCAA4D;AAiB5D,2MAA2M;AAC3M,MAAa,eAAe;aACF,sBAAiB,GAAe,wBAAe,CAAC,MAAM,CAAC;aACvD,sBAAiB,GAAG,IAAI,CAAC;IAEjD,2JAA2J;IAC3J,MAAM,CAAC,YAAY,CAAC,KAAc;QAChC,MAAM,UAAU,GAAG,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;QAExD,QAAQ,UAAU,EAAE,CAAC;YACnB,KAAK,IAAI,CAAC,CAAC,CAAC;gBACV,OAAO,wBAAe,CAAC,MAAM,CAAC;YAChC,CAAC;YACD,KAAK,IAAI,CAAC;YACV,KAAK,KAAK,CAAC,CAAC,CAAC;gBACX,OAAO,wBAAe,CAAC,KAAK,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,CAAC,IAAI,CACV,yEAAyE,EACzE,KAAK,EACL,eAAe,CAAC,iBAAiB,CAClC,CAAC;gBACF,OAAO,eAAe,CAAC,iBAAiB,CAAC;YAC3C,CAAC;QACH,CAAC;IACH,CAAC;IAED,+FAA+F;IACvF,MAAM,CAAC,kBAAkB,CAAC,KAAa,EAAE,SAAqB;QACpE,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC9C,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,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ACL,CAAC;YACD,KAAK,MAAM,CAAC,CAAC,CAAC;gBACZ,8BAAa,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;gBAC/E,OAAO,cAAI,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;YACxE,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;;AA9HH,0CA+HC;AAED,kGAAkG;AAClG,gEAAgE;AACzD,MAAM,YAAY,GAAG,CAAC,KAAc,EAAc,EAAE,CAAC,eAAe,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAAnF,QAAA,YAAY,gBAAuE;AAEzF,MAAM,kBAAkB,GAAG,CAAC,IAA+C,EAAU,EAAE,CAC5F,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAD9B,QAAA,kBAAkB,sBACY;AAEpC,MAAM,sBAAsB,GAAG,GAAqB,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;AAA/E,QAAA,sBAAsB,0BAAyD;AAErF,MAAM,gBAAgB,GAAG,CAAC,IAAsB,EAAsC,EAAE,CAC7F,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AADjB,QAAA,gBAAgB,oBACC","sourcesContent":["import { Defaults } from '@/common/constants';\nimport { blankToUndefined } from '@/utilities/parse.utility';\nimport { ModuleUtility } from '@/utilities/module.utility';\nimport path from 'node:path';\nimport pino from 'pino';\nimport { LoggerFormats, resolveLoggerColorize } from '../common';\n\nimport { PinoFrequencies, type TFrequency } from './common';\n\n/** Pure description of where pino should write, derived from env; `PinoDestination.build()` is the impure half that acts on it. */\nexport type TDestinationPlan =\n | { kind: 'stdout' }\n | { kind: 'pretty' }\n | {\n kind: 'roll';\n options: {\n file: string;\n frequency: TFrequency;\n size: string;\n limit: { count: number };\n mkdir: true;\n };\n };\n\n/** Reads `APP_ENV_LOGGER_*` and turns it into a destination. Warning prefixes name the operation, not the class - the tests and the published API still call these `mapFrequency`/`mapMaxFilesToCount`. */\nexport class PinoDestination {\n private static readonly DEFAULT_FREQUENCY: TFrequency = PinoFrequencies.HOURLY;\n private static readonly DEFAULT_MAX_FILES = '5d';\n\n /** `APP_ENV_LOGGER_FILE_FREQUENCY` -> pino-roll's `frequency`; an unrecognized value warns and falls back rather than throwing, so the app still boots. */\n static mapFrequency(value?: string): TFrequency {\n const normalized = (value ?? '1h').trim().toLowerCase();\n\n switch (normalized) {\n case '1h': {\n return PinoFrequencies.HOURLY;\n }\n case '1d':\n case '24h': {\n return PinoFrequencies.DAILY;\n }\n default: {\n console.warn(\n '[mapFrequency] Invalid logger file frequency | value: %s | fallback: %s',\n value,\n PinoDestination.DEFAULT_FREQUENCY,\n );\n return PinoDestination.DEFAULT_FREQUENCY;\n }\n }\n }\n\n /** `null` means \"not a recognized shape\" - the caller decides what default to fall back to. */\n private static parseMaxFilesValue(value: string, frequency: TFrequency): number | null {\n const dayMatch = /^(\\d+)d$/i.exec(value);\n if (dayMatch) {\n const days = Number.parseInt(dayMatch[1], 10);\n return frequency === 'hourly' ? days * 24 : days;\n }\n\n const bareMatch = /^\\d+$/.exec(value);\n if (bareMatch) {\n return Number.parseInt(value, 10);\n }\n\n return null;\n }\n\n /** `APP_ENV_LOGGER_FILE_MAX_FILES` -> pino-roll's `limit.count`: `'<n>d'` scales by frequency (hourly: days*24), a bare integer is a literal count, unrecognized falls back to `'5d'`. */\n static mapMaxFilesToCount(opts: { value?: string; frequency: TFrequency }): number {\n const { value, frequency } = opts;\n const normalized = value?.trim();\n\n if (normalized) {\n const parsed = PinoDestination.parseMaxFilesValue(normalized, frequency);\n if (parsed !== null) {\n return parsed;\n }\n }\n\n // Unset is a normal configuration (mirror the sibling defaults) - only a PROVIDED value that failed to parse deserves a warning.\n if (normalized && normalized !== PinoDestination.DEFAULT_MAX_FILES) {\n console.warn(\n '[mapMaxFilesToCount] Invalid logger file max files value | value: %s | fallback: %s',\n value,\n PinoDestination.DEFAULT_MAX_FILES,\n );\n }\n\n return PinoDestination.parseMaxFilesValue(\n PinoDestination.DEFAULT_MAX_FILES,\n frequency,\n ) as number;\n }\n\n /** Pure: which destination pino should write to, derived from `APP_ENV_LOGGER_*` at CALL time. `DATE_PATTERN` is deliberately not read - pino-roll has no equivalent. */\n static resolvePlan(): TDestinationPlan {\n const folderPath = process.env.APP_ENV_LOGGER_FOLDER_PATH;\n\n if (folderPath && folderPath.trim() !== '') {\n const frequency = PinoDestination.mapFrequency(process.env.APP_ENV_LOGGER_FILE_FREQUENCY);\n const count = PinoDestination.mapMaxFilesToCount({\n value: process.env.APP_ENV_LOGGER_FILE_MAX_FILES,\n frequency,\n });\n\n return {\n kind: 'roll',\n options: {\n file: path.join(folderPath, Defaults.APPLICATION_NAME),\n frequency,\n size: blankToUndefined(process.env.APP_ENV_LOGGER_FILE_MAX_SIZE) ?? '100m',\n limit: { count },\n mkdir: true,\n },\n };\n }\n\n // UNSET means NDJSON to stdout, the locked default for this provider; only an EXPLICIT `text` opts into pino-pretty, and falling back to TEXT here (winston's default) would make the documented minimal install (pino only, no pino-pretty) crash on its first log line.\n if (process.env.APP_ENV_LOGGER_FORMAT === LoggerFormats.TEXT) {\n return { kind: 'pretty' };\n }\n\n return { kind: 'stdout' };\n }\n\n /** `pino.transport()` is SYNCHRONOUS - it returns a `ThreadStream` that BUFFERS writes until its worker thread loads, so no async gating is needed; `ModuleUtility.assertInstalled` runs first so a missing optional peer fails loudly here, not as an opaque worker-thread crash. */\n static build(plan: TDestinationPlan): pino.DestinationStream | undefined {\n switch (plan.kind) {\n case 'stdout': {\n return undefined;\n }\n case 'pretty': {\n ModuleUtility.assertInstalled({ scope: 'PinoLogger', modules: ['pino-pretty'] });\n\n // Only a decision is forwarded. Left alone, pino-pretty's own `isColorSupported` still\n // suppresses color when stdout is not a terminal - a check winston has no equivalent of.\n const colorize = resolveLoggerColorize();\n return pino.transport({\n target: 'pino-pretty',\n ...(colorize === undefined ? {} : { options: { colorize } }),\n });\n }\n case 'roll': {\n ModuleUtility.assertInstalled({ scope: 'PinoLogger', modules: ['pino-roll'] });\n return pino.transport({ target: 'pino-roll', options: plan.options });\n }\n default: {\n return undefined;\n }\n }\n }\n}\n\n// Published names, kept so `@venizia/ignis-helpers/pino` consumers do not have to move; the class\n// above is the implementation and the entry point for new code.\nexport const mapFrequency = (value?: string): TFrequency => PinoDestination.mapFrequency(value);\n\nexport const mapMaxFilesToCount = (opts: { value?: string; frequency: TFrequency }): number =>\n PinoDestination.mapMaxFilesToCount(opts);\n\nexport const resolveDestinationPlan = (): TDestinationPlan => PinoDestination.resolvePlan();\n\nexport const buildDestination = (plan: TDestinationPlan): pino.DestinationStream | undefined =>\n PinoDestination.build(plan);\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TConstValue } from '../../../../common/types';
|
|
2
|
+
/** The HTTP clients a fetcher can be built on. */
|
|
3
|
+
export declare class FetcherVariants {
|
|
4
|
+
static readonly NODE_FETCH = "node-fetch";
|
|
5
|
+
static readonly AXIOS = "axios";
|
|
6
|
+
static readonly SCHEME_SET: Set<string>;
|
|
7
|
+
static isValid(value: string): boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Valid fetcher variant values. */
|
|
10
|
+
export type TFetcherVariant = TConstValue<typeof FetcherVariants>;
|
|
11
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,kDAAkD;AAClD,qBAAa,eAAe;IAC1B,MAAM,CAAC,QAAQ,CAAC,UAAU,gBAAgB;IAC1C,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW;IAEhC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAAkD;IAE5E,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,oCAAoC;AACpC,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FetcherVariants = void 0;
|
|
4
|
+
/** The HTTP clients a fetcher can be built on. */
|
|
5
|
+
class FetcherVariants {
|
|
6
|
+
static { this.NODE_FETCH = 'node-fetch'; }
|
|
7
|
+
static { this.AXIOS = 'axios'; }
|
|
8
|
+
static { this.SCHEME_SET = new Set([this.NODE_FETCH, this.AXIOS]); }
|
|
9
|
+
static isValid(value) {
|
|
10
|
+
return this.SCHEME_SET.has(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.FetcherVariants = FetcherVariants;
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/constants.ts"],"names":[],"mappings":";;;AAEA,kDAAkD;AAClD,MAAa,eAAe;aACV,eAAU,GAAG,YAAY,CAAC;aAC1B,UAAK,GAAG,OAAO,CAAC;aAEhB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAE5E,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AARH,0CASC","sourcesContent":["import type { TConstValue } from '@/common/types';\n\n/** The HTTP clients a fetcher can be built on. */\nexport class FetcherVariants {\n static readonly NODE_FETCH = 'node-fetch';\n static readonly AXIOS = 'axios';\n\n static readonly SCHEME_SET = new Set<string>([this.NODE_FETCH, this.AXIOS]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid fetcher variant values. */\nexport type TFetcherVariant = TConstValue<typeof FetcherVariants>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
17
18
|
__exportStar(require("./types"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB","sourcesContent":["export * from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,0CAAwB","sourcesContent":["export * from './constants';\nexport * from './types';\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/types.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
+
import type { TConstValue } from '../../../common/types';
|
|
1
2
|
import { type ValueOrPromise } from '../../../common/types';
|
|
2
3
|
import { BaseHelper } from '../../base';
|
|
3
4
|
import { type ListenOptions, type ServerOpts, type Socket as SocketClient, type Server as SocketServer } from 'node:net';
|
|
5
|
+
/** Where a TCP client is in the authentication handshake. */
|
|
6
|
+
export declare class TcpClientStates {
|
|
7
|
+
static readonly UNAUTHORIZED = "unauthorized";
|
|
8
|
+
static readonly AUTHENTICATING = "authenticating";
|
|
9
|
+
static readonly AUTHENTICATED = "authenticated";
|
|
10
|
+
static readonly SCHEME_SET: Set<string>;
|
|
11
|
+
static isValid(value: string): boolean;
|
|
12
|
+
}
|
|
13
|
+
/** Valid TCP client state values. */
|
|
14
|
+
export type TTcpClientState = TConstValue<typeof TcpClientStates>;
|
|
4
15
|
export interface ITcpSocketClient<SocketClientType> {
|
|
5
16
|
id: string;
|
|
6
17
|
socket: SocketClientType;
|
|
7
|
-
state:
|
|
18
|
+
state: TTcpClientState;
|
|
8
19
|
subscriptions: Set<string>;
|
|
9
20
|
storage: {
|
|
10
21
|
connectedAt: Date;
|
|
@@ -112,7 +123,7 @@ export declare class BaseNetworkTcpServer<SocketServerOptions extends ServerOpts
|
|
|
112
123
|
shutdown(): Promise<void>;
|
|
113
124
|
doAuthenticate(opts: {
|
|
114
125
|
id: string;
|
|
115
|
-
state:
|
|
126
|
+
state: TTcpClientState;
|
|
116
127
|
}): void;
|
|
117
128
|
emit(opts: {
|
|
118
129
|
clientId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-tcp-server.helper.d.ts","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/base-tcp-server.helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,MAAM,IAAI,YAAY,EAC3B,KAAK,MAAM,IAAI,YAAY,EAC5B,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,gBAAgB,CAAC,gBAAgB;IAChD,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,gBAAgB,CAAC;IACzB,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"base-tcp-server.helper.d.ts","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/base-tcp-server.helper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAI5C,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,MAAM,IAAI,YAAY,EAC3B,KAAK,MAAM,IAAI,YAAY,EAC5B,MAAM,UAAU,CAAC;AAElB,6DAA6D;AAC7D,qBAAa,eAAe;IAC1B,MAAM,CAAC,QAAQ,CAAC,YAAY,kBAAkB;IAC9C,MAAM,CAAC,QAAQ,CAAC,cAAc,oBAAoB;IAClD,MAAM,CAAC,QAAQ,CAAC,aAAa,mBAAmB;IAEhD,MAAM,CA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EAAE,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,gBAAgB,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,KAAK,IAAI,CAAC;IACjG,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,gBAAgB,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,KAAK,IAAI,CAAC;gBAGnF,IAAI,EAAE,uBAAuB,CAAC,mBAAmB,EAAE,gBAAgB,EAAE,gBAAgB,CAAC;IAuCxF,SAAS,CAAC,UAAU,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,IAAI,CAAA;KAAE;IAUnE,SAAS;IAiCT,eAAe,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,gBAAgB,CAAA;KAAE;IAwHlD,UAAU;IAIV,SAAS,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE;IAI9B,SAAS;IAIT,0LAA0L;IACpL,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC/B,cAAc,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,eAAe,CAAA;KAAE;IAgC3D,IAAI,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;CA4B1D"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseNetworkTcpServer = void 0;
|
|
3
|
+
exports.BaseNetworkTcpServer = exports.TcpClientStates = void 0;
|
|
4
4
|
const base_1 = require("../../base");
|
|
5
5
|
const error_1 = require("../../error");
|
|
6
6
|
const parse_utility_1 = require("../../../utilities/parse.utility");
|
|
7
7
|
const promise_utility_1 = require("../../../utilities/promise.utility");
|
|
8
|
+
/** Where a TCP client is in the authentication handshake. */
|
|
9
|
+
class TcpClientStates {
|
|
10
|
+
static { this.UNAUTHORIZED = 'unauthorized'; }
|
|
11
|
+
static { this.AUTHENTICATING = 'authenticating'; }
|
|
12
|
+
static { this.AUTHENTICATED = 'authenticated'; }
|
|
13
|
+
static { this.SCHEME_SET = new Set([
|
|
14
|
+
this.UNAUTHORIZED,
|
|
15
|
+
this.AUTHENTICATING,
|
|
16
|
+
this.AUTHENTICATED,
|
|
17
|
+
]); }
|
|
18
|
+
static isValid(value) {
|
|
19
|
+
return this.SCHEME_SET.has(value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.TcpClientStates = TcpClientStates;
|
|
8
23
|
class BaseNetworkTcpServer extends base_1.BaseHelper {
|
|
9
24
|
constructor(opts) {
|
|
10
25
|
super({
|
|
@@ -13,7 +28,8 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
|
|
|
13
28
|
});
|
|
14
29
|
this.serverOptions = {};
|
|
15
30
|
this.listenOptions = {};
|
|
16
|
-
|
|
31
|
+
// No prototype: `getClient({ id: 'constructor' })` must find nothing, not `Object`.
|
|
32
|
+
this.clients = Object.create(null);
|
|
17
33
|
this.serverOptions = opts.serverOptions;
|
|
18
34
|
this.listenOptions = opts.listenOptions;
|
|
19
35
|
this.authenticateOptions = opts.authenticateOptions;
|
|
@@ -123,7 +139,9 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
|
|
|
123
139
|
this.clients[id] = {
|
|
124
140
|
id,
|
|
125
141
|
socket,
|
|
126
|
-
state: this.authenticateOptions.required
|
|
142
|
+
state: this.authenticateOptions.required
|
|
143
|
+
? TcpClientStates.UNAUTHORIZED
|
|
144
|
+
: TcpClientStates.AUTHENTICATED,
|
|
127
145
|
subscriptions: new Set([]),
|
|
128
146
|
storage: {
|
|
129
147
|
connectedAt: new Date(),
|
|
@@ -148,7 +166,7 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
|
|
|
148
166
|
return;
|
|
149
167
|
}
|
|
150
168
|
client.storage.authenticateTimeout = null;
|
|
151
|
-
if (client.state ===
|
|
169
|
+
if (client.state === TcpClientStates.AUTHENTICATED) {
|
|
152
170
|
return;
|
|
153
171
|
}
|
|
154
172
|
this.emit({ clientId: id, payload: 'Unauthorized Client' });
|
|
@@ -182,7 +200,7 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
|
|
|
182
200
|
}
|
|
183
201
|
client.socket.destroy();
|
|
184
202
|
}
|
|
185
|
-
this.clients =
|
|
203
|
+
this.clients = Object.create(null);
|
|
186
204
|
const server = this.server;
|
|
187
205
|
if (!server) {
|
|
188
206
|
return;
|
|
@@ -207,12 +225,12 @@ class BaseNetworkTcpServer extends base_1.BaseHelper {
|
|
|
207
225
|
}
|
|
208
226
|
client.state = state;
|
|
209
227
|
switch (state) {
|
|
210
|
-
case
|
|
211
|
-
case
|
|
228
|
+
case TcpClientStates.UNAUTHORIZED:
|
|
229
|
+
case TcpClientStates.AUTHENTICATING: {
|
|
212
230
|
client.storage.authenticatedAt = null;
|
|
213
231
|
break;
|
|
214
232
|
}
|
|
215
|
-
case
|
|
233
|
+
case TcpClientStates.AUTHENTICATED: {
|
|
216
234
|
client.storage.authenticatedAt = new Date();
|
|
217
235
|
if (client.storage.authenticateTimeout) {
|
|
218
236
|
clearTimeout(client.storage.authenticateTimeout);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-tcp-server.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/base-tcp-server.helper.ts"],"names":[],"mappings":";;;AACA,yCAA4C;AAC5C,2CAA2C;AAC3C,6DAAmD;AACnD,iEAA4D;AAmD5D,MAAa,oBAIX,SAAQ,iBAAU;IA6BlB,YACE,IAAsF;QAEtF,KAAK,CAAC;YACJ,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,IAAI,oBAAoB,CAAC,IAAI;YACjE,UAAU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ACR,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,CAAC,IAAoD;QACvD,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEhD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,2BAA2B,EAAE,QAAQ,CAAC,CAAC;YAC7E,OAAO;QACT,CAAC;QAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QAC1B,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YACrB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,8BAA8B,EAAE,QAAQ,CAAC,CAAC;YAChF,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC;YACrB,IAAI,CAAC,MAAM;iBACR,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;iBACnB,IAAI,CACH,0DAA0D,EAC1D,IAAI,CAAC,UAAU,EACf,QAAQ,CACT,CAAC;YACJ,OAAO;QACT,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;CACF;AApVD,oDAoVC","sourcesContent":["import { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { getUID } from '@/utilities/parse.utility';\nimport { voidExecution } from '@/utilities/promise.utility';\nimport {\n type ListenOptions,\n type ServerOpts,\n type Socket as SocketClient,\n type Server as SocketServer,\n} from 'node:net';\n\nexport interface ITcpSocketClient<SocketClientType> {\n id: string;\n socket: SocketClientType;\n state: 'unauthorized' | 'authenticating' | 'authenticated';\n subscriptions: Set<string>;\n storage: {\n connectedAt: Date;\n authenticatedAt: Date | null;\n authenticateTimeout?: ReturnType<typeof setTimeout> | null;\n [additionField: symbol | string]: any;\n };\n}\n\nexport interface ITcpSocketServerOptions<\n SocketServerOptions extends ServerOpts = ServerOpts,\n SocketServerType extends SocketServer = SocketServer,\n SocketClientType extends SocketClient = SocketClient,\n> {\n scope?: string;\n identifier: string;\n\n serverOptions: Partial<SocketServerOptions>;\n listenOptions: Partial<ListenOptions>;\n authenticateOptions: { required: boolean; duration?: number };\n\n extraEvents?: Record<\n string,\n (opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>\n >;\n\n createServerFn: (\n options: Partial<SocketServerOptions>,\n connectionListener: (socket: SocketClientType) => void,\n ) => SocketServerType;\n\n onServerReady?: (opts: { server: SocketServerType }) => void;\n onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;\n onClientData?: (opts: { id: string; socket: SocketClientType; data: Buffer | string }) => void;\n onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;\n onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;\n onServerError?: (opts: { server: SocketServerType; error: Error }) => void;\n}\n\nexport class BaseNetworkTcpServer<\n SocketServerOptions extends ServerOpts = ServerOpts,\n SocketServerType extends SocketServer = SocketServer,\n SocketClientType extends SocketClient = SocketClient,\n> extends BaseHelper {\n protected serverOptions: Partial<SocketServerOptions> = {};\n protected listenOptions: Partial<ListenOptions> = {};\n protected authenticateOptions: { required: boolean; duration?: number };\n\n protected clients: Record<string, ITcpSocketClient<SocketClientType>>;\n protected server: SocketServerType;\n\n protected extraEvents: Record<\n string,\n (opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>\n >;\n\n protected createServerFn: (\n options: Partial<SocketServerOptions>,\n connectionListener: (socket: SocketClientType) => void,\n ) => SocketServerType;\n\n protected onServerReady?: (opts: { server: SocketServerType }) => void;\n protected onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;\n protected onClientData?: (opts: {\n id: string;\n socket: SocketClientType;\n data: Buffer | string;\n }) => void;\n protected onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;\n protected onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;\n protected onServerError?: (opts: { server: SocketServerType; error: Error }) => void;\n\n constructor(\n opts: ITcpSocketServerOptions<SocketServerOptions, SocketServerType, SocketClientType>,\n ) {\n super({\n scope: opts.scope ?? opts.identifier ?? BaseNetworkTcpServer.name,\n identifier: opts.identifier,\n });\n\n this.clients = Object.assign({});\n\n this.serverOptions = opts.serverOptions;\n this.listenOptions = opts.listenOptions;\n this.authenticateOptions = opts.authenticateOptions;\n\n if (\n this.authenticateOptions.required &&\n (!this.authenticateOptions.duration || this.authenticateOptions.duration < 0)\n ) {\n throw getError({\n message:\n 'TCP Server | Invalid authenticate duration | Required duration for authenticateOptions',\n });\n }\n\n this.extraEvents = opts.extraEvents ?? {};\n\n this.createServerFn = opts.createServerFn;\n\n this.onServerReady = opts.onServerReady;\n this.onClientConnected = opts.onClientConnected;\n this.onClientData = opts.onClientData;\n this.onClientClose = opts.onClientClose;\n this.onClientError = opts.onClientError;\n this.onServerError = opts.onServerError;\n\n this.configure();\n }\n\n // Hooks run inside socket event listeners: a synchronous throw there is an uncaught exception that kills the process and skips the client-registry cleanup that follows it.\n protected invokeHook(opts: { scope: string; execution: () => void }) {\n const { scope, execution } = opts;\n\n try {\n execution();\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n configure() {\n this.server = this.createServerFn(this.serverOptions, (socket) => {\n this.onNewConnection({ socket });\n });\n\n // Without this listener a failed listen - a port already in use is the commonest boot failure there is - emits an unhandled 'error' event, which takes the whole process down with it.\n this.server.on('error', (error: Error) => {\n this.logger\n .for(this.configure.name)\n .error('TCP Socket Server error | Options: %j | Error: %s', this.listenOptions, error);\n\n this.invokeHook({\n scope: this.configure.name,\n execution: () => {\n this.onServerError?.({ server: this.server, error });\n },\n });\n });\n\n this.server.listen(this.listenOptions, () => {\n this.logger\n .for(this.configure.name)\n .info('TCP Socket Server is now listening | Options: %j', this.listenOptions);\n\n this.invokeHook({\n scope: this.configure.name,\n execution: () => {\n this.onServerReady?.({ server: this.server });\n },\n });\n });\n }\n\n onNewConnection(opts: { socket: SocketClientType }) {\n const { socket } = opts;\n\n const id = getUID();\n\n socket.on('data', (data: Buffer | string) => {\n this.invokeHook({\n scope: 'onClientData',\n execution: () => {\n this.onClientData?.({ id, socket, data });\n },\n });\n });\n\n socket.on('error', (error: Error) => {\n this.logger.for('onClientConnect').error('Socket Error | ID: %s | Error: %s', id, error);\n\n this.invokeHook({\n scope: 'onClientError',\n execution: () => {\n this.onClientError?.({ id, socket, error });\n },\n });\n\n socket.end();\n });\n\n socket.on('close', (hasError: boolean) => {\n this.logger\n .for('onClientConnect')\n .info('Socket Closed | ID: %s | hasError: %s', id, hasError);\n\n this.invokeHook({\n scope: 'onClientClose',\n execution: () => {\n this.onClientClose?.({ id, socket });\n },\n });\n\n const authenticateTimeout = this.getClient({ id })?.storage?.authenticateTimeout;\n if (authenticateTimeout) {\n clearTimeout(authenticateTimeout);\n }\n\n // `delete`, not `omit`: omit rebuilds the WHOLE registry per disconnect, so a disconnect\n // storm is O(n^2) - measured at 5000 clients, 2.3s of drain with a 2.2s worst-case stall.\n delete this.clients[id];\n });\n\n for (const extraEvent in this.extraEvents) {\n socket.on(extraEvent, (args) => {\n voidExecution({\n logger: this.logger,\n scope: 'onClientConnect',\n // The async wrapper turns a SYNCHRONOUS throw from the handler into a rejection; calling it bare would throw out of this listener as an uncaught exception.\n execution: (async () => this.extraEvents[extraEvent]({ id, socket, args }))(),\n });\n });\n }\n\n this.clients[id] = {\n id,\n socket,\n state: this.authenticateOptions.required ? 'unauthorized' : 'authenticated',\n subscriptions: new Set([]),\n storage: {\n connectedAt: new Date(),\n authenticatedAt: this.authenticateOptions.required ? null : new Date(),\n },\n };\n\n this.logger\n .for('onClientConnect')\n .info(\n 'New TCP SocketClient | Client: %s | authenticateOptions: %s %s',\n `${id} - ${socket.remoteAddress} - ${socket.remotePort} - ${socket.remoteFamily}`,\n this.authenticateOptions.required,\n this.authenticateOptions.duration,\n );\n\n this.invokeHook({\n scope: 'onClientConnected',\n execution: () => {\n this.onClientConnected?.({ id, socket });\n },\n });\n\n if (\n this.authenticateOptions.required &&\n this.authenticateOptions.duration &&\n this.authenticateOptions.duration > 0\n ) {\n const authenticateTimeout = setTimeout(() => {\n const client = this.getClient({ id });\n if (!client) {\n return;\n }\n\n client.storage.authenticateTimeout = null;\n\n if (client.state === 'authenticated') {\n return;\n }\n\n this.emit({ clientId: id, payload: 'Unauthorized Client' });\n client.socket.end();\n }, this.authenticateOptions.duration);\n\n const client = this.getClient({ id });\n if (!client) {\n clearTimeout(authenticateTimeout);\n return;\n }\n\n client.storage.authenticateTimeout = authenticateTimeout;\n }\n }\n\n getClients() {\n return this.clients;\n }\n\n getClient(opts: { id: string }) {\n return this.clients?.[opts.id];\n }\n\n getServer() {\n return this.server;\n }\n\n /** Clears timers and destroys all client sockets before closing the listener - `server.close()` alone never settles while a socket stays attached. Idempotent; safe if never listened. */\n async shutdown(): Promise<void> {\n const clientsValues = Object.values(this.clients);\n for (const client of clientsValues) {\n const { authenticateTimeout } = client.storage;\n if (authenticateTimeout) {\n clearTimeout(authenticateTimeout);\n client.storage.authenticateTimeout = null;\n }\n\n client.socket.destroy();\n }\n\n this.clients = {};\n\n const server = this.server;\n if (!server) {\n return;\n }\n\n // Not guarded on `listening`: listen() is async (DNS lookup), so a shutdown() racing startup could skip close() and leave the server bound forever; close() on a never-listened server just logs ERR_SERVER_NOT_RUNNING below.\n\n await new Promise<void>((resolve) => {\n server.close((error) => {\n if (error) {\n this.logger.for(this.shutdown.name).error('Failed to close server | Error: %s', error);\n }\n\n resolve();\n });\n });\n\n this.logger.for(this.shutdown.name).info('Server closed | Identifier: %s', this.identifier);\n }\n\n doAuthenticate(opts: { id: string; state: 'unauthorized' | 'authenticating' | 'authenticated' }) {\n const { id, state } = opts;\n\n const client = this.getClient({ id });\n if (!client) {\n this.logger.for('authenticateClient').error('Client NOT FOUND | ID: %s', id);\n return;\n }\n\n client.state = state;\n\n switch (state) {\n case 'unauthorized':\n case 'authenticating': {\n client.storage.authenticatedAt = null;\n break;\n }\n case 'authenticated': {\n client.storage.authenticatedAt = new Date();\n\n if (client.storage.authenticateTimeout) {\n clearTimeout(client.storage.authenticateTimeout);\n client.storage.authenticateTimeout = null;\n }\n break;\n }\n default: {\n break;\n }\n }\n }\n\n emit(opts: { clientId: string; payload: Buffer | string }) {\n const { clientId, payload } = opts;\n const client = this.getClient({ id: clientId });\n\n if (!client) {\n this.logger.for(this.emit.name).error('Client NOT FOUND | ID: %s', clientId);\n return;\n }\n\n const { socket } = client;\n if (!socket.writable) {\n this.logger.for(this.emit.name).error('Client NOT WRITABLE | ID: %s', clientId);\n return;\n }\n\n if (!payload?.length) {\n this.logger\n .for(this.emit.name)\n .info(\n '[%s] Client %s | Invalid payload to write to TCP Socket!',\n this.identifier,\n clientId,\n );\n return;\n }\n\n socket.write(payload);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base-tcp-server.helper.js","sourceRoot":"","sources":["../../../../../src/modules/network/tcp-socket/base-tcp-server.helper.ts"],"names":[],"mappings":";;;AAEA,yCAA4C;AAC5C,2CAA2C;AAC3C,6DAAmD;AACnD,iEAA4D;AAQ5D,6DAA6D;AAC7D,MAAa,eAAe;aACV,iBAAY,GAAG,cAAc,CAAC;aAC9B,mBAAc,GAAG,gBAAgB,CAAC;aAClC,kBAAa,GAAG,eAAe,CAAC;aAEhC,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,YAAY;QACjB,IAAI,CAAC,cAAc;QACnB,IAAI,CAAC,aAAa;KACnB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1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AC1D,IAAI,CAAC,UAAU,EACf,QAAQ,CACT,CAAC;YACJ,OAAO;QACT,CAAC;QAED,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;CACF;AAvVD,oDAuVC","sourcesContent":["import type { TConstValue } from '@/common/types';\nimport { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { getUID } from '@/utilities/parse.utility';\nimport { voidExecution } from '@/utilities/promise.utility';\nimport {\n type ListenOptions,\n type ServerOpts,\n type Socket as SocketClient,\n type Server as SocketServer,\n} from 'node:net';\n\n/** Where a TCP client is in the authentication handshake. */\nexport class TcpClientStates {\n static readonly UNAUTHORIZED = 'unauthorized';\n static readonly AUTHENTICATING = 'authenticating';\n static readonly AUTHENTICATED = 'authenticated';\n\n static readonly SCHEME_SET = new Set<string>([\n this.UNAUTHORIZED,\n this.AUTHENTICATING,\n this.AUTHENTICATED,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid TCP client state values. */\nexport type TTcpClientState = TConstValue<typeof TcpClientStates>;\n\nexport interface ITcpSocketClient<SocketClientType> {\n id: string;\n socket: SocketClientType;\n state: TTcpClientState;\n subscriptions: Set<string>;\n storage: {\n connectedAt: Date;\n authenticatedAt: Date | null;\n authenticateTimeout?: ReturnType<typeof setTimeout> | null;\n [additionField: symbol | string]: any;\n };\n}\n\nexport interface ITcpSocketServerOptions<\n SocketServerOptions extends ServerOpts = ServerOpts,\n SocketServerType extends SocketServer = SocketServer,\n SocketClientType extends SocketClient = SocketClient,\n> {\n scope?: string;\n identifier: string;\n\n serverOptions: Partial<SocketServerOptions>;\n listenOptions: Partial<ListenOptions>;\n authenticateOptions: { required: boolean; duration?: number };\n\n extraEvents?: Record<\n string,\n (opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>\n >;\n\n createServerFn: (\n options: Partial<SocketServerOptions>,\n connectionListener: (socket: SocketClientType) => void,\n ) => SocketServerType;\n\n onServerReady?: (opts: { server: SocketServerType }) => void;\n onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;\n onClientData?: (opts: { id: string; socket: SocketClientType; data: Buffer | string }) => void;\n onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;\n onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;\n onServerError?: (opts: { server: SocketServerType; error: Error }) => void;\n}\n\nexport class BaseNetworkTcpServer<\n SocketServerOptions extends ServerOpts = ServerOpts,\n SocketServerType extends SocketServer = SocketServer,\n SocketClientType extends SocketClient = SocketClient,\n> extends BaseHelper {\n protected serverOptions: Partial<SocketServerOptions> = {};\n protected listenOptions: Partial<ListenOptions> = {};\n protected authenticateOptions: { required: boolean; duration?: number };\n\n protected clients: Record<string, ITcpSocketClient<SocketClientType>>;\n protected server: SocketServerType;\n\n protected extraEvents: Record<\n string,\n (opts: { id: string; socket: SocketClientType; args: any }) => ValueOrPromise<void>\n >;\n\n protected createServerFn: (\n options: Partial<SocketServerOptions>,\n connectionListener: (socket: SocketClientType) => void,\n ) => SocketServerType;\n\n protected onServerReady?: (opts: { server: SocketServerType }) => void;\n protected onClientConnected?: (opts: { id: string; socket: SocketClientType }) => void;\n protected onClientData?: (opts: {\n id: string;\n socket: SocketClientType;\n data: Buffer | string;\n }) => void;\n protected onClientClose?: (opts: { id: string; socket: SocketClientType }) => void;\n protected onClientError?: (opts: { id: string; socket: SocketClientType; error: Error }) => void;\n protected onServerError?: (opts: { server: SocketServerType; error: Error }) => void;\n\n constructor(\n opts: ITcpSocketServerOptions<SocketServerOptions, SocketServerType, SocketClientType>,\n ) {\n super({\n scope: opts.scope ?? opts.identifier ?? BaseNetworkTcpServer.name,\n identifier: opts.identifier,\n });\n\n // No prototype: `getClient({ id: 'constructor' })` must find nothing, not `Object`.\n this.clients = Object.create(null);\n\n this.serverOptions = opts.serverOptions;\n this.listenOptions = opts.listenOptions;\n this.authenticateOptions = opts.authenticateOptions;\n\n if (\n this.authenticateOptions.required &&\n (!this.authenticateOptions.duration || this.authenticateOptions.duration < 0)\n ) {\n throw getError({\n message:\n 'TCP Server | Invalid authenticate duration | Required duration for authenticateOptions',\n });\n }\n\n this.extraEvents = opts.extraEvents ?? {};\n\n this.createServerFn = opts.createServerFn;\n\n this.onServerReady = opts.onServerReady;\n this.onClientConnected = opts.onClientConnected;\n this.onClientData = opts.onClientData;\n this.onClientClose = opts.onClientClose;\n this.onClientError = opts.onClientError;\n this.onServerError = opts.onServerError;\n\n this.configure();\n }\n\n // Hooks run inside socket event listeners: a synchronous throw there is an uncaught exception that kills the process and skips the client-registry cleanup that follows it.\n protected invokeHook(opts: { scope: string; execution: () => void }) {\n const { scope, execution } = opts;\n\n try {\n execution();\n } catch (error) {\n this.logger.for(scope).error('Hook execution FAILED | Error: %s', error);\n }\n }\n\n configure() {\n this.server = this.createServerFn(this.serverOptions, (socket) => {\n this.onNewConnection({ socket });\n });\n\n // Without this listener a failed listen - a port already in use is the commonest boot failure there is - emits an unhandled 'error' event, which takes the whole process down with it.\n this.server.on('error', (error: Error) => {\n this.logger\n .for(this.configure.name)\n .error('TCP Socket Server error | Options: %j | Error: %s', this.listenOptions, error);\n\n this.invokeHook({\n scope: this.configure.name,\n execution: () => {\n this.onServerError?.({ server: this.server, error });\n },\n });\n });\n\n this.server.listen(this.listenOptions, () => {\n this.logger\n .for(this.configure.name)\n .info('TCP Socket Server is now listening | Options: %j', this.listenOptions);\n\n this.invokeHook({\n scope: this.configure.name,\n execution: () => {\n this.onServerReady?.({ server: this.server });\n },\n });\n });\n }\n\n onNewConnection(opts: { socket: SocketClientType }) {\n const { socket } = opts;\n\n const id = getUID();\n\n socket.on('data', (data: Buffer | string) => {\n this.invokeHook({\n scope: 'onClientData',\n execution: () => {\n this.onClientData?.({ id, socket, data });\n },\n });\n });\n\n socket.on('error', (error: Error) => {\n this.logger.for('onClientConnect').error('Socket Error | ID: %s | Error: %s', id, error);\n\n this.invokeHook({\n scope: 'onClientError',\n execution: () => {\n this.onClientError?.({ id, socket, error });\n },\n });\n\n socket.end();\n });\n\n socket.on('close', (hasError: boolean) => {\n this.logger\n .for('onClientConnect')\n .info('Socket Closed | ID: %s | hasError: %s', id, hasError);\n\n this.invokeHook({\n scope: 'onClientClose',\n execution: () => {\n this.onClientClose?.({ id, socket });\n },\n });\n\n const authenticateTimeout = this.getClient({ id })?.storage?.authenticateTimeout;\n if (authenticateTimeout) {\n clearTimeout(authenticateTimeout);\n }\n\n // `delete`, not `omit`: omit rebuilds the WHOLE registry per disconnect, so a disconnect\n // storm is O(n^2) - measured at 5000 clients, 2.3s of drain with a 2.2s worst-case stall.\n delete this.clients[id];\n });\n\n for (const extraEvent in this.extraEvents) {\n socket.on(extraEvent, (args) => {\n voidExecution({\n logger: this.logger,\n scope: 'onClientConnect',\n // The async wrapper turns a SYNCHRONOUS throw from the handler into a rejection; calling it bare would throw out of this listener as an uncaught exception.\n execution: (async () => this.extraEvents[extraEvent]({ id, socket, args }))(),\n });\n });\n }\n\n this.clients[id] = {\n id,\n socket,\n state: this.authenticateOptions.required\n ? TcpClientStates.UNAUTHORIZED\n : TcpClientStates.AUTHENTICATED,\n subscriptions: new Set([]),\n storage: {\n connectedAt: new Date(),\n authenticatedAt: this.authenticateOptions.required ? null : new Date(),\n },\n };\n\n this.logger\n .for('onClientConnect')\n .info(\n 'New TCP SocketClient | Client: %s | authenticateOptions: %s %s',\n `${id} - ${socket.remoteAddress} - ${socket.remotePort} - ${socket.remoteFamily}`,\n this.authenticateOptions.required,\n this.authenticateOptions.duration,\n );\n\n this.invokeHook({\n scope: 'onClientConnected',\n execution: () => {\n this.onClientConnected?.({ id, socket });\n },\n });\n\n if (\n this.authenticateOptions.required &&\n this.authenticateOptions.duration &&\n this.authenticateOptions.duration > 0\n ) {\n const authenticateTimeout = setTimeout(() => {\n const client = this.getClient({ id });\n if (!client) {\n return;\n }\n\n client.storage.authenticateTimeout = null;\n\n if (client.state === TcpClientStates.AUTHENTICATED) {\n return;\n }\n\n this.emit({ clientId: id, payload: 'Unauthorized Client' });\n client.socket.end();\n }, this.authenticateOptions.duration);\n\n const client = this.getClient({ id });\n if (!client) {\n clearTimeout(authenticateTimeout);\n return;\n }\n\n client.storage.authenticateTimeout = authenticateTimeout;\n }\n }\n\n getClients() {\n return this.clients;\n }\n\n getClient(opts: { id: string }) {\n return this.clients?.[opts.id];\n }\n\n getServer() {\n return this.server;\n }\n\n /** Clears timers and destroys all client sockets before closing the listener - `server.close()` alone never settles while a socket stays attached. Idempotent; safe if never listened. */\n async shutdown(): Promise<void> {\n const clientsValues = Object.values(this.clients);\n for (const client of clientsValues) {\n const { authenticateTimeout } = client.storage;\n if (authenticateTimeout) {\n clearTimeout(authenticateTimeout);\n client.storage.authenticateTimeout = null;\n }\n\n client.socket.destroy();\n }\n\n this.clients = Object.create(null);\n\n const server = this.server;\n if (!server) {\n return;\n }\n\n // Not guarded on `listening`: listen() is async (DNS lookup), so a shutdown() racing startup could skip close() and leave the server bound forever; close() on a never-listened server just logs ERR_SERVER_NOT_RUNNING below.\n\n await new Promise<void>((resolve) => {\n server.close((error) => {\n if (error) {\n this.logger.for(this.shutdown.name).error('Failed to close server | Error: %s', error);\n }\n\n resolve();\n });\n });\n\n this.logger.for(this.shutdown.name).info('Server closed | Identifier: %s', this.identifier);\n }\n\n doAuthenticate(opts: { id: string; state: TTcpClientState }) {\n const { id, state } = opts;\n\n const client = this.getClient({ id });\n if (!client) {\n this.logger.for('authenticateClient').error('Client NOT FOUND | ID: %s', id);\n return;\n }\n\n client.state = state;\n\n switch (state) {\n case TcpClientStates.UNAUTHORIZED:\n case TcpClientStates.AUTHENTICATING: {\n client.storage.authenticatedAt = null;\n break;\n }\n case TcpClientStates.AUTHENTICATED: {\n client.storage.authenticatedAt = new Date();\n\n if (client.storage.authenticateTimeout) {\n clearTimeout(client.storage.authenticateTimeout);\n client.storage.authenticateTimeout = null;\n }\n break;\n }\n default: {\n break;\n }\n }\n }\n\n emit(opts: { clientId: string; payload: Buffer | string }) {\n const { clientId, payload } = opts;\n const client = this.getClient({ id: clientId });\n\n if (!client) {\n this.logger.for(this.emit.name).error('Client NOT FOUND | ID: %s', clientId);\n return;\n }\n\n const { socket } = client;\n if (!socket.writable) {\n this.logger.for(this.emit.name).error('Client NOT WRITABLE | ID: %s', clientId);\n return;\n }\n\n if (!payload?.length) {\n this.logger\n .for(this.emit.name)\n .info(\n '[%s] Client %s | Invalid payload to write to TCP Socket!',\n this.identifier,\n clientId,\n );\n return;\n }\n\n socket.write(payload);\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TConstValue } from '../../../common/types';
|
|
2
|
+
/** What a BullMQ helper is: the QUEUE that jobs are added to, or the WORKER that runs them. */
|
|
3
|
+
export declare class BullQueueRoles {
|
|
4
|
+
static readonly QUEUE = "queue";
|
|
5
|
+
static readonly WORKER = "worker";
|
|
6
|
+
static readonly SCHEME_SET: Set<string>;
|
|
7
|
+
static isValid(value: string): boolean;
|
|
8
|
+
}
|
|
9
|
+
/** Valid BullMQ queue role values. */
|
|
10
|
+
export type TBullQueueRole = TConstValue<typeof BullQueueRoles>;
|
|
11
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,+FAA+F;AAC/F,qBAAa,cAAc;IACzB,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW;IAChC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAElC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAA8C;IAExE,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGvC;AAED,sCAAsC;AACtC,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BullQueueRoles = void 0;
|
|
4
|
+
/** What a BullMQ helper is: the QUEUE that jobs are added to, or the WORKER that runs them. */
|
|
5
|
+
class BullQueueRoles {
|
|
6
|
+
static { this.QUEUE = 'queue'; }
|
|
7
|
+
static { this.WORKER = 'worker'; }
|
|
8
|
+
static { this.SCHEME_SET = new Set([this.QUEUE, this.WORKER]); }
|
|
9
|
+
static isValid(value) {
|
|
10
|
+
return this.SCHEME_SET.has(value);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.BullQueueRoles = BullQueueRoles;
|
|
14
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/constants.ts"],"names":[],"mappings":";;;AAEA,+FAA+F;AAC/F,MAAa,cAAc;aACT,UAAK,GAAG,OAAO,CAAC;aAChB,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAExE,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AARH,wCASC","sourcesContent":["import type { TConstValue } from '@/common/types';\n\n/** What a BullMQ helper is: the QUEUE that jobs are added to, or the WORKER that runs them. */\nexport class BullQueueRoles {\n static readonly QUEUE = 'queue';\n static readonly WORKER = 'worker';\n\n static readonly SCHEME_SET = new Set<string>([this.QUEUE, this.WORKER]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n\n/** Valid BullMQ queue role values. */\nexport type TBullQueueRole = TConstValue<typeof BullQueueRoles>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
17
18
|
__exportStar(require("./hook"), exports);
|
|
18
19
|
__exportStar(require("./types"), exports);
|
|
19
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB","sourcesContent":["export * from './hook';\nexport * from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,yCAAuB;AACvB,0CAAwB","sourcesContent":["export * from './constants';\nexport * from './hook';\nexport * from './types';\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/modules/queue/common/types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/types.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|