open ai api

This commit is contained in:
2025-09-16 09:38:01 +08:00
parent c71c3ab417
commit 5f9a2bc78c
7168 changed files with 352600 additions and 209 deletions

View File

@@ -0,0 +1,10 @@
import type { PipelinePolicy } from "@azure/core-rest-pipeline";
import type { ClientOptions } from "./common.js";
export declare const apiVersionPolicyName = "ApiVersionPolicy";
/**
* Creates a policy that sets the apiVersion as a query parameter on every request
* @param options - Client options
* @returns Pipeline policy that sets the apiVersion as a query parameter on every request
*/
export declare function apiVersionPolicy(options: ClientOptions): PipelinePolicy;
//# sourceMappingURL=apiVersionPolicy.d.ts.map

View File

@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export const apiVersionPolicyName = "ApiVersionPolicy";
/**
* Creates a policy that sets the apiVersion as a query parameter on every request
* @param options - Client options
* @returns Pipeline policy that sets the apiVersion as a query parameter on every request
*/
export function apiVersionPolicy(options) {
return {
name: apiVersionPolicyName,
sendRequest: (req, next) => {
// Use the apiVesion defined in request url directly
// Append one if there is no apiVesion and we have one at client options
const url = new URL(req.url);
if (!url.searchParams.get("api-version") && options.apiVersion) {
req.url = `${req.url}${Array.from(url.searchParams.keys()).length > 0 ? "&" : "?"}api-version=${options.apiVersion}`;
}
return next(req);
},
};
}
//# sourceMappingURL=apiVersionPolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"apiVersionPolicy.js","sourceRoot":"","sources":["../../src/apiVersionPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAKlC,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAC;AAEvD;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAsB;IACrD,OAAO;QACL,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACzB,oDAAoD;YACpD,wEAAwE;YACxE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBAC/D,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,GAAG,GAClB,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GACzD,eAAe,OAAO,CAAC,UAAU,EAAE,CAAC;YACtC,CAAC;YAED,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { PipelinePolicy } from \"@azure/core-rest-pipeline\";\nimport type { ClientOptions } from \"./common.js\";\n\nexport const apiVersionPolicyName = \"ApiVersionPolicy\";\n\n/**\n * Creates a policy that sets the apiVersion as a query parameter on every request\n * @param options - Client options\n * @returns Pipeline policy that sets the apiVersion as a query parameter on every request\n */\nexport function apiVersionPolicy(options: ClientOptions): PipelinePolicy {\n return {\n name: apiVersionPolicyName,\n sendRequest: (req, next) => {\n // Use the apiVesion defined in request url directly\n // Append one if there is no apiVesion and we have one at client options\n const url = new URL(req.url);\n if (!url.searchParams.get(\"api-version\") && options.apiVersion) {\n req.url = `${req.url}${\n Array.from(url.searchParams.keys()).length > 0 ? \"&\" : \"?\"\n }api-version=${options.apiVersion}`;\n }\n\n return next(req);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,26 @@
import type { HttpClient, Pipeline } from "@azure/core-rest-pipeline";
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
import type { ClientOptions } from "./common.js";
/**
* Optional parameters for adding a credential policy to the pipeline.
*/
export interface AddCredentialPipelinePolicyOptions {
/**
* Options related to the client.
*/
clientOptions?: ClientOptions;
/**
* The credential to use.
*/
credential?: TokenCredential | KeyCredential;
}
/**
* Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.
*/
export declare function addCredentialPipelinePolicy(pipeline: Pipeline, endpoint: string, options?: AddCredentialPipelinePolicyOptions): void;
/**
* Creates a default rest pipeline to re-use accross Rest Level Clients
*/
export declare function createDefaultPipeline(endpoint: string, credential?: TokenCredential | KeyCredential, options?: ClientOptions): Pipeline;
export declare function getCachedDefaultHttpsClient(): HttpClient;
//# sourceMappingURL=clientHelpers.d.ts.map

View File

