@empathyco/x-adapter 8.2.6 → 8.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-adapter",
3
- "version": "8.2.6",
3
+ "version": "8.3.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.1.6"
47
+ "@empathyco/x-utils": "1.2.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": "587b5e39b6d1efe5b2cdc805efa09f040908ba28"
58
+ "gitHead": "193fbc1c4fef9c7dcaa6060cd2331b66e1a551d2"
59
59
  }
@@ -1,23 +1,39 @@
1
1
  ---
2
2
  name: x-adapter
3
- description: 'Use when importing, using, or debugging components from x-adapter.'
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
- # x-adapter
6
+ <!-- skills-check ignore: httpClient, requestMapper, responseMapper, $subSchema, Response -->
7
7
 
8
- Librería de utilidades para crear un cliente de cualquier API: configura endpoints, mapea peticiones y respuestas (con o sin schemas) y reutiliza mappers.
8
+ # @empathyco/x-adapter
9
9
 
10
- ## Componentes disponibles
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
- - `endpointAdapterFactory` — crea un `EndpointAdapter` (función de petición) a partir de `endpoint`, `httpClient` y mappers.
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
- ## Instalación
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
- npm install @empathyco/x-adapter
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`.