@sepo27/servicio 0.0.0-stage → 0.2.3
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 +37 -0
- package/README.md +38 -2
- package/dist/spec/index.d.ts +1 -0
- package/dist/spec/index.js +1 -0
- package/dist/spec/mocks/expressRequestMock.d.ts +2 -0
- package/dist/spec/mocks/expressRequestMock.js +2 -0
- package/dist/spec/mocks/expressResponseMock.d.ts +8 -0
- package/dist/spec/mocks/expressResponseMock.js +5 -0
- package/dist/spec/mocks/index.d.ts +2 -0
- package/dist/spec/mocks/index.js +2 -0
- package/dist/src/Servicio.d.ts +8 -0
- package/dist/src/Servicio.js +50 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/lib/common/isType.d.ts +2 -0
- package/dist/src/lib/common/isType.js +2 -0
- package/dist/src/lib/common/string.d.ts +1 -0
- package/dist/src/lib/common/string.js +1 -0
- package/dist/src/lib/common/types.d.ts +4 -0
- package/dist/src/lib/common/types.js +1 -0
- package/dist/src/lib/express/types.d.ts +28 -0
- package/dist/src/lib/express/types.js +38 -0
- package/dist/src/lib/http-meta/HttpMethod.d.ts +29 -0
- package/dist/src/lib/http-meta/HttpMethod.js +33 -0
- package/dist/src/lib/http-meta/index.d.ts +5 -0
- package/dist/src/lib/http-meta/index.js +4 -0
- package/dist/src/lib/http-meta/response/HttpResponse.d.ts +7 -0
- package/dist/src/lib/http-meta/response/HttpResponse.js +1 -0
- package/dist/src/lib/http-meta/response/SuccessResponse.d.ts +11 -0
- package/dist/src/lib/http-meta/response/SuccessResponse.js +29 -0
- package/dist/src/lib/http-meta/response/errors/HttpError.d.ts +15 -0
- package/dist/src/lib/http-meta/response/errors/HttpError.js +20 -0
- package/dist/src/lib/http-meta/response/errors/errors.d.ts +122 -0
- package/dist/src/lib/http-meta/response/errors/errors.js +243 -0
- package/dist/src/lib/http-meta/response/errors/index.d.ts +2 -0
- package/dist/src/lib/http-meta/response/errors/index.js +2 -0
- package/dist/src/lib/http-meta/response/httpStatus.d.ts +83 -0
- package/dist/src/lib/http-meta/response/httpStatus.js +94 -0
- package/dist/src/lib/http-meta/response/types.d.ts +3 -0
- package/dist/src/lib/http-meta/response/types.js +1 -0
- package/dist/src/main/Route.d.ts +9 -0
- package/dist/src/main/Route.js +21 -0
- package/dist/src/main/Route.spec.d.ts +1 -0
- package/dist/src/main/Route.spec.js +26 -0
- package/dist/src/main/ServicioApp.d.ts +10 -0
- package/dist/src/main/ServicioApp.js +39 -0
- package/dist/src/main/ServicioApp.spec.d.ts +1 -0
- package/dist/src/main/ServicioApp.spec.js +85 -0
- package/dist/src/main/index.d.ts +1 -0
- package/dist/src/main/index.js +2 -0
- package/dist/src/main/servicio.d.ts +2 -0
- package/dist/src/main/servicio.js +41 -0
- package/dist/src/main/servicio.spec.d.ts +1 -0
- package/dist/src/main/servicio.spec.js +71 -0
- package/dist/src/main/types.d.ts +13 -0
- package/dist/src/main/types.js +1 -0
- package/package.json +54 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
## <small>0.2.3 (2026-11-25)</small>
|
|
2
|
+
|
|
3
|
+
## <small>0.2.2 (2026-11-25)</small>
|
|
4
|
+
|
|
5
|
+
* chore: Update package name ([039f7f6](https://github.com/sepo27/servicio/commit/039f7f6))
|
|
6
|
+
|
|
7
|
+
## <small>0.2.1 (2026-11-25)</small>
|
|
8
|
+
|
|
9
|
+
* chore: Prep for publish ([59b4eab](https://github.com/sepo27/servicio/commit/59b4eab))
|
|
10
|
+
|
|
11
|
+
## 0.2.0 (2026-11-25)
|
|
12
|
+
|
|
13
|
+
* feat: Implement base skeleton ([37661e3](https://github.com/sepo27/servicio/commit/37661e3))
|
|
14
|
+
* feat(http-meta): Implement basics ([6a51c04](https://github.com/sepo27/servicio/commit/6a51c04))
|
|
15
|
+
|
|
16
|
+
## <small>0.1.1 (2026-11-08)</small>
|
|
17
|
+
|
|
18
|
+
* Init README ([428213c](https://github.com/sepo27/servicio/commit/428213c))
|
|
19
|
+
|
|
20
|
+
## 0.1.0 (2026-11-08)
|
|
21
|
+
|
|
22
|
+
* Fix changelog script & update AGENTS.md respectivelly ([1e17b68](https://github.com/sepo27/servicio/commit/1e17b68))
|
|
23
|
+
* Fix package prepare and update AGENTS.md respectivelly ([db1085b](https://github.com/sepo27/servicio/commit/db1085b))
|
|
24
|
+
* Fix build ([1c4c514](https://github.com/sepo27/servicio/commit/1c4c514))
|
|
25
|
+
* Fix typecheck & lint ([5dfc7b7](https://github.com/sepo27/servicio/commit/5dfc7b7))
|
|
26
|
+
* Update AGENTS.md ([5af5476](https://github.com/sepo27/servicio/commit/5af5476))
|
|
27
|
+
* Update git hooks setup ([fe016fd](https://github.com/sepo27/servicio/commit/fe016fd))
|
|
28
|
+
* Setup changelog ([1c5cd0d](https://github.com/sepo27/servicio/commit/1c5cd0d))
|
|
29
|
+
* Update AGENTS.md ([762db31](https://github.com/sepo27/servicio/commit/762db31))
|
|
30
|
+
* Setup git hooks ([e73e7bb](https://github.com/sepo27/servicio/commit/e73e7bb))
|
|
31
|
+
* Setup Eslint ([aff2d1b](https://github.com/sepo27/servicio/commit/aff2d1b))
|
|
32
|
+
* Update AGENTS.md ([f9b79f8](https://github.com/sepo27/servicio/commit/f9b79f8))
|
|
33
|
+
* Init PNPM package ([170d773](https://github.com/sepo27/servicio/commit/170d773))
|
|
34
|
+
* Update AGENTS.md ([f1eea7e](https://github.com/sepo27/servicio/commit/f1eea7e))
|
|
35
|
+
* Setup NodeJS version ([34ca64d](https://github.com/sepo27/servicio/commit/34ca64d))
|
|
36
|
+
* Init gitignore ([1f1e619](https://github.com/sepo27/servicio/commit/1f1e619))
|
|
37
|
+
* Initial commit ([dc43132](https://github.com/sepo27/servicio/commit/dc43132))
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Purpose
|
|
2
|
+
|
|
3
|
+
Backend Service Frame.
|
|
4
|
+
*(Based on express JS)*
|
|
5
|
+
|
|
6
|
+
**Features:**
|
|
7
|
+
- lightweight *(as express JS itself)*
|
|
8
|
+
- reusable routes abstraction
|
|
9
|
+
- returnable http response (from route handler)
|
|
10
|
+
|
|
11
|
+
# Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Route, servicio, HttpStatus, SuccessResponse } from '@sepo27/servicio';
|
|
15
|
+
|
|
16
|
+
const app = servicio();
|
|
17
|
+
|
|
18
|
+
const fooRoute = new Route('GET /foo', () => {
|
|
19
|
+
return new SuccessResponse({
|
|
20
|
+
status: HttpStatus.OK,
|
|
21
|
+
body: {
|
|
22
|
+
ok: true,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
app.addRoute(fooRoute);
|
|
28
|
+
|
|
29
|
+
app.listen(3000, () => {
|
|
30
|
+
console.log('=== Servicio listening on port 3000');
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
2
39
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mocks/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './mocks/index.js';
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
export class Servicio {
|
|
3
|
+
constructor() {
|
|
4
|
+
this._express = express();
|
|
5
|
+
}
|
|
6
|
+
get express() {
|
|
7
|
+
return this._express;
|
|
8
|
+
}
|
|
9
|
+
run() {
|
|
10
|
+
console.log('=== Running servicio app');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// Pass-through proxy wrapper
|
|
14
|
+
export function createServicio() {
|
|
15
|
+
const servicio = new Servicio();
|
|
16
|
+
const target = servicio;
|
|
17
|
+
const expressApp = servicio.express;
|
|
18
|
+
return new Proxy(servicio, {
|
|
19
|
+
get(_target, prop) {
|
|
20
|
+
const t = _target;
|
|
21
|
+
// If the property exists on the Servicio instance, return it
|
|
22
|
+
if (prop in t) {
|
|
23
|
+
const value = t[prop];
|
|
24
|
+
// Bind methods to the target instance so they have access to `this`
|
|
25
|
+
if (typeof value === 'function') {
|
|
26
|
+
return value.bind(t);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
// Otherwise, pass through to the Express application
|
|
31
|
+
return expressApp[prop];
|
|
32
|
+
},
|
|
33
|
+
set(_target, prop, value) {
|
|
34
|
+
const t = _target;
|
|
35
|
+
// If the property exists on the Servicio instance, set it there
|
|
36
|
+
if (prop in t) {
|
|
37
|
+
t[prop] = value;
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
// Otherwise, pass through to the Express application
|
|
41
|
+
expressApp[prop] = value;
|
|
42
|
+
return true;
|
|
43
|
+
},
|
|
44
|
+
has(_target, prop) {
|
|
45
|
+
const t = _target;
|
|
46
|
+
// Check both the Servicio instance and the Express application
|
|
47
|
+
return prop in t || prop in expressApp;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const isStr: (val: any) => boolean, isNum: (val: any) => boolean, isBool: (val: any) => boolean, isNull: (val: any) => boolean, isArr: (val: any) => boolean, isObj: (val: any) => boolean, isFn: (val: any) => boolean, isRegex: (val: any) => boolean;
|
|
2
|
+
export declare const isEnum: (Enum: Object, val: string | number) => boolean;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export const isStr = (val) => typeof val === 'string', isNum = (val) => typeof val === 'number', isBool = (val) => typeof val === 'boolean', isNull = (val) => val === null, isArr = (val) => Array.isArray(val), isObj = (val) => typeof val === 'object' && !isArr(val) && !isNull(val), isFn = (val) => typeof val === 'function', isRegex = (val) => (val instanceof RegExp);
|
|
2
|
+
export const isEnum = (Enum, val) => (Object.values(Enum).indexOf(val) > -1);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const toCamelCase: (str: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const toCamelCase = (str) => str[0].toUpperCase() + str.substring(1).toLowerCase();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type ExpressPathParams = string | RegExp | Array<string | RegExp>;
|
|
2
|
+
export declare enum ExpressHttpMethod {
|
|
3
|
+
CONNECT = "connect",
|
|
4
|
+
COPY = "copy",
|
|
5
|
+
DELETE = "delete",
|
|
6
|
+
GET = "get",
|
|
7
|
+
HEAD = "head",
|
|
8
|
+
LINK = "link",
|
|
9
|
+
LOCK = "lock",
|
|
10
|
+
MKCOL = "mkcol",
|
|
11
|
+
MOVE = "move",
|
|
12
|
+
NOTIFY = "notify",
|
|
13
|
+
OPTIONS = "options",
|
|
14
|
+
PATCH = "patch",
|
|
15
|
+
POST = "post",
|
|
16
|
+
PROPFIND = "propfind",
|
|
17
|
+
PROPPATCH = "proppatch",
|
|
18
|
+
PURGE = "purge",
|
|
19
|
+
PUT = "put",
|
|
20
|
+
QUERY = "query",
|
|
21
|
+
REPORT = "report",
|
|
22
|
+
SEARCH = "search",
|
|
23
|
+
SUBSCRIBE = "subscribe",
|
|
24
|
+
TRACE = "trace",
|
|
25
|
+
UNLINK = "unlink",
|
|
26
|
+
UNLOCK = "unlock",
|
|
27
|
+
UNSUBSCRIBE = "unsubscribe"
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export var ExpressHttpMethod;
|
|
2
|
+
(function (ExpressHttpMethod) {
|
|
3
|
+
// ACL = 'acl',
|
|
4
|
+
// BIND = 'bind',
|
|
5
|
+
// CHECKOUT = 'checkout',
|
|
6
|
+
ExpressHttpMethod["CONNECT"] = "connect";
|
|
7
|
+
ExpressHttpMethod["COPY"] = "copy";
|
|
8
|
+
ExpressHttpMethod["DELETE"] = "delete";
|
|
9
|
+
ExpressHttpMethod["GET"] = "get";
|
|
10
|
+
ExpressHttpMethod["HEAD"] = "head";
|
|
11
|
+
ExpressHttpMethod["LINK"] = "link";
|
|
12
|
+
ExpressHttpMethod["LOCK"] = "lock";
|
|
13
|
+
// M_SEARCH = 'm-search',
|
|
14
|
+
// MERGE = 'merge',
|
|
15
|
+
// MKACTIVITY = 'mkactivity',
|
|
16
|
+
// MKCALENDAR = 'mkcalendar',
|
|
17
|
+
ExpressHttpMethod["MKCOL"] = "mkcol";
|
|
18
|
+
ExpressHttpMethod["MOVE"] = "move";
|
|
19
|
+
ExpressHttpMethod["NOTIFY"] = "notify";
|
|
20
|
+
ExpressHttpMethod["OPTIONS"] = "options";
|
|
21
|
+
ExpressHttpMethod["PATCH"] = "patch";
|
|
22
|
+
ExpressHttpMethod["POST"] = "post";
|
|
23
|
+
ExpressHttpMethod["PROPFIND"] = "propfind";
|
|
24
|
+
ExpressHttpMethod["PROPPATCH"] = "proppatch";
|
|
25
|
+
ExpressHttpMethod["PURGE"] = "purge";
|
|
26
|
+
ExpressHttpMethod["PUT"] = "put";
|
|
27
|
+
ExpressHttpMethod["QUERY"] = "query";
|
|
28
|
+
// REBIND = 'rebind',
|
|
29
|
+
ExpressHttpMethod["REPORT"] = "report";
|
|
30
|
+
ExpressHttpMethod["SEARCH"] = "search";
|
|
31
|
+
// SOURCE = 'source',
|
|
32
|
+
ExpressHttpMethod["SUBSCRIBE"] = "subscribe";
|
|
33
|
+
ExpressHttpMethod["TRACE"] = "trace";
|
|
34
|
+
// UNBIND = 'unbind',
|
|
35
|
+
ExpressHttpMethod["UNLINK"] = "unlink";
|
|
36
|
+
ExpressHttpMethod["UNLOCK"] = "unlock";
|
|
37
|
+
ExpressHttpMethod["UNSUBSCRIBE"] = "unsubscribe";
|
|
38
|
+
})(ExpressHttpMethod || (ExpressHttpMethod = {}));
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Methods enum.
|
|
3
|
+
* Based on RFC 9110 (HTTP Semantics) and IANA Registry of HTTP Methods.
|
|
4
|
+
* Covers all standard and commonly registered HTTP methods.
|
|
5
|
+
*
|
|
6
|
+
* (Generated by Junie).
|
|
7
|
+
*/
|
|
8
|
+
export declare enum HttpMethod {
|
|
9
|
+
GET = "GET",
|
|
10
|
+
HEAD = "HEAD",
|
|
11
|
+
POST = "POST",
|
|
12
|
+
PUT = "PUT",
|
|
13
|
+
DELETE = "DELETE",
|
|
14
|
+
CONNECT = "CONNECT",
|
|
15
|
+
OPTIONS = "OPTIONS",
|
|
16
|
+
TRACE = "TRACE",
|
|
17
|
+
PATCH = "PATCH",
|
|
18
|
+
PROPFIND = "PROPFIND",
|
|
19
|
+
PROPPATCH = "PROPPATCH",
|
|
20
|
+
MKCOL = "MKCOL",
|
|
21
|
+
COPY = "COPY",
|
|
22
|
+
MOVE = "MOVE",
|
|
23
|
+
LOCK = "LOCK",
|
|
24
|
+
UNLOCK = "UNLOCK",
|
|
25
|
+
SEARCH = "SEARCH",
|
|
26
|
+
NOTIFY = "NOTIFY",
|
|
27
|
+
SUBSCRIBE = "SUBSCRIBE",
|
|
28
|
+
UNSUBSCRIBE = "UNSUBSCRIBE"
|
|
29
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP Methods enum.
|
|
3
|
+
* Based on RFC 9110 (HTTP Semantics) and IANA Registry of HTTP Methods.
|
|
4
|
+
* Covers all standard and commonly registered HTTP methods.
|
|
5
|
+
*
|
|
6
|
+
* (Generated by Junie).
|
|
7
|
+
*/
|
|
8
|
+
export var HttpMethod;
|
|
9
|
+
(function (HttpMethod) {
|
|
10
|
+
// Standard HTTP methods (RFC 9110)
|
|
11
|
+
HttpMethod["GET"] = "GET";
|
|
12
|
+
HttpMethod["HEAD"] = "HEAD";
|
|
13
|
+
HttpMethod["POST"] = "POST";
|
|
14
|
+
HttpMethod["PUT"] = "PUT";
|
|
15
|
+
HttpMethod["DELETE"] = "DELETE";
|
|
16
|
+
HttpMethod["CONNECT"] = "CONNECT";
|
|
17
|
+
HttpMethod["OPTIONS"] = "OPTIONS";
|
|
18
|
+
HttpMethod["TRACE"] = "TRACE";
|
|
19
|
+
HttpMethod["PATCH"] = "PATCH";
|
|
20
|
+
// WebDAV methods (RFC 4918, RFC 5842, RFC 8328)
|
|
21
|
+
HttpMethod["PROPFIND"] = "PROPFIND";
|
|
22
|
+
HttpMethod["PROPPATCH"] = "PROPPATCH";
|
|
23
|
+
HttpMethod["MKCOL"] = "MKCOL";
|
|
24
|
+
HttpMethod["COPY"] = "COPY";
|
|
25
|
+
HttpMethod["MOVE"] = "MOVE";
|
|
26
|
+
HttpMethod["LOCK"] = "LOCK";
|
|
27
|
+
HttpMethod["UNLOCK"] = "UNLOCK";
|
|
28
|
+
HttpMethod["SEARCH"] = "SEARCH";
|
|
29
|
+
// Other registered methods
|
|
30
|
+
HttpMethod["NOTIFY"] = "NOTIFY";
|
|
31
|
+
HttpMethod["SUBSCRIBE"] = "SUBSCRIBE";
|
|
32
|
+
HttpMethod["UNSUBSCRIBE"] = "UNSUBSCRIBE";
|
|
33
|
+
})(HttpMethod || (HttpMethod = {}));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { HttpMethod } from './HttpMethod.js';
|
|
2
|
+
export { HttpStatus } from './response/httpStatus.js';
|
|
3
|
+
export type { HttpResponse } from './response/HttpResponse.js';
|
|
4
|
+
export { SuccessResponse } from './response/SuccessResponse.js';
|
|
5
|
+
export { HttpError, BadRequestError, } from './response/errors/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DefaultHttpResponseBody, HttpHeaders } from './types.js';
|
|
2
|
+
import { HttpStatus } from './httpStatus.js';
|
|
3
|
+
import { HttpResponse } from './HttpResponse.js';
|
|
4
|
+
type Params<B = DefaultHttpResponseBody> = [] | [HttpStatus] | [HttpResponse<B>];
|
|
5
|
+
export declare class SuccessResponse<B = DefaultHttpResponseBody> implements HttpResponse<B> {
|
|
6
|
+
constructor(...args: Params<B>);
|
|
7
|
+
readonly status: HttpStatus;
|
|
8
|
+
readonly headers?: HttpHeaders;
|
|
9
|
+
readonly body?: B;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { HttpStatus } from './httpStatus.js';
|
|
2
|
+
import { isObj } from '../../common/isType.js';
|
|
3
|
+
const DEFAULT_STATUS = HttpStatus.OK;
|
|
4
|
+
export class SuccessResponse {
|
|
5
|
+
constructor(...args) {
|
|
6
|
+
this.status = HttpStatus.OK;
|
|
7
|
+
const { status, headers, body } = extractArgs(args);
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.headers = headers;
|
|
10
|
+
this.body = body;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/*** Private ***/
|
|
14
|
+
function extractArgs(args) {
|
|
15
|
+
let status, headers, body;
|
|
16
|
+
if (args.length === 0) {
|
|
17
|
+
status = DEFAULT_STATUS;
|
|
18
|
+
}
|
|
19
|
+
else if (args.length === 1 && Number.isInteger(args[0])) {
|
|
20
|
+
status = args[0];
|
|
21
|
+
}
|
|
22
|
+
else if (args.length === 1 && isObj(args[0])) {
|
|
23
|
+
({ status, headers, body } = args[0]);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`Invalid '${SuccessResponse.name}' args`);
|
|
27
|
+
}
|
|
28
|
+
return { status, headers, body };
|
|
29
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HttpResponse } from '../HttpResponse.js';
|
|
2
|
+
import { DefaultHttpResponseBody, HttpHeaders } from '../types.js';
|
|
3
|
+
import { HttpErrorStatus } from '../httpStatus.js';
|
|
4
|
+
import { LooseObject } from '../../../common/types.js';
|
|
5
|
+
export interface HttpErrorOpts<B = any> {
|
|
6
|
+
headers?: LooseObject;
|
|
7
|
+
body?: B;
|
|
8
|
+
message?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class HttpError<B = DefaultHttpResponseBody> extends Error implements HttpResponse<B> {
|
|
11
|
+
constructor(status: HttpErrorStatus, opts?: HttpErrorOpts<B>);
|
|
12
|
+
readonly status: HttpErrorStatus;
|
|
13
|
+
readonly headers?: HttpHeaders;
|
|
14
|
+
readonly body?: B;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { httpStatusText } from '../httpStatus.js';
|
|
2
|
+
export class HttpError extends Error {
|
|
3
|
+
constructor(status, opts = {}) {
|
|
4
|
+
super(makeMessage(status, opts));
|
|
5
|
+
// Set the prototype explicitly
|
|
6
|
+
Object.setPrototypeOf(this, HttpError.prototype);
|
|
7
|
+
// this.name = HttpError.name; // TODO: not needed (name derived via prototype) ?
|
|
8
|
+
this.status = status;
|
|
9
|
+
this.headers = opts.headers;
|
|
10
|
+
this.body = opts.body;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/*** Private ***/
|
|
14
|
+
function makeMessage(status, opts) {
|
|
15
|
+
const msg = [`[${status} ${httpStatusText(status)}]`];
|
|
16
|
+
if (opts.message) {
|
|
17
|
+
msg.push(`${opts.message}`);
|
|
18
|
+
}
|
|
19
|
+
return msg.join(' ');
|
|
20
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { HttpError, HttpErrorOpts } from './HttpError.js';
|
|
2
|
+
import { DefaultHttpResponseBody } from '../types.js';
|
|
3
|
+
export declare class BadRequestError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
4
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
5
|
+
}
|
|
6
|
+
export declare class UnauthorizedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
7
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
8
|
+
}
|
|
9
|
+
export declare class PaymentRequiredError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
10
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
11
|
+
}
|
|
12
|
+
export declare class ForbiddenError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
13
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
14
|
+
}
|
|
15
|
+
export declare class NotFoundError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
16
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
17
|
+
}
|
|
18
|
+
export declare class MethodNotAllowedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
19
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
20
|
+
}
|
|
21
|
+
export declare class NotAcceptableError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
22
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
23
|
+
}
|
|
24
|
+
export declare class ProxyAuthenticationRequiredError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
25
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
26
|
+
}
|
|
27
|
+
export declare class RequestTimeoutError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
28
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
29
|
+
}
|
|
30
|
+
export declare class ConflictError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
31
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
32
|
+
}
|
|
33
|
+
export declare class GoneError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
34
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
35
|
+
}
|
|
36
|
+
export declare class LengthRequiredError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
37
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
38
|
+
}
|
|
39
|
+
export declare class PreconditionFailedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
40
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
41
|
+
}
|
|
42
|
+
export declare class ContentTooLargeError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
43
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
44
|
+
}
|
|
45
|
+
export declare class UriTooLongError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
46
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
47
|
+
}
|
|
48
|
+
export declare class UnsupportedMediaTypeError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
49
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
50
|
+
}
|
|
51
|
+
export declare class RangeNotSatisfiableError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
52
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
53
|
+
}
|
|
54
|
+
export declare class ExpectationFailedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
55
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
56
|
+
}
|
|
57
|
+
export declare class ImATeapotError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
58
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
59
|
+
}
|
|
60
|
+
export declare class MisdirectedRequestError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
61
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
62
|
+
}
|
|
63
|
+
export declare class UnprocessableContentError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
64
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
65
|
+
}
|
|
66
|
+
export declare class LockedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
67
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
68
|
+
}
|
|
69
|
+
export declare class FailedDependencyError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
70
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
71
|
+
}
|
|
72
|
+
export declare class TooEarlyError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
73
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
74
|
+
}
|
|
75
|
+
export declare class UpgradeRequiredError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
76
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
77
|
+
}
|
|
78
|
+
export declare class PreconditionRequiredError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
79
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
80
|
+
}
|
|
81
|
+
export declare class TooManyRequestsError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
82
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
83
|
+
}
|
|
84
|
+
export declare class RequestHeaderFieldsTooLargeError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
85
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
86
|
+
}
|
|
87
|
+
export declare class UnavailableForLegalReasonsError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
88
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
89
|
+
}
|
|
90
|
+
export declare class InternalServerError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
91
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
92
|
+
}
|
|
93
|
+
export declare class NotImplementedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
94
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
95
|
+
}
|
|
96
|
+
export declare class BadGatewayError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
97
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
98
|
+
}
|
|
99
|
+
export declare class ServiceUnavailableError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
100
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
101
|
+
}
|
|
102
|
+
export declare class GatewayTimeoutError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
103
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
104
|
+
}
|
|
105
|
+
export declare class HttpVersionNotSupportedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
106
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
107
|
+
}
|
|
108
|
+
export declare class VariantAlsoNegotiatesError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
109
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
110
|
+
}
|
|
111
|
+
export declare class InsufficientStorageError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
112
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
113
|
+
}
|
|
114
|
+
export declare class LoopDetectedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
115
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
116
|
+
}
|
|
117
|
+
export declare class NotExtendedError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
118
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
119
|
+
}
|
|
120
|
+
export declare class NetworkAuthenticationRequiredError<B = DefaultHttpResponseBody> extends HttpError<B> {
|
|
121
|
+
constructor(opts?: HttpErrorOpts<B>);
|
|
122
|
+
}
|