@zeroxsolutions/response 0.12.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/CHANGELOG.md +330 -0
- package/README.md +237 -0
- package/dist/api-response.d.ts +24 -0
- package/dist/api-response.d.ts.map +1 -0
- package/dist/api-response.js +18 -0
- package/dist/document-shape.d.ts +17 -0
- package/dist/document-shape.d.ts.map +1 -0
- package/dist/document-shape.js +29 -0
- package/dist/document.d.ts +47 -0
- package/dist/document.d.ts.map +1 -0
- package/dist/document.js +54 -0
- package/dist/domain-error-resolver.d.ts +37 -0
- package/dist/domain-error-resolver.d.ts.map +1 -0
- package/dist/domain-error-resolver.js +39 -0
- package/dist/error-map.d.ts +14 -0
- package/dist/error-map.d.ts.map +1 -0
- package/dist/error-map.js +1 -0
- package/dist/errors/error-document.d.ts +189 -0
- package/dist/errors/error-document.d.ts.map +1 -0
- package/dist/errors/error-document.js +37 -0
- package/dist/errors/error-registry.d.ts +49 -0
- package/dist/errors/error-registry.d.ts.map +1 -0
- package/dist/errors/error-registry.js +13 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +5 -0
- package/dist/errors/jsonapi-error.d.ts +27 -0
- package/dist/errors/jsonapi-error.d.ts.map +1 -0
- package/dist/errors/jsonapi-error.js +21 -0
- package/dist/errors/resolved-error.d.ts +7 -0
- package/dist/errors/resolved-error.d.ts.map +1 -0
- package/dist/errors/resolved-error.js +1 -0
- package/dist/errors/to-error-document.d.ts +11 -0
- package/dist/errors/to-error-document.d.ts.map +1 -0
- package/dist/errors/to-error-document.js +25 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/media-type.d.ts +5 -0
- package/dist/media-type.d.ts.map +1 -0
- package/dist/media-type.js +4 -0
- package/dist/primitives.d.ts +161 -0
- package/dist/primitives.d.ts.map +1 -0
- package/dist/primitives.js +47 -0
- package/dist/relationship.d.ts +37 -0
- package/dist/relationship.d.ts.map +1 -0
- package/dist/relationship.js +44 -0
- package/dist/resource.d.ts +35 -0
- package/dist/resource.d.ts.map +1 -0
- package/dist/resource.js +63 -0
- package/dist/serialize.d.ts +44 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +77 -0
- package/dist/upstream-error.d.ts +34 -0
- package/dist/upstream-error.d.ts.map +1 -0
- package/dist/upstream-error.js +33 -0
- package/package.json +38 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { UpstreamErrorMap } from './error-map.js';
|
|
2
|
+
import type { ErrorDocument, ErrorLinks } from './errors/error-document.js';
|
|
3
|
+
import type { ErrorStatus } from './errors/error-registry.js';
|
|
4
|
+
import { JsonApiError } from './errors/jsonapi-error.js';
|
|
5
|
+
import type { Meta } from './primitives.js';
|
|
6
|
+
/**
|
|
7
|
+
* This transport's answer to one `code` a fronted service renders - its own title and detail, since the service's were
|
|
8
|
+
* written for its single internal caller.
|
|
9
|
+
*/
|
|
10
|
+
export interface UpstreamErrorAnswer extends ErrorStatus {
|
|
11
|
+
code: string;
|
|
12
|
+
/** Human-readable and request-specific; the error's `message` falls back to the title without one. */
|
|
13
|
+
detail?: string;
|
|
14
|
+
/** A page about this occurrence, and a page about its type of problem. */
|
|
15
|
+
links?: ErrorLinks;
|
|
16
|
+
/**
|
|
17
|
+
* Reads what the upstream error's `meta` promises into this error's `meta` - omit to render none.
|
|
18
|
+
*
|
|
19
|
+
* It returns what its parse produced, never `upstream` as received: the schema is what keeps a member the service
|
|
20
|
+
* adds later from crossing. `undefined` answers the fallback, because a mapped code missing the data its contract
|
|
21
|
+
* promises is an answer this transport does not recognise.
|
|
22
|
+
*/
|
|
23
|
+
meta?: (upstream: Meta | undefined) => Meta | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Binds one fronted service's answers and fallback into the function translating its rendered document into this
|
|
27
|
+
* transport's own error, to be thrown so `onError` renders it.
|
|
28
|
+
*
|
|
29
|
+
* The document's FIRST error decides, because `createErrorHandler` renders exactly one per failure. Nothing else of the
|
|
30
|
+
* service's error survives unless an answer's `meta` reads it: its `code` names a namespace this surface's contract
|
|
31
|
+
* never declared, and its `detail` and `source` describe a request this client never sent.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createUpstreamErrorTranslator(answers: UpstreamErrorMap, fallback: Omit<UpstreamErrorAnswer, 'meta'>): (document: ErrorDocument) => JsonApiError;
|
|
34
|
+
//# sourceMappingURL=upstream-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstream-error.d.ts","sourceRoot":"","sources":["../src/upstream-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,WAAW;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,sGAAsG;IACtG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,GAAG,SAAS,KAAK,IAAI,GAAG,SAAS,CAAC;CACzD;AAaD;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAC1C,CAAC,QAAQ,EAAE,aAAa,KAAK,YAAY,CAa3C"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { JsonApiError } from './errors/jsonapi-error.js';
|
|
2
|
+
function toJsonApiError(answer, meta) {
|
|
3
|
+
return new JsonApiError({
|
|
4
|
+
status: answer.status,
|
|
5
|
+
title: answer.title,
|
|
6
|
+
code: answer.code,
|
|
7
|
+
detail: answer.detail,
|
|
8
|
+
links: answer.links,
|
|
9
|
+
meta,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Binds one fronted service's answers and fallback into the function translating its rendered document into this
|
|
14
|
+
* transport's own error, to be thrown so `onError` renders it.
|
|
15
|
+
*
|
|
16
|
+
* The document's FIRST error decides, because `createErrorHandler` renders exactly one per failure. Nothing else of the
|
|
17
|
+
* service's error survives unless an answer's `meta` reads it: its `code` names a namespace this surface's contract
|
|
18
|
+
* never declared, and its `detail` and `source` describe a request this client never sent.
|
|
19
|
+
*/
|
|
20
|
+
export function createUpstreamErrorTranslator(answers, fallback) {
|
|
21
|
+
return (document) => {
|
|
22
|
+
const [upstream] = document.errors;
|
|
23
|
+
const answer = upstream?.code === undefined ? undefined : answers[upstream.code];
|
|
24
|
+
if (answer === undefined) {
|
|
25
|
+
return toJsonApiError(fallback);
|
|
26
|
+
}
|
|
27
|
+
if (answer.meta === undefined) {
|
|
28
|
+
return toJsonApiError(answer);
|
|
29
|
+
}
|
|
30
|
+
const meta = answer.meta(upstream?.meta);
|
|
31
|
+
return meta === undefined ? toJsonApiError(fallback) : toJsonApiError(answer, meta);
|
|
32
|
+
};
|
|
33
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zeroxsolutions/response",
|
|
3
|
+
"version": "0.12.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"description": "The response half of the HTTP contract shared across ZeroXSolutions services and the edge gateway - JSON:API resource declarations and their serializers, the three OpenAPI response descriptors (okResponse / listResponse / errorResponse) every route spells its `responses` from, and the error document and error map.",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"README.md",
|
|
11
|
+
"CHANGELOG.md",
|
|
12
|
+
"!**/*.tsbuildinfo"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"import": "./dist/index.js",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"tslib": "^2.3.0",
|
|
24
|
+
"ts-japi": "^1.12.3"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"zod": "^4.3.6"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"zod": "^4.3.6"
|
|
31
|
+
},
|
|
32
|
+
"nx": {
|
|
33
|
+
"name": "@zeroxsolutions/response"
|
|
34
|
+
},
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"module": "./dist/index.js",
|
|
37
|
+
"types": "./dist/index.d.ts"
|
|
38
|
+
}
|