@forklaunch/core 0.5.5 → 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 +52 -46
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forklaunch/core",
3
- "version": "0.5.5",
3
+ "version": "0.6.0",
4
4
  "description": "forklaunch-js core package. Contains useful building blocks.",
5
5
  "homepage": "https://github.com/forklaunch/forklaunch-js#readme",
6
6
  "bugs": {
@@ -14,76 +14,82 @@
14
14
  "author": "Rohin Bhargava",
15
15
  "exports": {
16
16
  "./cache": {
17
- "types": "./lib/cache/index.d.ts",
18
- "import": "./lib/cache/index.mjs",
19
- "require": "./lib/cache/index.js",
20
- "default": "./lib/cache/index.js"
17
+ "types": "./lib/src/cache/index.d.ts",
18
+ "import": "./lib/src/cache/index.mjs",
19
+ "require": "./lib/src/cache/index.js",
20
+ "default": "./lib/src/cache/index.js"
21
21
  },
22
22
  "./controllers": {
23
- "types": "./lib/controllers/index.d.ts",
24
- "import": "./lib/controllers/index.mjs",
25
- "require": "./lib/controllers/index.js",
26
- "default": "./lib/controllers/index.js"
23
+ "types": "./lib/src/controllers/index.d.ts",
24
+ "import": "./lib/src/controllers/index.mjs",
25
+ "require": "./lib/src/controllers/index.js",
26
+ "default": "./lib/src/controllers/index.js"
27
27
  },
28
28
  "./dtoMapper": {
29
- "types": "./lib/dtoMapper/index.d.ts",
30
- "import": "./lib/dtoMapper/index.mjs",
31
- "require": "./lib/dtoMapper/index.js",
32
- "default": "./lib/dtoMapper/index.js"
29
+ "types": "./lib/src/dtoMapper/index.d.ts",
30
+ "import": "./lib/src/dtoMapper/index.mjs",
31
+ "require": "./lib/src/dtoMapper/index.js",
32
+ "default": "./lib/src/dtoMapper/index.js"
33
33
  },
34
34
  "./http": {
35
- "types": "./lib/http/index.d.ts",
36
- "import": "./lib/http/index.mjs",
37
- "require": "./lib/http/index.js",
38
- "default": "./lib/http/index.js"
35
+ "types": "./lib/src/http/index.d.ts",
36
+ "import": "./lib/src/http/index.mjs",
37
+ "require": "./lib/src/http/index.js",
38
+ "default": "./lib/src/http/index.js"
39
39
  },
40
40
  "./services": {
41
- "types": "./lib/services/index.d.ts",
42
- "import": "./lib/services/index.mjs",
43
- "require": "./lib/services/index.js",
44
- "default": "./lib/services/index.js"
41
+ "types": "./lib/src/services/index.d.ts",
42
+ "import": "./lib/src/services/index.mjs",
43
+ "require": "./lib/src/services/index.js",
44
+ "default": "./lib/src/services/index.js"
45
+ },
46
+ "./test": {
47
+ "types": "./lib/__test__/index.d.ts",
48
+ "import": "./lib/__test__/index.mjs",
49
+ "require": "./lib/__test__/index.js",
50
+ "default": "./lib/__test__/index.js"
45
51
  }
46
52
  },
47
53
  "types": "lib/index.d.ts",
48
54
  "directories": {
49
- "test": "tests"
55
+ "test": "__test__"
50
56
  },
51
57
  "files": [
52
58
  "lib"
53
59
  ],
54
60
  "dependencies": {
55
61
  "@forklaunch/opentelemetry-instrumentation-hyper-express": "0.0.5",
56
- "@mikro-orm/core": "^6.4.9",
57
- "@mikro-orm/mongodb": "^6.4.9",
62
+ "@mikro-orm/core": "^6.4.11",
63
+ "@mikro-orm/mongodb": "^6.4.11",
58
64
  "@opentelemetry/api": "^1.9.0",
59
- "@opentelemetry/api-logs": "^0.57.2",
60
- "@opentelemetry/exporter-logs-otlp-http": "^0.57.2",
61
- "@opentelemetry/exporter-metrics-otlp-http": "^0.57.2",
62
- "@opentelemetry/exporter-prometheus": "^0.57.2",
63
- "@opentelemetry/exporter-trace-otlp-http": "^0.57.2",
64
- "@opentelemetry/instrumentation-express": "^0.47.1",
65
- "@opentelemetry/instrumentation-http": "^0.57.2",
66
- "@opentelemetry/resources": "^1.30.1",
67
- "@opentelemetry/sdk-logs": "^0.57.2",
68
- "@opentelemetry/sdk-metrics": "^1.30.1",
69
- "@opentelemetry/sdk-node": "^0.57.2",
70
- "@opentelemetry/sdk-trace-node": "^1.30.1",
65
+ "@opentelemetry/api-logs": "^0.200.0",
66
+ "@opentelemetry/exporter-logs-otlp-http": "^0.200.0",
67
+ "@opentelemetry/exporter-metrics-otlp-http": "^0.200.0",
68
+ "@opentelemetry/exporter-prometheus": "^0.200.0",
69
+ "@opentelemetry/exporter-trace-otlp-http": "^0.200.0",
70
+ "@opentelemetry/instrumentation-express": "^0.48.0",
71
+ "@opentelemetry/instrumentation-http": "^0.200.0",
72
+ "@opentelemetry/resources": "^2.0.0",
73
+ "@opentelemetry/sdk-logs": "^0.200.0",
74
+ "@opentelemetry/sdk-metrics": "^2.0.0",
75
+ "@opentelemetry/sdk-node": "^0.200.0",
76
+ "@opentelemetry/sdk-trace-node": "^2.0.0",
71
77
  "@opentelemetry/semantic-conventions": "^1.30.0",
72
78
  "cors": "^2.8.5",
73
79
  "dotenv": "^16.4.7",
74
- "jose": "^6.0.8",
80
+ "jose": "^6.0.10",
75
81
  "openapi3-ts": "^4.4.0",
76
82
  "pino": "^9.6.0",
77
83
  "pino-http": "^10.4.0",
78
84
  "pino-pretty": "^13.0.0",
79
85
  "redis": "^4.7.0",
80
86
  "uuid": "^11.1.0",
81
- "@forklaunch/common": "0.2.3",
82
- "@forklaunch/validator": "0.4.6"
87
+ "@forklaunch/common": "0.2.5",
88
+ "@forklaunch/validator": "0.4.8"
83
89
  },
84
90
  "devDependencies": {
85
- "@eslint/js": "^9.22.0",
86
- "@scalar/express-api-reference": "^0.4.192",
91
+ "@eslint/js": "^9.23.0",
92
+ "@scalar/express-api-reference": "^0.6.5",
87
93
  "@types/cors": "^2.8.17",
88
94
  "@types/jest": "^29.5.14",
89
95
  "@types/qs": "^6.9.18",
@@ -91,16 +97,16 @@
91
97
  "globals": "^16.0.0",
92
98
  "jest": "^29.7.0",
93
99
  "prettier": "^3.5.3",
94
- "testcontainers": "^10.18.0",
95
- "ts-jest": "^29.2.6",
100
+ "testcontainers": "^10.23.0",
101
+ "ts-jest": "^29.3.1",
96
102
  "ts-node": "^10.9.2",
97
103
  "tsup": "^8.4.0",
98
- "typedoc": "^0.27.9",
104
+ "typedoc": "^0.28.1",
99
105
  "typescript": "^5.8.2",
100
- "typescript-eslint": "^8.26.0"
106
+ "typescript-eslint": "^8.29.0"
101
107
  },
102
108
  "scripts": {
103
- "build": "tsc --noEmit && tsup ./src/cache/index.ts ./src/controllers/index.ts ./src/database/mikro/models/entities/base.entity.ts ./src/database/mikro/models/entities/mongo.base.entity.ts ./src/database/mikro/models/entities/role.entity.ts ./src/database/mikro/models/entities/user.entity.ts ./src/dtoMapper/index.ts ./src/http/index.ts ./src/services/index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean --sourcemap",
109
+ "build": "tsc --noEmit && tsup ./src/cache/index.ts ./src/controllers/index.ts ./src/database/mikro/models/entities/base.entity.ts ./src/database/mikro/models/entities/mongo.base.entity.ts ./src/database/mikro/models/entities/role.entity.ts ./src/database/mikro/models/entities/user.entity.ts ./src/dtoMapper/index.ts ./src/http/index.ts ./src/services/index.ts ./__test__/index.ts --format cjs,esm --no-splitting --dts --tsconfig tsconfig.json --out-dir lib --clean --sourcemap",
104
110
  "clean": "rm -rf lib pnpm.lock.yaml node_modules",
105
111
  "docs": "typedoc --out docs *",
106
112
  "format": "prettier --ignore-path=.prettierignore --config .prettierrc '**/*.{ts,tsx,json}' --write",
@@ -1 +0,0 @@
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;A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AAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
@@ -1 +0,0 @@
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,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OA,qBAA6B;AAC3B,WAAO,KAAK;AAAA,EACd;AACF;;;ACpHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/controllers/index.ts"],"sourcesContent":["export * from './interfaces/controller.interface';\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +0,0 @@
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"],"sourcesContent":["export * from './models/requestDtoMapper.model';\nexport * from './models/responseDtoMapper.model';\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"],"mappings":";;;;;;;;;;;;;;;;;;;;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;AAA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G,cAAc,GACpB;AACT,WAAO,UAAU,MAAM,eAAe,EACnC,WAAW,QAAQ,GAAG,cAAc,EACpC,MAAM;AAAA,EACX;AACF;","names":["import_validator","import_validator"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/dtoMapper/models/requestDtoMapper.model.ts","../../src/dtoMapper/models/baseDtoMapper.model.ts","../../src/dtoMapper/models/responseDtoMapper.model.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"],"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;AAAA,EAOU;AAAA;AAAA;AAAA;AAAA;AAAA,EAaV,OAAmC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAUpC,YAAY,iBAAqB;AAC/B,SAAK,kBAAkB;AAAA,EACzB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAA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