@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { bearerTokenAuthenticationPolicy, createDefaultHttpClient, createPipelineFromOptions, } from "@azure/core-rest-pipeline";
import { isTokenCredential } from "@azure/core-auth";
import { apiVersionPolicy } from "./apiVersionPolicy.js";
import { keyCredentialAuthenticationPolicy } from "./keyCredentialAuthenticationPolicy.js";
let cachedHttpClient;
/**
* Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.
*/
export function addCredentialPipelinePolicy(pipeline, endpoint, options = {}) {
var _a, _b, _c, _d;
const { credential, clientOptions } = options;
if (!credential) {
return;
}
if (isTokenCredential(credential)) {
const tokenPolicy = bearerTokenAuthenticationPolicy({
credential,
scopes: (_b = (_a = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _a === void 0 ? void 0 : _a.scopes) !== null && _b !== void 0 ? _b : `${endpoint}/.default`,
});
pipeline.addPolicy(tokenPolicy);
}
else if (isKeyCredential(credential)) {
if (!((_c = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _c === void 0 ? void 0 : _c.apiKeyHeaderName)) {
throw new Error(`Missing API Key Header Name`);
}
const keyPolicy = keyCredentialAuthenticationPolicy(credential, (_d = clientOptions === null || clientOptions === void 0 ? void 0 : clientOptions.credentials) === null || _d === void 0 ? void 0 : _d.apiKeyHeaderName);
pipeline.addPolicy(keyPolicy);
}
}
/**
* Creates a default rest pipeline to re-use accross Rest Level Clients
*/
export function createDefaultPipeline(endpoint, credential, options = {}) {
const pipeline = createPipelineFromOptions(options);
pipeline.addPolicy(apiVersionPolicy(options));
addCredentialPipelinePolicy(pipeline, endpoint, { credential, clientOptions: options });
return pipeline;
}
function isKeyCredential(credential) {
return credential.key !== undefined;
}
export function getCachedDefaultHttpsClient() {
if (!cachedHttpClient) {
cachedHttpClient = createDefaultHttpClient();
}
return cachedHttpClient;
}
//# sourceMappingURL=clientHelpers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"clientHelpers.js","sourceRoot":"","sources":["../../src/clientHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EACL,+BAA+B,EAC/B,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAE3F,IAAI,gBAAwC,CAAC;AAgB7C;;GAEG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAAkB,EAClB,QAAgB,EAChB,UAA8C,EAAE;;IAEhD,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAC9C,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO;IACT,CAAC;IAED,IAAI,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,WAAW,GAAG,+BAA+B,CAAC;YAClD,UAAU;YACV,MAAM,EAAE,MAAA,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,WAAW,0CAAE,MAAM,mCAAI,GAAG,QAAQ,WAAW;SACrE,CAAC,CAAC;QACH,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAClC,CAAC;SAAM,IAAI,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,CAAA,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,WAAW,0CAAE,gBAAgB,CAAA,EAAE,CAAC;YAClD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,SAAS,GAAG,iCAAiC,CACjD,UAAU,EACV,MAAA,aAAa,aAAb,aAAa,uBAAb,aAAa,CAAE,WAAW,0CAAE,gBAAgB,CAC7C,CAAC;QACF,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAgB,EAChB,UAA4C,EAC5C,UAAyB,EAAE;IAE3B,MAAM,QAAQ,GAAG,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAEpD,QAAQ,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;IAE9C,2BAA2B,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC,CAAC;IACxF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,eAAe,CAAC,UAAe;IACtC,OAAQ,UAA4B,CAAC,GAAG,KAAK,SAAS,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,2BAA2B;IACzC,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,gBAAgB,GAAG,uBAAuB,EAAE,CAAC;IAC/C,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { HttpClient, Pipeline } from \"@azure/core-rest-pipeline\";\nimport {\n bearerTokenAuthenticationPolicy,\n createDefaultHttpClient,\n createPipelineFromOptions,\n} from \"@azure/core-rest-pipeline\";\nimport type { KeyCredential, TokenCredential } from \"@azure/core-auth\";\nimport { isTokenCredential } from \"@azure/core-auth\";\n\nimport type { ClientOptions } from \"./common.js\";\nimport { apiVersionPolicy } from \"./apiVersionPolicy.js\";\nimport { keyCredentialAuthenticationPolicy } from \"./keyCredentialAuthenticationPolicy.js\";\n\nlet cachedHttpClient: HttpClient | undefined;\n\n/**\n * Optional parameters for adding a credential policy to the pipeline.\n */\nexport interface AddCredentialPipelinePolicyOptions {\n /**\n * Options related to the client.\n */\n clientOptions?: ClientOptions;\n /**\n * The credential to use.\n */\n credential?: TokenCredential | KeyCredential;\n}\n\n/**\n * Adds a credential policy to the pipeline if a credential is provided. If none is provided, no policy is added.\n */\nexport function addCredentialPipelinePolicy(\n pipeline: Pipeline,\n endpoint: string,\n options: AddCredentialPipelinePolicyOptions = {},\n): void {\n const { credential, clientOptions } = options;\n if (!credential) {\n return;\n }\n\n if (isTokenCredential(credential)) {\n const tokenPolicy = bearerTokenAuthenticationPolicy({\n credential,\n scopes: clientOptions?.credentials?.scopes ?? `${endpoint}/.default`,\n });\n pipeline.addPolicy(tokenPolicy);\n } else if (isKeyCredential(credential)) {\n if (!clientOptions?.credentials?.apiKeyHeaderName) {\n throw new Error(`Missing API Key Header Name`);\n }\n const keyPolicy = keyCredentialAuthenticationPolicy(\n credential,\n clientOptions?.credentials?.apiKeyHeaderName,\n );\n pipeline.addPolicy(keyPolicy);\n }\n}\n\n/**\n * Creates a default rest pipeline to re-use accross Rest Level Clients\n */\nexport function createDefaultPipeline(\n endpoint: string,\n credential?: TokenCredential | KeyCredential,\n options: ClientOptions = {},\n): Pipeline {\n const pipeline = createPipelineFromOptions(options);\n\n pipeline.addPolicy(apiVersionPolicy(options));\n\n addCredentialPipelinePolicy(pipeline, endpoint, { credential, clientOptions: options });\n return pipeline;\n}\n\nfunction isKeyCredential(credential: any): credential is KeyCredential {\n return (credential as KeyCredential).key !== undefined;\n}\n\nexport function getCachedDefaultHttpsClient(): HttpClient {\n if (!cachedHttpClient) {\n cachedHttpClient = createDefaultHttpClient();\n }\n\n return cachedHttpClient;\n}\n"]}

View File

@@ -0,0 +1,398 @@
import type { HttpClient, LogPolicyOptions, Pipeline, PipelineOptions, PipelinePolicy, PipelineRequest, PipelineResponse, RawHttpHeaders, RequestBodyType, TransferProgressEvent } from "@azure/core-rest-pipeline";
import type { RawHttpHeadersInput } from "@azure/core-rest-pipeline";
import type { AbortSignalLike } from "@azure/abort-controller";
import type { OperationTracingOptions } from "@azure/core-tracing";
/**
* Shape of the default request parameters, this may be overridden by the specific
* request types to provide strong types
*/
export type RequestParameters = {
/**
* Headers to send along with the request
*/
headers?: RawHttpHeadersInput;
/**
* Sets the accept header to send to the service
* defaults to 'application/json'. If also a header "accept" is set
* this property will take precedence.
*/
accept?: string;
/**
* Body to send with the request
*/
body?: unknown;
/**
* Query parameters to send with the request
*/
queryParameters?: Record<string, unknown>;
/**
* Set an explicit content-type to send with the request. If also a header "content-type" is set
* this property will take precedence.
*/
contentType?: string;
/** Set to true if the request is sent over HTTP instead of HTTPS */
allowInsecureConnection?: boolean;
/** Set to true if you want to skip encoding the path parameters */
skipUrlEncoding?: boolean;
/**
* Path parameters for custom the base url
*/
pathParameters?: Record<string, any>;
/**
* The number of milliseconds a request can take before automatically being terminated.
*/
timeout?: number;
/**
* Callback which fires upon upload progress.
*/
onUploadProgress?: (progress: TransferProgressEvent) => void;
/**
* Callback which fires upon download progress.
*/
onDownloadProgress?: (progress: TransferProgressEvent) => void;
/**
* The signal which can be used to abort requests.
*/
abortSignal?: AbortSignalLike;
/**
* Options used when tracing is enabled.
*/
tracingOptions?: OperationTracingOptions;
/**
* A function to be called each time a response is received from the server
* while performing the requested operation.
* May be called multiple times.
*/
onResponse?: RawResponseCallback;
};
/**
* A function to be called each time a response is received from the server
* while performing the requested operation.
* May be called multiple times.
*
* This callback will be called with two parameters: the raw response, including headers and response body; and an error
* object which will be provided if an error was thrown while processing the request.
* The third __legacyError parameter is provided for backwards compatability only and will have an identical value to the `error` parameter.
*/
export type RawResponseCallback = (rawResponse: FullOperationResponse, error?: unknown, __legacyError?: unknown) => void;
/**
* Wrapper object for http request and response. Deserialized object is stored in
* the `parsedBody` property when the response body is received in JSON.
*/
export interface FullOperationResponse extends PipelineResponse {
/**
* The raw HTTP response headers.
*/
rawHeaders?: RawHttpHeaders;
/**
* The response body as parsed JSON.
*/
parsedBody?: RequestBodyType;
/**
* The request that generated the response.
*/
request: PipelineRequest;
}
/**
* The base options type for all operations.
*/
export interface OperationOptions {
/**
* The signal which can be used to abort requests.
*/
abortSignal?: AbortSignalLike;
/**
* Options used when creating and sending HTTP requests for this operation.
*/
requestOptions?: OperationRequestOptions;
/**
* Options used when tracing is enabled.
*/
tracingOptions?: OperationTracingOptions;
/**
* A function to be called each time a response is received from the server
* while performing the requested operation.
* May be called multiple times.
*/
onResponse?: RawResponseCallback;
}
/**
* Options used when creating and sending HTTP requests for this operation.
*/
export interface OperationRequestOptions {
/**
* User defined custom request headers that
* will be applied before the request is sent.
*/
headers?: RawHttpHeadersInput;
/**
* The number of milliseconds a request can take before automatically being terminated.
*/
timeout?: number;
/**
* Callback which fires upon upload progress.
*/
onUploadProgress?: (progress: TransferProgressEvent) => void;
/**
* Callback which fires upon download progress.
*/
onDownloadProgress?: (progress: TransferProgressEvent) => void;
/**
* Set to true if the request is sent over HTTP instead of HTTPS
*/
allowInsecureConnection?: boolean;
/**
* Set to true if you want to skip encoding the path parameters
*/
skipUrlEncoding?: boolean;
}
/**
* Type to use with pathUnchecked, overrides the body type to any to allow flexibility
*/
export type PathUncheckedResponse = HttpResponse & {
body: any;
};
/**
* Shape of a Rest Level Client
*/
export interface Client {
/**
* The pipeline used by this client to make requests
*/
pipeline: Pipeline;
/**
* This method will be used to send request that would check the path to provide
* strong types. When used by the codegen this type gets overridden with the generated
* types. For example:
* ```typescript snippet:PathExample
* import { Client } from "@azure-rest/core-client";
*
* type MyClient = Client & {
* path: Routes;
* };
* ```
*/
path: Function;
/**
* This method allows arbitrary paths and doesn't provide strong types
*/
pathUnchecked: PathUnchecked;
}
/**
* A Node.js Readable stream that also has a `destroy` method.
*/
export interface NodeJSReadableStream extends NodeJS.ReadableStream {
/**
* Destroy the stream. Optionally emit an 'error' event, and emit a
* 'close' event (unless emitClose is set to false). After this call,
* internal resources will be released.
*/
destroy(error?: Error): void;
}
/**
* Http Response which body is a NodeJS stream object
*/
export type HttpNodeStreamResponse = HttpResponse & {
/**
* Streamable body
*/
body?: NodeJSReadableStream;
};
/**
* Http Response which body is a NodeJS stream object
*/
export type HttpBrowserStreamResponse = HttpResponse & {
/**
* Streamable body
*/
body?: ReadableStream<Uint8Array>;
};
/**
* Defines the type for a method that supports getting the response body as
* a raw stream
*/
export type StreamableMethod<TResponse = PathUncheckedResponse> = PromiseLike<TResponse> & {
/**
* Returns the response body as a NodeJS stream. Only available in Node-like environments.
*/
asNodeStream: () => Promise<HttpNodeStreamResponse>;
/**
* Returns the response body as a browser (Web) stream. Only available in the browser. If you require a Web Stream of the response in Node, consider using the
* `Readable.toWeb` Node API on the result of `asNodeStream`.
*/
asBrowserStream: () => Promise<HttpBrowserStreamResponse>;
};
/**
* Defines the signature for pathUnchecked.
*/
export type PathUnchecked = <TPath extends string>(path: TPath, ...args: PathParameters<TPath>) => ResourceMethods<StreamableMethod>;
/**
* Defines the methods that can be called on a resource
*/
export interface ResourceMethods<TResponse = PromiseLike<PathUncheckedResponse>> {
/**
* Definition of the GET HTTP method for a resource
*/
get: (options?: RequestParameters) => TResponse;
/**
* Definition of the POST HTTP method for a resource
*/
post: (options?: RequestParameters) => TResponse;
/**
* Definition of the PUT HTTP method for a resource
*/
put: (options?: RequestParameters) => TResponse;
/**
* Definition of the PATCH HTTP method for a resource
*/
patch: (options?: RequestParameters) => TResponse;
/**
* Definition of the DELETE HTTP method for a resource
*/
delete: (options?: RequestParameters) => TResponse;
/**
* Definition of the HEAD HTTP method for a resource
*/
head: (options?: RequestParameters) => TResponse;
/**
* Definition of the OPTIONS HTTP method for a resource
*/
options: (options?: RequestParameters) => TResponse;
/**
* Definition of the TRACE HTTP method for a resource
*/
trace: (options?: RequestParameters) => TResponse;
}
/**
* Used to configure additional policies added to the pipeline at construction.
*/
export interface AdditionalPolicyConfig {
/**
* A policy to be added.
*/
policy: PipelinePolicy;
/**
* Determines if this policy be applied before or after retry logic.
* Only use `perRetry` if you need to modify the request again
* each time the operation is retried due to retryable service
* issues.
*/
position: "perCall" | "perRetry";
}
/**
* General options that a Rest Level Client can take
*/
export type ClientOptions = PipelineOptions & {
/**
* Credentials information
*/
credentials?: {
/**
* Authentication scopes for AAD
*/
scopes?: string[];
/**
* Heder name for Client Secret authentication
*/
apiKeyHeaderName?: string;
};
/**
* Base url for the client
* @deprecated This property is deprecated and will be removed soon, please use endpoint instead
*/
baseUrl?: string;
/**
* Endpoint for the client
*/
endpoint?: string;
/**
* Options for setting a custom apiVersion.
*/
apiVersion?: string;
/**
* Option to allow calling http (insecure) endpoints
*/
allowInsecureConnection?: boolean;
/**
* Additional policies to include in the HTTP pipeline.
*/
additionalPolicies?: AdditionalPolicyConfig[];
/**
* Specify a custom HttpClient when making requests.
*/
httpClient?: HttpClient;
/**
* Options to configure request/response logging.
*/
loggingOptions?: LogPolicyOptions;
};
/**
* Represents the shape of an HttpResponse
*/
export type HttpResponse = {
/**
* The request that generated this response.
*/
request: PipelineRequest;
/**
* The HTTP response headers.
*/
headers: RawHttpHeaders;
/**
* Parsed body
*/
body: unknown;
/**
* The HTTP status code of the response.
*/
status: string;
};
/**
* Helper type used to detect parameters in a path template
* text surrounded by \{\} will be considered a path parameter
*/
export type PathParameters<TRoute extends string> = TRoute extends `${infer _Head}/{${infer _Param}}${infer Tail}` ? [
pathParameter: string | number | PathParameterWithOptions,
...pathParameters: PathParameters<Tail>
] : [
];
/** A response containing error details. */
export interface ErrorResponse {
/** The error object. */
error: ErrorModel;
}
/** The error object. */
export interface ErrorModel {
/** One of a server-defined set of error codes. */
code: string;
/** A human-readable representation of the error. */
message: string;
/** The target of the error. */
target?: string;
/** An array of details about specific errors that led to this reported error. */
details: Array<ErrorModel>;
/** An object containing more specific information than the current object about the error. */
innererror?: InnerError;
}
/** 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. */
export interface InnerError {
/** One of a server-defined set of error codes. */
code: string;
/** Inner error. */
innererror?: InnerError;
}
/**
* An object that can be passed as a path parameter, allowing for additional options to be set relating to how the parameter is encoded.
*/
export interface PathParameterWithOptions {
/**
* The value of the parameter.
*/
value: string | number;
/**
* 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.
* Defaults to false.
*/
allowReserved?: boolean;
}
//# sourceMappingURL=common.d.ts.map

View File

@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
export {};
//# sourceMappingURL=common.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,16 @@
import type { KeyCredential, TokenCredential } from "@azure/core-auth";
import type { Client, ClientOptions } from "./common.js";
/**
* Creates a client with a default pipeline
* @param endpoint - Base endpoint for the client
* @param options - Client options
*/
export declare function getClient(endpoint: string, options?: ClientOptions): Client;
/**
* Creates a client with a default pipeline
* @param endpoint - Base endpoint for the client
* @param credentials - Credentials to authenticate the requests
* @param options - Client options
*/
export declare function getClient(endpoint: string, credentials?: TokenCredential | KeyCredential, options?: ClientOptions): Client;
//# sourceMappingURL=getClient.d.ts.map

View File

@@ -0,0 +1,67 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { isKeyCredential, isTokenCredential } from "@azure/core-auth";
import { createDefaultPipeline } from "./clientHelpers.js";
import { getClient as tspGetClient, } from "@typespec/ts-http-runtime";
/**
* Function to wrap RequestParameters so that we get the legacy onResponse behavior in core-client-rest
*/
function wrapRequestParameters(parameters) {
if (parameters.onResponse) {
return Object.assign(Object.assign({}, parameters), { onResponse(rawResponse, error) {
var _a;
(_a = parameters.onResponse) === null || _a === void 0 ? void 0 : _a.call(parameters, rawResponse, error, error);
} });
}
return parameters;
}
export function getClient(endpoint, credentialsOrPipelineOptions, clientOptions = {}) {
let credentials;
if (credentialsOrPipelineOptions) {
if (isCredential(credentialsOrPipelineOptions)) {
credentials = credentialsOrPipelineOptions;
}
else {
clientOptions = credentialsOrPipelineOptions !== null && credentialsOrPipelineOptions !== void 0 ? credentialsOrPipelineOptions : {};
}
}
const pipeline = createDefaultPipeline(endpoint, credentials, clientOptions);
const tspClient = tspGetClient(endpoint, Object.assign(Object.assign({}, clientOptions), { pipeline }));
const client = (path, ...args) => {
return {
get: (requestOptions = {}) => {
return tspClient.path(path, ...args).get(wrapRequestParameters(requestOptions));
},
post: (requestOptions = {}) => {
return tspClient.path(path, ...args).post(wrapRequestParameters(requestOptions));
},
put: (requestOptions = {}) => {
return tspClient.path(path, ...args).put(wrapRequestParameters(requestOptions));
},
patch: (requestOptions = {}) => {
return tspClient.path(path, ...args).patch(wrapRequestParameters(requestOptions));
},
delete: (requestOptions = {}) => {
return tspClient.path(path, ...args).delete(wrapRequestParameters(requestOptions));
},
head: (requestOptions = {}) => {
return tspClient.path(path, ...args).head(wrapRequestParameters(requestOptions));
},
options: (requestOptions = {}) => {
return tspClient.path(path, ...args).options(wrapRequestParameters(requestOptions));
},
trace: (requestOptions = {}) => {
return tspClient.path(path, ...args).trace(wrapRequestParameters(requestOptions));
},
};
};
return {
path: client,
pathUnchecked: client,
pipeline: tspClient.pipeline,
};
}
function isCredential(param) {
return isKeyCredential(param) || isTokenCredential(param);
}
//# sourceMappingURL=getClient.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,10 @@
/**
* Azure Rest Core Client library for JavaScript
* @packageDocumentation
*/
export { createRestError } from "./restError.js";
export { addCredentialPipelinePolicy, AddCredentialPipelinePolicyOptions, } from "./clientHelpers.js";
export { operationOptionsToRequestParameters } from "./operationOptionHelpers.js";
export * from "./getClient.js";
export * from "./common.js";
//# sourceMappingURL=index.d.ts.map

12
node_modules/@azure-rest/core-client/dist/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* Azure Rest Core Client library for JavaScript
* @packageDocumentation
*/
export { createRestError } from "./restError.js";
export { addCredentialPipelinePolicy, } from "./clientHelpers.js";
export { operationOptionsToRequestParameters } from "./operationOptionHelpers.js";
export * from "./getClient.js";
export * from "./common.js";
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC;;;GAGG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EACL,2BAA2B,GAE5B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,mCAAmC,EAAE,MAAM,6BAA6B,CAAC;AAClF,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/**\n * Azure Rest Core Client library for JavaScript\n * @packageDocumentation\n */\n\nexport { createRestError } from \"./restError.js\";\nexport {\n addCredentialPipelinePolicy,\n AddCredentialPipelinePolicyOptions,\n} from \"./clientHelpers.js\";\nexport { operationOptionsToRequestParameters } from \"./operationOptionHelpers.js\";\nexport * from \"./getClient.js\";\nexport * from \"./common.js\";\n"]}

