typespec-typescript-emitter 1.1.0 → 1.1.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.
- package/.husky/pre-commit +1 -0
- package/CHANGELOG.md +16 -18
- package/README.md +128 -22
- package/dist/src/emit_mapped_types.js +63 -20
- package/dist/src/emit_mapped_types.js.map +1 -1
- package/dist/src/emit_routes.js +9 -6
- package/dist/src/emit_routes.js.map +1 -1
- package/dist/src/emit_types.js +18 -3
- package/dist/src/emit_types.js.map +1 -1
- package/dist/src/emit_types_resolve.d.ts +19 -7
- package/dist/src/emit_types_resolve.js +91 -31
- package/dist/src/emit_types_resolve.js.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js.map +1 -1
- package/eslint.config.js +2 -0
- package/package.json +8 -4
- package/src/emit_mapped_types.ts +86 -31
- package/src/emit_routes.ts +15 -9
- package/src/emit_types.ts +19 -3
- package/src/emit_types_resolve.ts +119 -74
- package/src/index.ts +1 -1
- package/test/main.test.ts +83 -0
- package/test/out/.gitkeep +0 -0
- package/test/runner.ts +5 -0
- package/test/targets/enum.routed-types.ts +59 -0
- package/test/targets/enum.routes.ts +29 -0
- package/test/targets/enum.target.ts +39 -0
- package/test/targets/enum.tsp +36 -0
- package/test/targets/pr8.routed-types.ts +131 -0
- package/test/targets/pr8.routes.ts +30 -0
- package/test/targets/pr8.target.ts +97 -0
- package/test/targets/pr8.tsp +62 -0
- package/test/targets/simple-routes.routed-types.ts +64 -0
- package/test/targets/simple-routes.routes.ts +29 -0
- package/test/targets/simple-routes.target.ts +21 -0
- package/test/targets/simple-routes.tsp +23 -0
- package/test/targets/union.routed-types.ts +59 -0
- package/test/targets/union.routes.ts +23 -0
- package/test/targets/union.target.ts +59 -0
- package/test/targets/union.tsp +38 -0
- package/test/targets/visibility.routed-types.ts +81 -0
- package/test/targets/visibility.routes.ts +38 -0
- package/test/targets/visibility.target.ts +36 -0
- package/test/targets/visibility.tsp +49 -0
- package/tsconfig.json +1 -1
- package/vitest.config.ts +10 -0
- package/dist/src/testing/index.d.ts +0 -2
- package/dist/src/testing/index.js +0 -8
- package/dist/src/testing/index.js.map +0 -1
- package/dist/test/hello.test.d.ts +0 -1
- package/dist/test/hello.test.js +0 -10
- package/dist/test/hello.test.js.map +0 -1
- package/dist/test/test-host.d.ts +0 -5
- package/dist/test/test-host.js +0 -36
- package/dist/test/test-host.js.map +0 -1
- package/src/testing/index.ts +0 -12
- package/test/hello.test.ts +0 -10
- package/test/test-host.ts +0 -49
package/.husky/pre-commit
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,48 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# [1.0.0](https://github.com/crowbait/typespec-typescript-emitter/compare/v0.4.1...v1.0.0) (2025-03-13)
|
|
1
|
+
## [1.1.2](https://github.com/crowbait/typespec-typescript-emitter/compare/v1.1.1...v1.1.2) (2025-11-17)
|
|
6
2
|
|
|
7
3
|
|
|
8
|
-
* feat!: complete rework of routes emitter ([2f07e7f](https://github.com/crowbait/typespec-typescript-emitter/commit/2f07e7f487f0e6531b89e66f7de4d7d09382e4e5))
|
|
9
4
|
|
|
5
|
+
## [1.1.1](https://github.com/crowbait/typespec-typescript-emitter/compare/v1.1.0...v1.1.1) (2025-09-26)
|
|
10
6
|
|
|
11
|
-
### Features
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
### Bug Fixes
|
|
14
9
|
|
|
10
|
+
* routed typemap respects visibility modifiers ([13c0a45](https://github.com/crowbait/typespec-typescript-emitter/commit/13c0a45f38b949a36ad2e8b6c40a1829ff3b54da))
|
|
11
|
+
* routed-typemap handling of multiple verbs on same path ([f33e6d9](https://github.com/crowbait/typespec-typescript-emitter/commit/f33e6d94d78523206813ab4191feee29cb6c3b2e))
|
|
12
|
+
* routes / routed typemap emitters now resolve ops inside interfaces ([21504bc](https://github.com/crowbait/typespec-typescript-emitter/commit/21504bc74cc4f77aeac1f1bcb4e52a42917d9146))
|
|
13
|
+
* thorough resolution of nested types in typemap ([95af299](https://github.com/crowbait/typespec-typescript-emitter/commit/95af299b662dbcba0d21b56aa8ebe2f91c6e6e92))
|
|
15
14
|
|
|
16
|
-
### BREAKING CHANGES
|
|
17
15
|
|
|
18
|
-
* This breaks existing configurations and - depending on how it was used - usage of the emitted routes object.
|
|
19
16
|
|
|
17
|
+
# [1.1.0](https://github.com/crowbait/typespec-typescript-emitter/compare/v1.0.0...v1.1.0) (2025-05-23)
|
|
20
18
|
|
|
21
19
|
|
|
22
|
-
## [0.4.1](https://github.com/crowbait/typespec-typescript-emitter/compare/v0.4.0...v0.4.1) (2025-02-25)
|
|
23
20
|
|
|
21
|
+
# [1.0.0](https://github.com/crowbait/typespec-typescript-emitter/compare/v0.4.1...v1.0.0) (2025-03-13)
|
|
24
22
|
|
|
25
|
-
### Bug Fixes
|
|
26
23
|
|
|
27
|
-
*
|
|
24
|
+
* feat!: complete rework of routes emitter ([2f07e7f](https://github.com/crowbait/typespec-typescript-emitter/commit/2f07e7f487f0e6531b89e66f7de4d7d09382e4e5))
|
|
28
25
|
|
|
29
26
|
|
|
27
|
+
### Features
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
* routed typemap ([0a57f43](https://github.com/crowbait/typespec-typescript-emitter/commit/0a57f439e6f483c35b00824c725aecc66d3a80df))
|
|
32
30
|
|
|
33
31
|
|
|
34
|
-
###
|
|
32
|
+
### BREAKING CHANGES
|
|
35
33
|
|
|
36
|
-
*
|
|
34
|
+
* This breaks existing configurations and - depending on how it was used - usage of the emitted routes object.
|
|
37
35
|
|
|
38
36
|
|
|
39
37
|
|
|
40
|
-
## [0.
|
|
38
|
+
## [0.4.1](https://github.com/crowbait/typespec-typescript-emitter/compare/v0.4.0...v0.4.1) (2025-02-25)
|
|
41
39
|
|
|
42
40
|
|
|
43
41
|
### Bug Fixes
|
|
44
42
|
|
|
45
|
-
*
|
|
43
|
+
* fixed eslint ignore directives ([9c0477a](https://github.com/crowbait/typespec-typescript-emitter/commit/9c0477a6925715b99c38d4133d04ee774a0a65f7))
|
|
46
44
|
|
|
47
45
|
|
|
48
46
|
|
package/README.md
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
# typespec-typescript-emitter
|
|
2
2
|
|
|
3
|
-
This is a [TypeSpec](https://typespec.io) library aiming to provide
|
|
4
|
-
TypeScript output to a TypeSpec project.
|
|
3
|
+
This is a [TypeSpec](https://typespec.io) library aiming to provide TypeScript output to a TypeSpec project.
|
|
5
4
|
|
|
6
|
-
Currently, this library is tailored to my specific use case, which is defining
|
|
7
|
-
|
|
5
|
+
Currently, this library is tailored to my specific use case, which is defining HTTP APIs.
|
|
6
|
+
The 'routes'-emitter will only work on HTTP operations. **However**, exporting all models as types is independent of HTTP, and so may also benefit projects with a different usage scenario.
|
|
8
7
|
|
|
9
8
|
It can the following things:
|
|
10
9
|
|
|
11
|
-
- ts files exporting every model present in
|
|
12
|
-
- 1 file for each
|
|
10
|
+
- ts files exporting every model present in a namespace
|
|
11
|
+
- 1 file for each nested namespace
|
|
13
12
|
- exports models, enums and unions
|
|
14
13
|
- does NOT export aliases (see below)
|
|
15
14
|
- optional typeguards, *if* type export is enabled
|
|
16
|
-
|
|
17
|
-
- for `TypeSpec.Http`:
|
|
18
|
-
- this can be imported at runtime to provide a robust way of eg. accessing URLs
|
|
15
|
+
- for `TypeSpec.Http`: ts file containing a nested object (by namespace-opname) containing information about every route (eg. url-from-parameters, method, etc.)
|
|
16
|
+
- for `TypeSpec.Http`: "routed typemap" mapping types to their routes (path and verb) (respects Lifecycle visibility)
|
|
19
17
|
|
|
20
18
|
## Content <!-- omit from toc -->
|
|
21
19
|
|
|
22
|
-
- [
|
|
23
|
-
- [
|
|
24
|
-
- [
|
|
25
|
-
- [
|
|
26
|
-
- [
|
|
20
|
+
- [typespec-typescript-emitter](#typespec-typescript-emitter)
|
|
21
|
+
- [Installation](#installation)
|
|
22
|
+
- [Configuration](#configuration)
|
|
23
|
+
- [Types Emitter](#types-emitter)
|
|
24
|
+
- [Aliases](#aliases)
|
|
25
|
+
- [Routes Emitter](#routes-emitter)
|
|
26
|
+
- [Routed Typemap](#routed-typemap)
|
|
27
27
|
|
|
28
28
|
## Installation
|
|
29
29
|
|
|
@@ -45,6 +45,7 @@ options:
|
|
|
45
45
|
enable-types: true
|
|
46
46
|
enable-typeguards: false
|
|
47
47
|
enable-routes: false
|
|
48
|
+
enable-routed-typemap: false
|
|
48
49
|
```
|
|
49
50
|
|
|
50
51
|
The following options are available:
|
|
@@ -54,15 +55,21 @@ The following options are available:
|
|
|
54
55
|
- `enable-types` (default: true): enables output of TypeScript types.
|
|
55
56
|
- `enable-typeguards` (default: false): enables output of typeguards, *IF* type-output is enabled.
|
|
56
57
|
- `enable-routes` (default: false): enables output of the HTTP-routes object.
|
|
58
|
+
- `enable-routed-typemap` (default: false): enables output of an indexable type mapping paths and HTTP verbs to request and response bodies.
|
|
57
59
|
|
|
58
|
-
## Types
|
|
60
|
+
## Types Emitter
|
|
59
61
|
|
|
60
62
|
This emitter will traverse your configured root namespace and all nested namespaces, generating a `{namespace-name}.ts`-file.
|
|
61
63
|
|
|
62
|
-
The emitter can handle `Model`s, `Enum`s and `Union`s. ~~`Alias`'s~~ are
|
|
64
|
+
The emitter can handle `Model`s, `Enum`s and `Union`s. ~~`Alias`'s~~ are *not* emitted - more on that [later](#aliases). It will also preserve docs as JSDoc-style comments.
|
|
63
65
|
|
|
64
66
|
The emitter should be able to handle most basic TS contructs, like scalars, literals, object, arrays, tuples and intrinsics (eg. `null`).
|
|
65
67
|
|
|
68
|
+
> [!IMPORTANT]
|
|
69
|
+
> These types do not respect most transformative decorators, notable `@visibility`.
|
|
70
|
+
> This is because it's non-trivial to do, has unexpected problems and the functionality is *somewhat* already there, in the form of [Routed Typemaps](#routed-typemap).
|
|
71
|
+
> For additional information, see [#7](https://github.com/crowbait/typespec-typescript-emitter/issues/7).
|
|
72
|
+
|
|
66
73
|
Example:
|
|
67
74
|
|
|
68
75
|
```ts
|
|
@@ -126,9 +133,9 @@ export function isBook(arg: any): arg is Book {
|
|
|
126
133
|
Typeguards *should* create comprehensive checks that adhere as strictly to the source model as possible.
|
|
127
134
|
If you find a case where the typeguard is looser than it needs to be, please report that as a bug.
|
|
128
135
|
|
|
129
|
-
###
|
|
136
|
+
### Aliases
|
|
130
137
|
|
|
131
|
-
There seems to be no way to extract aliases from TypeSpec's emitter framework. Because of that, `Alias`
|
|
138
|
+
There seems to be no way to extract aliases from TypeSpec's emitter framework. Because of that, `Alias`es are ignored by the emitter (or, to be more precise: `Alias`es reach the emitter already resolved. They won't be exported as their own type but directly substituted where they're needed).
|
|
132
139
|
|
|
133
140
|
That means, if you want something to be emitted, it can't be an alias:
|
|
134
141
|
|
|
@@ -145,16 +152,17 @@ alias Derived1 = OmitProperties<Demo, "prop1">;
|
|
|
145
152
|
model Derived2 {...OmitProperties<Demo, "prop1">};
|
|
146
153
|
```
|
|
147
154
|
|
|
148
|
-
## Routes
|
|
155
|
+
## Routes Emitter
|
|
149
156
|
|
|
150
157
|
**This emitter depends on your use of the `TypeSpec.Http` library**.
|
|
151
158
|
|
|
152
159
|
If you're using `TypeSpec.Http` to define your API routes and endpoints, this library offers an emitter to export a `routes` object.
|
|
153
160
|
It will generate a nested object containing information about every `op` you have defined, nested by namespace.
|
|
154
161
|
I contains the following data (per `op`):
|
|
162
|
+
|
|
155
163
|
- `method`: HTTP method
|
|
156
|
-
- `path`: Path (as defined
|
|
157
|
-
- `getUrl`: Function for generating a valid URL to this `op`; if the path has parameters, this function will have
|
|
164
|
+
- `path`: Path (as defined in the `route` string; parameters are not substituted)
|
|
165
|
+
- `getUrl`: Function for generating a valid URL to this `op`; if the path has parameters, this function will have matching parameters
|
|
158
166
|
- `auth`: Array of valid authentication schemes (or `[null]`, if none)
|
|
159
167
|
Just as the types emitter, this emitter will also preserve docs as JSDoc-style comments.
|
|
160
168
|
|
|
@@ -212,4 +220,102 @@ export const routes_myProject = {
|
|
|
212
220
|
}
|
|
213
221
|
}
|
|
214
222
|
} as const;
|
|
215
|
-
```
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Routed Typemap
|
|
226
|
+
|
|
227
|
+
This emitter produces a Typemap (a typescript type indexed by string keys mapping other types) based on your HTTP routes and verbs.
|
|
228
|
+
In short, this allows you to select a type *used in a body of your HTTP ops* using it's path and verb. This includes request and response bodies. Path parameters are not relevant for this emitter; those are already handled in the Routes object.
|
|
229
|
+
This can be helpful when, for example, building a wrapper around your API.
|
|
230
|
+
|
|
231
|
+
> [!NOTE]
|
|
232
|
+
> The Typemap is not nested! This means that, let's say the route "/user/account" will not be mapped to `{user: {account: /* ... */}}` (somewhat similar to how the Routes Emitter works), but to `{"/user/account": /* ... */}`. Crucially, those map keys are *the same as the `path` property in the Routes object* emitted from the Routes Emitter.
|
|
233
|
+
> This means you can select from the Typemap *using* the structured Routes object.
|
|
234
|
+
|
|
235
|
+
Example:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
@route("/typemap")
|
|
239
|
+
namespace namespaceA.typemap {
|
|
240
|
+
model ModelA {
|
|
241
|
+
id: int32,
|
|
242
|
+
name: string
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@get
|
|
246
|
+
op getAll(): {@body body: ModelA[]} | {@statusCode status: 418, @body body: "Me teapot"};
|
|
247
|
+
|
|
248
|
+
@post
|
|
249
|
+
op add(@body body: ModelA): OkResponse;
|
|
250
|
+
|
|
251
|
+
@post
|
|
252
|
+
@route("{id}")
|
|
253
|
+
op getOne(
|
|
254
|
+
@path id: int32
|
|
255
|
+
): {@body body: ModelA}| NotFoundResponse | {@statusCode status: 418} | {@statusCode status: 419, @body body: null};
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
...will be transformed into:
|
|
260
|
+
|
|
261
|
+
```ts
|
|
262
|
+
/* /path/to/outdir/routedTypemap_{root-namespace}.ts */
|
|
263
|
+
export type types_namespaceA = {
|
|
264
|
+
['/typemap']: {
|
|
265
|
+
['GET']: {
|
|
266
|
+
request: null
|
|
267
|
+
response: {status: 200, body: {
|
|
268
|
+
id: number,
|
|
269
|
+
name: string
|
|
270
|
+
}[]} | {status: 418, body: 'Me teapot'}
|
|
271
|
+
},
|
|
272
|
+
['POST']: {
|
|
273
|
+
request: {
|
|
274
|
+
id: number,
|
|
275
|
+
name: string
|
|
276
|
+
}
|
|
277
|
+
response: {status: 200, body: {
|
|
278
|
+
/** The status code. */
|
|
279
|
+
statusCode: 200
|
|
280
|
+
}}
|
|
281
|
+
}
|
|
282
|
+
},
|
|
283
|
+
['/typemap/{id}']: {
|
|
284
|
+
['POST']: {
|
|
285
|
+
request: null
|
|
286
|
+
response: {status: 200, body: {
|
|
287
|
+
id: number,
|
|
288
|
+
name: string
|
|
289
|
+
}} | {status: 404, body: {
|
|
290
|
+
/** The status code. */
|
|
291
|
+
statusCode: 404
|
|
292
|
+
}} | {status: 418, body: {
|
|
293
|
+
status: 418
|
|
294
|
+
}} | {status: 419, body: null}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
...which can be accessed like this:
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
// Accessing type of response body directly by knowing path and verb
|
|
304
|
+
type T_update1 = types_namespaceA['/typemap']['POST']['response']['body']
|
|
305
|
+
|
|
306
|
+
// Accessing type of request body by indexing Routes object
|
|
307
|
+
// namespace "namespaceA.typemap", op "add"
|
|
308
|
+
type T_update2 = types_namespaceA[typeof routes_namespaceA.typemap.add.path]['POST']['request']
|
|
309
|
+
// One could also use `typeof routes_namespace.testSimple.update.method` instead of 'POST'.
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
> [!NOTE]
|
|
313
|
+
> Observe how the emitter
|
|
314
|
+
>
|
|
315
|
+
> - assumes a `200` status code for an op's response type if you didn't define any (first responses on `getAll` and `getOne` ops)
|
|
316
|
+
> - assumes the entire response type is the body of no body is explicitely decorated (418 on `getOne` op) (this is non-standard; I have seen quite a few projects not realizing the response definition should have a body *in* it and treating the whole thing as a body; so while technically "wrong", this accomodates those projects. You can easily define a truly empty body using `{}`, `""`, `null`..., see 419 on `getOne` op)
|
|
317
|
+
|
|
318
|
+
Additional notes:
|
|
319
|
+
|
|
320
|
+
- There is currently no built-in way of accessing typeguards from paths their types may be associated with.
|
|
321
|
+
- Models are not reused in or imported by this emitter. Reasoning involves "no runtime overhead either way", "simpler code", "self-contained emitter modules" and "you're not supposed to rummage around in the generated files anyway, just import them"; this has been touched upon in [#4](https://github.com/crowbait/typespec-typescript-emitter/issues/4#issuecomment-2720955282) and [#6](https://github.com/crowbait/typespec-typescript-emitter/issues/6#issuecomment-3049999155).
|
|
@@ -1,22 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isTemplateDeclaration, } from "@typespec/compiler";
|
|
2
|
+
import { getHttpOperation, resolveRequestVisibility, Visibility, } from "@typespec/http";
|
|
2
3
|
import { resolveType } from "./emit_types_resolve.js";
|
|
3
4
|
export const emitRoutedTypemap = (context, namespace) => {
|
|
4
5
|
const ops = {};
|
|
5
6
|
const traverseNamespace = (n) => {
|
|
6
7
|
// operations
|
|
7
|
-
|
|
8
|
+
const processOp = (op) => {
|
|
8
9
|
const httpOp = getHttpOperation(context.program, op);
|
|
9
|
-
const
|
|
10
|
-
|
|
10
|
+
const path = httpOp[0].path;
|
|
11
|
+
const verb = httpOp[0].verb.toUpperCase();
|
|
12
|
+
if (!ops[path])
|
|
13
|
+
ops[path] = {};
|
|
14
|
+
ops[path][verb] = {
|
|
11
15
|
request: "null",
|
|
12
|
-
response: [{ status: 200, body: "
|
|
16
|
+
response: [{ status: 200, body: "{}" }],
|
|
13
17
|
};
|
|
14
18
|
// request
|
|
15
19
|
let request = "null";
|
|
16
|
-
if (
|
|
17
|
-
request = resolveType(
|
|
20
|
+
if (httpOp[0].parameters.body) {
|
|
21
|
+
request = resolveType(httpOp[0].parameters.body.type, {
|
|
22
|
+
nestlevel: 2,
|
|
23
|
+
currentNamespace: namespace,
|
|
24
|
+
context,
|
|
25
|
+
visibility: resolveRequestVisibility(context.program, op, httpOp[0].verb),
|
|
26
|
+
resolveEvenWithName: true,
|
|
27
|
+
}).replaceAll("\n", "\n ");
|
|
18
28
|
}
|
|
19
|
-
ops[
|
|
29
|
+
ops[path][verb].request = request;
|
|
20
30
|
// response
|
|
21
31
|
if (op.returnType && op.returnType.kind) {
|
|
22
32
|
const getReturnType = (t) => {
|
|
@@ -25,7 +35,7 @@ export const emitRoutedTypemap = (context, namespace) => {
|
|
|
25
35
|
// if the return type is a model, it may have a fully qualified body
|
|
26
36
|
const modelret = {
|
|
27
37
|
status: 200,
|
|
28
|
-
body: "
|
|
38
|
+
body: "{}",
|
|
29
39
|
};
|
|
30
40
|
let wasQualifiedBody = false;
|
|
31
41
|
t.properties.forEach((prop) => {
|
|
@@ -36,14 +46,26 @@ export const emitRoutedTypemap = (context, namespace) => {
|
|
|
36
46
|
modelret.status = prop.type.value;
|
|
37
47
|
// one of the properties may be the body definition
|
|
38
48
|
if (dec.definition?.name === "@body") {
|
|
39
|
-
modelret.body = resolveType(prop.type,
|
|
49
|
+
modelret.body = resolveType(prop.type, {
|
|
50
|
+
nestlevel: 2,
|
|
51
|
+
currentNamespace: namespace,
|
|
52
|
+
context,
|
|
53
|
+
visibility: Visibility.Read,
|
|
54
|
+
resolveEvenWithName: true,
|
|
55
|
+
}).replaceAll("\n", "\n ");
|
|
40
56
|
wasQualifiedBody = true;
|
|
41
57
|
}
|
|
42
58
|
});
|
|
43
59
|
});
|
|
44
60
|
// ... if not, we assume status 200 and treat the model as the body
|
|
45
61
|
if (!wasQualifiedBody) {
|
|
46
|
-
modelret.body = resolveType(t,
|
|
62
|
+
modelret.body = resolveType(t, {
|
|
63
|
+
nestlevel: 2,
|
|
64
|
+
currentNamespace: namespace,
|
|
65
|
+
context,
|
|
66
|
+
visibility: Visibility.Read,
|
|
67
|
+
resolveEvenWithName: true,
|
|
68
|
+
}).replaceAll("\n", "\n ");
|
|
47
69
|
}
|
|
48
70
|
ret.push(modelret);
|
|
49
71
|
}
|
|
@@ -55,24 +77,45 @@ export const emitRoutedTypemap = (context, namespace) => {
|
|
|
55
77
|
});
|
|
56
78
|
}
|
|
57
79
|
else
|
|
58
|
-
ret.push({
|
|
80
|
+
ret.push({
|
|
81
|
+
status: 200,
|
|
82
|
+
body: resolveType(t, {
|
|
83
|
+
nestlevel: 1,
|
|
84
|
+
currentNamespace: namespace,
|
|
85
|
+
context,
|
|
86
|
+
visibility: Visibility.Read,
|
|
87
|
+
resolveEvenWithName: true,
|
|
88
|
+
}),
|
|
89
|
+
});
|
|
59
90
|
return ret;
|
|
60
91
|
};
|
|
61
|
-
ops[
|
|
92
|
+
ops[path][verb].response = getReturnType(op.returnType);
|
|
62
93
|
}
|
|
63
|
-
}
|
|
94
|
+
}; // end operations
|
|
95
|
+
n.operations.forEach(processOp);
|
|
96
|
+
n.interfaces.forEach((itf) => {
|
|
97
|
+
if (!isTemplateDeclaration(itf))
|
|
98
|
+
itf.operations.forEach(processOp);
|
|
99
|
+
});
|
|
64
100
|
// get and traverse all namespaces
|
|
65
101
|
n.namespaces.forEach((ns) => traverseNamespace(ns));
|
|
66
102
|
};
|
|
67
103
|
traverseNamespace(namespace);
|
|
68
104
|
let out = `export type types_${context.options["root-namespace"]} = {\n`;
|
|
69
105
|
out += Object.entries(ops)
|
|
70
|
-
.map((
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
106
|
+
.map((path) => {
|
|
107
|
+
let pathret = ` ['${path[0]}']: {\n`;
|
|
108
|
+
pathret += Object.entries(path[1])
|
|
109
|
+
.map((verb) => {
|
|
110
|
+
let verbret = ` ['${verb[0]}']: {\n`;
|
|
111
|
+
verbret += ` request: ${verb[1].request}\n`;
|
|
112
|
+
verbret += ` response: ${verb[1].response.map((res) => `{status: ${res.status}, body: ${res.body}}`).join(" | ")}\n`;
|
|
113
|
+
verbret += " }";
|
|
114
|
+
return verbret;
|
|
115
|
+
})
|
|
116
|
+
.join(",\n");
|
|
117
|
+
pathret += "\n }";
|
|
118
|
+
return pathret;
|
|
76
119
|
})
|
|
77
120
|
.join(",\n");
|
|
78
121
|
out += "\n};\n";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit_mapped_types.js","sourceRoot":"","sources":["../../src/emit_mapped_types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"emit_mapped_types.js","sourceRoot":"","sources":["../../src/emit_mapped_types.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,GAItB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,gBAAgB,EAChB,wBAAwB,EACxB,UAAU,GACX,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,OAAoB,EACpB,SAAoB,EACZ,EAAE;IACV,MAAM,GAAG,GAQL,EAAE,CAAC;IAEP,MAAM,iBAAiB,GAAG,CAAC,CAAY,EAAQ,EAAE;QAC/C,aAAa;QACb,MAAM,SAAS,GAAG,CAAC,EAAa,EAAE,EAAE;YAClC,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACrD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YAC1C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YAC/B,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG;gBAChB,OAAO,EAAE,MAAM;gBACf,QAAQ,EAAE,C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,CAAC,CAAC,IAAI,EAAE,EAAE;YACZ,IAAI,OAAO,GAAG,SAAS,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;YACxC,OAAO,IAAI,kBAAkB,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,IAAI,CAAC;YACjD,OAAO,IAAI,mBAAmB,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,YAAY,GAAG,CAAC,MAAM,WAAW,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YAC1H,OAAO,IAAI,OAAO,CAAC;YACnB,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;aACD,IAAI,CAAC,KAAK,CAAC,CAAC;QACf,OAAO,IAAI,OAAO,CAAC;QACnB,OAAO,OAAO,CAAC;IACjB,CAAC,CAAC;SACD,IAAI,CAAC,KAAK,CAAC,CAAC;IACf,GAAG,IAAI,QAAQ,CAAC;IAChB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
package/dist/src/emit_routes.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { getDoc } from "@typespec/compiler";
|
|
1
|
+
import { getDoc, isTemplateDeclaration, } from "@typespec/compiler";
|
|
2
2
|
import { getAuthentication, getHttpOperation } from "@typespec/http";
|
|
3
3
|
export const emitRoutes = (context, namespace) => {
|
|
4
4
|
let out = `export const routes_${context.options["root-namespace"]} = {\n`;
|
|
5
5
|
const traverseNamespace = (n, nestLevel) => {
|
|
6
6
|
// operations
|
|
7
|
-
|
|
8
|
-
n.operations.forEach((op) => {
|
|
9
|
-
opnum++;
|
|
7
|
+
const processOp = (op) => {
|
|
10
8
|
const httpOp = getHttpOperation(context.program, op);
|
|
11
9
|
// jsdoc comment
|
|
12
10
|
const doc = getDoc(context.program, op);
|
|
@@ -58,8 +56,13 @@ export const emitRoutes = (context, namespace) => {
|
|
|
58
56
|
.join(", ")}}`)
|
|
59
57
|
.join(", ")}]`, nestLevel + 2);
|
|
60
58
|
// finalize route entry
|
|
61
|
-
out = out.addLine(
|
|
62
|
-
}
|
|
59
|
+
out = out.addLine("},", nestLevel + 1);
|
|
60
|
+
}; // end operations
|
|
61
|
+
n.operations.forEach(processOp);
|
|
62
|
+
n.interfaces.forEach((itf) => {
|
|
63
|
+
if (!isTemplateDeclaration(itf))
|
|
64
|
+
itf.operations.forEach(processOp);
|
|
65
|
+
});
|
|
63
66
|
// get and traverse all namespaces
|
|
64
67
|
let nsnum = 0;
|
|
65
68
|
n.namespaces.forEach((ns) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit_routes.js","sourceRoot":"","sources":["../../src/emit_routes.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"emit_routes.js","sourceRoot":"","sources":["../../src/emit_routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EACN,qBAAqB,GAGtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAErE,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,OAAoB,EACpB,SAAoB,EACZ,EAAE;IACV,IAAI,GAAG,GAAG,uBAAuB,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC;IAE3E,MAAM,iBAAiB,GAAG,CAAC,CAAY,EAAE,SAAiB,EAAQ,EAAE;QAClE,aAAa;QACb,MAAM,SAAS,GAAG,CAAC,EAAa,EAAE,EAAE;YAClC,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAErD,gBAAgB;YAChB,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACxC,IAAI,GAAG;gBAAE,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,OAA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GAAG,CAAC,CAAC,CAAC;YAClD,iBAAiB,CAAC,EAAE,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;YACrC,GAAG,GAAG,GAAG,CAAC,OAAO,CACf,IAAI,KAAK,GAAG,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAC1C,SAAS,GAAG,CAAC,CACd,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,iBAAiB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAChC,GAAG,IAAI,eAAe,CAAC;IACvB,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
package/dist/src/emit_types.js
CHANGED
|
@@ -7,7 +7,12 @@ const emitTypes = (context, namespace, options) => {
|
|
|
7
7
|
let file = "";
|
|
8
8
|
n.enums.forEach((e) => {
|
|
9
9
|
if (options["enable-types"]) {
|
|
10
|
-
const resolved = resolveEnum(e,
|
|
10
|
+
const resolved = resolveEnum(e, {
|
|
11
|
+
context: context,
|
|
12
|
+
currentNamespace: n,
|
|
13
|
+
nestlevel: 0,
|
|
14
|
+
isNamespaceRoot: true,
|
|
15
|
+
});
|
|
11
16
|
if (resolved) {
|
|
12
17
|
const doc = getDoc(context.program, e);
|
|
13
18
|
if (doc)
|
|
@@ -18,7 +23,12 @@ const emitTypes = (context, namespace, options) => {
|
|
|
18
23
|
});
|
|
19
24
|
n.unions.forEach((u) => {
|
|
20
25
|
if (options["enable-types"]) {
|
|
21
|
-
const resolved = resolveUnion(u,
|
|
26
|
+
const resolved = resolveUnion(u, {
|
|
27
|
+
currentNamespace: n,
|
|
28
|
+
context,
|
|
29
|
+
nestlevel: 0,
|
|
30
|
+
isNamespaceRoot: true,
|
|
31
|
+
});
|
|
22
32
|
if (resolved) {
|
|
23
33
|
const doc = getDoc(context.program, u);
|
|
24
34
|
if (doc)
|
|
@@ -29,7 +39,12 @@ const emitTypes = (context, namespace, options) => {
|
|
|
29
39
|
});
|
|
30
40
|
n.models.forEach((m) => {
|
|
31
41
|
if (options["enable-types"]) {
|
|
32
|
-
const resolved = resolveModel(m,
|
|
42
|
+
const resolved = resolveModel(m, {
|
|
43
|
+
nestlevel: 0,
|
|
44
|
+
currentNamespace: n,
|
|
45
|
+
context,
|
|
46
|
+
isNamespaceRoot: true,
|
|
47
|
+
});
|
|
33
48
|
if (resolved) {
|
|
34
49
|
const doc = getDoc(context.program, m);
|
|
35
50
|
if (doc)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emit_types.js","sourceRoot":"","sources":["../../src/emit_types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAa,MAAM,oBAAoB,CAAC;AACpE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAG/D,MAAM,SAAS,GAAG,CAChB,OAAoB,EACpB,SAAoB,EACpB,OAAuB,EAIvB,EAAE;IACF,MAAM,GAAG,GAAiC,EAAE,KAAK,EAAE,EAAE,EAAE,gBAAgB,EAAE,EAAE,EAAE,CAAC;IAE9E,MAAM,iBAAiB,GAAG,CAAC,CAAY,EAAQ,EAAE;QAC/C,IAAI,IAAI,GAAG,EAAE,CAAC;QAEd,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACpB,IAAI,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;gBAC5B,MAAM,QAAQ,GAAG,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"emit_types.js","sourceRoot":"","sources":["../../src/emit_types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAa,MAAM,oBAAoB,CAAC;AACpE,OAAO,EACL,WAAW,EACX,YAAY,EACZ,YAAY,GACb,MAAM,yBAAyB,CAAC;AAC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|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { Visibility } from "@typespec/http";
|
|
3
|
+
type CommonOptions = {
|
|
4
|
+
nestlevel: number;
|
|
5
|
+
currentNamespace: Namespace;
|
|
6
|
+
context: EmitContext;
|
|
7
|
+
visibility?: Visibility;
|
|
8
|
+
resolveEvenWithName?: boolean;
|
|
9
|
+
isNamespaceRoot?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const resolveType: (t: Type, opts: CommonOptions) => string;
|
|
12
|
+
export declare const resolveArray: (a: ArrayModelType, opts: CommonOptions) => string;
|
|
13
|
+
export declare const resolveRecord: (a: RecordModelType, opts: CommonOptions) => string;
|
|
14
|
+
export declare const resolveEnum: (e: Enum, opts: CommonOptions) => string;
|
|
15
|
+
export declare const resolveTuple: (t: Tuple, opts: CommonOptions) => string;
|
|
16
|
+
export declare const resolveUnion: (u: Union, opts: CommonOptions) => string;
|
|
8
17
|
export declare const resolveScalar: (s: Scalar) => string;
|
|
9
|
-
export declare const resolveModel: (m: Model,
|
|
18
|
+
export declare const resolveModel: (m: Model, opts: CommonOptions) => string;
|
|
19
|
+
export declare const resolveEnumMemberValue: (e: Enum, name: string) => string | number | undefined;
|
|
20
|
+
export declare const resolveEnumAsUnion: (e: Enum) => string;
|
|
21
|
+
export {};
|