@databricks/sdk-vectorsearch 0.1.0-dev.3 → 0.1.0-dev.5

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.
@@ -1,73 +0,0 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import type {Credentials} from '@databricks/sdk-auth';
4
- import {defaultCredentials} from '@databricks/sdk-auth/credentials';
5
- import type {
6
- HttpClient,
7
- HttpRequest,
8
- HttpResponse,
9
- } from '@databricks/sdk-core/http';
10
- import {newFetchHttpClient} from '@databricks/sdk-core/http';
11
- import type {ClientOptions} from '@databricks/sdk-options/client';
12
-
13
- /** Creates a new HTTP client with the given options. */
14
- export function newHttpClient(options?: ClientOptions): HttpClient {
15
- const opts = options ?? {};
16
-
17
- // If an HTTP client is provided, use it as-is. Throw if other options are
18
- // also set, since they would be silently ignored.
19
- if (opts.httpClient !== undefined) {
20
- if (opts.credentials !== undefined || opts.timeout !== undefined) {
21
- throw new Error(
22
- 'httpClient cannot be combined with credentials or timeout'
23
- );
24
- }
25
- return opts.httpClient;
26
- }
27
-
28
- const credentials = opts.credentials ?? defaultCredentials();
29
-
30
- const base = newFetchHttpClient();
31
- let client: HttpClient = new AuthHttpClient(base, credentials);
32
-
33
- if (opts.timeout !== undefined) {
34
- client = new TimeoutHttpClient(client, opts.timeout);
35
- }
36
-
37
- return client;
38
- }
39
-
40
- /** Wraps an HttpClient and adds authentication headers to requests. */
41
- class AuthHttpClient implements HttpClient {
42
- constructor(
43
- private readonly base: HttpClient,
44
- private readonly credentials: Credentials
45
- ) {}
46
-
47
- async send(request: HttpRequest): Promise<HttpResponse> {
48
- const authHeaders = await this.credentials.authHeaders();
49
- // Do not modify the original request.
50
- const headers = new Headers(request.headers);
51
- for (const h of authHeaders) {
52
- headers.set(h.key, h.value);
53
- }
54
- return this.base.send({...request, headers});
55
- }
56
- }
57
-
58
- /** Wraps an HttpClient and applies a default timeout to requests. */
59
- class TimeoutHttpClient implements HttpClient {
60
- constructor(
61
- private readonly base: HttpClient,
62
- private readonly timeout: number
63
- ) {}
64
-
65
- async send(request: HttpRequest): Promise<HttpResponse> {
66
- const timeoutSignal = AbortSignal.timeout(this.timeout);
67
- const signal =
68
- request.signal !== undefined
69
- ? AbortSignal.any([request.signal, timeoutSignal])
70
- : timeoutSignal;
71
- return this.base.send({...request, signal});
72
- }
73
- }
package/src/v1/utils.ts DELETED
@@ -1,180 +0,0 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import type {Options} from '@databricks/sdk-core/ops';
4
- import {execute, retryOn} from '@databricks/sdk-core/ops';
5
- import {ApiError} from '@databricks/sdk-core/apierror';
6
- import type {
7
- HttpClient,
8
- HttpRequest,
9
- HttpResponse,
10
- } from '@databricks/sdk-core/http';
11
- import type {Logger} from '@databricks/sdk-core/logger';
12
- import type {CallOptions} from '@databricks/sdk-options/call';
13
- import type {LroOptions} from '@databricks/sdk-options/lro';
14
- import JSONBig from 'json-bigint';
15
- import type {z} from 'zod';
16
-
17
- // JSON codec that preserves int64 precision. On the way in, large integer
18
- // literals come back as bigint instead of being rounded to JS Number. On the
19
- // way out, bigint values are emitted as raw JSON number digits.
20
- const jsonBigint = JSONBig({useNativeBigInt: true});
21
-
22
- export interface HttpCallOptions {
23
- readonly request: HttpRequest;
24
- readonly httpClient: HttpClient;
25
- readonly logger: Logger;
26
- }
27
-
28
- /**
29
- * Translates public CallOptions to the internal Options shape accepted by
30
- * execute(). Even though the shapes match today, this isolates the public
31
- * API from the executor's internal type so they can diverge.
32
- */
33
- export async function executeCall(
34
- call: (signal?: AbortSignal) => Promise<void>,
35
- options?: CallOptions
36
- ): Promise<void> {
37
- const opts: Options = {
38
- ...(options?.retrier !== undefined && {retrier: options.retrier}),
39
- ...(options?.rateLimiter !== undefined && {
40
- rateLimiter: options.rateLimiter,
41
- }),
42
- ...(options?.timeout !== undefined && {timeout: options.timeout}),
43
- };
44
- return execute(options?.signal, call, opts);
45
- }
46
-
47
- /**
48
- * Sentinel thrown by a polling call to signal that the operation has not
49
- * yet reached a terminal state. {@link executeWait} treats this error as
50
- * retriable; any other error aborts the wait.
51
- */
52
- export class StillRunningError extends Error {}
53
-
54
- /**
55
- * Polls until the call returns without throwing {@link StillRunningError}.
56
- * Abort and overall-deadline behavior come from the supplied LroOptions.
57
- */
58
- export async function executeWait(
59
- call: (signal?: AbortSignal) => Promise<void>,
60
- options?: LroOptions
61
- ): Promise<void> {
62
- const opts: Options = {
63
- ...(options?.timeout !== undefined && {timeout: options.timeout}),
64
- retrier: () =>
65
- retryOn({}, (err: Error) => err instanceof StillRunningError),
66
- };
67
- return execute(options?.signal, call, opts);
68
- }
69
-
70
- async function readAll(
71
- body: ReadableStream<Uint8Array> | null
72
- ): Promise<Uint8Array> {
73
- if (body === null) {
74
- return new Uint8Array(0);
75
- }
76
- const reader = body.getReader();
77
- const chunks: Uint8Array[] = [];
78
- for (;;) {
79
- const {done, value} = await reader.read();
80
- if (done) {
81
- break;
82
- }
83
- chunks.push(value);
84
- }
85
- const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
86
- const result = new Uint8Array(totalLength);
87
- let offset = 0;
88
- for (const chunk of chunks) {
89
- result.set(chunk, offset);
90
- offset += chunk.length;
91
- }
92
- return result;
93
- }
94
-
95
- export async function executeHttpCall(
96
- opts: HttpCallOptions
97
- ): Promise<Uint8Array> {
98
- opts.logger.debug('HTTP request', {
99
- method: opts.request.method,
100
- url: opts.request.url,
101
- });
102
-
103
- let resp: HttpResponse;
104
- try {
105
- resp = await opts.httpClient.send(opts.request);
106
- } catch (e: unknown) {
107
- opts.logger.debug('HTTP request failed');
108
- throw e;
109
- }
110
-
111
- const body = await readAll(resp.body);
112
-
113
- opts.logger.debug('HTTP response', {
114
- statusCode: resp.statusCode,
115
- body: new TextDecoder().decode(body),
116
- });
117
-
118
- const apiErr = ApiError.fromHttpError(resp.statusCode, resp.headers, body);
119
- if (apiErr !== undefined) {
120
- throw apiErr;
121
- }
122
-
123
- return body;
124
- }
125
-
126
- export function buildHttpRequest(
127
- method: string,
128
- url: string,
129
- headers: Headers,
130
- signal?: AbortSignal,
131
- body?: string | ReadableStream<Uint8Array>
132
- ): HttpRequest {
133
- const req: HttpRequest = {url, method, headers};
134
- if (body !== undefined) {
135
- req.body = body;
136
- }
137
- if (signal !== undefined) {
138
- req.signal = signal;
139
- }
140
- return req;
141
- }
142
-
143
- export function parseResponse<T>(body: Uint8Array, schema: z.ZodType<T>): T {
144
- const text = new TextDecoder().decode(body);
145
- const parsed: unknown = jsonBigint.parse(text);
146
- return schema.parse(parsed);
147
- }
148
-
149
- export function marshalRequest(data: unknown, schema: z.ZodType): string {
150
- return jsonBigint.stringify(schema.parse(data));
151
- }
152
-
153
- export function flattenQueryParams(
154
- prefix: string,
155
- value: unknown,
156
- params: URLSearchParams
157
- ): void {
158
- if (value === null || value === undefined) {
159
- return;
160
- }
161
- if (Array.isArray(value)) {
162
- // arrays of objects are not yet supported
163
- for (const item of value) {
164
- params.append(prefix, String(item));
165
- }
166
- } else if (typeof value === 'object') {
167
- for (const [key, val] of Object.entries(value as Record<string, unknown>)) {
168
- flattenQueryParams(`${prefix}.${key}`, val, params);
169
- }
170
- } else if (
171
- typeof value === 'string' ||
172
- typeof value === 'number' ||
173
- typeof value === 'boolean' ||
174
- typeof value === 'bigint'
175
- ) {
176
- params.append(prefix, String(value));
177
- } else {
178
- throw new Error(`Unsupported query parameter type: ${typeof value}`);
179
- }
180
- }