@empathyco/x-adapter 8.0.0-alpha.8 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +683 -5
  2. package/dist/cjs/http-clients/fetch.http-client.js +2 -2
  3. package/dist/cjs/http-clients/fetch.http-client.js.map +1 -1
  4. package/dist/cjs/mappers/schema-mapper.factory.js +3 -4
  5. package/dist/cjs/mappers/schema-mapper.factory.js.map +1 -1
  6. package/dist/cjs/schemas/types.js.map +1 -1
  7. package/dist/cjs/schemas/utils.js +7 -5
  8. package/dist/cjs/schemas/utils.js.map +1 -1
  9. package/dist/cjs/utils/index.js +0 -1
  10. package/dist/cjs/utils/index.js.map +1 -1
  11. package/dist/cjs/utils/interpolate.js +3 -3
  12. package/dist/cjs/utils/interpolate.js.map +1 -1
  13. package/dist/esm/http-clients/fetch.http-client.js +3 -3
  14. package/dist/esm/http-clients/fetch.http-client.js.map +1 -1
  15. package/dist/esm/mappers/schema-mapper.factory.js +4 -5
  16. package/dist/esm/mappers/schema-mapper.factory.js.map +1 -1
  17. package/dist/esm/schemas/types.js.map +1 -1
  18. package/dist/esm/schemas/utils.js +7 -5
  19. package/dist/esm/schemas/utils.js.map +1 -1
  20. package/dist/esm/utils/index.js +0 -1
  21. package/dist/esm/utils/index.js.map +1 -1
  22. package/dist/esm/utils/interpolate.js +3 -3
  23. package/dist/esm/utils/interpolate.js.map +1 -1
  24. package/dist/types/endpoint-adapter/types.d.ts +1 -1
  25. package/dist/types/http-clients/types.d.ts +1 -1
  26. package/dist/types/mappers/schema-mapper.factory.d.ts +2 -2
  27. package/dist/types/mappers/types.d.ts +1 -1
  28. package/dist/types/schemas/types.d.ts +14 -12
  29. package/dist/types/schemas/utils.d.ts +1 -1
  30. package/dist/types/utils/index.d.ts +0 -1
  31. package/package.json +18 -14
  32. package/dist/cjs/utils/extract-value.js +0 -28
  33. package/dist/cjs/utils/extract-value.js.map +0 -1
  34. package/dist/esm/utils/extract-value.js +0 -24
  35. package/dist/esm/utils/extract-value.js.map +0 -1
  36. package/dist/types/utils/extract-value.d.ts +0 -12
@@ -1,4 +1,4 @@
1
- import { AnyFunction, ExtractPath, ExtractPathByType, ExtractType, Primitive } from '@empathyco/x-utils';
1
+ import { AnyFunction, DeepPartial, ExtractPath, ExtractPathByType, ExtractType, Primitive } from '@empathyco/x-utils';
2
2
  import { MapperContext } from '../mappers/types';
3
3
  /**
4
4
  * Template object to transform a source object to a target object.
@@ -34,7 +34,7 @@ import { MapperContext } from '../mappers/types';
34
34
  * ```
35
35
  * @public
36
36
  */
