@typespec/ts-http-runtime 1.0.0-alpha.20241101.1 → 1.0.0-alpha.20241111.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/README.md +23 -12
- package/dist/browser/abort-controller/AbortError.d.ts +1 -1
- package/dist/browser/abort-controller/AbortError.js +1 -1
- package/dist/browser/abort-controller/AbortError.js.map +1 -1
- package/dist/browser/client/common.d.ts +2 -2
- package/dist/browser/client/common.js.map +1 -1
- package/dist/commonjs/abort-controller/AbortError.d.ts +1 -1
- package/dist/commonjs/abort-controller/AbortError.js +1 -1
- package/dist/commonjs/abort-controller/AbortError.js.map +1 -1
- package/dist/commonjs/client/common.d.ts +2 -2
- package/dist/commonjs/client/common.js.map +1 -1
- package/dist/esm/abort-controller/AbortError.d.ts +1 -1
- package/dist/esm/abort-controller/AbortError.js +1 -1
- package/dist/esm/abort-controller/AbortError.js.map +1 -1
- package/dist/esm/client/common.d.ts +2 -2
- package/dist/esm/client/common.js.map +1 -1
- package/dist/react-native/abort-controller/AbortError.d.ts +1 -1
- package/dist/react-native/abort-controller/AbortError.js +1 -1
- package/dist/react-native/abort-controller/AbortError.js.map +1 -1
- package/dist/react-native/client/common.d.ts +2 -2
- package/dist/react-native/client/common.js.map +1 -1
- package/dist/ts-http-runtime.d.ts +3 -3
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -32,9 +32,9 @@ A `PipelineResponse` describes the HTTP response (body, headers, and status code
|
|
|
32
32
|
A `SendRequest` method is a method that given a `PipelineRequest` can asynchronously return a `PipelineResponse`.
|
|
33
33
|
|
|
34
34
|
```ts snippet:send_request
|
|
35
|
-
import { PipelineResponse } from "@typespec/ts-http-runtime";
|
|
35
|
+
import { PipelineRequest, PipelineResponse } from "@typespec/ts-http-runtime";
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
type SendRequest = (request: PipelineRequest) => Promise<PipelineResponse>;
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
### HttpClient
|
|
@@ -42,7 +42,9 @@ export type SendRequest = (request: PipelineRequest) => Promise<PipelineResponse
|
|
|
42
42
|
An `HttpClient` is any object that satisfies the following interface to implement a `SendRequest` method:
|
|
43
43
|
|
|
44
44
|
```ts snippet:http_request
|
|
45
|
-
|
|
45
|
+
import { SendRequest } from "@typespec/ts-http-runtime";
|
|
46
|
+
|
|
47
|
+
interface HttpClient {
|
|
46
48
|
/**
|
|
47
49
|
* The method that makes the request and returns a response.
|
|
48
50
|
*/
|
|
@@ -57,9 +59,9 @@ export interface HttpClient {
|
|
|
57
59
|
A `PipelinePolicy` is a simple object that implements the following interface:
|
|
58
60
|
|
|
59
61
|
```ts snippet:pipeline_policy
|
|
60
|
-
import { PipelineResponse } from "@typespec/ts-http-runtime";
|
|
62
|
+
import { PipelineRequest, SendRequest, PipelineResponse } from "@typespec/ts-http-runtime";
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
interface PipelinePolicy {
|
|
63
65
|
/**
|
|
64
66
|
* The policy name. Must be a unique string in the pipeline.
|
|
65
67
|
*/
|
|
@@ -80,7 +82,7 @@ One can view the role of policies as that of `middleware`, a concept that is fam
|
|
|
80
82
|
The `sendRequest` implementation can both transform the outgoing request as well as the incoming response:
|
|
81
83
|
|
|
82
84
|
```ts snippet:custom_policy
|
|
83
|
-
import { PipelineResponse } from "@typespec/ts-http-runtime";
|
|
85
|
+
import { PipelineRequest, SendRequest, PipelineResponse } from "@typespec/ts-http-runtime";
|
|
84
86
|
|
|
85
87
|
const customPolicy = {
|
|
86
88
|
name: "My wonderful policy",
|
|
@@ -88,7 +90,7 @@ const customPolicy = {
|
|
|
88
90
|
// Change the outgoing request by adding a new header
|
|
89
91
|
request.headers.set("X-Cool-Header", 42);
|
|
90
92
|
const result = await next(request);
|
|
91
|
-
if (
|
|
93
|
+
if (result.status === 403) {
|
|
92
94
|
// Do something special if this policy sees Forbidden
|
|
93
95
|
}
|
|
94
96
|
return result;
|
|
@@ -107,10 +109,17 @@ You can think of policies being applied like a stack (first-in/last-out.) The fi
|
|
|
107
109
|
A `Pipeline` satisfies the following interface:
|
|
108
110
|
|
|
109
111
|
```ts snippet:pipeline
|
|
110
|
-
import {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
import {
|
|
113
|
+
PipelinePolicy,
|
|
114
|
+
AddPipelineOptions,
|
|
115
|
+
PipelinePhase,
|
|
116
|
+
HttpClient,
|
|
117
|
+
PipelineRequest,
|
|
118
|
+
PipelineResponse,
|
|
119
|
+
} from "@typespec/ts-http-runtime";
|
|
120
|
+
|
|
121
|
+
interface Pipeline {
|
|
122
|
+
addPolicy(policy: PipelinePolicy, options?: AddPipelineOptions): void;
|
|
114
123
|
removePolicy(options: { name?: string; phase?: PipelinePhase }): PipelinePolicy[];
|
|
115
124
|
sendRequest(httpClient: HttpClient, request: PipelineRequest): Promise<PipelineResponse>;
|
|
116
125
|
getOrderedPolicies(): PipelinePolicy[];
|
|
@@ -132,7 +141,9 @@ Phases occur in the above order, with serialization policies being applied first
|
|
|
132
141
|
When adding a policy to the pipeline you can specify not only what phase a policy is in, but also if it has any dependencies:
|
|
133
142
|
|
|
134
143
|
```ts snippet:add_policy_options
|
|
135
|
-
|
|
144
|
+
import { PipelinePhase } from "@typespec/ts-http-runtime";
|
|
145
|
+
|
|
146
|
+
interface AddPipelineOptions {
|
|
136
147
|
beforePolicies?: string[];
|
|
137
148
|
afterPolicies?: string[];
|
|
138
149
|
afterPhase?: PipelinePhase;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * ```ts snippet:abort_error\n * import { AbortError } from \"@typespec/ts-http-runtime\";\n *\n * async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {\n * if (options.abortSignal.aborted) {\n * throw new AbortError();\n * }\n * // do async work\n * }\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork({ abortSignal: controller.signal });\n * } catch (e) {\n * if (e.name === \"AbortError\") {\n * // handle abort error here.\n * }\n * }\n * ```\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * ```ts snippet:abort_error\n * import { AbortError } from \"@typespec/ts-http-runtime\";\n *\n * async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {\n * if (options.abortSignal.aborted) {\n * throw new AbortError();\n * }\n * // do async work\n * }\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork({ abortSignal: controller.signal });\n * } catch (e) {\n * if (e instanceof Error && e.name === \"AbortError\") {\n * // handle abort error here.\n * }\n * }\n * ```\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n"]}
|
|
@@ -163,9 +163,9 @@ export interface Client {
|
|
|
163
163
|
* strong types. When used by the codegen this type gets overridden with the generated
|
|
164
164
|
* types. For example:
|
|
165
165
|
* ```typescript snippet:path_example
|
|
166
|
-
* import { Client
|
|
166
|
+
* import { Client } from "@typespec/ts-http-runtime";
|
|
167
167
|
*
|
|
168
|
-
*
|
|
168
|
+
* type MyClient = Client & {
|
|
169
169
|
* path: Routes;
|
|
170
170
|
* };
|
|
171
171
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { OperationTracingOptions } from \"../tracing/interfaces.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:path_example\n * import { Client, Routes } from \"@typespec/ts-http-runtime\";\n *\n * export type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * Credentials information\n */\n credentials?: {\n /**\n * Authentication scopes for AAD\n */\n scopes?: string[];\n /**\n * Heder name for Client Secret authentication\n */\n apiKeyHeaderName?: string;\n };\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { OperationTracingOptions } from \"../tracing/interfaces.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:path_example\n * import { Client } from \"@typespec/ts-http-runtime\";\n *\n * type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * Credentials information\n */\n credentials?: {\n /**\n * Authentication scopes for AAD\n */\n scopes?: string[];\n /**\n * Heder name for Client Secret authentication\n */\n apiKeyHeaderName?: string;\n };\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortError.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AALD,gCAKC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * ```ts snippet:abort_error\n * import { AbortError } from \"@typespec/ts-http-runtime\";\n *\n * async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {\n * if (options.abortSignal.aborted) {\n * throw new AbortError();\n * }\n * // do async work\n * }\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork({ abortSignal: controller.signal });\n * } catch (e) {\n * if (e.name === \"AbortError\") {\n * // handle abort error here.\n * }\n * }\n * ```\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortError.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC;;;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAa,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AALD,gCAKC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * ```ts snippet:abort_error\n * import { AbortError } from \"@typespec/ts-http-runtime\";\n *\n * async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {\n * if (options.abortSignal.aborted) {\n * throw new AbortError();\n * }\n * // do async work\n * }\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork({ abortSignal: controller.signal });\n * } catch (e) {\n * if (e instanceof Error && e.name === \"AbortError\") {\n * // handle abort error here.\n * }\n * }\n * ```\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n"]}
|
|
@@ -163,9 +163,9 @@ export interface Client {
|
|
|
163
163
|
* strong types. When used by the codegen this type gets overridden with the generated
|
|
164
164
|
* types. For example:
|
|
165
165
|
* ```typescript snippet:path_example
|
|
166
|
-
* import { Client
|
|
166
|
+
* import { Client } from "@typespec/ts-http-runtime";
|
|
167
167
|
*
|
|
168
|
-
*
|
|
168
|
+
* type MyClient = Client & {
|
|
169
169
|
* path: Routes;
|
|
170
170
|
* };
|
|
171
171
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { OperationTracingOptions } from \"../tracing/interfaces.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:path_example\n * import { Client, Routes } from \"@typespec/ts-http-runtime\";\n *\n * export type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * Credentials information\n */\n credentials?: {\n /**\n * Authentication scopes for AAD\n */\n scopes?: string[];\n /**\n * Heder name for Client Secret authentication\n */\n apiKeyHeaderName?: string;\n };\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":";AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { OperationTracingOptions } from \"../tracing/interfaces.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:path_example\n * import { Client } from \"@typespec/ts-http-runtime\";\n *\n * type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * Credentials information\n */\n credentials?: {\n /**\n * Authentication scopes for AAD\n */\n scopes?: string[];\n /**\n * Heder name for Client Secret authentication\n */\n apiKeyHeaderName?: string;\n };\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * ```ts snippet:abort_error\n * import { AbortError } from \"@typespec/ts-http-runtime\";\n *\n * async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {\n * if (options.abortSignal.aborted) {\n * throw new AbortError();\n * }\n * // do async work\n * }\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork({ abortSignal: controller.signal });\n * } catch (e) {\n * if (e.name === \"AbortError\") {\n * // handle abort error here.\n * }\n * }\n * ```\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * ```ts snippet:abort_error\n * import { AbortError } from \"@typespec/ts-http-runtime\";\n *\n * async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {\n * if (options.abortSignal.aborted) {\n * throw new AbortError();\n * }\n * // do async work\n * }\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork({ abortSignal: controller.signal });\n * } catch (e) {\n * if (e instanceof Error && e.name === \"AbortError\") {\n * // handle abort error here.\n * }\n * }\n * ```\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n"]}
|
|
@@ -163,9 +163,9 @@ export interface Client {
|
|
|
163
163
|
* strong types. When used by the codegen this type gets overridden with the generated
|
|
164
164
|
* types. For example:
|
|
165
165
|
* ```typescript snippet:path_example
|
|
166
|
-
* import { Client
|
|
166
|
+
* import { Client } from "@typespec/ts-http-runtime";
|
|
167
167
|
*
|
|
168
|
-
*
|
|
168
|
+
* type MyClient = Client & {
|
|
169
169
|
* path: Routes;
|
|
170
170
|
* };
|
|
171
171
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { OperationTracingOptions } from \"../tracing/interfaces.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:path_example\n * import { Client, Routes } from \"@typespec/ts-http-runtime\";\n *\n * export type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * Credentials information\n */\n credentials?: {\n /**\n * Authentication scopes for AAD\n */\n scopes?: string[];\n /**\n * Heder name for Client Secret authentication\n */\n apiKeyHeaderName?: string;\n };\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { OperationTracingOptions } from \"../tracing/interfaces.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:path_example\n * import { Client } from \"@typespec/ts-http-runtime\";\n *\n * type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * Credentials information\n */\n credentials?: {\n /**\n * Authentication scopes for AAD\n */\n scopes?: string[];\n /**\n * Heder name for Client Secret authentication\n */\n apiKeyHeaderName?: string;\n };\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * ```ts snippet:abort_error\n * import { AbortError } from \"@typespec/ts-http-runtime\";\n *\n * async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {\n * if (options.abortSignal.aborted) {\n * throw new AbortError();\n * }\n * // do async work\n * }\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork({ abortSignal: controller.signal });\n * } catch (e) {\n * if (e.name === \"AbortError\") {\n * // handle abort error here.\n * }\n * }\n * ```\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AbortError.js","sourceRoot":"","sources":["../../../src/abort-controller/AbortError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * This error is thrown when an asynchronous operation has been aborted.\n * Check for this error by testing the `name` that the name property of the\n * error matches `\"AbortError\"`.\n *\n * @example\n * ```ts snippet:abort_error\n * import { AbortError } from \"@typespec/ts-http-runtime\";\n *\n * async function doAsyncWork(options: { abortSignal: AbortSignal }): Promise<void> {\n * if (options.abortSignal.aborted) {\n * throw new AbortError();\n * }\n * // do async work\n * }\n * const controller = new AbortController();\n * controller.abort();\n * try {\n * doAsyncWork({ abortSignal: controller.signal });\n * } catch (e) {\n * if (e instanceof Error && e.name === \"AbortError\") {\n * // handle abort error here.\n * }\n * }\n * ```\n */\nexport class AbortError extends Error {\n constructor(message?: string) {\n super(message);\n this.name = \"AbortError\";\n }\n}\n"]}
|
|
@@ -163,9 +163,9 @@ export interface Client {
|
|
|
163
163
|
* strong types. When used by the codegen this type gets overridden with the generated
|
|
164
164
|
* types. For example:
|
|
165
165
|
* ```typescript snippet:path_example
|
|
166
|
-
* import { Client
|
|
166
|
+
* import { Client } from "@typespec/ts-http-runtime";
|
|
167
167
|
*
|
|
168
|
-
*
|
|
168
|
+
* type MyClient = Client & {
|
|
169
169
|
* path: Routes;
|
|
170
170
|
* };
|
|
171
171
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { OperationTracingOptions } from \"../tracing/interfaces.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:path_example\n * import { Client, Routes } from \"@typespec/ts-http-runtime\";\n *\n * export type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * Credentials information\n */\n credentials?: {\n /**\n * Authentication scopes for AAD\n */\n scopes?: string[];\n /**\n * Heder name for Client Secret authentication\n */\n apiKeyHeaderName?: string;\n };\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/client/common.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type {\n HttpClient,\n PipelineRequest,\n PipelineResponse,\n RawHttpHeaders,\n RequestBodyType,\n TransferProgressEvent,\n RawHttpHeadersInput,\n} from \"../interfaces.js\";\nimport type { Pipeline, PipelinePolicy } from \"../pipeline.js\";\nimport type { AbortSignalLike } from \"../abort-controller/AbortSignalLike.js\";\nimport type { OperationTracingOptions } from \"../tracing/interfaces.js\";\nimport type { PipelineOptions } from \"../createPipelineFromOptions.js\";\nimport type { LogPolicyOptions } from \"../policies/logPolicy.js\";\n\n/**\n * Shape of the default request parameters, this may be overridden by the specific\n * request types to provide strong types\n */\nexport type RequestParameters = {\n /**\n * Headers to send along with the request\n */\n headers?: RawHttpHeadersInput;\n /**\n * Sets the accept header to send to the service\n * defaults to 'application/json'. If also a header \"accept\" is set\n * this property will take precedence.\n */\n accept?: string;\n /**\n * Body to send with the request\n */\n body?: unknown;\n /**\n * Query parameters to send with the request\n */\n queryParameters?: Record<string, unknown>;\n /**\n * Set an explicit content-type to send with the request. If also a header \"content-type\" is set\n * this property will take precedence.\n */\n contentType?: string;\n /** Set to true if the request is sent over HTTP instead of HTTPS */\n allowInsecureConnection?: boolean;\n /** Set to true if you want to skip encoding the path parameters */\n skipUrlEncoding?: boolean;\n /**\n * Path parameters for custom the base url\n */\n pathParameters?: Record<string, any>;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n};\n\n/**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n// UNBRANDED DIFFERENCE: onResponse callback does not have a second __legacyError parameter which was provided for backwards compatibility\nexport type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown) => void;\n\n/**\n * Wrapper object for http request and response. Deserialized object is stored in\n * the `parsedBody` property when the response body is received in JSON.\n */\nexport interface FullOperationResponse extends PipelineResponse {\n /**\n * The raw HTTP response headers.\n */\n rawHeaders?: RawHttpHeaders;\n\n /**\n * The response body as parsed JSON.\n */\n parsedBody?: RequestBodyType;\n\n /**\n * The request that generated the response.\n */\n request: PipelineRequest;\n}\n\n/**\n * The base options type for all operations.\n */\nexport interface OperationOptions {\n /**\n * The signal which can be used to abort requests.\n */\n abortSignal?: AbortSignalLike;\n /**\n * Options used when creating and sending HTTP requests for this operation.\n */\n requestOptions?: OperationRequestOptions;\n /**\n * Options used when tracing is enabled.\n */\n tracingOptions?: OperationTracingOptions;\n\n /**\n * A function to be called each time a response is received from the server\n * while performing the requested operation.\n * May be called multiple times.\n */\n onResponse?: RawResponseCallback;\n}\n\n/**\n * Options used when creating and sending HTTP requests for this operation.\n */\nexport interface OperationRequestOptions {\n /**\n * User defined custom request headers that\n * will be applied before the request is sent.\n */\n headers?: RawHttpHeadersInput;\n\n /**\n * The number of milliseconds a request can take before automatically being terminated.\n */\n timeout?: number;\n\n /**\n * Callback which fires upon upload progress.\n */\n onUploadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Callback which fires upon download progress.\n */\n onDownloadProgress?: (progress: TransferProgressEvent) => void;\n\n /**\n * Set to true if the request is sent over HTTP instead of HTTPS\n */\n allowInsecureConnection?: boolean;\n\n /**\n * Set to true if you want to skip encoding the path parameters\n */\n skipUrlEncoding?: boolean;\n}\n\n/**\n * Type to use with pathUnchecked, overrides the body type to any to allow flexibility\n */\nexport type PathUncheckedResponse = HttpResponse & { body: any };\n\n/**\n * Shape of a Rest Level Client\n */\nexport interface Client {\n /**\n * The pipeline used by this client to make requests\n */\n pipeline: Pipeline;\n /**\n * This method will be used to send request that would check the path to provide\n * strong types. When used by the codegen this type gets overridden with the generated\n * types. For example:\n * ```typescript snippet:path_example\n * import { Client } from \"@typespec/ts-http-runtime\";\n *\n * type MyClient = Client & {\n * path: Routes;\n * };\n * ```\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n path: Function;\n /**\n * This method allows arbitrary paths and doesn't provide strong types\n */\n pathUnchecked: PathUnchecked;\n}\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpNodeStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: NodeJS.ReadableStream;\n};\n\n/**\n * Http Response which body is a NodeJS stream object\n */\nexport type HttpBrowserStreamResponse = HttpResponse & {\n /**\n * Streamable body\n */\n body?: ReadableStream<Uint8Array>;\n};\n\n/**\n * Defines the type for a method that supports getting the response body as\n * a raw stream\n */\nexport type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {\n asNodeStream: () => Promise<HttpNodeStreamResponse>;\n asBrowserStream: () => Promise<HttpBrowserStreamResponse>;\n};\n\n/**\n * Defines the signature for pathUnchecked.\n */\nexport type PathUnchecked = <TPath extends string>(\n path: TPath,\n ...args: PathParameters<TPath>\n) => ResourceMethods<StreamableMethod>;\n\n/**\n * Defines the methods that can be called on a resource\n */\nexport interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {\n /**\n * Definition of the GET HTTP method for a resource\n */\n get: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the POST HTTP method for a resource\n */\n post: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PUT HTTP method for a resource\n */\n put: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the PATCH HTTP method for a resource\n */\n patch: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the DELETE HTTP method for a resource\n */\n delete: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the HEAD HTTP method for a resource\n */\n head: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the OPTIONS HTTP method for a resource\n */\n options: (options?: RequestParameters) => TResponse;\n /**\n * Definition of the TRACE HTTP method for a resource\n */\n trace: (options?: RequestParameters) => TResponse;\n}\n\n/**\n * Used to configure additional policies added to the pipeline at construction.\n */\nexport interface AdditionalPolicyConfig {\n /**\n * A policy to be added.\n */\n policy: PipelinePolicy;\n /**\n * Determines if this policy be applied before or after retry logic.\n * Only use `perRetry` if you need to modify the request again\n * each time the operation is retried due to retryable service\n * issues.\n */\n position: \"perCall\" | \"perRetry\";\n}\n\n/**\n * General options that a Rest Level Client can take\n */\nexport type ClientOptions = PipelineOptions & {\n /**\n * Credentials information\n */\n credentials?: {\n /**\n * Authentication scopes for AAD\n */\n scopes?: string[];\n /**\n * Heder name for Client Secret authentication\n */\n apiKeyHeaderName?: string;\n };\n\n // UNBRANDED DIFFERENCE: The deprecated baseUrl property is removed in favor of the endpoint property in the unbranded Core package\n\n /**\n * Endpoint for the client\n */\n endpoint?: string;\n /**\n * Options for setting a custom apiVersion.\n */\n apiVersion?: string;\n /**\n * Option to allow calling http (insecure) endpoints\n */\n allowInsecureConnection?: boolean;\n /**\n * Additional policies to include in the HTTP pipeline.\n */\n additionalPolicies?: AdditionalPolicyConfig[];\n /**\n * Specify a custom HttpClient when making requests.\n */\n httpClient?: HttpClient;\n /**\n * Options to configure request/response logging.\n */\n loggingOptions?: LogPolicyOptions;\n};\n\n/**\n * Represents the shape of an HttpResponse\n */\nexport type HttpResponse = {\n /**\n * The request that generated this response.\n */\n request: PipelineRequest;\n /**\n * The HTTP response headers.\n */\n headers: RawHttpHeaders;\n /**\n * Parsed body\n */\n body: unknown;\n /**\n * The HTTP status code of the response.\n */\n status: string;\n};\n\n/**\n * Helper type used to detect parameters in a path template\n * text surrounded by \\{\\} will be considered a path parameter\n */\nexport type PathParameters<\n TRoute extends string,\n // This is trying to match the string in TRoute with a template where HEAD/{PARAM}/TAIL\n // for example in the followint path: /foo/{fooId}/bar/{barId}/baz the template will infer\n // HEAD: /foo\n // Param: fooId\n // Tail: /bar/{barId}/baz\n // The above sample path would return [pathParam: string, pathParam: string]\n> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}`\n ? // In case we have a match for the template above we know for sure\n // that we have at least one pathParameter, that's why we set the first pathParam\n // in the tuple. At this point we have only matched up until param, if we want to identify\n // additional parameters we can call RouteParameters recursively on the Tail to match the remaining parts,\n // in case the Tail has more parameters, it will return a tuple with the parameters found in tail.\n // We spread the second path params to end up with a single dimension tuple at the end.\n [\n pathParameter: string | number | PathParameterWithOptions,\n ...pathParameters: PathParameters<Tail>,\n ]\n : // When the path doesn't match the template, it means that we have no path parameters so we return\n // an empty tuple.\n [];\n\n/** A response containing error details. */\nexport interface ErrorResponse {\n /** The error object. */\n error: ErrorModel;\n}\n\n/** The error object. */\nexport interface ErrorModel {\n /** One of a server-defined set of error codes. */\n code: string;\n /** A human-readable representation of the error. */\n message: string;\n /** The target of the error. */\n target?: string;\n /** An array of details about specific errors that led to this reported error. */\n details: Array<ErrorModel>;\n /** An object containing more specific information than the current object about the error. */\n innererror?: InnerError;\n}\n\n/** An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. */\nexport interface InnerError {\n /** One of a server-defined set of error codes. */\n code: string;\n /** Inner error. */\n innererror?: InnerError;\n}\n\n/**\n * An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.\n */\nexport interface PathParameterWithOptions {\n /**\n * The value of the parameter.\n */\n value: string | number;\n\n /**\n * Whether to allow for reserved characters in the value. If set to true, special characters such as '/' in the parameter's value will not be URL encoded.\n * Defaults to false.\n */\n allowReserved?: boolean;\n}\n"]}
|
|
@@ -25,7 +25,7 @@ export declare type AbortablePromiseBuilder<T> = (abortOptions: {
|
|
|
25
25
|
* try {
|
|
26
26
|
* doAsyncWork({ abortSignal: controller.signal });
|
|
27
27
|
* } catch (e) {
|
|
28
|
-
* if (e.name === "AbortError") {
|
|
28
|
+
* if (e instanceof Error && e.name === "AbortError") {
|
|
29
29
|
* // handle abort error here.
|
|
30
30
|
* }
|
|
31
31
|
* }
|
|
@@ -334,9 +334,9 @@ export declare interface Client {
|
|
|
334
334
|
* strong types. When used by the codegen this type gets overridden with the generated
|
|
335
335
|
* types. For example:
|
|
336
336
|
* ```typescript snippet:path_example
|
|
337
|
-
* import { Client
|
|
337
|
+
* import { Client } from "@typespec/ts-http-runtime";
|
|
338
338
|
*
|
|
339
|
-
*
|
|
339
|
+
* type MyClient = Client & {
|
|
340
340
|
* path: Routes;
|
|
341
341
|
* };
|
|
342
342
|
* ```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typespec/ts-http-runtime",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20241111.2",
|
|
4
4
|
"description": "Isomorphic client library for making HTTP requests in node.js and browser.",
|
|
5
5
|
"sdk-type": "client",
|
|
6
6
|
"type": "module",
|
|
@@ -102,7 +102,6 @@
|
|
|
102
102
|
"@types/node": "^18.0.0",
|
|
103
103
|
"@vitest/browser": "^2.0.5",
|
|
104
104
|
"@vitest/coverage-istanbul": "^2.0.5",
|
|
105
|
-
"cross-env": "^7.0.2",
|
|
106
105
|
"eslint": "^9.9.0",
|
|
107
106
|
"playwright": "^1.41.2",
|
|
108
107
|
"typescript": "~5.6.2",
|