@databricks/sdk-clusterlibraries 0.0.0-dev → 0.1.0-dev.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/LICENSE +203 -0
- package/dist/v2/client.d.ts +37 -0
- package/dist/v2/client.d.ts.map +1 -0
- package/dist/v2/client.js +162 -0
- package/dist/v2/client.js.map +1 -0
- package/dist/v2/index.d.ts +4 -0
- package/dist/v2/index.d.ts.map +1 -0
- package/dist/v2/index.js +4 -0
- package/dist/v2/index.js.map +1 -0
- package/dist/v2/model.d.ts +178 -0
- package/dist/v2/model.d.ts.map +1 -0
- package/dist/v2/model.js +212 -0
- package/dist/v2/model.js.map +1 -0
- package/dist/v2/transport.d.ts +5 -0
- package/dist/v2/transport.d.ts.map +1 -0
- package/dist/v2/transport.js +57 -0
- package/dist/v2/transport.js.map +1 -0
- package/dist/v2/utils.d.ts +21 -0
- package/dist/v2/utils.d.ts.map +1 -0
- package/dist/v2/utils.js +113 -0
- package/dist/v2/utils.js.map +1 -0
- package/package.json +38 -4
- package/src/v2/client.ts +217 -0
- package/src/v2/index.ts +21 -0
- package/src/v2/model.ts +383 -0
- package/src/v2/transport.ts +73 -0
- package/src/v2/utils.ts +156 -0
- package/README.md +0 -1
- package/index.js +0 -1
package/src/v2/utils.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
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} 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 JSONBig from 'json-bigint';
|
|
14
|
+
import type {z} from 'zod';
|
|
15
|
+
|
|
16
|
+
// JSON codec that preserves int64 precision. On the way in, large integer
|
|
17
|
+
// literals come back as bigint instead of being rounded to JS Number. On the
|
|
18
|
+
// way out, bigint values are emitted as raw JSON number digits.
|
|
19
|
+
const jsonBigint = JSONBig({useNativeBigInt: true});
|
|
20
|
+
|
|
21
|
+
export interface HttpCallOptions {
|
|
22
|
+
readonly request: HttpRequest;
|
|
23
|
+
readonly httpClient: HttpClient;
|
|
24
|
+
readonly logger: Logger;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Translates public CallOptions to the internal Options shape accepted by
|
|
29
|
+
* execute(). Even though the shapes match today, this isolates the public
|
|
30
|
+
* API from the executor's internal type so they can diverge.
|
|
31
|
+
*/
|
|
32
|
+
export async function executeCall(
|
|
33
|
+
call: (signal?: AbortSignal) => Promise<void>,
|
|
34
|
+
options?: CallOptions
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
const opts: Options = {
|
|
37
|
+
...(options?.retrier !== undefined && {retrier: options.retrier}),
|
|
38
|
+
...(options?.rateLimiter !== undefined && {
|
|
39
|
+
rateLimiter: options.rateLimiter,
|
|
40
|
+
}),
|
|
41
|
+
...(options?.timeout !== undefined && {timeout: options.timeout}),
|
|
42
|
+
};
|
|
43
|
+
return execute(options?.signal, call, opts);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async function readAll(
|
|
47
|
+
body: ReadableStream<Uint8Array> | null
|
|
48
|
+
): Promise<Uint8Array> {
|
|
49
|
+
if (body === null) {
|
|
50
|
+
return new Uint8Array(0);
|
|
51
|
+
}
|
|
52
|
+
const reader = body.getReader();
|
|
53
|
+
const chunks: Uint8Array[] = [];
|
|
54
|
+
for (;;) {
|
|
55
|
+
const {done, value} = await reader.read();
|
|
56
|
+
if (done) {
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
chunks.push(value);
|
|
60
|
+
}
|
|
61
|
+
const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
|
|
62
|
+
const result = new Uint8Array(totalLength);
|
|
63
|
+
let offset = 0;
|
|
64
|
+
for (const chunk of chunks) {
|
|
65
|
+
result.set(chunk, offset);
|
|
66
|
+
offset += chunk.length;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function executeHttpCall(
|
|
72
|
+
opts: HttpCallOptions
|
|
73
|
+
): Promise<Uint8Array> {
|
|
74
|
+
opts.logger.debug('HTTP request', {
|
|
75
|
+
method: opts.request.method,
|
|
76
|
+
url: opts.request.url,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
let resp: HttpResponse;
|
|
80
|
+
try {
|
|
81
|
+
resp = await opts.httpClient.send(opts.request);
|
|
82
|
+
} catch (e: unknown) {
|
|
83
|
+
opts.logger.debug('HTTP request failed');
|
|
84
|
+
throw e;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const body = await readAll(resp.body);
|
|
88
|
+
|
|
89
|
+
opts.logger.debug('HTTP response', {
|
|
90
|
+
statusCode: resp.statusCode,
|
|
91
|
+
body: new TextDecoder().decode(body),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const apiErr = ApiError.fromHttpError(resp.statusCode, resp.headers, body);
|
|
95
|
+
if (apiErr !== undefined) {
|
|
96
|
+
throw apiErr;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return body;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function buildHttpRequest(
|
|
103
|
+
method: string,
|
|
104
|
+
url: string,
|
|
105
|
+
headers: Headers,
|
|
106
|
+
signal?: AbortSignal,
|
|
107
|
+
body?: string | ReadableStream<Uint8Array>
|
|
108
|
+
): HttpRequest {
|
|
109
|
+
const req: HttpRequest = {url, method, headers};
|
|
110
|
+
if (body !== undefined) {
|
|
111
|
+
req.body = body;
|
|
112
|
+
}
|
|
113
|
+
if (signal !== undefined) {
|
|
114
|
+
req.signal = signal;
|
|
115
|
+
}
|
|
116
|
+
return req;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function parseResponse<T>(body: Uint8Array, schema: z.ZodType<T>): T {
|
|
120
|
+
const text = new TextDecoder().decode(body);
|
|
121
|
+
const parsed: unknown = jsonBigint.parse(text);
|
|
122
|
+
return schema.parse(parsed);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function marshalRequest(data: unknown, schema: z.ZodType): string {
|
|
126
|
+
return jsonBigint.stringify(schema.parse(data));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function flattenQueryParams(
|
|
130
|
+
prefix: string,
|
|
131
|
+
value: unknown,
|
|
132
|
+
params: URLSearchParams
|
|
133
|
+
): void {
|
|
134
|
+
if (value === null || value === undefined) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(value)) {
|
|
138
|
+
// arrays of objects are not yet supported
|
|
139
|
+
for (const item of value) {
|
|
140
|
+
params.append(prefix, String(item));
|
|
141
|
+
}
|
|
142
|
+
} else if (typeof value === 'object') {
|
|
143
|
+
for (const [key, val] of Object.entries(value as Record<string, unknown>)) {
|
|
144
|
+
flattenQueryParams(`${prefix}.${key}`, val, params);
|
|
145
|
+
}
|
|
146
|
+
} else if (
|
|
147
|
+
typeof value === 'string' ||
|
|
148
|
+
typeof value === 'number' ||
|
|
149
|
+
typeof value === 'boolean' ||
|
|
150
|
+
typeof value === 'bigint'
|
|
151
|
+
) {
|
|
152
|
+
params.append(prefix, String(value));
|
|
153
|
+
} else {
|
|
154
|
+
throw new Error(`Unsupported query parameter type: ${typeof value}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
This is a placeholder release used to enable OIDC trusted publishing. Real code lands in a later version.
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {};
|