@empathyco/x-adapter 8.1.0-alpha.4 → 8.1.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/endpoint-adapter/endpoint-adapter.factory.js.map +1 -1
- package/dist/cjs/http-clients/__mocks__/fetch.mock.js +2 -2
- package/dist/cjs/http-clients/__mocks__/fetch.mock.js.map +1 -1
- package/dist/cjs/http-clients/fetch.http-client.js.map +1 -1
- package/dist/cjs/http-clients/utils.js +2 -3
- package/dist/cjs/http-clients/utils.js.map +1 -1
- package/dist/cjs/mappers/combine-mappers.js +1 -2
- package/dist/cjs/mappers/combine-mappers.js.map +1 -1
- package/dist/cjs/mappers/identity.mapper.js +1 -2
- package/dist/cjs/mappers/identity.mapper.js.map +1 -1
- package/dist/cjs/mappers/schema-mapper.factory.js +1 -2
- package/dist/cjs/mappers/schema-mapper.factory.js.map +1 -1
- package/dist/cjs/schemas/utils.js +2 -3
- package/dist/cjs/schemas/utils.js.map +1 -1
- package/dist/cjs/utils/interpolate.js +1 -2
- package/dist/cjs/utils/interpolate.js.map +1 -1
- package/dist/esm/endpoint-adapter/endpoint-adapter.factory.js.map +1 -1
- package/dist/esm/http-clients/__mocks__/fetch.mock.js.map +1 -1
- package/dist/esm/http-clients/fetch.http-client.js.map +1 -1
- package/dist/esm/http-clients/utils.js.map +1 -1
- package/dist/esm/mappers/schema-mapper.factory.js.map +1 -1
- package/dist/esm/schemas/utils.js.map +1 -1
- package/dist/types/http-clients/__mocks__/fetch.mock.d.ts +0 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-adapter.factory.js","sourceRoot":"","sources":["../../../src/endpoint-adapter/endpoint-adapter.factory.ts"],"names":[],"mappings":";;;AAMA,0DAAmD;AACnD,yEAAmE;AACnE,gEAA2D;AAC3D,sDAAkD;AAElD;;;;;;;;;GASG;AACI,MAAM,sBAAsB,GAA2B,CAC5D,OA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AAK,UAAU;QACnC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QACvB,CAAC,CAAC,IAAA,yBAAW,EAAC,QAAQ,EAAE,OAAkC,CAAC,CAAA;AAC/D,CAAC","sourcesContent":["import type { Mapper } from '../mappers/types'\nimport type {\n EndpointAdapterFactory,\n EndpointAdapterOptions,\n ExtendableEndpointAdapter,\n} from './types'\nimport { deepMerge } from '@empathyco/x-deep-merge'\nimport { fetchHttpClient } from '../http-clients/fetch.http-client'\nimport { identityMapper } from '../mappers/identity.mapper'\nimport { interpolate } from '../utils/interpolate'\n\n/**\n * Factory to create {@link ExtendableEndpointAdapter | endpoint adapters} with the given\n * {@link EndpointAdapterOptions | options}.\n *\n * @param options - The {@link EndpointAdapterOptions | options} to create a new\n * {@link ExtendableEndpointAdapter} with.\n *\n * @returns A brand new {@link ExtendableEndpointAdapter} object.\n * @public\n */\nexport const endpointAdapterFactory: EndpointAdapterFactory = <Request, Response>(\n options: EndpointAdapterOptions<Request, Response>,\n) => {\n const endpointAdapter: ExtendableEndpointAdapter<Request, Response> = async (\n request,\n { endpoint: requestEndpoint, ...requestOptions } = {},\n ) => {\n const {\n endpoint: rawEndpoint,\n httpClient = fetchHttpClient,\n requestMapper = identityMapper,\n responseMapper = identityMapper,\n defaultRequestOptions = {},\n }: EndpointAdapterOptions<Request, Response> = options\n\n const endpoint = getEndpoint(requestEndpoint ?? rawEndpoint, request)\n const requestParameters = requestMapper(request, { endpoint })\n\n return httpClient(\n endpoint,\n deepMerge({}, defaultRequestOptions, requestOptions, { parameters: requestParameters }),\n ).then(response => responseMapper(response, { endpoint, requestParameters }))\n }\n\n endpointAdapter.extends = <NewRequest, NewResponse>(\n extendedOptions: Partial<EndpointAdapterOptions<NewRequest, NewResponse>>,\n ) =>\n endpointAdapterFactory<NewRequest, NewResponse>({\n ...options,\n ...extendedOptions,\n } as EndpointAdapterOptions<NewRequest, NewResponse>)\n\n return endpointAdapter\n}\n\n/**\n * Returns an endpoint.\n *\n * @param endpoint - The endpoint to process.\n * @param request - The request object.\n *\n * @returns The endpoint.\n * @internal\n */\nfunction getEndpoint<Request>(\n endpoint: string | Mapper<Request, string> | undefined,\n request: Request,\n): string {\n if (!endpoint) {\n throw new Error('Tried to make a request without an endpoint')\n }\n\n return typeof endpoint === 'function'\n ? endpoint(request, {})\n : interpolate(endpoint, request as Record<string, unknown>)\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.koFetchMock = exports.okFetchMock = void 0;
|
|
4
|
+
exports.fetchMock = fetchMock;
|
|
4
5
|
exports.okFetchMock = jest.fn(fetchMock({}));
|
|
5
6
|
exports.koFetchMock = jest.fn(async () => Promise.resolve({
|
|
6
7
|
ok: false,
|
|
@@ -35,5 +36,4 @@ function fetchMock(response) {
|
|
|
35
36
|
});
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
|
-
exports.fetchMock = fetchMock;
|
|
39
39
|
//# sourceMappingURL=fetch.mock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.mock.js","sourceRoot":"","sources":["../../../../src/http-clients/__mocks__/fetch.mock.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"fetch.mock.js","sourceRoot":"","sources":["../../../../src/http-clients/__mocks__/fetch.mock.ts"],"names":[],"mappings":";;;AAkBA,8BAmBC;AArCY,QAAA,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAA;AAEpC,QAAA,WAAW,GAAG,IAAI,CAAC,EAAE,CAAC,KAAK,IAAI,EAAE,CAC5C,OAAO,CAAC,OAAO,CAAC;IACd,EAAE,EAAE,KAAK;IACT,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IACrC,MAAM,EAAE,GAAG;IACX,UAAU,EAAE,kBAAkB;CAC/B,CAAC,CACH,CAAA;AACD;;;;;;;GAOG;AACH,SAAgB,SAAS,CACvB,QAAiB;IAEjB,OAAO,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;QAChC,OAAO,IAAI,OAAO,CAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC/C,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,CAAC;oBACpB,MAAM,CAAC,IAAI,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAA;gBACnD,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC;wBACN,EAAE,EAAE,IAAI;wBACR,MAAM,EAAE,GAAG;wBACX,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;wBAC3C,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;qBAChD,CAAC,CAAA;gBAChB,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC","sourcesContent":["export const okFetchMock = jest.fn(fetchMock({}))\n\nexport const koFetchMock = jest.fn(async () =>\n Promise.resolve({\n ok: false,\n json: async () => Promise.resolve({}),\n status: 500,\n statusText: 'Unexpected error',\n }),\n)\n/**\n * The `fetchMock()` method mocks a `fetch` API call.\n *\n * @param response - The expected response resolved by calling `fetch()`.\n * @returns A Promise object.\n *\n * @internal\n */\nexport function fetchMock(\n response: unknown,\n): (url: string, params: RequestInit) => Promise<Response> {\n return async (_url, { signal }) => {\n return new Promise<Response>((resolve, reject) => {\n setTimeout(() => {\n if (signal?.aborted) {\n reject(new DOMException('Aborted', 'AbortError'))\n } else {\n resolve({\n ok: true,\n status: 200,\n json: async () => Promise.resolve(response),\n text: async () => Promise.resolve(JSON.stringify(response)),\n } as Response)\n }\n })\n })\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/fetch.http-client.ts"],"names":[],"mappings":";;;AAEA,gDAA2D;AAC3D,mCAA0C;AAE1C;;;;;;;;;;;;;;;GAeG;AACI,MAAM,eAAe,GAAe,KAAK,EAC9C,QAAQ,EACR,EACE,EAAE,GAAG,QAAQ,EACb,UAAU,GAAG,IAAI,EACjB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,GACxB,GAAG,EAAE,EACN,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,IAAI,CAAC,eAAe,EAAE;
|
|
1
|
+
{"version":3,"file":"fetch.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/fetch.http-client.ts"],"names":[],"mappings":";;;AAEA,gDAA2D;AAC3D,mCAA0C;AAE1C;;;;;;;;;;;;;;;GAeG;AACI,MAAM,eAAe,GAAe,KAAK,EAC9C,QAAQ,EACR,EACE,EAAE,GAAG,QAAQ,EACb,UAAU,GAAG,IAAI,EACjB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,GACxB,GAAG,EAAE,EACN,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,UAAU,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IACD,MAAM,cAAc,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAA,gBAAQ,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IAC5E,MAAM,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnF,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,GAAG,UAAU;QACb,GAAG,cAAc;QACjB,GAAG,MAAM;KACV,CAAC,CAAC,IAAI,CAAC,cAAM,CAAC,CAAA;AACjB,CAAC,CAAA;AAxBY,QAAA,eAAe,mBAwB3B;AAED;;GAEG;AACH,MAAM,uBAAuB,GAAgC,EAAE,CAAA;AAE/D;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,EAAU;;IAC3C,MAAA,uBAAuB,CAAC,EAAE,CAAC,0CAAE,KAAK,EAAE,CAAA;IACpC,uBAAuB,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,CAAA;IACnD,OAAO,uBAAuB,CAAC,EAAE,CAAC,CAAC,MAAM,CAAA;AAC3C,CAAC","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\nimport type { HttpClient } from './types'\nimport { cleanEmpty, flatObject } from '@empathyco/x-utils'\nimport { buildUrl, toJson } from './utils'\n\n/**\n * The `fetchHttpClient()` function is a http client implementation using the `fetch` WebAPI.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n * @param options.cancelable - Cancelable option.\n * @param options.id - ID option.\n * @param options.parameters - Parameters option.\n * @param options.properties - Properties option.\n * @param options.sendEmptyParams - SendEmptyParams option.\n * @param options.sendParamsInBody - SendParamsInBody option.\n *\n * @returns A `Promise` object.\n *\n * @public\n */\nexport const fetchHttpClient: HttpClient = async (\n endpoint,\n {\n id = endpoint,\n cancelable = true,\n parameters = {},\n properties,\n sendParamsInBody = false,\n sendEmptyParams = false,\n } = {},\n) => {\n const signal = cancelable ? { signal: abortAndGetNewAbortSignal(id) } : {}\n if (!sendEmptyParams) {\n parameters = cleanEmpty(parameters)\n }\n const flatParameters = flatObject(parameters)\n const url = sendParamsInBody ? endpoint : buildUrl(endpoint, flatParameters)\n const bodyParameters = sendParamsInBody ? { body: JSON.stringify(parameters) } : {}\n\n return fetch(url, {\n ...properties,\n ...bodyParameters,\n ...signal,\n }).then(toJson)\n}\n\n/**\n * Dictionary with the request id as key and an `AbortController` as value.\n */\nconst requestAbortControllers: Dictionary<AbortController> = {}\n\n/**\n * Function that cancels previous request with the same `id` and returns a new `AbortSignal` for\n * the new request.\n *\n * @param id - The identifier of the request to cancel and create a new `AbortSignal`.\n *\n * @returns The new `AbortSignal`.\n */\nfunction abortAndGetNewAbortSignal(id: string): AbortSignal {\n requestAbortControllers[id]?.abort()\n requestAbortControllers[id] = new AbortController()\n return requestAbortControllers[id].signal\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toJson = toJson;
|
|
4
|
+
exports.buildUrl = buildUrl;
|
|
4
5
|
const x_utils_1 = require("@empathyco/x-utils");
|
|
5
6
|
const request_error_1 = require("./errors/request-error");
|
|
6
7
|
/**
|
|
@@ -21,7 +22,6 @@ async function toJson(response) {
|
|
|
21
22
|
throw new request_error_1.RequestError('Request failed', response);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
|
-
exports.toJson = toJson;
|
|
25
25
|
/**
|
|
26
26
|
* Builds a URL object based on the passed endpoint and the request parameters.
|
|
27
27
|
*
|
|
@@ -37,5 +37,4 @@ function buildUrl(endpoint, params = {}) {
|
|
|
37
37
|
(0, x_utils_1.forEach)(params, (key, value) => (Array.isArray(value) ? value : [value]).forEach(arrayItemValue => url.searchParams.append(key, String(arrayItemValue))));
|
|
38
38
|
return url.href;
|
|
39
39
|
}
|
|
40
|
-
exports.buildUrl = buildUrl;
|
|
41
40
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/http-clients/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/http-clients/utils.ts"],"names":[],"mappings":";;AAcA,wBAMC;AAYD,4BAQC;AAvCD,gDAA4C;AAC5C,0DAAqD;AAErD;;;;;;;;;GASG;AACI,KAAK,UAAU,MAAM,CAAC,QAAkB;IAC7C,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;QAChB,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACrE,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,4BAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAA;IACpD,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,QAAgB,EAAE,SAA8B,EAAE;IACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC7B,IAAA,iBAAO,EAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAC7B,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAChE,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,CACrD,CACF,CAAA;IACD,OAAO,GAAG,CAAC,IAAI,CAAA;AACjB,CAAC","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\nimport { forEach } from '@empathyco/x-utils'\nimport { RequestError } from './errors/request-error'\n\n/**\n * Formats a response object to JSON.\n *\n * @remarks If the `response.ok` is falsy, a `RequestError` object is thrown.\n *\n * @param response - The response to convert to JSON format.\n * @returns - The resultant promise of formatting the response to JSON.\n *\n * @public\n */\nexport async function toJson(response: Response): Promise<any> {\n if (response.ok) {\n return response.text().then(text => (text ? JSON.parse(text) : {}))\n } else {\n throw new RequestError('Request failed', response)\n }\n}\n\n/**\n * Builds a URL object based on the passed endpoint and the request parameters.\n *\n * @param endpoint - The endpoint.\n * @param params - The request parameters.\n *\n * @returns The `href` property of the newly built `URL` object.\n *\n * @public\n */\nexport function buildUrl(endpoint: string, params: Dictionary<unknown> = {}): URL['href'] {\n const url = new URL(endpoint)\n forEach(params, (key, value) =>\n (Array.isArray(value) ? value : [value]).forEach(arrayItemValue =>\n url.searchParams.append(key, String(arrayItemValue)),\n ),\n )\n return url.href\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.combineMappers =
|
|
3
|
+
exports.combineMappers = combineMappers;
|
|
4
4
|
const x_deep_merge_1 = require("@empathyco/x-deep-merge");
|
|
5
5
|
/**
|
|
6
6
|
* Combines the given {@link Mapper | mappers} into a single {@link Mapper | mapper function}.
|
|
@@ -17,5 +17,4 @@ function combineMappers(...mappers) {
|
|
|
17
17
|
return value;
|
|
18
18
|
}, {});
|
|
19
19
|
}
|
|
20
|
-
exports.combineMappers = combineMappers;
|
|
21
20
|
//# sourceMappingURL=combine-mappers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"combine-mappers.js","sourceRoot":"","sources":["../../../src/mappers/combine-mappers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"combine-mappers.js","sourceRoot":"","sources":["../../../src/mappers/combine-mappers.ts"],"names":[],"mappings":";;AAYA,wCASC;AAnBD,0DAAmD;AAEnD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,GAAG,OAAwC;IAE3C,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CACvB,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QAC/B,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QACzC,OAAO,CAAC,WAAW,GAAG,IAAA,wBAAS,EAAC,KAAK,EAAE,WAAW,CAAC,CAAA;QACnD,OAAO,KAAK,CAAA;IACd,CAAC,EAAE,EAAE,CAAO,CAAA;AAChB,CAAC","sourcesContent":["import type { DeepPartial } from '@empathyco/x-utils'\nimport type { Mapper } from './types'\nimport { deepMerge } from '@empathyco/x-deep-merge'\n\n/**\n * Combines the given {@link Mapper | mappers} into a single {@link Mapper | mapper function}.\n *\n * @param mappers - The {@link Mapper | mapper functions} to combine.\n * @returns The combined {@link Mapper | mapper function}.\n *\n * @public\n */\nexport function combineMappers<From, To>(\n ...mappers: Mapper<From, DeepPartial<To>>[]\n): Mapper<From, To> {\n return (from, context) =>\n mappers.reduce((value, mapper) => {\n const mappedValue = mapper(from, context)\n context.mappedValue = deepMerge(value, mappedValue)\n return value\n }, {}) as To\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.identityMapper =
|
|
3
|
+
exports.identityMapper = identityMapper;
|
|
4
4
|
/**
|
|
5
5
|
* Maps an entity to itself.
|
|
6
6
|
*
|
|
@@ -12,5 +12,4 @@ exports.identityMapper = void 0;
|
|
|
12
12
|
function identityMapper(value) {
|
|
13
13
|
return value;
|
|
14
14
|
}
|
|
15
|
-
exports.identityMapper = identityMapper;
|
|
16
15
|
//# sourceMappingURL=identity.mapper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity.mapper.js","sourceRoot":"","sources":["../../../src/mappers/identity.mapper.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"identity.mapper.js","sourceRoot":"","sources":["../../../src/mappers/identity.mapper.ts"],"names":[],"mappings":";;AAQA,wCAEC;AAVD;;;;;;;GAOG;AACH,SAAgB,cAAc,CAAY,KAAgB;IACxD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["/**\n * Maps an entity to itself.\n *\n * @param value - The entity to map.\n *\n * @returns The mapped entity.\n * @public\n */\nexport function identityMapper<Something>(value: Something): Something {\n return value\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.schemaMapperFactory =
|
|
3
|
+
exports.schemaMapperFactory = schemaMapperFactory;
|
|
4
4
|
const x_deep_merge_1 = require("@empathyco/x-deep-merge");
|
|
5
5
|
const x_utils_1 = require("@empathyco/x-utils");
|
|
6
6
|
const utils_1 = require("../schemas/utils");
|
|
@@ -17,7 +17,6 @@ function schemaMapperFactory(schema) {
|
|
|
17
17
|
return mapSchema(source, schema, context);
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
exports.schemaMapperFactory = schemaMapperFactory;
|
|
21
20
|
/**
|
|
22
21
|
* The `mapSchema()` function creates a new object populated with the transformations defined by a
|
|
23
22
|
* {@link Schema} applied to a source object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-mapper.factory.js","sourceRoot":"","sources":["../../../src/mappers/schema-mapper.factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema-mapper.factory.js","sourceRoot":"","sources":["../../../src/mappers/schema-mapper.factory.ts"],"names":[],"mappings":";;AAsBA,kDAMC;AAzBD,0DAAmD;AACnD,gDAO2B;AAC3B,4CAAwE;AAExE;;;;;;;GAOG;AACH,SAAg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;IACxB,CAAC;IACD,OAAO,IAAA,iBAAO,EAAC,SAAS,CAAC;QACvB,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAW,CAAC;QACtE,CAAC,CAAC,SAAS,CACP,SAAS,EACT,SAA6C,EAC7C,OAAO,CACR,CAAA;AACP,CAAC","sourcesContent":["import type { Dictionary, ExtractPath } from '@empathyco/x-utils'\nimport type { MutableSchema, Schema, SubSchemaTransformer } from '../schemas/types'\nimport type { Mapper, MapperContext } from './types'\nimport { deepMerge } from '@empathyco/x-deep-merge'\nimport {\n getSafePropertyChain,\n isArray,\n isFunction,\n isObject,\n isPath,\n reduce,\n} from '@empathyco/x-utils'\nimport { createMutableSchema, isInternalMethod } from '../schemas/utils'\n\n/**\n * The 'schemaMapperFactory' function creates a {@link Mapper | mapper function} for a given\n * {@link Schema | schema}.\n *\n * @param schema - The {@link Schema | schema} to apply in the {@link Mapper | mapper function}.\n * @returns A {@link Mapper | mapper function} that applies the given {@link Schema | schema}.\n * @public\n */\nexport function schemaMapperFactory<Source, Target>(\n schema: Schema<Source, Target> | MutableSchema<Source, Target>,\n): Mapper<Source, Target> {\n return function mapper(source: Source, context: MapperContext): Target {\n return mapSchema(source, schema, context)\n }\n}\n\n/**\n * The `mapSchema()` function creates a new object populated with the transformations defined by a\n * {@link Schema} applied to a source object.\n *\n * @param source - The object to apply the transformations to.\n * @param schema - The object that defines the transformations to apply.\n * @param context - The {@link MapperContext | mapper context} to feed the transformations with.\n * @returns A new object with each element being the result of the applied transformation.\n * @internal\n */\nfunction mapSchema<Source, Target>(\n source: Source,\n schema: Schema<Source, Target>,\n context: MapperContext,\n): Target {\n if (!source) {\n console.warn('This schema cannot be applied', createMutableSchema(schema))\n return undefined as any\n }\n return reduce(\n schema,\n (target, key, transformer) => {\n type TargetKey = Target[keyof Target]\n if (typeof transformer === 'string' && isPath(source, transformer)) {\n target[key] = getSafePropertyChain(source, transformer) as TargetKey\n } else if (isFunction(transformer) && !isInternalMethod(transformer.name)) {\n target[key] = transformer(source, context)\n } else if (isObject(transformer)) {\n const value =\n '$subSchema' in transformer\n ? (applySubSchemaTransformer<Source, TargetKey>(\n source,\n transformer as SubSchemaTransformer<Source, TargetKey>,\n context,\n schema as unknown as Schema<Source, TargetKey>,\n ) as TargetKey)\n : mapSchema<Source, TargetKey>(\n source,\n transformer as Schema<Source, TargetKey>,\n context,\n )\n\n if (value) {\n target[key] = value\n }\n }\n return target\n },\n {} as Target,\n )\n}\n\n/**\n * The `applySubSchemaTransformer()` function executes a `mapSchema()` function applying the defined\n * {@link SubSchemaTransformer.$subSchema}.\n *\n * @param source - The object to feed the schema.\n * @param subSchemaTransformer - The {@link SubSchemaTransformer} object with a $path, $subSchema\n * and $context options.\n * @param subSchemaTransformer.$path\n * @param subSchemaTransformer.$subSchema\n * @param subSchemaTransformer.$context\n * @param rawContext - The {@link MapperContext | mapper context} to feed the mapSchema function.\n * @param schema - The {@link Schema} to apply.\n * @returns The result of calling `mapSchema()` with the source, schema and context arguments.\n * @internal\n */\nfunction applySubSchemaTransformer<Source, Target>(\n source: Source,\n { $subSchema, $path, $context }: SubSchemaTransformer<Source, Target>,\n rawContext: MapperContext,\n schema: Schema<Source, Target>,\n): Target | Target[] | undefined {\n const subSource = getSafePropertyChain(source, $path)\n\n if (!subSource) {\n return\n }\n\n const extendedContext: Dictionary = {}\n if ($context) {\n Object.entries($context).forEach(([key, value]) => {\n if (['requestParameters', 'endpoint', 'mappedValue'].includes(key)) {\n return\n }\n extendedContext[key] = isFunction(value)\n ? value(source)\n : getSafePropertyChain(source, value as ExtractPath<typeof source>)\n })\n }\n\n const context = deepMerge({}, rawContext, $context, extendedContext)\n let subSchema: typeof $subSchema | typeof schema\n if ($subSchema === '$self') {\n subSchema = schema\n } else if (isFunction($subSchema)) {\n subSchema = $subSchema(source)\n } else {\n subSchema = $subSchema\n }\n return isArray(subSource)\n ? subSource.map(item => mapSchema(item, subSchema, context) as Target)\n : mapSchema<typeof subSource, Target>(\n subSource,\n subSchema as Schema<typeof subSource, Target>,\n context,\n )\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createMutableSchema = createMutableSchema;
|
|
4
|
+
exports.isInternalMethod = isInternalMethod;
|
|
4
5
|
const x_deep_merge_1 = require("@empathyco/x-deep-merge");
|
|
5
6
|
const x_utils_1 = require("@empathyco/x-utils");
|
|
6
7
|
/**
|
|
@@ -42,7 +43,6 @@ function createMutableSchema(schema) {
|
|
|
42
43
|
},
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
|
-
exports.createMutableSchema = createMutableSchema;
|
|
46
46
|
/**
|
|
47
47
|
* Checks if the given key is a {@link MutableSchema | mutableSchema} method.
|
|
48
48
|
*
|
|
@@ -56,7 +56,6 @@ exports.createMutableSchema = createMutableSchema;
|
|
|
56
56
|
function isInternalMethod(name) {
|
|
57
57
|
return mutableSchemasInternalMethods.includes(name);
|
|
58
58
|
}
|
|
59
|
-
exports.isInternalMethod = isInternalMethod;
|
|
60
59
|
/**
|
|
61
60
|
* Returns a string representing of the given object.
|
|
62
61
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/schemas/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/schemas/utils.ts"],"names":[],"mappings":";;AAkBA,kDA2BC;AAYD,4CAEC;AA1DD,0DAAmD;AACnD,gDAAkE;AAElE;;GAEG;AACH,MAAM,6BAA6B,GAAa,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;AAEjG;;;;;;;;GAQG;AACH,SAAgB,mBAAmB,CACjC,MAA8B;IAE9B,OAAO;QACL,GAAG,MAAM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AG,WAAW,MAAM,CAAA;QACvB,CAAC;aAAM,IAAI,CAAC,IAAA,oBAAU,EAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,sBAAsB,EAAE,CAAC;YAClF,MAAM,IAAI,GAAG,WAAW,GAAG,GAAG,KAAK,KAAY,KAAK,CAAA;QACtD,CAAC;IACH,CAAC,CAAC,CAAA;IACF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import type { MutableSchema, Schema } from './types'\nimport { deepMerge } from '@empathyco/x-deep-merge'\nimport { forEach, isFunction, isObject } from '@empathyco/x-utils'\n\n/**\n * Collection of internal method names for {@link MutableSchema | mutable schemas}.\n */\nconst mutableSchemasInternalMethods: string[] = ['$replace', '$override', '$extends', 'toString']\n\n/**\n * Creates a {@link MutableSchema | mutable schema } version of a given {@link Schema | schema}.\n *\n * @param schema - The {@link Schema | schema} to make mutable.\n *\n * @returns A {@link MutableSchema | mutable schema} version of the given {@link Schema | schema}.\n *\n * @public\n */\nexport function createMutableSchema<Source, Target>(\n schema: Schema<Source, Target>,\n): MutableSchema<Source, Target> {\n return {\n ...schema,\n $replace(newSchema) {\n forEach(this, key => {\n if (isInternalMethod(key as string)) {\n return\n }\n delete this[key]\n })\n Object.assign(this, newSchema)\n /* We are replacing the schema with a completely new schema , so it makes sense that TS\n complains that the old schema and the new one are not the same. */\n return this as any\n },\n $override(newSchema) {\n return deepMerge(this, newSchema)\n },\n $extends(newSchema: unknown) {\n return deepMerge({}, this, newSchema)\n },\n toString(includeInternalMethods = false) {\n return serialize(this, !!includeInternalMethods)\n },\n }\n}\n\n/**\n * Checks if the given key is a {@link MutableSchema | mutableSchema} method.\n *\n * @param name - The key to check.\n *\n * @returns True if it is a {@link MutableSchema | mutableSchema} method,\n * false otherwise.\n *\n * @public\n */\nexport function isInternalMethod(name: string): boolean {\n return mutableSchemasInternalMethods.includes(name)\n}\n\n/**\n * Returns a string representing of the given object.\n *\n * @param data - The object to get the string representation from.\n * @param includeInternalMethods - Flag to include in the string representation\n * the internal methods. Disabled by default.\n * @param deep - The level of indentation.\n * @returns The string representation.\n */\nfunction serialize(\n data: Record<string, unknown>,\n includeInternalMethods: boolean,\n deep = 0,\n): string {\n const indentation = ' '.repeat(deep)\n let output = ''\n forEach(data, (key, value) => {\n if (isObject(value)) {\n output += `${indentation}${key}: {\\n${serialize(\n value,\n includeInternalMethods,\n ++deep,\n )}${indentation}},\\n`\n } else if (!isFunction(value) || !isInternalMethod(key) || includeInternalMethods) {\n output += `${indentation}${key}: ${value as any},\\n`\n }\n })\n return output\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.interpolate =
|
|
3
|
+
exports.interpolate = interpolate;
|
|
4
4
|
const x_utils_1 = require("@empathyco/x-utils");
|
|
5
5
|
/**
|
|
6
6
|
* Syntax to detect and extract string parameters. A string parameter contains a property name
|
|
@@ -100,5 +100,4 @@ function interpolate(string, parameters) {
|
|
|
100
100
|
return value ? `${String(head)}${String(value)}${String(tail)}` : '';
|
|
101
101
|
}));
|
|
102
102
|
}
|
|
103
|
-
exports.interpolate = interpolate;
|
|
104
103
|
//# sourceMappingURL=interpolate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interpolate.js","sourceRoot":"","sources":["../../../src/utils/interpolate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interpolate.js","sourceRoot":"","sources":["../../../src/utils/interpolate.ts"],"names":[],"mappings":";;AA6FA,kCAaC;AA1GD,gDAAyD;AAEzD;;;;;;;;;;;;;GAaG;AACH,MAAM,iBAAiB,GAAG,cAAc,CAAA;AAExC;;;;;GAKG;AACH,MAAM,YAAY,GAAG,iBAAiB,CAAA;AACtC;;;;;;;;;;;;;;;GAeG;AACH,oGAAoG;AACpG,MAAM,wBAAwB,GAAG,IAAI,MAAM,CAAC,IAAI,YAAY,UAAU,YAAY,GAAG,EAAE,GAAG,CAAC,CAAA;AAE3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,SAAgB,WAAW,CAAC,MAAc,EAAE,UAAmC;IAC7E,OAAO,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,iBAAyB,EAAE,EAAE,CAC7E,iBAAiB,CAAC,OAAO,CACvB,wBAAwB,EACxB,CAAC,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,QAAgB,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;QACjD,MAAM,KAAK,GAAG,IAAA,8BAAoB,EAAC,UAAU,EAAE,QAAQ,CAAC,CAAA;QACxD;;4DAEoD;QACpD,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IACtE,CAAC,CACF,CACF,CAAA;AACH,CAAC","sourcesContent":["import { getSafePropertyChain } from '@empathyco/x-utils'\n\n/**\n * Syntax to detect and extract string parameters. A string parameter contains a property name\n * with an optional header or tail to concatenate wrapped in curly braces (`{}`).\n * The different parts of a string parameter are explained in {@link STRING_PARAMETER_CONTENT}.\n *\n * @example Different string parameters\n * ```js\n * \"\\{env\\}\" // No optional head or tail.\n * \"\\{(.)env\\}\" // Optional `.` head.\n * \"\\{env(-api)\\}\" // Optional `-api` tail.\n * \"\\{(api-)env(.)\\}\" // Optional `api-` head and `.` tail.\n * ```\n * @internal\n */\nconst STRING_PARAMETERS = /\\{([^}]+)\\}/g\n\n/**\n * Shape of the optional head and tail parts of the {@link STRING_PARAMETER_CONTENT} regex.\n * This can be anything wrapped into parentheses.\n *\n * @internal\n */\nconst HEAD_OR_TAIL = '(?:\\\\((.+)\\\\))?'\n/**\n * Syntax of a single string parameter. A string parameter shape is composed by\n * the name of the property that should be replaced. This property name can be preceded\n * or followed by an optional string to prepend or to append to the property value\n * in case it is defined.\n *\n * @example Valid string parameters content\n * ```js\n * \"env\" // No optional head or tail to concatenate.\n * \"(.)env\" // The `.` character will be prepended as long as the `env` property is defined.\n * \"env(-api)\" // The `-api` string will be appended as long as the `env` property is defined.\n * \"(api-)env(.)\" // The `api-` string and the `.` character will be added as long as\n * // the `env` property is defined.\n * ```\n * @internal\n */\n// eslint-disable-next-line regexp/no-misleading-capturing-group,regexp/no-super-linear-backtracking\nconst STRING_PARAMETER_CONTENT = new RegExp(`^${HEAD_OR_TAIL}([^(]+)${HEAD_OR_TAIL}$`, 'g')\n\n/**\n * Interpolates different parameters into a string.\n * The provided string can set the parameters to replace wrapping a parameter name in curly\n * braces. This will then be replaced by the parameter value as long as it is defined. If it\n * is not provided, the parameter name will just be removed from the final string.\n *\n * @param string - The string to interpolate different parameters in.\n * @param parameters - Value of the different parameters to interpolate.\n * @returns The interpolated string.\n * @example Different usages of the interpolate function.\n * ```js\n * interpolate('https://{env}.empathy.co/{instance}', {\n * env: 'live',\n * instance: 'demo'\n * }) // 'https://live.empathy.co/demo'\n *\n * interpolate('https://{(api-)env}.empathy.co/{instance}', {\n * env: 'live',\n * instance: 'demo'\n * }) // 'https://api-live.empathy.co/demo'\n *\n * interpolate('https://api.{env(.)}empathy.co/{instance}', {\n * env: 'live',\n * instance: 'demo'\n * }) // 'https://api.live.empathy.co/demo'\n *\n * interpolate('https://{(api-)env(.)}empathy.co/{instance}', {\n * env: 'live',\n * instance: 'demo'\n * }) // 'https://api-live.empathy.co/demo'\n *\n * interpolate('https://{env}.empathy.co/{instance}', {\n * env: 'live'\n * }) // 'https://live.empathy.co/'\n *\n * interpolate('https://search{(api-)env}.empathy.co/{instance}', {\n * instance: 'demo'\n * }) // 'https://search.empathy.co/demo'\n *\n * interpolate('https://api.{env(.)}empathy.co/{instance}', {\n * instance: 'demo'\n * }) // 'https://api.empathy.co/demo'\n *\n * interpolate('https://search.{(api-)env(.)}empathy.co/{instance}', {\n * instance: 'demo'\n * }) // 'https://search.empathy.co/demo'\n * ```\n * @public\n */\nexport function interpolate(string: string, parameters: Record<string, unknown>): string {\n return string.replace(STRING_PARAMETERS, (_match, propertyToReplace: string) =>\n propertyToReplace.replace(\n STRING_PARAMETER_CONTENT,\n (_match, head = '', property: string, tail = '') => {\n const value = getSafePropertyChain(parameters, property)\n /* As the replacer function has a very dynamic signature, it is typed as a function with\n * `any` arguments. This makes it impossible for TS to infer the correct `string`\n * type that we are using as default values here. */\n return value ? `${String(head)}${String(value)}${String(tail)}` : ''\n },\n ),\n )\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint-adapter.factory.js","sourceRoot":"","sources":["../../../src/endpoint-adapter/endpoint-adapter.factory.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAA2B,CAC5D,OAAkD,EAClD,EAAE;IACF,MAAM,eAAe,GAAiD,KAAK,EACzE,OAAO,EACP,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,cAAc,EAAE,GAAG,EAAE,EACrD,EAAE;QACF,MAAM,EACJ,QAAQ,EAAE,WAAW,EACrB,UAAU,GAAG,eAAe,EAC5B,aAAa,GAAG,cAAc,EAC9B,cAAc,GAAG,cAAc,EAC/B,qBAAqB,GAAG,EAAE,GAC3B,GAA8C,OAAO,CAAA;QAEtD,MAAM,QAAQ,GAAG,WAAW,CAAC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,WAAW,EAAE,OAAO,CAAC,CAAA;QACrE,MAAM,iBAAiB,GAAG,aAAa,CAA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EAAE,GAC3B,GAA8C,OAAO,CAAA;QAEtD,MAAM,QAAQ,GAAG,WAAW,CAAC,eAAe,aAAf,eAAe,cAAf,eAAe,GAAI,WAAW,EAAE,OAAO,CAAC,CAAA;QACrE,MAAM,iBAAiB,GAAG,aAAa,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAA;QAE9D,OAAO,UAAU,CACf,QAAQ,EACR,SAAS,CAAC,EAAE,EAAE,qBAAqB,EAAE,cAAc,EAAE,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC,CACxF,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,cAAc,CAAC,QAAQ,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE,CAAC,CAAC,CAAA;IAC/E,CAAC,CAAA;IAED,eAAe,CAAC,OAAO,GAAG,CACxB,eAAyE,EACzE,EAAE,CACF,sBAAsB,CAA0B;QAC9C,GAAG,OAAO;QACV,GAAG,eAAe;KACgC,CAAC,CAAA;IAEvD,OAAO,eAAe,CAAA;AACxB,CAAC,CAAA;AAED;;;;;;;;GAQG;AACH,SAAS,WAAW,CAClB,QAAsD,EACtD,OAAgB;IAEhB,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChE,CAAC;IAED,OAAO,OAAO,QAAQ,KAAK,UAAU;QACnC,CAAC,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC;QACvB,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAkC,CAAC,CAAA;AAC/D,CAAC","sourcesContent":["import type { Mapper } from '../mappers/types'\nimport type {\n EndpointAdapterFactory,\n EndpointAdapterOptions,\n ExtendableEndpointAdapter,\n} from './types'\nimport { deepMerge } from '@empathyco/x-deep-merge'\nimport { fetchHttpClient } from '../http-clients/fetch.http-client'\nimport { identityMapper } from '../mappers/identity.mapper'\nimport { interpolate } from '../utils/interpolate'\n\n/**\n * Factory to create {@link ExtendableEndpointAdapter | endpoint adapters} with the given\n * {@link EndpointAdapterOptions | options}.\n *\n * @param options - The {@link EndpointAdapterOptions | options} to create a new\n * {@link ExtendableEndpointAdapter} with.\n *\n * @returns A brand new {@link ExtendableEndpointAdapter} object.\n * @public\n */\nexport const endpointAdapterFactory: EndpointAdapterFactory = <Request, Response>(\n options: EndpointAdapterOptions<Request, Response>,\n) => {\n const endpointAdapter: ExtendableEndpointAdapter<Request, Response> = async (\n request,\n { endpoint: requestEndpoint, ...requestOptions } = {},\n ) => {\n const {\n endpoint: rawEndpoint,\n httpClient = fetchHttpClient,\n requestMapper = identityMapper,\n responseMapper = identityMapper,\n defaultRequestOptions = {},\n }: EndpointAdapterOptions<Request, Response> = options\n\n const endpoint = getEndpoint(requestEndpoint ?? rawEndpoint, request)\n const requestParameters = requestMapper(request, { endpoint })\n\n return httpClient(\n endpoint,\n deepMerge({}, defaultRequestOptions, requestOptions, { parameters: requestParameters }),\n ).then(response => responseMapper(response, { endpoint, requestParameters }))\n }\n\n endpointAdapter.extends = <NewRequest, NewResponse>(\n extendedOptions: Partial<EndpointAdapterOptions<NewRequest, NewResponse>>,\n ) =>\n endpointAdapterFactory<NewRequest, NewResponse>({\n ...options,\n ...extendedOptions,\n } as EndpointAdapterOptions<NewRequest, NewResponse>)\n\n return endpointAdapter\n}\n\n/**\n * Returns an endpoint.\n *\n * @param endpoint - The endpoint to process.\n * @param request - The request object.\n *\n * @returns The endpoint.\n * @internal\n */\nfunction getEndpoint<Request>(\n endpoint: string | Mapper<Request, string> | undefined,\n request: Request,\n): string {\n if (!endpoint) {\n throw new Error('Tried to make a request without an endpoint')\n }\n\n return typeof endpoint === 'function'\n ? endpoint(request, {})\n : interpolate(endpoint, request as Record<string, unknown>)\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.mock.js","sourceRoot":"","sources":["../../../../src/http-clients/__mocks__/fetch.mock.ts"],"names":[],"mappings":"AAAA,MAAM,CAA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,EAAE,EAAE;QAChC,OAAO,IAAI,OAAO,CAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC/C,UAAU,CAAC,GAAG,EAAE;gBACd,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,EAAE,CAAC;oBACpB,MAAM,CAAC,IAAI,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC,CAAA;gBACnD,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC;wBACN,EAAE,EAAE,IAAI;wBACR,MAAM,EAAE,GAAG;wBACX,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;wBAC3C,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;qBAChD,CAAC,CAAA;gBAChB,CAAC;YACH,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;AACH,CAAC","sourcesContent":["export const okFetchMock = jest.fn(fetchMock({}))\n\nexport const koFetchMock = jest.fn(async () =>\n Promise.resolve({\n ok: false,\n json: async () => Promise.resolve({}),\n status: 500,\n statusText: 'Unexpected error',\n }),\n)\n/**\n * The `fetchMock()` method mocks a `fetch` API call.\n *\n * @param response - The expected response resolved by calling `fetch()`.\n * @returns A Promise object.\n *\n * @internal\n */\nexport function fetchMock(\n response: unknown,\n): (url: string, params: RequestInit) => Promise<Response> {\n return async (_url, { signal }) => {\n return new Promise<Response>((resolve, reject) => {\n setTimeout(() => {\n if (signal?.aborted) {\n reject(new DOMException('Aborted', 'AbortError'))\n } else {\n resolve({\n ok: true,\n status: 200,\n json: async () => Promise.resolve(response),\n text: async () => Promise.resolve(JSON.stringify(response)),\n } as Response)\n }\n })\n })\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/fetch.http-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,eAAe,GAAe,KAAK,EAC9C,QAAQ,EACR,EACE,EAAE,GAAG,QAAQ,EACb,UAAU,GAAG,IAAI,EACjB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,GACxB,GAAG,EAAE,EACN,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,IAAI,CAAC,eAAe,EAAE;
|
|
1
|
+
{"version":3,"file":"fetch.http-client.js","sourceRoot":"","sources":["../../../src/http-clients/fetch.http-client.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAE1C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,eAAe,GAAe,KAAK,EAC9C,QAAQ,EACR,EACE,EAAE,GAAG,QAAQ,EACb,UAAU,GAAG,IAAI,EACjB,UAAU,GAAG,EAAE,EACf,UAAU,EACV,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,GACxB,GAAG,EAAE,EACN,EAAE;IACF,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,yBAAyB,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAC1E,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IACrC,CAAC;IACD,MAAM,cAAc,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;IAC5E,MAAM,cAAc,GAAG,gBAAgB,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAA;IAEnF,OAAO,KAAK,CAAC,GAAG,EAAE;QAChB,GAAG,UAAU;QACb,GAAG,cAAc;QACjB,GAAG,MAAM;KACV,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AACjB,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,uBAAuB,GAAgC,EAAE,CAAA;AAE/D;;;;;;;GAOG;AACH,SAAS,yBAAyB,CAAC,EAAU;;IAC3C,MAAA,uBAAuB,CAAC,EAAE,CAAC,0CAAE,KAAK,EAAE,CAAA;IACpC,uBAAuB,CAAC,EAAE,CAAC,GAAG,IAAI,eAAe,EAAE,CAAA;IACnD,OAAO,uBAAuB,CAAC,EAAE,CAAC,CAAC,MAAM,CAAA;AAC3C,CAAC","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\nimport type { HttpClient } from './types'\nimport { cleanEmpty, flatObject } from '@empathyco/x-utils'\nimport { buildUrl, toJson } from './utils'\n\n/**\n * The `fetchHttpClient()` function is a http client implementation using the `fetch` WebAPI.\n *\n * @param endpoint - The endpoint to make the request to.\n * @param options - The request options.\n * @param options.cancelable - Cancelable option.\n * @param options.id - ID option.\n * @param options.parameters - Parameters option.\n * @param options.properties - Properties option.\n * @param options.sendEmptyParams - SendEmptyParams option.\n * @param options.sendParamsInBody - SendParamsInBody option.\n *\n * @returns A `Promise` object.\n *\n * @public\n */\nexport const fetchHttpClient: HttpClient = async (\n endpoint,\n {\n id = endpoint,\n cancelable = true,\n parameters = {},\n properties,\n sendParamsInBody = false,\n sendEmptyParams = false,\n } = {},\n) => {\n const signal = cancelable ? { signal: abortAndGetNewAbortSignal(id) } : {}\n if (!sendEmptyParams) {\n parameters = cleanEmpty(parameters)\n }\n const flatParameters = flatObject(parameters)\n const url = sendParamsInBody ? endpoint : buildUrl(endpoint, flatParameters)\n const bodyParameters = sendParamsInBody ? { body: JSON.stringify(parameters) } : {}\n\n return fetch(url, {\n ...properties,\n ...bodyParameters,\n ...signal,\n }).then(toJson)\n}\n\n/**\n * Dictionary with the request id as key and an `AbortController` as value.\n */\nconst requestAbortControllers: Dictionary<AbortController> = {}\n\n/**\n * Function that cancels previous request with the same `id` and returns a new `AbortSignal` for\n * the new request.\n *\n * @param id - The identifier of the request to cancel and create a new `AbortSignal`.\n *\n * @returns The new `AbortSignal`.\n */\nfunction abortAndGetNewAbortSignal(id: string): AbortSignal {\n requestAbortControllers[id]?.abort()\n requestAbortControllers[id] = new AbortController()\n return requestAbortControllers[id].signal\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/http-clients/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,QAAkB;IAC7C,IAAI,QAAQ,CAAC,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/http-clients/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAErD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,QAAkB;IAC7C,IAAI,QAAQ,CAAC,EAAE,EAAE,CAAC;QAChB,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACrE,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,YAAY,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAA;IACpD,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAC,QAAgB,EAAE,SAA8B,EAAE;IACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC7B,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAC7B,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAChE,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC,CACrD,CACF,CAAA;IACD,OAAO,GAAG,CAAC,IAAI,CAAA;AACjB,CAAC","sourcesContent":["import type { Dictionary } from '@empathyco/x-utils'\nimport { forEach } from '@empathyco/x-utils'\nimport { RequestError } from './errors/request-error'\n\n/**\n * Formats a response object to JSON.\n *\n * @remarks If the `response.ok` is falsy, a `RequestError` object is thrown.\n *\n * @param response - The response to convert to JSON format.\n * @returns - The resultant promise of formatting the response to JSON.\n *\n * @public\n */\nexport async function toJson(response: Response): Promise<any> {\n if (response.ok) {\n return response.text().then(text => (text ? JSON.parse(text) : {}))\n } else {\n throw new RequestError('Request failed', response)\n }\n}\n\n/**\n * Builds a URL object based on the passed endpoint and the request parameters.\n *\n * @param endpoint - The endpoint.\n * @param params - The request parameters.\n *\n * @returns The `href` property of the newly built `URL` object.\n *\n * @public\n */\nexport function buildUrl(endpoint: string, params: Dictionary<unknown> = {}): URL['href'] {\n const url = new URL(endpoint)\n forEach(params, (key, value) =>\n (Array.isArray(value) ? value : [value]).forEach(arrayItemValue =>\n url.searchParams.append(key, String(arrayItemValue)),\n ),\n )\n return url.href\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-mapper.factory.js","sourceRoot":"","sources":["../../../src/mappers/schema-mapper.factory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EACL,oBAAoB,EACpB,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,MAAM,GACP,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExE;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA8D;IAE9D,OAAO,SAAS,MAAM,CAAC,MAAc,EAAE,OAAsB;QAC3D,OAAO,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;IAC3C,CAAC,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,SAAS,CAChB,MAAc,EACd,MAA8B,EAC9B,OAAsB;IAEtB,IAAI,CAAC,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"schema-mapper.factory.js","sourceRoot":"","sources":["../../../src/mappers/schema-mapper.factory.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EACL,oBAAoB,EACpB,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,MAAM,GACP,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExE;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAC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I,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,CAAW,CAAC;QACtE,CAAC,CAAC,SAAS,CACP,SAAS,EACT,SAA6C,EAC7C,OAAO,CACR,CAAA;AACP,CAAC","sourcesContent":["import type { Dictionary, ExtractPath } from '@empathyco/x-utils'\nimport type { MutableSchema, Schema, SubSchemaTransformer } from '../schemas/types'\nimport type { Mapper, MapperContext } from './types'\nimport { deepMerge } from '@empathyco/x-deep-merge'\nimport {\n getSafePropertyChain,\n isArray,\n isFunction,\n isObject,\n isPath,\n reduce,\n} from '@empathyco/x-utils'\nimport { createMutableSchema, isInternalMethod } from '../schemas/utils'\n\n/**\n * The 'schemaMapperFactory' function creates a {@link Mapper | mapper function} for a given\n * {@link Schema | schema}.\n *\n * @param schema - The {@link Schema | schema} to apply in the {@link Mapper | mapper function}.\n * @returns A {@link Mapper | mapper function} that applies the given {@link Schema | schema}.\n * @public\n */\nexport function schemaMapperFactory<Source, Target>(\n schema: Schema<Source, Target> | MutableSchema<Source, Target>,\n): Mapper<Source, Target> {\n return function mapper(source: Source, context: MapperContext): Target {\n return mapSchema(source, schema, context)\n }\n}\n\n/**\n * The `mapSchema()` function creates a new object populated with the transformations defined by a\n * {@link Schema} applied to a source object.\n *\n * @param source - The object to apply the transformations to.\n * @param schema - The object that defines the transformations to apply.\n * @param context - The {@link MapperContext | mapper context} to feed the transformations with.\n * @returns A new object with each element being the result of the applied transformation.\n * @internal\n */\nfunction mapSchema<Source, Target>(\n source: Source,\n schema: Schema<Source, Target>,\n context: MapperContext,\n): Target {\n if (!source) {\n console.warn('This schema cannot be applied', createMutableSchema(schema))\n return undefined as any\n }\n return reduce(\n schema,\n (target, key, transformer) => {\n type TargetKey = Target[keyof Target]\n if (typeof transformer === 'string' && isPath(source, transformer)) {\n target[key] = getSafePropertyChain(source, transformer) as TargetKey\n } else if (isFunction(transformer) && !isInternalMethod(transformer.name)) {\n target[key] = transformer(source, context)\n } else if (isObject(transformer)) {\n const value =\n '$subSchema' in transformer\n ? (applySubSchemaTransformer<Source, TargetKey>(\n source,\n transformer as SubSchemaTransformer<Source, TargetKey>,\n context,\n schema as unknown as Schema<Source, TargetKey>,\n ) as TargetKey)\n : mapSchema<Source, TargetKey>(\n source,\n transformer as Schema<Source, TargetKey>,\n context,\n )\n\n if (value) {\n target[key] = value\n }\n }\n return target\n },\n {} as Target,\n )\n}\n\n/**\n * The `applySubSchemaTransformer()` function executes a `mapSchema()` function applying the defined\n * {@link SubSchemaTransformer.$subSchema}.\n *\n * @param source - The object to feed the schema.\n * @param subSchemaTransformer - The {@link SubSchemaTransformer} object with a $path, $subSchema\n * and $context options.\n * @param subSchemaTransformer.$path\n * @param subSchemaTransformer.$subSchema\n * @param subSchemaTransformer.$context\n * @param rawContext - The {@link MapperContext | mapper context} to feed the mapSchema function.\n * @param schema - The {@link Schema} to apply.\n * @returns The result of calling `mapSchema()` with the source, schema and context arguments.\n * @internal\n */\nfunction applySubSchemaTransformer<Source, Target>(\n source: Source,\n { $subSchema, $path, $context }: SubSchemaTransformer<Source, Target>,\n rawContext: MapperContext,\n schema: Schema<Source, Target>,\n): Target | Target[] | undefined {\n const subSource = getSafePropertyChain(source, $path)\n\n if (!subSource) {\n return\n }\n\n const extendedContext: Dictionary = {}\n if ($context) {\n Object.entries($context).forEach(([key, value]) => {\n if (['requestParameters', 'endpoint', 'mappedValue'].includes(key)) {\n return\n }\n extendedContext[key] = isFunction(value)\n ? value(source)\n : getSafePropertyChain(source, value as ExtractPath<typeof source>)\n })\n }\n\n const context = deepMerge({}, rawContext, $context, extendedContext)\n let subSchema: typeof $subSchema | typeof schema\n if ($subSchema === '$self') {\n subSchema = schema\n } else if (isFunction($subSchema)) {\n subSchema = $subSchema(source)\n } else {\n subSchema = $subSchema\n }\n return isArray(subSource)\n ? subSource.map(item => mapSchema(item, subSchema, context) as Target)\n : mapSchema<typeof subSource, Target>(\n subSource,\n subSchema as Schema<typeof subSource, Target>,\n context,\n )\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/schemas/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElE;;GAEG;AACH,MAAM,6BAA6B,GAAa,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;AAEjG;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA8B;IAE9B,OAAO;QACL,GAAG,MAAM;QACT,QAAQ,CAAC,SAAS;YAChB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;gBAClB,IAAI,gBAAgB,CAAC,GAAa,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/schemas/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElE;;GAEG;AACH,MAAM,6BAA6B,GAAa,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;AAEjG;;;;;;;;GAQG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAA8B;IAE9B,OAAO;QACL,GAAG,MAAM;QACT,QAAQ,CAAC,SAAS;YAChB,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE;gBAClB,IAAI,gBAAgB,CAAC,GAAa,CAAC,EAAE,CAAC;oBACpC,OAAM;gBACR,CAAC;gBACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;YAClB,CAAC,CAAC,CAAA;YACF,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;YAC9B;+EACmE;YACnE,OAAO,I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-merge'\nimport { forEach, isFunction, isObject } from '@empathyco/x-utils'\n\n/**\n * Collection of internal method names for {@link MutableSchema | mutable schemas}.\n */\nconst mutableSchemasInternalMethods: string[] = ['$replace', '$override', '$extends', 'toString']\n\n/**\n * Creates a {@link MutableSchema | mutable schema } version of a given {@link Schema | schema}.\n *\n * @param schema - The {@link Schema | schema} to make mutable.\n *\n * @returns A {@link MutableSchema | mutable schema} version of the given {@link Schema | schema}.\n *\n * @public\n */\nexport function createMutableSchema<Source, Target>(\n schema: Schema<Source, Target>,\n): MutableSchema<Source, Target> {\n return {\n ...schema,\n $replace(newSchema) {\n forEach(this, key => {\n if (isInternalMethod(key as string)) {\n return\n }\n delete this[key]\n })\n Object.assign(this, newSchema)\n /* We are replacing the schema with a completely new schema , so it makes sense that TS\n complains that the old schema and the new one are not the same. */\n return this as any\n },\n $override(newSchema) {\n return deepMerge(this, newSchema)\n },\n $extends(newSchema: unknown) {\n return deepMerge({}, this, newSchema)\n },\n toString(includeInternalMethods = false) {\n return serialize(this, !!includeInternalMethods)\n },\n }\n}\n\n/**\n * Checks if the given key is a {@link MutableSchema | mutableSchema} method.\n *\n * @param name - The key to check.\n *\n * @returns True if it is a {@link MutableSchema | mutableSchema} method,\n * false otherwise.\n *\n * @public\n */\nexport function isInternalMethod(name: string): boolean {\n return mutableSchemasInternalMethods.includes(name)\n}\n\n/**\n * Returns a string representing of the given object.\n *\n * @param data - The object to get the string representation from.\n * @param includeInternalMethods - Flag to include in the string representation\n * the internal methods. Disabled by default.\n * @param deep - The level of indentation.\n * @returns The string representation.\n */\nfunction serialize(\n data: Record<string, unknown>,\n includeInternalMethods: boolean,\n deep = 0,\n): string {\n const indentation = ' '.repeat(deep)\n let output = ''\n forEach(data, (key, value) => {\n if (isObject(value)) {\n output += `${indentation}${key}: {\\n${serialize(\n value,\n includeInternalMethods,\n ++deep,\n )}${indentation}},\\n`\n } else if (!isFunction(value) || !isInternalMethod(key) || includeInternalMethods) {\n output += `${indentation}${key}: ${value as any},\\n`\n }\n })\n return output\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empathyco/x-adapter",
|
|
3
|
-
"version": "8.1.0-alpha.
|
|
3
|
+
"version": "8.1.0-alpha.6",
|
|
4
4
|
"description": "A utils library to create a client for any API",
|
|
5
5
|
"author": "Empathy Systems Corporation S.L.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -41,20 +41,20 @@
|
|
|
41
41
|
"prepublishOnly": "pnpm run build"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@empathyco/x-deep-merge": "^2.0.3-alpha.
|
|
45
|
-
"@empathyco/x-utils": "^1.0.3-alpha.
|
|
46
|
-
"tslib": "~2.
|
|
44
|
+
"@empathyco/x-deep-merge": "^2.0.3-alpha.7",
|
|
45
|
+
"@empathyco/x-utils": "^1.0.3-alpha.6",
|
|
46
|
+
"tslib": "~2.8.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/jest": "27.5.0",
|
|
50
|
-
"concurrently": "8.2.
|
|
50
|
+
"concurrently": "8.2.2",
|
|
51
51
|
"jest": "27.5.0",
|
|
52
52
|
"rimraf": "3.0.2",
|
|
53
53
|
"ts-jest": "27.1.0",
|
|
54
|
-
"typescript": "
|
|
54
|
+
"typescript": "5.8.3"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "34cf2da4d594e0e65548e3d3a375fc01ba1bf483"
|
|
60
60
|
}
|