@typespec/http 0.65.0-dev.2 → 0.65.0-dev.4
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/dist/src/experimental/typekit/index.d.ts +2 -0
- package/dist/src/experimental/typekit/index.d.ts.map +1 -0
- package/dist/src/experimental/typekit/index.js +2 -0
- package/dist/src/experimental/typekit/index.js.map +1 -0
- package/dist/src/experimental/typekit/kits/http-operation.d.ts +57 -0
- package/dist/src/experimental/typekit/kits/http-operation.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/http-operation.js +63 -0
- package/dist/src/experimental/typekit/kits/http-operation.js.map +1 -0
- package/dist/src/experimental/typekit/kits/http-request.d.ts +32 -0
- package/dist/src/experimental/typekit/kits/http-request.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/http-request.js +54 -0
- package/dist/src/experimental/typekit/kits/http-request.js.map +1 -0
- package/dist/src/experimental/typekit/kits/http-response.d.ts +44 -0
- package/dist/src/experimental/typekit/kits/http-response.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/http-response.js +21 -0
- package/dist/src/experimental/typekit/kits/http-response.js.map +1 -0
- package/dist/src/experimental/typekit/kits/index.d.ts +5 -0
- package/dist/src/experimental/typekit/kits/index.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/index.js +5 -0
- package/dist/src/experimental/typekit/kits/index.js.map +1 -0
- package/dist/src/experimental/typekit/kits/model-property.d.ts +53 -0
- package/dist/src/experimental/typekit/kits/model-property.d.ts.map +1 -0
- package/dist/src/experimental/typekit/kits/model-property.js +40 -0
- package/dist/src/experimental/typekit/kits/model-property.js.map +1 -0
- package/package.json +8 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/experimental/typekit/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/experimental/typekit/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Operation, Type } from "@typespec/compiler";
|
|
2
|
+
import { HttpOperation, HttpOperationResponseContent, HttpStatusCodesEntry } from "../../../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Utilities for working with HTTP operations.
|
|
5
|
+
* @experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface HttpOperationKit {
|
|
8
|
+
/**
|
|
9
|
+
* Get the corresponding HTTP operation for the given TypeSpec operation. The same
|
|
10
|
+
* TypeSpec operation will always return the exact same HttpOperation object.
|
|
11
|
+
*
|
|
12
|
+
* @param op The TypeSpec operation to get the HTTP operation metadata for.
|
|
13
|
+
*/
|
|
14
|
+
get(op: Operation): HttpOperation;
|
|
15
|
+
/**
|
|
16
|
+
* Get the responses for the given operation. This function will return an array of responses grouped by status code and content type.
|
|
17
|
+
* @param op operation to extract the HttpResponse from
|
|
18
|
+
*/
|
|
19
|
+
getResponses(op: Operation): FlatHttpResponse[];
|
|
20
|
+
/**
|
|
21
|
+
* Get the Http Return type for the given operation. This function will resolve the returnType based on the Http Operation.
|
|
22
|
+
* @param op operation to get the return type for
|
|
23
|
+
*/
|
|
24
|
+
getReturnType(op: Operation, options?: {
|
|
25
|
+
includeErrors?: boolean;
|
|
26
|
+
}): Type;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Structure of a flat HTTP response, which is grouped by status code and content type.
|
|
30
|
+
*/
|
|
31
|
+
export interface FlatHttpResponse {
|
|
32
|
+
/**
|
|
33
|
+
* Response status code.
|
|
34
|
+
*/
|
|
35
|
+
statusCode: HttpStatusCodesEntry;
|
|
36
|
+
/**
|
|
37
|
+
* Content type. Might be undefined if the response does not have a body.
|
|
38
|
+
*/
|
|
39
|
+
contentType?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Response content.
|
|
42
|
+
*/
|
|
43
|
+
responseContent: HttpOperationResponseContent;
|
|
44
|
+
}
|
|
45
|
+
interface TypekitExtension {
|
|
46
|
+
/**
|
|
47
|
+
* Utilities for working with HTTP operations.
|
|
48
|
+
* @experimental
|
|
49
|
+
*/
|
|
50
|
+
httpOperation: HttpOperationKit;
|
|
51
|
+
}
|
|
52
|
+
declare module "@typespec/compiler/experimental/typekit" {
|
|
53
|
+
interface Typekit extends TypekitExtension {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=http-operation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-operation.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/http-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,SAAS,EAAiB,IAAI,EAAY,MAAM,oBAAoB,CAAC;AAGjG,OAAO,EACL,aAAa,EACb,4BAA4B,EAC5B,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;OAKG;IACH,GAAG,CAAC,EAAE,EAAE,SAAS,GAAG,aAAa,CAAC;IAClC;;;OAGG;IACH,YAAY,CAAC,EAAE,EAAE,SAAS,GAAG,gBAAgB,EAAE,CAAC;IAChD;;;OAGG;IACH,aAAa,CAAC,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC3E;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,UAAU,EAAE,oBAAoB,CAAC;IACjC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,eAAe,EAAE,4BAA4B,CAAC;CAC/C;AAED,UAAU,gBAAgB;IACxB;;;OAGG;IACH,aAAa,EAAE,gBAAgB,CAAC;CACjC;AAED,OAAO,QAAQ,yCAAyC,CAAC;IACvD,UAAU,OAAQ,SAAQ,gBAAgB;KAAG;CAC9C"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ignoreDiagnostics } from "@typespec/compiler";
|
|
2
|
+
import { defineKit } from "@typespec/compiler/experimental/typekit";
|
|
3
|
+
import { getHttpOperation } from "../../../operations.js";
|
|
4
|
+
defineKit({
|
|
5
|
+
httpOperation: {
|
|
6
|
+
get(op) {
|
|
7
|
+
return ignoreDiagnostics(getHttpOperation(this.program, op));
|
|
8
|
+
},
|
|
9
|
+
getReturnType(operation, options) {
|
|
10
|
+
let responses = this.httpOperation.getResponses(operation);
|
|
11
|
+
if (!options?.includeErrors) {
|
|
12
|
+
responses = responses.filter((r) => !this.httpResponse.isErrorResponse(r.responseContent));
|
|
13
|
+
}
|
|
14
|
+
const voidType = { kind: "Intrinsic", name: "void" };
|
|
15
|
+
let httpReturnType = voidType;
|
|
16
|
+
if (!responses.length) {
|
|
17
|
+
return voidType;
|
|
18
|
+
}
|
|
19
|
+
if (responses.length > 1) {
|
|
20
|
+
const res = [...new Set(responses.map((r) => r.responseContent.body?.type))];
|
|
21
|
+
httpReturnType = this.union.create({
|
|
22
|
+
variants: res.map((t) => {
|
|
23
|
+
return this.unionVariant.create({
|
|
24
|
+
type: getEffectiveType(this, t),
|
|
25
|
+
});
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
httpReturnType = getEffectiveType(this, responses[0].responseContent.body?.type);
|
|
31
|
+
}
|
|
32
|
+
return httpReturnType;
|
|
33
|
+
},
|
|
34
|
+
getResponses(operation) {
|
|
35
|
+
const responsesMap = [];
|
|
36
|
+
const httpOperation = this.httpOperation.get(operation);
|
|
37
|
+
for (const response of httpOperation.responses) {
|
|
38
|
+
for (const responseContent of response.responses) {
|
|
39
|
+
const contentTypeProperty = responseContent.properties.find((property) => property.kind === "contentType");
|
|
40
|
+
let contentType;
|
|
41
|
+
if (contentTypeProperty) {
|
|
42
|
+
contentType = contentTypeProperty.property.type.value;
|
|
43
|
+
}
|
|
44
|
+
else if (responseContent.body) {
|
|
45
|
+
contentType = "application/json";
|
|
46
|
+
}
|
|
47
|
+
responsesMap.push({ statusCode: response.statusCodes, contentType, responseContent });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return responsesMap;
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
function getEffectiveType(typekit, type) {
|
|
55
|
+
if (type === undefined) {
|
|
56
|
+
return { kind: "Intrinsic", name: "void" };
|
|
57
|
+
}
|
|
58
|
+
if (typekit.model.is(type)) {
|
|
59
|
+
return typekit.model.getEffectiveModel(type);
|
|
60
|
+
}
|
|
61
|
+
return type;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=http-operation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-operation.js","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/http-operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA4C,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAE,SAAS,EAAW,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA6D1D,SAAS,CAAmB;IAC1B,aAAa,EAAE;QACb,GAAG,CAAC,EAAE;YACJ,OAAO,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;QAC/D,CAAC;QACD,aAAa,CAAC,SAAS,EAAE,OAAO;YAC9B,IAAI,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;YAE3D,IAAI,CAAC,OAAO,EAAE,aAAa,EAAE,CAAC;gBAC5B,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,CA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,MAAM,mBAAmB,GAAG,eAAe,CAAC,UAAU,CAAC,IAAI,CACzD,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,aAAa,CAC9C,CAAC;oBAEF,IAAI,WAA+B,CAAC;oBAEpC,IAAI,mBAAmB,EAAE,CAAC;wBACxB,WAAW,GAAI,mBAAmB,CAAC,QAAQ,CAAC,IAAsB,CAAC,KAAK,CAAC;oBAC3E,CAAC;yBAAM,IAAI,eAAe,CAAC,IAAI,EAAE,CAAC;wBAChC,WAAW,GAAG,kBAAkB,CAAC;oBACnC,CAAC;oBAED,YAAY,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,QAAQ,CAAC,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;gBACxF,CAAC;YACH,CAAC;YAED,OAAO,YAAY,CAAC;QACtB,CAAC;KACF;CACF,CAAC,CAAC;AAEH,SAAS,gBAAgB,CAAC,OAAgB,EAAE,IAAW;IACrD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAc,CAAC;IACzD,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Model } from "@typespec/compiler";
|
|
2
|
+
import { HttpOperation } from "../../../types.js";
|
|
3
|
+
export type HttpRequestParameterKind = "query" | "header" | "path" | "contentType" | "body";
|
|
4
|
+
interface HttpRequestKit {
|
|
5
|
+
body: {
|
|
6
|
+
/**
|
|
7
|
+
* Checks the body is a property explicitly tagged with @body or @bodyRoot
|
|
8
|
+
* @param httpOperation the http operation to check
|
|
9
|
+
*/
|
|
10
|
+
isExplicit(httpOperation: HttpOperation): boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Gets a Model representing the body parameters of an http operation.
|
|
14
|
+
* @param httpOperation the http operation to get the body parameters from
|
|
15
|
+
*/
|
|
16
|
+
getBodyParameters(httpOperation: HttpOperation): Model | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Gets a Model representing the parameters of an http operation.
|
|
19
|
+
* @param httpOperation The Http operation to get the parameters from.
|
|
20
|
+
* @param kind A string to filters specific parameter kinds, or an array to combine multiple kinds.
|
|
21
|
+
*/
|
|
22
|
+
getParameters(httpOperation: HttpOperation, kind: HttpRequestParameterKind[] | HttpRequestParameterKind): Model | undefined;
|
|
23
|
+
}
|
|
24
|
+
interface TypekitExtension {
|
|
25
|
+
httpRequest: HttpRequestKit;
|
|
26
|
+
}
|
|
27
|
+
declare module "@typespec/compiler/experimental/typekit" {
|
|
28
|
+
interface Typekit extends TypekitExtension {
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
32
|
+
//# sourceMappingURL=http-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-request.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/http-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAiB,MAAM,oBAAoB,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,aAAa,GAAG,MAAM,CAAC;AAE5F,UAAU,cAAc;IACtB,IAAI,EAAE;QACJ;;;WAGG;QACH,UAAU,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC;KACnD,CAAC;IACF;;;OAGG;IACH,iBAAiB,CAAC,aAAa,EAAE,aAAa,GAAG,KAAK,GAAG,SAAS,CAAC;IACnE;;;;OAIG;IACH,aAAa,CACX,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,wBAAwB,EAAE,GAAG,wBAAwB,GAC1D,KAAK,GAAG,SAAS,CAAC;CACtB;AAED,UAAU,gBAAgB;IACxB,WAAW,EAAE,cAAc,CAAC;CAC7B;AAED,OAAO,QAAQ,yCAAyC,CAAC;IACvD,UAAU,OAAQ,SAAQ,gBAAgB;KAAG;CAC9C"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { defineKit } from "@typespec/compiler/experimental/typekit";
|
|
2
|
+
defineKit({
|
|
3
|
+
httpRequest: {
|
|
4
|
+
body: {
|
|
5
|
+
isExplicit(httpOperation) {
|
|
6
|
+
return (httpOperation.parameters.properties.find((p) => p.kind === "body" || p.kind === "bodyRoot") !== undefined);
|
|
7
|
+
},
|
|
8
|
+
},
|
|
9
|
+
getBodyParameters(httpOperation) {
|
|
10
|
+
const body = httpOperation.parameters.body;
|
|
11
|
+
if (!body) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const bodyProperty = body.property;
|
|
15
|
+
if (!bodyProperty) {
|
|
16
|
+
if (body.type.kind === "Model") {
|
|
17
|
+
return body.type;
|
|
18
|
+
}
|
|
19
|
+
throw new Error("Body property not found");
|
|
20
|
+
}
|
|
21
|
+
const bodyPropertyName = bodyProperty.name ? bodyProperty.name : "body";
|
|
22
|
+
return this.model.create({
|
|
23
|
+
properties: { [bodyPropertyName]: bodyProperty },
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
getParameters(httpOperation, kind) {
|
|
27
|
+
const kinds = new Set(Array.isArray(kind) ? kind : [kind]);
|
|
28
|
+
const parameterProperties = [];
|
|
29
|
+
for (const kind of kinds) {
|
|
30
|
+
if (kind === "body") {
|
|
31
|
+
const bodyParams = Array.from(this.httpRequest.getBodyParameters(httpOperation)?.properties.values() ?? []);
|
|
32
|
+
if (bodyParams) {
|
|
33
|
+
parameterProperties.push(...bodyParams);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const params = httpOperation.parameters.properties
|
|
38
|
+
.filter((p) => p.kind === kind)
|
|
39
|
+
.map((p) => p.property);
|
|
40
|
+
parameterProperties.push(...params);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (parameterProperties.length === 0) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
const properties = parameterProperties.reduce((acc, prop) => {
|
|
47
|
+
acc[prop.name] = prop;
|
|
48
|
+
return acc;
|
|
49
|
+
}, {});
|
|
50
|
+
return this.model.create({ properties });
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=http-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-request.js","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/http-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAqCpE,SAAS,CAAmB;IAC1B,WAAW,EAAE;QACX,IAAI,EAAE;YACJ,UAAU,CAAC,aAA4B;gBACrC,OAAO,CACL,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CACtC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,CAClD,KAAK,SAAS,CAChB,CAAC;YACJ,CAAC;SACF;QACD,iBAAiB,CAAC,aAA4B;YAC5C,MAAM,IAAI,GAAG,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC;YAE3C,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC;YAEnC,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;oBAC/B,OAAO,IAAI,CAAC,IAAI,CAAC;g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AAC;YAED,IAAI,mBAAmB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACrC,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAC3C,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;gBACZ,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;gBACtB,OAAO,GAAG,CAAC;YACb,CAAC,EACD,EAAmC,CACpC,CAAC;YAEF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;QAC3C,CAAC;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { HttpOperationResponseContent, HttpStatusCodeRange, HttpStatusCodesEntry } from "../../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Utilities for working with HTTP responses.
|
|
4
|
+
* @experimental
|
|
5
|
+
*/
|
|
6
|
+
export interface HttpResponseKit {
|
|
7
|
+
/**
|
|
8
|
+
* Check if the response is an error response.
|
|
9
|
+
*/
|
|
10
|
+
isErrorResponse(response: HttpOperationResponseContent): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* utilities to perform checks on status codes
|
|
13
|
+
*/
|
|
14
|
+
statusCode: {
|
|
15
|
+
/**
|
|
16
|
+
* Check if the status code is a single status code
|
|
17
|
+
* @param statusCode status code to check
|
|
18
|
+
*/
|
|
19
|
+
isSingle(statusCode: HttpStatusCodesEntry): statusCode is number;
|
|
20
|
+
/**
|
|
21
|
+
* Check if the status code is a range of status codes
|
|
22
|
+
* @param statusCode status code to check
|
|
23
|
+
*/
|
|
24
|
+
isRange(statusCode: HttpStatusCodesEntry): statusCode is HttpStatusCodeRange;
|
|
25
|
+
/**
|
|
26
|
+
* Check if the status code is a default status code
|
|
27
|
+
* @param statusCode status code to check
|
|
28
|
+
*/
|
|
29
|
+
isDefault(statusCode: HttpStatusCodesEntry): statusCode is "*";
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
interface TypekitExtension {
|
|
33
|
+
/**
|
|
34
|
+
* Utilities for working with HTTP responses.
|
|
35
|
+
* @experimental
|
|
36
|
+
*/
|
|
37
|
+
httpResponse: HttpResponseKit;
|
|
38
|
+
}
|
|
39
|
+
declare module "@typespec/compiler/experimental/typekit" {
|
|
40
|
+
interface Typekit extends TypekitExtension {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=http-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/http-response.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,EAC5B,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,eAAe,CAAC,QAAQ,EAAE,4BAA4B,GAAG,OAAO,CAAC;IACjE;;OAEG;IACH,UAAU,EAAE;QACV;;;WAGG;QACH,QAAQ,CAAC,UAAU,EAAE,oBAAoB,GAAG,UAAU,IAAI,MAAM,CAAC;QACjE;;;WAGG;QACH,OAAO,CAAC,UAAU,EAAE,oBAAoB,GAAG,UAAU,IAAI,mBAAmB,CAAC;QAC7E;;;WAGG;QACH,SAAS,CAAC,UAAU,EAAE,oBAAoB,GAAG,UAAU,IAAI,GAAG,CAAC;KAChE,CAAC;CACH;AAED,UAAU,gBAAgB;IACxB;;;OAGG;IACH,YAAY,EAAE,eAAe,CAAC;CAC/B;AAED,OAAO,QAAQ,yCAAyC,CAAC;IACvD,UAAU,OAAQ,SAAQ,gBAAgB;KAAG;CAC9C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isErrorModel } from "@typespec/compiler";
|
|
2
|
+
import { defineKit } from "@typespec/compiler/experimental/typekit";
|
|
3
|
+
defineKit({
|
|
4
|
+
httpResponse: {
|
|
5
|
+
isErrorResponse(response) {
|
|
6
|
+
return response.body ? isErrorModel(this.program, response.body.type) : false;
|
|
7
|
+
},
|
|
8
|
+
statusCode: {
|
|
9
|
+
isSingle(statusCode) {
|
|
10
|
+
return typeof statusCode === "number";
|
|
11
|
+
},
|
|
12
|
+
isRange(statusCode) {
|
|
13
|
+
return typeof statusCode === "object" && "start" in statusCode && "end" in statusCode;
|
|
14
|
+
},
|
|
15
|
+
isDefault(statusCode) {
|
|
16
|
+
return statusCode === "*";
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
//# sourceMappingURL=http-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-response.js","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/http-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAkDpE,SAAS,CAAmB;IAC1B,YAAY,EAAE;QACZ,eAAe,CAAC,QAAQ;YACtB,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAChF,CAAC;QACD,UAAU,EAAE;YACV,QAAQ,CAAC,UAAU;gBACjB,OAAO,OAAO,UAAU,KAAK,QAAQ,CAAC;YACxC,CAAC;YACD,OAAO,CAAC,UAAU;gBAChB,OAAO,OAAO,UAAU,KAAK,QAAQ,IAAI,OAAO,IAAI,UAAU,IAAI,KAAK,IAAI,UAAU,CAAC;YACxF,CAAC;YACD,SAAS,CAAC,UAAU;gBAClB,OAAO,UAAU,KAAK,GAAG,CAAC;YAC5B,CAAC;SACF;KACF;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ModelProperty } from "@typespec/compiler";
|
|
2
|
+
import { HeaderFieldOptions, PathParameterOptions, QueryParameterOptions } from "../../../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Utilities for working with model properties in the context of Http.
|
|
5
|
+
* @experimental
|
|
6
|
+
*/
|
|
7
|
+
export interface HttpModelProperty {
|
|
8
|
+
/**
|
|
9
|
+
* Get the Http parameter options for a model property.
|
|
10
|
+
* @param prop a TypeSpec ModelProperty
|
|
11
|
+
*/
|
|
12
|
+
getHttpParamOptions(prop: ModelProperty): HeaderFieldOptions | PathParameterOptions | QueryParameterOptions | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Get the Http header options for a model property.
|
|
15
|
+
* @param prop a TypeSpec ModelProperty
|
|
16
|
+
*/
|
|
17
|
+
getHttpHeaderOptions(prop: ModelProperty): HeaderFieldOptions | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Get the Http path options for a model property.
|
|
20
|
+
* @param prop a TypeSpec ModelProperty
|
|
21
|
+
*/
|
|
22
|
+
getHttpPathOptions(prop: ModelProperty): PathParameterOptions | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Get the Http query options for a model property.
|
|
25
|
+
* @param prop a TypeSpec ModelProperty
|
|
26
|
+
*/
|
|
27
|
+
getHttpQueryOptions(prop: ModelProperty): QueryParameterOptions | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Check if a model property is an Http header.
|
|
30
|
+
* @param prop a TypeSpec ModelProperty
|
|
31
|
+
*/
|
|
32
|
+
isHttpHeader(prop: ModelProperty): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a model property is an Http path parameter.
|
|
35
|
+
* @param prop a TypeSpec ModelProperty
|
|
36
|
+
*/
|
|
37
|
+
isHttpPathParam(prop: ModelProperty): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if a model property is an Http query parameter.
|
|
40
|
+
* @param prop a TypeSpec ModelProperty
|
|
41
|
+
*/
|
|
42
|
+
isHttpQueryParam(prop: ModelProperty): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Check if a model property is an Http multipart body.
|
|
45
|
+
* @param prop a TypeSpec ModelProperty
|
|
46
|
+
*/
|
|
47
|
+
isHttpMultipartBody(prop: ModelProperty): boolean;
|
|
48
|
+
}
|
|
49
|
+
declare module "@typespec/compiler/experimental/typekit" {
|
|
50
|
+
interface ModelPropertyKit extends HttpModelProperty {
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=model-property.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-property.d.ts","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/model-property.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAWnD,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAEpG;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,mBAAmB,CACjB,IAAI,EAAE,aAAa,GAClB,kBAAkB,GAAG,oBAAoB,GAAG,qBAAqB,GAAG,SAAS,CAAC;IACjF;;;OAGG;IACH,oBAAoB,CAAC,IAAI,EAAE,aAAa,GAAG,kBAAkB,GAAG,SAAS,CAAC;IAC1E;;;OAGG;IACH,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,oBAAoB,GAAG,SAAS,CAAC;IAC1E;;;OAGG;IACH,mBAAmB,CAAC,IAAI,EAAE,aAAa,GAAG,qBAAqB,GAAG,SAAS,CAAC;IAC5E;;;OAGG;IACH,YAAY,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC;IAC3C;;;OAGG;IACH,eAAe,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC;IAC9C;;;OAGG;IACH,gBAAgB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC;IAC/C;;;OAGG;IACH,mBAAmB,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC;CACnD;AAMD,OAAO,QAAQ,yCAAyC,CAAC;IACvD,UAAU,gBAAiB,SAAQ,iBAAiB;KAAG;CACxD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineKit } from "@typespec/compiler/experimental/typekit";
|
|
2
|
+
import { getHeaderFieldOptions, getPathParamOptions, getQueryParamOptions, isHeader, isMultipartBodyProperty, isPathParam, isQueryParam, } from "../../../decorators.js";
|
|
3
|
+
defineKit({
|
|
4
|
+
modelProperty: {
|
|
5
|
+
getHttpParamOptions(prop) {
|
|
6
|
+
if (isHeader(this.program, prop)) {
|
|
7
|
+
return getHeaderFieldOptions(this.program, prop);
|
|
8
|
+
}
|
|
9
|
+
if (isPathParam(this.program, prop)) {
|
|
10
|
+
return getPathParamOptions(this.program, prop);
|
|
11
|
+
}
|
|
12
|
+
if (isQueryParam(this.program, prop)) {
|
|
13
|
+
return getQueryParamOptions(this.program, prop);
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
},
|
|
17
|
+
getHttpHeaderOptions(prop) {
|
|
18
|
+
return getHeaderFieldOptions(this.program, prop);
|
|
19
|
+
},
|
|
20
|
+
getHttpPathOptions(prop) {
|
|
21
|
+
return getPathParamOptions(this.program, prop);
|
|
22
|
+
},
|
|
23
|
+
getHttpQueryOptions(prop) {
|
|
24
|
+
return getQueryParamOptions(this.program, prop);
|
|
25
|
+
},
|
|
26
|
+
isHttpHeader(prop) {
|
|
27
|
+
return isHeader(this.program, prop);
|
|
28
|
+
},
|
|
29
|
+
isHttpPathParam(prop) {
|
|
30
|
+
return isPathParam(this.program, prop);
|
|
31
|
+
},
|
|
32
|
+
isHttpQueryParam(prop) {
|
|
33
|
+
return isQueryParam(this.program, prop);
|
|
34
|
+
},
|
|
35
|
+
isHttpMultipartBody(prop) {
|
|
36
|
+
return isMultipartBodyProperty(this.program, prop);
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=model-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-property.js","sourceRoot":"","sources":["../../../../../src/experimental/typekit/kits/model-property.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,QAAQ,EACR,uBAAuB,EACvB,WAAW,EACX,YAAY,GACb,MAAM,wBAAwB,CAAC;AA4DhC,SAAS,CAAmB;IAC1B,aAAa,EAAE;QACb,mBAAmB,CAAC,IAAmB;YACrC,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;gBACjC,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACnD,CAAC;YAED,IAAI,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;gBACpC,OAAO,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACjD,CAAC;YAED,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC;gBACrC,OAAO,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAClD,CAAC;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,oBAAoB,CAAC,IAAmB;YACtC,OAAO,qBAAqB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACnD,CAAC;QACD,kBAAkB,CAAC,IAAI;YACrB,OAAO,mBAAmB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACjD,CAAC;QACD,mBAAmB,CAAC,IAAmB;YACrC,OAAO,oBAAoB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;QACD,YAAY,CAAC,IAAmB;YAC9B,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACtC,CAAC;QACD,eAAe,CAAC,IAAmB;YACjC,OAAO,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACzC,CAAC;QACD,gBAAgB,CAAC,IAAmB;YAClC,OAAO,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC1C,CAAC;QACD,mBAAmB,CAAC,IAAmB;YACrC,OAAO,uBAAuB,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KACF;CACF,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/http",
|
|
3
|
-
"version": "0.65.0-dev.
|
|
3
|
+
"version": "0.65.0-dev.4",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec HTTP protocol binding",
|
|
6
6
|
"homepage": "https://github.com/microsoft/typespec",
|
|
@@ -38,6 +38,10 @@
|
|
|
38
38
|
"./experimental": {
|
|
39
39
|
"types": "./dist/src/experimental/index.d.ts",
|
|
40
40
|
"default": "./dist/src/experimental/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./experimental/typekit": {
|
|
43
|
+
"types": "./dist/src/experimental/typekit/index.d.ts",
|
|
44
|
+
"default": "./dist/src/experimental/typekit/index.js"
|
|
41
45
|
}
|
|
42
46
|
},
|
|
43
47
|
"engines": {
|
|
@@ -58,16 +62,16 @@
|
|
|
58
62
|
}
|
|
59
63
|
},
|
|
60
64
|
"devDependencies": {
|
|
61
|
-
"@types/node": "~22.10.
|
|
65
|
+
"@types/node": "~22.10.10",
|
|
62
66
|
"@typespec/compiler": "~0.64.0 || >=0.65.0-dev <0.65.0",
|
|
63
67
|
"@typespec/library-linter": "~0.64.0 || >=0.65.0-dev <0.65.0",
|
|
64
68
|
"@typespec/streams": "~0.64.0 || >=0.65.0-dev <0.65.0",
|
|
65
|
-
"@vitest/coverage-v8": "^3.0.
|
|
69
|
+
"@vitest/coverage-v8": "^3.0.4",
|
|
66
70
|
"@vitest/ui": "^3.0.3",
|
|
67
71
|
"c8": "^10.1.3",
|
|
68
72
|
"rimraf": "~6.0.1",
|
|
69
73
|
"typescript": "~5.7.3",
|
|
70
|
-
"vitest": "^3.0.
|
|
74
|
+
"vitest": "^3.0.4",
|
|
71
75
|
"@typespec/tspd": "~0.46.0"
|
|
72
76
|
},
|
|
73
77
|
"dependencies": {},
|