@forklaunch/core 0.5.6 → 0.6.0

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.
Files changed (45) hide show
  1. package/lib/__test__/index.d.mts +11 -0
  2. package/lib/__test__/index.d.ts +11 -0
  3. package/lib/__test__/index.js +54 -0
  4. package/lib/__test__/index.js.map +1 -0
  5. package/lib/__test__/index.mjs +30 -0
  6. package/lib/__test__/index.mjs.map +1 -0
  7. package/lib/{cache → src/cache}/index.d.mts +1 -1
  8. package/lib/{cache → src/cache}/index.d.ts +1 -1
  9. package/lib/src/cache/index.js.map +1 -0
  10. package/lib/src/cache/index.mjs.map +1 -0
  11. package/lib/{controllers → src/controllers}/index.d.mts +2 -0
  12. package/lib/{controllers → src/controllers}/index.d.ts +2 -0
  13. package/lib/src/controllers/index.js.map +1 -0
  14. package/lib/{dtoMapper → src/dtoMapper}/index.d.mts +67 -1
  15. package/lib/{dtoMapper → src/dtoMapper}/index.d.ts +67 -1
  16. package/lib/{dtoMapper → src/dtoMapper}/index.js +36 -2
  17. package/lib/src/dtoMapper/index.js.map +1 -0
  18. package/lib/{dtoMapper → src/dtoMapper}/index.mjs +33 -1
  19. package/lib/src/dtoMapper/index.mjs.map +1 -0
  20. package/lib/{http → src/http}/index.d.mts +2 -2
  21. package/lib/{http → src/http}/index.d.ts +2 -2
  22. package/lib/{http → src/http}/index.js +8 -3
  23. package/lib/{http → src/http}/index.js.map +1 -1
  24. package/lib/{http → src/http}/index.mjs +9 -4
  25. package/lib/src/http/index.mjs.map +1 -0
  26. package/lib/{services → src/services}/index.d.mts +43 -13
  27. package/lib/{services → src/services}/index.d.ts +43 -13
  28. package/lib/{services → src/services}/index.js +56 -12
  29. package/lib/src/services/index.js.map +1 -0
  30. package/lib/{services → src/services}/index.mjs +55 -12
  31. package/lib/src/services/index.mjs.map +1 -0
  32. package/package.json +51 -45
  33. package/lib/cache/index.js.map +0 -1
  34. package/lib/cache/index.mjs.map +0 -1
  35. package/lib/controllers/index.js.map +0 -1
  36. package/lib/dtoMapper/index.js.map +0 -1
  37. package/lib/dtoMapper/index.mjs.map +0 -1
  38. package/lib/http/index.mjs.map +0 -1
  39. package/lib/services/index.js.map +0 -1
  40. package/lib/services/index.mjs.map +0 -1
  41. /package/lib/{cache → src/cache}/index.js +0 -0
  42. /package/lib/{cache → src/cache}/index.mjs +0 -0
  43. /package/lib/{controllers → src/controllers}/index.js +0 -0
  44. /package/lib/{controllers → src/controllers}/index.mjs +0 -0
  45. /package/lib/{controllers → src/controllers}/index.mjs.map +0 -0