View File

@@ -0,0 +1,8 @@
import type { KeyCredential } from "@azure/core-auth";
import type { PipelinePolicy } from "@azure/core-rest-pipeline";
/**
* The programmatic identifier of the bearerTokenAuthenticationPolicy.
*/
export declare const keyCredentialAuthenticationPolicyName = "keyCredentialAuthenticationPolicy";
export declare function keyCredentialAuthenticationPolicy(credential: KeyCredential, apiKeyHeaderName: string): PipelinePolicy;
//# sourceMappingURL=keyCredentialAuthenticationPolicy.d.ts.map

View File

@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/**
* The programmatic identifier of the bearerTokenAuthenticationPolicy.
*/
export const keyCredentialAuthenticationPolicyName = "keyCredentialAuthenticationPolicy";
export function keyCredentialAuthenticationPolicy(credential, apiKeyHeaderName) {
return {
name: keyCredentialAuthenticationPolicyName,
async sendRequest(request, next) {
request.headers.set(apiKeyHeaderName, credential.key);
return next(request);
},
};
}
//# sourceMappingURL=keyCredentialAuthenticationPolicy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"keyCredentialAuthenticationPolicy.js","sourceRoot":"","sources":["../../src/keyCredentialAuthenticationPolicy.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAUlC;;GAEG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,mCAAmC,CAAC;AAEzF,MAAM,UAAU,iCAAiC,CAC/C,UAAyB,EACzB,gBAAwB;IAExB,OAAO;QACL,IAAI,EAAE,qCAAqC;QAC3C,KAAK,CAAC,WAAW,CAAC,OAAwB,EAAE,IAAiB;YAC3D,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC;YACtD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { KeyCredential } from \"@azure/core-auth\";\nimport type {\n PipelinePolicy,\n PipelineRequest,\n PipelineResponse,\n SendRequest,\n} from \"@azure/core-rest-pipeline\";\n\n/**\n * The programmatic identifier of the bearerTokenAuthenticationPolicy.\n */\nexport const keyCredentialAuthenticationPolicyName = \"keyCredentialAuthenticationPolicy\";\n\nexport function keyCredentialAuthenticationPolicy(\n credential: KeyCredential,\n apiKeyHeaderName: string,\n): PipelinePolicy {\n return {\n name: keyCredentialAuthenticationPolicyName,\n async sendRequest(request: PipelineRequest, next: SendRequest): Promise<PipelineResponse> {\n request.headers.set(apiKeyHeaderName, credential.key);\n return next(request);\n },\n };\n}\n"]}

