@venizia/ignis-helpers 0.4.2 → 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/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/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/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 +23 -6
- 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/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/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/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/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/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 +21 -5
- 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/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/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,5 +1,5 @@
|
|
|
1
1
|
/** Error layer lives in `@venizia/ignis-inversion` so browser apps (DI-only, no helpers) share the same class; re-exported by NAME, not `export *`, to keep inversion's DI container off the helpers surface. */
|
|
2
2
|
/** Augment `IErrorKeyRegistry` via whichever module the file imports - see `registry-augmentation.test.ts`. */
|
|
3
|
-
export { ApplicationError, ErrorScopes, fromError, getError, isApplicationError, MessageCode, MessageTemplate, } from '@venizia/ignis-inversion';
|
|
3
|
+
export { ApplicationError, ErrorLogLevels, ErrorScopes, fromError, getError, isApplicationError, MessageCode, MessageTemplate, } from '@venizia/ignis-inversion';
|
|
4
4
|
export type { IErrorKeyRegistry, TError, TErrorByDefinition, TErrorByField, TErrorDefinition, TErrorDefinitionMessage, TErrorKey, TErrorLogLevel, TErrorMessage, TErrorMessageInput, TErrorMessageOverride, TErrorNormalized, TErrorNormalizeTransformFn, TErrorScope, TRegisterErrors, TResponsedError, } from '@venizia/ignis-inversion';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/error/index.ts"],"names":[],"mappings":"AAAA,iNAAiN;AACjN,+GAA+G;AAC/G,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,QAAQ,EACR,kBAAkB,EAClB,WAAW,EACX,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAElC,YAAY,EACV,iBAAiB,EACjB,MAAM,EACN,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,uBAAuB,EACvB,SAAS,EACT,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,0BAA0B,EAC1B,WAAW,EACX,eAAe,EACf,eAAe,GAChB,MAAM,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/error/index.ts"],"names":[],"mappings":"AAAA,iNAAiN;AACjN,+GAA+G;AAC/G,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,SAAS,EACT,QAAQ,EACR,kBAAkB,EAClB,WAAW,EACX,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAElC,YAAY,EACV,iBAAiB,EACjB,MAAM,EACN,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,uBAAuB,EACvB,SAAS,EACT,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,0BAA0B,EAC1B,WAAW,EACX,eAAe,EACf,eAAe,GAChB,MAAM,0BAA0B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Error layer lives in `@venizia/ignis-inversion` so browser apps (DI-only, no helpers) share the same class; re-exported by NAME, not `export *`, to keep inversion's DI container off the helpers surface. */
|
|
2
2
|
/** Augment `IErrorKeyRegistry` via whichever module the file imports - see `registry-augmentation.test.ts`. */
|
|
3
|
-
export { ApplicationError, ErrorScopes, fromError, getError, isApplicationError, MessageCode, MessageTemplate, } from '@venizia/ignis-inversion';
|
|
3
|
+
export { ApplicationError, ErrorLogLevels, ErrorScopes, fromError, getError, isApplicationError, MessageCode, MessageTemplate, } from '@venizia/ignis-inversion';
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/error/index.ts"],"names":[],"mappings":"AAAA,iNAAiN;AACjN,+GAA+G;AAC/G,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,QAAQ,EACR,kBAAkB,EAClB,WAAW,EACX,eAAe,GAChB,MAAM,0BAA0B,CAAC","sourcesContent":["/** Error layer lives in `@venizia/ignis-inversion` so browser apps (DI-only, no helpers) share the same class; re-exported by NAME, not `export *`, to keep inversion's DI container off the helpers surface. */\n/** Augment `IErrorKeyRegistry` via whichever module the file imports - see `registry-augmentation.test.ts`. */\nexport {\n ApplicationError,\n ErrorScopes,\n fromError,\n getError,\n isApplicationError,\n MessageCode,\n MessageTemplate,\n} from '@venizia/ignis-inversion';\n\nexport type {\n IErrorKeyRegistry,\n TError,\n TErrorByDefinition,\n TErrorByField,\n TErrorDefinition,\n TErrorDefinitionMessage,\n TErrorKey,\n TErrorLogLevel,\n TErrorMessage,\n TErrorMessageInput,\n TErrorMessageOverride,\n TErrorNormalized,\n TErrorNormalizeTransformFn,\n TErrorScope,\n TRegisterErrors,\n TResponsedError,\n} from '@venizia/ignis-inversion';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/error/index.ts"],"names":[],"mappings":"AAAA,iNAAiN;AACjN,+GAA+G;AAC/G,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,SAAS,EACT,QAAQ,EACR,kBAAkB,EAClB,WAAW,EACX,eAAe,GAChB,MAAM,0BAA0B,CAAC","sourcesContent":["/** Error layer lives in `@venizia/ignis-inversion` so browser apps (DI-only, no helpers) share the same class; re-exported by NAME, not `export *`, to keep inversion's DI container off the helpers surface. */\n/** Augment `IErrorKeyRegistry` via whichever module the file imports - see `registry-augmentation.test.ts`. */\nexport {\n ApplicationError,\n ErrorLogLevels,\n ErrorScopes,\n fromError,\n getError,\n isApplicationError,\n MessageCode,\n MessageTemplate,\n} from '@venizia/ignis-inversion';\n\nexport type {\n IErrorKeyRegistry,\n TError,\n TErrorByDefinition,\n TErrorByField,\n TErrorDefinition,\n TErrorDefinitionMessage,\n TErrorKey,\n TErrorLogLevel,\n TErrorMessage,\n TErrorMessageInput,\n TErrorMessageOverride,\n TErrorNormalized,\n TErrorNormalizeTransformFn,\n TErrorScope,\n TRegisterErrors,\n TResponsedError,\n} from '@venizia/ignis-inversion';\n"]}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TLogLevel } from '../../common/index.js';
|
|
2
|
+
/** The levels the high-frequency logger writes: the shared log levels. */
|
|
3
|
+
export type THfLogLevel = TLogLevel;
|
|
2
4
|
export type THfSinkBatch = {
|
|
3
5
|
lines: Array<string>;
|
|
4
6
|
dropped: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/logger/hf/common/types.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/modules/logger/hf/common/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9C,0EAA0E;AAC1E,MAAM,MAAM,WAAW,GAAG,SAAS,CAAC;AAEpC,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAErE,uQAAuQ;AACvQ,MAAM,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAEpD,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,UAAU,GAAG;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,GAAG,EAAE,YAAY,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/modules/logger/hf/common/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../src/modules/logger/hf/common/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TLogLevel } from '../../common';\n\n/** The levels the high-frequency logger writes: the shared log levels. */\nexport type THfLogLevel = TLogLevel;\n\nexport type THfSinkBatch = { lines: Array<string>; dropped: number };\n\n/** Declared `=> void` ON PURPOSE: TS's void-return exemption lets both sync and `async` sinks assign to it (`void | Promise<void>` would reject the sync form); the flusher still awaits a returned thenable, so a rejection is caught and logged, never unhandled. */\nexport type THfSink = (batch: THfSinkBatch) => void;\n\nexport interface IHfLogFlusherOptions {\n /** Full custom delivery. Overrides filePath. */\n sink?: THfSink;\n /** Default sink appends here instead of writing to stdout. */\n filePath?: string;\n /** Entries rendered per batch before yielding. Defaults to HF_DEFAULT_BATCH_SIZE. */\n batchSize?: number;\n}\n\nexport type TRingState = { bytes: Uint8Array; f64: Float64Array; writeIndex: number };\n"]}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import type { TConstValue } from '../../../../common/types/index.js';
|
|
1
2
|
import { type TPinoCustomLevelName } from './types.js';
|
|
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"}
|
|
@@ -2,4 +2,13 @@
|
|
|
2
2
|
export const PINO_CUSTOM_LEVELS = {
|
|
3
3
|
emerg: 70,
|
|
4
4
|
};
|
|
5
|
+
/** How often the file destination rolls (pino-roll's `frequency`). */
|
|
6
|
+
export class PinoFrequencies {
|
|
7
|
+
static { this.HOURLY = 'hourly'; }
|
|
8
|
+
static { this.DAILY = 'daily'; }
|
|
9
|
+
static { this.SCHEME_SET = new Set([this.HOURLY, this.DAILY]); }
|
|
10
|
+
static isValid(value) {
|
|
11
|
+
return this.SCHEME_SET.has(value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
5
14
|
//# 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;AAC5K,MAAM,CAAC,MAAM,kBAAkB,GAAyC;IACtE,KAAK,EAAE,EAAE;CACV,CAAC;AAEF,sEAAsE;AACtE,MAAM,OAAO,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","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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import { ModuleUtility } from '../../../utilities/module.utility.js';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import pino from 'pino';
|
|
6
6
|
import { LoggerFormats, resolveLoggerColorize } from '../common/index.js';
|
|
7
|
+
import { PinoFrequencies } from './common/index.js';
|
|
7
8
|
/** 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`. */
|
|
8
9
|
export class PinoDestination {
|
|
9
|
-
static { this.DEFAULT_FREQUENCY =
|
|
10
|
+
static { this.DEFAULT_FREQUENCY = PinoFrequencies.HOURLY; }
|
|
10
11
|
static { this.DEFAULT_MAX_FILES = '5d'; }
|
|
11
12
|
/** `APP_ENV_LOGGER_FILE_FREQUENCY` -> pino-roll's `frequency`; an unrecognized value warns and falls back rather than throwing, so the app still boots. */
|
|
12
13
|
static mapFrequency(value) {
|
|
13
14
|
const normalized = (value ?? '1h').trim().toLowerCase();
|
|
14
15
|
switch (normalized) {
|
|
15
16
|
case '1h': {
|
|
16
|
-
return
|
|
17
|
+
return PinoFrequencies.HOURLY;
|
|
17
18
|
}
|
|
18
19
|
case '1d':
|
|
19
20
|
case '24h': {
|
|
20
|
-
return
|
|
21
|
+
return PinoFrequencies.DAILY;
|
|
21
22
|
}
|
|
22
23
|
default: {
|
|
23
24
|
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,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,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AE,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;;AAGH,kGAAkG;AAClG,gEAAgE;AAChE,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAc,EAAE,CAAC,eAAe,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AAEhG,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAA+C,EAAU,EAAE,CAC5F,eAAe,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;AAE3C,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAqB,EAAE,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC;AAE5F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAsB,EAAsC,EAAE,CAC7F,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC","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,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAmB,MAAM,UAAU,CAAC;AAiB5D,2MAA2M;AAC3M,MAAM,OAAO,eAAe;aACF,sBAAiB,GAAe,eAAe,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,eAAe,CAAC,MAAM,CAAC;YAChC,CAAC;YACD,KAAK,IAAI,CAAC;YACV,KAAK,KAAK,CAAC,CAAC,CAAC;gBACX,OAAO,eAAe,CAAC,KAAK,CAAC;YAC/B,CAAC;YACD,OAAO,CAAC,CAAC,CAAC;gBACR,OAAO,CAAC,IAAI,CACV,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AAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC","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/index.js';
|
|
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,10 @@
|
|
|
1
|
+
/** The HTTP clients a fetcher can be built on. */
|
|
2
|
+
export class FetcherVariants {
|
|
3
|
+
static { this.NODE_FETCH = 'node-fetch'; }
|
|
4
|
+
static { this.AXIOS = 'axios'; }
|
|
5
|
+
static { this.SCHEME_SET = new Set([this.NODE_FETCH, this.AXIOS]); }
|
|
6
|
+
static isValid(value) {
|
|
7
|
+
return this.SCHEME_SET.has(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# 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,MAAM,OAAO,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","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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC","sourcesContent":["export * from './types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../src/modules/network/http-request/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC","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/index.js';
|
|
1
2
|
import { type ValueOrPromise } from '../../../common/types/index.js';
|
|
2
3
|
import { BaseHelper } from '../../base.js';
|
|
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,CAAC,QAAQ,CAAC,UAAU,cAIvB;IAEH,MAAM,CAAC,O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AAC;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"}
|
|
@@ -2,6 +2,20 @@ import { BaseHelper } from '../../base.js';
|
|
|
2
2
|
import { getError } from '../../error/index.js';
|
|
3
3
|
import { getUID } from '../../../utilities/parse.utility.js';
|
|
4
4
|
import { voidExecution } from '../../../utilities/promise.utility.js';
|
|
5
|
+
/** Where a TCP client is in the authentication handshake. */
|
|
6
|
+
export class TcpClientStates {
|
|
7
|
+
static { this.UNAUTHORIZED = 'unauthorized'; }
|
|
8
|
+
static { this.AUTHENTICATING = 'authenticating'; }
|
|
9
|
+
static { this.AUTHENTICATED = 'authenticated'; }
|
|
10
|
+
static { this.SCHEME_SET = new Set([
|
|
11
|
+
this.UNAUTHORIZED,
|
|
12
|
+
this.AUTHENTICATING,
|
|
13
|
+
this.AUTHENTICATED,
|
|
14
|
+
]); }
|
|
15
|
+
static isValid(value) {
|
|
16
|
+
return this.SCHEME_SET.has(value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
5
19
|
export class BaseNetworkTcpServer extends BaseHelper {
|
|
6
20
|
constructor(opts) {
|
|
7
21
|
super({
|
|
@@ -121,7 +135,9 @@ export class BaseNetworkTcpServer extends BaseHelper {
|
|
|
121
135
|
this.clients[id] = {
|
|
122
136
|
id,
|
|
123
137
|
socket,
|
|
124
|
-
state: this.authenticateOptions.required
|
|
138
|
+
state: this.authenticateOptions.required
|
|
139
|
+
? TcpClientStates.UNAUTHORIZED
|
|
140
|
+
: TcpClientStates.AUTHENTICATED,
|
|
125
141
|
subscriptions: new Set([]),
|
|
126
142
|
storage: {
|
|
127
143
|
connectedAt: new Date(),
|
|
@@ -146,7 +162,7 @@ export class BaseNetworkTcpServer extends BaseHelper {
|
|
|
146
162
|
return;
|
|
147
163
|
}
|
|
148
164
|
client.storage.authenticateTimeout = null;
|
|
149
|
-
if (client.state ===
|
|
165
|
+
if (client.state === TcpClientStates.AUTHENTICATED) {
|
|
150
166
|
return;
|
|
151
167
|
}
|
|
152
168
|
this.emit({ clientId: id, payload: 'Unauthorized Client' });
|
|
@@ -205,12 +221,12 @@ export class BaseNetworkTcpServer extends BaseHelper {
|
|
|
205
221
|
}
|
|
206
222
|
client.state = state;
|
|
207
223
|
switch (state) {
|
|
208
|
-
case
|
|
209
|
-
case
|
|
224
|
+
case TcpClientStates.UNAUTHORIZED:
|
|
225
|
+
case TcpClientStates.AUTHENTICATING: {
|
|
210
226
|
client.storage.authenticatedAt = null;
|
|
211
227
|
break;
|
|
212
228
|
}
|
|
213
|
-
case
|
|
229
|
+
case TcpClientStates.AUTHENTICATED: {
|
|
214
230
|
client.storage.authenticatedAt = new Date();
|
|
215
231
|
if (client.storage.authenticateTimeout) {
|
|
216
232
|
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,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAmD5D,MAAM,OAAO,oBAIX,SAAQ,UAAU;IA6BlB,YACE,IAAsF;QAEtF,KAAK,CAAC;YACJ,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,IAAI,oBAAoB,CAAC,IAAI;YACjE,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;QAlCK,kBAAa,GAAiC,EAAE,CAAC;QACjD,kBAAa,GAA2B,EAAE,CAAC;QAmCnD,oFAAoF;QACpF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAEnC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC;QACxC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAEpD,IACE,IAAI,CAAC,mBAAmB,CAAC,QAAQ;YACjC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,IAAI,IAAI,CAAC,mBAAmB,CAAC,QAAQ,GAAG,CAAC,CAAC,EAC7E,CAAC;YACD,MAAM,QAAQ,CAAC;gBACb,OAAO,EACL,wFAAwF;aAC3F,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,WAAW,GAAG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,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","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 // 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 ? '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 = 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: '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,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAQ5D,6DAA6D;AAC7D,MAAM,OAAO,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;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAiDH,MAAM,OAAO,oBAIX,SAAQ,UAAU;IA6BlB,YACE,IAAsF;QAEtF,KAAK,CAAC;YACJ,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,IAAI,oBAAoB,CAAC,IAAI;YACjE,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;QAlCK,kBAAa,GAAiC,EAAE,CAAC;QACjD,kBAAa,GAA2B,EAAE,CAAC;QAmCnD,oFAAoF;QACpF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,I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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","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/index.js';
|
|
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,10 @@
|
|
|
1
|
+
/** What a BullMQ helper is: the QUEUE that jobs are added to, or the WORKER that runs them. */
|
|
2
|
+
export class BullQueueRoles {
|
|
3
|
+
static { this.QUEUE = 'queue'; }
|
|
4
|
+
static { this.WORKER = 'worker'; }
|
|
5
|
+
static { this.SCHEME_SET = new Set([this.QUEUE, this.WORKER]); }
|
|
6
|
+
static isValid(value) {
|
|
7
|
+
return this.SCHEME_SET.has(value);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# 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,MAAM,OAAO,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","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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/queue/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC","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,cAAc,aAAa,CAAC;AAC5B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC","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":[""]}
|
|
@@ -56,4 +56,13 @@ export declare class KafkaDefaults {
|
|
|
56
56
|
static readonly SHUTDOWN_TIMEOUT = 30000;
|
|
57
57
|
static readonly LAG_MONITOR_INTERVAL = 30000;
|
|
58
58
|
}
|
|
59
|
+
/** Why every broker of a consumer is gone: DISCONNECTED (the connections closed) or FAILED (they errored). */
|
|
60
|
+
export declare class KafkaBrokersDownReasons {
|
|
61
|
+
static readonly DISCONNECTED = "disconnected";
|
|
62
|
+
static readonly FAILED = "failed";
|
|
63
|
+
static readonly SCHEME_SET: Set<string>;
|
|
64
|
+
static isValid(value: string): boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Valid Kafka brokers-down reason values. */
|
|
67
|
+
export type TKafkaBrokersDownReason = TConstValue<typeof KafkaBrokersDownReasons>;
|
|
59
68
|
//# sourceMappingURL=constants.d.ts.map
|