@@ -0,0 +1,11 @@
1
+ import { IdiomaticSchema, Schema } from '@forklaunch/validator';
2
+ import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
3
+ import { ZodSchemaValidator } from '@forklaunch/validator/zod';
4
+
5
+ declare function testSchemaEquality<Z extends IdiomaticSchema<ZodSchemaValidator>, T extends IdiomaticSchema<TypeboxSchemaValidator>>(zodSchema: Z, typeBoxSchema: T, testData: Schema<Z, ZodSchemaValidator>): Schema<Z, ZodSchemaValidator> extends Schema<T, TypeboxSchemaValidator> ? Schema<T, TypeboxSchemaValidator> extends Schema<Z, ZodSchemaValidator> ? true : false : false;
6
+ declare enum DummyEnum {
7
+ A = "A",
8
+ B = "B"
9
+ }
10
+
11
+ export { DummyEnum, testSchemaEquality };
@@ -0,0 +1,11 @@
1
+ import { IdiomaticSchema, Schema } from '@forklaunch/validator';
2
+ import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
3
+ import { ZodSchemaValidator } from '@forklaunch/validator/zod';
4
+
5
+ declare function testSchemaEquality<Z extends IdiomaticSchema<ZodSchemaValidator>, T extends IdiomaticSchema<TypeboxSchemaValidator>>(zodSchema: Z, typeBoxSchema: T, testData: Schema<Z, ZodSchemaValidator>): Schema<Z, ZodSchemaValidator> extends Schema<T, TypeboxSchemaValidator> ? Schema<T, TypeboxSchemaValidator> extends Schema<Z, ZodSchemaValidator> ? true : false : false;
6
+ declare enum DummyEnum {
7
+ A = "A",
8
+ B = "B"
9
+ }
10
+
11
+ export { DummyEnum, testSchemaEquality };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // __test__/index.ts
21
+ var test_exports = {};
22
+ __export(test_exports, {
23
+ DummyEnum: () => DummyEnum,
24
+ testSchemaEquality: () => testSchemaEquality
25
+ });
26
+ module.exports = __toCommonJS(test_exports);
27
+
28
+ // __test__/utils/schemaEquality.ts
29
+ var import_common = require("@forklaunch/common");
30
+ var import_typebox = require("@forklaunch/validator/typebox");
31
+ var import_zod = require("@forklaunch/validator/zod");
32
+ function testSchemaEquality(zodSchema, typeBoxSchema, testData) {
33
+ const zodParseResult = (0, import_zod.parse)(zodSchema, testData);
34
+ const typeboxParseResult = (0, import_typebox.parse)(typeBoxSchema, testData);
35
+ const isEqual = JSON.stringify(
36
+ zodParseResult.ok ? (0, import_common.sortObjectKeys)(
37
+ zodParseResult.value
38
+ ) : "-1"
39
+ ) === JSON.stringify(
40
+ typeboxParseResult.ok ? (0, import_common.sortObjectKeys)(typeboxParseResult.value) : "1"
41
+ );
42
+ return isEqual;
43
+ }
44
+ var DummyEnum = /* @__PURE__ */ ((DummyEnum2) => {
45
+ DummyEnum2["A"] = "A";
46
+ DummyEnum2["B"] = "B";
47
+ return DummyEnum2;
48
+ })(DummyEnum || {});
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ DummyEnum,
52
+ testSchemaEquality
53
+ });
54
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../__test__/index.ts","../../__test__/utils/schemaEquality.ts"],"sourcesContent":["export * from './utils/schemaEquality';\n","import { sortObjectKeys } from '@forklaunch/common';\nimport { IdiomaticSchema } from '@forklaunch/validator';\n\nimport { Schema } from '@forklaunch/validator';\nimport {\n TypeboxSchemaValidator,\n parse as typeboxParse\n} from '@forklaunch/validator/typebox';\nimport {\n ZodSchemaValidator,\n parse as zodParse\n} from '@forklaunch/validator/zod';\n\nexport function testSchemaEquality<\n Z extends IdiomaticSchema<ZodSchemaValidator>,\n T extends IdiomaticSchema<TypeboxSchemaValidator>\n>(zodSchema: Z, typeBoxSchema: T, testData: Schema<Z, ZodSchemaValidator>) {\n const zodParseResult = zodParse(zodSchema, testData);\n const typeboxParseResult = typeboxParse(typeBoxSchema, testData);\n\n const isEqual =\n JSON.stringify(\n zodParseResult.ok\n ? sortObjectKeys(\n zodParseResult.value as unknown as Record<string, unknown>\n )\n : '-1'\n ) ===\n JSON.stringify(\n typeboxParseResult.ok ? sortObjectKeys(typeboxParseResult.value) : '1'\n );\n\n return isEqual as Schema<Z, ZodSchemaValidator> extends Schema<\n T,\n TypeboxSchemaValidator\n >\n ? Schema<T, TypeboxSchemaValidator> extends Schema<Z, ZodSchemaValidator>\n ? true\n : false\n : false;\n}\n\nexport enum DummyEnum {\n A = 'A',\n B = 'B'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAA+B;AAI/B,qBAGO;AACP,iBAGO;AAEA,SAAS,mBAGd,WAAc,eAAkB,UAAyC;AACzE,QAAM,qBAAiB,WAAAA,OAAS,WAAW,QAAQ;AACnD,QAAM,yBAAqB,eAAAC,OAAa,eAAe,QAAQ;AAE/D,QAAM,UACJ,KAAK;AAAA,IACH,eAAe,SACX;AAAA,MACE,eAAe;AAAA,IACjB,IACA;AAAA,EACN,MACA,KAAK;AAAA,IACH,mBAAmB,SAAK,8BAAe,mBAAmB,KAAK,IAAI;AAAA,EACrE;AAEF,SAAO;AAQT;AAEO,IAAK,YAAL,kBAAKC,eAAL;AACL,EAAAA,WAAA,OAAI;AACJ,EAAAA,WAAA,OAAI;AAFM,SAAAA;AAAA,GAAA;","names":["zodParse","typeboxParse","DummyEnum"]}
@@ -0,0 +1,30 @@
1
+ // __test__/utils/schemaEquality.ts
2
+ import { sortObjectKeys } from "@forklaunch/common";
3
+ import {
4
+ parse as typeboxParse
5
+ } from "@forklaunch/validator/typebox";
6
+ import {
7
+ parse as zodParse
8
+ } from "@forklaunch/validator/zod";
9
+ function testSchemaEquality(zodSchema, typeBoxSchema, testData) {
10
+ const zodParseResult = zodParse(zodSchema, testData);
11
+ const typeboxParseResult = typeboxParse(typeBoxSchema, testData);
12
+ const isEqual = JSON.stringify(
13
+ zodParseResult.ok ? sortObjectKeys(
14
+ zodParseResult.value
15
+ ) : "-1"
16
+ ) === JSON.stringify(
17
+ typeboxParseResult.ok ? sortObjectKeys(typeboxParseResult.value) : "1"
18
+ );
19
+ return isEqual;
20
+ }
21
+ var DummyEnum = /* @__PURE__ */ ((DummyEnum2) => {
22
+ DummyEnum2["A"] = "A";
23
+ DummyEnum2["B"] = "B";
24
+ return DummyEnum2;
25
+ })(DummyEnum || {});
26
+ export {
27
+ DummyEnum,
28
+ testSchemaEquality
29
+ };
30
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../__test__/utils/schemaEquality.ts"],"sourcesContent":["import { sortObjectKeys } from '@forklaunch/common';\nimport { IdiomaticSchema } from '@forklaunch/validator';\n\nimport { Schema } from '@forklaunch/validator';\nimport {\n TypeboxSchemaValidator,\n parse as typeboxParse\n} from '@forklaunch/validator/typebox';\nimport {\n ZodSchemaValidator,\n parse as zodParse\n} from '@forklaunch/validator/zod';\n\nexport function testSchemaEquality<\n Z extends IdiomaticSchema<ZodSchemaValidator>,\n T extends IdiomaticSchema<TypeboxSchemaValidator>\n>(zodSchema: Z, typeBoxSchema: T, testData: Schema<Z, ZodSchemaValidator>) {\n const zodParseResult = zodParse(zodSchema, testData);\n const typeboxParseResult = typeboxParse(typeBoxSchema, testData);\n\n const isEqual =\n JSON.stringify(\n zodParseResult.ok\n ? sortObjectKeys(\n zodParseResult.value as unknown as Record<string, unknown>\n )\n : '-1'\n ) ===\n JSON.stringify(\n typeboxParseResult.ok ? sortObjectKeys(typeboxParseResult.value) : '1'\n );\n\n return isEqual as Schema<Z, ZodSchemaValidator> extends Schema<\n T,\n TypeboxSchemaValidator\n >\n ? Schema<T, TypeboxSchemaValidator> extends Schema<Z, ZodSchemaValidator>\n ? true\n : false\n : false;\n}\n\nexport enum DummyEnum {\n A = 'A',\n B = 'B'\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAI/B;AAAA,EAEE,SAAS;AAAA,OACJ;AACP;AAAA,EAEE,SAAS;AAAA,OACJ;AAEA,SAAS,mBAGd,WAAc,eAAkB,UAAyC;AACzE,QAAM,iBAAiB,SAAS,WAAW,QAAQ;AACnD,QAAM,qBAAqB,aAAa,eAAe,QAAQ;AAE/D,QAAM,UACJ,KAAK;AAAA,IACH,eAAe,KACX;AAAA,MACE,eAAe;AAAA,IACjB,IACA;AAAA,EACN,MACA,KAAK;AAAA,IACH,mBAAmB,KAAK,eAAe,mBAAmB,KAAK,IAAI;AAAA,EACrE;AAEF,SAAO;AAQT;AAEO,IAAK,YAAL,kBAAKA,eAAL;AACL,EAAAA,WAAA,OAAI;AACJ,EAAAA,WAAA,OAAI;AAFM,SAAAA;AAAA,GAAA;","names":["DummyEnum"]}
@@ -1,5 +1,5 @@
1
1
  import { RedisClientOptions } from 'redis';
2
- import { O as OpenTelemetryCollector, M as MetricsDefinition } from '../openTelemetryCollector-CWrfzmmW.mjs';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition } from '../../openTelemetryCollector-CWrfzmmW.mjs';
3
3
  import '@opentelemetry/api';
4
4
  import 'pino';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { RedisClientOptions } from 'redis';
2
- import { O as OpenTelemetryCollector, M as MetricsDefinition } from '../openTelemetryCollector-CWrfzmmW.js';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition } from '../../openTelemetryCollector-CWrfzmmW.js';
3
3
  import '@opentelemetry/api';
4
4
  import 'pino';
