@typespec/http-server-js 0.58.0-alpha.10-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/LICENSE +21 -0
- package/README.md +183 -0
- package/build-helpers.ts +170 -0
- package/dist/generated-defs/helpers/header.d.ts +4 -0
- package/dist/generated-defs/helpers/header.d.ts.map +1 -0
- package/dist/generated-defs/helpers/header.js +76 -0
- package/dist/generated-defs/helpers/header.js.map +1 -0
- package/dist/generated-defs/helpers/http.d.ts +4 -0
- package/dist/generated-defs/helpers/http.d.ts.map +1 -0
- package/dist/generated-defs/helpers/http.js +134 -0
- package/dist/generated-defs/helpers/http.js.map +1 -0
- package/dist/generated-defs/helpers/index.d.ts +4 -0
- package/dist/generated-defs/helpers/index.d.ts.map +1 -0
- package/dist/generated-defs/helpers/index.js +21 -0
- package/dist/generated-defs/helpers/index.js.map +1 -0
- package/dist/generated-defs/helpers/multipart.d.ts +4 -0
- package/dist/generated-defs/helpers/multipart.d.ts.map +1 -0
- package/dist/generated-defs/helpers/multipart.js +249 -0
- package/dist/generated-defs/helpers/multipart.js.map +1 -0
- package/dist/generated-defs/helpers/router.d.ts +4 -0
- package/dist/generated-defs/helpers/router.d.ts.map +1 -0
- package/dist/generated-defs/helpers/router.js +259 -0
- package/dist/generated-defs/helpers/router.js.map +1 -0
- package/dist/src/common/declaration.d.ts +13 -0
- package/dist/src/common/declaration.d.ts.map +1 -0
- package/dist/src/common/declaration.js +45 -0
- package/dist/src/common/declaration.js.map +1 -0
- package/dist/src/common/documentation.d.ts +12 -0
- package/dist/src/common/documentation.d.ts.map +1 -0
- package/dist/src/common/documentation.js +21 -0
- package/dist/src/common/documentation.js.map +1 -0
- package/dist/src/common/enum.d.ts +10 -0
- package/dist/src/common/enum.d.ts.map +1 -0
- package/dist/src/common/enum.js +21 -0
- package/dist/src/common/enum.js.map +1 -0
- package/dist/src/common/interface.d.ts +50 -0
- package/dist/src/common/interface.d.ts.map +1 -0
- package/dist/src/common/interface.js +194 -0
- package/dist/src/common/interface.js.map +1 -0
- package/dist/src/common/model.d.ts +26 -0
- package/dist/src/common/model.d.ts.map +1 -0
- package/dist/src/common/model.js +115 -0
- package/dist/src/common/model.js.map +1 -0
- package/dist/src/common/namespace.d.ts +38 -0
- package/dist/src/common/namespace.d.ts.map +1 -0
- package/dist/src/common/namespace.js +184 -0
- package/dist/src/common/namespace.js.map +1 -0
- package/dist/src/common/reference.d.ts +46 -0
- package/dist/src/common/reference.d.ts.map +1 -0
- package/dist/src/common/reference.js +243 -0
- package/dist/src/common/reference.js.map +1 -0
- package/dist/src/common/scalar.d.ts +50 -0
- package/dist/src/common/scalar.d.ts.map +1 -0
- package/dist/src/common/scalar.js +144 -0
- package/dist/src/common/scalar.js.map +1 -0
- package/dist/src/common/serialization/index.d.ts +11 -0
- package/dist/src/common/serialization/index.d.ts.map +1 -0
- package/dist/src/common/serialization/index.js +72 -0
- package/dist/src/common/serialization/index.js.map +1 -0
- package/dist/src/common/serialization/json.d.ts +6 -0
- package/dist/src/common/serialization/json.d.ts.map +1 -0
- package/dist/src/common/serialization/json.js +341 -0
- package/dist/src/common/serialization/json.js.map +1 -0
- package/dist/src/common/union.d.ts +23 -0
- package/dist/src/common/union.d.ts.map +1 -0
- package/dist/src/common/union.js +57 -0
- package/dist/src/common/union.js.map +1 -0
- package/dist/src/ctx.d.ts +242 -0
- package/dist/src/ctx.d.ts.map +1 -0
- package/dist/src/ctx.js +211 -0
- package/dist/src/ctx.js.map +1 -0
- package/dist/src/helpers/header.d.ts +14 -0
- package/dist/src/helpers/header.d.ts.map +1 -0
- package/dist/src/helpers/header.js +38 -0
- package/dist/src/helpers/header.js.map +1 -0
- package/dist/src/helpers/http.d.ts +70 -0
- package/dist/src/helpers/http.d.ts.map +1 -0
- package/dist/src/helpers/http.js +86 -0
- package/dist/src/helpers/http.js.map +1 -0
- package/dist/src/helpers/multipart.d.ts +26 -0
- package/dist/src/helpers/multipart.d.ts.map +1 -0
- package/dist/src/helpers/multipart.js +182 -0
- package/dist/src/helpers/multipart.js.map +1 -0
- package/dist/src/helpers/router.d.ts +176 -0
- package/dist/src/helpers/router.d.ts.map +1 -0
- package/dist/src/helpers/router.js +55 -0
- package/dist/src/helpers/router.js.map +1 -0
- package/dist/src/http/index.d.ts +24 -0
- package/dist/src/http/index.d.ts.map +1 -0
- package/dist/src/http/index.js +52 -0
- package/dist/src/http/index.js.map +1 -0
- package/dist/src/http/server/index.d.ts +11 -0
- package/dist/src/http/server/index.d.ts.map +1 -0
- package/dist/src/http/server/index.js +413 -0
- package/dist/src/http/server/index.js.map +1 -0
- package/dist/src/http/server/multipart.d.ts +16 -0
- package/dist/src/http/server/multipart.d.ts.map +1 -0
- package/dist/src/http/server/multipart.js +214 -0
- package/dist/src/http/server/multipart.js.map +1 -0
- package/dist/src/http/server/router.d.ts +15 -0
- package/dist/src/http/server/router.d.ts.map +1 -0
- package/dist/src/http/server/router.js +459 -0
- package/dist/src/http/server/router.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +38 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +141 -0
- package/dist/src/lib.d.ts.map +1 -0
- package/dist/src/lib.js +116 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/scripts/scaffold/bin.d.mts +14 -0
- package/dist/src/scripts/scaffold/bin.d.mts.map +1 -0
- package/dist/src/scripts/scaffold/bin.mjs +559 -0
- package/dist/src/scripts/scaffold/bin.mjs.map +1 -0
- package/dist/src/testing/index.d.ts +3 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/testing/index.js +6 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/util/case.d.ts +81 -0
- package/dist/src/util/case.d.ts.map +1 -0
- package/dist/src/util/case.js +111 -0
- package/dist/src/util/case.js.map +1 -0
- package/dist/src/util/differentiate.d.ts +251 -0
- package/dist/src/util/differentiate.d.ts.map +1 -0
- package/dist/src/util/differentiate.js +580 -0
- package/dist/src/util/differentiate.js.map +1 -0
- package/dist/src/util/error.d.ts +13 -0
- package/dist/src/util/error.d.ts.map +1 -0
- package/dist/src/util/error.js +25 -0
- package/dist/src/util/error.js.map +1 -0
- package/dist/src/util/extends.d.ts +10 -0
- package/dist/src/util/extends.d.ts.map +1 -0
- package/dist/src/util/extends.js +31 -0
- package/dist/src/util/extends.js.map +1 -0
- package/dist/src/util/iter.d.ts +39 -0
- package/dist/src/util/iter.d.ts.map +1 -0
- package/dist/src/util/iter.js +72 -0
- package/dist/src/util/iter.js.map +1 -0
- package/dist/src/util/keywords.d.ts +10 -0
- package/dist/src/util/keywords.d.ts.map +1 -0
- package/dist/src/util/keywords.js +85 -0
- package/dist/src/util/keywords.js.map +1 -0
- package/dist/src/util/name.d.ts +12 -0
- package/dist/src/util/name.d.ts.map +1 -0
- package/dist/src/util/name.js +26 -0
- package/dist/src/util/name.js.map +1 -0
- package/dist/src/util/once-queue.d.ts +24 -0
- package/dist/src/util/once-queue.d.ts.map +1 -0
- package/dist/src/util/once-queue.js +34 -0
- package/dist/src/util/once-queue.js.map +1 -0
- package/dist/src/util/openapi3.d.ts +23 -0
- package/dist/src/util/openapi3.d.ts.map +1 -0
- package/dist/src/util/openapi3.js +40 -0
- package/dist/src/util/openapi3.js.map +1 -0
- package/dist/src/util/pluralism.d.ts +23 -0
- package/dist/src/util/pluralism.d.ts.map +1 -0
- package/dist/src/util/pluralism.js +36 -0
- package/dist/src/util/pluralism.js.map +1 -0
- package/dist/src/util/scope.d.ts +85 -0
- package/dist/src/util/scope.d.ts.map +1 -0
- package/dist/src/util/scope.js +111 -0
- package/dist/src/util/scope.js.map +1 -0
- package/dist/src/write.d.ts +23 -0
- package/dist/src/write.d.ts.map +1 -0
- package/dist/src/write.js +62 -0
- package/dist/src/write.js.map +1 -0
- package/generated-defs/helpers/header.ts +83 -0
- package/generated-defs/helpers/http.ts +141 -0
- package/generated-defs/helpers/index.ts +27 -0
- package/generated-defs/helpers/multipart.ts +256 -0
- package/generated-defs/helpers/router.ts +266 -0
- package/package.json +71 -0
- package/src/common/declaration.ts +52 -0
- package/src/common/documentation.ts +26 -0
- package/src/common/enum.ts +28 -0
- package/src/common/interface.ts +264 -0
- package/src/common/model.ts +160 -0
- package/src/common/namespace.ts +243 -0
- package/src/common/reference.ts +319 -0
- package/src/common/scalar.ts +173 -0
- package/src/common/serialization/index.ts +124 -0
- package/src/common/serialization/json.ts +444 -0
- package/src/common/union.ts +76 -0
- package/src/ctx.ts +497 -0
- package/src/helpers/header.ts +55 -0
- package/src/helpers/http.ts +113 -0
- package/src/helpers/multipart.ts +228 -0
- package/src/helpers/router.ts +238 -0
- package/src/http/index.ts +81 -0
- package/src/http/server/index.ts +548 -0
- package/src/http/server/multipart.ts +272 -0
- package/src/http/server/router.ts +686 -0
- package/src/index.ts +56 -0
- package/src/lib.ts +130 -0
- package/src/scripts/scaffold/bin.mts +781 -0
- package/src/testing/index.ts +10 -0
- package/src/util/case.ts +182 -0
- package/src/util/differentiate.ts +957 -0
- package/src/util/error.ts +28 -0
- package/src/util/extends.ts +43 -0
- package/src/util/iter.ts +85 -0
- package/src/util/keywords.ts +90 -0
- package/src/util/name.ts +33 -0
- package/src/util/once-queue.ts +55 -0
- package/src/util/openapi3.ts +53 -0
- package/src/util/pluralism.ts +37 -0
- package/src/util/scope.ts +211 -0
- package/src/write.ts +88 -0
- package/temp/tsconfig.tsbuildinfo +1 -0
- package/test/header.test.ts +26 -0
- package/test/multipart.test.ts +169 -0
- package/tsconfig.json +10 -0
- package/vitest.config.ts +4 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Changelog - @typespec/http-server-js
|
|
2
|
+
|
|
3
|
+
## 0.58.0-alpha.9
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#5906](https://github.com/microsoft/typespec/pull/5906) Implement basic project scaffolding.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## 0.58.0-alpha.8
|
|
11
|
+
|
|
12
|
+
### Bump dependencies
|
|
13
|
+
|
|
14
|
+
- [#5690](https://github.com/microsoft/typespec/pull/5690) Upgrade dependencies
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 0.58.0-alpha.7
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
- [#5514](https://github.com/microsoft/typespec/pull/5514) - Implemented new-style multipart request handling.
|
|
22
|
+
- Fixed JSON serialization/deserialization in some cases where models that required serialization occurred within arrays.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 0.58.0-alpha.6
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
- [#5253](https://github.com/microsoft/typespec/pull/5253) Added an additional check for the presence of a property before performing a bounds check on integer properties constrained to a range.
|
|
30
|
+
- [#5253](https://github.com/microsoft/typespec/pull/5253) Fixed a null check in query parameter requiredness check by replacing it with a falseness check.
|
|
31
|
+
- [#5188](https://github.com/microsoft/typespec/pull/5188) Added logic to handle "unspeakable" identifier names (#5185)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
## 0.58.0-alpha.5
|
|
35
|
+
|
|
36
|
+
### Bump dependencies
|
|
37
|
+
|
|
38
|
+
- [#4679](https://github.com/microsoft/typespec/pull/4679) Upgrade dependencies - October 2024
|
|
39
|
+
|
|
40
|
+
### Features
|
|
41
|
+
|
|
42
|
+
- [#4761](https://github.com/microsoft/typespec/pull/4761) Add `@cookie` decorator to specify cookie parameters
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## 0.58.0-alpha.4
|
|
46
|
+
|
|
47
|
+
### Bump dependencies
|
|
48
|
+
|
|
49
|
+
- [#4424](https://github.com/microsoft/typespec/pull/4424) Bump dependencies
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## 0.58.0-alpha.3
|
|
53
|
+
|
|
54
|
+
No changes, version bump only.
|
|
55
|
+
|
|
56
|
+
## 0.58.0-alpha.2
|
|
57
|
+
|
|
58
|
+
### Bug Fixes
|
|
59
|
+
|
|
60
|
+
- [#3933](https://github.com/microsoft/typespec/pull/3933) Fix some diagnostic not showing the right message
|
|
61
|
+
- [#4101](https://github.com/microsoft/typespec/pull/4101) Fixed enum representation, an edge case with optional parameter joining, and a couple of type errors around query/header params.
|
|
62
|
+
- [#4115](https://github.com/microsoft/typespec/pull/4115) Fixed a router bug where paths would sometimes fail to match after a parameter was bound.
|
|
63
|
+
|
|
64
|
+
### Bump dependencies
|
|
65
|
+
|
|
66
|
+
- [#3948](https://github.com/microsoft/typespec/pull/3948) Update dependencies
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
package/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# @typespec/http-server-js
|
|
2
|
+
|
|
3
|
+
:warning: **This package is highly experimental and may be subject to breaking changes and bugs.** Please expect that your code may need to be updated as this package evolves, and please report any issues you encounter.
|
|
4
|
+
|
|
5
|
+
TypeSpec HTTP server code generator for JavaScript and TypeScript.
|
|
6
|
+
|
|
7
|
+
This package generates an implementation of an HTTP server layer for a TypeSpec API. It supports binding directly to a
|
|
8
|
+
Node.js HTTP server or Express.js application.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @typespec/http-server-js
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Emitter
|
|
17
|
+
|
|
18
|
+
### Usage
|
|
19
|
+
|
|
20
|
+
1. Via the command line
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
tsp compile . --emit=@typespec/http-server-js
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
2. Via the config
|
|
27
|
+
|
|
28
|
+
```yaml
|
|
29
|
+
emit:
|
|
30
|
+
- "@typespec/http-server-js"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Emitter options
|
|
34
|
+
|
|
35
|
+
#### `express`
|
|
36
|
+
|
|
37
|
+
**Type:** `boolean`
|
|
38
|
+
|
|
39
|
+
If set to `true`, the emitter will generate a router that exposes an Express.js middleware function in addition to the
|
|
40
|
+
ordinary Node.js HTTP server router.
|
|
41
|
+
|
|
42
|
+
If this option is not set to `true`, the `expressMiddleware` property will not be present on the generated router.
|
|
43
|
+
|
|
44
|
+
#### `omit-unreachable-types`
|
|
45
|
+
|
|
46
|
+
**Type:** `boolean`
|
|
47
|
+
|
|
48
|
+
By default, the emitter will create interfaces that represent all models in the service namespace. If this option is set
|
|
49
|
+
to `true`, the emitter will only emit those types that are reachable from an HTTP operation.
|
|
50
|
+
|
|
51
|
+
#### `no-format`
|
|
52
|
+
|
|
53
|
+
**Type:** `boolean`
|
|
54
|
+
|
|
55
|
+
If set to `true`, the emitter will not format the generated code using Prettier.
|
|
56
|
+
|
|
57
|
+
## Functionality and generated code
|
|
58
|
+
|
|
59
|
+
The emitter generates a few major components:
|
|
60
|
+
|
|
61
|
+
### Router
|
|
62
|
+
|
|
63
|
+
The highest-level component that your code interacts with directly is the router implementation.
|
|
64
|
+
`@typespec/http-server-js` generates a static router that you can bind to an implementation of an HTTP server.
|
|
65
|
+
|
|
66
|
+
The router is generated in the `http/router.js` module within the output directory. Each service will have its own
|
|
67
|
+
router implementation named after the service. For example, given a service namespace named `Todo`, the router module
|
|
68
|
+
will export a function `createTodoRouter`. This function creates an instance of a router that dispatches methods within
|
|
69
|
+
the `Todo` service.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { createTodoRouter } from "../tsp-output/@typespec/http-server-js/http/router.js";
|
|
73
|
+
|
|
74
|
+
const router = createTodoRouter(users, todoItems, attachments);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
As arguments, the `createTodoRouter` function expects implementations of the underlying service interfaces. These
|
|
78
|
+
interfaces are explained further in the next section.
|
|
79
|
+
|
|
80
|
+
Once the router is created, it is bound to an instance of the HTTP server. The router's `dispatch` method implements the
|
|
81
|
+
Node.js event handler signature for the `request` event on a Node.js HTTP server.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
const server = http.createServer();
|
|
85
|
+
|
|
86
|
+
server.on("request", router.dispatch);
|
|
87
|
+
|
|
88
|
+
server.listen(8080, () => {
|
|
89
|
+
console.log("Server listening on http://localhost:8080");
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Alternatively, the router can be used with Express.js instead of the Node.js HTTP server directly. If the `express`
|
|
94
|
+
feature is enabled in the emitter options, the router will expose an `expressMiddleware` property that implements the
|
|
95
|
+
Express.js middleware interface.
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import express from "express";
|
|
99
|
+
|
|
100
|
+
const app = express();
|
|
101
|
+
|
|
102
|
+
app.use(router.expressMiddleware);
|
|
103
|
+
|
|
104
|
+
app.listen(8080, () => {
|
|
105
|
+
console.log("Server listening on http://localhost:8080");
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Service interfaces
|
|
110
|
+
|
|
111
|
+
The emitter generates interfaces for each collection of service methods that exists in the service namespace.
|
|
112
|
+
Implementations of these interfaces are required to instantiate the router. When the router processes an HTTP request,
|
|
113
|
+
it will call the appropriate method on the service implementation after determining the route and method.
|
|
114
|
+
|
|
115
|
+
For example, given the following TypeSpec namespace `Users` within the `Todo` service:
|
|
116
|
+
|
|
117
|
+
```tsp
|
|
118
|
+
namespace Users {
|
|
119
|
+
@route("/users")
|
|
120
|
+
@post
|
|
121
|
+
op create(
|
|
122
|
+
user: User,
|
|
123
|
+
): WithStandardErrors<UserCreatedResponse | UserExistsResponse | InvalidUserResponse>;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The emitter will generate a corresponding interface `Users` within the module `models/all/todo/index.js` in the output
|
|
128
|
+
directory.
|
|
129
|
+
|
|
130
|
+
```ts
|
|
131
|
+
/** An interface representing the operations defined in the 'Todo.Users' namespace. */
|
|
132
|
+
export interface Users<Context = unknown> {
|
|
133
|
+
create(
|
|
134
|
+
ctx: Context,
|
|
135
|
+
user: User,
|
|
136
|
+
): Promise<
|
|
137
|
+
| UserCreatedResponse
|
|
138
|
+
| UserExistsResponse
|
|
139
|
+
| InvalidUserResponse
|
|
140
|
+
| Standard4XxResponse
|
|
141
|
+
| Standard5XxResponse
|
|
142
|
+
>;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
An object implementing this `Users` interface must be passed to the router when it is created. The `Context` type
|
|
147
|
+
parameter represents the underlying protocol or framework-specific context that the service implementation may inspect.
|
|
148
|
+
If you need to access the HTTP request or response objects directly in the implementation of the service methods, you
|
|
149
|
+
must use the `HttpContext` type as the `Context` argument when implementing the service interface. Otherwise, it is safe
|
|
150
|
+
to use the default `unknown` argument.
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { HttpContext } from "../tsp-output/@typespec/http-server-js/helpers/router.js";
|
|
154
|
+
import { Users } from "../tsp-output/@typespec/http-server-js/models/all/todo/index.js";
|
|
155
|
+
|
|
156
|
+
export const users: Users<HttpContext> = {
|
|
157
|
+
async create(ctx, user) {
|
|
158
|
+
// Implementation
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Models
|
|
164
|
+
|
|
165
|
+
The emitter generates TypeScript interfaces that represent the model types used in the service operations. This allows
|
|
166
|
+
the service implementation to interact with the data structures carried over the HTTP protocol in a type-safe manner.
|
|
167
|
+
|
|
168
|
+
### Operation functions
|
|
169
|
+
|
|
170
|
+
While your code should never need to interact with these functions directly, the emitter generates a function per HTTP
|
|
171
|
+
operation that handles the parsing and validation of the request contents. This allows the service implementation to be
|
|
172
|
+
written in terms of ordinary TypeScript types and values rather than raw HTTP request and response objects. In general:
|
|
173
|
+
|
|
174
|
+
- The Node.js HTTP server or Express.js application (your code) calls the router (generated code), which determines
|
|
175
|
+
which service operation function (generated code) to call based on the route, method, and other HTTP metadata in the
|
|
176
|
+
case of shared routes.
|
|
177
|
+
- The operation function (generated code) deserializes the request body, query parameters, and headers into TypeScript
|
|
178
|
+
types, and may perform request validation.
|
|
179
|
+
- The operation function (generated code) calls the service implementation (your code) with the deserialized request
|
|
180
|
+
data.
|
|
181
|
+
- The service implementation (your code) returns a result or throws an error.
|
|
182
|
+
- The operation function (generated code) responds to the HTTP request on your behalf, converting the result or error
|
|
183
|
+
into HTTP response data.
|
package/build-helpers.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation.
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
/* eslint no-console: "off" */
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
const HELPER_DECLARATION_PATH = path.resolve("generated-defs", "helpers");
|
|
10
|
+
const HELPER_SRC_PATH = path.resolve("src", "helpers");
|
|
11
|
+
|
|
12
|
+
console.log("Building JS server generator helpers.");
|
|
13
|
+
|
|
14
|
+
async function* visitAllFiles(base: string): AsyncIterable<string> {
|
|
15
|
+
const contents = await fs.readdir(base, { withFileTypes: true });
|
|
16
|
+
|
|
17
|
+
for (const entry of contents) {
|
|
18
|
+
if (entry.isDirectory()) {
|
|
19
|
+
yield* visitAllFiles(path.join(base, entry.name));
|
|
20
|
+
} else if (entry.isFile()) {
|
|
21
|
+
yield path.join(base, entry.name);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function main() {
|
|
27
|
+
const allFiles: string[] = [];
|
|
28
|
+
const indices = new Map<string, string[]>();
|
|
29
|
+
|
|
30
|
+
const ctxPath = path.resolve("src", "ctx.js");
|
|
31
|
+
|
|
32
|
+
await fs.rm(HELPER_DECLARATION_PATH, { recursive: true, force: true });
|
|
33
|
+
|
|
34
|
+
function addIndex(dir: string, file: string) {
|
|
35
|
+
const index = indices.get(dir);
|
|
36
|
+
|
|
37
|
+
if (index) {
|
|
38
|
+
index.push(file);
|
|
39
|
+
} else {
|
|
40
|
+
indices.set(dir, [file]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for await (const file of visitAllFiles(HELPER_SRC_PATH)) {
|
|
45
|
+
allFiles.push(file);
|
|
46
|
+
addIndex(path.dirname(file), file);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
for (const file of allFiles) {
|
|
50
|
+
if (!file.endsWith(".ts")) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const relativePath = path.relative(HELPER_SRC_PATH, file);
|
|
55
|
+
|
|
56
|
+
console.log("Building helper:", relativePath);
|
|
57
|
+
|
|
58
|
+
const targetPath = path.resolve(HELPER_DECLARATION_PATH, relativePath);
|
|
59
|
+
|
|
60
|
+
const targetDir = path.dirname(targetPath);
|
|
61
|
+
const targetFileBase = path.basename(targetPath, ".ts");
|
|
62
|
+
const isIndex = targetFileBase === "index";
|
|
63
|
+
const targetBase = isIndex ? path.basename(targetDir) : targetFileBase;
|
|
64
|
+
await fs.mkdir(targetDir, { recursive: true });
|
|
65
|
+
|
|
66
|
+
const childModules = isIndex ? indices.get(path.dirname(file)) : [];
|
|
67
|
+
|
|
68
|
+
if (isIndex) {
|
|
69
|
+
indices.delete(path.dirname(file));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const contents = await fs.readFile(file, "utf-8");
|
|
73
|
+
|
|
74
|
+
let childModuleLines =
|
|
75
|
+
childModules
|
|
76
|
+
?.filter((m) => path.basename(m, ".ts") !== "index")
|
|
77
|
+
.map((child) => {
|
|
78
|
+
const childBase = path.basename(child, ".ts");
|
|
79
|
+
return ` await import("./${childBase}.js").then((m) => m.createModule(module));`;
|
|
80
|
+
}) ?? [];
|
|
81
|
+
|
|
82
|
+
if (childModuleLines.length > 0) {
|
|
83
|
+
childModuleLines = [" // Child modules", ...childModuleLines, ""];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const transformed = [
|
|
87
|
+
"// Copyright (c) Microsoft Corporation",
|
|
88
|
+
"// Licensed under the MIT license.",
|
|
89
|
+
"",
|
|
90
|
+
`import { Module } from "${path.relative(targetDir, ctxPath).replace(/\\/g, "/")}";`,
|
|
91
|
+
"",
|
|
92
|
+
"export let module: Module = undefined as any;",
|
|
93
|
+
"",
|
|
94
|
+
"// prettier-ignore",
|
|
95
|
+
"const lines = [",
|
|
96
|
+
...contents.split(/\r?\n/).map((line) => " " + JSON.stringify(line) + ","),
|
|
97
|
+
"];",
|
|
98
|
+
"",
|
|
99
|
+
"export async function createModule(parent: Module): Promise<Module> {",
|
|
100
|
+
" if (module) return module;",
|
|
101
|
+
"",
|
|
102
|
+
" module = {",
|
|
103
|
+
` name: ${JSON.stringify(targetBase)},`,
|
|
104
|
+
` cursor: parent.cursor.enter(${JSON.stringify(targetBase)}),`,
|
|
105
|
+
" imports: [],",
|
|
106
|
+
" declarations: [],",
|
|
107
|
+
" };",
|
|
108
|
+
"",
|
|
109
|
+
...childModuleLines,
|
|
110
|
+
" module.declarations.push(lines);",
|
|
111
|
+
"",
|
|
112
|
+
" parent.declarations.push(module);",
|
|
113
|
+
"",
|
|
114
|
+
" return module;",
|
|
115
|
+
"}",
|
|
116
|
+
"",
|
|
117
|
+
].join("\n");
|
|
118
|
+
|
|
119
|
+
await fs.writeFile(targetPath, transformed);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
console.log("Building index files.");
|
|
123
|
+
|
|
124
|
+
for (const [dir, files] of indices.entries()) {
|
|
125
|
+
console.log("Building index:", dir);
|
|
126
|
+
|
|
127
|
+
const relativePath = path.relative(HELPER_SRC_PATH, dir);
|
|
128
|
+
|
|
129
|
+
const targetPath = path.resolve(HELPER_DECLARATION_PATH, relativePath, "index.ts");
|
|
130
|
+
|
|
131
|
+
const children = files.map((file) => {
|
|
132
|
+
return ` await import("./${path.basename(file, ".ts")}.js").then((m) => m.createModule(module));`;
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const transformed = [
|
|
136
|
+
"// Copyright (c) Microsoft Corporation",
|
|
137
|
+
"// Licensed under the MIT license.",
|
|
138
|
+
"",
|
|
139
|
+
`import { Module } from "${path.relative(path.dirname(targetPath), ctxPath).replace(/\\/g, "/")}";`,
|
|
140
|
+
"",
|
|
141
|
+
"export let module: Module = undefined as any;",
|
|
142
|
+
"",
|
|
143
|
+
"export async function createModule(parent: Module): Promise<Module> {",
|
|
144
|
+
" if (module) return module;",
|
|
145
|
+
"",
|
|
146
|
+
" module = {",
|
|
147
|
+
` name: ${JSON.stringify(path.basename(dir))},`,
|
|
148
|
+
` cursor: parent.cursor.enter(${JSON.stringify(path.basename(dir))}),`,
|
|
149
|
+
" imports: [],",
|
|
150
|
+
" declarations: [],",
|
|
151
|
+
" };",
|
|
152
|
+
"",
|
|
153
|
+
" // Child modules",
|
|
154
|
+
...children,
|
|
155
|
+
"",
|
|
156
|
+
" parent.declarations.push(module);",
|
|
157
|
+
"",
|
|
158
|
+
" return module;",
|
|
159
|
+
"}",
|
|
160
|
+
"",
|
|
161
|
+
].join("\n");
|
|
162
|
+
|
|
163
|
+
await fs.writeFile(targetPath, transformed);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
main().catch((err) => {
|
|
168
|
+
console.error(err);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../../generated-defs/helpers/header.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,eAAO,IAAI,MAAM,EAAE,MAAyB,CAAC;AA8D7C,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAelE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
export let module = undefined;
|
|
4
|
+
// prettier-ignore
|
|
5
|
+
const lines = [
|
|
6
|
+
"// Copyright (c) Microsoft Corporation",
|
|
7
|
+
"// Licensed under the MIT license.",
|
|
8
|
+
"",
|
|
9
|
+
"export interface HeaderValueParameters {",
|
|
10
|
+
" value: string;",
|
|
11
|
+
" verbatim: string;",
|
|
12
|
+
" params: { [k: string]: string };",
|
|
13
|
+
"}",
|
|
14
|
+
"",
|
|
15
|
+
"/**",
|
|
16
|
+
" * Parses a header value that may contain additional parameters (e.g. `text/html; charset=utf-8`).",
|
|
17
|
+
" * @param headerValueText - the text of the header value to parse",
|
|
18
|
+
" * @returns an object containing the value and a map of parameters",
|
|
19
|
+
" */",
|
|
20
|
+
"export function parseHeaderValueParameters<Header extends string | undefined>(",
|
|
21
|
+
" headerValueText: Header,",
|
|
22
|
+
"): undefined extends Header ? HeaderValueParameters | undefined : HeaderValueParameters {",
|
|
23
|
+
" if (headerValueText === undefined) {",
|
|
24
|
+
" return undefined as any;",
|
|
25
|
+
" }",
|
|
26
|
+
"",
|
|
27
|
+
" const idx = headerValueText.indexOf(\";\");",
|
|
28
|
+
" const [value, _paramsText] =",
|
|
29
|
+
" idx === -1",
|
|
30
|
+
" ? [headerValueText, \"\"]",
|
|
31
|
+
" : [headerValueText.slice(0, idx), headerValueText.slice(idx + 1)];",
|
|
32
|
+
"",
|
|
33
|
+
" let paramsText = _paramsText;",
|
|
34
|
+
"",
|
|
35
|
+
" // Parameters are a sequence of key=value pairs separated by semicolons, but the value may be quoted in which case it",
|
|
36
|
+
" // may contain semicolons. We use a regular expression to iteratively split the parameters into key=value pairs.",
|
|
37
|
+
" const params: { [k: string]: string } = {};",
|
|
38
|
+
"",
|
|
39
|
+
" let match;",
|
|
40
|
+
"",
|
|
41
|
+
" // TODO: may need to support ext-parameter (e.g. \"filename*=UTF-8''%e2%82%ac%20rates\" => { filename: \"€ rates\" }).",
|
|
42
|
+
" // By default we decoded everything as UTF-8, and non-UTF-8 agents are a dying breed, but we may need to support",
|
|
43
|
+
" // this for completeness. If we do support it, we'll prefer an ext-parameter over a regular parameter. Currently, we'll",
|
|
44
|
+
" // just treat them as separate keys and put the raw value in the parameter.",
|
|
45
|
+
" //",
|
|
46
|
+
" // https://datatracker.ietf.org/doc/html/rfc5987#section-3.2.1",
|
|
47
|
+
" while ((match = paramsText.match(/\\s*([^=]+)=(?:\"([^\"]+)\"|([^;]+));?/))) {",
|
|
48
|
+
" const [, key, quotedValue, unquotedValue] = match;",
|
|
49
|
+
"",
|
|
50
|
+
" params[key.trim()] = quotedValue ?? unquotedValue;",
|
|
51
|
+
"",
|
|
52
|
+
" paramsText = paramsText.slice(match[0].length);",
|
|
53
|
+
" }",
|
|
54
|
+
"",
|
|
55
|
+
" return {",
|
|
56
|
+
" value: value.trim(),",
|
|
57
|
+
" verbatim: headerValueText,",
|
|
58
|
+
" params,",
|
|
59
|
+
" };",
|
|
60
|
+
"}",
|
|
61
|
+
"",
|
|
62
|
+
];
|
|
63
|
+
export async function createModule(parent) {
|
|
64
|
+
if (module)
|
|
65
|
+
return module;
|
|
66
|
+
module = {
|
|
67
|
+
name: "header",
|
|
68
|
+
cursor: parent.cursor.enter("header"),
|
|
69
|
+
imports: [],
|
|
70
|
+
declarations: [],
|
|
71
|
+
};
|
|
72
|
+
module.declarations.push(lines);
|
|
73
|
+
parent.declarations.push(module);
|
|
74
|
+
return module;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header.js","sourceRoot":"","sources":["../../../generated-defs/helpers/header.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AAIlC,MAAM,CAAC,IAAI,MAAM,GAAW,SAAgB,CAAC;AAE7C,kBAAkB;AAClB,MAAM,KAAK,GAAG;IACZ,wCAAwC;IACxC,oCAAoC;IACpC,EAAE;IACF,0CAA0C;IAC1C,kBAAkB;IAClB,qBAAqB;IACrB,oCAAoC;IACpC,GAAG;IACH,EAAE;IACF,KAAK;IACL,oGAAoG;IACpG,mEAAmE;IACnE,oEAAoE;IACpE,KAAK;IACL,gFAAgF;IAChF,4BAA4B;IAC5B,2FAA2F;IAC3F,wCAAwC;IACxC,8BAA8B;IAC9B,KAAK;IACL,EAAE;IACF,+CAA+C;IAC/C,gCAAgC;IAChC,gBAAgB;IAChB,iCAAiC;IACjC,0EAA0E;IAC1E,EAAE;IACF,iCAAiC;IACjC,EAAE;IACF,yHAAyH;IACzH,oHAAoH;IACpH,+CAA+C;IAC/C,EAAE;IACF,cAAc;IACd,EAAE;IACF,0HAA0H;IAC1H,oHAAoH;IACpH,2HAA2H;IAC3H,+EAA+E;IAC/E,MAAM;IACN,kEAAkE;IAClE,kFAAkF;IAClF,wDAAwD;IACxD,EAAE;IACF,wDAAwD;IACxD,EAAE;IACF,qDAAqD;IACrD,KAAK;IACL,EAAE;IACF,YAAY;IACZ,0BAA0B;IAC1B,gCAAgC;IAChC,aAAa;IACb,MAAM;IACN,GAAG;IACH,EAAE;CACH,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc;IAC/C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,GAAG;QACP,IAAI,EAAE,QAAQ;QACd,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC;QACrC,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,EAAE;KACjB,CAAC;IAEF,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEhC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../generated-defs/helpers/http.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,eAAO,IAAI,MAAM,EAAE,MAAyB,CAAC;AAwH7C,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAelE"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// Copyright (c) Microsoft Corporation
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
export let module = undefined;
|
|
4
|
+
// prettier-ignore
|
|
5
|
+
const lines = [
|
|
6
|
+
"// Copyright (c) Microsoft Corporation.",
|
|
7
|
+
"// Licensed under the MIT License.",
|
|
8
|
+
"",
|
|
9
|
+
"import { HttpContext } from \"./router.js\";",
|
|
10
|
+
"",
|
|
11
|
+
"export const HTTP_RESPONDER = Symbol.for(\"@typespec/http-server-js.HttpResponder\");",
|
|
12
|
+
"",
|
|
13
|
+
"/**",
|
|
14
|
+
" * A type that can respond to an HTTP request.",
|
|
15
|
+
" */",
|
|
16
|
+
"export interface HttpResponder {",
|
|
17
|
+
" /**",
|
|
18
|
+
" * A function that handles an HTTP request and response.",
|
|
19
|
+
" *",
|
|
20
|
+
" * @param context - The HTTP context.",
|
|
21
|
+
" */",
|
|
22
|
+
" [HTTP_RESPONDER]: (context: HttpContext) => void;",
|
|
23
|
+
"}",
|
|
24
|
+
"",
|
|
25
|
+
"/**",
|
|
26
|
+
" * Determines if a value is an HttpResponder.",
|
|
27
|
+
" * @param value - The value to check.",
|
|
28
|
+
" * @returns `true` if the value is an HttpResponder, otherwise `false`.",
|
|
29
|
+
" */",
|
|
30
|
+
"export function isHttpResponder(value: unknown): value is HttpResponder {",
|
|
31
|
+
" return (",
|
|
32
|
+
" typeof value === \"object\" &&",
|
|
33
|
+
" value !== null &&",
|
|
34
|
+
" HTTP_RESPONDER in value &&",
|
|
35
|
+
" typeof value[HTTP_RESPONDER] === \"function\"",
|
|
36
|
+
" );",
|
|
37
|
+
"}",
|
|
38
|
+
"",
|
|
39
|
+
"/**",
|
|
40
|
+
" * An Error that can respond to an HTTP request if thrown from a route handler.",
|
|
41
|
+
" */",
|
|
42
|
+
"export class HttpResponderError extends Error implements HttpResponder {",
|
|
43
|
+
" #statusCode: number;",
|
|
44
|
+
"",
|
|
45
|
+
" constructor(statusCode: number, message: string) {",
|
|
46
|
+
" super(message);",
|
|
47
|
+
" this.#statusCode = statusCode;",
|
|
48
|
+
" }",
|
|
49
|
+
"",
|
|
50
|
+
" [HTTP_RESPONDER](ctx: HttpContext): void {",
|
|
51
|
+
" ctx.response.statusCode = this.#statusCode;",
|
|
52
|
+
" ctx.response.setHeader(\"Content-Type\", \"text/plain\");",
|
|
53
|
+
" ctx.response.end(this.message);",
|
|
54
|
+
" }",
|
|
55
|
+
"}",
|
|
56
|
+
"",
|
|
57
|
+
"/**",
|
|
58
|
+
" * The requested resource was not found.",
|
|
59
|
+
" */",
|
|
60
|
+
"export class NotFoundError extends HttpResponderError {",
|
|
61
|
+
" constructor() {",
|
|
62
|
+
" super(404, \"Not Found\");",
|
|
63
|
+
" }",
|
|
64
|
+
"}",
|
|
65
|
+
"",
|
|
66
|
+
"/**",
|
|
67
|
+
" * The request was malformed.",
|
|
68
|
+
" */",
|
|
69
|
+
"export class BadRequestError extends HttpResponderError {",
|
|
70
|
+
" constructor() {",
|
|
71
|
+
" super(400, \"Bad Request\");",
|
|
72
|
+
" }",
|
|
73
|
+
"}",
|
|
74
|
+
"",
|
|
75
|
+
"/**",
|
|
76
|
+
" * The request is missing required authentication credentials.",
|
|
77
|
+
" */",
|
|
78
|
+
"export class UnauthorizedError extends HttpResponderError {",
|
|
79
|
+
" constructor() {",
|
|
80
|
+
" super(401, \"Unauthorized\");",
|
|
81
|
+
" }",
|
|
82
|
+
"}",
|
|
83
|
+
"",
|
|
84
|
+
"/**",
|
|
85
|
+
" * The request is missing required permissions.",
|
|
86
|
+
" */",
|
|
87
|
+
"export class ForbiddenError extends HttpResponderError {",
|
|
88
|
+
" constructor() {",
|
|
89
|
+
" super(403, \"Forbidden\");",
|
|
90
|
+
" }",
|
|
91
|
+
"}",
|
|
92
|
+
"",
|
|
93
|
+
"/**",
|
|
94
|
+
" * The request conflicts with the current state of the server.",
|
|
95
|
+
" */",
|
|
96
|
+
"export class ConflictError extends HttpResponderError {",
|
|
97
|
+
" constructor() {",
|
|
98
|
+
" super(409, \"Conflict\");",
|
|
99
|
+
" }",
|
|
100
|
+
"}",
|
|
101
|
+
"",
|
|
102
|
+
"/**",
|
|
103
|
+
" * The server encountered an unexpected condition that prevented it from fulfilling the request.",
|
|
104
|
+
" */",
|
|
105
|
+
"export class InternalServerError extends HttpResponderError {",
|
|
106
|
+
" constructor() {",
|
|
107
|
+
" super(500, \"Internal Server Error\");",
|
|
108
|
+
" }",
|
|
109
|
+
"}",
|
|
110
|
+
"",
|
|
111
|
+
"/**",
|
|
112
|
+
" * The server does not support the functionality required to fulfill the request.",
|
|
113
|
+
" */",
|
|
114
|
+
"export class NotImplementedError extends HttpResponderError {",
|
|
115
|
+
" constructor() {",
|
|
116
|
+
" super(501, \"Not Implemented\");",
|
|
117
|
+
" }",
|
|
118
|
+
"}",
|
|
119
|
+
"",
|
|
120
|
+
];
|
|
121
|
+
export async function createModule(parent) {
|
|
122
|
+
if (module)
|
|
123
|
+
return module;
|
|
124
|
+
module = {
|
|
125
|
+
name: "http",
|
|
126
|
+
cursor: parent.cursor.enter("http"),
|
|
127
|
+
imports: [],
|
|
128
|
+
declarations: [],
|
|
129
|
+
};
|
|
130
|
+
module.declarations.push(lines);
|
|
131
|
+
parent.declarations.push(module);
|
|
132
|
+
return module;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../../generated-defs/helpers/http.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,kCAAkC;AAIlC,MAAM,CAAC,IAAI,MAAM,GAAW,SAAgB,CAAC;AAE7C,kBAAkB;AAClB,MAAM,KAAK,GAAG;IACZ,yCAAyC;IACzC,oCAAoC;IACpC,EAAE;IACF,8CAA8C;IAC9C,EAAE;IACF,uFAAuF;IACvF,EAAE;IACF,KAAK;IACL,gDAAgD;IAChD,KAAK;IACL,kCAAkC;IAClC,OAAO;IACP,4DAA4D;IAC5D,MAAM;IACN,yCAAyC;IACzC,OAAO;IACP,qDAAqD;IACrD,GAAG;IACH,EAAE;IACF,KAAK;IACL,+CAA+C;IAC/C,uCAAuC;IACvC,yEAAyE;IACzE,KAAK;IACL,2EAA2E;IAC3E,YAAY;IACZ,oCAAoC;IACpC,uBAAuB;IACvB,gCAAgC;IAChC,mDAAmD;IACnD,MAAM;IACN,GAAG;IACH,EAAE;IACF,KAAK;IACL,iFAAiF;IACjF,KAAK;IACL,0EAA0E;IAC1E,wBAAwB;IACxB,EAAE;IACF,sDAAsD;IACtD,qBAAqB;IACrB,oCAAoC;IACpC,KAAK;IACL,EAAE;IACF,8CAA8C;IAC9C,iDAAiD;IACjD,+DAA+D;IAC/D,qCAAqC;IACrC,KAAK;IACL,GAAG;IACH,EAAE;IACF,KAAK;IACL,0CAA0C;IAC1C,KAAK;IACL,yDAAyD;IACzD,mBAAmB;IACnB,gCAAgC;IAChC,KAAK;IACL,GAAG;IACH,EAAE;IACF,KAAK;IACL,+BAA+B;IAC/B,KAAK;IACL,2DAA2D;IAC3D,mBAAmB;IACnB,kCAAkC;IAClC,KAAK;IACL,GAAG;IACH,EAAE;IACF,KAAK;IACL,gEAAgE;IAChE,KAAK;IACL,6DAA6D;IAC7D,mBAAmB;IACnB,mCAAmC;IACnC,KAAK;IACL,GAAG;IACH,EAAE;IACF,KAAK;IACL,iDAAiD;IACjD,KAAK;IACL,0DAA0D;IAC1D,mBAAmB;IACnB,gCAAgC;IAChC,KAAK;IACL,GAAG;IACH,EAAE;IACF,KAAK;IACL,gEAAgE;IAChE,KAAK;IACL,yDAAyD;IACzD,mBAAmB;IACnB,+BAA+B;IAC/B,KAAK;IACL,GAAG;IACH,EAAE;IACF,KAAK;IACL,kGAAkG;IAClG,KAAK;IACL,+DAA+D;IAC/D,mBAAmB;IACnB,4CAA4C;IAC5C,KAAK;IACL,GAAG;IACH,EAAE;IACF,KAAK;IACL,mFAAmF;IACnF,KAAK;IACL,+DAA+D;IAC/D,mBAAmB;IACnB,sCAAsC;IACtC,KAAK;IACL,GAAG;IACH,EAAE;CACH,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAc;IAC/C,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAE1B,MAAM,GAAG;QACP,IAAI,EAAE,MAAM;QACZ,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;QACnC,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,EAAE;KACjB,CAAC;IAEF,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEhC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEjC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|