@toa.io/extensions.exposition 0.8.3-dev.9 → 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.
Files changed (363) hide show
  1. package/components/context.toa.yaml +15 -0
  2. package/components/identity.bans/manifest.toa.yaml +18 -0
  3. package/components/identity.basic/events/principal.js +9 -0
  4. package/components/identity.basic/manifest.toa.yaml +50 -0
  5. package/components/identity.basic/source/authenticate.ts +29 -0
  6. package/components/identity.basic/source/create.ts +19 -0
  7. package/components/identity.basic/source/transit.ts +64 -0
  8. package/components/identity.basic/source/types.ts +42 -0
  9. package/components/identity.basic/tsconfig.json +9 -0
  10. package/components/identity.roles/manifest.toa.yaml +31 -0
  11. package/components/identity.roles/source/list.ts +7 -0
  12. package/components/identity.roles/source/principal.ts +20 -0
  13. package/components/identity.roles/tsconfig.json +9 -0
  14. package/components/identity.tokens/manifest.toa.yaml +39 -0
  15. package/components/identity.tokens/receivers/identity.bans.updated.js +3 -0
  16. package/components/identity.tokens/source/authenticate.test.ts +56 -0
  17. package/components/identity.tokens/source/authenticate.ts +38 -0
  18. package/components/identity.tokens/source/decrypt.test.ts +59 -0
  19. package/components/identity.tokens/source/decrypt.ts +25 -0
  20. package/components/identity.tokens/source/encrypt.test.ts +35 -0
  21. package/components/identity.tokens/source/encrypt.ts +25 -0
  22. package/components/identity.tokens/source/revoke.ts +5 -0
  23. package/components/identity.tokens/source/types.ts +48 -0
  24. package/components/identity.tokens/tsconfig.json +9 -0
  25. package/cucumber.js +9 -0
  26. package/documentation/.assets/ia3-dark.jpg +0 -0
  27. package/documentation/.assets/ia3-light.jpg +0 -0
  28. package/documentation/.assets/overview-dark.jpg +0 -0
  29. package/documentation/.assets/overview-light.jpg +0 -0
  30. package/documentation/.assets/role-scopes-dark.jpg +0 -0
  31. package/documentation/.assets/role-scopes-light.jpg +0 -0
  32. package/documentation/.assets/rtd-dark.jpg +0 -0
  33. package/documentation/.assets/rtd-light.jpg +0 -0
  34. package/documentation/access.md +256 -0
  35. package/documentation/components.md +276 -0
  36. package/documentation/identity.md +156 -0
  37. package/documentation/protocol.md +15 -0
  38. package/documentation/query.md +226 -0
  39. package/documentation/tree.md +169 -0
  40. package/features/access.feature +442 -0
  41. package/features/annotation.feature +28 -0
  42. package/features/body.feature +21 -0
  43. package/features/directives.feature +56 -0
  44. package/features/dynamic.feature +89 -0
  45. package/features/errors.feature +208 -0
  46. package/features/identity.basic.feature +235 -0
  47. package/features/identity.feature +61 -0
  48. package/features/identity.roles.feature +51 -0
  49. package/features/identity.tokens.feature +116 -0
  50. package/features/queries.feature +214 -0
  51. package/features/routes.feature +49 -0
  52. package/features/steps/Common.ts +10 -0
  53. package/features/steps/Components.ts +43 -0
  54. package/features/steps/Database.ts +58 -0
  55. package/features/steps/Gateway.ts +105 -0
  56. package/features/steps/HTTP.ts +71 -0
  57. package/features/steps/Parameters.ts +12 -0
  58. package/features/steps/Workspace.ts +40 -0
  59. package/features/steps/components/greeter/manifest.toa.yaml +9 -0
  60. package/features/steps/components/greeter/operations/greet.js +7 -0
  61. package/features/steps/components/pots/manifest.toa.yaml +20 -0
  62. package/features/steps/components/users/manifest.toa.yaml +11 -0
  63. package/features/steps/tsconfig.json +9 -0
  64. package/package.json +31 -17
  65. package/readme.md +181 -0
  66. package/schemas/annotation.cos.yaml +4 -0
  67. package/schemas/directive.cos.yaml +3 -0
  68. package/schemas/method.cos.yaml +9 -0
  69. package/schemas/node.cos.yaml +5 -0
  70. package/schemas/query.cos.yaml +16 -0
  71. package/schemas/querystring.cos.yaml +5 -0
  72. package/schemas/range.cos.yaml +2 -0
  73. package/schemas/route.cos.yaml +2 -0
  74. package/source/Annotation.ts +6 -0
  75. package/source/Branch.ts +8 -0
  76. package/source/Composition.ts +58 -0
  77. package/source/Context.ts +6 -0
  78. package/source/Directive.test.ts +91 -0
  79. package/source/Directive.ts +120 -0
  80. package/source/Endpoint.ts +57 -0
  81. package/source/Factory.ts +53 -0
  82. package/source/Gateway.ts +93 -0
  83. package/source/HTTP/Server.fixtures.ts +45 -0
  84. package/source/HTTP/Server.test.ts +221 -0
  85. package/source/HTTP/Server.ts +135 -0
  86. package/source/HTTP/exceptions.ts +77 -0
  87. package/source/HTTP/formats/index.ts +19 -0
  88. package/source/HTTP/formats/json.ts +13 -0
  89. package/source/HTTP/formats/msgpack.ts +10 -0
  90. package/source/HTTP/formats/text.ts +9 -0
  91. package/source/HTTP/formats/yaml.ts +14 -0
  92. package/source/HTTP/index.ts +3 -0
  93. package/source/HTTP/messages.test.ts +116 -0
  94. package/source/HTTP/messages.ts +77 -0
  95. package/source/Mapping.ts +48 -0
  96. package/source/Query.test.ts +37 -0
  97. package/source/Query.ts +105 -0
  98. package/source/RTD/Context.ts +16 -0
  99. package/source/RTD/Directives.ts +9 -0
  100. package/source/RTD/Endpoint.ts +11 -0
  101. package/source/RTD/Match.ts +16 -0
  102. package/source/RTD/Method.ts +24 -0
  103. package/source/RTD/Node.ts +85 -0
  104. package/source/RTD/Route.ts +58 -0
  105. package/source/RTD/Tree.ts +57 -0
  106. package/source/RTD/factory.ts +47 -0
  107. package/source/RTD/index.ts +8 -0
  108. package/source/RTD/segment.test.ts +32 -0
  109. package/source/RTD/segment.ts +25 -0
  110. package/source/RTD/syntax/index.ts +2 -0
  111. package/source/RTD/syntax/parse.test.ts +188 -0
  112. package/source/RTD/syntax/parse.ts +153 -0
  113. package/source/RTD/syntax/types.ts +48 -0
  114. package/source/Remotes.test.ts +41 -0
  115. package/source/Remotes.ts +20 -0
  116. package/source/Tenant.ts +38 -0
  117. package/source/deployment.ts +42 -0
  118. package/source/directives/auth/Anonymous.ts +14 -0
  119. package/source/directives/auth/Echo.ts +12 -0
  120. package/source/directives/auth/Family.ts +145 -0
  121. package/source/directives/auth/Id.ts +19 -0
  122. package/source/directives/auth/Incept.ts +42 -0
  123. package/source/directives/auth/Role.test.ts +62 -0
  124. package/source/directives/auth/Role.ts +56 -0
  125. package/source/directives/auth/Rule.ts +28 -0
  126. package/source/directives/auth/Scheme.ts +26 -0
  127. package/source/directives/auth/index.ts +3 -0
  128. package/source/directives/auth/schemes.ts +8 -0
  129. package/source/directives/auth/split.ts +15 -0
  130. package/source/directives/auth/types.ts +37 -0
  131. package/source/directives/dev/Family.ts +34 -0
  132. package/source/directives/dev/Stub.ts +14 -0
  133. package/source/directives/dev/index.ts +3 -0
  134. package/source/directives/dev/types.ts +5 -0
  135. package/source/directives/index.ts +5 -0
  136. package/source/discovery.ts +1 -0
  137. package/source/exceptions.ts +17 -0
  138. package/source/index.test.ts +9 -0
  139. package/source/index.ts +6 -0
  140. package/source/manifest.test.ts +57 -0
  141. package/source/manifest.ts +35 -0
  142. package/source/root.ts +38 -0
  143. package/source/schemas.ts +9 -0
  144. package/transpiled/Annotation.d.ts +6 -0
  145. package/transpiled/Annotation.js +3 -0
  146. package/transpiled/Annotation.js.map +1 -0
  147. package/transpiled/Branch.d.ts +7 -0
  148. package/transpiled/Branch.js +3 -0
  149. package/transpiled/Branch.js.map +1 -0
  150. package/transpiled/Composition.d.ts +14 -0
  151. package/transpiled/Composition.js +43 -0
  152. package/transpiled/Composition.js.map +1 -0
  153. package/transpiled/Context.d.ts +5 -0
  154. package/transpiled/Context.js +3 -0
  155. package/transpiled/Context.js.map +1 -0
  156. package/transpiled/Directive.d.ts +32 -0
  157. package/transpiled/Directive.js +76 -0
  158. package/transpiled/Directive.js.map +1 -0
  159. package/transpiled/Endpoint.d.ts +20 -0
  160. package/transpiled/Endpoint.js +44 -0
  161. package/transpiled/Endpoint.js.map +1 -0
  162. package/transpiled/Factory.d.ts +11 -0
  163. package/transpiled/Factory.js +67 -0
  164. package/transpiled/Factory.js.map +1 -0
  165. package/transpiled/Gateway.d.ts +19 -0
  166. package/transpiled/Gateway.js +90 -0
  167. package/transpiled/Gateway.js.map +1 -0
  168. package/transpiled/HTTP/Server.d.ts +22 -0
  169. package/transpiled/HTTP/Server.fixtures.d.ts +12 -0
  170. package/transpiled/HTTP/Server.fixtures.js +36 -0
  171. package/transpiled/HTTP/Server.fixtures.js.map +1 -0
  172. package/transpiled/HTTP/Server.js +111 -0
  173. package/transpiled/HTTP/Server.js.map +1 -0
  174. package/transpiled/HTTP/exceptions.d.ts +39 -0
  175. package/transpiled/HTTP/exceptions.js +78 -0
  176. package/transpiled/HTTP/exceptions.js.map +1 -0
  177. package/transpiled/HTTP/formats/index.d.ts +8 -0
  178. package/transpiled/HTTP/formats/index.js +38 -0
  179. package/transpiled/HTTP/formats/index.js.map +1 -0
  180. package/transpiled/HTTP/formats/json.d.ts +4 -0
  181. package/transpiled/HTTP/formats/json.js +15 -0
  182. package/transpiled/HTTP/formats/json.js.map +1 -0
  183. package/transpiled/HTTP/formats/msgpack.d.ts +4 -0
  184. package/transpiled/HTTP/formats/msgpack.js +36 -0
  185. package/transpiled/HTTP/formats/msgpack.js.map +1 -0
  186. package/transpiled/HTTP/formats/text.d.ts +4 -0
  187. package/transpiled/HTTP/formats/text.js +13 -0
  188. package/transpiled/HTTP/formats/text.js.map +1 -0
  189. package/transpiled/HTTP/formats/yaml.d.ts +4 -0
  190. package/transpiled/HTTP/formats/yaml.js +39 -0
  191. package/transpiled/HTTP/formats/yaml.js.map +1 -0
  192. package/transpiled/HTTP/index.d.ts +3 -0
  193. package/transpiled/HTTP/index.js +20 -0
  194. package/transpiled/HTTP/index.js.map +1 -0
  195. package/transpiled/HTTP/messages.d.ts +27 -0
  196. package/transpiled/HTTP/messages.js +49 -0
  197. package/transpiled/HTTP/messages.js.map +1 -0
  198. package/transpiled/Mapping.d.ts +8 -0
  199. package/transpiled/Mapping.js +35 -0
  200. package/transpiled/Mapping.js.map +1 -0
  201. package/transpiled/Query.d.ts +13 -0
  202. package/transpiled/Query.js +107 -0
  203. package/transpiled/Query.js.map +1 -0
  204. package/transpiled/RTD/Context.d.ts +11 -0
  205. package/transpiled/RTD/Context.js +3 -0
  206. package/transpiled/RTD/Context.js.map +1 -0
  207. package/transpiled/RTD/Directives.d.ts +7 -0
  208. package/transpiled/RTD/Directives.js +3 -0
  209. package/transpiled/RTD/Directives.js.map +1 -0
  210. package/transpiled/RTD/Endpoint.d.ts +9 -0
  211. package/transpiled/RTD/Endpoint.js +3 -0
  212. package/transpiled/RTD/Endpoint.js.map +1 -0
  213. package/transpiled/RTD/Match.d.ts +11 -0
  214. package/transpiled/RTD/Match.js +3 -0
  215. package/transpiled/RTD/Match.js.map +1 -0
  216. package/transpiled/RTD/Method.d.ts +9 -0
  217. package/transpiled/RTD/Method.js +16 -0
  218. package/transpiled/RTD/Method.js.map +1 -0
  219. package/transpiled/RTD/Node.d.ts +21 -0
  220. package/transpiled/RTD/Node.js +61 -0
  221. package/transpiled/RTD/Node.js.map +1 -0
  222. package/transpiled/RTD/Route.d.ts +14 -0
  223. package/transpiled/RTD/Route.js +48 -0
  224. package/transpiled/RTD/Route.js.map +1 -0
  225. package/transpiled/RTD/Tree.d.ts +14 -0
  226. package/transpiled/RTD/Tree.js +45 -0
  227. package/transpiled/RTD/Tree.js.map +1 -0
  228. package/transpiled/RTD/factory.d.ts +6 -0
  229. package/transpiled/RTD/factory.js +36 -0
  230. package/transpiled/RTD/factory.js.map +1 -0
  231. package/transpiled/RTD/index.d.ts +8 -0
  232. package/transpiled/RTD/index.js +38 -0
  233. package/transpiled/RTD/index.js.map +1 -0
  234. package/transpiled/RTD/segment.d.ts +8 -0
  235. package/transpiled/RTD/segment.js +23 -0
  236. package/transpiled/RTD/segment.js.map +1 -0
  237. package/transpiled/RTD/syntax/index.d.ts +2 -0
  238. package/transpiled/RTD/syntax/index.js +19 -0
  239. package/transpiled/RTD/syntax/index.js.map +1 -0
  240. package/transpiled/RTD/syntax/parse.d.ts +4 -0
  241. package/transpiled/RTD/syntax/parse.js +128 -0
  242. package/transpiled/RTD/syntax/parse.js.map +1 -0
  243. package/transpiled/RTD/syntax/types.d.ts +41 -0
  244. package/transpiled/RTD/syntax/types.js +5 -0
  245. package/transpiled/RTD/syntax/types.js.map +1 -0
  246. package/transpiled/Remotes.d.ts +7 -0
  247. package/transpiled/Remotes.js +19 -0
  248. package/transpiled/Remotes.js.map +1 -0
  249. package/transpiled/Tenant.d.ts +12 -0
  250. package/transpiled/Tenant.js +30 -0
  251. package/transpiled/Tenant.js.map +1 -0
  252. package/transpiled/deployment.d.ts +3 -0
  253. package/transpiled/deployment.js +61 -0
  254. package/transpiled/deployment.js.map +1 -0
  255. package/transpiled/directives/auth/Anonymous.d.ts +6 -0
  256. package/transpiled/directives/auth/Anonymous.js +17 -0
  257. package/transpiled/directives/auth/Anonymous.js.map +1 -0
  258. package/transpiled/directives/auth/Echo.d.ts +6 -0
  259. package/transpiled/directives/auth/Echo.js +13 -0
  260. package/transpiled/directives/auth/Echo.js.map +1 -0
  261. package/transpiled/directives/auth/Family.d.ts +20 -0
  262. package/transpiled/directives/auth/Family.js +125 -0
  263. package/transpiled/directives/auth/Family.js.map +1 -0
  264. package/transpiled/directives/auth/Id.d.ts +7 -0
  265. package/transpiled/directives/auth/Id.js +17 -0
  266. package/transpiled/directives/auth/Id.js.map +1 -0
  267. package/transpiled/directives/auth/Incept.d.ts +10 -0
  268. package/transpiled/directives/auth/Incept.js +59 -0
  269. package/transpiled/directives/auth/Incept.js.map +1 -0
  270. package/transpiled/directives/auth/Role.d.ts +11 -0
  271. package/transpiled/directives/auth/Role.js +44 -0
  272. package/transpiled/directives/auth/Role.js.map +1 -0
  273. package/transpiled/directives/auth/Rule.d.ts +9 -0
  274. package/transpiled/directives/auth/Rule.js +22 -0
  275. package/transpiled/directives/auth/Rule.js.map +1 -0
  276. package/transpiled/directives/auth/Scheme.d.ts +7 -0
  277. package/transpiled/directives/auth/Scheme.js +47 -0
  278. package/transpiled/directives/auth/Scheme.js.map +1 -0
  279. package/transpiled/directives/auth/index.d.ts +2 -0
  280. package/transpiled/directives/auth/index.js +7 -0
  281. package/transpiled/directives/auth/index.js.map +1 -0
  282. package/transpiled/directives/auth/schemes.d.ts +3 -0
  283. package/transpiled/directives/auth/schemes.js +9 -0
  284. package/transpiled/directives/auth/schemes.js.map +1 -0
  285. package/transpiled/directives/auth/split.d.ts +2 -0
  286. package/transpiled/directives/auth/split.js +38 -0
  287. package/transpiled/directives/auth/split.js.map +1 -0
  288. package/transpiled/directives/auth/types.d.ts +31 -0
  289. package/transpiled/directives/auth/types.js +3 -0
  290. package/transpiled/directives/auth/types.js.map +1 -0
  291. package/transpiled/directives/dev/Family.d.ts +10 -0
  292. package/transpiled/directives/dev/Family.js +25 -0
  293. package/transpiled/directives/dev/Family.js.map +1 -0
  294. package/transpiled/directives/dev/Stub.d.ts +7 -0
  295. package/transpiled/directives/dev/Stub.js +14 -0
  296. package/transpiled/directives/dev/Stub.js.map +1 -0
  297. package/transpiled/directives/dev/index.d.ts +2 -0
  298. package/transpiled/directives/dev/index.js +7 -0
  299. package/transpiled/directives/dev/index.js.map +1 -0
  300. package/transpiled/directives/dev/types.d.ts +4 -0
  301. package/transpiled/directives/dev/types.js +3 -0
  302. package/transpiled/directives/dev/types.js.map +1 -0
  303. package/transpiled/directives/index.d.ts +2 -0
  304. package/transpiled/directives/index.js +10 -0
  305. package/transpiled/directives/index.js.map +1 -0
  306. package/transpiled/discovery.d.ts +1 -0
  307. package/transpiled/discovery.js +3 -0
  308. package/transpiled/discovery.js.map +1 -0
  309. package/transpiled/exceptions.d.ts +2 -0
  310. package/transpiled/exceptions.js +39 -0
  311. package/transpiled/exceptions.js.map +1 -0
  312. package/transpiled/index.d.ts +5 -0
  313. package/transpiled/index.js +12 -0
  314. package/transpiled/index.js.map +1 -0
  315. package/transpiled/manifest.d.ts +3 -0
  316. package/transpiled/manifest.js +30 -0
  317. package/transpiled/manifest.js.map +1 -0
  318. package/transpiled/root.d.ts +2 -0
  319. package/transpiled/root.js +39 -0
  320. package/transpiled/root.js.map +1 -0
  321. package/transpiled/schemas.d.ts +3 -0
  322. package/transpiled/schemas.js +14 -0
  323. package/transpiled/schemas.js.map +1 -0
  324. package/transpiled/tsconfig.tsbuildinfo +1 -0
  325. package/tsconfig.json +12 -0
  326. package/src/.manifest/index.js +0 -7
  327. package/src/.manifest/normalize.js +0 -58
  328. package/src/.manifest/schema.yaml +0 -69
  329. package/src/.manifest/validate.js +0 -17
  330. package/src/constants.js +0 -3
  331. package/src/deployment.js +0 -23
  332. package/src/exposition.js +0 -68
  333. package/src/factory.js +0 -76
  334. package/src/index.js +0 -9
  335. package/src/manifest.js +0 -12
  336. package/src/query/criteria.js +0 -55
  337. package/src/query/enum.js +0 -35
  338. package/src/query/index.js +0 -17
  339. package/src/query/query.js +0 -60
  340. package/src/query/range.js +0 -28
  341. package/src/query/sort.js +0 -19
  342. package/src/remote.js +0 -88
  343. package/src/server.js +0 -83
  344. package/src/tenant.js +0 -29
  345. package/src/translate/etag.js +0 -14
  346. package/src/translate/index.js +0 -7
  347. package/src/translate/request.js +0 -68
  348. package/src/translate/response.js +0 -62
  349. package/src/tree.js +0 -109
  350. package/test/manifest.normalize.fixtures.js +0 -37
  351. package/test/manifest.normalize.test.js +0 -37
  352. package/test/manifest.validate.test.js +0 -40
  353. package/test/query.range.test.js +0 -18
  354. package/test/tree.fixtures.js +0 -21
  355. package/test/tree.test.js +0 -44
  356. package/types/annotations.d.ts +0 -10
  357. package/types/declarations.d.ts +0 -31
  358. package/types/exposition.d.ts +0 -13
  359. package/types/http.d.ts +0 -13
  360. package/types/query.d.ts +0 -16
  361. package/types/remote.d.ts +0 -19
  362. package/types/server.d.ts +0 -13
  363. 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":"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"}