5
5
 
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/cache/index.ts","../../../src/cache/redisTtlCache.ts","../../../src/cache/utils/cacheKey.ts"],"sourcesContent":["export * from './interfaces/ttlCache.interface';\nexport * from './redisTtlCache';\nexport * from './types/ttlCacheRecord.types';\nexport * from './utils/cacheKey';\n","import { RedisClientOptions, createClient } from 'redis';\nimport { TtlCache } from './interfaces/ttlCache.interface';\nimport { TtlCacheRecord } from './types/ttlCacheRecord.types';\nimport { OpenTelemetryCollector } from '../http/telemetry/openTelemetryCollector';\nimport { MetricsDefinition } from '../http';\n\n/**\n * Class representing a Redis-based TTL (Time-To-Live) cache.\n * Implements the TtlCache interface.\n */\nexport class RedisTtlCache implements TtlCache {\n private client;\n\n /**\n * Creates an instance of RedisTtlCache.\n *\n * @param {number} ttlMilliseconds - The default TTL in milliseconds.\n * @param {RedisClientOptions} [hostingOptions] - The Redis client options.\n */\n constructor(\n private ttlMilliseconds: number,\n private openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,\n hostingOptions?: RedisClientOptions\n ) {\n // Connects to localhost:6379 by default\n // url usage: redis[s]://[[username][:password]@][host][:port][/db-number]\n this.client = createClient(hostingOptions);\n this.client.on('error', (err) => openTelemetryCollector.error(err));\n this.client.connect().catch(openTelemetryCollector.error);\n }\n\n /**\n * Puts a record into the Redis cache.\n *\n * @param {TtlCacheRecord} param0 - The cache record to put into the cache.\n * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.\n */\n async putRecord<T>({\n key,\n value,\n ttlMilliseconds = this.ttlMilliseconds\n }: TtlCacheRecord<T>): Promise<void> {\n await this.client.set(key, JSON.stringify(value), {\n PX: ttlMilliseconds\n });\n }\n\n /**\n * Deletes a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to delete.\n * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.\n */\n async deleteRecord(cacheRecordKey: string): Promise<void> {\n await this.client.del(cacheRecordKey);\n }\n\n /**\n * Reads a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to read.\n * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.\n * @throws {Error} - Throws an error if the record is not found.\n */\n async readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>> {\n const value = await this.client.get(cacheRecordKey);\n if (value === null) {\n throw new Error(`Record not found for key: ${cacheRecordKey}`);\n }\n const ttl = await this.client.ttl(cacheRecordKey); // Fetch TTL from Redis\n return {\n key: cacheRecordKey,\n value: JSON.parse(value),\n ttlMilliseconds: ttl * 1000\n };\n }\n\n /**\n * Lists the keys in the Redis cache that match a pattern prefix.\n *\n * @param {string} pattern_prefix - The pattern prefix to match.\n * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.\n */\n async listKeys(pattern_prefix: string): Promise<string[]> {\n const keys = await this.client.keys(pattern_prefix + '*');\n return keys;\n }\n\n /**\n * Peeks at a record in the Redis cache to check if it exists.\n *\n * @param {string} cacheRecordKey - The key of the cache record to peek at.\n * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.\n */\n async peekRecord(cacheRecordKey: string): Promise<boolean> {\n const result = await this.client.exists(cacheRecordKey);\n return result === 1;\n }\n\n /**\n * Disconnects the Redis client.\n *\n * @returns {Promise<void>} - A promise that resolves when the client is disconnected.\n */\n async disconnect(): Promise<void> {\n await this.client.quit();\n }\n\n /**\n * Gets the default TTL (Time-To-Live) in milliseconds.\n *\n * @returns {number} - The TTL in milliseconds.\n */\n getTtlMilliseconds(): number {\n return this.ttlMilliseconds;\n }\n}\n","export const createCacheKey = (cacheKeyPrefix: string) => (id: string) => {\n return `${cacheKeyPrefix}:${id}`;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAiD;AAU1C,IAAM,gBAAN,MAAwC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YACU,iBACA,wBACR,gBACA;AAHQ;AACA;AAKR,SAAK,aAAS,2BAAa,cAAc;AACzC,SAAK,OAAO,GAAG,SAAS,CAAC,QAAQ,uBAAuB,MAAM,GAAG,CAAC;AAClE,SAAK,OAAO,QAAQ,EAAE,MAAM,uBAAuB,KAAK;AAAA,EAC1D;AAAA,EAlBQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BR,MAAM,UAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA,kBAAkB,KAAK;AAAA,EACzB,GAAqC;AACnC,UAAM,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,GAAG;AAAA,MAChD,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aAAa,gBAAuC;AACxD,UAAM,KAAK,OAAO,IAAI,cAAc;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAc,gBAAoD;AACtE,UAAM,QAAQ,MAAM,KAAK,OAAO,IAAI,cAAc;AAClD,QAAI,UAAU,MAAM;AAClB,YAAM,IAAI,MAAM,6BAA6B,cAAc,EAAE;AAAA,IAC/D;AACA,UAAM,MAAM,MAAM,KAAK,OAAO,IAAI,cAAc;AAChD,WAAO;AAAA,MACL,KAAK;AAAA,MACL,OAAO,KAAK,MAAM,KAAK;AAAA,MACvB,iBAAiB,MAAM;AAAA,IACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,gBAA2C;AACxD,UAAM,OAAO,MAAM,KAAK,OAAO,KAAK,iBAAiB,GAAG;AACxD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,gBAA0C;AACzD,UAAM,SAAS,MAAM,KAAK,OAAO,OAAO,cAAc;AACtD,WAAO,WAAW;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAA4B;AAChC,UAAM,KAAK,OAAO,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;;;ACpHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/cache/redisTtlCache.ts","../../../src/cache/utils/cacheKey.ts"],"sourcesContent":["import { RedisClientOptions, createClient } from 'redis';\nimport { TtlCache } from './interfaces/ttlCache.interface';\nimport { TtlCacheRecord } from './types/ttlCacheRecord.types';\nimport { OpenTelemetryCollector } from '../http/telemetry/openTelemetryCollector';\nimport { MetricsDefinition } from '../http';\n\n/**\n * Class representing a Redis-based TTL (Time-To-Live) cache.\n * Implements the TtlCache interface.\n */\nexport class RedisTtlCache implements TtlCache {\n private client;\n\n /**\n * Creates an instance of RedisTtlCache.\n *\n * @param {number} ttlMilliseconds - The default TTL in milliseconds.\n * @param {RedisClientOptions} [hostingOptions] - The Redis client options.\n */\n constructor(\n private ttlMilliseconds: number,\n private openTelemetryCollector: OpenTelemetryCollector<MetricsDefinition>,\n hostingOptions?: RedisClientOptions\n ) {\n // Connects to localhost:6379 by default\n // url usage: redis[s]://[[username][:password]@][host][:port][/db-number]\n this.client = createClient(hostingOptions);\n this.client.on('error', (err) => openTelemetryCollector.error(err));\n this.client.connect().catch(openTelemetryCollector.error);\n }\n\n /**\n * Puts a record into the Redis cache.\n *\n * @param {TtlCacheRecord} param0 - The cache record to put into the cache.\n * @returns {Promise<void>} - A promise that resolves when the record is put into the cache.\n */\n async putRecord<T>({\n key,\n value,\n ttlMilliseconds = this.ttlMilliseconds\n }: TtlCacheRecord<T>): Promise<void> {\n await this.client.set(key, JSON.stringify(value), {\n PX: ttlMilliseconds\n });\n }\n\n /**\n * Deletes a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to delete.\n * @returns {Promise<void>} - A promise that resolves when the record is deleted from the cache.\n */\n async deleteRecord(cacheRecordKey: string): Promise<void> {\n await this.client.del(cacheRecordKey);\n }\n\n /**\n * Reads a record from the Redis cache.\n *\n * @param {string} cacheRecordKey - The key of the cache record to read.\n * @returns {Promise<TtlCacheRecord>} - A promise that resolves with the cache record.\n * @throws {Error} - Throws an error if the record is not found.\n */\n async readRecord<T>(cacheRecordKey: string): Promise<TtlCacheRecord<T>> {\n const value = await this.client.get(cacheRecordKey);\n if (value === null) {\n throw new Error(`Record not found for key: ${cacheRecordKey}`);\n }\n const ttl = await this.client.ttl(cacheRecordKey); // Fetch TTL from Redis\n return {\n key: cacheRecordKey,\n value: JSON.parse(value),\n ttlMilliseconds: ttl * 1000\n };\n }\n\n /**\n * Lists the keys in the Redis cache that match a pattern prefix.\n *\n * @param {string} pattern_prefix - The pattern prefix to match.\n * @returns {Promise<string[]>} - A promise that resolves with an array of keys matching the pattern prefix.\n */\n async listKeys(pattern_prefix: string): Promise<string[]> {\n const keys = await this.client.keys(pattern_prefix + '*');\n return keys;\n }\n\n /**\n * Peeks at a record in the Redis cache to check if it exists.\n *\n * @param {string} cacheRecordKey - The key of the cache record to peek at.\n * @returns {Promise<boolean>} - A promise that resolves with a boolean indicating if the record exists.\n */\n async peekRecord(cacheRecordKey: string): Promise<boolean> {\n const result = await this.client.exists(cacheRecordKey);\n return result === 1;\n }\n\n /**\n * Disconnects the Redis client.\n *\n * @returns {Promise<void>} - A promise that resolves when the client is disconnected.\n */\n async disconnect(): Promise<void> {\n await this.client.quit();\n }\n\n /**\n * Gets the default TTL (Time-To-Live) in milliseconds.\n *\n * @returns {number} - The TTL in milliseconds.\n */\n getTtlMilliseconds(): number {\n return this.ttlMilliseconds;\n }\n}\n","export const createCacheKey = (cacheKeyPrefix: string) => (id: string) => {\n return `${cacheKeyPrefix}:${id}`;\n};\n"],"mappings":";AAAA,SAA6B,oBAAoB;AAU1C,IAAM,gBAAN,MAAwC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YACU,iBACA,wBACR,gBACA;AAHQ;AACA;AAKR,SAAK,SAAS,aAAa,cAAc;AACzC,SAAK,OAAO,GAAG,SAAS,CAAC,QAAQ,uBAAuB,MAAM,GAAG,CAAC;AAClE,SAAK,OAAO,QAAQ,EAAE,MAAM,uBAAuB,KAAK;AAAA,EAC1D;AAAA,EAlBQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA0BR,MAAM,UAAa;AAAA,IACjB;AAAA,IACA;AAAA,IACA,kBAAkB,KAAK;AAAA,EACzB,GAAqC;AACnC,UAAM,KAAK,OAAO,IAAI,KAAK,KAAK,UAAU,KAAK,GAAG;AAAA,MAChD,IAAI;AAAA,IACN,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,aAAa,gBAAuC;AACxD,UAAM,KAAK,OAAO,IAAI,cAAc;AAAA,EACtC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAM,WAAc,gBAAoD;AACtE,UAAM,QAAQ,MAAM,KAAK,OAAO,IAAI,cAAc;AAClD,QAAI,UAAU,MAAM;AAClB,YAAM,IAAI,MAAM,6BAA6B,cAAc,EAAE;AAAA,IAC/D;AACA,UAAM,MAAM,MAAM,KAAK,OAAO,IAAI,cAAc;AAChD,WAAO;AAAA,MACL,KAAK;AAAA,MACL,OAAO,KAAK,MAAM,KAAK;AAAA,MACvB,iBAAiB,MAAM;AAAA,IACzB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,SAAS,gBAA2C;AACxD,UAAM,OAAO,MAAM,KAAK,OAAO,KAAK,iBAAiB,GAAG;AACxD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,WAAW,gBAA0C;AACzD,UAAM,SAAS,MAAM,KAAK,OAAO,OAAO,cAAc;AACtD,WAAO,WAAW;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,aAA4B;AAChC,UAAM,KAAK,OAAO,KAAK;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,qBAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;;;ACpHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
@@ -5,6 +5,8 @@ type Controller<Service, BaseRequest, BaseResponse, NextFunction, ParsedQs> = {
5
5
  readonly __response?: BaseResponse;
6
6
  readonly __next?: NextFunction;
7
7
  readonly __qs?: ParsedQs;
8
+ } & {
9
+ [K: string]: unknown;
8
10
  };
9
11
 
10
12
  export type { Controller };
@@ -5,6 +5,8 @@ type Controller<Service, BaseRequest, BaseResponse, NextFunction, ParsedQs> = {
5
5
  readonly __response?: BaseResponse;
6
6
  readonly __next?: NextFunction;
7
7
  readonly __qs?: ParsedQs;
8
+ } & {
9
+ [K: string]: unknown;
8
10
  };
9
11
 
10
12
  export type { Controller };
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/controllers/index.ts"],"sourcesContent":["export * from './interfaces/controller.interface';\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,4 +1,7 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
2
+ import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
3
+ import { ZodSchemaValidator } from '@forklaunch/validator/zod';
4
+ import { InstanceTypeRecord } from '@forklaunch/common';
2
5
 
3
6
  /**
4
7
  * Interface representing a constructor for an entity mapper.
@@ -24,6 +27,30 @@ interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
24
27
  * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
25
28
  */
26
29
  type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
30
+ /**
31
+ * Type representing a response DTO mapper for an entity mapper.
32
+ *
33
+ * @template SchemaValidator - A type that extends AnySchemaValidator.
34
+ * @template Dto - The type of the DTO object.
35
+ * @template Entity - The type of the entity object.
36
+ */
37
+ type ResponseDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, SerializeEntityToDto = unknown> = new (schemaValidator: SchemaValidator) => {
38
+ dto: Dto;
39
+ _Entity: Entity;
40
+ serializeEntityToDto: SerializeEntityToDto;
41
+ };
42
+ /**
43
+ * Type representing a request DTO mapper for an entity mapper.
44
+ *
45
+ * @template SV - A type that extends AnySchemaValidator.
46
+ * @template Dto - The type of the DTO object.
47
+ * @template Entity - The type of the entity object.
48
+ */
49
+ type RequestDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, DeserializeDtoToEntity = unknown> = new (schemaValidator: SchemaValidator) => {
50
+ dto: Dto;
51
+ _Entity: Entity;
52
+ deserializeDtoToEntity: DeserializeDtoToEntity;
53
+ };
27
54
 
28
55
  /**
29
56
  * Abstract class representing a base entity mapper.
@@ -211,4 +238,43 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
211
238
  static serializeEntityToDto<T extends ResponseDtoMapper<unknown, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): DtoType;
212
239
  }
213
240
 
214
- export { RequestDtoMapper, ResponseDtoMapper };
241
+ type SchemasByValidator<T extends AnySchemaValidator, TypeBoxSchemas extends (...args: never[]) => unknown, ZodSchemas extends (...args: never[]) => unknown> = T extends TypeboxSchemaValidator ? ReturnType<TypeBoxSchemas> : T extends ZodSchemaValidator ? ReturnType<ZodSchemas> : never;
242
+
243
+ declare function serviceSchemaResolver<TypeBoxSchemas extends (uuidId: boolean) => unknown, ZodSchemas extends (uuidId: boolean) => unknown>(TypeBoxSchemas: TypeBoxSchemas, ZodSchemas: ZodSchemas): <SchemaValidator extends AnySchemaValidator>(schemaValidator: SchemaValidator, uuidId: boolean) => SchemasByValidator<SchemaValidator, TypeBoxSchemas, ZodSchemas>;
244
+
245
+ type AllAfterFirstParameters<T> = T extends (first: never, ...args: infer U) => unknown ? U : never[];
246
+ type InternalDtoMapper<DtoMapper extends Record<string, {
247
+ dto: unknown;
248
+ _Entity: unknown;
249
+ serializeEntityToDto: unknown;
250
+ } | {
251
+ dto: unknown;
252
+ _Entity: unknown;
253
+ deserializeDtoToEntity: unknown;
254
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>> = {
255
+ [K in keyof DtoMapper]: DtoMapper[K] extends {
256
+ dto: unknown;
257
+ _Entity: unknown;
258
+ serializeEntityToDto: unknown;
259
+ } ? {
260
+ serializeEntityToDto: (entity: Entities[K], ...additionalArgs: AllAfterFirstParameters<DtoMapper[K]['serializeEntityToDto']>) => Dto[K];
261
+ } : DtoMapper[K] extends {
262
+ dto: unknown;
263
+ _Entity: unknown;
264
+ deserializeDtoToEntity: unknown;
265
+ } ? {
266
+ deserializeDtoToEntity: (dto: Dto[K], ...additionalArgs: AllAfterFirstParameters<DtoMapper[K]['deserializeDtoToEntity']>) => Entities[K];
267
+ } : never;
268
+ };
269
+
270
+ declare function transformIntoInternalDtoMapper<SchemaValidator extends AnySchemaValidator, DtoMapper extends Record<string, new (schemaValidator: SchemaValidator) => {
271
+ dto: unknown;
272
+ _Entity: unknown;
273
+ serializeEntityToDto: unknown;
274
+ } | {
275
+ dto: unknown;
276
+ _Entity: unknown;
277
+ deserializeDtoToEntity: unknown;
278
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>>(dtoMappers: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto>;
279
+
280
+ export { type DtoMapperSchemaValidatorObject, type InternalDtoMapper, RequestDtoMapper, type RequestDtoMapperConstructor, ResponseDtoMapper, type ResponseDtoMapperConstructor, type SchemasByValidator, serviceSchemaResolver, transformIntoInternalDtoMapper };
@@ -1,4 +1,7 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
2
+ import { TypeboxSchemaValidator } from '@forklaunch/validator/typebox';
3
+ import { ZodSchemaValidator } from '@forklaunch/validator/zod';
4
+ import { InstanceTypeRecord } from '@forklaunch/common';
2
5
 
3
6
  /**
4
7
  * Interface representing a constructor for an entity mapper.
@@ -24,6 +27,30 @@ interface DtoMapperConstructor<T, SV extends AnySchemaValidator> {
24
27
  * @typedef {SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>} DtoMapperSchemaValidatorObject
25
28
  */
26
29
  type DtoMapperSchemaValidatorObject<SV extends AnySchemaValidator> = SV['_ValidSchemaObject'] | UnboxedObjectSchema<SV>;
30
+ /**
31
+ * Type representing a response DTO mapper for an entity mapper.
32
+ *
33
+ * @template SchemaValidator - A type that extends AnySchemaValidator.
34
+ * @template Dto - The type of the DTO object.
35
+ * @template Entity - The type of the entity object.
36
+ */
37
+ type ResponseDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, SerializeEntityToDto = unknown> = new (schemaValidator: SchemaValidator) => {
38
+ dto: Dto;
39
+ _Entity: Entity;
40
+ serializeEntityToDto: SerializeEntityToDto;
41
+ };
42
+ /**
43
+ * Type representing a request DTO mapper for an entity mapper.
44
+ *
45
+ * @template SV - A type that extends AnySchemaValidator.
46
+ * @template Dto - The type of the DTO object.
47
+ * @template Entity - The type of the entity object.
48
+ */
49
+ type RequestDtoMapperConstructor<SchemaValidator extends AnySchemaValidator, Dto, Entity, DeserializeDtoToEntity = unknown> = new (schemaValidator: SchemaValidator) => {
50
+ dto: Dto;
51
+ _Entity: Entity;
52
+ deserializeDtoToEntity: DeserializeDtoToEntity;
53
+ };
27
54
 
28
55
  /**
29
56
  * Abstract class representing a base entity mapper.
@@ -211,4 +238,43 @@ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator>
211
238
  static serializeEntityToDto<T extends ResponseDtoMapper<unknown, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): DtoType;
212
239
  }
213
240
 
214
- export { RequestDtoMapper, ResponseDtoMapper };
241
+ type SchemasByValidator<T extends AnySchemaValidator, TypeBoxSchemas extends (...args: never[]) => unknown, ZodSchemas extends (...args: never[]) => unknown> = T extends TypeboxSchemaValidator ? ReturnType<TypeBoxSchemas> : T extends ZodSchemaValidator ? ReturnType<ZodSchemas> : never;
242
+
243
+ declare function serviceSchemaResolver<TypeBoxSchemas extends (uuidId: boolean) => unknown, ZodSchemas extends (uuidId: boolean) => unknown>(TypeBoxSchemas: TypeBoxSchemas, ZodSchemas: ZodSchemas): <SchemaValidator extends AnySchemaValidator>(schemaValidator: SchemaValidator, uuidId: boolean) => SchemasByValidator<SchemaValidator, TypeBoxSchemas, ZodSchemas>;
244
+
245
+ type AllAfterFirstParameters<T> = T extends (first: never, ...args: infer U) => unknown ? U : never[];
246
+ type InternalDtoMapper<DtoMapper extends Record<string, {
247
+ dto: unknown;
248
+ _Entity: unknown;
249
+ serializeEntityToDto: unknown;
250
+ } | {
251
+ dto: unknown;
252
+ _Entity: unknown;
253
+ deserializeDtoToEntity: unknown;
254
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>> = {
255
+ [K in keyof DtoMapper]: DtoMapper[K] extends {
256
+ dto: unknown;
257
+ _Entity: unknown;
258
+ serializeEntityToDto: unknown;
259
+ } ? {
260
+ serializeEntityToDto: (entity: Entities[K], ...additionalArgs: AllAfterFirstParameters<DtoMapper[K]['serializeEntityToDto']>) => Dto[K];
261
+ } : DtoMapper[K] extends {
262
+ dto: unknown;
263
+ _Entity: unknown;
264
+ deserializeDtoToEntity: unknown;
265
+ } ? {
266
+ deserializeDtoToEntity: (dto: Dto[K], ...additionalArgs: AllAfterFirstParameters<DtoMapper[K]['deserializeDtoToEntity']>) => Entities[K];
267
+ } : never;
268
+ };
269
+
270
+ declare function transformIntoInternalDtoMapper<SchemaValidator extends AnySchemaValidator, DtoMapper extends Record<string, new (schemaValidator: SchemaValidator) => {
271
+ dto: unknown;
272
+ _Entity: unknown;
273
+ serializeEntityToDto: unknown;
274
+ } | {
275
+ dto: unknown;
276
+ _Entity: unknown;
277
+ deserializeDtoToEntity: unknown;
278
+ }>, Entities extends Record<keyof DtoMapper, unknown>, Dto extends Record<keyof DtoMapper, unknown>>(dtoMappers: DtoMapper, schemaValidator: SchemaValidator): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto>;
279
+
280
+ export { type DtoMapperSchemaValidatorObject, type InternalDtoMapper, RequestDtoMapper, type RequestDtoMapperConstructor, ResponseDtoMapper, type ResponseDtoMapperConstructor, type SchemasByValidator, serviceSchemaResolver, transformIntoInternalDtoMapper };
@@ -21,7 +21,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var dtoMapper_exports = {};
22
22
  __export(dtoMapper_exports, {
23
23
  RequestDtoMapper: () => RequestDtoMapper,
24
- ResponseDtoMapper: () => ResponseDtoMapper
24
+ ResponseDtoMapper: () => ResponseDtoMapper,
25
+ serviceSchemaResolver: () => serviceSchemaResolver,
26
+ transformIntoInternalDtoMapper: () => transformIntoInternalDtoMapper
25
27
  });
26
28
  module.exports = __toCommonJS(dtoMapper_exports);
27
29
 
@@ -228,9 +230,41 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
228
230
  return construct(this, schemaValidator).fromEntity(entity, ...additionalArgs).toDto();
229
231
  }
230
232
  };
233
+
234
+ // src/dtoMapper/serviceSchemaResolver.ts
235
+ var import_common = require("@forklaunch/common");
236
+ function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
237
+ return (schemaValidator, uuidId) => {
238
+ switch (schemaValidator._Type) {
239
+ case "TypeBox":
240
+ return TypeBoxSchemas(uuidId);
241
+ case "Zod":
242
+ return ZodSchemas(uuidId);
243
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
244
+ // @ts-ignore
245
+ case "Mock":
246
+ throw new Error("Mock schema validator not supported");
247
+ default:
248
+ (0, import_common.isNever)(schemaValidator._Type);
249
+ throw new Error("Invalid schema validator");
250
+ }
251
+ };
252
+ }
253
+
254
+ // src/dtoMapper/transformIntoInternalDtoMappers.ts
255
+ function transformIntoInternalDtoMapper(dtoMappers, schemaValidator) {
256
+ return Object.fromEntries(
257
+ Object.entries(dtoMappers).map(([key, value]) => [
258
+ key,
259
+ new value(schemaValidator)
260
+ ])
261
+ );
262
+ }
231
263
  // Annotate the CommonJS export names for ESM import in node:
232
264
  0 && (module.exports = {
233
265
  RequestDtoMapper,
234
- ResponseDtoMapper
266
+ ResponseDtoMapper,
267
+ serviceSchemaResolver,
268
+ transformIntoInternalDtoMapper
235
269
  });
236
270
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/dtoMapper/index.ts","../../../src/dtoMapper/models/requestDtoMapper.model.ts","../../../src/dtoMapper/models/baseDtoMapper.model.ts","../../../src/dtoMapper/models/responseDtoMapper.model.ts","../../../src/dtoMapper/serviceSchemaResolver.ts","../../../src/dtoMapper/transformIntoInternalDtoMappers.ts"],"sourcesContent":["export * from './models/requestDtoMapper.model';\nexport * from './models/responseDtoMapper.model';\nexport * from './serviceSchemaResolver';\nexport * from './transformIntoInternalDtoMappers';\nexport * from './types/dtoMapper.types';\nexport * from './types/internalDtoMapper.types';\nexport * from './types/serviceSchemaResolver.types';\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/dtoMapper.interface';\nimport { BaseDtoMapper, construct } from './baseDtoMapper.model';\n\n/**\n * Abstract class representing a request entity mapper.\n *\n * @template Entity - A type that extends BaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseDtoMapper<SV>}\n */\nexport abstract class RequestDtoMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseDtoMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Converts the underlying DTO to an entity.\n *\n * @abstract\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Entity} - The entity.\n */\n abstract toEntity(...additionalArgs: unknown[]): Entity;\n\n /**\n * Populates the DTO with data from a JSON object.\n *\n * @param {this['_dto']} json - The JSON object.\n * @returns {this} - The instance of the RequestDtoMapper.\n */\n fromDto(json: this['_dto']): this {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n json\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this.dto = json;\n return this;\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @param {this['_dto']} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Entity} - The entity.\n */\n deserializeDtoToEntity(\n json: this['_dto'],\n ...additionalArgs: Parameters<this['toEntity']>\n ): Entity {\n return this.fromDto(json).toEntity(...additionalArgs);\n }\n\n /**\n * Creates an instance of a RequestDtoMapper from a JSON object.\n *\n * @template T - A type that extends RequestDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @returns {T} - An instance of the T.\n */\n static fromDto<\n T extends RequestDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T {\n return construct(this, schemaValidator).fromDto(json);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @template T - A type that extends RequestDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {T['_Entity']} - The entity.\n */\n static deserializeDtoToEntity<\n T extends RequestDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType,\n ...additionalArgs: Parameters<T['toEntity']>\n ): T['_Entity'] {\n return construct(this, schemaValidator)\n .fromDto(json)\n .toEntity(...additionalArgs);\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/dtoMapper.interface';\nimport { DtoMapperSchemaValidatorObject } from '../types/dtoMapper.types';\n\n/**\n * Constructs an instance of a T.\n *\n * @template T - A type that extends BaseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} self - The constructor of the T.\n * @param {SV} [schemaValidator] - The optional schema validator.\n * @returns {T} - An instance of the T.\n */\nexport function construct<T, SV extends AnySchemaValidator>(\n self: DtoMapperConstructor<T, SV>,\n schemaValidator?: SV\n): T {\n return new self(schemaValidator || ({} as SV));\n}\n\n/**\n * Abstract class representing a base entity mapper.\n *\n * @template SV - A type that extends AnySchemaValidator.\n */\nexport abstract class BaseDtoMapper<SV extends AnySchemaValidator> {\n /**\n * The schema validator exact type.\n * @type {SV}\n * @protected\n */\n _SV!: SV;\n\n /**\n * The schema validator as a general type.\n * @type {SchemaValidator}\n * @protected\n */\n protected schemaValidator: SchemaValidator;\n\n /**\n * The schema definition.\n * @type {DtoMapperSchemaValidatorObject<SV>}\n * @abstract\n */\n abstract schema: DtoMapperSchemaValidatorObject<SV>;\n\n /**\n * The Data Transfer Object (DTO).\n * @type {Schema<this['schema'], SV>}\n */\n _dto: Schema<this['schema'], SV> = {} as unknown as Schema<\n this['schema'],\n SV\n >;\n\n /**\n * Creates an instance of BaseDtoMapper.\n *\n * @param {SV} schemaValidator - The schema provider.\n */\n constructor(schemaValidator: SV) {\n this.schemaValidator = schemaValidator as unknown as SchemaValidator;\n }\n\n /**\n * Validates and sets the Data Transfer Object (DTO).\n *\n * @param {this['_dto']} dto - The Data Transfer Object (DTO).\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n set dto(_dto: this['_dto']) {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n _dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this._dto = _dto as unknown as Schema<this['schema'], SV>;\n }\n\n /**\n * Validates and gets the Data Transfer Object (DTO).\n *\n * @returns {this['_dto']} - The Data Transfer Object (DTO).\n */\n get dto(): this['_dto'] {\n return this._dto as unknown as this['_dto'];\n }\n\n /**\n * Gets the schema of a T.\n *\n * @template T - A type that extends BaseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @returns {T['schema']} - The schema of the T.\n */\n static schema<T extends BaseDtoMapper<SV>, SV extends AnySchemaValidator>(\n this: DtoMapperConstructor<T, SV>\n ): T['schema'] {\n return construct(this).schema;\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/dtoMapper.interface';\nimport { BaseDtoMapper, construct } from './baseDtoMapper.model';\n\n/**\n * Abstract class representing a response entity mapper.\n *\n * @template Entity - A type that extends BaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseDtoMapper<SV>}\n */\nexport abstract class ResponseDtoMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseDtoMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @abstract\n * @param {Entity} entity - The entity to convert.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {this} - The instance of the ResponseDtoMapper.\n */\n abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): this;\n\n /**\n * Converts the underlying DTO to a JSON object.\n *\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n toDto(): this['_dto'] {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n this.dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return this.dto;\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @param {Entity} entity - The entity to serialize.\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n serializeEntityToDto(\n ...[entity, ...additionalArgs]: Parameters<this['fromEntity']>\n ): this['_dto'] {\n return this.fromEntity(entity, ...additionalArgs).toDto();\n }\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @template T - A type that extends ResponseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to convert.\n * @returns {T} - An instance of the T.\n */\n static fromEntity<\n T extends ResponseDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): T {\n return construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @template T - A type that extends ResponseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to serialize.\n * @returns {T['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n static serializeEntityToDto<\n T extends ResponseDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n DtoType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): DtoType {\n return construct(this, schemaValidator)\n .fromEntity(entity, ...additionalArgs)\n .toDto() as DtoType;\n }\n}\n","import { isNever } from '@forklaunch/common';\nimport { AnySchemaValidator } from '@forklaunch/validator';\nimport { SchemasByValidator } from './types/serviceSchemaResolver.types';\n\nexport function serviceSchemaResolver<\n TypeBoxSchemas extends (uuidId: boolean) => unknown,\n ZodSchemas extends (uuidId: boolean) => unknown\n>(TypeBoxSchemas: TypeBoxSchemas, ZodSchemas: ZodSchemas) {\n return <SchemaValidator extends AnySchemaValidator>(\n schemaValidator: SchemaValidator,\n uuidId: boolean\n ): SchemasByValidator<SchemaValidator, TypeBoxSchemas, ZodSchemas> => {\n switch (schemaValidator._Type) {\n case 'TypeBox':\n return TypeBoxSchemas(uuidId) as SchemasByValidator<\n SchemaValidator,\n TypeBoxSchemas,\n ZodSchemas\n >;\n case 'Zod':\n return ZodSchemas(uuidId) as SchemasByValidator<\n SchemaValidator,\n TypeBoxSchemas,\n ZodSchemas\n >;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n case 'Mock':\n throw new Error('Mock schema validator not supported');\n default:\n isNever(schemaValidator._Type);\n throw new Error('Invalid schema validator');\n }\n };\n}\n","import { InstanceTypeRecord } from '@forklaunch/common';\nimport { AnySchemaValidator } from '@forklaunch/validator';\nimport { InternalDtoMapper } from './types/internalDtoMapper.types';\n\nexport function transformIntoInternalDtoMapper<\n SchemaValidator extends AnySchemaValidator,\n DtoMapper extends Record<\n string,\n new (schemaValidator: SchemaValidator) =>\n | {\n dto: unknown;\n _Entity: unknown;\n serializeEntityToDto: unknown;\n }\n | {\n dto: unknown;\n _Entity: unknown;\n deserializeDtoToEntity: unknown;\n }\n >,\n Entities extends Record<keyof DtoMapper, unknown>,\n Dto extends Record<keyof DtoMapper, unknown>\n>(\n dtoMappers: DtoMapper,\n schemaValidator: SchemaValidator\n): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto> {\n return Object.fromEntries(\n Object.entries(dtoMappers).map(([key, value]) => [\n key,\n new value(schemaValidator)\n ])\n ) as unknown as InternalDtoMapper<\n InstanceTypeRecord<DtoMapper>,\n Entities,\n Dto\n >;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,oBAGO;;;ACHP,uBAKO;AAaA,SAAS,UACd,MACA,iBACG;AACH,SAAO,IAAI,KAAK,mBAAoB,CAAC,CAAQ;AAC/C;AAOO,IAAe,gBAAf,MAA4D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU;AAAA;AAAA;AAAA;AAAA;AAAA,EAaV,OAAmC,CAA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wB;AAIjB,SAAS,sBAGd,gBAAgC,YAAwB;AACxD,SAAO,CACL,iBACA,WACoE;AACpE,YAAQ,gBAAgB,OAAO;AAAA,MAC7B,KAAK;AACH,eAAO,eAAe,MAAM;AAAA,MAK9B,KAAK;AACH,eAAO,WAAW,MAAM;AAAA;AAAA;AAAA,MAO1B,KAAK;AACH,cAAM,IAAI,MAAM,qCAAqC;AAAA,MACvD;AACE,mCAAQ,gBAAgB,KAAK;AAC7B,cAAM,IAAI,MAAM,0BAA0B;AAAA,IAC9C;AAAA,EACF;AACF;;;AC9BO,SAAS,+BAmBd,YACA,iBACiE;AACjE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,MAC/C;AAAA,MACA,IAAI,MAAM,eAAe;AAAA,IAC3B,CAAC;AAAA,EACH;AAKF;","names":["import_validator","import_validator"]}
@@ -207,8 +207,40 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
207
207
  return construct(this, schemaValidator).fromEntity(entity, ...additionalArgs).toDto();
208
208
  }
209
209
  };
210
+
211
+ // src/dtoMapper/serviceSchemaResolver.ts
212
+ import { isNever } from "@forklaunch/common";
213
+ function serviceSchemaResolver(TypeBoxSchemas, ZodSchemas) {
214
+ return (schemaValidator, uuidId) => {
215
+ switch (schemaValidator._Type) {
216
+ case "TypeBox":
217
+ return TypeBoxSchemas(uuidId);
218
+ case "Zod":
219
+ return ZodSchemas(uuidId);
220
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
221
+ // @ts-ignore
222
+ case "Mock":
223
+ throw new Error("Mock schema validator not supported");
224
+ default:
225
+ isNever(schemaValidator._Type);
226
+ throw new Error("Invalid schema validator");
227
+ }
228
+ };
229
+ }
230
+
231
+ // src/dtoMapper/transformIntoInternalDtoMappers.ts
232
+ function transformIntoInternalDtoMapper(dtoMappers, schemaValidator) {
233
+ return Object.fromEntries(
234
+ Object.entries(dtoMappers).map(([key, value]) => [
235
+ key,
236
+ new value(schemaValidator)
237
+ ])
238
+ );
239
+ }
210
240
  export {
211
241
  RequestDtoMapper,
212
- ResponseDtoMapper
242
+ ResponseDtoMapper,
243
+ serviceSchemaResolver,
244
+ transformIntoInternalDtoMapper
213
245
  };
214
246
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/dtoMapper/models/requestDtoMapper.model.ts","../../../src/dtoMapper/models/baseDtoMapper.model.ts","../../../src/dtoMapper/models/responseDtoMapper.model.ts","../../../src/dtoMapper/serviceSchemaResolver.ts","../../../src/dtoMapper/transformIntoInternalDtoMappers.ts"],"sourcesContent":["import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/dtoMapper.interface';\nimport { BaseDtoMapper, construct } from './baseDtoMapper.model';\n\n/**\n * Abstract class representing a request entity mapper.\n *\n * @template Entity - A type that extends BaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseDtoMapper<SV>}\n */\nexport abstract class RequestDtoMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseDtoMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Converts the underlying DTO to an entity.\n *\n * @abstract\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Entity} - The entity.\n */\n abstract toEntity(...additionalArgs: unknown[]): Entity;\n\n /**\n * Populates the DTO with data from a JSON object.\n *\n * @param {this['_dto']} json - The JSON object.\n * @returns {this} - The instance of the RequestDtoMapper.\n */\n fromDto(json: this['_dto']): this {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n json\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this.dto = json;\n return this;\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @param {this['_dto']} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {Entity} - The entity.\n */\n deserializeDtoToEntity(\n json: this['_dto'],\n ...additionalArgs: Parameters<this['toEntity']>\n ): Entity {\n return this.fromDto(json).toEntity(...additionalArgs);\n }\n\n /**\n * Creates an instance of a RequestDtoMapper from a JSON object.\n *\n * @template T - A type that extends RequestDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @returns {T} - An instance of the T.\n */\n static fromDto<\n T extends RequestDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T {\n return construct(this, schemaValidator).fromDto(json);\n }\n\n /**\n * Deserializes a JSON object to an entity.\n *\n * @template T - A type that extends RequestDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @template JsonType - The type of the JSON object.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {JsonType} json - The JSON object.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {T['_Entity']} - The entity.\n */\n static deserializeDtoToEntity<\n T extends RequestDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n JsonType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n json: JsonType,\n ...additionalArgs: Parameters<T['toEntity']>\n ): T['_Entity'] {\n return construct(this, schemaValidator)\n .fromDto(json)\n .toEntity(...additionalArgs);\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors,\n Schema,\n SchemaValidator\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/dtoMapper.interface';\nimport { DtoMapperSchemaValidatorObject } from '../types/dtoMapper.types';\n\n/**\n * Constructs an instance of a T.\n *\n * @template T - A type that extends BaseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} self - The constructor of the T.\n * @param {SV} [schemaValidator] - The optional schema validator.\n * @returns {T} - An instance of the T.\n */\nexport function construct<T, SV extends AnySchemaValidator>(\n self: DtoMapperConstructor<T, SV>,\n schemaValidator?: SV\n): T {\n return new self(schemaValidator || ({} as SV));\n}\n\n/**\n * Abstract class representing a base entity mapper.\n *\n * @template SV - A type that extends AnySchemaValidator.\n */\nexport abstract class BaseDtoMapper<SV extends AnySchemaValidator> {\n /**\n * The schema validator exact type.\n * @type {SV}\n * @protected\n */\n _SV!: SV;\n\n /**\n * The schema validator as a general type.\n * @type {SchemaValidator}\n * @protected\n */\n protected schemaValidator: SchemaValidator;\n\n /**\n * The schema definition.\n * @type {DtoMapperSchemaValidatorObject<SV>}\n * @abstract\n */\n abstract schema: DtoMapperSchemaValidatorObject<SV>;\n\n /**\n * The Data Transfer Object (DTO).\n * @type {Schema<this['schema'], SV>}\n */\n _dto: Schema<this['schema'], SV> = {} as unknown as Schema<\n this['schema'],\n SV\n >;\n\n /**\n * Creates an instance of BaseDtoMapper.\n *\n * @param {SV} schemaValidator - The schema provider.\n */\n constructor(schemaValidator: SV) {\n this.schemaValidator = schemaValidator as unknown as SchemaValidator;\n }\n\n /**\n * Validates and sets the Data Transfer Object (DTO).\n *\n * @param {this['_dto']} dto - The Data Transfer Object (DTO).\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n set dto(_dto: this['_dto']) {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n _dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n this._dto = _dto as unknown as Schema<this['schema'], SV>;\n }\n\n /**\n * Validates and gets the Data Transfer Object (DTO).\n *\n * @returns {this['_dto']} - The Data Transfer Object (DTO).\n */\n get dto(): this['_dto'] {\n return this._dto as unknown as this['_dto'];\n }\n\n /**\n * Gets the schema of a T.\n *\n * @template T - A type that extends BaseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @returns {T['schema']} - The schema of the T.\n */\n static schema<T extends BaseDtoMapper<SV>, SV extends AnySchemaValidator>(\n this: DtoMapperConstructor<T, SV>\n ): T['schema'] {\n return construct(this).schema;\n }\n}\n","import {\n AnySchemaValidator,\n prettyPrintParseErrors\n} from '@forklaunch/validator';\nimport { DtoMapperConstructor } from '../interfaces/dtoMapper.interface';\nimport { BaseDtoMapper, construct } from './baseDtoMapper.model';\n\n/**\n * Abstract class representing a response entity mapper.\n *\n * @template Entity - A type that extends BaseEntity.\n * @template SV - A type that extends AnySchemaValidator.\n * @extends {BaseDtoMapper<SV>}\n */\nexport abstract class ResponseDtoMapper<\n Entity,\n SV extends AnySchemaValidator\n> extends BaseDtoMapper<SV> {\n /**\n * The entity type.\n * @type {Entity}\n * @protected\n */\n _Entity!: Entity;\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @abstract\n * @param {Entity} entity - The entity to convert.\n * @param {...unknown[]} additionalArgs - Additional arguments.\n * @returns {this} - The instance of the ResponseDtoMapper.\n */\n abstract fromEntity(entity: Entity, ...additionalArgs: unknown[]): this;\n\n /**\n * Converts the underlying DTO to a JSON object.\n *\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n toDto(): this['_dto'] {\n const parsedSchema = this.schemaValidator.parse(\n this.schemaValidator.schemify(this.schema),\n this.dto\n );\n if (!parsedSchema.ok) {\n throw new Error(prettyPrintParseErrors(parsedSchema.errors, 'DTO'));\n }\n return this.dto;\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @param {Entity} entity - The entity to serialize.\n * @returns {this['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n serializeEntityToDto(\n ...[entity, ...additionalArgs]: Parameters<this['fromEntity']>\n ): this['_dto'] {\n return this.fromEntity(entity, ...additionalArgs).toDto();\n }\n\n /**\n * Populates entity mapper with DTO from an entity.\n *\n * @template T - A type that extends ResponseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to convert.\n * @returns {T} - An instance of the T.\n */\n static fromEntity<\n T extends ResponseDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): T {\n return construct(this, schemaValidator).fromEntity(\n entity,\n ...additionalArgs\n );\n }\n\n /**\n * Serializes an entity to a JSON object.\n *\n * @template T - A type that extends ResponseDtoMapper.\n * @template SV - A type that extends AnySchemaValidator.\n * @param {DtoMapperConstructor<T, SV>} this - The constructor of the T.\n * @param {SV} schemaValidator - The schema provider.\n * @param {T['_Entity']} entity - The entity to serialize.\n * @returns {T['_dto']} - The JSON object.\n * @throws {Error} - Throws an error if the DTO is invalid.\n */\n static serializeEntityToDto<\n T extends ResponseDtoMapper<unknown, SV>,\n SV extends AnySchemaValidator,\n DtoType extends T['_dto']\n >(\n this: DtoMapperConstructor<T, SV>,\n schemaValidator: SV,\n ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>\n ): DtoType {\n return construct(this, schemaValidator)\n .fromEntity(entity, ...additionalArgs)\n .toDto() as DtoType;\n }\n}\n","import { isNever } from '@forklaunch/common';\nimport { AnySchemaValidator } from '@forklaunch/validator';\nimport { SchemasByValidator } from './types/serviceSchemaResolver.types';\n\nexport function serviceSchemaResolver<\n TypeBoxSchemas extends (uuidId: boolean) => unknown,\n ZodSchemas extends (uuidId: boolean) => unknown\n>(TypeBoxSchemas: TypeBoxSchemas, ZodSchemas: ZodSchemas) {\n return <SchemaValidator extends AnySchemaValidator>(\n schemaValidator: SchemaValidator,\n uuidId: boolean\n ): SchemasByValidator<SchemaValidator, TypeBoxSchemas, ZodSchemas> => {\n switch (schemaValidator._Type) {\n case 'TypeBox':\n return TypeBoxSchemas(uuidId) as SchemasByValidator<\n SchemaValidator,\n TypeBoxSchemas,\n ZodSchemas\n >;\n case 'Zod':\n return ZodSchemas(uuidId) as SchemasByValidator<\n SchemaValidator,\n TypeBoxSchemas,\n ZodSchemas\n >;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n case 'Mock':\n throw new Error('Mock schema validator not supported');\n default:\n isNever(schemaValidator._Type);\n throw new Error('Invalid schema validator');\n }\n };\n}\n","import { InstanceTypeRecord } from '@forklaunch/common';\nimport { AnySchemaValidator } from '@forklaunch/validator';\nimport { InternalDtoMapper } from './types/internalDtoMapper.types';\n\nexport function transformIntoInternalDtoMapper<\n SchemaValidator extends AnySchemaValidator,\n DtoMapper extends Record<\n string,\n new (schemaValidator: SchemaValidator) =>\n | {\n dto: unknown;\n _Entity: unknown;\n serializeEntityToDto: unknown;\n }\n | {\n dto: unknown;\n _Entity: unknown;\n deserializeDtoToEntity: unknown;\n }\n >,\n Entities extends Record<keyof DtoMapper, unknown>,\n Dto extends Record<keyof DtoMapper, unknown>\n>(\n dtoMappers: DtoMapper,\n schemaValidator: SchemaValidator\n): InternalDtoMapper<InstanceTypeRecord<DtoMapper>, Entities, Dto> {\n return Object.fromEntries(\n Object.entries(dtoMappers).map(([key, value]) => [\n key,\n new value(schemaValidator)\n ])\n ) as unknown as InternalDtoMapper<\n InstanceTypeRecord<DtoMapper>,\n Entities,\n Dto\n >;\n}\n"],"mappings":";AAAA;AAAA,EAEE,0BAAAA;AAAA,OACK;;;ACHP;AAAA,EAEE;AAAA,OAGK;AAaA,SAAS,UACd,MACA,iBACG;AACH,SAAO,IAAI,KAAK,mBAAoB,CAAC,CAAQ;AAC/C;AAOO,IAAe,gBAAf,MAA4D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMjE;AAAA;AAAA;AAAA;AAAA;AAAA;AA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e,EACnC,WAAW,QAAQ,GAAG,cAAc,EACpC,MAAM;AAAA,EACX;AACF;;;ACjHA,SAAS,eAAe;AAIjB,SAAS,sBAGd,gBAAgC,YAAwB;AACxD,SAAO,CACL,iBACA,WACoE;AACpE,YAAQ,gBAAgB,OAAO;AAAA,MAC7B,KAAK;AACH,eAAO,eAAe,MAAM;AAAA,MAK9B,KAAK;AACH,eAAO,WAAW,MAAM;AAAA;AAAA;AAAA,MAO1B,KAAK;AACH,cAAM,IAAI,MAAM,qCAAqC;AAAA,MACvD;AACE,gBAAQ,gBAAgB,KAAK;AAC7B,cAAM,IAAI,MAAM,0BAA0B;AAAA,IAC9C;AAAA,EACF;AACF;;;AC9BO,SAAS,+BAmBd,YACA,iBACiE;AACjE,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAAA,MAC/C;AAAA,MACA,IAAI,MAAM,eAAe;AAAA,IAC3B,CAAC;AAAA,EACH;AAKF;","names":["prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors"]}
@@ -1,6 +1,6 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
2
- import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../openTelemetryCollector-CWrfzmmW.mjs';
3
- export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../openTelemetryCollector-CWrfzmmW.mjs';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../../openTelemetryCollector-CWrfzmmW.mjs';
3
+ export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../../openTelemetryCollector-CWrfzmmW.mjs';
4
4
  import { Prettify, RemoveTrailingSlash, MakePropertyOptionalIfChildrenOptional } from '@forklaunch/common';