View File

@@ -0,0 +1,8 @@
import type { OperationOptions, RequestParameters } from "./common.js";
/**
* Helper function to convert OperationOptions to RequestParameters
* @param options - the options that are used by Modular layer to send the request
* @returns the result of the conversion in RequestParameters of RLC layer
*/
export declare function operationOptionsToRequestParameters(options: OperationOptions): RequestParameters;
//# sourceMappingURL=operationOptionHelpers.d.ts.map

View File

@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { operationOptionsToRequestParameters as tspOperationOptionsToRequestParameters, } from "@typespec/ts-http-runtime";
/**
* Helper function to convert OperationOptions to RequestParameters
* @param options - the options that are used by Modular layer to send the request
* @returns the result of the conversion in RequestParameters of RLC layer
*/
export function operationOptionsToRequestParameters(options) {
return tspOperationOptionsToRequestParameters(options);
}
//# sourceMappingURL=operationOptionHelpers.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"operationOptionHelpers.js","sourceRoot":"","sources":["../../src/operationOptionHelpers.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAIlC,OAAO,EACL,mCAAmC,IAAI,sCAAsC,GAE9E,MAAM,2BAA2B,CAAC;AAEnC;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CAAC,OAAyB;IAC3E,OAAO,sCAAsC,CAC3C,OAA8B,CACV,CAAC;AACzB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { OperationOptions, RequestParameters } from \"./common.js\";\n\nimport {\n operationOptionsToRequestParameters as tspOperationOptionsToRequestParameters,\n type OperationOptions as TspOperationOptions,\n} from \"@typespec/ts-http-runtime\";\n\n/**\n * Helper function to convert OperationOptions to RequestParameters\n * @param options - the options that are used by Modular layer to send the request\n * @returns the result of the conversion in RequestParameters of RLC layer\n */\nexport function operationOptionsToRequestParameters(options: OperationOptions): RequestParameters {\n return tspOperationOptionsToRequestParameters(\n options as TspOperationOptions,\n ) as RequestParameters;\n}\n"]}