@@ -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;IAE1B,YAAuB,MAAc,EAAE,IAAU;QAC/C,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;CACF;AATD,8BASC;AAED,MAAa,WAAY,SAAQ,SAAS;CACzC;AADD,kCACC;AAED,MAAa,UAAW,SAAQ,WAAW;IACzC,YAAoB,IAAU;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAClB,CAAC;CACF;AAJD,gCAIC;AAED,MAAa,YAAa,SAAQ,WAAW;IAC3C,YAAoB,IAAU;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAClB,CAAC;CACF;AAJD,oCAIC;AAED,MAAa,SAAU,SAAQ,WAAW;IACxC,YAAoB,IAAU;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAClB,CAAC;CACF;AAJD,8BAIC;AAED,MAAa,QAAS,SAAQ,WAAW;IACvC,YAAoB,IAAU;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAClB,CAAC;CACF;AAJD,4BAIC;AAED,MAAa,QAAS,SAAQ,WAAW;IACvC,YAAoB,IAAS;QAC3B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;IAClB,CAAC;CACF;AAJD,4BAIC;AAED,MAAa,gBAAiB,SAAQ,WAAW;IAC/C;QACE,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;CACF;AAJD,4CAIC;AAED,MAAM,kBAAmB,SAAQ,WAAW;IAClC,MAAM,CAAU,OAAO,GAAG,4BAA4B,GAAG,eAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAEnF,YAAuB,MAAc;QACnC,KAAK,CAAC,MAAM,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAA;IAC3C,CAAC;;AAGH,MAAa,aAAc,SAAQ,kBAAkB;IACnD;QACE,KAAK,CAAC,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,4 @@
1
+ /// <reference types="node" />
2
+ import { Buffer } from 'node:buffer';
3
+ export declare function decode(buffer: Buffer): any;
4
+ export declare function encode(value: any): Buffer;
@@ -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,4 @@
1
+ /// <reference types="node" />
2
+ import { type Buffer } from 'node:buffer';
3
+ export declare function decode(buffer: Buffer): any;
4
+ export declare function encode(value: any): Buffer;
@@ -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,4 @@
1
+ /// <reference types="node" />
2
+ import { Buffer } from 'node:buffer';
3
+ export declare function decode(buffer: Buffer): any;
4
+ export declare function encode(value: any): Buffer;
@@ -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,4 @@
1
+ /// <reference types="node" />
2
+ import { Buffer } from 'node:buffer';
3
+ export declare function decode(buffer: Buffer): any;
4
+ export declare function encode(value: any): Buffer;
@@ -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,3 @@
1
+ export * from './Server';
2
+ export * from './messages';
3
+ export * from './exceptions';
@@ -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
+ }