@databricks/sdk-uc-connections 0.1.0-dev.2 → 0.1.0-dev.4

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/src/v1/model.ts DELETED
@@ -1,451 +0,0 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
-
3
- import {z} from 'zod';
4
-
5
- /** Next Id: 126 */
6
- export enum ConnectionType {
7
- UNKNOWN_CONNECTION_TYPE = 'UNKNOWN_CONNECTION_TYPE',
8
- MYSQL = 'MYSQL',
9
- POSTGRESQL = 'POSTGRESQL',
10
- SNOWFLAKE = 'SNOWFLAKE',
11
- REDSHIFT = 'REDSHIFT',
12
- SQLDW = 'SQLDW',
13
- SQLSERVER = 'SQLSERVER',
14
- DATABRICKS = 'DATABRICKS',
15
- SALESFORCE = 'SALESFORCE',
16
- BIGQUERY = 'BIGQUERY',
17
- WORKDAY_RAAS = 'WORKDAY_RAAS',
18
- HIVE_METASTORE = 'HIVE_METASTORE',
19
- GA4_RAW_DATA = 'GA4_RAW_DATA',
20
- SERVICENOW = 'SERVICENOW',
21
- SALESFORCE_DATA_CLOUD = 'SALESFORCE_DATA_CLOUD',
22
- GLUE = 'GLUE',
23
- ORACLE = 'ORACLE',
24
- TERADATA = 'TERADATA',
25
- HTTP = 'HTTP',
26
- POWER_BI = 'POWER_BI',
27
- CONFLUENCE = 'CONFLUENCE',
28
- META_MARKETING = 'META_MARKETING',
29
- HUBSPOT = 'HUBSPOT',
30
- ZENDESK = 'ZENDESK',
31
- GITHUB = 'GITHUB',
32
- OUTLOOK = 'OUTLOOK',
33
- SMARTSHEET = 'SMARTSHEET',
34
- }
35
-
36
- /** Next Id: 19 */
37
- export enum CredentialType {
38
- UNKNOWN_CREDENTIAL_TYPE = 'UNKNOWN_CREDENTIAL_TYPE',
39
- USERNAME_PASSWORD = 'USERNAME_PASSWORD',
40
- OAUTH_U2M = 'OAUTH_U2M',
41
- OAUTH_M2M = 'OAUTH_M2M',
42
- OAUTH_REFRESH_TOKEN = 'OAUTH_REFRESH_TOKEN',
43
- OAUTH_ACCESS_TOKEN = 'OAUTH_ACCESS_TOKEN',
44
- OAUTH_RESOURCE_OWNER_PASSWORD = 'OAUTH_RESOURCE_OWNER_PASSWORD',
45
- SERVICE_CREDENTIAL = 'SERVICE_CREDENTIAL',
46
- BEARER_TOKEN = 'BEARER_TOKEN',
47
- OIDC_TOKEN = 'OIDC_TOKEN',
48
- PEM_PRIVATE_KEY = 'PEM_PRIVATE_KEY',
49
- OAUTH_U2M_MAPPING = 'OAUTH_U2M_MAPPING',
50
- ANY_STATIC_CREDENTIAL = 'ANY_STATIC_CREDENTIAL',
51
- OAUTH_MTLS = 'OAUTH_MTLS',
52
- SSWS_TOKEN = 'SSWS_TOKEN',
53
- EDGEGRID_AKAMAI = 'EDGEGRID_AKAMAI',
54
- }
55
-
56
- /** The type of Unity Catalog securable. */
57
- export enum SecurableType {
58
- CATALOG = 'CATALOG',
59
- SCHEMA = 'SCHEMA',
60
- TABLE = 'TABLE',
61
- STORAGE_CREDENTIAL = 'STORAGE_CREDENTIAL',
62
- EXTERNAL_LOCATION = 'EXTERNAL_LOCATION',
63
- FUNCTION = 'FUNCTION',
64
- SHARE = 'SHARE',
65
- PROVIDER = 'PROVIDER',
66
- RECIPIENT = 'RECIPIENT',
67
- CLEAN_ROOM = 'CLEAN_ROOM',
68
- METASTORE = 'METASTORE',
69
- PIPELINE = 'PIPELINE',
70
- VOLUME = 'VOLUME',
71
- CONNECTION = 'CONNECTION',
72
- CREDENTIAL = 'CREDENTIAL',
73
- EXTERNAL_METADATA = 'EXTERNAL_METADATA',
74
- /** TODO: [UC-2980] Staging tables aren't full-fleged securables yet. */
75
- STAGING_TABLE = 'STAGING_TABLE',
76
- }
77
-
78
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested enum name.
79
- export enum ProvisioningInfo_State {
80
- STATE_UNSPECIFIED = 'STATE_UNSPECIFIED',
81
- PROVISIONING = 'PROVISIONING',
82
- ACTIVE = 'ACTIVE',
83
- FAILED = 'FAILED',
84
- DELETING = 'DELETING',
85
- UPDATING = 'UPDATING',
86
- DEGRADED = 'DEGRADED',
87
- }
88
-
89
- export interface ConnectionInfo {
90
- /** Name of the connection. */
91
- name?: string | undefined;
92
- /** The type of connection. */
93
- connectionType?: ConnectionType | undefined;
94
- /** Username of current owner of the connection. */
95
- owner?: string | undefined;
96
- /** If the connection is read only. */
97
- readOnly?: boolean | undefined;
98
- /** User-provided free-form text description. */
99
- comment?: string | undefined;
100
- /** Full name of connection. */
101
- fullName?: string | undefined;
102
- /** URL of the remote data source, extracted from options. */
103
- url?: string | undefined;
104
- /** The type of credential. */
105
- credentialType?: CredentialType | undefined;
106
- /** Unique identifier of the Connection. */
107
- connectionId?: string | undefined;
108
- /** Unique identifier of parent metastore. */
109
- metastoreId?: string | undefined;
110
- /** Time at which this connection was created, in epoch milliseconds. */
111
- createdAt?: bigint | undefined;
112
- /** Username of connection creator. */
113
- createdBy?: string | undefined;
114
- /** Time at which this connection was updated, in epoch milliseconds. */
115
- updatedAt?: bigint | undefined;
116
- /** Username of user who last modified connection. */
117
- updatedBy?: string | undefined;
118
- securableType?: SecurableType | undefined;
119
- provisioningInfo?: ProvisioningInfo | undefined;
120
- /** A map of key-value properties attached to the securable. */
121
- options?: Record<string, string> | undefined;
122
- /** A map of key-value properties attached to the securable. */
123
- properties?: Record<string, string> | undefined;
124
- }
125
-
126
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
127
- export interface ConnectionInfo_OptionsEntry {
128
- key?: string | undefined;
129
- value?: string | undefined;
130
- }
131
-
132
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
133
- export interface ConnectionInfo_PropertiesEntry {
134
- key?: string | undefined;
135
- value?: string | undefined;
136
- }
137
-
138
- export interface CreateConnectionRequest {
139
- /** Name of the connection. */
140
- name?: string | undefined;
141
- /** The type of connection. */
142
- connectionType?: ConnectionType | undefined;
143
- /** Username of current owner of the connection. */
144
- owner?: string | undefined;
145
- /** If the connection is read only. */
146
- readOnly?: boolean | undefined;
147
- /** User-provided free-form text description. */
148
- comment?: string | undefined;
149
- /** Full name of connection. */
150
- fullName?: string | undefined;
151
- /** URL of the remote data source, extracted from options. */
152
- url?: string | undefined;
153
- /** The type of credential. */
154
- credentialType?: CredentialType | undefined;
155
- /** Unique identifier of the Connection. */
156
- connectionId?: string | undefined;
157
- /** Unique identifier of parent metastore. */
158
- metastoreId?: string | undefined;
159
- /** Time at which this connection was created, in epoch milliseconds. */
160
- createdAt?: bigint | undefined;
161
- /** Username of connection creator. */
162
- createdBy?: string | undefined;
163
- /** Time at which this connection was updated, in epoch milliseconds. */
164
- updatedAt?: bigint | undefined;
165
- /** Username of user who last modified connection. */
166
- updatedBy?: string | undefined;
167
- securableType?: SecurableType | undefined;
168
- provisioningInfo?: ProvisioningInfo | undefined;
169
- /** A map of key-value properties attached to the securable. */
170
- options?: Record<string, string> | undefined;
171
- /** A map of key-value properties attached to the securable. */
172
- properties?: Record<string, string> | undefined;
173
- }
174
-
175
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
176
- export interface CreateConnectionRequest_OptionsEntry {
177
- key?: string | undefined;
178
- value?: string | undefined;
179
- }
180
-
181
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
182
- export interface CreateConnectionRequest_PropertiesEntry {
183
- key?: string | undefined;
184
- value?: string | undefined;
185
- }
186
-
187
- export interface DeleteConnectionRequest {
188
- /** The name of the connection to be deleted. */
189
- nameArg?: string | undefined;
190
- }
191
-
192
- // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type -- Proto-style nested message name.
193
- export interface DeleteConnectionRequest_Response {}
194
-
195
- export interface GetConnectionRequest {
196
- /** Name of the connection. */
197
- nameArg?: string | undefined;
198
- }
199
-
200
- export interface ListConnectionsRequest {
201
- /**
202
- * Maximum number of connections to return.
203
- * - If not set, all connections are returned (not recommended).
204
- * - when set to a value greater than 0, the page length is the minimum of this value and a server configured value;
205
- * - when set to 0, the page length is set to a server configured value (recommended);
206
- * - when set to a value less than 0, an invalid parameter error is returned;
207
- */
208
- maxResults?: number | undefined;
209
- /** Opaque pagination token to go to next page based on previous query. */
210
- pageToken?: string | undefined;
211
- }
212
-
213
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
214
- export interface ListConnectionsRequest_Response {
215
- /** An array of connection information objects. */
216
- connections?: ConnectionInfo[] | undefined;
217
- /**
218
- * Opaque token to retrieve the next page of results. Absent if there are no more pages.
219
- * __page_token__ should be set to this value for the next request (for the next page of results).
220
- */
221
- nextPageToken?: string | undefined;
222
- }
223
-
224
- /** Status of an asynchronously provisioned resource. */
225
- export interface ProvisioningInfo {
226
- /** The provisioning state of the resource. */
227
- state?: ProvisioningInfo_State | undefined;
228
- }
229
-
230
- export interface UpdateConnectionRequest {
231
- /** Name of the connection. */
232
- nameArg?: string | undefined;
233
- /** New name for the connection. */
234
- newName?: string | undefined;
235
- /** Name of the connection. */
236
- name?: string | undefined;
237
- /** The type of connection. */
238
- connectionType?: ConnectionType | undefined;
239
- /** Username of current owner of the connection. */
240
- owner?: string | undefined;
241
- /** If the connection is read only. */
242
- readOnly?: boolean | undefined;
243
- /** User-provided free-form text description. */
244
- comment?: string | undefined;
245
- /** Full name of connection. */
246
- fullName?: string | undefined;
247
- /** URL of the remote data source, extracted from options. */
248
- url?: string | undefined;
249
- /** The type of credential. */
250
- credentialType?: CredentialType | undefined;
251
- /** Unique identifier of the Connection. */
252
- connectionId?: string | undefined;
253
- /** Unique identifier of parent metastore. */
254
- metastoreId?: string | undefined;
255
- /** Time at which this connection was created, in epoch milliseconds. */
256
- createdAt?: bigint | undefined;
257
- /** Username of connection creator. */
258
- createdBy?: string | undefined;
259
- /** Time at which this connection was updated, in epoch milliseconds. */
260
- updatedAt?: bigint | undefined;
261
- /** Username of user who last modified connection. */
262
- updatedBy?: string | undefined;
263
- securableType?: SecurableType | undefined;
264
- provisioningInfo?: ProvisioningInfo | undefined;
265
- /** A map of key-value properties attached to the securable. */
266
- options?: Record<string, string> | undefined;
267
- /** A map of key-value properties attached to the securable. */
268
- properties?: Record<string, string> | undefined;
269
- }
270
-
271
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
272
- export interface UpdateConnectionRequest_OptionsEntry {
273
- key?: string | undefined;
274
- value?: string | undefined;
275
- }
276
-
277
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
278
- export interface UpdateConnectionRequest_PropertiesEntry {
279
- key?: string | undefined;
280
- value?: string | undefined;
281
- }
282
-
283
- export const unmarshalConnectionInfoSchema: z.ZodType<ConnectionInfo> = z
284
- .object({
285
- name: z.string().optional(),
286
- connection_type: z.enum(ConnectionType).optional(),
287
- owner: z.string().optional(),
288
- read_only: z.boolean().optional(),
289
- comment: z.string().optional(),
290
- full_name: z.string().optional(),
291
- url: z.string().optional(),
292
- credential_type: z.enum(CredentialType).optional(),
293
- connection_id: z.string().optional(),
294
- metastore_id: z.string().optional(),
295
- created_at: z
296
- .union([z.number(), z.bigint()])
297
- .transform(v => BigInt(v))
298
- .optional(),
299
- created_by: z.string().optional(),
300
- updated_at: z
301
- .union([z.number(), z.bigint()])
302
- .transform(v => BigInt(v))
303
- .optional(),
304
- updated_by: z.string().optional(),
305
- securable_type: z.enum(SecurableType).optional(),
306
- provisioning_info: z.lazy(() => unmarshalProvisioningInfoSchema).optional(),
307
- options: z.record(z.string(), z.string()).optional(),
308
- properties: z.record(z.string(), z.string()).optional(),
309
- })
310
- .transform(d => ({
311
- name: d.name,
312
- connectionType: d.connection_type,
313
- owner: d.owner,
314
- readOnly: d.read_only,
315
- comment: d.comment,
316
- fullName: d.full_name,
317
- url: d.url,
318
- credentialType: d.credential_type,
319
- connectionId: d.connection_id,
320
- metastoreId: d.metastore_id,
321
- createdAt: d.created_at,
322
- createdBy: d.created_by,
323
- updatedAt: d.updated_at,
324
- updatedBy: d.updated_by,
325
- securableType: d.securable_type,
326
- provisioningInfo: d.provisioning_info,
327
- options: d.options,
328
- properties: d.properties,
329
- }));
330
-
331
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
332
- export const unmarshalDeleteConnectionRequest_ResponseSchema: z.ZodType<DeleteConnectionRequest_Response> =
333
- z.object({});
334
-
335
- // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
336
- export const unmarshalListConnectionsRequest_ResponseSchema: z.ZodType<ListConnectionsRequest_Response> =
337
- z
338
- .object({
339
- connections: z
340
- .array(z.lazy(() => unmarshalConnectionInfoSchema))
341
- .optional(),
342
- next_page_token: z.string().optional(),
343
- })
344
- .transform(d => ({
345
- connections: d.connections,
346
- nextPageToken: d.next_page_token,
347
- }));
348
-
349
- export const unmarshalProvisioningInfoSchema: z.ZodType<ProvisioningInfo> = z
350
- .object({
351
- state: z.enum(ProvisioningInfo_State).optional(),
352
- })
353
- .transform(d => ({
354
- state: d.state,
355
- }));
356
-
357
- export const marshalCreateConnectionRequestSchema: z.ZodType = z
358
- .object({
359
- name: z.string().optional(),
360
- connectionType: z.enum(ConnectionType).optional(),
361
- owner: z.string().optional(),
362
- readOnly: z.boolean().optional(),
363
- comment: z.string().optional(),
364
- fullName: z.string().optional(),
365
- url: z.string().optional(),
366
- credentialType: z.enum(CredentialType).optional(),
367
- connectionId: z.string().optional(),
368
- metastoreId: z.string().optional(),
369
- createdAt: z.bigint().optional(),
370
- createdBy: z.string().optional(),
371
- updatedAt: z.bigint().optional(),
372
- updatedBy: z.string().optional(),
373
- securableType: z.enum(SecurableType).optional(),
374
- provisioningInfo: z.lazy(() => marshalProvisioningInfoSchema).optional(),
375
- options: z.record(z.string(), z.string()).optional(),
376
- properties: z.record(z.string(), z.string()).optional(),
377
- })
378
- .transform(d => ({
379
- name: d.name,
380
- connection_type: d.connectionType,
381
- owner: d.owner,
382
- read_only: d.readOnly,
383
- comment: d.comment,
384
- full_name: d.fullName,
385
- url: d.url,
386
- credential_type: d.credentialType,
387
- connection_id: d.connectionId,
388
- metastore_id: d.metastoreId,
389
- created_at: d.createdAt,
390
- created_by: d.createdBy,
391
- updated_at: d.updatedAt,
392
- updated_by: d.updatedBy,
393
- securable_type: d.securableType,
394
- provisioning_info: d.provisioningInfo,
395
- options: d.options,
396
- properties: d.properties,
397
- }));
398
-
399
- export const marshalProvisioningInfoSchema: z.ZodType = z
400
- .object({
401
- state: z.enum(ProvisioningInfo_State).optional(),
402
- })
403
- .transform(d => ({
404
- state: d.state,
405
- }));
406
-
407
- export const marshalUpdateConnectionRequestSchema: z.ZodType = z
408
- .object({
409
- nameArg: z.string().optional(),
410
- newName: z.string().optional(),
411
- name: z.string().optional(),
412
- connectionType: z.enum(ConnectionType).optional(),
413
- owner: z.string().optional(),
414
- readOnly: z.boolean().optional(),
415
- comment: z.string().optional(),
416
- fullName: z.string().optional(),
417
- url: z.string().optional(),
418
- credentialType: z.enum(CredentialType).optional(),
419
- connectionId: z.string().optional(),
420
- metastoreId: z.string().optional(),
421
- createdAt: z.bigint().optional(),
422
- createdBy: z.string().optional(),
423
- updatedAt: z.bigint().optional(),
424
- updatedBy: z.string().optional(),
425
- securableType: z.enum(SecurableType).optional(),
426
- provisioningInfo: z.lazy(() => marshalProvisioningInfoSchema).optional(),
427
- options: z.record(z.string(), z.string()).optional(),
428
- properties: z.record(z.string(), z.string()).optional(),
429
- })
430
- .transform(d => ({
431
- name_arg: d.nameArg,
432
- new_name: d.newName,
433
- name: d.name,
434
- connection_type: d.connectionType,
435
- owner: d.owner,
436
- read_only: d.readOnly,
437
- comment: d.comment,
438
- full_name: d.fullName,
439
- url: d.url,
440
- credential_type: d.credentialType,
441
- connection_id: d.connectionId,
442
- metastore_id: d.metastoreId,
443
- created_at: d.createdAt,
444
- created_by: d.createdBy,
445
- updated_at: d.updatedAt,
446
- updated_by: d.updatedBy,
447
- securable_type: d.securableType,
448
- provisioning_info: d.provisioningInfo,
449
- options: d.options,
450
- properties: d.properties,
451
- }));
@@ -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,156 +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} 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
- }