@empathyco/x-adapter 8.2.6 → 8.4.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.
- package/package.json +3 -3
- package/skills/x-adapter/SKILL.md +30 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empathyco/x-adapter",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.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",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"prepublishOnly": "pnpm run build"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@empathyco/x-utils": "1.
|
|
47
|
+
"@empathyco/x-utils": "1.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@vitest/coverage-v8": "4.1.12",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "ca952751b59d92301723b572942e6b86f1d7fc9b"
|
|
59
59
|
}
|
|
@@ -1,23 +1,39 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: x-adapter
|
|
3
|
-
description: 'Use when
|
|
3
|
+
description: 'Generic toolkit to build typed API clients (@empathyco/x-adapter): endpointAdapterFactory, schemaMapperFactory, createMutableSchema, fetchHttpClient, buildUrl and interpolate. Use when creating an endpoint adapter for a custom or third-party API, writing request/response mappers or schemas, replacing the HTTP client, or debugging cancelled or wrongly built requests. To customize the existing Empathy Platform endpoints use x-adapter-platform.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
<!-- skills-check ignore: httpClient, requestMapper, responseMapper, $subSchema, Response -->
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
# @empathyco/x-adapter
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Framework to create API clients: an endpoint adapter is a function that maps the request,
|
|
11
|
+
calls an HTTP client and maps the response.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
- `schemaMapperFactory` — genera mappers de petición/respuesta a partir de un `Schema` (dictcionario de paths o funciones).
|
|
14
|
-
- `createMutableSchema` — crea un `MutableSchema` reutilizable con los métodos `$extends`, `$override` y `$replace`.
|
|
15
|
-
- `identityMapper` / `combineMappers` — mappers auxiliares para identidad y composición.
|
|
16
|
-
- `fetchHttpClient` / `fetchRawHttpClient` — clientes HTTP por defecto basados en la Fetch API.
|
|
17
|
-
- `buildUrl` / `interpolate` — utilidades para construir URLs y parametrizar endpoints (`https://api/{id}`).
|
|
13
|
+
## Building blocks
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
- `endpointAdapterFactory({ endpoint, httpClient, requestMapper, responseMapper })` returns an
|
|
16
|
+
endpoint adapter. The result has `.extends(options)` to create a customized copy — prefer it
|
|
17
|
+
over rebuilding the adapter.
|
|
18
|
+
- `schemaMapperFactory(schema)` creates a mapper from a `Schema`: an object whose values are
|
|
19
|
+
source paths, functions, nested schemas or `$subSchema`/`$path` definitions.
|
|
20
|
+
- `createMutableSchema(schema)` adds `$extends`, `$override` and `$replace`:
|
|
21
|
+
- `$extends` returns a **new** schema;
|
|
22
|
+
- `$override` and `$replace` **mutate** the schema in place, affecting every adapter that
|
|
23
|
+
uses it.
|
|
24
|
+
- `identityMapper`, `combineMappers` — helper mappers.
|
|
25
|
+
- `fetchHttpClient` (parses JSON) and `fetchRawHttpClient` (returns the raw `Response`).
|
|
26
|
+
- `buildUrl`, `interpolate` — URL helpers; `interpolate` fills `{param}` placeholders in an
|
|
27
|
+
endpoint such as `https://api.example.com/{id}`, and drops empty ones.
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
## Common mistakes
|
|
30
|
+
|
|
31
|
+
- `fetchHttpClient` is cancelable by default: a new request with the same `id` (the endpoint
|
|
32
|
+
by default) aborts the previous one. Pass a distinct `id` or `cancelable: false` for
|
|
33
|
+
requests that must run in parallel.
|
|
34
|
+
- Calling `$override` on a shared schema when a copy was intended (use `$extends`).
|
|
35
|
+
|
|
36
|
+
## More
|
|
37
|
+
|
|
38
|
+
The package `README.md` (in `node_modules/@empathyco/x-adapter`) has complete examples of
|
|
39
|
+
schemas, sub-schemas, mutable schemas and `.extends`.
|