@toa.io/extensions.exposition 0.9.0-canary.2 → 0.20.0-alpha.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/components/context.toa.yaml +15 -0
- package/components/identity.bans/manifest.toa.yaml +18 -0
- package/components/identity.basic/events/principal.js +9 -0
- package/components/identity.basic/manifest.toa.yaml +50 -0
- package/components/identity.basic/source/authenticate.ts +29 -0
- package/components/identity.basic/source/create.ts +19 -0
- package/components/identity.basic/source/transit.ts +64 -0
- package/components/identity.basic/source/types.ts +42 -0
- package/components/identity.basic/tsconfig.json +9 -0
- package/components/identity.roles/manifest.toa.yaml +31 -0
- package/components/identity.roles/source/list.ts +7 -0
- package/components/identity.roles/source/principal.ts +20 -0
- package/components/identity.roles/tsconfig.json +9 -0
- package/components/identity.tokens/manifest.toa.yaml +39 -0
- package/components/identity.tokens/receivers/identity.bans.updated.js +3 -0
- package/components/identity.tokens/source/authenticate.test.ts +56 -0
- package/components/identity.tokens/source/authenticate.ts +38 -0
- package/components/identity.tokens/source/decrypt.test.ts +59 -0
- package/components/identity.tokens/source/decrypt.ts +25 -0
- package/components/identity.tokens/source/encrypt.test.ts +35 -0
- package/components/identity.tokens/source/encrypt.ts +25 -0
- package/components/identity.tokens/source/revoke.ts +5 -0
- package/components/identity.tokens/source/types.ts +48 -0
- package/components/identity.tokens/tsconfig.json +9 -0
- package/cucumber.js +9 -0
- package/documentation/.assets/ia3-dark.jpg +0 -0
- package/documentation/.assets/ia3-light.jpg +0 -0
- package/documentation/.assets/overview-dark.jpg +0 -0
- package/documentation/.assets/overview-light.jpg +0 -0
- package/documentation/.assets/role-scopes-dark.jpg +0 -0
- package/documentation/.assets/role-scopes-light.jpg +0 -0
- package/documentation/.assets/rtd-dark.jpg +0 -0
- package/documentation/.assets/rtd-light.jpg +0 -0
- package/documentation/access.md +256 -0
- package/documentation/components.md +276 -0
- package/documentation/identity.md +156 -0
- package/documentation/protocol.md +15 -0
- package/documentation/query.md +226 -0
- package/documentation/tree.md +169 -0
- package/features/access.feature +442 -0
- package/features/annotation.feature +28 -0
- package/features/body.feature +21 -0
- package/features/directives.feature +56 -0
- package/features/dynamic.feature +89 -0
- package/features/errors.feature +208 -0
- package/features/identity.basic.feature +235 -0
- package/features/identity.feature +61 -0
- package/features/identity.roles.feature +51 -0
- package/features/identity.tokens.feature +116 -0
- package/features/queries.feature +214 -0
- package/features/routes.feature +49 -0
- package/features/steps/Common.ts +10 -0
- package/features/steps/Components.ts +43 -0
- package/features/steps/Database.ts +58 -0
- package/features/steps/Gateway.ts +105 -0
- package/features/steps/HTTP.ts +71 -0
- package/features/steps/Parameters.ts +12 -0
- package/features/steps/Workspace.ts +40 -0
- package/features/steps/components/greeter/manifest.toa.yaml +9 -0
- package/features/steps/components/greeter/operations/greet.js +7 -0
- package/features/steps/components/pots/manifest.toa.yaml +20 -0
- package/features/steps/components/users/manifest.toa.yaml +11 -0
- package/features/steps/tsconfig.json +9 -0
- package/package.json +31 -17
- package/readme.md +181 -0
- package/schemas/annotation.cos.yaml +4 -0
- package/schemas/directive.cos.yaml +3 -0
- package/schemas/method.cos.yaml +9 -0
- package/schemas/node.cos.yaml +5 -0
- package/schemas/query.cos.yaml +16 -0
- package/schemas/querystring.cos.yaml +5 -0
- package/schemas/range.cos.yaml +2 -0
- package/schemas/route.cos.yaml +2 -0
- package/source/Annotation.ts +6 -0
- package/source/Branch.ts +8 -0
- package/source/Composition.ts +58 -0
- package/source/Context.ts +6 -0
- package/source/Directive.test.ts +91 -0
- package/source/Directive.ts +120 -0
- package/source/Endpoint.ts +57 -0
- package/source/Factory.ts +53 -0
- package/source/Gateway.ts +93 -0
- package/source/HTTP/Server.fixtures.ts +45 -0
- package/source/HTTP/Server.test.ts +221 -0
- package/source/HTTP/Server.ts +135 -0
- package/source/HTTP/exceptions.ts +77 -0
- package/source/HTTP/formats/index.ts +19 -0
- package/source/HTTP/formats/json.ts +13 -0
- package/source/HTTP/formats/msgpack.ts +10 -0
- package/source/HTTP/formats/text.ts +9 -0
- package/source/HTTP/formats/yaml.ts +14 -0
- package/source/HTTP/index.ts +3 -0
- package/source/HTTP/messages.test.ts +116 -0
- package/source/HTTP/messages.ts +77 -0
- package/source/Mapping.ts +48 -0
- package/source/Query.test.ts +37 -0
- package/source/Query.ts +105 -0
- package/source/RTD/Context.ts +16 -0
- package/source/RTD/Directives.ts +9 -0
- package/source/RTD/Endpoint.ts +11 -0
- package/source/RTD/Match.ts +16 -0
- package/source/RTD/Method.ts +24 -0
- package/source/RTD/Node.ts +85 -0
- package/source/RTD/Route.ts +58 -0
- package/source/RTD/Tree.ts +57 -0
- package/source/RTD/factory.ts +47 -0
- package/source/RTD/index.ts +8 -0
- package/source/RTD/segment.test.ts +32 -0
- package/source/RTD/segment.ts +25 -0
- package/source/RTD/syntax/index.ts +2 -0
- package/source/RTD/syntax/parse.test.ts +188 -0
- package/source/RTD/syntax/parse.ts +153 -0
- package/source/RTD/syntax/types.ts +48 -0
- package/source/Remotes.test.ts +41 -0
- package/source/Remotes.ts +20 -0
- package/source/Tenant.ts +38 -0
- package/source/deployment.ts +42 -0
- package/source/directives/auth/Anonymous.ts +14 -0
- package/source/directives/auth/Echo.ts +12 -0
- package/source/directives/auth/Family.ts +145 -0
- package/source/directives/auth/Id.ts +19 -0
- package/source/directives/auth/Incept.ts +42 -0
- package/source/directives/auth/Role.test.ts +62 -0
- package/source/directives/auth/Role.ts +56 -0
- package/source/directives/auth/Rule.ts +28 -0
- package/source/directives/auth/Scheme.ts +26 -0
- package/source/directives/auth/index.ts +3 -0
- package/source/directives/auth/schemes.ts +8 -0
- package/source/directives/auth/split.ts +15 -0
- package/source/directives/auth/types.ts +37 -0
- package/source/directives/dev/Family.ts +34 -0
- package/source/directives/dev/Stub.ts +14 -0
- package/source/directives/dev/index.ts +3 -0
- package/source/directives/dev/types.ts +5 -0
- package/source/directives/index.ts +5 -0
- package/source/discovery.ts +1 -0
- package/source/exceptions.ts +17 -0
- package/source/index.test.ts +9 -0
- package/source/index.ts +6 -0
- package/source/manifest.test.ts +57 -0
- package/source/manifest.ts +35 -0
- package/source/root.ts +38 -0
- package/source/schemas.ts +9 -0
- package/transpiled/Annotation.d.ts +6 -0
- package/transpiled/Annotation.js +3 -0
- package/transpiled/Annotation.js.map +1 -0
- package/transpiled/Branch.d.ts +7 -0
- package/transpiled/Branch.js +3 -0
- package/transpiled/Branch.js.map +1 -0
- package/transpiled/Composition.d.ts +14 -0
- package/transpiled/Composition.js +43 -0
- package/transpiled/Composition.js.map +1 -0
- package/transpiled/Context.d.ts +5 -0
- package/transpiled/Context.js +3 -0
- package/transpiled/Context.js.map +1 -0
- package/transpiled/Directive.d.ts +32 -0
- package/transpiled/Directive.js +76 -0
- package/transpiled/Directive.js.map +1 -0
- package/transpiled/Endpoint.d.ts +20 -0
- package/transpiled/Endpoint.js +44 -0
- package/transpiled/Endpoint.js.map +1 -0
- package/transpiled/Factory.d.ts +11 -0
- package/transpiled/Factory.js +67 -0
- package/transpiled/Factory.js.map +1 -0
- package/transpiled/Gateway.d.ts +19 -0
- package/transpiled/Gateway.js +90 -0
- package/transpiled/Gateway.js.map +1 -0
- package/transpiled/HTTP/Server.d.ts +22 -0
- package/transpiled/HTTP/Server.fixtures.d.ts +12 -0
- package/transpiled/HTTP/Server.fixtures.js +36 -0
- package/transpiled/HTTP/Server.fixtures.js.map +1 -0
- package/transpiled/HTTP/Server.js +111 -0
- package/transpiled/HTTP/Server.js.map +1 -0
- package/transpiled/HTTP/exceptions.d.ts +39 -0
- package/transpiled/HTTP/exceptions.js +78 -0
- package/transpiled/HTTP/exceptions.js.map +1 -0
- package/transpiled/HTTP/formats/index.d.ts +8 -0
- package/transpiled/HTTP/formats/index.js +38 -0
- package/transpiled/HTTP/formats/index.js.map +1 -0
- package/transpiled/HTTP/formats/json.d.ts +4 -0
- package/transpiled/HTTP/formats/json.js +15 -0
- package/transpiled/HTTP/formats/json.js.map +1 -0
- package/transpiled/HTTP/formats/msgpack.d.ts +4 -0
- package/transpiled/HTTP/formats/msgpack.js +36 -0
- package/transpiled/HTTP/formats/msgpack.js.map +1 -0
- package/transpiled/HTTP/formats/text.d.ts +4 -0
- package/transpiled/HTTP/formats/text.js +13 -0
- package/transpiled/HTTP/formats/text.js.map +1 -0
- package/transpiled/HTTP/formats/yaml.d.ts +4 -0
- package/transpiled/HTTP/formats/yaml.js +39 -0
- package/transpiled/HTTP/formats/yaml.js.map +1 -0
- package/transpiled/HTTP/index.d.ts +3 -0
- package/transpiled/HTTP/index.js +20 -0
- package/transpiled/HTTP/index.js.map +1 -0
- package/transpiled/HTTP/messages.d.ts +27 -0
- package/transpiled/HTTP/messages.js +49 -0
- package/transpiled/HTTP/messages.js.map +1 -0
- package/transpiled/Mapping.d.ts +8 -0
- package/transpiled/Mapping.js +35 -0
- package/transpiled/Mapping.js.map +1 -0
- package/transpiled/Query.d.ts +13 -0
- package/transpiled/Query.js +107 -0
- package/transpiled/Query.js.map +1 -0
- package/transpiled/RTD/Context.d.ts +11 -0
- package/transpiled/RTD/Context.js +3 -0
- package/transpiled/RTD/Context.js.map +1 -0
- package/transpiled/RTD/Directives.d.ts +7 -0
- package/transpiled/RTD/Directives.js +3 -0
- package/transpiled/RTD/Directives.js.map +1 -0
- package/transpiled/RTD/Endpoint.d.ts +9 -0
- package/transpiled/RTD/Endpoint.js +3 -0
- package/transpiled/RTD/Endpoint.js.map +1 -0
- package/transpiled/RTD/Match.d.ts +11 -0
- package/transpiled/RTD/Match.js +3 -0
- package/transpiled/RTD/Match.js.map +1 -0
- package/transpiled/RTD/Method.d.ts +9 -0
- package/transpiled/RTD/Method.js +16 -0
- package/transpiled/RTD/Method.js.map +1 -0
- package/transpiled/RTD/Node.d.ts +21 -0
- package/transpiled/RTD/Node.js +61 -0
- package/transpiled/RTD/Node.js.map +1 -0
- package/transpiled/RTD/Route.d.ts +14 -0
- package/transpiled/RTD/Route.js +48 -0
- package/transpiled/RTD/Route.js.map +1 -0
- package/transpiled/RTD/Tree.d.ts +14 -0
- package/transpiled/RTD/Tree.js +45 -0
- package/transpiled/RTD/Tree.js.map +1 -0
- package/transpiled/RTD/factory.d.ts +6 -0
- package/transpiled/RTD/factory.js +36 -0
- package/transpiled/RTD/factory.js.map +1 -0
- package/transpiled/RTD/index.d.ts +8 -0
- package/transpiled/RTD/index.js +38 -0
- package/transpiled/RTD/index.js.map +1 -0
- package/transpiled/RTD/segment.d.ts +8 -0
- package/transpiled/RTD/segment.js +23 -0
- package/transpiled/RTD/segment.js.map +1 -0
- package/transpiled/RTD/syntax/index.d.ts +2 -0
- package/transpiled/RTD/syntax/index.js +19 -0
- package/transpiled/RTD/syntax/index.js.map +1 -0
- package/transpiled/RTD/syntax/parse.d.ts +4 -0
- package/transpiled/RTD/syntax/parse.js +128 -0
- package/transpiled/RTD/syntax/parse.js.map +1 -0
- package/transpiled/RTD/syntax/types.d.ts +41 -0
- package/transpiled/RTD/syntax/types.js +5 -0
- package/transpiled/RTD/syntax/types.js.map +1 -0
- package/transpiled/Remotes.d.ts +7 -0
- package/transpiled/Remotes.js +19 -0
- package/transpiled/Remotes.js.map +1 -0
- package/transpiled/Tenant.d.ts +12 -0
- package/transpiled/Tenant.js +30 -0
- package/transpiled/Tenant.js.map +1 -0
- package/transpiled/deployment.d.ts +3 -0
- package/transpiled/deployment.js +61 -0
- package/transpiled/deployment.js.map +1 -0
- package/transpiled/directives/auth/Anonymous.d.ts +6 -0
- package/transpiled/directives/auth/Anonymous.js +17 -0
- package/transpiled/directives/auth/Anonymous.js.map +1 -0
- package/transpiled/directives/auth/Echo.d.ts +6 -0
- package/transpiled/directives/auth/Echo.js +13 -0
- package/transpiled/directives/auth/Echo.js.map +1 -0
- package/transpiled/directives/auth/Family.d.ts +20 -0
- package/transpiled/directives/auth/Family.js +125 -0
- package/transpiled/directives/auth/Family.js.map +1 -0
- package/transpiled/directives/auth/Id.d.ts +7 -0
- package/transpiled/directives/auth/Id.js +17 -0
- package/transpiled/directives/auth/Id.js.map +1 -0
- package/transpiled/directives/auth/Incept.d.ts +10 -0
- package/transpiled/directives/auth/Incept.js +59 -0
- package/transpiled/directives/auth/Incept.js.map +1 -0
- package/transpiled/directives/auth/Role.d.ts +11 -0
- package/transpiled/directives/auth/Role.js +44 -0
- package/transpiled/directives/auth/Role.js.map +1 -0
- package/transpiled/directives/auth/Rule.d.ts +9 -0
- package/transpiled/directives/auth/Rule.js +22 -0
- package/transpiled/directives/auth/Rule.js.map +1 -0
- package/transpiled/directives/auth/Scheme.d.ts +7 -0
- package/transpiled/directives/auth/Scheme.js +47 -0
- package/transpiled/directives/auth/Scheme.js.map +1 -0
- package/transpiled/directives/auth/index.d.ts +2 -0
- package/transpiled/directives/auth/index.js +7 -0
- package/transpiled/directives/auth/index.js.map +1 -0
- package/transpiled/directives/auth/schemes.d.ts +3 -0
- package/transpiled/directives/auth/schemes.js +9 -0
- package/transpiled/directives/auth/schemes.js.map +1 -0
- package/transpiled/directives/auth/split.d.ts +2 -0
- package/transpiled/directives/auth/split.js +38 -0
- package/transpiled/directives/auth/split.js.map +1 -0
- package/transpiled/directives/auth/types.d.ts +31 -0
- package/transpiled/directives/auth/types.js +3 -0
- package/transpiled/directives/auth/types.js.map +1 -0
- package/transpiled/directives/dev/Family.d.ts +10 -0
- package/transpiled/directives/dev/Family.js +25 -0
- package/transpiled/directives/dev/Family.js.map +1 -0
- package/transpiled/directives/dev/Stub.d.ts +7 -0
- package/transpiled/directives/dev/Stub.js +14 -0
- package/transpiled/directives/dev/Stub.js.map +1 -0
- package/transpiled/directives/dev/index.d.ts +2 -0
- package/transpiled/directives/dev/index.js +7 -0
- package/transpiled/directives/dev/index.js.map +1 -0
- package/transpiled/directives/dev/types.d.ts +4 -0
- package/transpiled/directives/dev/types.js +3 -0
- package/transpiled/directives/dev/types.js.map +1 -0
- package/transpiled/directives/index.d.ts +2 -0
- package/transpiled/directives/index.js +10 -0
- package/transpiled/directives/index.js.map +1 -0
- package/transpiled/discovery.d.ts +1 -0
- package/transpiled/discovery.js +3 -0
- package/transpiled/discovery.js.map +1 -0
- package/transpiled/exceptions.d.ts +2 -0
- package/transpiled/exceptions.js +39 -0
- package/transpiled/exceptions.js.map +1 -0
- package/transpiled/index.d.ts +5 -0
- package/transpiled/index.js +12 -0
- package/transpiled/index.js.map +1 -0
- package/transpiled/manifest.d.ts +3 -0
- package/transpiled/manifest.js +30 -0
- package/transpiled/manifest.js.map +1 -0
- package/transpiled/root.d.ts +2 -0
- package/transpiled/root.js +39 -0
- package/transpiled/root.js.map +1 -0
- package/transpiled/schemas.d.ts +3 -0
- package/transpiled/schemas.js +14 -0
- package/transpiled/schemas.js.map +1 -0
- package/transpiled/tsconfig.tsbuildinfo +1 -0
- package/tsconfig.json +12 -0
- package/src/.manifest/index.js +0 -7
- package/src/.manifest/normalize.js +0 -58
- package/src/.manifest/schema.yaml +0 -71
- package/src/.manifest/validate.js +0 -17
- package/src/constants.js +0 -3
- package/src/deployment.js +0 -23
- package/src/exposition.js +0 -68
- package/src/factory.js +0 -76
- package/src/index.js +0 -9
- package/src/manifest.js +0 -12
- package/src/query/criteria.js +0 -55
- package/src/query/enum.js +0 -35
- package/src/query/index.js +0 -17
- package/src/query/query.js +0 -60
- package/src/query/range.js +0 -28
- package/src/query/sort.js +0 -19
- package/src/remote.js +0 -88
- package/src/server.js +0 -83
- package/src/tenant.js +0 -29
- package/src/translate/etag.js +0 -14
- package/src/translate/index.js +0 -7
- package/src/translate/request.js +0 -68
- package/src/translate/response.js +0 -62
- package/src/tree.js +0 -109
- package/test/manifest.normalize.fixtures.js +0 -37
- package/test/manifest.normalize.test.js +0 -37
- package/test/manifest.validate.test.js +0 -40
- package/test/query.range.test.js +0 -18
- package/test/tree.fixtures.js +0 -21
- package/test/tree.test.js +0 -44
- package/types/annotations.d.ts +0 -10
- package/types/declarations.d.ts +0 -31
- package/types/exposition.d.ts +0 -13
- package/types/http.d.ts +0 -13
- package/types/query.d.ts +0 -16
- package/types/remote.d.ts +0 -19
- package/types/server.d.ts +0 -13
- package/types/tree.d.ts +0 -33
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Server = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const cors_1 = __importDefault(require("cors"));
|
|
9
|
+
const core_1 = require("@toa.io/core");
|
|
10
|
+
const generic_1 = require("@toa.io/generic");
|
|
11
|
+
const messages_1 = require("./messages");
|
|
12
|
+
const exceptions_1 = require("./exceptions");
|
|
13
|
+
class Server extends core_1.Connector {
|
|
14
|
+
debug;
|
|
15
|
+
app;
|
|
16
|
+
server;
|
|
17
|
+
constructor(app, debug) {
|
|
18
|
+
super();
|
|
19
|
+
this.app = app;
|
|
20
|
+
this.debug = debug;
|
|
21
|
+
}
|
|
22
|
+
static create(options = {}) {
|
|
23
|
+
const properties = Object.assign({}, defaults(), options);
|
|
24
|
+
const app = (0, express_1.default)();
|
|
25
|
+
app.disable('x-powered-by');
|
|
26
|
+
app.use((0, cors_1.default)({ allowedHeaders: ['content-type'] }));
|
|
27
|
+
app.use(supportedMethods(properties.methods));
|
|
28
|
+
return new Server(app, properties.debug);
|
|
29
|
+
}
|
|
30
|
+
attach(process) {
|
|
31
|
+
this.app.use((request, response) => {
|
|
32
|
+
this.read(request)
|
|
33
|
+
.then(process)
|
|
34
|
+
.then(this.success(request, response))
|
|
35
|
+
.catch(this.fail(request, response));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async open() {
|
|
39
|
+
const listening = (0, generic_1.promex)();
|
|
40
|
+
this.server = this.app.listen(8000, listening.callback);
|
|
41
|
+
await listening;
|
|
42
|
+
console.info('HTTP Server is listening.');
|
|
43
|
+
}
|
|
44
|
+
async close() {
|
|
45
|
+
const stopped = (0, generic_1.promex)();
|
|
46
|
+
this.server?.close(stopped.callback);
|
|
47
|
+
await stopped;
|
|
48
|
+
}
|
|
49
|
+
dispose() {
|
|
50
|
+
console.info('HTTP Server has been stopped.');
|
|
51
|
+
}
|
|
52
|
+
async read(request) {
|
|
53
|
+
const { method, path, headers, query } = request;
|
|
54
|
+
const body = await (0, messages_1.read)(request);
|
|
55
|
+
return { method, path, headers, query, body };
|
|
56
|
+
}
|
|
57
|
+
success(request, response) {
|
|
58
|
+
return (message) => {
|
|
59
|
+
let status = message.status;
|
|
60
|
+
if (status === undefined)
|
|
61
|
+
if (message.body === null)
|
|
62
|
+
status = 404;
|
|
63
|
+
else if (request.method === 'POST')
|
|
64
|
+
status = 201;
|
|
65
|
+
else if (message.body === undefined)
|
|
66
|
+
status = 204;
|
|
67
|
+
else
|
|
68
|
+
status = 200;
|
|
69
|
+
response
|
|
70
|
+
.status(status)
|
|
71
|
+
.set(message.headers);
|
|
72
|
+
if (message.body !== undefined && message.body !== null)
|
|
73
|
+
(0, messages_1.write)(request, response, message.body);
|
|
74
|
+
else
|
|
75
|
+
response.end();
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
fail(request, response) {
|
|
79
|
+
return (exception) => {
|
|
80
|
+
let status = 500;
|
|
81
|
+
if (exception instanceof exceptions_1.Exception)
|
|
82
|
+
status = exception.status;
|
|
83
|
+
const outputAllowed = exception instanceof exceptions_1.ClientError || this.debug;
|
|
84
|
+
response.status(status);
|
|
85
|
+
if (outputAllowed) {
|
|
86
|
+
const body = exception instanceof exceptions_1.Exception
|
|
87
|
+
? exception.body
|
|
88
|
+
: (exception.stack ?? exception.message);
|
|
89
|
+
(0, messages_1.write)(request, response, body);
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
response.end();
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.Server = Server;
|
|
97
|
+
function supportedMethods(methods) {
|
|
98
|
+
return (req, res, next) => {
|
|
99
|
+
if (methods.has(req.method))
|
|
100
|
+
next();
|
|
101
|
+
else
|
|
102
|
+
res.sendStatus(501);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function defaults() {
|
|
106
|
+
return {
|
|
107
|
+
methods: new Set(['GET', 'POST', 'PUT', 'PATCH', 'DELETE']),
|
|
108
|
+
debug: process.env.TOA_DEV === '1'
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=Server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Server.js","sourceRoot":"","sources":["../../source/HTTP/Server.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAC7B,gDAAuB;AACvB,uCAAwC;AACxC,6CAAwC;AACxC,yCAAoF;AACpF,6CAAqD;AAIrD,MAAa,MAAO,SAAQ,gBAAS;IAClB,KAAK,CAAS;IACd,GAAG,CAAS;IACrB,MAAM,CAAc;IAE5B,YAAqB,GAAY,EAAE,KAAc;QAC/C,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAEM,MAAM,CAAC,MAAM,CAAE,UAA+B,EAAE;QACrD,MAAM,UAAU,GAAe,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAA;QAErE,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAA;QAErB,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;QAC3B,GAAG,CAAC,GAAG,CAAC,IAAA,cAAI,EAAC,EAAE,cAAc,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAA;QACnD,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAA;QAE7C,OAAO,IAAI,MAAM,CAAC,GAAG,EAAE,UAAU,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC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AO,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;aAC/B;;gBACC,QAAQ,CAAC,GAAG,EAAE,CAAA;QAClB,CAAC,CAAA;IACH,CAAC;CACF;AAxGD,wBAwGC;AAED,SAAS,gBAAgB,CAAE,OAAoB;IAC7C,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAQ,EAAE;QAC/D,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;YAAE,IAAI,EAAE,CAAA;;YAC9B,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IAC1B,CAAC,CAAA;AACH,CAAC;AAOD,SAAS,QAAQ;IACf,OAAO;QACL,OAAO,EAAE,IAAI,GAAG,CAAS,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;QACnE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO,KAAK,GAAG;KACnC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare class Exception extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly body?: any;
|
|
4
|
+
protected constructor(status: number, body?: any);
|
|
5
|
+
}
|
|
6
|
+
export declare class ClientError extends Exception {
|
|
7
|
+
}
|
|
8
|
+
export declare class BadRequest extends ClientError {
|
|
9
|
+
constructor(body?: any);
|
|
10
|
+
}
|
|
11
|
+
export declare class Unauthorized extends ClientError {
|
|
12
|
+
constructor(body?: any);
|
|
13
|
+
}
|
|
14
|
+
export declare class Forbidden extends ClientError {
|
|
15
|
+
constructor(body?: any);
|
|
16
|
+
}
|
|
17
|
+
export declare class NotFound extends ClientError {
|
|
18
|
+
constructor(body?: any);
|
|
19
|
+
}
|
|
20
|
+
export declare class Conflict extends ClientError {
|
|
21
|
+
constructor(body: any);
|
|
22
|
+
}
|
|
23
|
+
export declare class MethodNotAllowed extends ClientError {
|
|
24
|
+
constructor();
|
|
25
|
+
}
|
|
26
|
+
declare class MediaTypeException extends ClientError {
|
|
27
|
+
private static readonly message;
|
|
28
|
+
protected constructor(status: number);
|
|
29
|
+
}
|
|
30
|
+
export declare class NotAcceptable extends MediaTypeException {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
export declare class UnsupportedMediaType extends MediaTypeException {
|
|
34
|
+
constructor();
|
|
35
|
+
}
|
|
36
|
+
export declare class PreconditionFailed extends ClientError {
|
|
37
|
+
constructor();
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PreconditionFailed = exports.UnsupportedMediaType = exports.NotAcceptable = exports.MethodNotAllowed = exports.Conflict = exports.NotFound = exports.Forbidden = exports.Unauthorized = exports.BadRequest = exports.ClientError = exports.Exception = void 0;
|
|
4
|
+
const formats_1 = require("./formats");
|
|
5
|
+
class Exception extends Error {
|
|
6
|
+
status;
|
|
7
|
+
body;
|
|
8
|
+
constructor(status, body) {
|
|
9
|
+
super();
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.body = body;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Exception = Exception;
|
|
15
|
+
class ClientError extends Exception {
|
|
16
|
+
}
|
|
17
|
+
exports.ClientError = ClientError;
|
|
18
|
+
class BadRequest extends ClientError {
|
|
19
|
+
constructor(body) {
|
|
20
|
+
super(400, body);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.BadRequest = BadRequest;
|
|
24
|
+
class Unauthorized extends ClientError {
|
|
25
|
+
constructor(body) {
|
|
26
|
+
super(401, body);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.Unauthorized = Unauthorized;
|
|
30
|
+
class Forbidden extends ClientError {
|
|
31
|
+
constructor(body) {
|
|
32
|
+
super(403, body);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Forbidden = Forbidden;
|
|
36
|
+
class NotFound extends ClientError {
|
|
37
|
+
constructor(body) {
|
|
38
|
+
super(404, body);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.NotFound = NotFound;
|
|
42
|
+
class Conflict extends ClientError {
|
|
43
|
+
constructor(body) {
|
|
44
|
+
super(409, body);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Conflict = Conflict;
|
|
48
|
+
class MethodNotAllowed extends ClientError {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(405);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.MethodNotAllowed = MethodNotAllowed;
|
|
54
|
+
class MediaTypeException extends ClientError {
|
|
55
|
+
static message = 'Supported media types:\n- ' + formats_1.types.join('\n- ');
|
|
56
|
+
constructor(status) {
|
|
57
|
+
super(status, MediaTypeException.message);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class NotAcceptable extends MediaTypeException {
|
|
61
|
+
constructor() {
|
|
62
|
+
super(406);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.NotAcceptable = NotAcceptable;
|
|
66
|
+
class UnsupportedMediaType extends MediaTypeException {
|
|
67
|
+
constructor() {
|
|
68
|
+
super(415);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.UnsupportedMediaType = UnsupportedMediaType;
|
|
72
|
+
class PreconditionFailed extends ClientError {
|
|
73
|
+
constructor() {
|
|
74
|
+
super(412);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.PreconditionFailed = PreconditionFailed;
|
|
78
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../../source/HTTP/exceptions.ts"],"names":[],"mappings":";;;AAAA,uCAAiC;AAEjC,MAAa,SAAU,SAAQ,KAAK;IAClB,MAAM,CAAQ;IACd,IAAI,CAAM;IAE1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,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,sCAIC;AAED,MAAa,oBAAqB,SAAQ,kBAAkB;IAC1D;QACE,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,oDAIC;AAED,MAAa,kBAAmB,SAAQ,WAAW;IACjD;QACE,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,gDAIC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { type Buffer } from 'node:buffer';
|
|
3
|
+
export declare const formats: Record<string, Format>;
|
|
4
|
+
export declare const types: string[];
|
|
5
|
+
export interface Format {
|
|
6
|
+
encode: (value: any) => Buffer;
|
|
7
|
+
decode: (buffer: Buffer) => any;
|
|
8
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.types = exports.formats = void 0;
|
|
27
|
+
const json = __importStar(require("./json"));
|
|
28
|
+
const yaml = __importStar(require("./yaml"));
|
|
29
|
+
const msgpack = __importStar(require("./msgpack"));
|
|
30
|
+
const text = __importStar(require("./text"));
|
|
31
|
+
exports.formats = {
|
|
32
|
+
'application/yaml': yaml,
|
|
33
|
+
'application/msgpack': msgpack,
|
|
34
|
+
'application/json': json,
|
|
35
|
+
'text/plain': text
|
|
36
|
+
};
|
|
37
|
+
exports.types = Object.keys(exports.formats);
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../source/HTTP/formats/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,6CAA8B;AAC9B,6CAA8B;AAC9B,mDAAoC;AACpC,6CAA8B;AAEjB,QAAA,OAAO,GAA2B;IAC7C,kBAAkB,EAAE,IAAI;IACxB,qBAAqB,EAAE,OAAO;IAC9B,kBAAkB,EAAE,IAAI;IACxB,YAAY,EAAE,IAAI;CACnB,CAAA;AAEY,QAAA,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,eAAO,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encode = exports.decode = void 0;
|
|
4
|
+
const node_buffer_1 = require("node:buffer");
|
|
5
|
+
function decode(buffer) {
|
|
6
|
+
const text = buffer.toString();
|
|
7
|
+
return JSON.parse(text);
|
|
8
|
+
}
|
|
9
|
+
exports.decode = decode;
|
|
10
|
+
function encode(value) {
|
|
11
|
+
const text = JSON.stringify(value);
|
|
12
|
+
return node_buffer_1.Buffer.from(text);
|
|
13
|
+
}
|
|
14
|
+
exports.encode = encode;
|
|
15
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../source/HTTP/formats/json.ts"],"names":[],"mappings":";;;AAAA,6CAAoC;AAEpC,SAAgB,MAAM,CAAE,MAAc;IACpC,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;IAE9B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAJD,wBAIC;AAED,SAAgB,MAAM,CAAE,KAAU;IAChC,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IAElC,OAAO,oBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AAJD,wBAIC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.encode = exports.decode = void 0;
|
|
27
|
+
const msgpack = __importStar(require("msgpackr"));
|
|
28
|
+
function decode(buffer) {
|
|
29
|
+
return msgpack.decode(buffer);
|
|
30
|
+
}
|
|
31
|
+
exports.decode = decode;
|
|
32
|
+
function encode(value) {
|
|
33
|
+
return msgpack.encode(value);
|
|
34
|
+
}
|
|
35
|
+
exports.encode = encode;
|
|
36
|
+
//# sourceMappingURL=msgpack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgpack.js","sourceRoot":"","sources":["../../../source/HTTP/formats/msgpack.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,kDAAmC;AAEnC,SAAgB,MAAM,CAAE,MAAc;IACpC,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC/B,CAAC;AAFD,wBAEC;AAED,SAAgB,MAAM,CAAE,KAAU;IAChC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AAC9B,CAAC;AAFD,wBAEC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encode = exports.decode = void 0;
|
|
4
|
+
const node_buffer_1 = require("node:buffer");
|
|
5
|
+
function decode(buffer) {
|
|
6
|
+
return buffer.toString();
|
|
7
|
+
}
|
|
8
|
+
exports.decode = decode;
|
|
9
|
+
function encode(value) {
|
|
10
|
+
return node_buffer_1.Buffer.from(value.toString());
|
|
11
|
+
}
|
|
12
|
+
exports.encode = encode;
|
|
13
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../source/HTTP/formats/text.ts"],"names":[],"mappings":";;;AAAA,6CAAoC;AAEpC,SAAgB,MAAM,CAAE,MAAc;IACpC,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAA;AAC1B,CAAC;AAFD,wBAEC;AAED,SAAgB,MAAM,CAAE,KAAU;IAChC,OAAO,oBAAM,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;AACtC,CAAC;AAFD,wBAEC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.encode = exports.decode = void 0;
|
|
27
|
+
const node_buffer_1 = require("node:buffer");
|
|
28
|
+
const yaml = __importStar(require("js-yaml"));
|
|
29
|
+
function decode(buffer) {
|
|
30
|
+
const text = buffer.toString();
|
|
31
|
+
return yaml.load(text);
|
|
32
|
+
}
|
|
33
|
+
exports.decode = decode;
|
|
34
|
+
function encode(value) {
|
|
35
|
+
const text = yaml.dump(value);
|
|
36
|
+
return node_buffer_1.Buffer.from(text);
|
|
37
|
+
}
|
|
38
|
+
exports.encode = encode;
|
|
39
|
+
//# sourceMappingURL=yaml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"yaml.js","sourceRoot":"","sources":["../../../source/HTTP/formats/yaml.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAoC;AACpC,8CAA+B;AAE/B,SAAgB,MAAM,CAAE,MAAc;IACpC,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAA;IAE9B,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC;AAJD,wBAIC;AAED,SAAgB,MAAM,CAAE,KAAU;IAChC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAE7B,OAAO,oBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC1B,CAAC;AAJD,wBAIC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Server"), exports);
|
|
18
|
+
__exportStar(require("./messages"), exports);
|
|
19
|
+
__exportStar(require("./exceptions"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/HTTP/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,6CAA0B;AAC1B,+CAA4B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { type IncomingHttpHeaders, type OutgoingHttpHeaders } from 'node:http';
|
|
3
|
+
import { type Request, type Response } from 'express';
|
|
4
|
+
export declare function write(request: Request, response: Response, body: any): void;
|
|
5
|
+
export declare function read(request: Request): Promise<any>;
|
|
6
|
+
interface Message {
|
|
7
|
+
body: any;
|
|
8
|
+
}
|
|
9
|
+
export interface IncomingMessage extends Message {
|
|
10
|
+
method: string;
|
|
11
|
+
path: string;
|
|
12
|
+
headers: IncomingHttpHeaders;
|
|
13
|
+
query: Query;
|
|
14
|
+
}
|
|
15
|
+
export interface OutgoingMessage {
|
|
16
|
+
status?: number;
|
|
17
|
+
headers?: OutgoingHttpHeaders;
|
|
18
|
+
body?: any;
|
|
19
|
+
}
|
|
20
|
+
export interface Query {
|
|
21
|
+
id?: string;
|
|
22
|
+
criteria?: string;
|
|
23
|
+
sort?: string;
|
|
24
|
+
omit?: string;
|
|
25
|
+
limit?: string;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.read = exports.write = void 0;
|
|
7
|
+
const negotiator_1 = __importDefault(require("negotiator"));
|
|
8
|
+
const generic_1 = require("@toa.io/generic");
|
|
9
|
+
const formats_1 = require("./formats");
|
|
10
|
+
const exceptions_1 = require("./exceptions");
|
|
11
|
+
function write(request, response, body) {
|
|
12
|
+
const buf = format(body, request, response);
|
|
13
|
+
response.send(buf);
|
|
14
|
+
}
|
|
15
|
+
exports.write = write;
|
|
16
|
+
async function read(request) {
|
|
17
|
+
const type = request.headers['content-type'];
|
|
18
|
+
if (type === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (!(type in formats_1.formats))
|
|
21
|
+
throw new exceptions_1.UnsupportedMediaType();
|
|
22
|
+
const format = formats_1.formats[type];
|
|
23
|
+
const buf = await (0, generic_1.buffer)(request);
|
|
24
|
+
try {
|
|
25
|
+
return format.decode(buf);
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
throw new exceptions_1.BadRequest();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.read = read;
|
|
32
|
+
function format(body, request, response) {
|
|
33
|
+
if (body === undefined || body?.length === 0)
|
|
34
|
+
return;
|
|
35
|
+
const type = negotiate(request);
|
|
36
|
+
const format = formats_1.formats[type];
|
|
37
|
+
const buf = format.encode(body);
|
|
38
|
+
// content-length and etag are set by Express
|
|
39
|
+
response.set('content-type', type);
|
|
40
|
+
return buf;
|
|
41
|
+
}
|
|
42
|
+
function negotiate(request) {
|
|
43
|
+
const negotiator = new negotiator_1.default(request);
|
|
44
|
+
const mediaType = negotiator.mediaType(formats_1.types);
|
|
45
|
+
if (mediaType === undefined)
|
|
46
|
+
throw new exceptions_1.NotAcceptable();
|
|
47
|
+
return mediaType;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../source/HTTP/messages.ts"],"names":[],"mappings":";;;;;;AAEA,4DAAmC;AACnC,6CAAwC;AACxC,uCAA0C;AAC1C,6CAA8E;AAE9E,SAAgB,KAAK,CAAE,OAAgB,EAAE,QAAkB,EAAE,IAAS;IACpE,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAE3C,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACpB,CAAC;AAJD,sBAIC;AAEM,KAAK,UAAU,IAAI,CAAE,OAAgB;IAC1C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;IAE5C,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,SAAS,CAAA;IAExC,IAAI,CAAC,CAAC,IAAI,IAAI,iBAAO,CAAC;QAAE,MAAM,IAAI,iCAAoB,EAAE,CAAA;IAExD,MAAM,MAAM,GAAG,iBAAO,CAAC,IAAI,CAAC,CAAA;IAE5B,MAAM,GAAG,GAAG,MAAM,IAAA,gBAAM,EAAC,OAAO,CAAC,CAAA;IAEjC,IAAI;QACF,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;KAC1B;IAAC,MAAM;QACN,MAAM,IAAI,uBAAU,EAAE,CAAA;KACvB;AACH,CAAC;AAhBD,oBAgBC;AAED,SAAS,MAAM,CAAE,IAAS,EAAE,OAAgB,EAAE,QAAkB;IAC9D,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,EAAE,MAAM,KAAK,CAAC;QAAE,OAAM;IAEpD,MAAM,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;IAC/B,MAAM,MAAM,GAAG,iBAAO,CAAC,IAAI,CAAC,CAAA;IAC5B,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAE/B,6CAA6C;IAC7C,QAAQ,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;IAElC,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,SAAS,SAAS,CAAE,OAAgB;IAClC,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC,OAAO,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC,eAAK,CAAC,CAAA;IAE7C,IAAI,SAAS,KAAK,SAAS;QAAE,MAAM,IAAI,0BAAa,EAAE,CAAA;IAEtD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Parameter } from './RTD';
|
|
2
|
+
import type * as http from './HTTP';
|
|
3
|
+
import type * as syntax from './RTD/syntax';
|
|
4
|
+
import type * as core from '@toa.io/core';
|
|
5
|
+
export declare abstract class Mapping {
|
|
6
|
+
static create(verb: string, query?: syntax.Query): Mapping;
|
|
7
|
+
abstract fit(input: any, qs: http.Query, parameters: Parameter[]): core.Request;
|
|
8
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mapping = void 0;
|
|
4
|
+
const Query_1 = require("./Query");
|
|
5
|
+
class Mapping {
|
|
6
|
+
static create(verb, query) {
|
|
7
|
+
if (verb === 'POST')
|
|
8
|
+
return new InputMapping();
|
|
9
|
+
if (query === undefined)
|
|
10
|
+
throw new Error(`Query constraints must be defined for ${verb}`);
|
|
11
|
+
const q = new Query_1.Query(query);
|
|
12
|
+
return new QueryableMapping(q);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.Mapping = Mapping;
|
|
16
|
+
class QueryableMapping extends Mapping {
|
|
17
|
+
query;
|
|
18
|
+
constructor(query) {
|
|
19
|
+
super();
|
|
20
|
+
this.query = query;
|
|
21
|
+
}
|
|
22
|
+
fit(input, qs, parameters) {
|
|
23
|
+
const query = this.query.fit(qs, parameters);
|
|
24
|
+
return { input, query };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
class InputMapping extends Mapping {
|
|
28
|
+
fit(body, _, parameters) {
|
|
29
|
+
const input = { ...body };
|
|
30
|
+
for (const parameter of parameters)
|
|
31
|
+
input[parameter.name] = parameter.value;
|
|
32
|
+
return { input };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=Mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Mapping.js","sourceRoot":"","sources":["../source/Mapping.ts"],"names":[],"mappings":";;;AACA,mCAA+B;AAK/B,MAAsB,OAAO;IACpB,MAAM,CAAC,MAAM,CAAE,IAAY,EAAE,KAAoB;QACtD,IAAI,IAAI,KAAK,MAAM;YACjB,OAAO,IAAI,YAAY,EAAE,CAAA;QAE3B,IAAI,KAAK,KAAK,SAAS;YACrB,MAAM,IAAI,KAAK,CAAC,yCAAyC,IAAI,EAAE,CAAC,CAAA;QAElE,MAAM,CAAC,GAAG,IAAI,aAAK,CAAC,KAAK,CAAC,CAAA;QAE1B,OAAO,IAAI,gBAAgB,CAAC,CAAC,CAAC,CAAA;IAChC,CAAC;CAGF;AAdD,0BAcC;AAED,MAAM,gBAAiB,SAAQ,OAAO;IACnB,KAAK,CAAO;IAE7B,YAAoB,KAAY;QAC9B,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;IACpB,CAAC;IAEM,GAAG,CAAE,KAAU,EAAE,EAAc,EAAE,UAAuB;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,UAAU,CAAC,CAAA;QAE5C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;IACzB,CAAC;CACF;AAED,MAAM,YAAa,SAAQ,OAAO;IACzB,GAAG,CAAE,IAAS,EAAE,CAAU,EAAE,UAAuB;QACxD,MAAM,KAAK,GAAG,EAAE,GAAG,IAAI,EAAE,CAAA;QAEzB,KAAK,MAAM,SAAS,IAAI,UAAU;YAChC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,KAAK,CAAA;QAEzC,OAAO,EAAE,KAAK,EAAE,CAAA;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as http from './HTTP';
|
|
2
|
+
import { type Parameter } from './RTD';
|
|
3
|
+
import type * as syntax from './RTD/syntax';
|
|
4
|
+
import type * as core from '@toa.io/core';
|
|
5
|
+
export declare class Query {
|
|
6
|
+
private readonly query;
|
|
7
|
+
private readonly closed;
|
|
8
|
+
constructor(query: syntax.Query);
|
|
9
|
+
fit(query: http.Query, parameters: Parameter[]): core.Query;
|
|
10
|
+
private fitCriteria;
|
|
11
|
+
private fitRanges;
|
|
12
|
+
private fitSort;
|
|
13
|
+
}
|