View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

View File

@@ -0,0 +1,11 @@
import type { RestError } from "@azure/core-rest-pipeline";
import type { PathUncheckedResponse } from "./common.js";
/**
* Creates a rest error from a PathUnchecked response
*/
export declare function createRestError(response: PathUncheckedResponse): RestError;
/**
* Creates a rest error from an error message and a PathUnchecked response
*/
export declare function createRestError(message: string, response: PathUncheckedResponse): RestError;
//# sourceMappingURL=restError.d.ts.map

View File

@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { createRestError as tspCreateRestError, } from "@typespec/ts-http-runtime";
export function createRestError(messageOrResponse, response) {
if (typeof messageOrResponse === "string") {
return tspCreateRestError(messageOrResponse, response);
}
else {
return tspCreateRestError(messageOrResponse);
}
}
//# sourceMappingURL=restError.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"restError.js","sourceRoot":"","sources":["../../src/restError.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAKlC,OAAO,EACL,eAAe,IAAI,kBAAkB,GAEtC,MAAM,2BAA2B,CAAC;AAUnC,MAAM,UAAU,eAAe,CAC7B,iBAAiD,EACjD,QAAgC;IAEhC,IAAI,OAAO,iBAAiB,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,kBAAkB,CAAC,iBAAiB,EAAE,QAAqC,CAAC,CAAC;IACtF,CAAC;SAAM,CAAC;QACN,OAAO,kBAAkB,CAAC,iBAA6C,CAAC,CAAC;IAC3E,CAAC;AACH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport type { RestError } from \"@azure/core-rest-pipeline\";\nimport type { PathUncheckedResponse } from \"./common.js\";\n\nimport {\n createRestError as tspCreateRestError,\n type PathUncheckedResponse as TspPathUncheckedResponse,\n} from \"@typespec/ts-http-runtime\";\n\n/**\n * Creates a rest error from a PathUnchecked response\n */\nexport function createRestError(response: PathUncheckedResponse): RestError;\n/**\n * Creates a rest error from an error message and a PathUnchecked response\n */\nexport function createRestError(message: string, response: PathUncheckedResponse): RestError;\nexport function createRestError(\n messageOrResponse: string | PathUncheckedResponse,\n response?: PathUncheckedResponse,\n): RestError {\n if (typeof messageOrResponse === \"string\") {\n return tspCreateRestError(messageOrResponse, response! as TspPathUncheckedResponse);\n } else {\n return tspCreateRestError(messageOrResponse as TspPathUncheckedResponse);\n }\n}\n"]}