@typespec/http 0.64.0-dev.0 → 0.64.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.
@@ -0,0 +1,2 @@
1
+ export { StreamMetadata, getStreamMetadata } from "./streams.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { getStreamMetadata } from "./streams.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { Program, Type } from "@typespec/compiler";
2
+ import { HttpOperationParameters, HttpOperationResponseContent } from "../types.js";
3
+ export interface StreamMetadata {
4
+ /**
5
+ * The `Type` of the property decorated with `@body`.
6
+ */
7
+ bodyType: Type;
8
+ /**
9
+ * The `Type` of the stream model.
10
+ * For example, an instance of `HttpStream`.
11
+ */
12
+ originalType: Type;
13
+ /**
14
+ * The `Type` of the streaming payload.
15
+ *
16
+ * For example, given `HttpStream<Foo, "application/jsonl">`,
17
+ * the `streamType` would be `Foo`.
18
+ */
19
+ streamType: Type;
20
+ /**
21
+ * The list of content-types that this stream supports.
22
+ */
23
+ contentTypes: string[];
24
+ }
25
+ /**
26
+ * Gets stream metadata for a given `HttpOperationParameters` or `HttpOperationResponseContent`.
27
+ */
28
+ export declare function getStreamMetadata(program: Program, httpParametersOrResponse: HttpOperationParameters | HttpOperationResponseContent): StreamMetadata | undefined;
29
+ //# sourceMappingURL=streams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.d.ts","sourceRoot":"","sources":["../../../src/experimental/streams.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAYpF,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,QAAQ,EAAE,IAAI,CAAC;IACf;;;OAGG;IACH,YAAY,EAAE,IAAI,CAAC;IACnB;;;;;OAKG;IACH,UAAU,EAAE,IAAI,CAAC;IACjB;;OAEG;IACH,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,OAAO,EAChB,wBAAwB,EAAE,uBAAuB,GAAG,4BAA4B,GAC/E,cAAc,GAAG,SAAS,CAoB5B"}
@@ -0,0 +1,48 @@
1
+ let getStreamOf;
2
+ try {
3
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
4
+ // @ts-ignore
5
+ getStreamOf = (await import("@typespec/streams")).getStreamOf;
6
+ }
7
+ catch {
8
+ getStreamOf = () => {
9
+ throw new Error("@typespec/streams was not found");
10
+ };
11
+ }
12
+ /**
13
+ * Gets stream metadata for a given `HttpOperationParameters` or `HttpOperationResponseContent`.
14
+ */
15
+ export function getStreamMetadata(program, httpParametersOrResponse) {
16
+ const body = httpParametersOrResponse.body;
17
+ if (!body)
18
+ return;
19
+ const contentTypes = body.contentTypes;
20
+ if (!contentTypes.length)
21
+ return;
22
+ // @body is always explicitly set by HttpStream, so body.property will be defined.
23
+ const bodyProperty = body.property;
24
+ if (!bodyProperty)
25
+ return;
26
+ const streamData = getStreamFromBodyProperty(program, bodyProperty);
27
+ if (!streamData)
28
+ return;
29
+ return {
30
+ bodyType: body.type,
31
+ originalType: streamData.model,
32
+ streamType: streamData.streamOf,
33
+ contentTypes: contentTypes,
34
+ };
35
+ }
36
+ function getStreamFromBodyProperty(program, bodyProperty) {
37
+ // Check the model first, then if we can't find it, fallback to the sourceProperty model.
38
+ const streamOf = bodyProperty.model ? getStreamOf(program, bodyProperty.model) : undefined;
39
+ if (streamOf) {
40
+ // if `streamOf` is defined, then we know that `bodyProperty.model` is defined.
41
+ return { model: bodyProperty.model, streamOf };
42
+ }
43
+ if (bodyProperty.sourceProperty) {
44
+ return getStreamFromBodyProperty(program, bodyProperty.sourceProperty);
45
+ }
46
+ return;
47
+ }
48
+ //# sourceMappingURL=streams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.js","sourceRoot":"","sources":["../../../src/experimental/streams.ts"],"names":[],"mappings":"AAEA,IAAI,WAA2D,CAAC;AAChE,IAAI,CAAC;IACH,6DAA6D;IAC7D,aAAa;IACb,WAAW,GAAG,CAAC,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAC,WAAW,CAAC;AAChE,CAAC;AAAC,MAAM,CAAC;IACP,WAAW,GAAG,GAAG,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC,CAAC;AACJ,CAAC;AAyBD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAgB,EAChB,wBAAgF;IAEhF,MAAM,IAAI,GAAG,wBAAwB,CAAC,IAAI,CAAC;IAC3C,IAAI,CAAC,IAAI;QAAE,OAAO;IAElB,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;IACvC,IAAI,CAAC,YAAY,CAAC,MAAM;QAAE,OAAO;IAEjC,kFAAkF;IAClF,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC;IACnC,IAAI,CAAC,YAAY;QAAE,OAAO;IAE1B,MAAM,UAAU,GAAG,yBAAyB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACpE,IAAI,CAAC,UAAU;QAAE,OAAO;IAExB,OAAO;QACL,QAAQ,EAAE,IAAI,CAAC,IAAI;QACnB,YAAY,EAAE,UAAU,CAAC,KAAK;QAC9B,UAAU,EAAE,UAAU,CAAC,QAAQ;QAC/B,YAAY,EAAE,YAAY;KAC3B,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAChC,OAAgB,EAChB,YAA2B;IAE3B,yFAAyF;IACzF,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,OAAO,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE3F,IAAI,QAAQ,EAAE,CAAC;QACb,+EAA+E;QAC/E,OAAO,EAAE,KAAK,EAAE,YAAY,CAAC,KAAM,EAAE,QAAQ,EAAE,CAAC;IAClD,CAAC;IAED,IAAI,YAAY,CAAC,cAAc,EAAE,CAAC;QAChC,OAAO,yBAAyB,CAAC,OAAO,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;IACzE,CAAC;IACD,OAAO;AACT,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typespec/http",
3
- "version": "0.64.0-dev.0",
3
+ "version": "0.64.0",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec HTTP protocol binding",
6
6
  "homepage": "https://github.com/microsoft/typespec",
