@forklaunch/core 0.3.3 → 0.3.5

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.
@@ -131,3 +131,4 @@ var createCacheKey = (cacheKeyPrefix) => (id) => {
131
131
  RedisTtlCache,
132
132
  createCacheKey
133
133
  });
134
+ //# sourceMappingURL=index.js.map
@@ -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';\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 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) => console.error('Redis Client Error', err));\n this.client.connect().catch(console.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;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,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;;;ACjHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
@@ -103,3 +103,4 @@ export {
103
103
  RedisTtlCache,
104
104
  createCacheKey
105
105
  };
106
+ //# sourceMappingURL=index.mjs.map
@@ -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';\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 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) => console.error('Redis Client Error', err));\n this.client.connect().catch(console.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 `${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;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;;;ACjHO,IAAM,iBAAiB,CAAC,mBAA2B,CAAC,OAAe;AACxE,SAAO,GAAG,cAAc,IAAI,EAAE;AAChC;","names":[]}
@@ -16,3 +16,4 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  // src/controllers/index.ts
17
17
  var controllers_exports = {};
18
18
  module.exports = __toCommonJS(controllers_exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/controllers/index.ts"],"sourcesContent":["export * from './interfaces/controller.interface';\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,5 +1,4 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
2
- import { B as BaseEntity } from '../base.entity-DNfmMOgd.mjs';
3
2
 
4
3
  /**
5
4
  * Interface representing a constructor for an entity mapper.
@@ -92,7 +91,7 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
92
91
  * @template SV - A type that extends AnySchemaValidator.
93
92
  * @extends {BaseDtoMapper<SV>}
94
93
  */
95
- declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
94
+ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
96
95
  /**
97
96
  * The entity type.
98
97
  * @type {Entity}
@@ -133,7 +132,7 @@ declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends An
133
132
  * @param {JsonType} json - The JSON object.
134
133
  * @returns {T} - An instance of the T.
135
134
  */
136
- static fromDto<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
135
+ static fromDto<T extends RequestDtoMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
137
136
  /**
138
137
  * Deserializes a JSON object to an entity.
139
138
  *
@@ -146,7 +145,7 @@ declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends An
146
145
  * @param {...unknown[]} additionalArgs - Additional arguments.
147
146
  * @returns {T['_Entity']} - The entity.
148
147
  */
149
- static deserializeDtoToEntity<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): T['_Entity'];
148
+ static deserializeDtoToEntity<T extends RequestDtoMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): T['_Entity'];
150
149
  }
151
150
 
152
151
  /**
@@ -156,7 +155,7 @@ declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends An
156
155
  * @template SV - A type that extends AnySchemaValidator.
157
156
  * @extends {BaseDtoMapper<SV>}
158
157
  */
159
- declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
158
+ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
160
159
  /**
161
160
  * The entity type.
162
161
  * @type {Entity}
@@ -197,7 +196,7 @@ declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV extends A
197
196
  * @param {T['_Entity']} entity - The entity to convert.
198
197
  * @returns {T} - An instance of the T.
199
198
  */
200
- static fromEntity<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): T;
199
+ static fromEntity<T extends ResponseDtoMapper<unknown, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): T;
201
200
  /**
202
201
  * Serializes an entity to a JSON object.
203
202
  *
@@ -209,7 +208,7 @@ declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV extends A
209
208
  * @returns {T['_dto']} - The JSON object.
210
209
  * @throws {Error} - Throws an error if the DTO is invalid.
211
210
  */
212
- static serializeEntityToDto<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): DtoType;
211
+ 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;
213
212
  }
214
213
 
215
214
  export { RequestDtoMapper, ResponseDtoMapper };
@@ -1,5 +1,4 @@
1
1
  import { AnySchemaValidator, UnboxedObjectSchema, SchemaValidator, Schema } from '@forklaunch/validator';
2
- import { B as BaseEntity } from '../base.entity-DNfmMOgd.js';
3
2
 
4
3
  /**
5
4
  * Interface representing a constructor for an entity mapper.
@@ -92,7 +91,7 @@ declare abstract class BaseDtoMapper<SV extends AnySchemaValidator> {
92
91
  * @template SV - A type that extends AnySchemaValidator.
93
92
  * @extends {BaseDtoMapper<SV>}
94
93
  */
95
- declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
94
+ declare abstract class RequestDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
96
95
  /**
97
96
  * The entity type.
98
97
  * @type {Entity}
@@ -133,7 +132,7 @@ declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends An
133
132
  * @param {JsonType} json - The JSON object.
134
133
  * @returns {T} - An instance of the T.
135
134
  */
136
- static fromDto<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
135
+ static fromDto<T extends RequestDtoMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType): T;
137
136
  /**
138
137
  * Deserializes a JSON object to an entity.
139
138
  *
@@ -146,7 +145,7 @@ declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends An
146
145
  * @param {...unknown[]} additionalArgs - Additional arguments.
147
146
  * @returns {T['_Entity']} - The entity.
148
147
  */
149
- static deserializeDtoToEntity<T extends RequestDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): T['_Entity'];
148
+ static deserializeDtoToEntity<T extends RequestDtoMapper<unknown, SV>, SV extends AnySchemaValidator, JsonType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, json: JsonType, ...additionalArgs: Parameters<T['toEntity']>): T['_Entity'];
150
149
  }
151
150
 
