@venizia/ignis-helpers 0.4.8-10 → 0.4.8-11
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/README.md +2 -3
- package/dist/esm/common/constants/app.d.ts +1 -3
- package/dist/esm/common/constants/app.js +1 -11
- package/dist/esm/common/constants/app.js.map +1 -1
- package/dist/esm/common/constants/mime.d.ts +0 -2
- package/dist/esm/common/constants/mime.js +0 -4
- package/dist/esm/common/constants/mime.js.map +1 -1
- package/dist/esm/common/types/field-mapping.d.ts +0 -2
- package/dist/esm/common/types/field-mapping.js +0 -10
- package/dist/esm/common/types/field-mapping.js.map +1 -1
- package/dist/esm/modules/network/http-request/common/constants.d.ts +0 -2
- package/dist/esm/modules/network/http-request/common/constants.js +0 -4
- package/dist/esm/modules/network/http-request/common/constants.js.map +1 -1
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.d.ts +0 -2
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js +0 -8
- package/dist/esm/modules/network/tcp-socket/base-tcp-server.helper.js.map +1 -1
- package/dist/esm/modules/network/utilities/url-safety/common/constants.d.ts +0 -2
- package/dist/esm/modules/network/utilities/url-safety/common/constants.js +0 -4
- package/dist/esm/modules/network/utilities/url-safety/common/constants.js.map +1 -1
- package/dist/esm/modules/queue/bullmq/helper.d.ts +9 -9
- package/dist/esm/modules/queue/bullmq/helper.js +8 -10
- package/dist/esm/modules/queue/bullmq/helper.js.map +1 -1
- package/dist/esm/modules/queue/common/constants.d.ts +6 -2
- package/dist/esm/modules/queue/common/constants.js +6 -4
- package/dist/esm/modules/queue/common/constants.js.map +1 -1
- package/dist/esm/modules/queue/internal/sequential/common/types.d.ts +2 -4
- package/dist/esm/modules/queue/internal/sequential/common/types.js +0 -4
- package/dist/esm/modules/queue/internal/sequential/common/types.js.map +1 -1
- package/dist/esm/modules/queue/kafka/common/constants.d.ts +0 -4
- package/dist/esm/modules/queue/kafka/common/constants.js +0 -8
- package/dist/esm/modules/queue/kafka/common/constants.js.map +1 -1
- package/dist/esm/modules/redis/base/abstract.helper.d.ts +13 -2
- package/dist/esm/modules/redis/base/abstract.helper.js +47 -45
- package/dist/esm/modules/redis/base/abstract.helper.js.map +1 -1
- package/dist/esm/modules/redis/cluster/cluster.helper.d.ts +0 -1
- package/dist/esm/modules/redis/cluster/cluster.helper.js +12 -7
- package/dist/esm/modules/redis/cluster/cluster.helper.js.map +1 -1
- package/dist/esm/modules/redis/common/constants.d.ts +14 -12
- package/dist/esm/modules/redis/common/constants.js +15 -14
- package/dist/esm/modules/redis/common/constants.js.map +1 -1
- package/dist/esm/modules/redis/common/types.d.ts +4 -3
- package/dist/esm/modules/redis/common/types.js.map +1 -1
- package/dist/esm/modules/redis/factory.d.ts +4 -21
- package/dist/esm/modules/redis/factory.js +9 -18
- package/dist/esm/modules/redis/factory.js.map +1 -1
- package/dist/esm/modules/redis/sentinel/sentinel.helper.d.ts +0 -1
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js +11 -10
- package/dist/esm/modules/redis/sentinel/sentinel.helper.js.map +1 -1
- package/dist/esm/modules/redis/single/single.helper.d.ts +0 -1
- package/dist/esm/modules/redis/single/single.helper.js +3 -5
- package/dist/esm/modules/redis/single/single.helper.js.map +1 -1
- package/dist/esm/modules/storage/base.d.ts +19 -62
- package/dist/esm/modules/storage/base.js +60 -126
- package/dist/esm/modules/storage/base.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/helper.d.ts +13 -38
- package/dist/esm/modules/storage/bun-s3/helper.js +35 -69
- package/dist/esm/modules/storage/bun-s3/helper.js.map +1 -1
- package/dist/esm/modules/storage/bun-s3/utility.d.ts +8 -4
- package/dist/esm/modules/storage/bun-s3/utility.js +57 -44
- package/dist/esm/modules/storage/bun-s3/utility.js.map +1 -1
- package/dist/esm/modules/storage/common/constants.d.ts +23 -2
- package/dist/esm/modules/storage/common/constants.js +23 -4
- package/dist/esm/modules/storage/common/constants.js.map +1 -1
- package/dist/esm/modules/storage/common/types.d.ts +85 -65
- package/dist/esm/modules/storage/common/types.js.map +1 -1
- package/dist/esm/modules/storage/common/utility.js +4 -5
- package/dist/esm/modules/storage/common/utility.js.map +1 -1
- package/dist/esm/modules/storage/disk/helper.d.ts +3 -8
- package/dist/esm/modules/storage/disk/helper.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,15 +16,14 @@ Choose a logger provider once at the entrypoint, then take scoped loggers and he
|
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
18
|
// bun add pino ioredis
|
|
19
|
-
import { LoggerFactory, RedisHelperFactory
|
|
19
|
+
import { LoggerFactory, RedisHelperFactory } from '@venizia/ignis-helpers';
|
|
20
20
|
import { PinoLogger } from '@venizia/ignis-helpers/pino';
|
|
21
21
|
|
|
22
22
|
LoggerFactory.use({ provider: PinoLogger });
|
|
23
23
|
|
|
24
24
|
const logger = LoggerFactory.getLogger(['CacheService']);
|
|
25
25
|
|
|
26
|
-
const redis = RedisHelperFactory.
|
|
27
|
-
mode: RedisModes.SINGLE,
|
|
26
|
+
const redis = RedisHelperFactory.single({
|
|
28
27
|
name: 'cache',
|
|
29
28
|
host: '127.0.0.1',
|
|
30
29
|
port: 6379,
|
|
@@ -25,14 +25,12 @@ export declare class RuntimeModules {
|
|
|
25
25
|
}
|
|
26
26
|
/** The runtime names `RuntimeModules` holds; only `bun` today. */
|
|
27
27
|
export type TRuntimeModule = TConstValue<typeof RuntimeModules>;
|
|
28
|
-
/** The value kinds a stored field can hold
|
|
28
|
+
/** The value kinds a stored field can hold. */
|
|
29
29
|
export declare class DataTypes {
|
|
30
30
|
static readonly NUMBER = "NUMBER";
|
|
31
31
|
static readonly TEXT = "TEXT";
|
|
32
32
|
static readonly BYTE = "BYTE";
|
|
33
33
|
static readonly JSON = "JSON";
|
|
34
34
|
static readonly BOOLEAN = "BOOLEAN";
|
|
35
|
-
static readonly SCHEME_SET: Set<string>;
|
|
36
|
-
static isValid(orgType: string): boolean;
|
|
37
35
|
}
|
|
38
36
|
//# sourceMappingURL=app.d.ts.map
|
|
@@ -26,22 +26,12 @@ export class RuntimeModules {
|
|
|
26
26
|
return RuntimeModules.detect() === RuntimeModules.BUN;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
/** The value kinds a stored field can hold
|
|
29
|
+
/** The value kinds a stored field can hold. */
|
|
30
30
|
export class DataTypes {
|
|
31
31
|
static { this.NUMBER = 'NUMBER'; }
|
|
32
32
|
static { this.TEXT = 'TEXT'; }
|
|
33
33
|
static { this.BYTE = 'BYTE'; }
|
|
34
34
|
static { this.JSON = 'JSON'; }
|
|
35
35
|
static { this.BOOLEAN = 'BOOLEAN'; }
|
|
36
|
-
static { this.SCHEME_SET = new Set([
|
|
37
|
-
this.NUMBER,
|
|
38
|
-
this.TEXT,
|
|
39
|
-
this.BYTE,
|
|
40
|
-
this.JSON,
|
|
41
|
-
this.BOOLEAN,
|
|
42
|
-
]); }
|
|
43
|
-
static isValid(orgType) {
|
|
44
|
-
return this.SCHEME_SET.has(orgType);
|
|
45
|
-
}
|
|
46
36
|
}
|
|
47
37
|
//# sourceMappingURL=app.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../../src/common/constants/app.ts"],"names":[],"mappings":"AAEA,6FAA6F;AAC7F,MAAM,OAAO,QAAQ;IACnB;;;OAGG;aACa,qBAAgB,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,wBAAwB,IAAI,KAAK,CAAC;IAE9F;;;OAGG;aACa,gBAAW,GAAG,EAAE,CAAC;IACjC;;;OAGG;aACa,iBAAY,GAAG,CAAC,CAAC;;AAGnC,2HAA2H;AAC3H,MAAM,OAAO,cAAc;aACT,QAAG,GAAG,KAAK,CAAC;IAE5B,MAAM,CAAC,MAAM;QACX,OAAO,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IACrE,CAAC;IAED,MAAM,CAAC,KAAK;QACV,OAAO,cAAc,CAAC,MAAM,EAAE,KAAK,cAAc,CAAC,GAAG,CAAC;IACxD,CAAC;;AAKH
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../../../src/common/constants/app.ts"],"names":[],"mappings":"AAEA,6FAA6F;AAC7F,MAAM,OAAO,QAAQ;IACnB;;;OAGG;aACa,qBAAgB,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,wBAAwB,IAAI,KAAK,CAAC;IAE9F;;;OAGG;aACa,gBAAW,GAAG,EAAE,CAAC;IACjC;;;OAGG;aACa,iBAAY,GAAG,CAAC,CAAC;;AAGnC,2HAA2H;AAC3H,MAAM,OAAO,cAAc;aACT,QAAG,GAAG,KAAK,CAAC;IAE5B,MAAM,CAAC,MAAM;QACX,OAAO,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IACrE,CAAC;IAED,MAAM,CAAC,KAAK;QACV,OAAO,cAAc,CAAC,MAAM,EAAE,KAAK,cAAc,CAAC,GAAG,CAAC;IACxD,CAAC;;AAKH,+CAA+C;AAC/C,MAAM,OAAO,SAAS;aACJ,WAAM,GAAG,QAAQ,CAAC;aAClB,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aACd,SAAI,GAAG,MAAM,CAAC;aACd,YAAO,GAAG,SAAS,CAAC","sourcesContent":["import { type TConstValue } from '../types';\n\n/** Application-wide defaults: the application name and the paging values of a list query. */\nexport class Defaults {\n /**\n * The application name; reads `APP_ENV_APPLICATION_NAME`.\n * @default 'APP'\n */\n static readonly APPLICATION_NAME = globalThis.process?.env?.APP_ENV_APPLICATION_NAME ?? 'APP';\n\n /**\n * Rows a list query returns.\n * @default 50\n */\n static readonly QUERY_LIMIT = 50;\n /**\n * Rows a list query skips.\n * @default 0\n */\n static readonly QUERY_OFFSET = 0;\n}\n\n/** IGNIS runs on Bun only: `detect()` answers `'bun'` there and `undefined` anywhere else (a browser, another runtime). */\nexport class RuntimeModules {\n static readonly BUN = 'bun';\n\n static detect(): TRuntimeModule | undefined {\n return typeof Bun !== 'undefined' ? RuntimeModules.BUN : undefined;\n }\n\n static isBun(): boolean {\n return RuntimeModules.detect() === RuntimeModules.BUN;\n }\n}\n/** The runtime names `RuntimeModules` holds; only `bun` today. */\nexport type TRuntimeModule = TConstValue<typeof RuntimeModules>;\n\n/** The value kinds a stored field can hold. */\nexport class DataTypes {\n static readonly NUMBER = 'NUMBER';\n static readonly TEXT = 'TEXT';\n static readonly BYTE = 'BYTE';\n static readonly JSON = 'JSON';\n static readonly BOOLEAN = 'BOOLEAN';\n}\n"]}
|
|
@@ -5,8 +5,6 @@ export declare class MimeTypes {
|
|
|
5
5
|
static readonly IMAGE = "image";
|
|
6
6
|
static readonly VIDEO = "video";
|
|
7
7
|
static readonly TEXT = "text";
|
|
8
|
-
static readonly SCHEME_SET: Set<string>;
|
|
9
|
-
static isValid(value: string): boolean;
|
|
10
8
|
}
|
|
11
9
|
/** One of the `MimeTypes` values. */
|
|
12
10
|
export type TMimeTypes = TConstValue<typeof MimeTypes>;
|
|
@@ -4,10 +4,6 @@ export class MimeTypes {
|
|
|
4
4
|
static { this.IMAGE = 'image'; }
|
|
5
5
|
static { this.VIDEO = 'video'; }
|
|
6
6
|
static { this.TEXT = 'text'; }
|
|
7
|
-
static { this.SCHEME_SET = new Set([this.UNKNOWN, this.IMAGE, this.VIDEO, this.TEXT]); }
|
|
8
|
-
static isValid(value) {
|
|
9
|
-
return this.SCHEME_SET.has(value);
|
|
10
|
-
}
|
|
11
7
|
}
|
|
12
8
|
/** The leading dot is part of the value: `path.extname` returns one. */
|
|
13
9
|
export class FileExtensions {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../../../src/common/constants/mime.ts"],"names":[],"mappings":"AAEA,kIAAkI;A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AG;QACtC,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,IAAI;QACxC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;QACtC,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,IAAI;QACxC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;QACtC,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,IAAI;QACxC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;QACtC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;QACtC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;KACkB,CAAC;IAE3D;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,IAA0B;QACvC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,MAAM,OAAO,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QAE9E,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,YAAY,CAAC;IACnE,CAAC;;AAGH,gGAAgG;AAChG,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC,YAAY,CAAC","sourcesContent":["import { type TConstValue } from '../types';\n\n/** The top-level part of a MIME type (`image`, `video`, `text`), plus `unknown`. For the full content type see `ContentTypes`. */\nexport class MimeTypes {\n static readonly UNKNOWN = 'unknown';\n static readonly IMAGE = 'image';\n static readonly VIDEO = 'video';\n static readonly TEXT = 'text';\n\n static readonly SCHEME_SET = new Set<string>([this.UNKNOWN, this.IMAGE, this.VIDEO, this.TEXT]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n/** One of the `MimeTypes` values. */\nexport type TMimeTypes = TConstValue<typeof MimeTypes>;\n\n/** The leading dot is part of the value: `path.extname` returns one. */\nexport class FileExtensions {\n static readonly PNG = '.png';\n static readonly JPG = '.jpg';\n static readonly JPEG = '.jpeg';\n static readonly GIF = '.gif';\n static readonly WEBP = '.webp';\n static readonly SVG = '.svg';\n static readonly PDF = '.pdf';\n static readonly JSON = '.json';\n static readonly TXT = '.txt';\n static readonly HTML = '.html';\n static readonly CSS = '.css';\n static readonly JS = '.js';\n static readonly MP4 = '.mp4';\n static readonly WEBM = '.webm';\n static readonly MP3 = '.mp3';\n static readonly WAV = '.wav';\n static readonly ZIP = '.zip';\n static readonly CSV = '.csv';\n static readonly XML = '.xml';\n static readonly XLSX = '.xlsx';\n static readonly XLS = '.xls';\n static readonly DOCX = '.docx';\n static readonly DOC = '.doc';\n static readonly PPTX = '.pptx';\n static readonly PPT = '.ppt';\n static readonly ODT = '.odt';\n static readonly ODS = '.ods';\n\n static readonly SCHEME_SET = new Set<string>([\n this.PNG,\n this.JPG,\n this.JPEG,\n this.GIF,\n this.WEBP,\n this.SVG,\n this.PDF,\n this.JSON,\n this.TXT,\n this.HTML,\n this.CSS,\n this.JS,\n this.MP4,\n this.WEBM,\n this.MP3,\n this.WAV,\n this.ZIP,\n this.CSV,\n this.XML,\n this.XLSX,\n this.XLS,\n this.DOCX,\n this.DOC,\n this.PPTX,\n this.PPT,\n this.ODT,\n this.ODS,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n/** One of the `FileExtensions` values, with its leading dot. */\nexport type TFileExtension = TConstValue<typeof FileExtensions>;\n\n/** Full content types, as they go on the wire. `MimeTypes` holds only the top-level part. */\nexport class ContentTypes {\n static readonly OCTET_STREAM = 'application/octet-stream';\n static readonly PNG = 'image/png';\n static readonly JPEG = 'image/jpeg';\n static readonly GIF = 'image/gif';\n static readonly WEBP = 'image/webp';\n static readonly SVG = 'image/svg+xml';\n static readonly PDF = 'application/pdf';\n static readonly JSON = 'application/json';\n static readonly PLAIN_TEXT = 'text/plain';\n static readonly HTML = 'text/html';\n static readonly CSS = 'text/css';\n static readonly JAVASCRIPT = 'text/javascript';\n static readonly MP4 = 'video/mp4';\n static readonly WEBM = 'video/webm';\n static readonly MPEG_AUDIO = 'audio/mpeg';\n static readonly WAV = 'audio/wav';\n static readonly ZIP = 'application/zip';\n static readonly CSV = 'text/csv';\n static readonly XML = 'application/xml';\n static readonly XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n static readonly XLS = 'application/vnd.ms-excel';\n static readonly DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';\n static readonly DOC = 'application/msword';\n static readonly PPTX =\n 'application/vnd.openxmlformats-officedocument.presentationml.presentation';\n\n static readonly PPT = 'application/vnd.ms-powerpoint';\n static readonly ODT = 'application/vnd.oasis.opendocument.text';\n static readonly ODS = 'application/vnd.oasis.opendocument.spreadsheet';\n\n static readonly SCHEME_SET = new Set<string>([\n this.OCTET_STREAM,\n this.PNG,\n this.JPEG,\n this.GIF,\n this.WEBP,\n this.SVG,\n this.PDF,\n this.JSON,\n this.PLAIN_TEXT,\n this.HTML,\n this.CSS,\n this.JAVASCRIPT,\n this.MP4,\n this.WEBM,\n this.MPEG_AUDIO,\n this.WAV,\n this.ZIP,\n this.CSV,\n this.XML,\n this.XLSX,\n this.XLS,\n this.DOCX,\n this.DOC,\n this.PPTX,\n this.PPT,\n this.ODT,\n this.ODS,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n/** One of the `ContentTypes` values. */\nexport type TContentType = TConstValue<typeof ContentTypes>;\n\n/** The extension table and the lookup that reads it, together - the `DurationMultipliers` shape. */\nexport class ContentTypeTable {\n /** `satisfies` makes the table total; the declared `string` key keeps a lookup cast-free. */\n static readonly BY_EXTENSION: Readonly<Partial<Record<string, TContentType>>> = {\n [FileExtensions.PNG]: ContentTypes.PNG,\n [FileExtensions.JPG]: ContentTypes.JPEG,\n [FileExtensions.JPEG]: ContentTypes.JPEG,\n [FileExtensions.GIF]: ContentTypes.GIF,\n [FileExtensions.WEBP]: ContentTypes.WEBP,\n [FileExtensions.SVG]: ContentTypes.SVG,\n [FileExtensions.PDF]: ContentTypes.PDF,\n [FileExtensions.JSON]: ContentTypes.JSON,\n [FileExtensions.TXT]: ContentTypes.PLAIN_TEXT,\n [FileExtensions.HTML]: ContentTypes.HTML,\n [FileExtensions.CSS]: ContentTypes.CSS,\n [FileExtensions.JS]: ContentTypes.JAVASCRIPT,\n [FileExtensions.MP4]: ContentTypes.MP4,\n [FileExtensions.WEBM]: ContentTypes.WEBM,\n [FileExtensions.MP3]: ContentTypes.MPEG_AUDIO,\n [FileExtensions.WAV]: ContentTypes.WAV,\n [FileExtensions.ZIP]: ContentTypes.ZIP,\n [FileExtensions.CSV]: ContentTypes.CSV,\n [FileExtensions.XML]: ContentTypes.XML,\n [FileExtensions.XLSX]: ContentTypes.XLSX,\n [FileExtensions.XLS]: ContentTypes.XLS,\n [FileExtensions.DOCX]: ContentTypes.DOCX,\n [FileExtensions.DOC]: ContentTypes.DOC,\n [FileExtensions.PPTX]: ContentTypes.PPTX,\n [FileExtensions.PPT]: ContentTypes.PPT,\n [FileExtensions.ODT]: ContentTypes.ODT,\n [FileExtensions.ODS]: ContentTypes.ODS,\n } satisfies Readonly<Record<TFileExtension, TContentType>>;\n\n /**\n * The content type an object name implies. `node:path` is deliberately not used: this file is\n * reachable from the browser-pure `./common` subpath, and an extension is the tail after the last\n * dot either way.\n */\n static resolve(opts: { filename: string }): TContentType {\n const { filename } = opts;\n const lastDot = filename.lastIndexOf('.');\n const extension = lastDot === -1 ? '' : filename.slice(lastDot).toLowerCase();\n\n return this.BY_EXTENSION[extension] ?? ContentTypes.OCTET_STREAM;\n }\n}\n\n/** Published before the table moved onto the class; kept as the one-line delegate it now is. */\nexport const CONTENT_TYPE_BY_EXTENSION = ContentTypeTable.BY_EXTENSION;\n"]}
|
|
1
|
+
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../../../src/common/constants/mime.ts"],"names":[],"mappings":"AAEA,kIAAkI;AAClI,MAAM,OAAO,SAAS;aACJ,YAAO,GAAG,SAAS,CAAC;aACpB,UAAK,GAAG,OAAO,CAAC;aAChB,UAAK,GAAG,OAAO,CAAC;aAChB,SAAI,GAAG,MAAM,CAAC;;AAKhC,wEAAwE;AACxE,MAAM,OAAO,cAAc;aACT,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,OAAE,GAAG,KAAK,CAAC;aACX,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,SAAI,GAAG,OAAO,CAAC;aACf,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aACb,QAAG,GAAG,MAAM,CAAC;aAEb,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,GAAG;QACR,IAAI,CAAC,GAAG;QACR,IAAI,CAAC,IAAI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E,YAAY,CAAC,GAAG;QACtC,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,IAAI;QACxC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;QACtC,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,YAAY,CAAC,IAAI;QACxC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;QACtC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;QACtC,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,YAAY,CAAC,GAAG;KACkB,CAAC;IAE3D;;;;OAIG;IACH,MAAM,CAAC,OAAO,CAAC,IAA0B;QACvC,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;QAC1B,MAAM,OAAO,GAAG,QAAQ,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;QAE9E,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,YAAY,CAAC;IACnE,CAAC;;AAGH,gGAAgG;AAChG,MAAM,CAAC,MAAM,yBAAyB,GAAG,gBAAgB,CAAC,YAAY,CAAC","sourcesContent":["import { type TConstValue } from '../types';\n\n/** The top-level part of a MIME type (`image`, `video`, `text`), plus `unknown`. For the full content type see `ContentTypes`. */\nexport class MimeTypes {\n static readonly UNKNOWN = 'unknown';\n static readonly IMAGE = 'image';\n static readonly VIDEO = 'video';\n static readonly TEXT = 'text';\n}\n/** One of the `MimeTypes` values. */\nexport type TMimeTypes = TConstValue<typeof MimeTypes>;\n\n/** The leading dot is part of the value: `path.extname` returns one. */\nexport class FileExtensions {\n static readonly PNG = '.png';\n static readonly JPG = '.jpg';\n static readonly JPEG = '.jpeg';\n static readonly GIF = '.gif';\n static readonly WEBP = '.webp';\n static readonly SVG = '.svg';\n static readonly PDF = '.pdf';\n static readonly JSON = '.json';\n static readonly TXT = '.txt';\n static readonly HTML = '.html';\n static readonly CSS = '.css';\n static readonly JS = '.js';\n static readonly MP4 = '.mp4';\n static readonly WEBM = '.webm';\n static readonly MP3 = '.mp3';\n static readonly WAV = '.wav';\n static readonly ZIP = '.zip';\n static readonly CSV = '.csv';\n static readonly XML = '.xml';\n static readonly XLSX = '.xlsx';\n static readonly XLS = '.xls';\n static readonly DOCX = '.docx';\n static readonly DOC = '.doc';\n static readonly PPTX = '.pptx';\n static readonly PPT = '.ppt';\n static readonly ODT = '.odt';\n static readonly ODS = '.ods';\n\n static readonly SCHEME_SET = new Set<string>([\n this.PNG,\n this.JPG,\n this.JPEG,\n this.GIF,\n this.WEBP,\n this.SVG,\n this.PDF,\n this.JSON,\n this.TXT,\n this.HTML,\n this.CSS,\n this.JS,\n this.MP4,\n this.WEBM,\n this.MP3,\n this.WAV,\n this.ZIP,\n this.CSV,\n this.XML,\n this.XLSX,\n this.XLS,\n this.DOCX,\n this.DOC,\n this.PPTX,\n this.PPT,\n this.ODT,\n this.ODS,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n/** One of the `FileExtensions` values, with its leading dot. */\nexport type TFileExtension = TConstValue<typeof FileExtensions>;\n\n/** Full content types, as they go on the wire. `MimeTypes` holds only the top-level part. */\nexport class ContentTypes {\n static readonly OCTET_STREAM = 'application/octet-stream';\n static readonly PNG = 'image/png';\n static readonly JPEG = 'image/jpeg';\n static readonly GIF = 'image/gif';\n static readonly WEBP = 'image/webp';\n static readonly SVG = 'image/svg+xml';\n static readonly PDF = 'application/pdf';\n static readonly JSON = 'application/json';\n static readonly PLAIN_TEXT = 'text/plain';\n static readonly HTML = 'text/html';\n static readonly CSS = 'text/css';\n static readonly JAVASCRIPT = 'text/javascript';\n static readonly MP4 = 'video/mp4';\n static readonly WEBM = 'video/webm';\n static readonly MPEG_AUDIO = 'audio/mpeg';\n static readonly WAV = 'audio/wav';\n static readonly ZIP = 'application/zip';\n static readonly CSV = 'text/csv';\n static readonly XML = 'application/xml';\n static readonly XLSX = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n static readonly XLS = 'application/vnd.ms-excel';\n static readonly DOCX = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';\n static readonly DOC = 'application/msword';\n static readonly PPTX =\n 'application/vnd.openxmlformats-officedocument.presentationml.presentation';\n\n static readonly PPT = 'application/vnd.ms-powerpoint';\n static readonly ODT = 'application/vnd.oasis.opendocument.text';\n static readonly ODS = 'application/vnd.oasis.opendocument.spreadsheet';\n\n static readonly SCHEME_SET = new Set<string>([\n this.OCTET_STREAM,\n this.PNG,\n this.JPEG,\n this.GIF,\n this.WEBP,\n this.SVG,\n this.PDF,\n this.JSON,\n this.PLAIN_TEXT,\n this.HTML,\n this.CSS,\n this.JAVASCRIPT,\n this.MP4,\n this.WEBM,\n this.MPEG_AUDIO,\n this.WAV,\n this.ZIP,\n this.CSV,\n this.XML,\n this.XLSX,\n this.XLS,\n this.DOCX,\n this.DOC,\n this.PPTX,\n this.PPT,\n this.ODT,\n this.ODS,\n ]);\n\n static isValid(value: string): boolean {\n return this.SCHEME_SET.has(value);\n }\n}\n/** One of the `ContentTypes` values. */\nexport type TContentType = TConstValue<typeof ContentTypes>;\n\n/** The extension table and the lookup that reads it, together - the `DurationMultipliers` shape. */\nexport class ContentTypeTable {\n /** `satisfies` makes the table total; the declared `string` key keeps a lookup cast-free. */\n static readonly BY_EXTENSION: Readonly<Partial<Record<string, TContentType>>> = {\n [FileExtensions.PNG]: ContentTypes.PNG,\n [FileExtensions.JPG]: ContentTypes.JPEG,\n [FileExtensions.JPEG]: ContentTypes.JPEG,\n [FileExtensions.GIF]: ContentTypes.GIF,\n [FileExtensions.WEBP]: ContentTypes.WEBP,\n [FileExtensions.SVG]: ContentTypes.SVG,\n [FileExtensions.PDF]: ContentTypes.PDF,\n [FileExtensions.JSON]: ContentTypes.JSON,\n [FileExtensions.TXT]: ContentTypes.PLAIN_TEXT,\n [FileExtensions.HTML]: ContentTypes.HTML,\n [FileExtensions.CSS]: ContentTypes.CSS,\n [FileExtensions.JS]: ContentTypes.JAVASCRIPT,\n [FileExtensions.MP4]: ContentTypes.MP4,\n [FileExtensions.WEBM]: ContentTypes.WEBM,\n [FileExtensions.MP3]: ContentTypes.MPEG_AUDIO,\n [FileExtensions.WAV]: ContentTypes.WAV,\n [FileExtensions.ZIP]: ContentTypes.ZIP,\n [FileExtensions.CSV]: ContentTypes.CSV,\n [FileExtensions.XML]: ContentTypes.XML,\n [FileExtensions.XLSX]: ContentTypes.XLSX,\n [FileExtensions.XLS]: ContentTypes.XLS,\n [FileExtensions.DOCX]: ContentTypes.DOCX,\n [FileExtensions.DOC]: ContentTypes.DOC,\n [FileExtensions.PPTX]: ContentTypes.PPTX,\n [FileExtensions.PPT]: ContentTypes.PPT,\n [FileExtensions.ODT]: ContentTypes.ODT,\n [FileExtensions.ODS]: ContentTypes.ODS,\n } satisfies Readonly<Record<TFileExtension, TContentType>>;\n\n /**\n * The content type an object name implies. `node:path` is deliberately not used: this file is\n * reachable from the browser-pure `./common` subpath, and an extension is the tail after the last\n * dot either way.\n */\n static resolve(opts: { filename: string }): TContentType {\n const { filename } = opts;\n const lastDot = filename.lastIndexOf('.');\n const extension = lastDot === -1 ? '' : filename.slice(lastDot).toLowerCase();\n\n return this.BY_EXTENSION[extension] ?? ContentTypes.OCTET_STREAM;\n }\n}\n\n/** Published before the table moved onto the class; kept as the one-line delegate it now is. */\nexport const CONTENT_TYPE_BY_EXTENSION = ContentTypeTable.BY_EXTENSION;\n"]}
|
|
@@ -6,8 +6,6 @@ export declare class FieldMappingDataTypes {
|
|
|
6
6
|
static readonly STRINGS = "strings";
|
|
7
7
|
static readonly NUMBERS = "numbers";
|
|
8
8
|
static readonly BOOLEAN = "boolean";
|
|
9
|
-
static readonly SCHEME_SET: Set<string>;
|
|
10
|
-
static isValid(value: string): boolean;
|
|
11
9
|
}
|
|
12
10
|
/** Valid field mapping data type values. */
|
|
13
11
|
export type TFieldMappingDataType = TConstValue<typeof FieldMappingDataTypes>;
|
|
@@ -5,15 +5,5 @@ export class FieldMappingDataTypes {
|
|
|
5
5
|
static { this.STRINGS = 'strings'; }
|
|
6
6
|
static { this.NUMBERS = 'numbers'; }
|
|
7
7
|
static { this.BOOLEAN = 'boolean'; }
|
|
8
|
-
static { this.SCHEME_SET = new Set([
|
|
9
|
-
this.STRING,
|
|
10
|
-
this.NUMBER,
|
|
11
|
-
this.STRINGS,
|
|
12
|
-
this.NUMBERS,
|
|
13
|
-
this.BOOLEAN,
|
|
14
|
-
]); }
|
|
15
|
-
static isValid(value) {
|
|
16
|
-
return this.SCHEME_SET.has(value);
|
|
17
|
-
}
|
|
18
8
|
}
|
|
19
9
|
//# sourceMappingURL=field-mapping.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-mapping.js","sourceRoot":"","sources":["../../../../src/common/types/field-mapping.ts"],"names":[],"mappings":"AAEA,6CAA6C;AAC7C,MAAM,OAAO,qBAAqB;aAChB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,YAAO,GAAG,SAAS,CAAC;aACpB,YAAO,GAAG,SAAS,CAAC;aACpB,YAAO,GAAG,SAAS,CAAC
|
|
1
|
+
{"version":3,"file":"field-mapping.js","sourceRoot":"","sources":["../../../../src/common/types/field-mapping.ts"],"names":[],"mappings":"AAEA,6CAA6C;AAC7C,MAAM,OAAO,qBAAqB;aAChB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,YAAO,GAAG,SAAS,CAAC;aACpB,YAAO,GAAG,SAAS,CAAC;aACpB,YAAO,GAAG,SAAS,CAAC","sourcesContent":["import type { TConstValue } from './const-value';\n\n/** The value kinds a field mapping reads. */\nexport class FieldMappingDataTypes {\n static readonly STRING = 'string';\n static readonly NUMBER = 'number';\n static readonly STRINGS = 'strings';\n static readonly NUMBERS = 'numbers';\n static readonly BOOLEAN = 'boolean';\n}\n\n/** Valid field mapping data type values. */\nexport type TFieldMappingDataType = TConstValue<typeof FieldMappingDataTypes>;\n\n/** Describes one field to read: its `name`, its value `type`, and an optional `default`. */\nexport interface IFieldMapping {\n name: string;\n type: TFieldMappingDataType;\n default?: string | number | Array<string> | Array<number> | boolean;\n}\n\n/** The union of `name` values in a list of field mappings. */\nexport type TFieldMappingNames<T extends Array<IFieldMapping>> = Extract<\n T[number],\n { type: Exclude<T[number]['type'], undefined> }\n>['name'];\n\n/** The object a list of field mappings yields: one key per `name`, typed from its `type` (`string`, `number`, `boolean`, `strings` or `numbers`). Needs the list typed as a literal (`as const`) to narrow. */\nexport type TObjectFromFieldMappings<\n T extends readonly {\n name: string;\n type: string;\n [extra: string | symbol]: any;\n }[],\n> = {\n [K in T[number]['name']]: T extends {\n name: K;\n type: 'string';\n [extra: string | symbol]: any;\n }\n ? string\n : T extends { name: K; type: 'number'; [extra: string | symbol]: any }\n ? number\n : T extends { name: K; type: 'boolean'; [extra: string | symbol]: any }\n ? boolean\n : T extends { name: K; type: 'strings'; [extra: string | symbol]: any }\n ? string[]\n : T extends {\n name: K;\n type: 'numbers';\n [extra: string | symbol]: any;\n }\n ? number[]\n : never;\n};\n"]}
|
|
@@ -3,8 +3,6 @@ import type { TConstValue } from '../../../../common/types/index.js';
|
|
|
3
3
|
export declare class FetcherVariants {
|
|
4
4
|
static readonly NODE_FETCH = "node-fetch";
|
|
5
5
|
static readonly AXIOS = "axios";
|
|
6
|
-
static readonly SCHEME_SET: Set<string>;
|
|
7
|
-
static isValid(value: string): boolean;
|
|
8
6
|
}
|
|
9
7
|
/** Valid fetcher variant values. */
|
|
10
8
|
export type TFetcherVariant = TConstValue<typeof FetcherVariants>;
|
|
@@ -2,9 +2,5 @@
|
|
|
2
2
|
export class FetcherVariants {
|
|
3
3
|
static { this.NODE_FETCH = 'node-fetch'; }
|
|
4
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
5
|
}
|
|
10
6
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +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
|
|
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","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\n/** Valid fetcher variant values. */\nexport type TFetcherVariant = TConstValue<typeof FetcherVariants>;\n"]}
|
|
@@ -7,8 +7,6 @@ export declare class TcpClientStates {
|
|
|
7
7
|
static readonly UNAUTHORIZED = "unauthorized";
|
|
8
8
|
static readonly AUTHENTICATING = "authenticating";
|
|
9
9
|
static readonly AUTHENTICATED = "authenticated";
|
|
10
|
-
static readonly SCHEME_SET: Set<string>;
|
|
11
|
-
static isValid(value: string): boolean;
|
|
12
10
|
}
|
|
13
11
|
/** Valid TCP client state values. */
|
|
14
12
|
export type TTcpClientState = TConstValue<typeof TcpClientStates>;
|
|
@@ -7,14 +7,6 @@ export class TcpClientStates {
|
|
|
7
7
|
static { this.UNAUTHORIZED = 'unauthorized'; }
|
|
8
8
|
static { this.AUTHENTICATING = 'authenticating'; }
|
|
9
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
10
|
}
|
|
19
11
|
/** TCP or TLS server that tracks connected clients by id, with an optional authentication window, and reports connection events to the `onClient*` and `onServer*` callbacks. */
|
|
20
12
|
export class BaseNetworkTcpServer extends BaseHelper {
|
|
@@ -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":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAQ7D,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;;AAmDH,iLAAiL;AACjL,MAAM,OAAO,oBAIX,SAAQ,UAAU;IA8BlB,YACE,IAAsF;Q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ourcesContent":["import type { TConstValue } from '@/common/types';\nimport { type ValueOrPromise } from '@/common/types';\nimport { BaseHelper } from '@/modules/base';\nimport { getError } from '@/modules/error';\nimport { ParseUtility } from '@/utilities/parse.utility';\nimport { PromiseUtility } 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\n/** A client connected to `BaseNetworkTcpServer`: its `id`, `socket`, authentication `state`, `subscriptions` and `storage` (connect and authenticate times, the pending authenticate timer). */\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\n/** Options of `BaseNetworkTcpServer`. With `authenticateOptions.required`, `duration` (milliseconds, greater than 0) is how long a client has to authenticate before its socket is ended; the constructor throws without it. `createServerFn` builds the server, so one class serves plain and TLS. */\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\n/** TCP or TLS server that tracks connected clients by id, with an optional authentication window, and reports connection events to the `onClient*` and `onServer*` callbacks. */\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\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 = ParseUtility.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\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 PromiseUtility.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\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\n if (!client) {\n clearTimeout(authenticateTimeout);\n\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\n for (const client of clientsValues) {\n const { authenticateTimeout } = client.storage;\n\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\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\n if (!client) {\n this.logger.for('authenticateClient').error('Client NOT FOUND | ID: %s', id);\n\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\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\n return;\n }\n\n const { socket } = client;\n\n if (!socket.writable) {\n this.logger.for(this.emit.name).error('Client NOT WRITABLE | ID: %s', clientId);\n\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\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,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAQ7D,6DAA6D;AAC7D,MAAM,OAAO,eAAe;aACV,iBAAY,GAAG,cAAc,CAAC;aAC9B,mBAAc,GAAG,gBAAgB,CAAC;aAClC,kBAAa,GAAG,eAAe,CAAC;;AAmDlD,iLAAiL;AACjL,MAAM,OAAO,oBAIX,SAAQ,UAAU;IA8BlB,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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jD,MAAM,CAAC,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;gBAC5C,CAAC;gBAED,MAAM;YACR,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;YAE7E,OAAO;QACT,CAAC;QAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QAE1B,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;YAEhF,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;YAEJ,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 { ParseUtility } from '@/utilities/parse.utility';\nimport { PromiseUtility } 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\n/** Valid TCP client state values. */\nexport type TTcpClientState = TConstValue<typeof TcpClientStates>;\n\n/** A client connected to `BaseNetworkTcpServer`: its `id`, `socket`, authentication `state`, `subscriptions` and `storage` (connect and authenticate times, the pending authenticate timer). */\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\n/** Options of `BaseNetworkTcpServer`. With `authenticateOptions.required`, `duration` (milliseconds, greater than 0) is how long a client has to authenticate before its socket is ended; the constructor throws without it. `createServerFn` builds the server, so one class serves plain and TLS. */\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\n/** TCP or TLS server that tracks connected clients by id, with an optional authentication window, and reports connection events to the `onClient*` and `onServer*` callbacks. */\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\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 = ParseUtility.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\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 PromiseUtility.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\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\n if (!client) {\n clearTimeout(authenticateTimeout);\n\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\n for (const client of clientsValues) {\n const { authenticateTimeout } = client.storage;\n\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\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\n if (!client) {\n this.logger.for('authenticateClient').error('Client NOT FOUND | ID: %s', id);\n\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\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\n return;\n }\n\n const { socket } = client;\n\n if (!socket.writable) {\n this.logger.for(this.emit.name).error('Client NOT WRITABLE | ID: %s', clientId);\n\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\n return;\n }\n\n socket.write(payload);\n }\n}\n"]}
|
|
@@ -3,8 +3,6 @@ import { type TConstValue } from '../../../../../common/types/index.js';
|
|
|
3
3
|
export declare class UrlSchemes {
|
|
4
4
|
static readonly HTTP = "http:";
|
|
5
5
|
static readonly HTTPS = "https:";
|
|
6
|
-
static readonly SCHEME_SET: Set<string>;
|
|
7
|
-
static isValid(value: string): boolean;
|
|
8
6
|
}
|
|
9
7
|
/** A scheme a guarded fetch accepts: `http:` or `https:`. */
|
|
10
8
|
export type TUrlScheme = TConstValue<typeof UrlSchemes>;
|
|
@@ -2,10 +2,6 @@
|
|
|
2
2
|
export class UrlSchemes {
|
|
3
3
|
static { this.HTTP = 'http:'; }
|
|
4
4
|
static { this.HTTPS = 'https:'; }
|
|
5
|
-
static { this.SCHEME_SET = new Set([this.HTTP, this.HTTPS]); }
|
|
6
|
-
static isValid(value) {
|
|
7
|
-
return this.SCHEME_SET.has(value);
|
|
8
|
-
}
|
|
9
5
|
}
|
|
10
6
|
/** The values `IUrlSafetyPolicy` uses for a field the caller leaves unset; each is the safe choice. */
|
|
11
7
|
export class UrlSafetyDefaults {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/constants.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,MAAM,OAAO,UAAU;aACL,SAAI,GAAG,OAAO,CAAC;aACf,UAAK,GAAG,QAAQ,CAAC
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../src/modules/network/utilities/url-safety/common/constants.ts"],"names":[],"mappings":"AAEA,sGAAsG;AACtG,MAAM,OAAO,UAAU;aACL,SAAI,GAAG,OAAO,CAAC;aACf,UAAK,GAAG,QAAQ,CAAC;;AAKnC,uGAAuG;AACvG,MAAM,OAAO,iBAAiB;aACZ,oBAAe,GAAa,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;aAC/C,0BAAqB,GAAG,KAAK,CAAC;aAC9B,kBAAa,GAAG,CAAC,CAAC;aAClB,yBAAoB,GAAG,MAAM,CAAC;aAC9B,cAAS,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC","sourcesContent":["import { type TConstValue } from '@/common/types';\n\n/** The only schemes a guarded fetch will speak. `file:` and `gopher:` are the classic SSRF pivots. */\nexport class UrlSchemes {\n static readonly HTTP = 'http:';\n static readonly HTTPS = 'https:';\n}\n/** A scheme a guarded fetch accepts: `http:` or `https:`. */\nexport type TUrlScheme = TConstValue<typeof UrlSchemes>;\n\n/** The values `IUrlSafetyPolicy` uses for a field the caller leaves unset; each is the safe choice. */\nexport class UrlSafetyDefaults {\n static readonly ALLOWED_SCHEMES: string[] = [UrlSchemes.HTTPS];\n static readonly ALLOW_PRIVATE_ADDRESS = false;\n static readonly MAX_REDIRECTS = 3;\n static readonly TIMEOUT_MILLISECONDS = 10_000;\n static readonly MAX_BYTES = 10 * 1024 * 1024;\n}\n"]}
|
|
@@ -3,7 +3,7 @@ import { type IRedisHelper } from '../../redis/index.js';
|
|
|
3
3
|
import type { Job, Processor, Queue, QueueOptions, Worker, WorkerOptions } from 'bullmq';
|
|
4
4
|
import { type TBullQueueRole } from '../common/index.js';
|
|
5
5
|
/** Options for {@link BullMQHelper}. `role` decides whether a `Queue` or a `Worker` is built. */
|
|
6
|
-
export interface IBullMQOptions<TQueueElement =
|
|
6
|
+
export interface IBullMQOptions<TQueueElement = unknown, TQueueResult = unknown> {
|
|
7
7
|
queueName: string;
|
|
8
8
|
identifier: string;
|
|
9
9
|
role: TBullQueueRole;
|
|
@@ -12,27 +12,27 @@ export interface IBullMQOptions<TQueueElement = any, TQueueResult = any> {
|
|
|
12
12
|
module?: typeof import('bullmq');
|
|
13
13
|
/**
|
|
14
14
|
* Worker concurrency.
|
|
15
|
-
* @default
|
|
15
|
+
* @default BullMQDefaults.NUMBER_OF_WORKER
|
|
16
16
|
*/
|
|
17
17
|
numberOfWorker?: number;
|
|
18
18
|
/**
|
|
19
19
|
* How long a worker holds a job's lock, in milliseconds.
|
|
20
|
-
* @default
|
|
20
|
+
* @default BullMQDefaults.LOCK_DURATION_MS
|
|
21
21
|
*/
|
|
22
22
|
lockDuration?: number;
|
|
23
23
|
/** Merged over the framework defaults, under the fields the helper owns (`connection`) - see `queueOptionsFor`. */
|
|
24
24
|
queueOptions?: Omit<QueueOptions, 'connection'>;
|
|
25
25
|
/** Merged under the fields the helper owns (`connection`, `concurrency`, `lockDuration`) - see `workerOptionsFor`. */
|
|
26
26
|
workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;
|
|
27
|
-
onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<
|
|
28
|
-
onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result:
|
|
27
|
+
onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<TQueueResult>;
|
|
28
|
+
onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result: TQueueResult) => Promise<void>;
|
|
29
29
|
onWorkerDataFail?: (job: Job<TQueueElement, TQueueResult> | undefined, error: Error) => Promise<void>;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Wraps a BullMQ `Queue` or `Worker` (per `role`) on one Redis connection.
|
|
33
33
|
* Worker concurrency is `numberOfWorker`; `lockDuration` is in milliseconds.
|
|
34
34
|
*/
|
|
35
|
-
export declare class BullMQHelper<TQueueElement =
|
|
35
|
+
export declare class BullMQHelper<TQueueElement = unknown, TQueueResult = unknown> extends BaseHelper {
|
|
36
36
|
protected queueName: string;
|
|
37
37
|
protected role: TBullQueueRole;
|
|
38
38
|
protected redisConnection: IRedisHelper;
|
|
@@ -42,12 +42,12 @@ export declare class BullMQHelper<TQueueElement = any, TQueueResult = any> exten
|
|
|
42
42
|
protected lockDuration: number;
|
|
43
43
|
protected queueOptions?: Omit<QueueOptions, 'connection'>;
|
|
44
44
|
protected workerOptions?: Omit<WorkerOptions, 'connection' | 'concurrency' | 'lockDuration'>;
|
|
45
|
-
protected onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<
|
|
46
|
-
protected onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result:
|
|
45
|
+
protected onWorkerData?: (job: Job<TQueueElement, TQueueResult>) => Promise<TQueueResult>;
|
|
46
|
+
protected onWorkerDataCompleted?: (job: Job<TQueueElement, TQueueResult>, result: TQueueResult) => Promise<void>;
|
|
47
47
|
protected onWorkerDataFail?: (job: Job<TQueueElement, TQueueResult> | undefined, error: Error) => Promise<void>;
|
|
48
48
|
private readonly bullmqModule?;
|
|
49
49
|
constructor(options: IBullMQOptions<TQueueElement, TQueueResult>);
|
|
50
|
-
static newInstance<T =
|
|
50
|
+
static newInstance<T = unknown, R = unknown>(opts: IBullMQOptions<T, R>): BullMQHelper<T, R>;
|
|
51
51
|
/** Structural, never `instanceof`: ioredis is an optional peer, and a second copy fails `instanceof` anyway. */
|
|
52
52
|
protected isClusterClient(): boolean;
|
|
53
53
|
protected resolveQueueName(): string;
|
|
@@ -2,7 +2,7 @@ import { BaseHelper } from '../../base.js';
|
|
|
2
2
|
import { getError } from '../../error/index.js';
|
|
3
3
|
import { ErrorUtility } from '../../../utilities/error.utility.js';
|
|
4
4
|
import { ModuleUtility } from '../../../utilities/module.utility.js';
|
|
5
|
-
import { HookUtility } from '../common/index.js';
|
|
5
|
+
import { BullMQDefaults, BullQueueRoles, HookUtility } from '../common/index.js';
|
|
6
6
|
/**
|
|
7
7
|
* Wraps a BullMQ `Queue` or `Worker` (per `role`) on one Redis connection.
|
|
8
8
|
* Worker concurrency is `numberOfWorker`; `lockDuration` is in milliseconds.
|
|
@@ -10,9 +10,7 @@ import { HookUtility } from '../common/index.js';
|
|
|
10
10
|
export class BullMQHelper extends BaseHelper {
|
|
11
11
|
constructor(options) {
|
|
12
12
|
super({ scope: BullMQHelper.name, identifier: options.identifier });
|
|
13
|
-
|
|
14
|
-
this.lockDuration = 90 * 60 * 1000;
|
|
15
|
-
const { queueName, redisConnection, role, numberOfWorker = 1, lockDuration = 90 * 60 * 1000, queueOptions, workerOptions, onWorkerData, onWorkerDataCompleted, onWorkerDataFail, module, } = options;
|
|
13
|
+
const { queueName, redisConnection, role, numberOfWorker = BullMQDefaults.NUMBER_OF_WORKER, lockDuration = BullMQDefaults.LOCK_DURATION_MS, queueOptions, workerOptions, onWorkerData, onWorkerDataCompleted, onWorkerDataFail, module, } = options;
|
|
16
14
|
this.bullmqModule = module;
|
|
17
15
|
this.queueName = queueName;
|
|
18
16
|
this.role = role;
|
|
@@ -70,7 +68,8 @@ export class BullMQHelper extends BaseHelper {
|
|
|
70
68
|
removeOnFail: true,
|
|
71
69
|
},
|
|
72
70
|
...this.queueOptions,
|
|
73
|
-
|
|
71
|
+
// The helper's own client, never a duplicate: BullMQ marks a client it is handed as shared and never quits it, so a duplicate would leak one connection per queue and worker. BullMQ opens (and closes) its own blocking connection.
|
|
72
|
+
connection: this.redisConnection.getClient(),
|
|
74
73
|
};
|
|
75
74
|
}
|
|
76
75
|
/** Full `Worker` options: `this.workerOptions`, then the connection/concurrency/lock fields the helper owns - in that precedence order. */
|
|
@@ -80,7 +79,7 @@ export class BullMQHelper extends BaseHelper {
|
|
|
80
79
|
.debug('Building worker options | Queue: %s | ID: %s', opts.queueName, this.identifier);
|
|
81
80
|
return {
|
|
82
81
|
...this.workerOptions,
|
|
83
|
-
connection: this.redisConnection.
|
|
82
|
+
connection: this.redisConnection.getClient(),
|
|
84
83
|
concurrency: this.numberOfWorker,
|
|
85
84
|
lockDuration: this.lockDuration,
|
|
86
85
|
};
|
|
@@ -111,8 +110,7 @@ export class BullMQHelper extends BaseHelper {
|
|
|
111
110
|
queueName,
|
|
112
111
|
processor: async (job) => {
|
|
113
112
|
if (this.onWorkerData) {
|
|
114
|
-
|
|
115
|
-
return result;
|
|
113
|
+
return this.onWorkerData(job);
|
|
116
114
|
}
|
|
117
115
|
const { id, name, data } = job;
|
|
118
116
|
this.logger
|
|
@@ -150,11 +148,11 @@ export class BullMQHelper extends BaseHelper {
|
|
|
150
148
|
return;
|
|
151
149
|
}
|
|
152
150
|
switch (this.role) {
|
|
153
|
-
case
|
|
151
|
+
case BullQueueRoles.QUEUE: {
|
|
154
152
|
this.configureQueue();
|
|
155
153
|
break;
|
|
156
154
|
}
|
|
157
|
-
case
|
|
155
|
+
case BullQueueRoles.WORKER: {
|
|
158
156
|
this.configureWorker();
|
|
159
157
|
break;
|
|
160
158
|
}
|