typespec-fastify 0.0.0 → 0.2.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.
- package/LICENSE +21 -0
- package/dist/src/components/AppFile.d.ts +4 -0
- package/dist/src/components/AppFile.js +46 -0
- package/dist/src/components/AppFile.js.map +1 -0
- package/dist/src/components/AppFile.jsx +19 -0
- package/dist/src/components/AppFile.jsx.map +1 -0
- package/dist/src/components/ModelsDirectory.d.ts +9 -0
- package/dist/src/components/ModelsDirectory.js +33 -0
- package/dist/src/components/ModelsDirectory.js.map +1 -0
- package/dist/src/components/ModelsDirectory.jsx +18 -0
- package/dist/src/components/ModelsDirectory.jsx.map +1 -0
- package/dist/src/components/OperationInterface.d.ts +18 -0
- package/dist/src/components/OperationInterface.js +137 -0
- package/dist/src/components/OperationInterface.js.map +1 -0
- package/dist/src/components/OperationInterface.jsx +89 -0
- package/dist/src/components/OperationInterface.jsx.map +1 -0
- package/dist/src/components/OperationsDirectory.d.ts +8 -0
- package/dist/src/components/OperationsDirectory.js +41 -0
- package/dist/src/components/OperationsDirectory.js.map +1 -0
- package/dist/src/components/OperationsDirectory.jsx +31 -0
- package/dist/src/components/OperationsDirectory.jsx.map +1 -0
- package/dist/src/components/ResponseTypes.d.ts +4 -0
- package/dist/src/components/ResponseTypes.js +41 -0
- package/dist/src/components/ResponseTypes.js.map +1 -0
- package/dist/src/components/ResponseTypes.jsx +47 -0
- package/dist/src/components/ResponseTypes.jsx.map +1 -0
- package/dist/src/components/RouteRegistration.d.ts +16 -0
- package/dist/src/components/RouteRegistration.js +155 -0
- package/dist/src/components/RouteRegistration.js.map +1 -0
- package/dist/src/components/RouteRegistration.jsx +124 -0
- package/dist/src/components/RouteRegistration.jsx.map +1 -0
- package/dist/src/components/RouterFile.d.ts +12 -0
- package/dist/src/components/RouterFile.js +61 -0
- package/dist/src/components/RouterFile.js.map +1 -0
- package/dist/src/components/RouterFile.jsx +30 -0
- package/dist/src/components/RouterFile.jsx.map +1 -0
- package/dist/src/components/RoutesDirectory.d.ts +10 -0
- package/dist/src/components/RoutesDirectory.js +95 -0
- package/dist/src/components/RoutesDirectory.js.map +1 -0
- package/dist/src/components/RoutesDirectory.jsx +51 -0
- package/dist/src/components/RoutesDirectory.jsx.map +1 -0
- package/dist/src/components/TsTypes.d.ts +10 -0
- package/dist/src/components/TsTypes.js +31 -0
- package/dist/src/components/TsTypes.js.map +1 -0
- package/dist/src/components/TsTypes.jsx +25 -0
- package/dist/src/components/TsTypes.jsx.map +1 -0
- package/dist/src/emitter.d.ts +3 -0
- package/dist/src/emitter.js +55 -0
- package/dist/src/emitter.js.map +1 -0
- package/dist/src/emitter.jsx +29 -0
- package/dist/src/emitter.jsx.map +1 -0
- package/dist/src/external-packages/fastify.d.ts +18 -0
- package/dist/src/external-packages/fastify.js +18 -0
- package/dist/src/external-packages/fastify.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib.d.ts +38 -0
- package/dist/src/lib.js +32 -0
- package/dist/src/lib.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.js +6 -0
- package/dist/src/testing/index.js.map +1 -0
- package/dist/src/utils/http-helpers.d.ts +22 -0
- package/dist/src/utils/http-helpers.js +56 -0
- package/dist/src/utils/http-helpers.js.map +1 -0
- package/dist/src/utils/type-discovery.d.ts +7 -0
- package/dist/src/utils/type-discovery.js +87 -0
- package/dist/src/utils/type-discovery.js.map +1 -0
- package/package.json +67 -8
- package/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jordan Hood
|
|
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.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { List } from "@alloy-js/core";
|
|
3
|
+
import * as ts from "@alloy-js/typescript";
|
|
4
|
+
import { fastifyLib } from "../external-packages/fastify.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Generates the app.ts file which creates and configures a Fastify instance.
|
|
8
|
+
*/
|
|
9
|
+
export function AppFile() {
|
|
10
|
+
return _$createComponent(ts.SourceFile, {
|
|
11
|
+
path: "app.ts",
|
|
12
|
+
get children() {
|
|
13
|
+
return _$createComponent(ts.FunctionDeclaration, {
|
|
14
|
+
name: "createApp",
|
|
15
|
+
"export": true,
|
|
16
|
+
get returnType() {
|
|
17
|
+
return fastifyLib.FastifyInstance;
|
|
18
|
+
},
|
|
19
|
+
get children() {
|
|
20
|
+
return _$createComponent(List, {
|
|
21
|
+
get children() {
|
|
22
|
+
return [_$createComponent(ts.VarDeclaration, {
|
|
23
|
+
name: "server",
|
|
24
|
+
get children() {
|
|
25
|
+
return _$createComponent(ts.FunctionCallExpression, {
|
|
26
|
+
get target() {
|
|
27
|
+
return fastifyLib.fastify;
|
|
28
|
+
},
|
|
29
|
+
get args() {
|
|
30
|
+
return [_$createComponent(ts.ObjectExpression, {
|
|
31
|
+
jsValue: {
|
|
32
|
+
logger: true
|
|
33
|
+
}
|
|
34
|
+
})];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}), ["return server;"]];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=AppFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["List","ts","fastifyLib","AppFile","_$createComponent","SourceFile","path","children","FunctionDeclaration","name","returnType","FastifyInstance","VarDeclaration","FunctionCallExpression","target","fastify","args","ObjectExpression","jsValue","logger"],"sources":["../../../src/components/AppFile.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,IAAI,QAAQ,gBAAgB;AACrC,OAAO,KAAKC,EAAE,MAAM,sBAAsB;AAC1C,SAASC,UAAU,QAAQ,iCAAiC;;AAE5D;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAAA,EAAG;EACxB,OAAAC,iBAAA,CACGH,EAAE,CAACI,UAAU;IAACC,IAAI;IAAA,IAAAC,SAAA;MAAA,OAAAH,iBAAA,CAChBH,EAAE,CAACO,mBAAmB;QACrBC,IAAI;QAAA;QAAA,IAEJC,UAAUA,CAAA;UAAA,OAAER,UAAU,CAACS,eAAe;QAAA;QAAA,IAAAJ,SAAA;UAAA,OAAAH,iBAAA,CAErCJ,IAAI;YAAA,IAAAO,SAAA;cAAA,QAAAH,iBAAA,CACFH,EAAE,CAACW,cAAc;gBAACH,IAAI;gBAAA,IAAAF,SAAA;kBAAA,OAAAH,iBAAA,CACpBH,EAAE,CAACY,sBAAsB;oBAAA,IACxBC,MAAMA,CAAA;sBAAA,OAAEZ,UAAU,CAACa,OAAO;oBAAA;oBAAA,IAC1BC,IAAIA,CAAA;sBAAA,OAAE,CAAAZ,iBAAA,CAAEH,EAAE,CAACgB,gBAAgB;wBAACC,OAAO,EAAE;0BAAEC,MAAM,EAAE;wBAAK;sBAAC,GAAK;oBAAA;kBAAA;gBAAA;cAAA;YAAA;UAAA;QAAA;MAAA;IAAA;EAAA;AAQxE","ignoreList":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { List } from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { fastifyLib } from "../external-packages/fastify.js";
|
|
4
|
+
/**
|
|
5
|
+
* Generates the app.ts file which creates and configures a Fastify instance.
|
|
6
|
+
*/
|
|
7
|
+
export function AppFile() {
|
|
8
|
+
return (<ts.SourceFile path="app.ts">
|
|
9
|
+
<ts.FunctionDeclaration name="createApp" export returnType={fastifyLib.FastifyInstance}>
|
|
10
|
+
<List>
|
|
11
|
+
<ts.VarDeclaration name="server">
|
|
12
|
+
<ts.FunctionCallExpression target={fastifyLib.fastify} args={[<ts.ObjectExpression jsValue={{ logger: true }}/>]}/>
|
|
13
|
+
</ts.VarDeclaration>
|
|
14
|
+
<>return server;</>
|
|
15
|
+
</List>
|
|
16
|
+
</ts.FunctionDeclaration>
|
|
17
|
+
</ts.SourceFile>);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=AppFile.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppFile.jsx","sourceRoot":"","sources":["../../../src/components/AppFile.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE7D;;GAEG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,CACL,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAC1B;MAAA,CAAC,EAAE,CAAC,mBAAmB,CACrB,IAAI,CAAC,WAAW,CAChB,MAAM,CACN,UAAU,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAEvC;QAAA,CAAC,IAAI,CACH;UAAA,CAAC,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAC9B;YAAA,CAAC,EAAE,CAAC,sBAAsB,CACxB,MAAM,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAC3B,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAG,CAAC,CAAC,EAE/D;UAAA,EAAE,EAAE,CAAC,cAAc,CACnB;UAAA,EAAE,cAAc,GAClB;QAAA,EAAE,IAAI,CACR;MAAA,EAAE,EAAE,CAAC,mBAAmB,CAC1B;IAAA,EAAE,EAAE,CAAC,UAAU,CAAC,CACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Type } from "@typespec/compiler";
|
|
2
|
+
export interface ModelsDirectoryProps {
|
|
3
|
+
namespace: string;
|
|
4
|
+
types: Type[];
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Generates the models directory with TypeSpec type declarations.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ModelsDirectory(props: ModelsDirectoryProps): import("@alloy-js/core").Children;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { SourceDirectory } from "@alloy-js/core";
|
|
3
|
+
import * as ts from "@alloy-js/typescript";
|
|
4
|
+
import { TsTypes } from "./TsTypes.js";
|
|
5
|
+
import { ResponseTypes } from "./ResponseTypes.js";
|
|
6
|
+
/**
|
|
7
|
+
* Generates the models directory with TypeSpec type declarations.
|
|
8
|
+
*/
|
|
9
|
+
export function ModelsDirectory(props) {
|
|
10
|
+
return _$createComponent(SourceDirectory, {
|
|
11
|
+
path: "models",
|
|
12
|
+
get children() {
|
|
13
|
+
return [_$createComponent(ts.SourceFile, {
|
|
14
|
+
path: "response-types.ts",
|
|
15
|
+
get children() {
|
|
16
|
+
return _$createComponent(ResponseTypes, {});
|
|
17
|
+
}
|
|
18
|
+
}), _$createComponent(ts.SourceFile, {
|
|
19
|
+
get path() {
|
|
20
|
+
return `${props.namespace.toLowerCase()}.ts`;
|
|
21
|
+
},
|
|
22
|
+
get children() {
|
|
23
|
+
return _$createComponent(TsTypes, {
|
|
24
|
+
get types() {
|
|
25
|
+
return props.types;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
})];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=ModelsDirectory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SourceDirectory","ts","TsTypes","ResponseTypes","ModelsDirectory","props","_$createComponent","path","children","SourceFile","namespace","toLowerCase","types"],"sources":["../../../src/components/ModelsDirectory.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,eAAe,QAAQ,gBAAgB;AAChD,OAAO,KAAKC,EAAE,MAAM,sBAAsB;AAE1C,SAASC,OAAO,QAAQ,cAAc;AACtC,SAASC,aAAa,QAAQ,oBAAoB;AAOlD;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAACC,KAA2B,EAAE;EAC3D,OAAAC,iBAAA,CACGN,eAAe;IAACO,IAAI;IAAA,IAAAC,SAAA;MAAA,QAAAF,iBAAA,CAClBL,EAAE,CAACQ,UAAU;QAACF,IAAI;QAAA,IAAAC,SAAA;UAAA,OAAAF,iBAAA,CAChBH,aAAa;QAAA;MAAA,IAAAG,iBAAA,CAEfL,EAAE,CAACQ,UAAU;QAAA,IAACF,IAAIA,CAAA;UAAA,OAAE,GAAGF,KAAK,CAACK,SAAS,CAACC,WAAW,CAAC,CAAC,KAAK;QAAA;QAAA,IAAAH,SAAA;UAAA,OAAAF,iBAAA,CACvDJ,OAAO;YAAA,IAACU,KAAKA,CAAA;cAAA,OAAEP,KAAK,CAACO,KAAK;YAAA;UAAA;QAAA;MAAA;IAAA;EAAA;AAInC","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SourceDirectory } from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { TsTypes } from "./TsTypes.js";
|
|
4
|
+
import { ResponseTypes } from "./ResponseTypes.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generates the models directory with TypeSpec type declarations.
|
|
7
|
+
*/
|
|
8
|
+
export function ModelsDirectory(props) {
|
|
9
|
+
return (<SourceDirectory path="models">
|
|
10
|
+
<ts.SourceFile path="response-types.ts">
|
|
11
|
+
<ResponseTypes />
|
|
12
|
+
</ts.SourceFile>
|
|
13
|
+
<ts.SourceFile path={`${props.namespace.toLowerCase()}.ts`}>
|
|
14
|
+
<TsTypes types={props.types}/>
|
|
15
|
+
</ts.SourceFile>
|
|
16
|
+
</SourceDirectory>);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=ModelsDirectory.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModelsDirectory.jsx","sourceRoot":"","sources":["../../../src/components/ModelsDirectory.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAOnD;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAA2B;IACzD,OAAO,CACL,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAC5B;MAAA,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,mBAAmB,CACrC;QAAA,CAAC,aAAa,CAAC,AAAD,EAChB;MAAA,EAAE,EAAE,CAAC,UAAU,CACf;MAAA,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,WAAW,EAAE,KAAK,CAAC,CACzD;QAAA,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAC9B;MAAA,EAAE,EAAE,CAAC,UAAU,CACjB;IAAA,EAAE,eAAe,CAAC,CACnB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Refkey, type Children } from "@alloy-js/core";
|
|
2
|
+
import type { HttpOperation } from "@typespec/http";
|
|
3
|
+
export interface OperationInterfaceProps {
|
|
4
|
+
containerName: string;
|
|
5
|
+
operations: HttpOperation[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Creates a refkey for an operation interface.
|
|
9
|
+
* This allows other components to reference this interface and
|
|
10
|
+
* Alloy will automatically generate the import.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getOperationInterfaceRef(containerName: string): Refkey;
|
|
13
|
+
/**
|
|
14
|
+
* Generates a TypeScript interface for a group of HTTP operations.
|
|
15
|
+
* Following the http-server-js pattern, this creates an interface with methods
|
|
16
|
+
* for each operation that the user will implement.
|
|
17
|
+
*/
|
|
18
|
+
export declare function OperationInterface(props: OperationInterfaceProps): Children;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { For, List, refkey, code } from "@alloy-js/core";
|
|
3
|
+
import * as ts from "@alloy-js/typescript";
|
|
4
|
+
import { useTSNamePolicy } from "@alloy-js/typescript";
|
|
5
|
+
import { isVoidType } from "@typespec/compiler";
|
|
6
|
+
import { TypeExpression } from "@typespec/emitter-framework/typescript";
|
|
7
|
+
import { getNoContentResponseRef } from "./ResponseTypes.js";
|
|
8
|
+
/**
|
|
9
|
+
* Creates a refkey for an operation interface.
|
|
10
|
+
* This allows other components to reference this interface and
|
|
11
|
+
* Alloy will automatically generate the import.
|
|
12
|
+
*/
|
|
13
|
+
export function getOperationInterfaceRef(containerName) {
|
|
14
|
+
return refkey(containerName, "operation-interface");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Generates a TypeScript interface for a group of HTTP operations.
|
|
19
|
+
* Following the http-server-js pattern, this creates an interface with methods
|
|
20
|
+
* for each operation that the user will implement.
|
|
21
|
+
*/
|
|
22
|
+
export function OperationInterface(props) {
|
|
23
|
+
const {
|
|
24
|
+
containerName,
|
|
25
|
+
operations
|
|
26
|
+
} = props;
|
|
27
|
+
const interfaceRef = getOperationInterfaceRef(containerName);
|
|
28
|
+
const namePolicy = useTSNamePolicy();
|
|
29
|
+
return _$createComponent(ts.InterfaceDeclaration, {
|
|
30
|
+
name: containerName,
|
|
31
|
+
"export": true,
|
|
32
|
+
refkey: interfaceRef,
|
|
33
|
+
get children() {
|
|
34
|
+
return _$createComponent(List, {
|
|
35
|
+
get children() {
|
|
36
|
+
return _$createComponent(For, {
|
|
37
|
+
each: operations,
|
|
38
|
+
hardline: true,
|
|
39
|
+
semicolon: true,
|
|
40
|
+
children: operation => {
|
|
41
|
+
const opName = namePolicy.getName(operation.operation.name, "function");
|
|
42
|
+
const parameters = [];
|
|
43
|
+
for (const param of operation.parameters.parameters) {
|
|
44
|
+
if (param.type === "path") {
|
|
45
|
+
const paramName = namePolicy.getName(param.param.name, "parameter");
|
|
46
|
+
parameters.push({
|
|
47
|
+
name: paramName,
|
|
48
|
+
type: _$createComponent(TypeExpression, {
|
|
49
|
+
get type() {
|
|
50
|
+
return param.param.type;
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
optional: param.param.optional
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (operation.parameters.body) {
|
|
58
|
+
parameters.push({
|
|
59
|
+
name: "body",
|
|
60
|
+
type: _$createComponent(TypeExpression, {
|
|
61
|
+
get type() {
|
|
62
|
+
return operation.parameters.body.type;
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
for (const param of operation.parameters.parameters) {
|
|
68
|
+
if (param.type === "header") {
|
|
69
|
+
const paramName = namePolicy.getName(param.param.name, "parameter");
|
|
70
|
+
parameters.push({
|
|
71
|
+
name: paramName,
|
|
72
|
+
type: _$createComponent(TypeExpression, {
|
|
73
|
+
get type() {
|
|
74
|
+
return param.param.type;
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
optional: param.param.optional
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const queryParams = operation.parameters.parameters.filter(p => p.type === "query");
|
|
82
|
+
if (queryParams.length > 0) {
|
|
83
|
+
const optionsType = _$createComponent(ts.InterfaceExpression, {
|
|
84
|
+
get children() {
|
|
85
|
+
return _$createComponent(For, {
|
|
86
|
+
each: queryParams,
|
|
87
|
+
semicolon: true,
|
|
88
|
+
hardline: true,
|
|
89
|
+
children: param => {
|
|
90
|
+
const paramName = namePolicy.getName(param.param.name, "interface-member");
|
|
91
|
+
return _$createComponent(ts.InterfaceMember, {
|
|
92
|
+
name: paramName,
|
|
93
|
+
get optional() {
|
|
94
|
+
return param.param.optional;
|
|
95
|
+
},
|
|
96
|
+
get children() {
|
|
97
|
+
return _$createComponent(TypeExpression, {
|
|
98
|
+
get type() {
|
|
99
|
+
return param.param.type;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
parameters.push({
|
|
109
|
+
name: "options",
|
|
110
|
+
type: optionsType,
|
|
111
|
+
optional: true
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const isVoid = isVoidType(operation.operation.returnType);
|
|
115
|
+
const is204Response = operation.responses.some(function (r) {
|
|
116
|
+
return r.statusCodes === 204;
|
|
117
|
+
});
|
|
118
|
+
const shouldEmitVoid = isVoid || is204Response;
|
|
119
|
+
const noContentRef = getNoContentResponseRef();
|
|
120
|
+
const returnType = shouldEmitVoid ? code`Promise<${noContentRef}>` : code`Promise<ResponseWithBody<${_$createComponent(TypeExpression, {
|
|
121
|
+
get type() {
|
|
122
|
+
return operation.operation.returnType;
|
|
123
|
+
}
|
|
124
|
+
})}>>`;
|
|
125
|
+
return _$createComponent(ts.InterfaceMethod, {
|
|
126
|
+
name: opName,
|
|
127
|
+
parameters: parameters,
|
|
128
|
+
returnType: returnType
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=OperationInterface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["For","List","refkey","code","ts","useTSNamePolicy","isVoidType","TypeExpression","getNoContentResponseRef","getOperationInterfaceRef","containerName","OperationInterface","props","operations","interfaceRef","namePolicy","_$createComponent","InterfaceDeclaration","name","children","each","hardline","semicolon","operation","opName","getName","parameters","param","type","paramName","push","optional","body","queryParams","filter","p","length","optionsType","InterfaceExpression","InterfaceMember","isVoid","returnType","is204Response","responses","some","r","statusCodes","shouldEmitVoid","noContentRef","InterfaceMethod"],"sources":["../../../src/components/OperationInterface.tsx"],"sourcesContent":[null],"mappings":";AAAA,SACEA,GAAG,EACHC,IAAI,EACJC,MAAM,EAGNC,IAAI,QACC,gBAAgB;AACvB,OAAO,KAAKC,EAAE,MAAM,sBAAsB;AAC1C,SAASC,eAAe,QAAQ,sBAAsB;AAE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Ae;gBACjB/B,IAAI,EAAEM,MAAM;gBACZE,UAAU,EAAEA,UAAU;gBACtBe,UAAU,EAAEA;cAAU;YAG5B;UAAC;QAAA;MAAA;IAAA;EAAA;AAKX","ignoreList":[]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { For, List, refkey, code, } from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { useTSNamePolicy } from "@alloy-js/typescript";
|
|
4
|
+
import { isVoidType } from "@typespec/compiler";
|
|
5
|
+
import { TypeExpression } from "@typespec/emitter-framework/typescript";
|
|
6
|
+
import { getNoContentResponseRef } from "./ResponseTypes.js";
|
|
7
|
+
/**
|
|
8
|
+
* Creates a refkey for an operation interface.
|
|
9
|
+
* This allows other components to reference this interface and
|
|
10
|
+
* Alloy will automatically generate the import.
|
|
11
|
+
*/
|
|
12
|
+
export function getOperationInterfaceRef(containerName) {
|
|
13
|
+
return refkey(containerName, "operation-interface");
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generates a TypeScript interface for a group of HTTP operations.
|
|
17
|
+
* Following the http-server-js pattern, this creates an interface with methods
|
|
18
|
+
* for each operation that the user will implement.
|
|
19
|
+
*/
|
|
20
|
+
export function OperationInterface(props) {
|
|
21
|
+
const { containerName, operations } = props;
|
|
22
|
+
const interfaceRef = getOperationInterfaceRef(containerName);
|
|
23
|
+
const namePolicy = useTSNamePolicy();
|
|
24
|
+
return (<ts.InterfaceDeclaration name={containerName} export refkey={interfaceRef}>
|
|
25
|
+
<List>
|
|
26
|
+
<For each={operations} hardline semicolon>
|
|
27
|
+
{(operation) => {
|
|
28
|
+
const opName = namePolicy.getName(operation.operation.name, "function");
|
|
29
|
+
const parameters = [];
|
|
30
|
+
for (const param of operation.parameters.parameters) {
|
|
31
|
+
if (param.type === "path") {
|
|
32
|
+
const paramName = namePolicy.getName(param.param.name, "parameter");
|
|
33
|
+
parameters.push({
|
|
34
|
+
name: paramName,
|
|
35
|
+
type: <TypeExpression type={param.param.type}/>,
|
|
36
|
+
optional: param.param.optional,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (operation.parameters.body) {
|
|
41
|
+
parameters.push({
|
|
42
|
+
name: "body",
|
|
43
|
+
type: <TypeExpression type={operation.parameters.body.type}/>,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
for (const param of operation.parameters.parameters) {
|
|
47
|
+
if (param.type === "header") {
|
|
48
|
+
const paramName = namePolicy.getName(param.param.name, "parameter");
|
|
49
|
+
parameters.push({
|
|
50
|
+
name: paramName,
|
|
51
|
+
type: <TypeExpression type={param.param.type}/>,
|
|
52
|
+
optional: param.param.optional,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const queryParams = operation.parameters.parameters.filter((p) => p.type === "query");
|
|
57
|
+
if (queryParams.length > 0) {
|
|
58
|
+
const optionsType = (<ts.InterfaceExpression>
|
|
59
|
+
<For each={queryParams} semicolon hardline>
|
|
60
|
+
{(param) => {
|
|
61
|
+
const paramName = namePolicy.getName(param.param.name, "interface-member");
|
|
62
|
+
return (<ts.InterfaceMember name={paramName} optional={param.param.optional}>
|
|
63
|
+
<TypeExpression type={param.param.type}/>
|
|
64
|
+
</ts.InterfaceMember>);
|
|
65
|
+
}}
|
|
66
|
+
</For>
|
|
67
|
+
</ts.InterfaceExpression>);
|
|
68
|
+
parameters.push({
|
|
69
|
+
name: "options",
|
|
70
|
+
type: optionsType,
|
|
71
|
+
optional: true,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const isVoid = isVoidType(operation.operation.returnType);
|
|
75
|
+
const is204Response = operation.responses.some(function (r) {
|
|
76
|
+
return r.statusCodes === 204;
|
|
77
|
+
});
|
|
78
|
+
const shouldEmitVoid = isVoid || is204Response;
|
|
79
|
+
const noContentRef = getNoContentResponseRef();
|
|
80
|
+
const returnType = shouldEmitVoid
|
|
81
|
+
? code `Promise<${noContentRef}>`
|
|
82
|
+
: code `Promise<ResponseWithBody<${(<TypeExpression type={operation.operation.returnType}/>)}>>`;
|
|
83
|
+
return (<ts.InterfaceMethod name={opName} parameters={parameters} returnType={returnType}/>);
|
|
84
|
+
}}
|
|
85
|
+
</For>
|
|
86
|
+
</List>
|
|
87
|
+
</ts.InterfaceDeclaration>);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=OperationInterface.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationInterface.jsx","sourceRoot":"","sources":["../../../src/components/OperationInterface.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,IAAI,EACJ,MAAM,EAGN,IAAI,GACL,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAM7D;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CAAC,aAAqB;IAC5D,OAAO,MAAM,CAAC,aAAa,EAAE,qBAAqB,CAAC,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAA8B;IAC/D,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IAC5C,MAAM,YAAY,GAAG,wBAAwB,CAAC,aAAa,CAAC,CAAC;IAC7D,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC;IACrC,OAAO,CACL,CAAC,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CACxE;MAAA,CAAC,IAAI,CACH;QAAA,CAAC,GAAG,C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AG,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;YAC1D,MAAM,aAAa,GAAG,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;gBACxD,OAAO,CAAC,CAAC,WAAW,KAAK,GAAG,CAAC;YAC/B,CAAC,CAAC,CAAC;YACH,MAAM,cAAc,GAAG,MAAM,IAAI,aAAa,CAAC;YAC/C,MAAM,YAAY,GAAG,uBAAuB,EAAE,CAAC;YAC/C,MAAM,UAAU,GAAG,cAAc;gBAC/B,CAAC,CAAC,IAAI,CAAA,WAAW,YAAY,GAAG;gBAChC,CAAC,CAAC,IAAI,CAAA,4BAA4B,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,UAAU,CAAC,EAAG,CAAC,IAAI,CAAC;YACnG,OAAO,CACL,CAAC,EAAE,CAAC,eAAe,CACjB,IAAI,CAAC,CAAC,MAAM,CAAC,CACb,UAAU,CAAC,CAAC,UAAU,CAAC,CACvB,UAAU,CAAC,CAAC,UAAU,CAAC,EACvB,CACH,CAAC;QACJ,CAAC,CACH;QAAA,EAAE,GAAG,CACP;MAAA,EAAE,IAAI,CACR;IAAA,EAAE,EAAE,CAAC,oBAAoB,CAAC,CAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HttpOperation } from "@typespec/http";
|
|
2
|
+
export interface OperationsDirectoryProps {
|
|
3
|
+
groupedOperations: Map<string, HttpOperation[]>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Generates the operations directory with operation interface files.
|
|
7
|
+
*/
|
|
8
|
+
export declare function OperationsDirectory(props: OperationsDirectoryProps): import("@alloy-js/core").Children;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { For, SourceDirectory } from "@alloy-js/core";
|
|
3
|
+
import * as ts from "@alloy-js/typescript";
|
|
4
|
+
import { isVoidType } from "@typespec/compiler";
|
|
5
|
+
import { OperationInterface } from "./OperationInterface.js";
|
|
6
|
+
/**
|
|
7
|
+
* Generates the operations directory with operation interface files.
|
|
8
|
+
*/
|
|
9
|
+
export function OperationsDirectory(props) {
|
|
10
|
+
return _$createComponent(SourceDirectory, {
|
|
11
|
+
path: "operations",
|
|
12
|
+
get children() {
|
|
13
|
+
return _$createComponent(For, {
|
|
14
|
+
get each() {
|
|
15
|
+
return Array.from(props.groupedOperations.entries());
|
|
16
|
+
},
|
|
17
|
+
children: ([containerName, operations]) => {
|
|
18
|
+
const hasResponseWithBody = operations.some(function (op) {
|
|
19
|
+
const isVoid = isVoidType(op.operation.returnType);
|
|
20
|
+
const is204 = op.responses.some(function (r) {
|
|
21
|
+
return r.statusCodes === 204;
|
|
22
|
+
});
|
|
23
|
+
return !isVoid && !is204;
|
|
24
|
+
});
|
|
25
|
+
return _$createComponent(ts.SourceFile, {
|
|
26
|
+
get path() {
|
|
27
|
+
return `${containerName.toLowerCase()}.ts`;
|
|
28
|
+
},
|
|
29
|
+
get children() {
|
|
30
|
+
return [_$memo(() => hasResponseWithBody && ["import type ", "{", " ResponseWithBody ", "}", " from \"../models/response-types.js\";", "\n\n"]), _$createComponent(OperationInterface, {
|
|
31
|
+
containerName: containerName,
|
|
32
|
+
operations: operations
|
|
33
|
+
})];
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=OperationsDirectory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["For","SourceDirectory","ts","isVoidType","OperationInterface","OperationsDirectory","props","_$createComponent","path","children","each","Array","from","groupedOperations","entries","containerName","operations","hasResponseWithBody","some","op","isVoid","operation","returnType","is204","responses","r","statusCodes","SourceFile","toLowerCase","_$memo"],"sources":["../../../src/components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A;QAI9B;MAAC;IAAA;EAAA;AAIT","ignoreList":[]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { For, SourceDirectory } from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
import { isVoidType } from "@typespec/compiler";
|
|
4
|
+
import { OperationInterface } from "./OperationInterface.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generates the operations directory with operation interface files.
|
|
7
|
+
*/
|
|
8
|
+
export function OperationsDirectory(props) {
|
|
9
|
+
return (<SourceDirectory path="operations">
|
|
10
|
+
<For each={Array.from(props.groupedOperations.entries())}>
|
|
11
|
+
{([containerName, operations]) => {
|
|
12
|
+
const hasResponseWithBody = operations.some(function (op) {
|
|
13
|
+
const isVoid = isVoidType(op.operation.returnType);
|
|
14
|
+
const is204 = op.responses.some(function (r) {
|
|
15
|
+
return r.statusCodes === 204;
|
|
16
|
+
});
|
|
17
|
+
return !isVoid && !is204;
|
|
18
|
+
});
|
|
19
|
+
return (<ts.SourceFile path={`${containerName.toLowerCase()}.ts`}>
|
|
20
|
+
{hasResponseWithBody && (<>
|
|
21
|
+
import type {"{"} ResponseWithBody {"}"} from
|
|
22
|
+
"../models/response-types.js";
|
|
23
|
+
{"\n\n"}
|
|
24
|
+
</>)}
|
|
25
|
+
<OperationInterface containerName={containerName} operations={operations}/>
|
|
26
|
+
</ts.SourceFile>);
|
|
27
|
+
}}
|
|
28
|
+
</For>
|
|
29
|
+
</SourceDirectory>);
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=OperationsDirectory.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OperationsDirectory.jsx","sourceRoot":"","sources":["../../../src/components/OperationsDirectory.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3C,OAAO,EAAE,UAAU,E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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { refkey } from "@alloy-js/core";
|
|
3
|
+
import * as ts from "@alloy-js/typescript";
|
|
4
|
+
export function getNoContentResponseRef() {
|
|
5
|
+
return refkey("NoContentResponse", "response-types");
|
|
6
|
+
}
|
|
7
|
+
export function getResponseWithBodyRef() {
|
|
8
|
+
return refkey("ResponseWithBody", "response-types");
|
|
9
|
+
}
|
|
10
|
+
export function ResponseTypes() {
|
|
11
|
+
const noContentRef = getNoContentResponseRef();
|
|
12
|
+
return [_$createComponent(ts.InterfaceDeclaration, {
|
|
13
|
+
name: "NoContentResponse",
|
|
14
|
+
"export": true,
|
|
15
|
+
refkey: noContentRef,
|
|
16
|
+
get children() {
|
|
17
|
+
return ["statusCode: number"];
|
|
18
|
+
}
|
|
19
|
+
}), "\n\n", ["export interface ResponseWithBody", "<", "TBody", ">", " ", "{", "\n", " ", "statusCode: number;", "\n", " ", "body: TBody;", "\n", "}"]];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* not quite working yields
|
|
23
|
+
* export interface ResponseWithBody<t> {
|
|
24
|
+
statusCode: number;
|
|
25
|
+
body: T
|
|
26
|
+
}
|
|
27
|
+
*/
|
|
28
|
+
{
|
|
29
|
+
/* <ts.InterfaceDeclaration
|
|
30
|
+
name="ResponseWithBody"
|
|
31
|
+
export
|
|
32
|
+
refkey={responseWithBodyRef}
|
|
33
|
+
typeParameters={[{ name: "T" }]}
|
|
34
|
+
>
|
|
35
|
+
<>
|
|
36
|
+
statusCode: number;{"\n"}
|
|
37
|
+
body: T
|
|
38
|
+
</>
|
|
39
|
+
</ts.InterfaceDeclaration> */
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=ResponseTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["refkey","ts","getNoContentResponseRef","getResponseWithBodyRef","ResponseTypes","noContentRef","_$createComponent","InterfaceDeclaration","name","children"],"sources":["../../../src/components/ResponseTypes.tsx"],"sourcesContent":[null],"mappings":";AAAA,SAASA,MAAM,QAAqB,gBAAgB;AACpD,OAAO,KAAKC,EAAE,MAAM,sBAAsB;AAE1C,OAAO,SAASC,uBAAuBA,CAAA,EAAW;EAChD,OAAOF,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC;AACtD;AAEA,OAAO,SAASG,sBAAsBA,CAAA,EAAW;EAC/C,OAAOH,MAAM,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;AACrD;AAEA,OAAO,SAASI,aAAaA,CAAA,EAAG;EAC9B,MAAMC,YAAY,GAAGH,uBAAuB,CAAC,CAAC;EAE9C,QAAAI,iBAAA,CAEKL,EAAE,CAACM,oBAAoB;IACtBC,IAAI;IAAA;IAEJR,MAAM,EAAEK,YAAY;IAAA,IAAAI,SAAA;MAAA;IAAA;EAAA,IAIrB,MAAM,wCAE6B,GAAG,WAAO,GAAG,OAAG,GAAG,EACpD,IAAI,EACJ,IAAI,yBACJ,IAAI,EACJ,IAAI,kBACJ,IAAI,EACJ,GAAG;AAIZ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAVE","ignoreList":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { refkey } from "@alloy-js/core";
|
|
2
|
+
import * as ts from "@alloy-js/typescript";
|
|
3
|
+
export function getNoContentResponseRef() {
|
|
4
|
+
return refkey("NoContentResponse", "response-types");
|
|
5
|
+
}
|
|
6
|
+
export function getResponseWithBodyRef() {
|
|
7
|
+
return refkey("ResponseWithBody", "response-types");
|
|
8
|
+
}
|
|
9
|
+
export function ResponseTypes() {
|
|
10
|
+
const noContentRef = getNoContentResponseRef();
|
|
11
|
+
return (<>
|
|
12
|
+
<ts.InterfaceDeclaration name="NoContentResponse" export refkey={noContentRef}>
|
|
13
|
+
<>statusCode: number</>
|
|
14
|
+
</ts.InterfaceDeclaration>
|
|
15
|
+
{"\n\n"}
|
|
16
|
+
<>
|
|
17
|
+
export interface ResponseWithBody{"<"}TBody{">"} {"{"}
|
|
18
|
+
{"\n"}
|
|
19
|
+
{" "}statusCode: number;
|
|
20
|
+
{"\n"}
|
|
21
|
+
{" "}body: TBody;
|
|
22
|
+
{"\n"}
|
|
23
|
+
{"}"}
|
|
24
|
+
</>
|
|
25
|
+
</>);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* not quite working yields
|
|
29
|
+
* export interface ResponseWithBody<t> {
|
|
30
|
+
statusCode: number;
|
|
31
|
+
body: T
|
|
32
|
+
}
|
|
33
|
+
*/
|
|
34
|
+
{
|
|
35
|
+
/* <ts.InterfaceDeclaration
|
|
36
|
+
name="ResponseWithBody"
|
|
37
|
+
export
|
|
38
|
+
refkey={responseWithBodyRef}
|
|
39
|
+
typeParameters={[{ name: "T" }]}
|
|
40
|
+
>
|
|
41
|
+
<>
|
|
42
|
+
statusCode: number;{"\n"}
|
|
43
|
+
body: T
|
|
44
|
+
</>
|
|
45
|
+
</ts.InterfaceDeclaration> */
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=ResponseTypes.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResponseTypes.jsx","sourceRoot":"","sources":["../../../src/components/ResponseTypes.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE3C,MAAM,UAAU,uBAAuB;IACrC,OAAO,MAAM,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,MAAM,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,aAAa;IAC3B,MAAM,YAAY,GAAG,uBAAuB,EAAE,CAAC;IAE/C,OAAO,CACL,EACE;MAAA,CAAC,EAAE,CAAC,oBAAoB,CACtB,IAAI,CAAC,mBAAmB,CACxB,MAAM,CACN,MAAM,CAAC,CAAC,YAAY,CAAC,CAErB;QAAA,EAAE,kBAAkB,GACtB;MAAA,EAAE,EAAE,CAAC,oBAAoB,CACzB;MAAA,CAAC,MAAM,CACP;MAAA,EACE;yCAAiC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAE,CAAA,CAAC,GAAG,CACrD;QAAA,CAAC,IAAI,CACL;QAAA,CAAC,IAAI,CAAC;QACN,CAAC,IAAI,CACL;QAAA,CAAC,IAAI,CAAC;QACN,CAAC,IAAI,CACL;QAAA,CAAC,GAAG,CACN;MAAA,GACF;IAAA,GAAG,CACJ,CAAC;AACJ,CAAC;AACD;;;;;;GAMG;AACH,CAAC;IACC;;;;;;;;;;+BAU2B;AAC7B,CAAC"}
|