@toa.io/extensions.exposition 0.20.0-alpha.0 → 0.20.0-alpha.2

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.
Files changed (225) hide show
  1. package/components/context.toa.yaml +2 -2
  2. package/documentation/notes/sse.md +71 -0
  3. package/documentation/protocol.md +4 -1
  4. package/features/access.feature +48 -42
  5. package/features/annotation.feature +6 -4
  6. package/features/body.feature +24 -0
  7. package/features/directives.feature +2 -2
  8. package/features/dynamic.feature +11 -1
  9. package/features/errors.feature +14 -29
  10. package/features/identity.basic.feature +47 -6
  11. package/features/identity.tokens.feature +19 -16
  12. package/features/steps/Gateway.ts +26 -18
  13. package/features/steps/components/echo/manifest.toa.yaml +9 -0
  14. package/features/steps/components/echo/operations/affect.js +7 -0
  15. package/features/steps/components/echo/operations/compute.js +7 -0
  16. package/features/steps/components/greeter/manifest.toa.yaml +0 -4
  17. package/features/steps/components/greeter/operations/greet.js +1 -1
  18. package/features/steps/components/sequences/manifest.toa.yaml +10 -0
  19. package/features/steps/components/sequences/operations/numbers.js +7 -0
  20. package/features/steps/components/sequences/operations/tokens.js +16 -0
  21. package/features/streams.feature +26 -0
  22. package/package.json +7 -6
  23. package/readme.md +2 -0
  24. package/schemas/annotation.cos.yaml +5 -4
  25. package/schemas/method.cos.yaml +0 -1
  26. package/schemas/query.cos.yaml +1 -0
  27. package/source/Annotation.ts +1 -0
  28. package/source/Composition.ts +1 -2
  29. package/source/Endpoint.ts +5 -3
  30. package/source/Factory.ts +8 -10
  31. package/source/HTTP/Server.ts +1 -1
  32. package/source/HTTP/messages.ts +18 -6
  33. package/source/Mapping.ts +12 -9
  34. package/source/RTD/Node.ts +5 -5
  35. package/source/RTD/Route.ts +5 -4
  36. package/source/RTD/Tree.ts +2 -5
  37. package/source/RTD/syntax/parse.ts +1 -1
  38. package/source/Remotes.test.ts +2 -1
  39. package/source/Remotes.ts +2 -0
  40. package/source/deployment.ts +9 -2
  41. package/source/directives/dev/Family.ts +3 -1
  42. package/source/directives/dev/Throw.ts +14 -0
  43. package/source/manifest.test.ts +3 -1
  44. package/source/manifest.ts +22 -9
  45. package/transpiled/Annotation.d.ts +0 -6
  46. package/transpiled/Annotation.js +0 -3
  47. package/transpiled/Annotation.js.map +0 -1
  48. package/transpiled/Branch.d.ts +0 -7
  49. package/transpiled/Branch.js +0 -3
  50. package/transpiled/Branch.js.map +0 -1
  51. package/transpiled/Composition.d.ts +0 -14
  52. package/transpiled/Composition.js +0 -43
  53. package/transpiled/Composition.js.map +0 -1
  54. package/transpiled/Context.d.ts +0 -5
  55. package/transpiled/Context.js +0 -3
  56. package/transpiled/Context.js.map +0 -1
  57. package/transpiled/Directive.d.ts +0 -32
  58. package/transpiled/Directive.js +0 -76
  59. package/transpiled/Directive.js.map +0 -1
  60. package/transpiled/Endpoint.d.ts +0 -20
  61. package/transpiled/Endpoint.js +0 -44
  62. package/transpiled/Endpoint.js.map +0 -1
  63. package/transpiled/Factory.d.ts +0 -11
  64. package/transpiled/Factory.js +0 -67
  65. package/transpiled/Factory.js.map +0 -1
  66. package/transpiled/Gateway.d.ts +0 -19
  67. package/transpiled/Gateway.js +0 -90
  68. package/transpiled/Gateway.js.map +0 -1
  69. package/transpiled/HTTP/Server.d.ts +0 -22
  70. package/transpiled/HTTP/Server.fixtures.d.ts +0 -12
  71. package/transpiled/HTTP/Server.fixtures.js +0 -36
  72. package/transpiled/HTTP/Server.fixtures.js.map +0 -1
  73. package/transpiled/HTTP/Server.js +0 -111
  74. package/transpiled/HTTP/Server.js.map +0 -1
  75. package/transpiled/HTTP/exceptions.d.ts +0 -39
  76. package/transpiled/HTTP/exceptions.js +0 -78
  77. package/transpiled/HTTP/exceptions.js.map +0 -1
  78. package/transpiled/HTTP/formats/index.d.ts +0 -8
  79. package/transpiled/HTTP/formats/index.js +0 -38
  80. package/transpiled/HTTP/formats/index.js.map +0 -1
  81. package/transpiled/HTTP/formats/json.d.ts +0 -4
  82. package/transpiled/HTTP/formats/json.js +0 -15
  83. package/transpiled/HTTP/formats/json.js.map +0 -1
  84. package/transpiled/HTTP/formats/msgpack.d.ts +0 -4
  85. package/transpiled/HTTP/formats/msgpack.js +0 -36
  86. package/transpiled/HTTP/formats/msgpack.js.map +0 -1
  87. package/transpiled/HTTP/formats/text.d.ts +0 -4
  88. package/transpiled/HTTP/formats/text.js +0 -13
  89. package/transpiled/HTTP/formats/text.js.map +0 -1
  90. package/transpiled/HTTP/formats/yaml.d.ts +0 -4
  91. package/transpiled/HTTP/formats/yaml.js +0 -39
  92. package/transpiled/HTTP/formats/yaml.js.map +0 -1
  93. package/transpiled/HTTP/index.d.ts +0 -3
  94. package/transpiled/HTTP/index.js +0 -20
  95. package/transpiled/HTTP/index.js.map +0 -1
  96. package/transpiled/HTTP/messages.d.ts +0 -27
  97. package/transpiled/HTTP/messages.js +0 -49
  98. package/transpiled/HTTP/messages.js.map +0 -1
  99. package/transpiled/Mapping.d.ts +0 -8
  100. package/transpiled/Mapping.js +0 -35
  101. package/transpiled/Mapping.js.map +0 -1
  102. package/transpiled/Query.d.ts +0 -13
  103. package/transpiled/Query.js +0 -107
  104. package/transpiled/Query.js.map +0 -1
  105. package/transpiled/RTD/Context.d.ts +0 -11
  106. package/transpiled/RTD/Context.js +0 -3
  107. package/transpiled/RTD/Context.js.map +0 -1
  108. package/transpiled/RTD/Directives.d.ts +0 -7
  109. package/transpiled/RTD/Directives.js +0 -3
  110. package/transpiled/RTD/Directives.js.map +0 -1
  111. package/transpiled/RTD/Endpoint.d.ts +0 -9
  112. package/transpiled/RTD/Endpoint.js +0 -3
  113. package/transpiled/RTD/Endpoint.js.map +0 -1
  114. package/transpiled/RTD/Match.d.ts +0 -11
  115. package/transpiled/RTD/Match.js +0 -3
  116. package/transpiled/RTD/Match.js.map +0 -1
  117. package/transpiled/RTD/Method.d.ts +0 -9
  118. package/transpiled/RTD/Method.js +0 -16
  119. package/transpiled/RTD/Method.js.map +0 -1
  120. package/transpiled/RTD/Node.d.ts +0 -21
  121. package/transpiled/RTD/Node.js +0 -61
  122. package/transpiled/RTD/Node.js.map +0 -1
  123. package/transpiled/RTD/Route.d.ts +0 -14
  124. package/transpiled/RTD/Route.js +0 -48
  125. package/transpiled/RTD/Route.js.map +0 -1
  126. package/transpiled/RTD/Tree.d.ts +0 -14
  127. package/transpiled/RTD/Tree.js +0 -45
  128. package/transpiled/RTD/Tree.js.map +0 -1
  129. package/transpiled/RTD/factory.d.ts +0 -6
  130. package/transpiled/RTD/factory.js +0 -36
  131. package/transpiled/RTD/factory.js.map +0 -1
  132. package/transpiled/RTD/index.d.ts +0 -8
  133. package/transpiled/RTD/index.js +0 -38
  134. package/transpiled/RTD/index.js.map +0 -1
  135. package/transpiled/RTD/segment.d.ts +0 -8
  136. package/transpiled/RTD/segment.js +0 -23
  137. package/transpiled/RTD/segment.js.map +0 -1
  138. package/transpiled/RTD/syntax/index.d.ts +0 -2
  139. package/transpiled/RTD/syntax/index.js +0 -19
  140. package/transpiled/RTD/syntax/index.js.map +0 -1
  141. package/transpiled/RTD/syntax/parse.d.ts +0 -4
  142. package/transpiled/RTD/syntax/parse.js +0 -128
  143. package/transpiled/RTD/syntax/parse.js.map +0 -1
  144. package/transpiled/RTD/syntax/types.d.ts +0 -41
  145. package/transpiled/RTD/syntax/types.js +0 -5
  146. package/transpiled/RTD/syntax/types.js.map +0 -1
  147. package/transpiled/Remotes.d.ts +0 -7
  148. package/transpiled/Remotes.js +0 -19
  149. package/transpiled/Remotes.js.map +0 -1
  150. package/transpiled/Tenant.d.ts +0 -12
  151. package/transpiled/Tenant.js +0 -30
  152. package/transpiled/Tenant.js.map +0 -1
  153. package/transpiled/deployment.d.ts +0 -3
  154. package/transpiled/deployment.js +0 -61
  155. package/transpiled/deployment.js.map +0 -1
  156. package/transpiled/directives/auth/Anonymous.d.ts +0 -6
  157. package/transpiled/directives/auth/Anonymous.js +0 -17
  158. package/transpiled/directives/auth/Anonymous.js.map +0 -1
  159. package/transpiled/directives/auth/Echo.d.ts +0 -6
  160. package/transpiled/directives/auth/Echo.js +0 -13
  161. package/transpiled/directives/auth/Echo.js.map +0 -1
  162. package/transpiled/directives/auth/Family.d.ts +0 -20
  163. package/transpiled/directives/auth/Family.js +0 -125
  164. package/transpiled/directives/auth/Family.js.map +0 -1
  165. package/transpiled/directives/auth/Id.d.ts +0 -7
  166. package/transpiled/directives/auth/Id.js +0 -17
  167. package/transpiled/directives/auth/Id.js.map +0 -1
  168. package/transpiled/directives/auth/Incept.d.ts +0 -10
  169. package/transpiled/directives/auth/Incept.js +0 -59
  170. package/transpiled/directives/auth/Incept.js.map +0 -1
  171. package/transpiled/directives/auth/Role.d.ts +0 -11
  172. package/transpiled/directives/auth/Role.js +0 -44
  173. package/transpiled/directives/auth/Role.js.map +0 -1
  174. package/transpiled/directives/auth/Rule.d.ts +0 -9
  175. package/transpiled/directives/auth/Rule.js +0 -22
  176. package/transpiled/directives/auth/Rule.js.map +0 -1
  177. package/transpiled/directives/auth/Scheme.d.ts +0 -7
  178. package/transpiled/directives/auth/Scheme.js +0 -47
  179. package/transpiled/directives/auth/Scheme.js.map +0 -1
  180. package/transpiled/directives/auth/index.d.ts +0 -2
  181. package/transpiled/directives/auth/index.js +0 -7
  182. package/transpiled/directives/auth/index.js.map +0 -1
  183. package/transpiled/directives/auth/schemes.d.ts +0 -3
  184. package/transpiled/directives/auth/schemes.js +0 -9
  185. package/transpiled/directives/auth/schemes.js.map +0 -1
  186. package/transpiled/directives/auth/split.d.ts +0 -2
  187. package/transpiled/directives/auth/split.js +0 -38
  188. package/transpiled/directives/auth/split.js.map +0 -1
  189. package/transpiled/directives/auth/types.d.ts +0 -31
  190. package/transpiled/directives/auth/types.js +0 -3
  191. package/transpiled/directives/auth/types.js.map +0 -1
  192. package/transpiled/directives/dev/Family.d.ts +0 -10
  193. package/transpiled/directives/dev/Family.js +0 -25
  194. package/transpiled/directives/dev/Family.js.map +0 -1
  195. package/transpiled/directives/dev/Stub.d.ts +0 -7
  196. package/transpiled/directives/dev/Stub.js +0 -14
  197. package/transpiled/directives/dev/Stub.js.map +0 -1
  198. package/transpiled/directives/dev/index.d.ts +0 -2
  199. package/transpiled/directives/dev/index.js +0 -7
  200. package/transpiled/directives/dev/index.js.map +0 -1
  201. package/transpiled/directives/dev/types.d.ts +0 -4
  202. package/transpiled/directives/dev/types.js +0 -3
  203. package/transpiled/directives/dev/types.js.map +0 -1
  204. package/transpiled/directives/index.d.ts +0 -2
  205. package/transpiled/directives/index.js +0 -10
  206. package/transpiled/directives/index.js.map +0 -1
  207. package/transpiled/discovery.d.ts +0 -1
  208. package/transpiled/discovery.js +0 -3
  209. package/transpiled/discovery.js.map +0 -1
  210. package/transpiled/exceptions.d.ts +0 -2
  211. package/transpiled/exceptions.js +0 -39
  212. package/transpiled/exceptions.js.map +0 -1
  213. package/transpiled/index.d.ts +0 -5
  214. package/transpiled/index.js +0 -12
  215. package/transpiled/index.js.map +0 -1
  216. package/transpiled/manifest.d.ts +0 -3
  217. package/transpiled/manifest.js +0 -30
  218. package/transpiled/manifest.js.map +0 -1
  219. package/transpiled/root.d.ts +0 -2
  220. package/transpiled/root.js +0 -39
  221. package/transpiled/root.js.map +0 -1
  222. package/transpiled/schemas.d.ts +0 -3
  223. package/transpiled/schemas.js +0 -14
  224. package/transpiled/schemas.js.map +0 -1
  225. package/transpiled/tsconfig.tsbuildinfo +0 -1