37
- export declare type Schema<Source = any, Target = any> = {
37
+ export type Schema<Source = any, Target = any> = {
38
38
  [TargetKey in keyof Target]: SchemaTransformer<Source, Target, TargetKey>;
39
39
  };
40
40
  /**
@@ -44,29 +44,31 @@ export declare type Schema<Source = any, Target = any> = {
44
44
  * @param OriginalSchema - The {@link Schema | schema} that will be mutable.
45
45
  * @public
46
46
  */
47
- export declare type MutableSchema<OriginalSchema extends Schema> = OriginalSchema & {
47
+ export type MutableSchema<Source, Target> = Schema<Source, Target> & {
48
48
  /**
49
49
  * Replaces all usages of the original {@link Schema | schema} with the given one.
50
50
  *
51
51
  * @param newSchema - The {@link Schema | schema} to use instead of the original one.
52
52
  * @returns The new {@link Schema | schema} that will be used.
53
53
  */
54
- $replace: <Source, Target>(newSchema: Schema<Source, Target>) => MutableSchema<Schema<Source, Target>>;
54
+ $replace<NewSource, NewTarget>(newSchema: Schema<NewSource, NewTarget>): MutableSchema<NewSource, NewTarget>;
55
55
  /**
56
56
  * Merges the original {@link Schema | schema} with the given one.
57
57
  *
58
58
  * @param newSchema - The {@link Schema | schema} to use to merge with the original one.
59
59
  * @returns The {@link Schema | schema} returned by the merge.
60
60
  */
61
- $override: <Source, Target>(newSchema: Schema<Source, Target>) => MutableSchema<Schema<Source, Target>>;
61
+ $override<NewSource, NewTarget = {}>(newSchema: DeepPartial<Schema<Source & NewSource, Target>> & Schema<Source & NewSource, NewTarget>): MutableSchema<Source & NewSource, Target & NewTarget>;
62
62
  /**
63
63
  * Creates a new {@link Schema | schema} using the original one as starting point.
64
64
  * The original {@link Schema | schema} will remain unchanged.
65
65
  *
66
66
  * @param newSchema - The {@link Schema | schema} to be used to extend the original one.
67
+ * Both schema's Target and Source can be unique or also be extending from another one.
67
68
  * @returns The {@link Schema | schema} created.
68
69
  */
69
- $extends: <Source, Target>(newSchema: Schema<Source, Target>) => MutableSchema<Schema<Source, Target>>;
70
+ $extends<NewSource extends Source, NewTarget extends Target>(newSchema: DeepPartial<Schema<Source & NewSource, Target>> & Schema<Source & NewSource, Omit<NewTarget, keyof Target>>): MutableSchema<Source & NewSource, Target & NewTarget>;
71
+ $extends<NewSource, NewTarget = {}>(newSchema: DeepPartial<Schema<Source & NewSource, Target>> & Schema<Source & NewSource, NewTarget>): MutableSchema<Source & NewSource, Target & NewTarget>;
70
72
  /**
71
73
  * Returns a string representing of the {@link Schema | schema}.
72
74
  *
@@ -74,7 +76,7 @@ export declare type MutableSchema<OriginalSchema extends Schema> = OriginalSchem
74
76
  * the internal methods. Disabled by default.
75
77
  * @returns The string representation.
76
78
  */
77
- toString: (includeInternalMethods?: boolean) => string;
79
+ toString(includeInternalMethods?: boolean): string;
78
80
  };
79
81
  /**
80
82
  * The possible transformers to apply to the target key.
@@ -84,7 +86,7 @@ export declare type MutableSchema<OriginalSchema extends Schema> = OriginalSchem
84
86
  * @param TargetKey - The target key to apply the transformation.
85
87
  * @public
86
88
  */
87
- export declare type SchemaTransformer<Source, Target, TargetKey extends keyof Target> = PathTransformer<Source, Target[TargetKey]> | FunctionTransformer<Source, Target[TargetKey]> | SubSchemaTransformer<Source, Target[TargetKey]> | Schema<Source, Exclude<Target[TargetKey], AnyFunction | Primitive>>;
89
+ export type SchemaTransformer<Source, Target, TargetKey extends keyof Target> = PathTransformer<Source, Target[TargetKey]> | FunctionTransformer<Source, Target[TargetKey]> | SubSchemaTransformer<Source, Target[TargetKey]> | Schema<Source, Exclude<Target[TargetKey], AnyFunction | Primitive>>;
88
90
  /**
89
91
  * A function with the source object and mapper context as parameters that returns the value of a
90
92
  * target's property.
@@ -116,7 +118,7 @@ export declare type SchemaTransformer<Source, Target, TargetKey extends keyof Ta
116
118
  * ```
117
119
  * @public
118
120
  */
119
- export declare type PathTransformer<Source, Target> = ExtractPathByType<Source, Target>;
121
+ export type PathTransformer<Source, Target> = ExtractPathByType<Source, Target>;
120
122
  /**
121
123
  * A function with the source object and mapper context as parameters that returns the value of a
122
124
  * target's property.
@@ -144,7 +146,7 @@ export declare type PathTransformer<Source, Target> = ExtractPathByType<Source,
144
146
  * ```
145
147
  * @public
146
148
  */
147
- export declare type FunctionTransformer<Source, Target> = (source: Source, context?: MapperContext) => Target;
149
+ export type FunctionTransformer<Source, Target> = (source: Source, context?: MapperContext) => Target;
148
150
  /**
149
151
  * An object containing a schema narrowing its source object based on the given path.
150
152
  *
@@ -180,7 +182,7 @@ export declare type FunctionTransformer<Source, Target> = (source: Source, conte
180
182
  * ```
181
183
  * @public
182
184
  */
183
- export declare type SubSchemaTransformer<Source, Target> = {
185
+ export type SubSchemaTransformer<Source, Target> = {
184
186
  [Path in ExtractPath<Source>]: {
185
187
  $context?: MapperContext;
186
188
  $path: Path;
@@ -195,4 +197,4 @@ export declare type SubSchemaTransformer<Source, Target> = {
195
197
  * @param Path - The path where the schema will be applied.
196
198
  * @public
197
199
  */
198
- export declare type SubSchema<Source, Target, Path extends ExtractPath<Source>> = ExtractType<Source, Path> extends (infer SourceArrayType)[] ? Target extends (infer TargetArrayType)[] ? Schema<SourceArrayType, TargetArrayType> : never : Target extends [] ? never : Schema<ExtractType<Source, Path>, Target>;
200
+ export type SubSchema<Source, Target, Path extends ExtractPath<Source>> = ExtractType<Source, Path> extends (infer SourceArrayType)[] ? Target extends (infer TargetArrayType)[] ? Schema<SourceArrayType, TargetArrayType> : never : Target extends [] ? never : Schema<ExtractType<Source, Path>, Target>;
@@ -8,7 +8,7 @@ import { MutableSchema, Schema } from './types';
8
8
  *
9
9
  * @public
10
10
  */
11
- export declare function createMutableSchema<T extends Schema>(schema: T): MutableSchema<T>;
11
+ export declare function createMutableSchema<Source, Target>(schema: Schema<Source, Target>): MutableSchema<Source, Target>;
12
12
  /**
13
13
  * Checks if the given key is a {@link MutableSchema | mutableSchema} method.
14
14
  *
@@ -1,2 +1 @@
1
- export * from './extract-value';
2
1
  export * from './interpolate';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-adapter",
3
- "version": "8.0.0-alpha.8",
3
+ "version": "8.0.0",
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",
@@ -22,31 +22,35 @@
22
22
  "url": "git+https://github.com/empathyco/x.git",
23
23
  "directory": "packages/x-adapter"
24
24
  },
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
25
28
  "scripts": {
26
29
  "prebuild": "rimraf ./dist ./*.tgz",
27
- "build": "concurrently \"npm run build:*\"",
30
+ "build": "concurrently \"pnpm run build:*\"",
28
31
  "build:cjs": "tsc --project tsconfig.cjs.json",
29
32
  "build:esm": "tsc --project tsconfig.esm.json",
33
+ "postbuild": "pnpm pack",
34
+ "lint": "eslint . --ext .ts",
30
35
  "test": "jest",
31
- "postbuild": "npm pack",
32
- "prepublishOnly": "npm run build"
36
+ "test:unit": "jest",
37
+ "prepublishOnly": "pnpm run build"
33
38
  },
34
39
  "dependencies": {
35
- "@empathyco/x-deep-merge": "^1.3.0-alpha.21",
36
- "@empathyco/x-get-safe-property-chain": "^1.3.0-alpha.3",
37
- "tslib": "~2.3.0"
40
+ "@empathyco/x-deep-merge": "^2.0.0",
41
+ "@empathyco/x-utils": "^1.0.0",
42
+ "tslib": "~2.5.0"
38
43
  },
39
44
  "devDependencies": {
40
- "@empathyco/x-utils": "^1.0.0-alpha.7",
41
- "@types/jest": "~27.0.3",
42
- "concurrently": "~7.0.0",
43
- "jest": "~27.3.1",
45
+ "@types/jest": "~27.5.0",
46
+ "concurrently": "~8.1.0",
47
+ "jest": "~27.5.0",
44
48
  "rimraf": "~3.0.2",
45
- "ts-jest": "~27.0.7",
46
- "typescript": "~4.6.2"
49
+ "ts-jest": "~27.1.0",
50
+ "typescript": "~4.9.4"
47
51
  },
48
52
  "publishConfig": {
49
53
  "access": "public"
50
54
  },
51
- "gitHead": "c2150c4957ff99d27ce904c8554d72ac61261f36"
55
+ "gitHead": "b8ff7113a91e5a8f05228fc7994faa6dd91c44f3"
52
56
  }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.extractValue = void 0;
4
- const x_get_safe_property_chain_1 = require("@empathyco/x-get-safe-property-chain");
5
- const x_utils_1 = require("@empathyco/x-utils");
6
- /**
7
- * Extracts the value of the given property's path from the given object.
8
- *
9
- * @param obj - The object to extract the property's value from.
10
- * @param path - The path to the object's property.
11
- *
12
- * @returns The value of the property.
13
- *
14
- * @public
15
- */
16
- function extractValue(obj, path) {
17
- const result = (0, x_get_safe_property_chain_1.getSafePropertyChain)(obj, path);
18
- if (result !== undefined) {
19
- if ((0, x_utils_1.isArray)(result)) {
20
- return result;
21
- }
22
- else {
23
- return result;
24
- }
25
- }
26
- }
27
- exports.extractValue = extractValue;
28
- //# sourceMappingURL=extract-value.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract-value.js","sourceRoot":"","sources":["../../../src/utils/extract-value.ts"],"names":[],"mappings":";;;AAAA,oFAA4E;AAC5E,gDAAmF;AAEnF;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAC1B,GAA8B,EAC9B,IAAU;IAEV,MAAM,MAAM,GAAG,IAAA,gDAAoB,EAA+B,GAAG,EAAE,IAAI,CAAC,CAAC;IAC7E,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,IAAI,IAAA,iBAAO,EAAgC,MAAM,CAAC,EAAE;YAClD,OAAO,MAAM,CAAC;SACf;aAAM;YACL,OAAO,MAAM,CAAC;SACf;KACF;AACH,CAAC;AAZD,oCAYC","sourcesContent":["import { getSafePropertyChain } from '@empathyco/x-get-safe-property-chain';\nimport { Dictionary, ExtractPath, ExtractType, isArray } from '@empathyco/x-utils';\n\n/**\n * Extracts the value of the given property's path from the given object.\n *\n * @param obj - The object to extract the property's value from.\n * @param path - The path to the object's property.\n *\n * @returns The value of the property.\n *\n * @public\n */\nexport function extractValue<SomeObject extends Dictionary, Path extends ExtractPath<SomeObject>>(\n obj: SomeObject | SomeObject[],\n path: Path\n): ExtractType<SomeObject, Path> | ExtractType<SomeObject, Path>[] | undefined {\n const result = getSafePropertyChain<ReturnType<SomeObject, Path>>(obj, path);\n if (result !== undefined) {\n if (isArray<ExtractType<SomeObject, Path>>(result)) {\n return result;\n } else {\n return result;\n }\n }\n}\n\n/**\n * Helper to narrow down the type of the returned value when calling `getSafePropertyChain()`.\n *\n * @param SomeObject - The object to check.\n * @param Path - The path to check.\n *\n * @internal\n */\ntype ReturnType<SomeObject, Path extends ExtractPath<SomeObject>> =\n | ExtractType<SomeObject, Path>\n | ExtractType<SomeObject, Path>[];\n"]}
@@ -1,24 +0,0 @@
1
- import { getSafePropertyChain } from '@empathyco/x-get-safe-property-chain';
2
- import { isArray } from '@empathyco/x-utils';
3
- /**
4
- * Extracts the value of the given property's path from the given object.
5
- *
6
- * @param obj - The object to extract the property's value from.
7
- * @param path - The path to the object's property.
8
- *
9
- * @returns The value of the property.
10
- *
11
- * @public
12
- */
13
- export function extractValue(obj, path) {
14
- const result = getSafePropertyChain(obj, path);
15
- if (result !== undefined) {
16
- if (isArray(result)) {
17
- return result;
18
- }
19
- else {
20
- return result;
21
- }
22
- }
23
- }
24
- //# sourceMappingURL=extract-value.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract-value.js","sourceRoot":"","sources":["../../../src/utils/extract-value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAwC,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEnF;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAC1B,GAA8B,EAC9B,IAAU;IAEV,MAAM,MAAM,GAAG,oBAAoB,CAA+B,GAAG,EAAE,IAAI,CAAC,CAAC;IAC7E,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,IAAI,OAAO,CAAgC,MAAM,CAAC,EAAE;YAClD,OAAO,MAAM,CAAC;SACf;aAAM;YACL,OAAO,MAAM,CAAC;SACf;KACF;AACH,CAAC","sourcesContent":["import { getSafePropertyChain } from '@empathyco/x-get-safe-property-chain';\nimport { Dictionary, ExtractPath, ExtractType, isArray } from '@empathyco/x-utils';\n\n/**\n * Extracts the value of the given property's path from the given object.\n *\n * @param obj - The object to extract the property's value from.\n * @param path - The path to the object's property.\n *\n * @returns The value of the property.\n *\n * @public\n */\nexport function extractValue<SomeObject extends Dictionary, Path extends ExtractPath<SomeObject>>(\n obj: SomeObject | SomeObject[],\n path: Path\n): ExtractType<SomeObject, Path> | ExtractType<SomeObject, Path>[] | undefined {\n const result = getSafePropertyChain<ReturnType<SomeObject, Path>>(obj, path);\n if (result !== undefined) {\n if (isArray<ExtractType<SomeObject, Path>>(result)) {\n return result;\n } else {\n return result;\n }\n }\n}\n\n/**\n * Helper to narrow down the type of the returned value when calling `getSafePropertyChain()`.\n *\n * @param SomeObject - The object to check.\n * @param Path - The path to check.\n *\n * @internal\n */\ntype ReturnType<SomeObject, Path extends ExtractPath<SomeObject>> =\n | ExtractType<SomeObject, Path>\n | ExtractType<SomeObject, Path>[];\n"]}
@@ -1,12 +0,0 @@
1
- import { Dictionary, ExtractPath, ExtractType } from '@empathyco/x-utils';
2
- /**
3
- * Extracts the value of the given property's path from the given object.
4
- *
5
- * @param obj - The object to extract the property's value from.
6
- * @param path - The path to the object's property.
7
- *
8
- * @returns The value of the property.
9
- *
10
- * @public
11
- */
12
- export declare function extractValue<SomeObject extends Dictionary, Path extends ExtractPath<SomeObject>>(obj: SomeObject | SomeObject[], path: Path): ExtractType<SomeObject, Path> | ExtractType<SomeObject, Path>[] | undefined;