@databricks/sdk-repos 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/v1/client.d.ts +33 -0
- package/dist/v1/client.d.ts.map +1 -0
- package/dist/v1/client.js +195 -0
- package/dist/v1/client.js.map +1 -0
- package/dist/v1/index.d.ts +3 -0
- package/dist/v1/index.d.ts.map +1 -0
- package/dist/v1/index.js +3 -0
- package/dist/v1/index.js.map +1 -0
- package/dist/v1/model.d.ts +165 -0
- package/dist/v1/model.d.ts.map +1 -0
- package/dist/v1/model.js +132 -0
- package/dist/v1/model.js.map +1 -0
- package/dist/v1/transport.d.ts +5 -0
- package/dist/v1/transport.d.ts.map +1 -0
- package/dist/v1/transport.js +57 -0
- package/dist/v1/transport.js.map +1 -0
- package/dist/v1/utils.d.ts +21 -0
- package/dist/v1/utils.d.ts.map +1 -0
- package/dist/v1/utils.js +113 -0
- package/dist/v1/utils.js.map +1 -0
- package/package.json +38 -4
- package/src/v1/client.ts +256 -0
- package/src/v1/index.ts +19 -0
- package/src/v1/model.ts +316 -0
- package/src/v1/transport.ts +73 -0
- package/src/v1/utils.ts +156 -0
- package/README.md +0 -1
- package/index.js +0 -1
package/src/v1/index.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
export {ReposClient} from './client';
|
|
4
|
+
|
|
5
|
+
export type {
|
|
6
|
+
CreateRepoRequest,
|
|
7
|
+
CreateRepoRequest_Response,
|
|
8
|
+
DeleteProjectRequest,
|
|
9
|
+
DeleteProjectRequest_Response,
|
|
10
|
+
GetRepoRequest,
|
|
11
|
+
GetRepoRequest_Response,
|
|
12
|
+
ListReposRequest,
|
|
13
|
+
ListReposRequest_Response,
|
|
14
|
+
RepoInfo,
|
|
15
|
+
SparseCheckout,
|
|
16
|
+
SparseCheckoutUpdate,
|
|
17
|
+
UpdateRepoRequest,
|
|
18
|
+
UpdateRepoRequest_Response,
|
|
19
|
+
} from './model';
|
package/src/v1/model.ts
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
// Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
|
|
2
|
+
|
|
3
|
+
import {z} from 'zod';
|
|
4
|
+
|
|
5
|
+
export interface CreateRepoRequest {
|
|
6
|
+
/** URL of the Git repository to be linked. */
|
|
7
|
+
url?: string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Git provider. This field is case-insensitive. The available Git providers are `gitHub`,
|
|
10
|
+
* `bitbucketCloud`, `gitLab`, `azureDevOpsServices` (Azure DevOps Services, including
|
|
11
|
+
* Microsoft Entra ID authentication), `gitHubEnterprise`, `bitbucketServer` (Bitbucket
|
|
12
|
+
* Data Center), `gitLabEnterpriseEdition` (GitLab Self-Managed), and `awsCodeCommit`
|
|
13
|
+
* (deprecated by AWS, not accepting new customers).
|
|
14
|
+
*/
|
|
15
|
+
provider?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Desired path for the repo in the workspace. Almost any path in the workspace can be chosen.
|
|
18
|
+
* If repo is created in `/Repos`, path must be in the format `/Repos/{folder}/{repo-name}`.
|
|
19
|
+
*/
|
|
20
|
+
path?: string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* If specified, the repo will be created with sparse checkout enabled. You cannot enable/disable
|
|
23
|
+
* sparse checkout after the repo is created.
|
|
24
|
+
*/
|
|
25
|
+
sparseCheckout?: SparseCheckout | undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
29
|
+
export interface CreateRepoRequest_Response {
|
|
30
|
+
/** ID of the Git folder (repo) object in the workspace. */
|
|
31
|
+
id?: bigint | undefined;
|
|
32
|
+
/** Path of the Git folder (repo) in the workspace. */
|
|
33
|
+
path?: string | undefined;
|
|
34
|
+
/** URL of the linked Git repository. */
|
|
35
|
+
url?: string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Git provider of the linked Git repository, e.g. `gitHub`, `azureDevOpsServices`,
|
|
38
|
+
* `bitbucketServer` (Bitbucket Data Center), `gitLabEnterpriseEdition` (GitLab
|
|
39
|
+
* Self-Managed), or `awsCodeCommit` (deprecated).
|
|
40
|
+
*/
|
|
41
|
+
provider?: string | undefined;
|
|
42
|
+
/** Branch that the Git folder (repo) is checked out to. */
|
|
43
|
+
branch?: string | undefined;
|
|
44
|
+
/** SHA-1 hash representing the commit ID of the current HEAD of the Git folder (repo). */
|
|
45
|
+
headCommitId?: string | undefined;
|
|
46
|
+
/** Sparse checkout settings for the Git folder (repo). */
|
|
47
|
+
sparseCheckout?: SparseCheckout | undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface DeleteProjectRequest {
|
|
51
|
+
/** The ID for the corresponding repo to delete. */
|
|
52
|
+
id?: bigint | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type -- Proto-style nested message name.
|
|
56
|
+
export interface DeleteProjectRequest_Response {}
|
|
57
|
+
|
|
58
|
+
export interface GetRepoRequest {
|
|
59
|
+
/** ID of the Git folder (repo) object in the workspace. */
|
|
60
|
+
id?: bigint | undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
64
|
+
export interface GetRepoRequest_Response {
|
|
65
|
+
/** ID of the Git folder (repo) object in the workspace. */
|
|
66
|
+
id?: bigint | undefined;
|
|
67
|
+
/** Path of the Git folder (repo) in the workspace. */
|
|
68
|
+
path?: string | undefined;
|
|
69
|
+
/** URL of the linked Git repository. */
|
|
70
|
+
url?: string | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Git provider of the linked Git repository, e.g. `gitHub`, `azureDevOpsServices`,
|
|
73
|
+
* `bitbucketServer` (Bitbucket Data Center), `gitLabEnterpriseEdition` (GitLab
|
|
74
|
+
* Self-Managed), or `awsCodeCommit` (deprecated).
|
|
75
|
+
*/
|
|
76
|
+
provider?: string | undefined;
|
|
77
|
+
/** Branch that the local version of the repo is checked out to. */
|
|
78
|
+
branch?: string | undefined;
|
|
79
|
+
/** SHA-1 hash representing the commit ID of the current HEAD of the repo. */
|
|
80
|
+
headCommitId?: string | undefined;
|
|
81
|
+
/** Sparse checkout settings for the Git folder (repo). */
|
|
82
|
+
sparseCheckout?: SparseCheckout | undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface ListReposRequest {
|
|
86
|
+
/**
|
|
87
|
+
* Filters repos that have paths starting with the given path prefix.
|
|
88
|
+
* If not provided or when provided an effectively empty prefix (`/` or `/Workspace`)
|
|
89
|
+
* Git folders (repos) from `/Workspace/Repos` will be served.
|
|
90
|
+
*/
|
|
91
|
+
pathPrefix?: string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Token used to get the next page of results. If not specified, returns the first page of
|
|
94
|
+
* results as well as a next page token if there are more results.
|
|
95
|
+
*/
|
|
96
|
+
nextPageToken?: string | undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
100
|
+
export interface ListReposRequest_Response {
|
|
101
|
+
/** List of Git folders (repos). */
|
|
102
|
+
repos?: RepoInfo[] | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Token that can be specified as a query parameter to the `GET /repos` endpoint to retrieve
|
|
105
|
+
* the next page of results.
|
|
106
|
+
*/
|
|
107
|
+
nextPageToken?: string | undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Git folder (repo) information. */
|
|
111
|
+
export interface RepoInfo {
|
|
112
|
+
/** Id of the git folder (repo) in the Workspace. */
|
|
113
|
+
id?: bigint | undefined;
|
|
114
|
+
/** Root path of the git folder (repo) in the Workspace. */
|
|
115
|
+
path?: string | undefined;
|
|
116
|
+
/** URL of the remote git repository. */
|
|
117
|
+
url?: string | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Git provider of the remote git repository, e.g. `gitHub`, `azureDevOpsServices`,
|
|
120
|
+
* `bitbucketServer` (Bitbucket Data Center), `gitLabEnterpriseEdition` (GitLab
|
|
121
|
+
* Self-Managed), or `awsCodeCommit` (deprecated).
|
|
122
|
+
*/
|
|
123
|
+
provider?: string | undefined;
|
|
124
|
+
/** Name of the current git branch of the git folder (repo). */
|
|
125
|
+
branch?: string | undefined;
|
|
126
|
+
/** Current git commit id of the git folder (repo). */
|
|
127
|
+
headCommitId?: string | undefined;
|
|
128
|
+
/** Sparse checkout config for the git folder (repo). */
|
|
129
|
+
sparseCheckout?: SparseCheckout | undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Sparse checkout configuration, it contains options like cone patterns. */
|
|
133
|
+
export interface SparseCheckout {
|
|
134
|
+
/**
|
|
135
|
+
* List of sparse checkout cone patterns, see
|
|
136
|
+
* [cone mode handling](https://git-scm.com/docs/git-sparse-checkout#_internalscone_mode_handling)
|
|
137
|
+
* for details.
|
|
138
|
+
*/
|
|
139
|
+
patterns?: string[] | undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Sparse checkout configuration, it contains options like cone patterns. */
|
|
143
|
+
export interface SparseCheckoutUpdate {
|
|
144
|
+
/**
|
|
145
|
+
* List of sparse checkout cone patterns, see
|
|
146
|
+
* [cone mode handling](https://git-scm.com/docs/git-sparse-checkout#_internalscone_mode_handling)
|
|
147
|
+
* for details.
|
|
148
|
+
*/
|
|
149
|
+
patterns?: string[] | undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface UpdateRepoRequest {
|
|
153
|
+
/** ID of the Git folder (repo) object in the workspace. */
|
|
154
|
+
id?: bigint | undefined;
|
|
155
|
+
/** Branch that the local version of the repo is checked out to. */
|
|
156
|
+
branch?: string | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* Tag that the local version of the repo is checked out to. Updating the repo to a tag puts
|
|
159
|
+
* the repo in a detached HEAD state. Before committing new changes, you must update the repo to
|
|
160
|
+
* a branch instead of the detached HEAD.
|
|
161
|
+
*/
|
|
162
|
+
tag?: string | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* If specified, update the sparse checkout settings. The update will fail if sparse checkout is
|
|
165
|
+
* not enabled for the repo.
|
|
166
|
+
*/
|
|
167
|
+
sparseCheckout?: SparseCheckoutUpdate | undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type -- Proto-style nested message name.
|
|
171
|
+
export interface UpdateRepoRequest_Response {}
|
|
172
|
+
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
174
|
+
export const unmarshalCreateRepoRequest_ResponseSchema: z.ZodType<CreateRepoRequest_Response> =
|
|
175
|
+
z
|
|
176
|
+
.object({
|
|
177
|
+
id: z
|
|
178
|
+
.union([z.number(), z.bigint()])
|
|
179
|
+
.transform(v => BigInt(v))
|
|
180
|
+
.optional(),
|
|
181
|
+
path: z.string().optional(),
|
|
182
|
+
url: z.string().optional(),
|
|
183
|
+
provider: z.string().optional(),
|
|
184
|
+
branch: z.string().optional(),
|
|
185
|
+
head_commit_id: z.string().optional(),
|
|
186
|
+
sparse_checkout: z.lazy(() => unmarshalSparseCheckoutSchema).optional(),
|
|
187
|
+
})
|
|
188
|
+
.transform(d => ({
|
|
189
|
+
id: d.id,
|
|
190
|
+
path: d.path,
|
|
191
|
+
url: d.url,
|
|
192
|
+
provider: d.provider,
|
|
193
|
+
branch: d.branch,
|
|
194
|
+
headCommitId: d.head_commit_id,
|
|
195
|
+
sparseCheckout: d.sparse_checkout,
|
|
196
|
+
}));
|
|
197
|
+
|
|
198
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
199
|
+
export const unmarshalDeleteProjectRequest_ResponseSchema: z.ZodType<DeleteProjectRequest_Response> =
|
|
200
|
+
z.object({});
|
|
201
|
+
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
203
|
+
export const unmarshalGetRepoRequest_ResponseSchema: z.ZodType<GetRepoRequest_Response> =
|
|
204
|
+
z
|
|
205
|
+
.object({
|
|
206
|
+
id: z
|
|
207
|
+
.union([z.number(), z.bigint()])
|
|
208
|
+
.transform(v => BigInt(v))
|
|
209
|
+
.optional(),
|
|
210
|
+
path: z.string().optional(),
|
|
211
|
+
url: z.string().optional(),
|
|
212
|
+
provider: z.string().optional(),
|
|
213
|
+
branch: z.string().optional(),
|
|
214
|
+
head_commit_id: z.string().optional(),
|
|
215
|
+
sparse_checkout: z.lazy(() => unmarshalSparseCheckoutSchema).optional(),
|
|
216
|
+
})
|
|
217
|
+
.transform(d => ({
|
|
218
|
+
id: d.id,
|
|
219
|
+
path: d.path,
|
|
220
|
+
url: d.url,
|
|
221
|
+
provider: d.provider,
|
|
222
|
+
branch: d.branch,
|
|
223
|
+
headCommitId: d.head_commit_id,
|
|
224
|
+
sparseCheckout: d.sparse_checkout,
|
|
225
|
+
}));
|
|
226
|
+
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
228
|
+
export const unmarshalListReposRequest_ResponseSchema: z.ZodType<ListReposRequest_Response> =
|
|
229
|
+
z
|
|
230
|
+
.object({
|
|
231
|
+
repos: z.array(z.lazy(() => unmarshalRepoInfoSchema)).optional(),
|
|
232
|
+
next_page_token: z.string().optional(),
|
|
233
|
+
})
|
|
234
|
+
.transform(d => ({
|
|
235
|
+
repos: d.repos,
|
|
236
|
+
nextPageToken: d.next_page_token,
|
|
237
|
+
}));
|
|
238
|
+
|
|
239
|
+
export const unmarshalRepoInfoSchema: z.ZodType<RepoInfo> = z
|
|
240
|
+
.object({
|
|
241
|
+
id: z
|
|
242
|
+
.union([z.number(), z.bigint()])
|
|
243
|
+
.transform(v => BigInt(v))
|
|
244
|
+
.optional(),
|
|
245
|
+
path: z.string().optional(),
|
|
246
|
+
url: z.string().optional(),
|
|
247
|
+
provider: z.string().optional(),
|
|
248
|
+
branch: z.string().optional(),
|
|
249
|
+
head_commit_id: z.string().optional(),
|
|
250
|
+
sparse_checkout: z.lazy(() => unmarshalSparseCheckoutSchema).optional(),
|
|
251
|
+
})
|
|
252
|
+
.transform(d => ({
|
|
253
|
+
id: d.id,
|
|
254
|
+
path: d.path,
|
|
255
|
+
url: d.url,
|
|
256
|
+
provider: d.provider,
|
|
257
|
+
branch: d.branch,
|
|
258
|
+
headCommitId: d.head_commit_id,
|
|
259
|
+
sparseCheckout: d.sparse_checkout,
|
|
260
|
+
}));
|
|
261
|
+
|
|
262
|
+
export const unmarshalSparseCheckoutSchema: z.ZodType<SparseCheckout> = z
|
|
263
|
+
.object({
|
|
264
|
+
patterns: z.array(z.string()).optional(),
|
|
265
|
+
})
|
|
266
|
+
.transform(d => ({
|
|
267
|
+
patterns: d.patterns,
|
|
268
|
+
}));
|
|
269
|
+
|
|
270
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
|
|
271
|
+
export const unmarshalUpdateRepoRequest_ResponseSchema: z.ZodType<UpdateRepoRequest_Response> =
|
|
272
|
+
z.object({});
|
|
273
|
+
|
|
274
|
+
export const marshalCreateRepoRequestSchema: z.ZodType = z
|
|
275
|
+
.object({
|
|
276
|
+
url: z.string().optional(),
|
|
277
|
+
provider: z.string().optional(),
|
|
278
|
+
path: z.string().optional(),
|
|
279
|
+
sparseCheckout: z.lazy(() => marshalSparseCheckoutSchema).optional(),
|
|
280
|
+
})
|
|
281
|
+
.transform(d => ({
|
|
282
|
+
url: d.url,
|
|
283
|
+
provider: d.provider,
|
|
284
|
+
path: d.path,
|
|
285
|
+
sparse_checkout: d.sparseCheckout,
|
|
286
|
+
}));
|
|
287
|
+
|
|
288
|
+
export const marshalSparseCheckoutSchema: z.ZodType = z
|
|
289
|
+
.object({
|
|
290
|
+
patterns: z.array(z.string()).optional(),
|
|
291
|
+
})
|
|
292
|
+
.transform(d => ({
|
|
293
|
+
patterns: d.patterns,
|
|
294
|
+
}));
|
|
295
|
+
|
|
296
|
+
export const marshalSparseCheckoutUpdateSchema: z.ZodType = z
|
|
297
|
+
.object({
|
|
298
|
+
patterns: z.array(z.string()).optional(),
|
|
299
|
+
})
|
|
300
|
+
.transform(d => ({
|
|
301
|
+
patterns: d.patterns,
|
|
302
|
+
}));
|
|
303
|
+
|
|
304
|
+
export const marshalUpdateRepoRequestSchema: z.ZodType = z
|
|
305
|
+
.object({
|
|
306
|
+
id: z.bigint().optional(),
|
|
307
|
+
branch: z.string().optional(),
|
|
308
|
+
tag: z.string().optional(),
|
|
309
|
+
sparseCheckout: z.lazy(() => marshalSparseCheckoutUpdateSchema).optional(),
|
|
310
|
+
})
|
|
311
|
+
.transform(d => ({
|
|
312
|
+
id: d.id,
|
|
313
|
+
branch: d.branch,
|
|
314
|
+
tag: d.tag,
|
|
315
|
+
sparse_checkout: d.sparseCheckout,
|
|
316
|
+
}));
|
|
@@ -0,0 +1,73 @@
|
|
|
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
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 = {};
|