@@ -1,32 +0,0 @@
1
- import { type IncomingMessage, type OutgoingMessage } from './HTTP';
2
- import { type Remotes } from './Remotes';
3
- import type * as RTD from './RTD';
4
- export declare class Directives implements RTD.Directives<Directives> {
5
- private readonly directives;
6
- constructor(directives: DirectiveSet[]);
7
- preflight(request: IncomingMessage, parameters: RTD.Parameter[]): Promise<Output>;
8
- settle(request: IncomingMessage, response: OutgoingMessage): Promise<void>;
9
- merge(directives: Directives): void;
10
- }
11
- export declare class DirectivesFactory implements RTD.DirectivesFactory<Directives> {
12
- private readonly remtoes;
13
- private readonly families;
14
- private readonly mandatory;
15
- constructor(families: Family[], remotes: Remotes);
16
- create(declarations: RTD.syntax.Directive[]): Directives;
17
- }
18
- export declare const shortcuts: RTD.syntax.Shortcuts;
19
- export interface Family<TDirective = any, TExtension = any> {
20
- readonly name: string;
21
- readonly mandatory: boolean;
22
- create: (name: string, value: any, remotes: Remotes) => TDirective;
23
- preflight: (directives: TDirective[], request: IncomingMessage & TExtension, parameters: RTD.Parameter[]) => Output | Promise<Output>;
24
- settle?: (directives: TDirective[], request: IncomingMessage & TExtension, response: OutgoingMessage) => void | Promise<void>;
25
- }
26
- interface DirectiveSet {
27
- family: Family;
28
- directives: any[];
29
- }
30
- export type Input = IncomingMessage;
31
- export type Output = OutgoingMessage | null;
32
- export {};
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shortcuts = exports.DirectivesFactory = exports.Directives = void 0;
4
- class Directives {
5
- directives;
6
- constructor(directives) {
7
- this.directives = directives;
8
- }
9
- async preflight(request, parameters) {
10
- for (const directive of this.directives) {
11
- const output = await directive.family.preflight(directive.directives, request, parameters);
12
- if (output !== null) {
13
- await this.settle(request, output);
14
- return output;
15
- }
16
- }
17
- return null;
18
- }
19
- async settle(request, response) {
20
- for (const directive of this.directives)
21
- if (directive.family.settle !== undefined)
22
- await directive.family.settle(directive.directives, request, response);
23
- }
24
- merge(directives) {
25
- this.directives.push(...directives.directives);
26
- }
27
- }
28
- exports.Directives = Directives;
29
- class DirectivesFactory {
30
- remtoes;
31
- families = {};
32
- mandatory = [];
33
- constructor(families, remotes) {
34
- for (const family of families) {
35
- this.families[family.name] = family;
36
- if (family.mandatory)
37
- this.mandatory.push(family.name);
38
- }
39
- this.remtoes = remotes;
40
- }
41
- create(declarations) {
42
- const groups = {};
43
- const mandatory = new Set(this.mandatory);
44
- declarations.sort((a, b) => (mandatory.has(b.family) ? 1 : 0) - (mandatory.has(a.family) ? 1 : 0));
45
- for (const declaration of declarations) {
46
- const family = this.families[declaration.family];
47
- if (family === undefined)
48
- throw new Error(`Directive family '${declaration.family}' not found.`);
49
- const directive = family.create(declaration.name, declaration.value, this.remtoes);
50
- groups[family.name] ??= [];
51
- groups[family.name].push(directive);
52
- mandatory.delete(family.name);
53
- }
54
- const sets = [];
55
- for (const family of mandatory)
56
- sets.push({
57
- family: this.families[family],
58
- directives: []
59
- });
60
- for (const [family, directives] of Object.entries(groups))
61
- sets.push({
62
- family: this.families[family],
63
- directives
64
- });
65
- return new Directives(sets);
66
- }
67
- }
68
- exports.DirectivesFactory = DirectivesFactory;
69
- exports.shortcuts = new Map([
70
- ['anonymous', 'auth:anonymous'],
71
- ['id', 'auth:id'],
72
- ['role', 'auth:role'],
73
- ['rule', 'auth:rule'],
74
- ['incept', 'auth:incept']
75
- ]);
76
- //# sourceMappingURL=Directive.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Directive.js","sourceRoot":"","sources":["../source/Directive.ts"],"names":[],"mappings":";;;AAIA,MAAa,UAAU;IACJ,UAAU,CAAgB;IAE3C,YAAoB,UAA0B;QAC5C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;IAC9B,CAAC;IAEM,KAAK,CAAC,SAAS,CAAE,OAAwB,EAAE,UAA2B;QAC3E,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE;YACvC,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;YAE1F,IAAI,MAAM,KAAK,IAAI,EAAE;gBACnB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;gBAElC,OAAO,MAAM,CAAA;aACd;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAEM,KAAK,CAAC,MAAM,CAAE,OAAwB,EAAE,QAAyB;QACtE,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU;YACrC,IAAI,SAAS,CAAC,MAAM,CAAC,MA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Reply } from '@toa.io/core';
2
- import { type Remotes } from './Remotes';
3
- import { Mapping } from './Mapping';
4
- import { type Context } from './Context';
5
- import type * as RTD from './RTD';
6
- import type * as http from './HTTP';
7
- export declare class Endpoint implements RTD.Endpoint<Endpoint> {
8
- private readonly endpoint;
9
- private readonly mapping;
10
- private readonly discovery;
11
- private remote;
12
- constructor(endpoint: string, mapping: Mapping, discovery: Promise<Component>);
13
- call(body: any, query: http.Query, parameters: RTD.Parameter[]): Promise<Reply>;
14
- close(): Promise<void>;
15
- }
16
- export declare class EndpointFactory implements RTD.EndpointsFactory<Endpoint> {
17
- private readonly remotes;
18
- constructor(remotes: Remotes);
19
- create(method: RTD.syntax.Method, context: Context): Endpoint;
20
- }
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EndpointFactory = exports.Endpoint = void 0;
4
- const Mapping_1 = require("./Mapping");
5
- class Endpoint {
6
- endpoint;
7
- mapping;
8
- discovery;
9
- remote = null;
10
- constructor(endpoint, mapping, discovery) {
11
- this.endpoint = endpoint;
12
- this.mapping = mapping;
13
- this.discovery = discovery;
14
- }
15
- async call(body, query, parameters) {
16
- const request = this.mapping.fit(body, query, parameters);
17
- this.remote ??= await this.discovery;
18
- return await this.remote.invoke(this.endpoint, request);
19
- }
20
- async close() {
21
- this.remote ??= await this.discovery;
22
- await this.remote.disconnect();
23
- }
24
- }
25
- exports.Endpoint = Endpoint;
26
- class EndpointFactory {
27
- remotes;
28
- constructor(remotes) {
29
- this.remotes = remotes;
30
- }
31
- create(method, context) {
32
- if (method.mapping === undefined)
33
- throw new Error('Cannot create Endpoint without mapping.');
34
- const mapping = Mapping_1.Mapping.create(method.verb, method.mapping.query);
35
- const namespace = method.mapping.namespace ?? context.extension?.namespace;
36
- const component = method.mapping.component ?? context.extension?.component;
37
- if (namespace === undefined || component === undefined)
38
- throw new Error('Annotation endpoints must be fully qualified.');
39
- const discovery = this.remotes.discover(namespace, component);
40
- return new Endpoint(method.mapping.endpoint, mapping, discovery);
41
- }
42
- }
43
- exports.EndpointFactory = EndpointFactory;
44
- //# sourceMappingURL=Endpoint.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Endpoint.js","sourceRoot":"","sources":["../source/Endpoint.ts"],"names":[],"mappings":";;;AAEA,uCAAmC;AAKnC,MAAa,QAAQ;IACF,QAAQ,CAAQ;IAChB,OAAO,CAAS;IAChB,SAAS,CAAoB;IACtC,MAAM,GAAqB,IAAI,CAAA;IAEvC,YAAoB,QAAgB,EAAE,OAAgB,EAAE,SAA6B;QACnF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAEM,KAAK,CAAC,IAAI,CAAE,IAAS,EAAE,KAAiB,EAAE,UAA2B;QAC1E,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,EAAE,UAAU,CAAC,CAAA;QAEzD,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,SAAS,CAAA;QAEpC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IACzD,CAAC;IAEM,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,SAAS,CAAA;QAEpC,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAA;IAChC,CAAC;CACF;AAzBD,4BAyBC;AAED,MAAa,eAAe;IACT,OAAO,CAAS;IAEjC,YAAoB,OAAgB;QAClC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;IAEM,MAAM,CAAE,MAAyB,EAAE,OAAgB;QACxD,IAAI,MAAM,CAAC,OAAO,KAAK,SAAS;YAC9B,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;QAE5D,MAAM,OAAO,GAAG,iBAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACjE,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,SAAS,CAAA;QAC1E,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,EAAE,SAAS,CAAA;QAE1E,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS;YACpD,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;QAElE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAE7D,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;IAClE,CAAC;CACF;AAtBD,0CAsBC"}
@@ -1,11 +0,0 @@
1
- import { syntax } from './RTD';
2
- import type { Connector, Locator, extensions } from '@toa.io/core';
3
- export declare class Factory implements extensions.Factory {
4
- private readonly boot;
5
- private readonly families;
6
- constructor(boot: Bootloader);
7
- tenant(locator: Locator, manifest: syntax.Node): Connector;
8
- service(): Connector | null;
9
- private gateway;
10
- }
11
- export type Bootloader = typeof import('@toa.io/boot');
@@ -1,67 +0,0 @@
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.Factory = void 0;
27
- const Tenant_1 = require("./Tenant");
28
- const Gateway_1 = require("./Gateway");
29
- const Remotes_1 = require("./Remotes");
30
- const RTD_1 = require("./RTD");
31
- const HTTP_1 = require("./HTTP");
32
- const Endpoint_1 = require("./Endpoint");
33
- const directives = __importStar(require("./directives"));
34
- const Directive_1 = require("./Directive");
35
- const Composition_1 = require("./Composition");
36
- const root = __importStar(require("./root"));
37
- class Factory {
38
- boot;
39
- families;
40
- constructor(boot) {
41
- this.boot = boot;
42
- this.families = directives.families;
43
- }
44
- tenant(locator, manifest) {
45
- const broadcast = this.boot.bindings.broadcast(CHANNEL, locator.id);
46
- return new Tenant_1.Tenant(broadcast, locator, manifest);
47
- }
48
- service() {
49
- return this.gateway();
50
- }
51
- gateway() {
52
- const broadcast = this.boot.bindings.broadcast(CHANNEL);
53
- const server = HTTP_1.Server.create({ methods: RTD_1.syntax.verbs });
54
- const remotes = new Remotes_1.Remotes(this.boot);
55
- const methods = new Endpoint_1.EndpointFactory(remotes);
56
- const directives = new Directive_1.DirectivesFactory(this.families, remotes);
57
- const node = root.resolve();
58
- const tree = new RTD_1.Tree(node, methods, directives);
59
- const composition = new Composition_1.Composition(this.boot);
60
- const gateway = new Gateway_1.Gateway(broadcast, server, tree);
61
- gateway.depends(composition);
62
- return gateway;
63
- }
64
- }
65
- exports.Factory = Factory;
66
- const CHANNEL = 'exposition';
67
- //# sourceMappingURL=Factory.js.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AE,CAAA;QAC3B,MAAM,IAAI,GAAG,IAAI,UAAI,CAAuB,IAAI,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;QAEtE,MAAM,WAAW,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC9C,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;QAEpD,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QAE5B,OAAO,OAAO,CAAA;IAChB,CAAC;CACF;AAnCD,0BAmCC;AAED,MAAM,OAAO,GAAG,YAAY,CAAA"}
@@ -1,19 +0,0 @@
1
- import { type bindings, Connector } from '@toa.io/core';
2
- import * as http from './HTTP';
3
- import { type Tree } from './RTD';
4
- import { type Label } from './discovery';
5
- import { type Endpoint } from './Endpoint';
6
- import { type Directives } from './Directive';
7
- export declare class Gateway extends Connector {
8
- private readonly broadcast;
9
- private readonly tree;
10
- constructor(broadcast: Broadcast, server: http.Server, tree: Tree<Endpoint, Directives>);
11
- protected open(): Promise<void>;
12
- protected dispose(): void;
13
- private process;
14
- private call;
15
- private discover;
16
- private merge;
17
- }
18
- type Broadcast = bindings.Broadcast<Label>;
19
- export {};
@@ -1,90 +0,0 @@
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.Gateway = void 0;
27
- const core_1 = require("@toa.io/core");
28
- const nopeable_1 = require("nopeable");
29
- const http = __importStar(require("./HTTP"));
30
- const exceptions_1 = require("./exceptions");
31
- class Gateway extends core_1.Connector {
32
- broadcast;
33
- tree;
34
- constructor(broadcast, server, tree) {
35
- super();
36
- this.broadcast = broadcast;
37
- this.tree = tree;
38
- this.depends(broadcast);
39
- this.depends(server);
40
- server.attach(this.process.bind(this));
41
- }
42
- async open() {
43
- await this.discover();
44
- console.info('Gateway has started and is awaiting resource branches.');
45
- }
46
- dispose() {
47
- console.info('Gateway is closed.');
48
- }
49
- async process(request) {
50
- if (request.path[request.path.length - 1] !== '/')
51
- throw new http.NotFound('Trailing slash is required.');
52
- const match = this.tree.match(request.path);
53
- if (match === null)
54
- throw new http.NotFound();
55
- const { node, parameters } = match;
56
- if (!(request.method in node.methods))
57
- throw new http.MethodNotAllowed();
58
- const method = node.methods[request.method];
59
- const interruption = await method.directives.preflight(request, parameters);
60
- const response = interruption ?? await this.call(method, request, parameters);
61
- await method.directives.settle(request, response);
62
- return response;
63
- }
64
- async call(method, request, parameters) {
65
- if (method.endpoint === null)
66
- throw new http.MethodNotAllowed();
67
- const reply = await method.endpoint
68
- .call(request.body, request.query, parameters)
69
- .catch(exceptions_1.rethrow);
70
- if (reply instanceof nopeable_1.Nope)
71
- throw new http.Conflict(reply);
72
- return { body: reply };
73
- }
74
- async discover() {
75
- await this.broadcast.receive('expose', this.merge.bind(this));
76
- await this.broadcast.transmit('ping', null);
77
- }
78
- merge(branch) {
79
- try {
80
- this.tree.merge(branch.node, branch);
81
- console.info('Resource branch of ' +
82
- `'${branch.namespace}.${branch.component}' has been merged.`);
83
- }
84
- catch (exception) {
85
- console.error(exception);
86
- }
87
- }
88
- }
89
- exports.Gateway = Gateway;
90
- //# sourceMappingURL=Gateway.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Gateway.js","sourceRoot":"","sources":["../source/Gateway.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAuD;AACvD,uCAA8C;AAC9C,6CAA8B;AAC9B,6CAAsC;AAOtC,MAAa,OAAQ,SAAQ,gBAAS;IACnB,SAAS,CAAW;IACpB,IAAI,CAA4B;IAEjD,YAAoB,SAAoB,EAAE,MAAmB,EAAE,IAAgC;QAC7F,KAAK,EAAE,CAAA;QAEP,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAEhB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;QACvB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QAEpB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IACxC,CAAC;IAEkB,KAAK,CAAC,IAAI;QAC3B,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAA;QAErB,OAAO,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAA;IACxE,CAAC;IAEkB,OAAO;QACxB,OAAO,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAA;IACpC,CAAC;IAEO,KAAK,CAAC,OAAO,CAAE,OAA6B;QAClD,IAAI,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG;YAC/C,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CAAA;QAExD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAE3C,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,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QACrE,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAO,MAAM,EAAE,IAAI,CAAC,CAAA;IACnD,CAAC;IAEO,KAAK,CAAE,MAAc;QAC3B,IAAI;YACF,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;YAEpC,OAAO,CAAC,IAAI,CAAC,qBAAqB;gBAChC,IAAI,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,SAAS,oBAAoB,CAAC,CAAA;SAChE;QAAC,OAAO,SAAS,EAAE;YAClB,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;SACzB;IACH,CAAC;CACF;AAhFD,0BAgFC"}
@@ -1,22 +0,0 @@
1
- import { Connector } from '@toa.io/core';
2
- import { type IncomingMessage, type OutgoingMessage } from './messages';
3
- export declare class Server extends Connector {
4
- private readonly debug;
5
- private readonly app;
6
- private server?;
7
- private constructor();
8
- static create(options?: Partial<Properties>): Server;
9
- attach(process: Processing): void;
10
- protected open(): Promise<void>;
11
- protected close(): Promise<void>;
12
- protected dispose(): void;
13
- private read;
14
- private success;
15
- private fail;
16
- }
17
- interface Properties {
18
- methods: Set<string>;
19
- debug: boolean;
20
- }
21
- export type Processing = (input: IncomingMessage) => Promise<OutgoingMessage>;
22
- export {};
@@ -1,12 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="jest" />
3
- import { Buffer } from 'buffer';
4
- import type { IncomingMessage } from './messages';
5
- import type { NextFunction, Response, Express, Request } from 'express';
6
- import type { CorsOptions } from 'cors';
7
- export declare function createRequest(req?: Partial<Request>, content?: string | Buffer): jest.MockedObject<Request>;
8
- export declare function createIncomingMessage(path: string, method?: string): IncomingMessage;
9
- export declare const res: jest.MockedObject<Response<any, Record<string, any>>>;
10
- export declare const next: NextFunction;
11
- export declare const express: jest.Mock<jest.Mock<Express, any, any>, [], any>;
12
- export declare const cors: jest.Mock<() => undefined, [_: CorsOptions], any>;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cors = exports.express = exports.next = exports.res = exports.createIncomingMessage = exports.createRequest = void 0;
4
- const buffer_1 = require("buffer");
5
- const stream_1 = require("stream");
6
- const server = {
7
- close: jest.fn()
8
- };
9
- const app = {
10
- enable: jest.fn(),
11
- disable: jest.fn(),
12
- use: jest.fn(),
13
- listen: jest.fn(() => server)
14
- };
15
- function createRequest(req = {}, content = '') {
16
- const buffer = buffer_1.Buffer.isBuffer(content) ? content : buffer_1.Buffer.from(content);
17
- const stream = stream_1.Readable.from(buffer);
18
- Object.assign(stream, { headers: {} }, req);
19
- return stream;
20
- }
21
- exports.createRequest = createRequest;
22
- function createIncomingMessage(path, method = 'GET') {
23
- return { method, path, headers: {}, body: undefined, query: {} };
24
- }
25
- exports.createIncomingMessage = createIncomingMessage;
26
- exports.res = {
27
- status: jest.fn(() => exports.res),
28
- sendStatus: jest.fn(() => exports.res),
29
- set: jest.fn(() => exports.res),
30
- send: jest.fn(() => exports.res),
31
- end: jest.fn(() => exports.res)
32
- };
33
- exports.next = jest.fn();
34
- exports.express = jest.fn(() => app);
35
- exports.cors = jest.fn((_) => () => undefined);
36
- //# sourceMappingURL=Server.fixtures.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Server.fixtures.js","sourceRoot":"","sources":["../../source/HTTP/Server.fixtures.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAC/B,mCAAiC;AAMjC,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;CACoB,CAAA;AAEtC,MAAM,GAAG,GAAG;IACV,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;IACjB,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE;IAClB,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACd,MAAM,EAAE,IAAI,CAAC,EAAE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,IAAI,CAAC,EAAE,CAAC,CAAC,CAAc,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA"}
@@ -1,111 +0,0 @@
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
@@ -1 +0,0 @@
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,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;YAE3B,MAAM,aAAa,GAAG,SAAS,YAAY,wBAAW,IAAI,IAAI,CAAC,KAAK,CAAA;YAEpE,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;YAEvB,IAAI,aAAa,EAAE;gBACjB,MAAM,IAAI,GAAG,SAAS,YAAY,sBAAS;oBACzC,CAAC,CAAC,SAAS,CAAC,IAAI;oBAChB,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;gBAE1C,IAAA,gBAAK,EAAC,OAAO,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"}
@@ -1,39 +0,0 @@
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 {};