@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,47 @@
|
|
|
1
|
+
import type { ZodObject, ZodType } from 'zod';
|
|
2
|
+
import { type JsonApiObject, type Meta, type PaginationLinks, type ResourceIdentifier, type ResourceLinks } from './primitives.js';
|
|
3
|
+
import { type RelatedResource, type RelationshipDef } from './relationship.js';
|
|
4
|
+
/** One relationship as a document carries it - the linkage, plus its own links and meta. */
|
|
5
|
+
export interface Relationship {
|
|
6
|
+
data?: ResourceIdentifier | ResourceIdentifier[] | null;
|
|
7
|
+
links?: ResourceLinks;
|
|
8
|
+
meta?: Meta;
|
|
9
|
+
}
|
|
10
|
+
/** A resource object, with `attributes` carrying the declared attribute type. */
|
|
11
|
+
export interface ResourceObject<A> {
|
|
12
|
+
type: string;
|
|
13
|
+
id: string;
|
|
14
|
+
attributes: A;
|
|
15
|
+
relationships?: Record<string, Relationship>;
|
|
16
|
+
links?: ResourceLinks;
|
|
17
|
+
meta?: Meta;
|
|
18
|
+
}
|
|
19
|
+
/** A single-resource document. `included` holds other resource types, so its attributes stay unknown. */
|
|
20
|
+
export interface ResourceDocument<A> {
|
|
21
|
+
data: ResourceObject<A>;
|
|
22
|
+
included?: ResourceObject<unknown>[];
|
|
23
|
+
links?: ResourceLinks;
|
|
24
|
+
meta?: Meta;
|
|
25
|
+
jsonapi?: JsonApiObject;
|
|
26
|
+
}
|
|
27
|
+
/** A collection document - the same members with `data` an array and paginated `links`. */
|
|
28
|
+
export interface CollectionDocument<A> {
|
|
29
|
+
data: ResourceObject<A>[];
|
|
30
|
+
included?: ResourceObject<unknown>[];
|
|
31
|
+
links?: PaginationLinks;
|
|
32
|
+
meta?: Meta;
|
|
33
|
+
jsonapi?: JsonApiObject;
|
|
34
|
+
}
|
|
35
|
+
/** Wraps `attributes` into a resource object - `{ type, id, attributes, relationships?, links?, meta? }`. */
|
|
36
|
+
export declare function resourceObjectSchema(type: string, attributes: ZodObject, relationships?: Readonly<Record<string, RelationshipDef>>): ZodType;
|
|
37
|
+
/**
|
|
38
|
+
* The document for a SINGLE resource - `{ data, included?, links?, meta?, jsonapi? }`.
|
|
39
|
+
*
|
|
40
|
+
* `A` is asserted rather than inferred: the schema is assembled from a relationship graph reached
|
|
41
|
+
* through thunks, so nothing static carries the attribute type, and a client typing a route off this
|
|
42
|
+
* schema would otherwise read every member as `unknown`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function resourceDocumentSchema<A = unknown>(root: RelatedResource): ZodType<ResourceDocument<A>>;
|
|
45
|
+
/** The document for a COLLECTION - the same members, with `data` an array and paginated `links`. */
|
|
46
|
+
export declare function collectionDocumentSchema<A = unknown>(root: RelatedResource): ZodType<CollectionDocument<A>>;
|
|
47
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC9C,OAAO,EAKL,KAAK,aAAa,EAClB,KAAK,IAAI,EACT,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAA2C,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAExH,4FAA4F;AAC5F,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,EAAE,GAAG,IAAI,CAAC;IACxD,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,iFAAiF;AACjF,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,CAAC,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAC7C,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,yGAAyG;AACzG,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IACrC,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,2FAA2F;AAC3F,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;IACrC,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED,6GAA6G;AAC7G,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,SAAS,EACrB,aAAa,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAM,GAC5D,OAAO,CAUT;AAgBD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAQvG;AAED,oGAAoG;AACpG,wBAAgB,wBAAwB,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAQ3G"}
|
package/dist/document.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { jsonApiObjectSchema, metaSchema, paginationLinksSchema, resourceLinksSchema, } from './primitives.js';
|
|
3
|
+
import { relationshipsSchema, reachableResources } from './relationship.js';
|
|
4
|
+
/** Wraps `attributes` into a resource object - `{ type, id, attributes, relationships?, links?, meta? }`. */
|
|
5
|
+
export function resourceObjectSchema(type, attributes, relationships = {}) {
|
|
6
|
+
const linkage = relationshipsSchema(relationships);
|
|
7
|
+
return z.object({
|
|
8
|
+
type: z.literal(type),
|
|
9
|
+
id: z.string(),
|
|
10
|
+
attributes,
|
|
11
|
+
...(linkage ? { relationships: linkage.optional() } : {}),
|
|
12
|
+
links: resourceLinksSchema.optional(),
|
|
13
|
+
meta: metaSchema.optional(),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The `included` member: every resource reachable from `root`, as a union over their resource objects.
|
|
18
|
+
*
|
|
19
|
+
* A one-resource graph has no union to build, so its `included` is that resource's own array - a
|
|
20
|
+
* self-referential include (`?include=parent`) is the case that reaches it.
|
|
21
|
+
*/
|
|
22
|
+
function includedSchema(root) {
|
|
23
|
+
const reachable = reachableResources(root);
|
|
24
|
+
const [only] = reachable;
|
|
25
|
+
return reachable.length === 1
|
|
26
|
+
? z.array(only?.resourceObject ?? z.never())
|
|
27
|
+
: z.array(z.union(reachable.map((resource) => resource.resourceObject)));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The document for a SINGLE resource - `{ data, included?, links?, meta?, jsonapi? }`.
|
|
31
|
+
*
|
|
32
|
+
* `A` is asserted rather than inferred: the schema is assembled from a relationship graph reached
|
|
33
|
+
* through thunks, so nothing static carries the attribute type, and a client typing a route off this
|
|
34
|
+
* schema would otherwise read every member as `unknown`.
|
|
35
|
+
*/
|
|
36
|
+
export function resourceDocumentSchema(root) {
|
|
37
|
+
return z.object({
|
|
38
|
+
data: root.resourceObject,
|
|
39
|
+
included: includedSchema(root).optional(),
|
|
40
|
+
links: resourceLinksSchema.optional(),
|
|
41
|
+
meta: metaSchema.optional(),
|
|
42
|
+
jsonapi: jsonApiObjectSchema.optional(),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** The document for a COLLECTION - the same members, with `data` an array and paginated `links`. */
|
|
46
|
+
export function collectionDocumentSchema(root) {
|
|
47
|
+
return z.object({
|
|
48
|
+
data: z.array(root.resourceObject),
|
|
49
|
+
included: includedSchema(root).optional(),
|
|
50
|
+
links: paginationLinksSchema.optional(),
|
|
51
|
+
meta: metaSchema.optional(),
|
|
52
|
+
jsonapi: jsonApiObjectSchema.optional(),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { DomainErrorMap, ErrorClass } from './error-map.js';
|
|
2
|
+
import type { ErrorLinks, ErrorSource } from './errors/error-document.js';
|
|
3
|
+
import type { ErrorStatus } from './errors/error-registry.js';
|
|
4
|
+
import type { ResolvedError } from './errors/resolved-error.js';
|
|
5
|
+
import type { Meta } from './primitives.js';
|
|
6
|
+
/** What a transport renders for one domain-error class. */
|
|
7
|
+
export interface DomainErrorAnswer<E extends Error = Error> extends ErrorStatus {
|
|
8
|
+
/** This transport's own word for the failure, which a client switches on. */
|
|
9
|
+
code: string;
|
|
10
|
+
/** A page about this occurrence, and a page about its type of problem. */
|
|
11
|
+
links?: ErrorLinks;
|
|
12
|
+
/**
|
|
13
|
+
* The request slot to blame, read off the raised error - omit to render no `source` member.
|
|
14
|
+
*
|
|
15
|
+
* It lives in the MAP and not on the error because the two name different things: an error knows it refused a query
|
|
16
|
+
* parameter, and which member of the standard's `source` carries that is what this transport decides.
|
|
17
|
+
*/
|
|
18
|
+
source?: (error: E) => ErrorSource;
|
|
19
|
+
/** The data a client acts on, read off the raised error - omit to render no `meta` member. */
|
|
20
|
+
meta?: (error: E) => Meta;
|
|
21
|
+
}
|
|
22
|
+
/** One entry of a domain error map: the class it answers for, and that answer. */
|
|
23
|
+
export interface DomainErrorEntry {
|
|
24
|
+
readonly type: ErrorClass;
|
|
25
|
+
readonly answer: DomainErrorAnswer;
|
|
26
|
+
}
|
|
27
|
+
/** One entry of that map, inferring the error type so its `source` and `meta` read the members that class has. */
|
|
28
|
+
export declare function errorEntry<E extends Error>(type: ErrorClass<E>, answer: DomainErrorAnswer<E>): DomainErrorEntry;
|
|
29
|
+
/** Builds a transport's type-keyed error map - the one place deciding how each error type answers on the wire. */
|
|
30
|
+
export declare function defineErrorMap(entries: Iterable<DomainErrorEntry>): DomainErrorMap;
|
|
31
|
+
/**
|
|
32
|
+
* A `createErrorHandler` `resolve` hook mapping a raised error by its constructor identity - a hit renders the entry's
|
|
33
|
+
* answer with the error's `message` as `detail`, a miss returns `undefined` so an unregistered type falls through to a
|
|
34
|
+
* generic 500.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createDomainErrorResolver(map: DomainErrorMap): (error: Error) => ResolvedError | undefined;
|
|
37
|
+
//# sourceMappingURL=domain-error-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domain-error-resolver.d.ts","sourceRoot":"","sources":["../src/domain-error-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAE5C,2DAA2D;AAC3D,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,CAAE,SAAQ,WAAW;IAC7E,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,0EAA0E;IAC1E,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,WAAW,CAAC;IACnC,8FAA8F;IAC9F,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;CAC3B;AAED,kFAAkF;AAClF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;CACpC;AAED,kHAAkH;AAClH,wBAAgB,UAAU,CAAC,CAAC,SAAS,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAI/G;AAED,kHAAkH;AAClH,wBAAgB,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,gBAAgB,CAAC,GAAG,cAAc,CAElF;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,aAAa,GAAG,SAAS,CAuB1G"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** One entry of that map, inferring the error type so its `source` and `meta` read the members that class has. */
|
|
2
|
+
export function errorEntry(type, answer) {
|
|
3
|
+
// The map is keyed by constructor identity and only ever read back through that key, so the answer declared here is
|
|
4
|
+
// only ever handed an instance of `type`.
|
|
5
|
+
return { type, answer: answer };
|
|
6
|
+
}
|
|
7
|
+
/** Builds a transport's type-keyed error map - the one place deciding how each error type answers on the wire. */
|
|
8
|
+
export function defineErrorMap(entries) {
|
|
9
|
+
return new Map(Array.from(entries, ({ type, answer }) => [type, answer]));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A `createErrorHandler` `resolve` hook mapping a raised error by its constructor identity - a hit renders the entry's
|
|
13
|
+
* answer with the error's `message` as `detail`, a miss returns `undefined` so an unregistered type falls through to a
|
|
14
|
+
* generic 500.
|
|
15
|
+
*/
|
|
16
|
+
export function createDomainErrorResolver(map) {
|
|
17
|
+
return (error) => {
|
|
18
|
+
const answer = map.get(error.constructor);
|
|
19
|
+
if (!answer) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const source = answer.source?.(error);
|
|
23
|
+
const meta = answer.meta?.(error);
|
|
24
|
+
return {
|
|
25
|
+
status: answer.status,
|
|
26
|
+
errors: [
|
|
27
|
+
{
|
|
28
|
+
...(answer.links !== undefined ? { links: answer.links } : {}),
|
|
29
|
+
status: String(answer.status),
|
|
30
|
+
code: answer.code,
|
|
31
|
+
title: answer.title,
|
|
32
|
+
detail: error.message,
|
|
33
|
+
...(source !== undefined ? { source } : {}),
|
|
34
|
+
...(meta !== undefined ? { meta } : {}),
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DomainErrorAnswer } from './domain-error-resolver.js';
|
|
2
|
+
import type { UpstreamErrorAnswer } from './upstream-error.js';
|
|
3
|
+
/** A constructor of an `Error` subclass - the key of a type-keyed error map, never called through. */
|
|
4
|
+
export type ErrorClass<E extends Error = Error> = new (...args: any[]) => E;
|
|
5
|
+
/** A transport's map from an error's CONSTRUCTOR IDENTITY to the answer this wire renders for it. */
|
|
6
|
+
export type DomainErrorMap = ReadonlyMap<ErrorClass, DomainErrorAnswer>;
|
|
7
|
+
/**
|
|
8
|
+
* A transport's map from the `code` a fronted service rendered to this transport's own answer.
|
|
9
|
+
*
|
|
10
|
+
* A plain object rather than a `Map`: the key is a string the source spells literally, so an object literal already
|
|
11
|
+
* carries the lookup and the literal keys a builder would otherwise have to hand back.
|
|
12
|
+
*/
|
|
13
|
+
export type UpstreamErrorMap = Readonly<Record<string, UpstreamErrorAnswer>>;
|
|
14
|
+
//# sourceMappingURL=error-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-map.d.ts","sourceRoot":"","sources":["../src/error-map.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,sGAAsG;AAEtG,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,KAAK,GAAG,KAAK,IAAI,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AAE5E,qGAAqG;AACrG,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;AAExE;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Where in the request a JSON:API error originates (spec: error object `source`). */
|
|
3
|
+
export declare const errorSourceSchema: z.ZodObject<{
|
|
4
|
+
pointer: z.ZodOptional<z.ZodString>;
|
|
5
|
+
parameter: z.ZodOptional<z.ZodString>;
|
|
6
|
+
header: z.ZodOptional<z.ZodString>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type ErrorSource = z.infer<typeof errorSourceSchema>;
|
|
9
|
+
/** An error object's `links`: a page about this occurrence, and a page about its type of problem. */
|
|
10
|
+
export declare const errorLinksSchema: z.ZodObject<{
|
|
11
|
+
about: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
12
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
13
|
+
title: z.ZodOptional<z.ZodString>;
|
|
14
|
+
type: z.ZodOptional<z.ZodString>;
|
|
15
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
16
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
17
|
+
href: z.ZodString;
|
|
18
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
19
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
20
|
+
title: z.ZodOptional<z.ZodString>;
|
|
21
|
+
type: z.ZodOptional<z.ZodString>;
|
|
22
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
23
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
+
href: z.ZodString;
|
|
25
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
26
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
27
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
28
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
29
|
+
title: z.ZodOptional<z.ZodString>;
|
|
30
|
+
type: z.ZodOptional<z.ZodString>;
|
|
31
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
32
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
33
|
+
href: z.ZodString;
|
|
34
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
35
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
36
|
+
title: z.ZodOptional<z.ZodString>;
|
|
37
|
+
type: z.ZodOptional<z.ZodString>;
|
|
38
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
39
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
40
|
+
href: z.ZodString;
|
|
41
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
42
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
43
|
+
}, z.core.$strip>;
|
|
44
|
+
export type ErrorLinks = z.infer<typeof errorLinksSchema>;
|
|
45
|
+
/** A single JSON:API error object; every member is optional, and nothing here enforces the spec's at-least-one. */
|
|
46
|
+
export declare const errorObjectSchema: z.ZodObject<{
|
|
47
|
+
id: z.ZodOptional<z.ZodString>;
|
|
48
|
+
links: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
about: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
50
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
51
|
+
title: z.ZodOptional<z.ZodString>;
|
|
52
|
+
type: z.ZodOptional<z.ZodString>;
|
|
53
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
54
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
55
|
+
href: z.ZodString;
|
|
56
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
57
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
58
|
+
title: z.ZodOptional<z.ZodString>;
|
|
59
|
+
type: z.ZodOptional<z.ZodString>;
|
|
60
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
61
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
62
|
+
href: z.ZodString;
|
|
63
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
64
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
65
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
66
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
67
|
+
title: z.ZodOptional<z.ZodString>;
|
|
68
|
+
type: z.ZodOptional<z.ZodString>;
|
|
69
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
70
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
71
|
+
href: z.ZodString;
|
|
72
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
73
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
74
|
+
title: z.ZodOptional<z.ZodString>;
|
|
75
|
+
type: z.ZodOptional<z.ZodString>;
|
|
76
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
77
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
78
|
+
href: z.ZodString;
|
|
79
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
80
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
81
|
+
}, z.core.$strip>>;
|
|
82
|
+
status: z.ZodOptional<z.ZodString>;
|
|
83
|
+
code: z.ZodOptional<z.ZodString>;
|
|
84
|
+
title: z.ZodOptional<z.ZodString>;
|
|
85
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
86
|
+
source: z.ZodOptional<z.ZodObject<{
|
|
87
|
+
pointer: z.ZodOptional<z.ZodString>;
|
|
88
|
+
parameter: z.ZodOptional<z.ZodString>;
|
|
89
|
+
header: z.ZodOptional<z.ZodString>;
|
|
90
|
+
}, z.core.$strip>>;
|
|
91
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
92
|
+
}, z.core.$strip>;
|
|
93
|
+
export type ErrorObject = z.infer<typeof errorObjectSchema>;
|
|
94
|
+
/**
|
|
95
|
+
* A JSON:API error document - a top-level `errors` array of at least one member, which never carries `data`.
|
|
96
|
+
*
|
|
97
|
+
* Nothing here renders the top-level `meta` or `links`. They are declared so the schema `errorResponse` publishes is
|
|
98
|
+
* the whole document, and a client parsing another server's document keeps them.
|
|
99
|
+
*/
|
|
100
|
+
export declare const errorDocumentSchema: z.ZodObject<{
|
|
101
|
+
errors: z.ZodArray<z.ZodObject<{
|
|
102
|
+
id: z.ZodOptional<z.ZodString>;
|
|
103
|
+
links: z.ZodOptional<z.ZodObject<{
|
|
104
|
+
about: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
105
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
106
|
+
title: z.ZodOptional<z.ZodString>;
|
|
107
|
+
type: z.ZodOptional<z.ZodString>;
|
|
108
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
109
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
110
|
+
href: z.ZodString;
|
|
111
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
112
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
113
|
+
title: z.ZodOptional<z.ZodString>;
|
|
114
|
+
type: z.ZodOptional<z.ZodString>;
|
|
115
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
116
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
117
|
+
href: z.ZodString;
|
|
118
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
119
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
120
|
+
type: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
121
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
122
|
+
title: z.ZodOptional<z.ZodString>;
|
|
123
|
+
type: z.ZodOptional<z.ZodString>;
|
|
124
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
125
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
126
|
+
href: z.ZodString;
|
|
127
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
128
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
129
|
+
title: z.ZodOptional<z.ZodString>;
|
|
130
|
+
type: z.ZodOptional<z.ZodString>;
|
|
131
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
132
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
133
|
+
href: z.ZodString;
|
|
134
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
135
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
136
|
+
}, z.core.$strip>>;
|
|
137
|
+
status: z.ZodOptional<z.ZodString>;
|
|
138
|
+
code: z.ZodOptional<z.ZodString>;
|
|
139
|
+
title: z.ZodOptional<z.ZodString>;
|
|
140
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
141
|
+
source: z.ZodOptional<z.ZodObject<{
|
|
142
|
+
pointer: z.ZodOptional<z.ZodString>;
|
|
143
|
+
parameter: z.ZodOptional<z.ZodString>;
|
|
144
|
+
header: z.ZodOptional<z.ZodString>;
|
|
145
|
+
}, z.core.$strip>>;
|
|
146
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
147
|
+
}, z.core.$strip>>;
|
|
148
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
149
|
+
links: z.ZodOptional<z.ZodObject<{
|
|
150
|
+
self: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
151
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
152
|
+
title: z.ZodOptional<z.ZodString>;
|
|
153
|
+
type: z.ZodOptional<z.ZodString>;
|
|
154
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
155
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
156
|
+
href: z.ZodString;
|
|
157
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
158
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
159
|
+
title: z.ZodOptional<z.ZodString>;
|
|
160
|
+
type: z.ZodOptional<z.ZodString>;
|
|
161
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
162
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
163
|
+
href: z.ZodString;
|
|
164
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
165
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
166
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
167
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
168
|
+
title: z.ZodOptional<z.ZodString>;
|
|
169
|
+
type: z.ZodOptional<z.ZodString>;
|
|
170
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
171
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
172
|
+
href: z.ZodString;
|
|
173
|
+
describedby: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
174
|
+
rel: z.ZodOptional<z.ZodString>;
|
|
175
|
+
title: z.ZodOptional<z.ZodString>;
|
|
176
|
+
type: z.ZodOptional<z.ZodString>;
|
|
177
|
+
hreflang: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
178
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
179
|
+
href: z.ZodString;
|
|
180
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
181
|
+
}, z.core.$strip>, z.ZodNull]>>;
|
|
182
|
+
}, z.core.$strip>>;
|
|
183
|
+
jsonapi: z.ZodOptional<z.ZodObject<{
|
|
184
|
+
version: z.ZodOptional<z.ZodString>;
|
|
185
|
+
meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
186
|
+
}, z.core.$strip>>;
|
|
187
|
+
}, z.core.$strip>;
|
|
188
|
+
export type ErrorDocument = z.infer<typeof errorDocumentSchema>;
|
|
189
|
+
//# sourceMappingURL=error-document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-document.d.ts","sourceRoot":"","sources":["../../src/errors/error-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,sFAAsF;AACtF,eAAO,MAAM,iBAAiB;;;;iBAMlB,CAAC;AACb,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D,qGAAqG;AACrG,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA8D,CAAC;AAC5F,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,mHAAmH;AACnH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAWlB,CAAC;AACb,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAE5D;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAK9B,CAAC;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { jsonApiObjectSchema, linkSchema, metaSchema } from '../primitives.js';
|
|
3
|
+
/** Where in the request a JSON:API error originates (spec: error object `source`). */
|
|
4
|
+
export const errorSourceSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
pointer: z.string(),
|
|
7
|
+
parameter: z.string(),
|
|
8
|
+
header: z.string(),
|
|
9
|
+
})
|
|
10
|
+
.partial();
|
|
11
|
+
/** An error object's `links`: a page about this occurrence, and a page about its type of problem. */
|
|
12
|
+
export const errorLinksSchema = z.object({ about: linkSchema, type: linkSchema }).partial();
|
|
13
|
+
/** A single JSON:API error object; every member is optional, and nothing here enforces the spec's at-least-one. */
|
|
14
|
+
export const errorObjectSchema = z
|
|
15
|
+
.object({
|
|
16
|
+
id: z.string(),
|
|
17
|
+
links: errorLinksSchema,
|
|
18
|
+
status: z.string(),
|
|
19
|
+
code: z.string(),
|
|
20
|
+
title: z.string(),
|
|
21
|
+
detail: z.string(),
|
|
22
|
+
source: errorSourceSchema,
|
|
23
|
+
meta: metaSchema,
|
|
24
|
+
})
|
|
25
|
+
.partial();
|
|
26
|
+
/**
|
|
27
|
+
* A JSON:API error document - a top-level `errors` array of at least one member, which never carries `data`.
|
|
28
|
+
*
|
|
29
|
+
* Nothing here renders the top-level `meta` or `links`. They are declared so the schema `errorResponse` publishes is
|
|
30
|
+
* the whole document, and a client parsing another server's document keeps them.
|
|
31
|
+
*/
|
|
32
|
+
export const errorDocumentSchema = z.object({
|
|
33
|
+
errors: z.array(errorObjectSchema).min(1),
|
|
34
|
+
meta: metaSchema.optional(),
|
|
35
|
+
links: z.object({ self: linkSchema, describedby: linkSchema }).partial().optional(),
|
|
36
|
+
jsonapi: jsonApiObjectSchema.optional(),
|
|
37
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** The HTTP status and human-readable title an error answers with. */
|
|
2
|
+
export interface ErrorStatus {
|
|
3
|
+
status: number;
|
|
4
|
+
title: string;
|
|
5
|
+
}
|
|
6
|
+
/** The transport-level failures every service shares, rendered by status; a domain error maps by its TYPE instead. */
|
|
7
|
+
export declare const BASE_ERROR_CODES: {
|
|
8
|
+
readonly BAD_REQUEST: {
|
|
9
|
+
readonly status: 400;
|
|
10
|
+
readonly title: "Bad Request";
|
|
11
|
+
};
|
|
12
|
+
readonly UNAUTHORIZED: {
|
|
13
|
+
readonly status: 401;
|
|
14
|
+
readonly title: "Unauthorized";
|
|
15
|
+
};
|
|
16
|
+
readonly FORBIDDEN: {
|
|
17
|
+
readonly status: 403;
|
|
18
|
+
readonly title: "Forbidden";
|
|
19
|
+
};
|
|
20
|
+
readonly NOT_FOUND: {
|
|
21
|
+
readonly status: 404;
|
|
22
|
+
readonly title: "Not Found";
|
|
23
|
+
};
|
|
24
|
+
readonly NOT_ACCEPTABLE: {
|
|
25
|
+
readonly status: 406;
|
|
26
|
+
readonly title: "Not Acceptable";
|
|
27
|
+
};
|
|
28
|
+
readonly CONFLICT: {
|
|
29
|
+
readonly status: 409;
|
|
30
|
+
readonly title: "Conflict";
|
|
31
|
+
};
|
|
32
|
+
readonly UNSUPPORTED_MEDIA_TYPE: {
|
|
33
|
+
readonly status: 415;
|
|
34
|
+
readonly title: "Unsupported Media Type";
|
|
35
|
+
};
|
|
36
|
+
readonly UNPROCESSABLE_ENTITY: {
|
|
37
|
+
readonly status: 422;
|
|
38
|
+
readonly title: "Unprocessable Entity";
|
|
39
|
+
};
|
|
40
|
+
readonly INTERNAL_SERVER_ERROR: {
|
|
41
|
+
readonly status: 500;
|
|
42
|
+
readonly title: "Internal Server Error";
|
|
43
|
+
};
|
|
44
|
+
readonly BAD_GATEWAY: {
|
|
45
|
+
readonly status: 502;
|
|
46
|
+
readonly title: "Bad Gateway";
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=error-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-registry.d.ts","sourceRoot":"","sources":["../../src/errors/error-registry.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,sHAAsH;AACtH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAWmB,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** The transport-level failures every service shares, rendered by status; a domain error maps by its TYPE instead. */
|
|
2
|
+
export const BASE_ERROR_CODES = {
|
|
3
|
+
BAD_REQUEST: { status: 400, title: 'Bad Request' },
|
|
4
|
+
UNAUTHORIZED: { status: 401, title: 'Unauthorized' },
|
|
5
|
+
FORBIDDEN: { status: 403, title: 'Forbidden' },
|
|
6
|
+
NOT_FOUND: { status: 404, title: 'Not Found' },
|
|
7
|
+
NOT_ACCEPTABLE: { status: 406, title: 'Not Acceptable' },
|
|
8
|
+
CONFLICT: { status: 409, title: 'Conflict' },
|
|
9
|
+
UNSUPPORTED_MEDIA_TYPE: { status: 415, title: 'Unsupported Media Type' },
|
|
10
|
+
UNPROCESSABLE_ENTITY: { status: 422, title: 'Unprocessable Entity' },
|
|
11
|
+
INTERNAL_SERVER_ERROR: { status: 500, title: 'Internal Server Error' },
|
|
12
|
+
BAD_GATEWAY: { status: 502, title: 'Bad Gateway' },
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Meta } from '../primitives.js';
|
|
2
|
+
import type { ErrorLinks, ErrorSource } from './error-document.js';
|
|
3
|
+
import type { ErrorStatus } from './error-registry.js';
|
|
4
|
+
/** The fields required to throw a {@link JsonApiError} - a registry entry plus its `code` and context. */
|
|
5
|
+
export interface JsonApiErrorInit extends ErrorStatus {
|
|
6
|
+
code: string;
|
|
7
|
+
/** Human-readable, request-specific explanation; the error's `message` falls back to the title without one. */
|
|
8
|
+
detail?: string;
|
|
9
|
+
/** Where in the request the error originates. */
|
|
10
|
+
source?: ErrorSource;
|
|
11
|
+
/** A page about this occurrence, and a page about its type of problem. */
|
|
12
|
+
links?: ErrorLinks;
|
|
13
|
+
/** The data a client acts on that no other member carries. */
|
|
14
|
+
meta?: Meta;
|
|
15
|
+
}
|
|
16
|
+
/** A throwable error carrying the members of a JSON:API error object, which `onError` renders into a document. */
|
|
17
|
+
export declare class JsonApiError extends Error {
|
|
18
|
+
readonly status: number;
|
|
19
|
+
readonly title: string;
|
|
20
|
+
readonly code: string;
|
|
21
|
+
readonly detail?: string;
|
|
22
|
+
readonly source?: ErrorSource;
|
|
23
|
+
readonly links?: ErrorLinks;
|
|
24
|
+
readonly meta?: Meta;
|
|
25
|
+
constructor(init: JsonApiErrorInit);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=jsonapi-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonapi-error.d.ts","sourceRoot":"","sources":["../../src/errors/jsonapi-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,0GAA0G;AAC1G,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,IAAI,EAAE,MAAM,CAAC;IACb,+GAA+G;IAC/G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iDAAiD;IACjD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,8DAA8D;IAC9D,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,kHAAkH;AAClH,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC;gBAET,IAAI,EAAE,gBAAgB;CAWnC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** A throwable error carrying the members of a JSON:API error object, which `onError` renders into a document. */
|
|
2
|
+
export class JsonApiError extends Error {
|
|
3
|
+
status;
|
|
4
|
+
title;
|
|
5
|
+
code;
|
|
6
|
+
detail;
|
|
7
|
+
source;
|
|
8
|
+
links;
|
|
9
|
+
meta;
|
|
10
|
+
constructor(init) {
|
|
11
|
+
super(init.detail ?? init.title);
|
|
12
|
+
this.name = 'JsonApiError';
|
|
13
|
+
this.status = init.status;
|
|
14
|
+
this.title = init.title;
|
|
15
|
+
this.code = init.code;
|
|
16
|
+
this.detail = init.detail;
|
|
17
|
+
this.source = init.source;
|
|
18
|
+
this.links = init.links;
|
|
19
|
+
this.meta = init.meta;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ErrorObject } from './error-document.js';
|
|
2
|
+
/** A resolved failure: the HTTP status to emit and the JSON:API error objects to render. */
|
|
3
|
+
export interface ResolvedError {
|
|
4
|
+
status: number;
|
|
5
|
+
errors: ErrorObject[];
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=resolved-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolved-error.d.ts","sourceRoot":"","sources":["../../src/errors/resolved-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,4FAA4F;AAC5F,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ErrorDocument, type ErrorObject } from './error-document.js';
|
|
2
|
+
import { JsonApiError } from './jsonapi-error.js';
|
|
3
|
+
/** Projects a {@link JsonApiError} onto a JSON:API error object (status stringified per spec), each optional member where set. */
|
|
4
|
+
export declare function toErrorObject(error: JsonApiError): ErrorObject;
|
|
5
|
+
/**
|
|
6
|
+
* Renders one or more errors as a validated JSON:API error document, stamped with the spec version it is written to.
|
|
7
|
+
*
|
|
8
|
+
* @throws a `ZodError` on an empty array, which is not a legal error document
|
|
9
|
+
*/
|
|
10
|
+
export declare function toErrorDocument(errors: ErrorObject | JsonApiError | (ErrorObject | JsonApiError)[]): ErrorDocument;
|
|
11
|
+
//# sourceMappingURL=to-error-document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-error-document.d.ts","sourceRoot":"","sources":["../../src/errors/to-error-document.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,kIAAkI;AAClI,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,GAAG,WAAW,CAU9D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,GAAG,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,GAAG,aAAa,CAIlH"}
|