@@ -34,6 +34,10 @@
34
34
  "typespec": "./lib/streams/main.tsp",
35
35
  "types": "./dist/src/streams/index.d.ts",
36
36
  "default": "./dist/src/streams/index.js"
37
+ },
38
+ "./experimental": {
39
+ "types": "./dist/src/experimental/index.d.ts",
40
+ "default": "./dist/src/experimental/index.js"
37
41
  }
38
42
  },
39
43
  "engines": {
@@ -45,8 +49,8 @@
45
49
  "!dist/test/**"
46
50
  ],
47
51
  "peerDependencies": {
48
- "@typespec/compiler": "~0.63.0 || >=0.64.0-dev <0.64.0",
49
- "@typespec/streams": "~0.63.0 || >=0.64.0-dev <0.64.0"
52
+ "@typespec/compiler": "~0.64.0",
53
+ "@typespec/streams": "~0.64.0"
50
54
  },
51
55
  "peerDependenciesMeta": {
52
56
  "@typespec/streams": {
@@ -55,18 +59,17 @@
55
59
  },
56
60
  "devDependencies": {
57
61
  "@types/node": "~22.7.9",
58
- "@typespec/compiler": "~0.63.0 || >=0.64.0-dev <0.64.0",
59
- "@typespec/library-linter": "~0.63.0 || >=0.64.0-dev <0.64.0",
60
- "@typespec/streams": "~0.63.0 || >=0.64.0-dev <0.64.0",
61
62
  "@vitest/coverage-v8": "^2.1.5",
62
63
  "@vitest/ui": "^2.1.2",
63
64
  "c8": "^10.1.2",
64
65
  "rimraf": "~6.0.1",
65
66
  "typescript": "~5.6.3",
66
67
  "vitest": "^2.1.5",
68
+ "@typespec/compiler": "~0.64.0",
69
+ "@typespec/library-linter": "~0.64.0",
70
+ "@typespec/streams": "~0.64.0",
67
71
  "@typespec/tspd": "~0.46.0"
68
72
  },
69
- "dependencies": {},
70
73
  "scripts": {
71
74
  "clean": "rimraf ./dist ./temp",
72
75
  "build": "npm run gen-extern-signature && tsc -p . && npm run lint-typespec-library",