152
151
  /**
@@ -156,7 +155,7 @@ declare abstract class RequestDtoMapper<Entity extends BaseEntity, SV extends An
156
155
  * @template SV - A type that extends AnySchemaValidator.
157
156
  * @extends {BaseDtoMapper<SV>}
158
157
  */
159
- declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
158
+ declare abstract class ResponseDtoMapper<Entity, SV extends AnySchemaValidator> extends BaseDtoMapper<SV> {
160
159
  /**
161
160
  * The entity type.
162
161
  * @type {Entity}
@@ -197,7 +196,7 @@ declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV extends A
197
196
  * @param {T['_Entity']} entity - The entity to convert.
198
197
  * @returns {T} - An instance of the T.
199
198
  */
200
- static fromEntity<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): T;
199
+ static fromEntity<T extends ResponseDtoMapper<unknown, SV>, SV extends AnySchemaValidator>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): T;
201
200
  /**
202
201
  * Serializes an entity to a JSON object.
203
202
  *
@@ -209,7 +208,7 @@ declare abstract class ResponseDtoMapper<Entity extends BaseEntity, SV extends A
209
208
  * @returns {T['_dto']} - The JSON object.
210
209
  * @throws {Error} - Throws an error if the DTO is invalid.
211
210
  */
212
- static serializeEntityToDto<T extends ResponseDtoMapper<BaseEntity, SV>, SV extends AnySchemaValidator, DtoType extends T['_dto']>(this: DtoMapperConstructor<T, SV>, schemaValidator: SV, ...[entity, ...additionalArgs]: Parameters<T['fromEntity']>): DtoType;
211
+ 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;
213
212
  }
214
213
 
215
214
  export { RequestDtoMapper, ResponseDtoMapper };
@@ -233,3 +233,4 @@ var ResponseDtoMapper = class extends BaseDtoMapper {
233
233
  RequestDtoMapper,
234
234
  ResponseDtoMapper
235
235
  });
236
+ //# 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"],"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;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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,EAcA,OAAO,uBAML,iBACA,SACG,gBACW;AACd,WAAO,UAAU,MAAM,eAAe,EACnC,QAAQ,IAAI,EACZ,SAAS,GAAG,cAAc;AAAA,EAC/B;AACF;;;AE/GA,IAAAC,oBAGO;AAWA,IAAe,oBAAf,cAGG,cAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,QAAsB;AACpB,UAAM,eAAe,KAAK,gBAAgB;AAAA,MACxC,KAAK,gBAAgB,SAAS,KAAK,MAAM;AAAA,MACzC,KAAK;AAAA,IACP;AACA,QAAI,CAAC,aAAa,IAAI;AACpB,YAAM,IAAI,UAAM,0CAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,IACpE;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,wBACK,CAAC,QAAQ,GAAG,cAAc,GACf;AACd,WAAO,KAAK,WAAW,QAAQ,GAAG,cAAc,EAAE,MAAM;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,OAAO,WAKL,oBACG,CAAC,QAAQ,GAAG,cAAc,GAC1B;AACH,WAAO,UAAU,MAAM,eAAe,EAAE;AAAA,MACtC;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,OAAO,qBAML,oBACG,CAAC,QAAQ,GAAG,cAAc,GACpB;AACT,WAAO,UAAU,MAAM,eAAe,EACnC,WAAW,QAAQ,GAAG,cAAc,EACpC,MAAM;AAAA,EACX;AACF;","names":["import_validator","import_validator"]}
@@ -211,3 +211,4 @@ export {
211
211
  RequestDtoMapper,
212
212
  ResponseDtoMapper
213
213
  };
214
+ //# 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"],"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;AAAA,EAQA,IAAI,IAAI,MAAoB;AAC1B,UAAM,eAAe,KAAK,gBAAgB;AAAA,MACxC,KAAK,gBAAgB,SAAS,KAAK,MAAM;AAAA,MACzC;AAAA,IACF;AACA,QAAI,C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AAAC;AAAA,OACK;AAWA,IAAe,oBAAf,cAGG,cAAkB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAM1B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAkBA,QAAsB;AACpB,UAAM,eAAe,KAAK,gBAAgB;AAAA,MACxC,KAAK,gBAAgB,SAAS,KAAK,MAAM;AAAA,MACzC,KAAK;AAAA,IACP;AACA,QAAI,CAAC,aAAa,IAAI;AACpB,YAAM,IAAI,MAAMC,wBAAuB,aAAa,QAAQ,KAAK,CAAC;AAAA,IACpE;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,wBACK,CAAC,QAAQ,GAAG,cAAc,GACf;AACd,WAAO,KAAK,WAAW,QAAQ,GAAG,cAAc,EAAE,MAAM;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,OAAO,WAKL,oBACG,CAAC,QAAQ,GAAG,cAAc,GAC1B;AACH,WAAO,UAAU,MAAM,eAAe,EAAE;AAAA,MACtC;AAAA,MACA,GAAG;AAAA,IACL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAaA,OAAO,qBAML,oBACG,CAAC,QAAQ,GAAG,cAAc,GACpB;AACT,WAAO,UAAU,MAAM,eAAe,EACnC,WAAW,QAAQ,GAAG,cAAc,EACpC,MAAM;AAAA,EACX;AACF;","names":["prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors","prettyPrintParseErrors"]}
package/lib/http/index.js CHANGED
@@ -2187,3 +2187,4 @@ ${res.locals.errorMessage}`;
2187
2187
  trace,
2188
2188
  typedHandler
2189
2189
  });
2190
+ //# sourceMappingURL=index.js.map