@databricks/sdk-uc-rfa 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.
- package/README.md +28 -0
- package/dist/v1/client.d.ts +3 -3
- package/dist/v1/client.d.ts.map +1 -1
- package/dist/v1/client.js +26 -25
- package/dist/v1/client.js.map +1 -1
- package/dist/v1/model.d.ts +45 -41
- package/dist/v1/model.d.ts.map +1 -1
- package/dist/v1/model.js +53 -53
- package/dist/v1/model.js.map +1 -1
- package/dist/v1/transport.d.ts +30 -2
- package/dist/v1/transport.d.ts.map +1 -1
- package/dist/v1/transport.js +33 -16
- package/dist/v1/transport.js.map +1 -1
- package/dist/v1/utils.d.ts.map +1 -1
- package/dist/v1/utils.js +2 -1
- package/dist/v1/utils.js.map +1 -1
- package/package.json +9 -5
- package/src/v1/client.ts +0 -197
- package/src/v1/index.ts +0 -26
- package/src/v1/model.ts +0 -384
- package/src/v1/transport.ts +0 -73
- package/src/v1/utils.ts +0 -156
package/src/v1/model.ts
DELETED
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
// Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
|
|
2
|
-
|
|
3
|
-
import {FieldMask} from '@databricks/sdk-core/wkt';
|
|
4
|
-
import type {FieldMaskSchema} from '@databricks/sdk-core/wkt';
|
|
5
|
-
import {z} from 'zod';
|
|
6
|
-
|
|
7
|
-
export enum DestinationType {
|
|
8
|
-
DESTINATION_TYPE_UNSPECIFIED = 'DESTINATION_TYPE_UNSPECIFIED',
|
|
9
|
-
EMAIL = 'EMAIL',
|
|
10
|
-
SLACK = 'SLACK',
|
|
11
|
-
GENERIC_WEBHOOK = 'GENERIC_WEBHOOK',
|
|
12
|
-
MICROSOFT_TEAMS = 'MICROSOFT_TEAMS',
|
|
13
|
-
URL = 'URL',
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export enum PrincipalType {
|
|
17
|
-
PRINCIPAL_TYPE_UNSPECIFIED = 'PRINCIPAL_TYPE_UNSPECIFIED',
|
|
18
|
-
USER_PRINCIPAL = 'USER_PRINCIPAL',
|
|
19
|
-
GROUP_PRINCIPAL = 'GROUP_PRINCIPAL',
|
|
20
|
-
SERVICE_PRINCIPAL = 'SERVICE_PRINCIPAL',
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** The type of Unity Catalog securable. */
|
|
24
|
-
export enum SecurableType {
|
|
25
|
-
CATALOG = 'CATALOG',
|
|
26
|
-
SCHEMA = 'SCHEMA',
|
|
27
|
-
TABLE = 'TABLE',
|
|
28
|
-
STORAGE_CREDENTIAL = 'STORAGE_CREDENTIAL',
|
|
29
|
-
EXTERNAL_LOCATION = 'EXTERNAL_LOCATION',
|
|
30
|
-
FUNCTION = 'FUNCTION',
|
|
31
|
-
SHARE = 'SHARE',
|
|
32
|
-
PROVIDER = 'PROVIDER',
|
|
33
|
-
RECIPIENT = 'RECIPIENT',
|
|
34
|
-
CLEAN_ROOM = 'CLEAN_ROOM',
|
|
35
|
-
METASTORE = 'METASTORE',
|
|
36
|
-
PIPELINE = 'PIPELINE',
|
|
37
|
-
VOLUME = 'VOLUME',
|
|
38
|
-
CONNECTION = 'CONNECTION',
|
|
39
|
-
CREDENTIAL = 'CREDENTIAL',
|
|
40
|
-
EXTERNAL_METADATA = 'EXTERNAL_METADATA',
|
|
41
|
-
/** TODO: [UC-2980] Staging tables aren't full-fleged securables yet. */
|
|
42
|
-
STAGING_TABLE = 'STAGING_TABLE',
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export enum SpecialDestination {
|
|
46
|
-
SPECIAL_DESTINATION_UNSPECIFIED = 'SPECIAL_DESTINATION_UNSPECIFIED',
|
|
47
|
-
SPECIAL_DESTINATION_CATALOG_OWNER = 'SPECIAL_DESTINATION_CATALOG_OWNER',
|
|
48
|
-
SPECIAL_DESTINATION_EXTERNAL_LOCATION_OWNER = 'SPECIAL_DESTINATION_EXTERNAL_LOCATION_OWNER',
|
|
49
|
-
SPECIAL_DESTINATION_CONNECTION_OWNER = 'SPECIAL_DESTINATION_CONNECTION_OWNER',
|
|
50
|
-
SPECIAL_DESTINATION_CREDENTIAL_OWNER = 'SPECIAL_DESTINATION_CREDENTIAL_OWNER',
|
|
51
|
-
SPECIAL_DESTINATION_METASTORE_OWNER = 'SPECIAL_DESTINATION_METASTORE_OWNER',
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface AccessRequestDestinations {
|
|
55
|
-
/** The access request destinations for the securable. */
|
|
56
|
-
destinations?: NotificationDestination[] | undefined;
|
|
57
|
-
/** The securable for which the access request destinations are being modified or read. */
|
|
58
|
-
securable?: Securable | undefined;
|
|
59
|
-
/**
|
|
60
|
-
* Indicates whether any destinations are hidden from the caller due to a lack of permissions.
|
|
61
|
-
* This value is true if the caller does not have permission to see all destinations.
|
|
62
|
-
*/
|
|
63
|
-
areAnyDestinationsHidden?: boolean | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* The source securable from which the destinations are inherited. Either the same value as securable (if destination
|
|
66
|
-
* is set directly on the securable) or the nearest parent securable with destinations set.
|
|
67
|
-
*/
|
|
68
|
-
destinationSourceSecurable?: Securable | undefined;
|
|
69
|
-
/** The type of the securable. Redundant with the type in the securable object, but necessary for Terraform integration */
|
|
70
|
-
securableType?: string | undefined;
|
|
71
|
-
/** The full name of the securable. Redundant with the name in the securable object, but necessary for Terraform integration */
|
|
72
|
-
fullName?: string | undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface BatchCreateAccessRequestsRequest {
|
|
76
|
-
/**
|
|
77
|
-
* A list of individual access requests, where each request corresponds to
|
|
78
|
-
* a set of permissions being requested on a list of securables for a specified principal.
|
|
79
|
-
*
|
|
80
|
-
* At most 30 requests per API call.
|
|
81
|
-
*/
|
|
82
|
-
requests?: CreateAccessRequest[] | undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export interface BatchCreateAccessRequestsResponse {
|
|
86
|
-
/** The access request destinations for each securable object the principal requested. */
|
|
87
|
-
responses?: CreateAccessRequestResponse[] | undefined;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export interface CreateAccessRequest {
|
|
91
|
-
/**
|
|
92
|
-
* Optional. The principal this request is for.
|
|
93
|
-
* Empty `behalf_of` defaults to the requester's identity.
|
|
94
|
-
*
|
|
95
|
-
* Principals must be unique across the API call.
|
|
96
|
-
*/
|
|
97
|
-
behalfOf?: Principal | undefined;
|
|
98
|
-
/**
|
|
99
|
-
* Optional. Comment associated with the request.
|
|
100
|
-
*
|
|
101
|
-
* At most 200 characters, can only contain lowercase/uppercase
|
|
102
|
-
* letters (a-z, A-Z), numbers (0-9), punctuation, and spaces.
|
|
103
|
-
*/
|
|
104
|
-
comment?: string | undefined;
|
|
105
|
-
/**
|
|
106
|
-
* List of securables and their corresponding requested UC privileges.
|
|
107
|
-
*
|
|
108
|
-
* At most 30 securables can be requested for a principal per batched call.
|
|
109
|
-
* Each securable can only be requested once per principal.
|
|
110
|
-
*/
|
|
111
|
-
securablePermissions?: SecurablePermissions[] | undefined;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export interface CreateAccessRequestResponse {
|
|
115
|
-
/** The principal the request was made on behalf of. */
|
|
116
|
-
behalfOf?: Principal | undefined;
|
|
117
|
-
/** The access request destinations for all the securables the principal requested. */
|
|
118
|
-
requestDestinations?: AccessRequestDestinations[] | undefined;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface GetAccessRequestDestinationsRequest {
|
|
122
|
-
/** The type of the securable. */
|
|
123
|
-
securableType?: string | undefined;
|
|
124
|
-
/** The full name of the securable. */
|
|
125
|
-
fullName?: string | undefined;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface NotificationDestination {
|
|
129
|
-
/**
|
|
130
|
-
* The identifier for the destination. This is the email address for EMAIL destinations, the URL for URL destinations,
|
|
131
|
-
* or the unique <Databricks> notification destination ID for all other external destinations.
|
|
132
|
-
*/
|
|
133
|
-
destinationId?: string | undefined;
|
|
134
|
-
/** The type of the destination. */
|
|
135
|
-
destinationType?: DestinationType | undefined;
|
|
136
|
-
/**
|
|
137
|
-
* This field is used to denote whether the destination is the email of the owner of the securable object.
|
|
138
|
-
* The special destination cannot be assigned to a securable and only represents the default destination of the securable.
|
|
139
|
-
* The securable types that support default special destinations are: "catalog", "external_location", "connection", "credential", and "metastore".
|
|
140
|
-
* The **destination_type** of a **special_destination** is always EMAIL.
|
|
141
|
-
*/
|
|
142
|
-
specialDestination?: SpecialDestination | undefined;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export interface Principal {
|
|
146
|
-
/** <Databricks> user, group or service principal ID. */
|
|
147
|
-
id?: string | undefined;
|
|
148
|
-
principalType?: PrincipalType | undefined;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Generic definition of a securable, which is uniquely defined in a metastore
|
|
153
|
-
* by its type and full name.
|
|
154
|
-
*/
|
|
155
|
-
export interface Securable {
|
|
156
|
-
/**
|
|
157
|
-
* Required. The type of securable (catalog/schema/table).
|
|
158
|
-
* Optional if resource_name is present.
|
|
159
|
-
*/
|
|
160
|
-
type?: SecurableType | undefined;
|
|
161
|
-
/**
|
|
162
|
-
* Required. The full name of the catalog/schema/table.
|
|
163
|
-
* Optional if resource_name is present.
|
|
164
|
-
*/
|
|
165
|
-
fullName?: string | undefined;
|
|
166
|
-
/**
|
|
167
|
-
* Optional. The name of the Share object that contains the securable when the securable is
|
|
168
|
-
* getting shared in D2D Delta Sharing.
|
|
169
|
-
*/
|
|
170
|
-
providerShare?: string | undefined;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export interface SecurablePermissions {
|
|
174
|
-
/** The securable for which the access request destinations are being requested. */
|
|
175
|
-
securable?: Securable | undefined;
|
|
176
|
-
/** List of requested Unity Catalog permissions. */
|
|
177
|
-
permissions?: string[] | undefined;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export interface UpdateAccessRequestDestinationsRequest {
|
|
181
|
-
/**
|
|
182
|
-
* The access request destinations to assign to the securable.
|
|
183
|
-
* For each destination, a **destination_id** and **destination_type** must be defined.
|
|
184
|
-
*/
|
|
185
|
-
accessRequestDestinations?: AccessRequestDestinations | undefined;
|
|
186
|
-
updateMask?: FieldMask<AccessRequestDestinations> | undefined;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export const unmarshalAccessRequestDestinationsSchema: z.ZodType<AccessRequestDestinations> =
|
|
190
|
-
z
|
|
191
|
-
.object({
|
|
192
|
-
destinations: z
|
|
193
|
-
.array(z.lazy(() => unmarshalNotificationDestinationSchema))
|
|
194
|
-
.optional(),
|
|
195
|
-
securable: z.lazy(() => unmarshalSecurableSchema).optional(),
|
|
196
|
-
are_any_destinations_hidden: z.boolean().optional(),
|
|
197
|
-
destination_source_securable: z
|
|
198
|
-
.lazy(() => unmarshalSecurableSchema)
|
|
199
|
-
.optional(),
|
|
200
|
-
securable_type: z.string().optional(),
|
|
201
|
-
full_name: z.string().optional(),
|
|
202
|
-
})
|
|
203
|
-
.transform(d => ({
|
|
204
|
-
destinations: d.destinations,
|
|
205
|
-
securable: d.securable,
|
|
206
|
-
areAnyDestinationsHidden: d.are_any_destinations_hidden,
|
|
207
|
-
destinationSourceSecurable: d.destination_source_securable,
|
|
208
|
-
securableType: d.securable_type,
|
|
209
|
-
fullName: d.full_name,
|
|
210
|
-
}));
|
|
211
|
-
|
|
212
|
-
export const unmarshalBatchCreateAccessRequestsResponseSchema: z.ZodType<BatchCreateAccessRequestsResponse> =
|
|
213
|
-
z
|
|
214
|
-
.object({
|
|
215
|
-
responses: z
|
|
216
|
-
.array(z.lazy(() => unmarshalCreateAccessRequestResponseSchema))
|
|
217
|
-
.optional(),
|
|
218
|
-
})
|
|
219
|
-
.transform(d => ({
|
|
220
|
-
responses: d.responses,
|
|
221
|
-
}));
|
|
222
|
-
|
|
223
|
-
export const unmarshalCreateAccessRequestResponseSchema: z.ZodType<CreateAccessRequestResponse> =
|
|
224
|
-
z
|
|
225
|
-
.object({
|
|
226
|
-
behalf_of: z.lazy(() => unmarshalPrincipalSchema).optional(),
|
|
227
|
-
request_destinations: z
|
|
228
|
-
.array(z.lazy(() => unmarshalAccessRequestDestinationsSchema))
|
|
229
|
-
.optional(),
|
|
230
|
-
})
|
|
231
|
-
.transform(d => ({
|
|
232
|
-
behalfOf: d.behalf_of,
|
|
233
|
-
requestDestinations: d.request_destinations,
|
|
234
|
-
}));
|
|
235
|
-
|
|
236
|
-
export const unmarshalNotificationDestinationSchema: z.ZodType<NotificationDestination> =
|
|
237
|
-
z
|
|
238
|
-
.object({
|
|
239
|
-
destination_id: z.string().optional(),
|
|
240
|
-
destination_type: z.enum(DestinationType).optional(),
|
|
241
|
-
special_destination: z.enum(SpecialDestination).optional(),
|
|
242
|
-
})
|
|
243
|
-
.transform(d => ({
|
|
244
|
-
destinationId: d.destination_id,
|
|
245
|
-
destinationType: d.destination_type,
|
|
246
|
-
specialDestination: d.special_destination,
|
|
247
|
-
}));
|
|
248
|
-
|
|
249
|
-
export const unmarshalPrincipalSchema: z.ZodType<Principal> = z
|
|
250
|
-
.object({
|
|
251
|
-
id: z.string().optional(),
|
|
252
|
-
principal_type: z.enum(PrincipalType).optional(),
|
|
253
|
-
})
|
|
254
|
-
.transform(d => ({
|
|
255
|
-
id: d.id,
|
|
256
|
-
principalType: d.principal_type,
|
|
257
|
-
}));
|
|
258
|
-
|
|
259
|
-
export const unmarshalSecurableSchema: z.ZodType<Securable> = z
|
|
260
|
-
.object({
|
|
261
|
-
type: z.enum(SecurableType).optional(),
|
|
262
|
-
full_name: z.string().optional(),
|
|
263
|
-
provider_share: z.string().optional(),
|
|
264
|
-
})
|
|
265
|
-
.transform(d => ({
|
|
266
|
-
type: d.type,
|
|
267
|
-
fullName: d.full_name,
|
|
268
|
-
providerShare: d.provider_share,
|
|
269
|
-
}));
|
|
270
|
-
|
|
271
|
-
export const marshalAccessRequestDestinationsSchema: z.ZodType = z
|
|
272
|
-
.object({
|
|
273
|
-
destinations: z
|
|
274
|
-
.array(z.lazy(() => marshalNotificationDestinationSchema))
|
|
275
|
-
.optional(),
|
|
276
|
-
securable: z.lazy(() => marshalSecurableSchema).optional(),
|
|
277
|
-
areAnyDestinationsHidden: z.boolean().optional(),
|
|
278
|
-
destinationSourceSecurable: z.lazy(() => marshalSecurableSchema).optional(),
|
|
279
|
-
securableType: z.string().optional(),
|
|
280
|
-
fullName: z.string().optional(),
|
|
281
|
-
})
|
|
282
|
-
.transform(d => ({
|
|
283
|
-
destinations: d.destinations,
|
|
284
|
-
securable: d.securable,
|
|
285
|
-
are_any_destinations_hidden: d.areAnyDestinationsHidden,
|
|
286
|
-
destination_source_securable: d.destinationSourceSecurable,
|
|
287
|
-
securable_type: d.securableType,
|
|
288
|
-
full_name: d.fullName,
|
|
289
|
-
}));
|
|
290
|
-
|
|
291
|
-
export const marshalBatchCreateAccessRequestsRequestSchema: z.ZodType = z
|
|
292
|
-
.object({
|
|
293
|
-
requests: z
|
|
294
|
-
.array(z.lazy(() => marshalCreateAccessRequestSchema))
|
|
295
|
-
.optional(),
|
|
296
|
-
})
|
|
297
|
-
.transform(d => ({
|
|
298
|
-
requests: d.requests,
|
|
299
|
-
}));
|
|
300
|
-
|
|
301
|
-
export const marshalCreateAccessRequestSchema: z.ZodType = z
|
|
302
|
-
.object({
|
|
303
|
-
behalfOf: z.lazy(() => marshalPrincipalSchema).optional(),
|
|
304
|
-
comment: z.string().optional(),
|
|
305
|
-
securablePermissions: z
|
|
306
|
-
.array(z.lazy(() => marshalSecurablePermissionsSchema))
|
|
307
|
-
.optional(),
|
|
308
|
-
})
|
|
309
|
-
.transform(d => ({
|
|
310
|
-
behalf_of: d.behalfOf,
|
|
311
|
-
comment: d.comment,
|
|
312
|
-
securable_permissions: d.securablePermissions,
|
|
313
|
-
}));
|
|
314
|
-
|
|
315
|
-
export const marshalNotificationDestinationSchema: z.ZodType = z
|
|
316
|
-
.object({
|
|
317
|
-
destinationId: z.string().optional(),
|
|
318
|
-
destinationType: z.enum(DestinationType).optional(),
|
|
319
|
-
specialDestination: z.enum(SpecialDestination).optional(),
|
|
320
|
-
})
|
|
321
|
-
.transform(d => ({
|
|
322
|
-
destination_id: d.destinationId,
|
|
323
|
-
destination_type: d.destinationType,
|
|
324
|
-
special_destination: d.specialDestination,
|
|
325
|
-
}));
|
|
326
|
-
|
|
327
|
-
export const marshalPrincipalSchema: z.ZodType = z
|
|
328
|
-
.object({
|
|
329
|
-
id: z.string().optional(),
|
|
330
|
-
principalType: z.enum(PrincipalType).optional(),
|
|
331
|
-
})
|
|
332
|
-
.transform(d => ({
|
|
333
|
-
id: d.id,
|
|
334
|
-
principal_type: d.principalType,
|
|
335
|
-
}));
|
|
336
|
-
|
|
337
|
-
export const marshalSecurableSchema: z.ZodType = z
|
|
338
|
-
.object({
|
|
339
|
-
type: z.enum(SecurableType).optional(),
|
|
340
|
-
fullName: z.string().optional(),
|
|
341
|
-
providerShare: z.string().optional(),
|
|
342
|
-
})
|
|
343
|
-
.transform(d => ({
|
|
344
|
-
type: d.type,
|
|
345
|
-
full_name: d.fullName,
|
|
346
|
-
provider_share: d.providerShare,
|
|
347
|
-
}));
|
|
348
|
-
|
|
349
|
-
export const marshalSecurablePermissionsSchema: z.ZodType = z
|
|
350
|
-
.object({
|
|
351
|
-
securable: z.lazy(() => marshalSecurableSchema).optional(),
|
|
352
|
-
permissions: z.array(z.string()).optional(),
|
|
353
|
-
})
|
|
354
|
-
.transform(d => ({
|
|
355
|
-
securable: d.securable,
|
|
356
|
-
permissions: d.permissions,
|
|
357
|
-
}));
|
|
358
|
-
|
|
359
|
-
const accessRequestDestinationsFieldMaskSchema: FieldMaskSchema = {
|
|
360
|
-
areAnyDestinationsHidden: {wire: 'are_any_destinations_hidden'},
|
|
361
|
-
destinationSourceSecurable: {
|
|
362
|
-
wire: 'destination_source_securable',
|
|
363
|
-
children: () => securableFieldMaskSchema,
|
|
364
|
-
},
|
|
365
|
-
destinations: {wire: 'destinations'},
|
|
366
|
-
fullName: {wire: 'full_name'},
|
|
367
|
-
securable: {wire: 'securable', children: () => securableFieldMaskSchema},
|
|
368
|
-
securableType: {wire: 'securable_type'},
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
export function accessRequestDestinationsFieldMask(
|
|
372
|
-
...paths: string[]
|
|
373
|
-
): FieldMask<AccessRequestDestinations> {
|
|
374
|
-
return FieldMask.build<AccessRequestDestinations>(
|
|
375
|
-
paths,
|
|
376
|
-
accessRequestDestinationsFieldMaskSchema
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
const securableFieldMaskSchema: FieldMaskSchema = {
|
|
381
|
-
fullName: {wire: 'full_name'},
|
|
382
|
-
providerShare: {wire: 'provider_share'},
|
|
383
|
-
type: {wire: 'type'},
|
|
384
|
-
};
|
package/src/v1/transport.ts
DELETED
|
@@ -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
|
-
}
|