@toa.io/extensions.exposition 1.0.0-alpha.2 → 1.0.0-alpha.4
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/identity.bans/manifest.toa.yaml +1 -0
- package/components/identity.basic/manifest.toa.yaml +1 -0
- package/components/identity.basic/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.federation/manifest.toa.yaml +13 -0
- package/components/identity.federation/operations/authenticate.js +4 -4
- package/components/identity.federation/operations/authenticate.js.map +1 -1
- package/components/identity.federation/operations/create.js +4 -4
- package/components/identity.federation/operations/create.js.map +1 -1
- package/components/identity.federation/operations/{assertions-as-values.cjs → lib/assertions-as-values.js} +1 -1
- package/components/identity.federation/operations/lib/assertions-as-values.js.map +1 -0
- package/components/identity.federation/operations/{jwt.d.cts → lib/jwt.d.ts} +5 -4
- package/components/identity.federation/operations/{jwt.cjs → lib/jwt.js} +35 -11
- package/components/identity.federation/operations/lib/jwt.js.map +1 -0
- package/components/identity.federation/operations/schemas.d.ts +16 -0
- package/components/identity.federation/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.federation/operations/types.d.ts +1 -1
- package/components/identity.federation/source/authenticate.ts +2 -2
- package/components/identity.federation/source/create.ts +2 -2
- package/components/identity.federation/source/{assertions-as-values.cts → lib/assertions-as-values.ts} +1 -2
- package/components/identity.federation/source/lib/jwt.test.ts +56 -0
- package/components/identity.federation/source/{jwt.cts → lib/jwt.ts} +57 -29
- package/components/identity.federation/source/schemas.ts +16 -0
- package/components/identity.federation/source/types.ts +1 -1
- package/components/identity.roles/manifest.toa.yaml +1 -0
- package/components/identity.roles/operations/tsconfig.tsbuildinfo +1 -1
- package/components/identity.tokens/manifest.toa.yaml +1 -0
- package/components/identity.tokens/operations/tsconfig.tsbuildinfo +1 -1
- package/components/octets.storage/manifest.toa.yaml +1 -0
- package/components/octets.storage/operations/store.js +1 -1
- package/documentation/components.md +12 -5
- package/documentation/identity.md +7 -0
- package/documentation/octets.md +12 -0
- package/documentation/query.md +45 -2
- package/features/body.feature +1 -1
- package/features/errors.feature +1 -1
- package/features/etag.feature +86 -0
- package/features/identity.federation.feature +31 -1
- package/features/octets.entries.feature +1 -1
- package/features/octets.workflows.feature +38 -0
- package/features/steps/Gateway.ts +3 -0
- package/features/steps/IdP.ts +29 -0
- package/features/steps/components/echo/manifest.toa.yaml +1 -0
- package/features/steps/components/greeter/manifest.toa.yaml +1 -0
- package/features/steps/components/octets.tester/manifest.toa.yaml +1 -0
- package/features/steps/components/pots/manifest.toa.yaml +10 -3
- package/features/steps/components/sequences/manifest.toa.yaml +1 -0
- package/features/timing.feature +43 -0
- package/package.json +7 -10
- package/readme.md +7 -6
- package/schemas/annotation.cos.yaml +1 -0
- package/schemas/octets/workflow.cos.yaml +12 -0
- package/schemas/querystring.cos.yaml +1 -0
- package/source/Annotation.ts +1 -0
- package/source/Directive.test.ts +3 -3
- package/source/Directive.ts +11 -11
- package/source/Endpoint.ts +18 -4
- package/source/Factory.ts +8 -4
- package/source/Gateway.ts +55 -42
- package/source/HTTP/Context.ts +67 -0
- package/source/HTTP/Server.test.ts +1 -1
- package/source/HTTP/Server.ts +60 -95
- package/source/HTTP/Timing.ts +40 -0
- package/source/HTTP/index.ts +1 -0
- package/source/HTTP/messages.test.ts +27 -8
- package/source/HTTP/messages.ts +32 -48
- package/source/Mapping.ts +7 -8
- package/source/deployment.ts +6 -0
- package/source/directives/auth/Anonymous.ts +3 -2
- package/source/directives/auth/Authorization.ts +5 -3
- package/source/directives/auth/Incept.ts +11 -6
- package/source/directives/auth/Role.ts +5 -3
- package/source/directives/auth/Scheme.ts +2 -2
- package/source/directives/cache/Cache.ts +2 -2
- package/source/directives/cache/Control.ts +5 -5
- package/source/directives/cache/types.ts +1 -1
- package/source/directives/cors/CORS.ts +5 -3
- package/source/directives/octets/Context.ts +1 -1
- package/source/directives/octets/Delete.ts +21 -11
- package/source/directives/octets/Fetch.ts +29 -14
- package/source/directives/octets/List.ts +14 -6
- package/source/directives/octets/Octets.ts +7 -3
- package/source/directives/octets/Permute.ts +12 -6
- package/source/directives/octets/Store.ts +32 -16
- package/source/directives/octets/Workflow.ts +41 -0
- package/source/directives/octets/schemas.test.ts +21 -0
- package/source/directives/octets/schemas.ts +2 -0
- package/source/directives/octets/{workflow → workflows}/Execution.ts +0 -2
- package/source/directives/octets/{workflow → workflows}/Workflow.ts +2 -2
- package/source/directives/vary/Vary.ts +1 -1
- package/source/directives/vary/embeddings/Header.ts +1 -1
- package/source/directives/vary/embeddings/Language.ts +1 -1
- package/source/io.ts +2 -2
- package/transpiled/Annotation.d.ts +1 -0
- package/transpiled/Directive.d.ts +6 -6
- package/transpiled/Directive.js +8 -8
- package/transpiled/Directive.js.map +1 -1
- package/transpiled/Endpoint.d.ts +3 -3
- package/transpiled/Endpoint.js +34 -1
- package/transpiled/Endpoint.js.map +1 -1
- package/transpiled/Factory.js +4 -2
- package/transpiled/Factory.js.map +1 -1
- package/transpiled/Gateway.d.ts +5 -6
- package/transpiled/Gateway.js +38 -32
- package/transpiled/Gateway.js.map +1 -1
- package/transpiled/HTTP/Context.d.ts +24 -0
- package/transpiled/HTTP/Context.js +47 -0
- package/transpiled/HTTP/Context.js.map +1 -0
- package/transpiled/HTTP/Server.d.ts +8 -7
- package/transpiled/HTTP/Server.js +68 -76
- package/transpiled/HTTP/Server.js.map +1 -1
- package/transpiled/HTTP/Timing.d.ts +10 -0
- package/transpiled/HTTP/Timing.js +29 -0
- package/transpiled/HTTP/Timing.js.map +1 -0
- package/transpiled/HTTP/index.d.ts +1 -0
- package/transpiled/HTTP/index.js +1 -0
- package/transpiled/HTTP/index.js.map +1 -1
- package/transpiled/HTTP/messages.d.ts +7 -21
- package/transpiled/HTTP/messages.js +24 -26
- package/transpiled/HTTP/messages.js.map +1 -1
- package/transpiled/Mapping.js +7 -7
- package/transpiled/Mapping.js.map +1 -1
- package/transpiled/deployment.js +5 -0
- package/transpiled/deployment.js.map +1 -1
- package/transpiled/directives/auth/Anonymous.js +3 -4
- package/transpiled/directives/auth/Anonymous.js.map +1 -1
- package/transpiled/directives/auth/Authorization.js +1 -1
- package/transpiled/directives/auth/Authorization.js.map +1 -1
- package/transpiled/directives/auth/Incept.d.ts +1 -1
- package/transpiled/directives/auth/Incept.js +11 -6
- package/transpiled/directives/auth/Incept.js.map +1 -1
- package/transpiled/directives/auth/Role.js +5 -3
- package/transpiled/directives/auth/Role.js.map +1 -1
- package/transpiled/directives/auth/Scheme.js +2 -2
- package/transpiled/directives/auth/Scheme.js.map +1 -1
- package/transpiled/directives/cache/Cache.d.ts +1 -1
- package/transpiled/directives/cache/Cache.js +2 -2
- package/transpiled/directives/cache/Cache.js.map +1 -1
- package/transpiled/directives/cache/Control.d.ts +3 -3
- package/transpiled/directives/cache/Control.js +3 -3
- package/transpiled/directives/cache/Control.js.map +1 -1
- package/transpiled/directives/cache/types.d.ts +1 -1
- package/transpiled/directives/cors/CORS.js +4 -3
- package/transpiled/directives/cors/CORS.js.map +1 -1
- package/transpiled/directives/octets/Context.d.ts +1 -1
- package/transpiled/directives/octets/Context.js.map +1 -1
- package/transpiled/directives/octets/Delete.d.ts +2 -2
- package/transpiled/directives/octets/Delete.js +21 -11
- package/transpiled/directives/octets/Delete.js.map +1 -1
- package/transpiled/directives/octets/Fetch.d.ts +1 -1
- package/transpiled/directives/octets/Fetch.js +28 -14
- package/transpiled/directives/octets/Fetch.js.map +1 -1
- package/transpiled/directives/octets/List.d.ts +1 -1
- package/transpiled/directives/octets/List.js +13 -6
- package/transpiled/directives/octets/List.js.map +1 -1
- package/transpiled/directives/octets/Octets.js +7 -3
- package/transpiled/directives/octets/Octets.js.map +1 -1
- package/transpiled/directives/octets/Permute.d.ts +1 -1
- package/transpiled/directives/octets/Permute.js +11 -6
- package/transpiled/directives/octets/Permute.js.map +1 -1
- package/transpiled/directives/octets/Store.d.ts +3 -2
- package/transpiled/directives/octets/Store.js +19 -11
- package/transpiled/directives/octets/Store.js.map +1 -1
- package/transpiled/directives/octets/Workflow.d.ts +14 -0
- package/transpiled/directives/octets/Workflow.js +52 -0
- package/transpiled/directives/octets/Workflow.js.map +1 -0
- package/transpiled/directives/octets/schemas.d.ts +2 -0
- package/transpiled/directives/octets/schemas.js +2 -1
- package/transpiled/directives/octets/schemas.js.map +1 -1
- package/transpiled/directives/octets/{workflow → workflows}/Execution.js +0 -1
- package/transpiled/directives/octets/workflows/Execution.js.map +1 -0
- package/transpiled/directives/octets/{workflow → workflows}/Workflow.d.ts +1 -1
- package/transpiled/directives/octets/{workflow → workflows}/Workflow.js +2 -2
- package/transpiled/directives/octets/workflows/Workflow.js.map +1 -0
- package/transpiled/directives/octets/workflows/index.js.map +1 -0
- package/transpiled/directives/vary/Vary.js +1 -1
- package/transpiled/directives/vary/embeddings/Header.js +1 -1
- package/transpiled/directives/vary/embeddings/Header.js.map +1 -1
- package/transpiled/directives/vary/embeddings/Language.js +1 -1
- package/transpiled/directives/vary/embeddings/Language.js.map +1 -1
- package/transpiled/io.d.ts +2 -2
- package/transpiled/tsconfig.tsbuildinfo +1 -1
- package/components/identity.federation/operations/assertions-as-values.cjs.map +0 -1
- package/components/identity.federation/operations/jwt.cjs.map +0 -1
- package/source/HTTP/Server.fixtures.ts +0 -40
- package/transpiled/HTTP/Server.fixtures.d.ts +0 -10
- package/transpiled/HTTP/Server.fixtures.js +0 -31
- package/transpiled/HTTP/Server.fixtures.js.map +0 -1
- package/transpiled/directives/octets/workflow/Execution.js.map +0 -1
- package/transpiled/directives/octets/workflow/Workflow.js.map +0 -1
- package/transpiled/directives/octets/workflow/index.js.map +0 -1
- /package/components/identity.federation/operations/{assertions-as-values.d.cts → lib/assertions-as-values.d.ts} +0 -0
- /package/source/directives/octets/{workflow → workflows}/index.ts +0 -0
- /package/transpiled/directives/octets/{workflow → workflows}/Execution.d.ts +0 -0
- /package/transpiled/directives/octets/{workflow → workflows}/index.d.ts +0 -0
- /package/transpiled/directives/octets/{workflow → workflows}/index.js +0 -0
|
@@ -17,7 +17,7 @@ export class Language implements Embedding {
|
|
|
17
17
|
assert.ok(properties.languages.length > 0,
|
|
18
18
|
'List of supported languages is empty.')
|
|
19
19
|
|
|
20
|
-
const negotiator = new Negotiator(input)
|
|
20
|
+
const negotiator = new Negotiator(input.request)
|
|
21
21
|
const language = negotiator.language(properties.languages) ?? properties.languages[0]
|
|
22
22
|
|
|
23
23
|
input.pipelines.response.push((response) => {
|
package/source/io.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Context, OutgoingMessage } from './HTTP';
|
|
2
2
|
import type { Remotes } from './Remotes';
|
|
3
3
|
import type { Output } from './io';
|
|
4
4
|
import type * as RTD from './RTD';
|
|
5
5
|
export declare class Directives implements RTD.Directives<Directives> {
|
|
6
6
|
private readonly sets;
|
|
7
7
|
constructor(sets: DirectiveSet[]);
|
|
8
|
-
preflight(
|
|
9
|
-
settle(
|
|
8
|
+
preflight(context: Context, parameters: RTD.Parameter[]): Promise<Output>;
|
|
9
|
+
settle(context: Context, response: OutgoingMessage): Promise<void>;
|
|
10
10
|
merge(directives: Directives): void;
|
|
11
11
|
}
|
|
12
12
|
export declare class DirectivesFactory implements RTD.DirectivesFactory<Directives> {
|
|
13
|
-
private readonly
|
|
13
|
+
private readonly remotes;
|
|
14
14
|
private readonly families;
|
|
15
15
|
private readonly mandatory;
|
|
16
16
|
constructor(families: Family[], remotes: Remotes);
|
|
@@ -21,8 +21,8 @@ export interface Family<TDirective = any, TExtension = any> {
|
|
|
21
21
|
readonly name: string;
|
|
22
22
|
readonly mandatory: boolean;
|
|
23
23
|
create: (name: string, value: any, remotes: Remotes) => TDirective;
|
|
24
|
-
preflight?: (directives: TDirective[], request:
|
|
25
|
-
settle?: (directives: TDirective[], request:
|
|
24
|
+
preflight?: (directives: TDirective[], request: Context & TExtension, parameters: RTD.Parameter[]) => Output | Promise<Output>;
|
|
25
|
+
settle?: (directives: TDirective[], request: Context & TExtension, response: OutgoingMessage) => void | Promise<void>;
|
|
26
26
|
}
|
|
27
27
|
interface DirectiveSet {
|
|
28
28
|
family: Family;
|
package/transpiled/Directive.js
CHANGED
|
@@ -6,22 +6,22 @@ class Directives {
|
|
|
6
6
|
constructor(sets) {
|
|
7
7
|
this.sets = sets;
|
|
8
8
|
}
|
|
9
|
-
async preflight(
|
|
9
|
+
async preflight(context, parameters) {
|
|
10
10
|
for (const set of this.sets) {
|
|
11
11
|
if (set.family.preflight === undefined)
|
|
12
12
|
continue;
|
|
13
|
-
const output = await set.family.preflight(set.directives,
|
|
13
|
+
const output = await set.family.preflight(set.directives, context, parameters);
|
|
14
14
|
if (output !== null) {
|
|
15
|
-
await this.settle(
|
|
15
|
+
await this.settle(context, output);
|
|
16
16
|
return output;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
|
-
async settle(
|
|
21
|
+
async settle(context, response) {
|
|
22
22
|
for (const set of this.sets)
|
|
23
23
|
if (set.family.settle !== undefined)
|
|
24
|
-
await set.family.settle(set.directives,
|
|
24
|
+
await set.family.settle(set.directives, context, response);
|
|
25
25
|
}
|
|
26
26
|
merge(directives) {
|
|
27
27
|
this.sets.push(...directives.sets);
|
|
@@ -29,7 +29,7 @@ class Directives {
|
|
|
29
29
|
}
|
|
30
30
|
exports.Directives = Directives;
|
|
31
31
|
class DirectivesFactory {
|
|
32
|
-
|
|
32
|
+
remotes;
|
|
33
33
|
families = {};
|
|
34
34
|
mandatory = [];
|
|
35
35
|
constructor(families, remotes) {
|
|
@@ -38,7 +38,7 @@ class DirectivesFactory {
|
|
|
38
38
|
if (family.mandatory)
|
|
39
39
|
this.mandatory.push(family.name);
|
|
40
40
|
}
|
|
41
|
-
this.
|
|
41
|
+
this.remotes = remotes;
|
|
42
42
|
}
|
|
43
43
|
create(declarations) {
|
|
44
44
|
const groups = {};
|
|
@@ -48,7 +48,7 @@ class DirectivesFactory {
|
|
|
48
48
|
const family = this.families[declaration.family];
|
|
49
49
|
if (family === undefined)
|
|
50
50
|
throw new Error(`Directive family '${declaration.family}' is not found.`);
|
|
51
|
-
const directive = family.create(declaration.name, declaration.value, this.
|
|
51
|
+
const directive = family.create(declaration.name, declaration.value, this.remotes);
|
|
52
52
|
groups[family.name] ??= [];
|
|
53
53
|
groups[family.name].push(directive);
|
|
54
54
|
mandatory.delete(family.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Directive.js","sourceRoot":"","sources":["../source/Directive.ts"],"names":[],"mappings":";;;AAKA,MAAa,UAAU;IACJ,IAAI,CAAgB;IAErC,YAAoB,IAAoB;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,KAAK,CAAC,SAAS,CAAE,
|
|
1
|
+
{"version":3,"file":"Directive.js","sourceRoot":"","sources":["../source/Directive.ts"],"names":[],"mappings":";;;AAKA,MAAa,UAAU;IACJ,IAAI,CAAgB;IAErC,YAAoB,IAAoB;QACtC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAEM,KAAK,CAAC,SAAS,CAAE,OAAgB,EAAE,UAA2B;QACnE,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YAC5B,IAAI,GAAG,CAAC,MAAM,CAAC,SAAS,KAAK,SAAS;gBACpC,SAAQ;YAEV,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;YAE9E,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBACpB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;gBAElC,OAAO,MAAM,CAAA;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,KAAK,CAAC,MAAM,CAAE,OAAgB,EAAE,QAAyB;QAC9D,KAAK,MAAM,GAAG,IAAI,IAAI,CAA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,EAAE,aAAa,CAAC;CAC1B,CAAC,CAAA"}
|
package/transpiled/Endpoint.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { type Component
|
|
1
|
+
import { type Component } from '@toa.io/core';
|
|
2
2
|
import { type Remotes } from './Remotes';
|
|
3
3
|
import { Mapping } from './Mapping';
|
|
4
4
|
import { type Context } from './Context';
|
|
5
|
+
import * as http from './HTTP';
|
|
5
6
|
import type * as RTD from './RTD';
|
|
6
|
-
import type * as http from './HTTP';
|
|
7
7
|
export declare class Endpoint implements RTD.Endpoint<Endpoint> {
|
|
8
8
|
private readonly endpoint;
|
|
9
9
|
private readonly mapping;
|
|
10
10
|
private readonly discovery;
|
|
11
11
|
private remote;
|
|
12
12
|
constructor(endpoint: string, mapping: Mapping, discovery: Promise<Component>);
|
|
13
|
-
call(body: any, query: http.Query, parameters: RTD.Parameter[]): Promise<
|
|
13
|
+
call(body: any, query: http.Query, parameters: RTD.Parameter[]): Promise<http.OutgoingMessage>;
|
|
14
14
|
close(): Promise<void>;
|
|
15
15
|
}
|
|
16
16
|
export declare class EndpointsFactory implements RTD.EndpointsFactory<Endpoint> {
|
package/transpiled/Endpoint.js
CHANGED
|
@@ -1,7 +1,31 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.EndpointsFactory = exports.Endpoint = void 0;
|
|
4
27
|
const Mapping_1 = require("./Mapping");
|
|
28
|
+
const http = __importStar(require("./HTTP"));
|
|
5
29
|
class Endpoint {
|
|
6
30
|
endpoint;
|
|
7
31
|
mapping;
|
|
@@ -15,7 +39,16 @@ class Endpoint {
|
|
|
15
39
|
async call(body, query, parameters) {
|
|
16
40
|
const request = this.mapping.fit(body, query, parameters);
|
|
17
41
|
this.remote ??= await this.discovery;
|
|
18
|
-
|
|
42
|
+
const reply = await this.remote.invoke(this.endpoint, request);
|
|
43
|
+
if (reply instanceof Error)
|
|
44
|
+
throw new http.Conflict(reply);
|
|
45
|
+
const message = { body: reply };
|
|
46
|
+
if (typeof reply === 'object' && reply !== null && '_version' in reply) {
|
|
47
|
+
message.headers ??= new Headers();
|
|
48
|
+
message.headers.set('etag', `"${reply._version.toString()}"`);
|
|
49
|
+
delete reply._version;
|
|
50
|
+
}
|
|
51
|
+
return message;
|
|
19
52
|
}
|
|
20
53
|
async close() {
|
|
21
54
|
this.remote ??= await this.discovery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Endpoint.js","sourceRoot":"","sources":["../source/Endpoint.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Endpoint.js","sourceRoot":"","sources":["../source/Endpoint.ts"],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POSITION_TRACE === '1';
|
|
49
50
|
const broadcast = this.boot.bindings.broadcast(CHANNEL);
|
|
50
|
-
const server = HTTP_1.Server.create({ methods: RTD_1.syntax.verbs, debug });
|
|
51
|
+
const server = HTTP_1.Server.create({ methods: RTD_1.syntax.verbs, debug, trace });
|
|
51
52
|
const remotes = new Remotes_1.Remotes(this.boot);
|
|
52
53
|
const node = root.resolve();
|
|
53
54
|
const methods = new Endpoint_1.EndpointsFactory(remotes);
|
|
@@ -55,9 +56,10 @@ class Factory {
|
|
|
55
56
|
const interception = new Interception_1.Interception(directives_1.interceptors);
|
|
56
57
|
const tree = new RTD_1.Tree(node, methods, directives);
|
|
57
58
|
const composition = new Composition_1.Composition(this.boot);
|
|
58
|
-
const gateway = new Gateway_1.Gateway(broadcast,
|
|
59
|
+
const gateway = new Gateway_1.Gateway(broadcast, tree, interception);
|
|
59
60
|
gateway.depends(remotes);
|
|
60
61
|
gateway.depends(composition);
|
|
62
|
+
server.attach(gateway.process.bind(gateway));
|
|
61
63
|
server.depends(gateway);
|
|
62
64
|
return server;
|
|
63
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAiC;AACjC,uCAAmC;AACnC,uCAAmC;AACnC,+BAAoC;AACpC,iCAA+B;AAC/B,yCAA4D;AAC5D,6CAAqD;AACrD,2CAAgE;AAChE,+CAA2C;AAC3C,6CAA8B;AAC9B,iDAA6C;
|
|
1
|
+
{"version":3,"file":"Factory.js","sourceRoot":"","sources":["../source/Factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAiC;AACjC,uCAAmC;AACnC,uCAAmC;AACnC,+BAAoC;AACpC,iCAA+B;AAC/B,yCAA4D;AAC5D,6CAAqD;AACrD,2CAAgE;AAChE,+CAA2C;AAC3C,6CAA8B;AAC9B,iDAA6C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,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,SAAS,EAAE,IAAI,EAAE,YAAY,CAAC,CAAA;QAE1D,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACxB,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QAE5B,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAA;QAC5C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QAEvB,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AApCD,0BAoCC;AAED,MAAM,OAAO,GAAG,YAAY,CAAA"}
|
package/transpiled/Gateway.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type bindings, Connector } from '@toa.io/core';
|
|
2
2
|
import * as http from './HTTP';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Interception } from './Interception';
|
|
4
4
|
import type { Tree } from './RTD';
|
|
5
5
|
import type { Label } from './discovery';
|
|
6
6
|
import type { Endpoint } from './Endpoint';
|
|
@@ -9,14 +9,13 @@ export declare class Gateway extends Connector {
|
|
|
9
9
|
private readonly broadcast;
|
|
10
10
|
private readonly tree;
|
|
11
11
|
private readonly interceptor;
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
constructor(broadcast: Broadcast, tree: Tree<Endpoint, Directives>, interception: Interception);
|
|
13
|
+
process(context: http.Context): Promise<http.OutgoingMessage>;
|
|
14
14
|
protected open(): Promise<void>;
|
|
15
15
|
protected dispose(): void;
|
|
16
|
-
private process;
|
|
17
16
|
private call;
|
|
17
|
+
private query;
|
|
18
18
|
private discover;
|
|
19
19
|
private merge;
|
|
20
20
|
}
|
|
21
|
-
type Broadcast = bindings.Broadcast<Label>;
|
|
22
|
-
export {};
|
|
21
|
+
export type Broadcast = bindings.Broadcast<Label>;
|
package/transpiled/Gateway.js
CHANGED
|
@@ -31,57 +31,62 @@ class Gateway extends core_1.Connector {
|
|
|
31
31
|
broadcast;
|
|
32
32
|
tree;
|
|
33
33
|
interceptor;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
constructor(broadcast, server, tree, interception) {
|
|
34
|
+
// eslint-disable-next-line max-len
|
|
35
|
+
constructor(broadcast, tree, interception) {
|
|
37
36
|
super();
|
|
38
37
|
this.broadcast = broadcast;
|
|
39
38
|
this.tree = tree;
|
|
40
39
|
this.interceptor = interception;
|
|
41
|
-
this.server = server;
|
|
42
40
|
this.depends(broadcast);
|
|
43
|
-
// this.depends(server)
|
|
44
|
-
server.attach(this.process.bind(this));
|
|
45
41
|
}
|
|
46
|
-
async
|
|
47
|
-
await this.
|
|
48
|
-
console.info('Gateway has started and is awaiting resource branches.');
|
|
49
|
-
}
|
|
50
|
-
dispose() {
|
|
51
|
-
console.info('Gateway is closed.');
|
|
52
|
-
}
|
|
53
|
-
async process(request) {
|
|
54
|
-
const interception = await this.interceptor.intercept(request);
|
|
42
|
+
async process(context) {
|
|
43
|
+
const interception = await context.timing.capture('gate:intercept', this.interceptor.intercept(context));
|
|
55
44
|
if (interception !== null)
|
|
56
45
|
return interception;
|
|
57
|
-
const match = this.tree.match(
|
|
46
|
+
const match = this.tree.match(context.url.pathname);
|
|
58
47
|
if (match === null)
|
|
59
48
|
throw new http.NotFound();
|
|
60
49
|
const { node, parameters } = match;
|
|
61
|
-
if (!(request.method in node.methods))
|
|
50
|
+
if (!(context.request.method in node.methods))
|
|
62
51
|
throw new http.MethodNotAllowed();
|
|
63
|
-
const method = node.methods[request.method];
|
|
64
|
-
const interruption = await method.directives.preflight(
|
|
65
|
-
const response = interruption ??
|
|
66
|
-
|
|
52
|
+
const method = node.methods[context.request.method];
|
|
53
|
+
const interruption = await context.timing.capture('gate:preflight', method.directives.preflight(context, parameters));
|
|
54
|
+
const response = interruption ??
|
|
55
|
+
await context.timing.capture('gate:call', this.call(method, context, parameters));
|
|
56
|
+
await context.timing.capture('gate:settle', method.directives.settle(context, response));
|
|
67
57
|
return response;
|
|
68
58
|
}
|
|
69
|
-
async
|
|
70
|
-
|
|
59
|
+
async open() {
|
|
60
|
+
await this.discover();
|
|
61
|
+
console.info('Gateway has started and is awaiting resource branches.');
|
|
62
|
+
}
|
|
63
|
+
dispose() {
|
|
64
|
+
console.info('Gateway is closed.');
|
|
65
|
+
}
|
|
66
|
+
async call(method, context, parameters) {
|
|
67
|
+
if (context.url.pathname[context.url.pathname.length - 1] !== '/')
|
|
71
68
|
throw new http.NotFound('Trailing slash is required.');
|
|
72
|
-
if (
|
|
69
|
+
if (context.encoder === null)
|
|
73
70
|
throw new http.NotAcceptable();
|
|
74
71
|
if (method.endpoint === null)
|
|
75
72
|
throw new http.MethodNotAllowed();
|
|
76
|
-
const body = await
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
.call(body, request.query, parameters)
|
|
73
|
+
const body = await context.body();
|
|
74
|
+
const query = this.query(context);
|
|
75
|
+
return await method.endpoint
|
|
76
|
+
.call(body, query, parameters)
|
|
81
77
|
.catch(exceptions_1.rethrow);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
}
|
|
79
|
+
query(context) {
|
|
80
|
+
const query = Object.fromEntries(context.url.searchParams);
|
|
81
|
+
const etag = context.request.headers['if-match'];
|
|
82
|
+
if (etag !== undefined) {
|
|
83
|
+
const match = etag.match(ETAG);
|
|
84
|
+
if (match === null)
|
|
85
|
+
throw new http.BadRequest('Invalid ETag.');
|
|
86
|
+
else
|
|
87
|
+
query.version = parseInt(match.groups.version);
|
|
88
|
+
}
|
|
89
|
+
return query;
|
|
85
90
|
}
|
|
86
91
|
async discover() {
|
|
87
92
|
await this.broadcast.receive('expose', this.merge.bind(this));
|
|
@@ -99,4 +104,5 @@ class Gateway extends core_1.Connector {
|
|
|
99
104
|
}
|
|
100
105
|
}
|
|
101
106
|
exports.Gateway = Gateway;
|
|
107
|
+
const ETAG = /^"(?<version>\d{1,32})"$/;
|
|
102
108
|
//# sourceMappingURL=Gateway.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Gateway.js","sourceRoot":"","sources":["../source/Gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAuD;AACvD,6CAA8B;AAC9B,6CAAsC;
|
|
1
|
+
{"version":3,"file":"Gateway.js","sourceRoot":"","sources":["../source/Gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAuD;AACvD,6CAA8B;AAC9B,6CAAsC;AAQtC,MAAa,OAAQ,SAAQ,gBAAS;IACnB,SAAS,CAAW;IACpB,IAAI,CAA4B;IAChC,WAAW,CAAc;IAE1C,mCAAmC;IACnC,YAAoB,SAAoB,EAAE,IAAgC,EAAE,YAA0B;QACpG,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,WAAW,GAAG,YAAY,CAAA;QAE/B,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACzB,CAAC;IAEM,KAAK,CAAC,OAAO,CAAE,OAAqB;QACzC,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAChE,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;QAEtC,IAAI,YAAY,KAAK,IAAI;YACvB,OAAO,YAAY,CAAA;QAErB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAEnD,IAAI,KAAK,KAAK,IAAI;YAChB,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAA;QAE3B,MAAM,EACJ,IAAI,EACJ,UAAU,EACX,GAAG,KAAK,CAAA;QAET,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,IAAI,IAA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C,CAAA;YAEpC,OAAO,CAAC,IAAI,CAAC,qBAAqB;gBAChC,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,oBAAoB,CAAC,CAAA;QACjE,CAAC;QAAC,OAAO,SAAS,EAAE,CAAC;YACnB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAC1B,CAAC;IACH,CAAC;CACF;AA9GD,0BA8GC;AAED,MAAM,IAAI,GAAG,0BAA0B,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Timing } from './Timing';
|
|
3
|
+
import { type Format } from './formats';
|
|
4
|
+
import type { OutgoingMessage } from './messages';
|
|
5
|
+
import type * as http from 'node:http';
|
|
6
|
+
export declare class Context {
|
|
7
|
+
readonly request: IncomingMessage;
|
|
8
|
+
readonly url: URL;
|
|
9
|
+
readonly subtype: string | null;
|
|
10
|
+
readonly encoder: Format | null;
|
|
11
|
+
readonly timing: Timing;
|
|
12
|
+
readonly pipelines: Pipelines;
|
|
13
|
+
constructor(request: IncomingMessage, trace?: boolean);
|
|
14
|
+
body<T>(): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
export interface IncomingMessage extends http.IncomingMessage {
|
|
17
|
+
url: string;
|
|
18
|
+
method: string;
|
|
19
|
+
}
|
|
20
|
+
interface Pipelines {
|
|
21
|
+
body: Array<(input: unknown) => unknown>;
|
|
22
|
+
response: Array<(output: OutgoingMessage) => void>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
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.Context = void 0;
|
|
7
|
+
const negotiator_1 = __importDefault(require("negotiator"));
|
|
8
|
+
const Timing_1 = require("./Timing");
|
|
9
|
+
const formats_1 = require("./formats");
|
|
10
|
+
const messages_1 = require("./messages");
|
|
11
|
+
class Context {
|
|
12
|
+
request;
|
|
13
|
+
url;
|
|
14
|
+
subtype = null;
|
|
15
|
+
encoder = null;
|
|
16
|
+
timing;
|
|
17
|
+
pipelines = {
|
|
18
|
+
body: [],
|
|
19
|
+
response: []
|
|
20
|
+
};
|
|
21
|
+
constructor(request, trace = false) {
|
|
22
|
+
this.request = request;
|
|
23
|
+
this.url = new URL(request.url, `https://${request.headers.host}`);
|
|
24
|
+
this.timing = new Timing_1.Timing(trace);
|
|
25
|
+
if (this.request.headers.accept !== undefined) {
|
|
26
|
+
const match = SUBTYPE.exec(this.request.headers.accept);
|
|
27
|
+
if (match !== null) {
|
|
28
|
+
const { type, subtype, suffix } = match.groups;
|
|
29
|
+
this.request.headers.accept = `${type}/${suffix}`;
|
|
30
|
+
this.subtype = subtype;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const negotiator = new negotiator_1.default(this.request);
|
|
34
|
+
const mediaType = negotiator.mediaType(formats_1.types);
|
|
35
|
+
if (mediaType !== undefined)
|
|
36
|
+
this.encoder = formats_1.formats[mediaType];
|
|
37
|
+
}
|
|
38
|
+
async body() {
|
|
39
|
+
const value = await (0, messages_1.read)(this);
|
|
40
|
+
return this.pipelines.body.length === 0
|
|
41
|
+
? value
|
|
42
|
+
: this.pipelines.body.reduce((value, transform) => transform(value), value);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.Context = Context;
|
|
46
|
+
const SUBTYPE = /^(?<type>\w{1,32})\/(vnd\.toa\.(?<subtype>\S{1,32})\+)(?<suffix>\S{1,32})$/;
|
|
47
|
+
//# sourceMappingURL=Context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.js","sourceRoot":"","sources":["../../source/HTTP/Context.ts"],"names":[],"mappings":";;;;;;AAAA,4DAAmC;AACnC,qCAAiC;AACjC,uCAAuD;AACvD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C,IAAI;QACf,MAAM,KAAK,GAAG,MAAM,IAAA,eAAI,EAAC,IAAI,CAAC,CAAA;QAE9B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;YACrC,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA;IAC/E,CAAC;CACF;AA/CD,0BA+CC;AAYD,MAAM,OAAO,GAAG,4EAA4E,CAAA"}
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { Connector } from '@toa.io/core';
|
|
2
|
-
import { type
|
|
2
|
+
import { type OutgoingMessage } from './messages';
|
|
3
|
+
import { Context } from './Context';
|
|
3
4
|
export declare class Server extends Connector {
|
|
4
|
-
private server
|
|
5
|
-
private readonly
|
|
6
|
-
private
|
|
7
|
-
private readonly requestedPort;
|
|
5
|
+
private readonly server;
|
|
6
|
+
private readonly properties;
|
|
7
|
+
private process?;
|
|
8
8
|
private constructor();
|
|
9
9
|
get port(): number;
|
|
10
10
|
static create(options?: Partial<Properties>): Server;
|
|
11
11
|
attach(process: Processing): void;
|
|
12
12
|
protected open(): Promise<void>;
|
|
13
13
|
protected close(): Promise<void>;
|
|
14
|
-
private
|
|
14
|
+
private listener;
|
|
15
15
|
private success;
|
|
16
16
|
private fail;
|
|
17
17
|
}
|
|
18
18
|
interface Properties {
|
|
19
19
|
methods: Set<string>;
|
|
20
20
|
debug: boolean;
|
|
21
|
+
trace: boolean;
|
|
21
22
|
port: number;
|
|
22
23
|
}
|
|
23
|
-
export type Processing = (input:
|
|
24
|
+
export type Processing = (input: Context) => Promise<OutgoingMessage>;
|
|
24
25
|
export {};
|