5
5
  import { Span } from '@opentelemetry/api';
6
6
  import { ParsedQs } from 'qs';
@@ -1,6 +1,6 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, IdiomaticSchema, Schema } from '@forklaunch/validator';
2
- import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../openTelemetryCollector-CWrfzmmW.js';
3
- export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../openTelemetryCollector-CWrfzmmW.js';
2
+ import { O as OpenTelemetryCollector, M as MetricsDefinition, L as LoggerMeta, a as LogFn } from '../../openTelemetryCollector-CWrfzmmW.js';
3
+ export { c as MetricType, h as httpRequestsTotalCounter, b as httpServerDurationHistogram } from '../../openTelemetryCollector-CWrfzmmW.js';
4
4
  import { Prettify, RemoveTrailingSlash, MakePropertyOptionalIfChildrenOptional } from '@forklaunch/common';
5
5
  import { Span } from '@opentelemetry/api';
6
6
  import { ParsedQs } from 'qs';
@@ -481,7 +481,7 @@ var OpenTelemetryCollector = class {
481
481
  };
482
482
  import_dotenv.default.config({ path: getEnvVar("ENV_FILE_PATH") });
483
483
  new import_sdk_node.NodeSDK({
484
- resource: new import_resources.Resource({
484
+ resource: (0, import_resources.resourceFromAttributes)({
485
485
  [import_semantic_conventions2.ATTR_SERVICE_NAME]: getEnvVar("OTEL_SERVICE_NAME")
486
486
  }),
487
487
  traceExporter: new import_exporter_trace_otlp_http.OTLPTraceExporter({
@@ -588,7 +588,10 @@ function parse(req, res, next) {
588
588
  res.status(400);
589
589
  if (hasSend(res)) {
590
590
  res.send(
591
- `${(0, import_validator.prettyPrintParseErrors)(parsedRequest.errors, "Request")}
591
+ `${(0, import_validator.prettyPrintParseErrors)(
592
+ parsedRequest.errors,
593
+ "Request"
594
+ )}
592
595
 
593
596
  Correlation id: ${req.context.correlationId ?? "No correlation ID"}`
594
597
  );
@@ -2301,7 +2304,9 @@ function parse2(req, res, next) {
2301
2304
  if (hasSend(res)) {
2302
2305
  res.send(
2303
2306
  `Invalid response:
2304
- ${parseErrors.join("\n\n")}
2307
+ ${parseErrors.join(
2308
+ "\n\n"
2309
+ )}
2305
2310
 
2306
2311
  Correlation id: ${req.context.correlationId ?? "No correlation ID"}`
2307
2312
  );