@databricks/sdk-uc-registeredmodels 0.34.0 → 0.36.0

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/dist/v1/client.js CHANGED
@@ -1,528 +1,421 @@
1
- // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
- import { VERSION as AUTH_VERSION } from '@databricks/sdk-auth';
3
- import { createDefault } from '@databricks/sdk-core/clientinfo';
4
- import { NoOpLogger } from '@databricks/sdk-core/logger';
5
- import { resolveClientConfig } from './transport';
6
- import { buildHttpRequest, executeCall, executeHttpCall, marshalRequest, parseResponse, } from './utils';
7
- import pkgJson from '../../package.json' with { type: 'json' };
8
- import { marshalCreateRegisteredModelRequestSchema, marshalSetRegisteredModelAliasRequestSchema, marshalUpdateModelVersionRequestSchema, marshalUpdateRegisteredModelRequestSchema, unmarshalDeleteModelVersionResponseSchema, unmarshalDeleteRegisteredModelAliasResponseSchema, unmarshalDeleteRegisteredModelResponseSchema, unmarshalListModelVersionsResponseSchema, unmarshalListRegisteredModelsResponseSchema, unmarshalModelVersionInfoSchema, unmarshalRegisteredModelAliasInfoSchema, unmarshalRegisteredModelInfoSchema, } from './model';
9
- // Package identity segment for this client to be used in the User-Agent header.
1
+ import { resolveClientConfig } from "./transport.js";
2
+ import { buildHttpRequest, executeCall, executeHttpCall, marshalRequest, parseResponse } from "./utils.js";
3
+ import { name, version } from "../package.js";
4
+ import { marshalCreateRegisteredModelRequestSchema, marshalSetRegisteredModelAliasRequestSchema, marshalUpdateModelVersionRequestSchema, marshalUpdateRegisteredModelRequestSchema, unmarshalDeleteModelVersionResponseSchema, unmarshalDeleteRegisteredModelAliasResponseSchema, unmarshalDeleteRegisteredModelResponseSchema, unmarshalListModelVersionsResponseSchema, unmarshalListRegisteredModelsResponseSchema, unmarshalModelVersionInfoSchema, unmarshalRegisteredModelAliasInfoSchema, unmarshalRegisteredModelInfoSchema } from "./model.js";
5
+ import { VERSION } from "@databricks/sdk-auth";
6
+ import { createDefault } from "@databricks/sdk-core/clientinfo";
7
+ import { NoOpLogger } from "@databricks/sdk-core/logger";
8
+
9
+ //#region src/v1/client.ts
10
10
  const PACKAGE_SEGMENT = {
11
- key: 'sdk-js-' + pkgJson.name.replace(/^@[^/]+\/sdk-/, ''),
12
- value: pkgJson.version,
11
+ key: "sdk-js-" + name.replace(/^@[^/]+\/sdk-/, ""),
12
+ value: version
13
13
  };
14
- export class RegisteredModelsClient {
15
- options;
16
- logger;
17
- // User-Agent header value. Composed once at construction from
18
- // createDefault() merged with this package's identity and the active
19
- // credential's name.
20
- userAgent;
21
- // Memoized configuration. The profile is resolved once, lazily, on the first
22
- // request, then reused; host, workspaceId/accountId, and credentials are
23
- // filled from it when not set explicitly on the options.
24
- config;
25
- constructor(options) {
26
- this.options = options;
27
- this.logger = options.logger ?? new NoOpLogger();
28
- const info = createDefault()
29
- .with(PACKAGE_SEGMENT)
30
- .with({ key: 'sdk-js-auth', value: AUTH_VERSION })
31
- .with({ key: 'auth', value: options.credentials?.name() ?? 'default' });
32
- this.userAgent = info.toString();
33
- }
34
- resolveConfig() {
35
- this.config ??= resolveClientConfig(this.options);
36
- return this.config;
37
- }
38
- /**
39
- * Creates a new registered model in Unity Catalog.
40
- *
41
- * File storage for model versions in the registered model
42
- * will be located in the default location which is specified by the parent schema,
43
- * or the parent catalog, or the Metastore.
44
- *
45
- * For registered model creation to succeed, the user must satisfy the following conditions:
46
- * - The caller must be a metastore admin, or be the owner of the parent catalog and schema,
47
- * or have the **USE_CATALOG** privilege on the parent catalog
48
- * and the **USE_SCHEMA** privilege on the parent schema.
49
- * - The caller must have the **CREATE MODEL** or **CREATE FUNCTION** privilege on the parent schema.
50
- */
51
- async createRegisteredModel(req, options) {
52
- const { host, workspaceId, httpClient } = await this.resolveConfig();
53
- const url = `${host}/api/2.1/unity-catalog/models`;
54
- const body = marshalRequest(req, marshalCreateRegisteredModelRequestSchema);
55
- let resp;
56
- const call = async (callSignal) => {
57
- const headers = new Headers({ 'Content-Type': 'application/json' });
58
- if (workspaceId !== undefined) {
59
- headers.set('X-Databricks-Workspace-Id', workspaceId);
60
- }
61
- headers.set('User-Agent', this.userAgent);
62
- const httpReq = buildHttpRequest('POST', url, headers, callSignal, body);
63
- const respBody = await executeHttpCall({
64
- request: httpReq,
65
- httpClient,
66
- logger: this.logger,
67
- });
68
- resp = parseResponse(respBody, unmarshalRegisteredModelInfoSchema);
69
- };
70
- await executeCall(call, options);
71
- if (resp === undefined) {
72
- throw new Error('operation completed without a result.');
73
- }
74
- return resp;
75
- }
76
- /**
77
- * Deletes a model version from the specified registered model. Any aliases assigned to the
78
- * model version will also be deleted.
79
- *
80
- * The caller must be a metastore admin or an owner of the parent registered model.
81
- * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
82
- * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
83
- */
84
- async deleteModelVersion(req, options) {
85
- const { host, workspaceId, httpClient } = await this.resolveConfig();
86
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}/versions/${String(req.versionArg ?? '')}`;
87
- let resp;
88
- const call = async (callSignal) => {
89
- const headers = new Headers();
90
- if (workspaceId !== undefined) {
91
- headers.set('X-Databricks-Workspace-Id', workspaceId);
92
- }
93
- headers.set('User-Agent', this.userAgent);
94
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
95
- const respBody = await executeHttpCall({
96
- request: httpReq,
97
- httpClient,
98
- logger: this.logger,
99
- });
100
- resp = parseResponse(respBody, unmarshalDeleteModelVersionResponseSchema);
101
- };
102
- await executeCall(call, options);
103
- if (resp === undefined) {
104
- throw new Error('operation completed without a result.');
105
- }
106
- return resp;
107
- }
108
- /**
109
- * Deletes a registered model and all its model versions from the specified parent catalog and schema.
110
- *
111
- * The caller must be a metastore admin or an owner of the registered model.
112
- * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
113
- * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
114
- */
115
- async deleteRegisteredModel(req, options) {
116
- const { host, workspaceId, httpClient } = await this.resolveConfig();
117
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}`;
118
- let resp;
119
- const call = async (callSignal) => {
120
- const headers = new Headers();
121
- if (workspaceId !== undefined) {
122
- headers.set('X-Databricks-Workspace-Id', workspaceId);
123
- }
124
- headers.set('User-Agent', this.userAgent);
125
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
126
- const respBody = await executeHttpCall({
127
- request: httpReq,
128
- httpClient,
129
- logger: this.logger,
130
- });
131
- resp = parseResponse(respBody, unmarshalDeleteRegisteredModelResponseSchema);
132
- };
133
- await executeCall(call, options);
134
- if (resp === undefined) {
135
- throw new Error('operation completed without a result.');
136
- }
137
- return resp;
138
- }
139
- /**
140
- * Deletes a registered model alias.
141
- *
142
- * The caller must be a metastore admin or an owner of the registered model.
143
- * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
144
- * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
145
- */
146
- async deleteRegisteredModelAlias(req, options) {
147
- const { host, workspaceId, httpClient } = await this.resolveConfig();
148
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}/aliases/${req.aliasArg ?? ''}`;
149
- let resp;
150
- const call = async (callSignal) => {
151
- const headers = new Headers();
152
- if (workspaceId !== undefined) {
153
- headers.set('X-Databricks-Workspace-Id', workspaceId);
154
- }
155
- headers.set('User-Agent', this.userAgent);
156
- const httpReq = buildHttpRequest('DELETE', url, headers, callSignal);
157
- const respBody = await executeHttpCall({
158
- request: httpReq,
159
- httpClient,
160
- logger: this.logger,
161
- });
162
- resp = parseResponse(respBody, unmarshalDeleteRegisteredModelAliasResponseSchema);
163
- };
164
- await executeCall(call, options);
165
- if (resp === undefined) {
166
- throw new Error('operation completed without a result.');
167
- }
168
- return resp;
169
- }
170
- /**
171
- * Get a model version.
172
- *
173
- * The caller must be a metastore admin or an owner of (or have the **EXECUTE**
174
- * privilege on) the parent registered model. For the latter case, the caller must also be the owner
175
- * or have the **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** privilege
176
- * on the parent schema.
177
- */
178
- async getModelVersion(req, options) {
179
- const { host, workspaceId, httpClient } = await this.resolveConfig();
180
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}/versions/${String(req.versionArg ?? '')}`;
181
- const params = new URLSearchParams();
182
- if (req.includeAliases !== undefined) {
183
- params.append('include_aliases', String(req.includeAliases));
184
- }
185
- if (req.includeBrowse !== undefined) {
186
- params.append('include_browse', String(req.includeBrowse));
187
- }
188
- const query = params.toString();
189
- const fullUrl = query !== '' ? `${url}?${query}` : url;
190
- let resp;
191
- const call = async (callSignal) => {
192
- const headers = new Headers();
193
- if (workspaceId !== undefined) {
194
- headers.set('X-Databricks-Workspace-Id', workspaceId);
195
- }
196
- headers.set('User-Agent', this.userAgent);
197
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
198
- const respBody = await executeHttpCall({
199
- request: httpReq,
200
- httpClient,
201
- logger: this.logger,
202
- });
203
- resp = parseResponse(respBody, unmarshalModelVersionInfoSchema);
204
- };
205
- await executeCall(call, options);
206
- if (resp === undefined) {
207
- throw new Error('operation completed without a result.');
208
- }
209
- return resp;
210
- }
211
- /**
212
- * Get a model version by alias.
213
- *
214
- * The caller must be a metastore admin or an owner of (or have the **EXECUTE**
215
- * privilege on) the registered model. For the latter case, the caller must also be the owner
216
- * or have the **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** privilege
217
- * on the parent schema.
218
- */
219
- async getModelVersionByAlias(req, options) {
220
- const { host, workspaceId, httpClient } = await this.resolveConfig();
221
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}/aliases/${req.aliasArg ?? ''}`;
222
- const params = new URLSearchParams();
223
- if (req.includeAliases !== undefined) {
224
- params.append('include_aliases', String(req.includeAliases));
225
- }
226
- const query = params.toString();
227
- const fullUrl = query !== '' ? `${url}?${query}` : url;
228
- let resp;
229
- const call = async (callSignal) => {
230
- const headers = new Headers();
231
- if (workspaceId !== undefined) {
232
- headers.set('X-Databricks-Workspace-Id', workspaceId);
233
- }
234
- headers.set('User-Agent', this.userAgent);
235
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
236
- const respBody = await executeHttpCall({
237
- request: httpReq,
238
- httpClient,
239
- logger: this.logger,
240
- });
241
- resp = parseResponse(respBody, unmarshalModelVersionInfoSchema);
242
- };
243
- await executeCall(call, options);
244
- if (resp === undefined) {
245
- throw new Error('operation completed without a result.');
246
- }
247
- return resp;
248
- }
249
- /**
250
- * Get a registered model.
251
- *
252
- * The caller must be a metastore admin or an owner of (or have the **EXECUTE**
253
- * privilege on) the registered model. For the latter case, the caller must also be the owner
254
- * or have the **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** privilege
255
- * on the parent schema.
256
- */
257
- async getRegisteredModel(req, options) {
258
- const { host, workspaceId, httpClient } = await this.resolveConfig();
259
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}`;
260
- const params = new URLSearchParams();
261
- if (req.includeAliases !== undefined) {
262
- params.append('include_aliases', String(req.includeAliases));
263
- }
264
- if (req.includeBrowse !== undefined) {
265
- params.append('include_browse', String(req.includeBrowse));
266
- }
267
- const query = params.toString();
268
- const fullUrl = query !== '' ? `${url}?${query}` : url;
269
- let resp;
270
- const call = async (callSignal) => {
271
- const headers = new Headers();
272
- if (workspaceId !== undefined) {
273
- headers.set('X-Databricks-Workspace-Id', workspaceId);
274
- }
275
- headers.set('User-Agent', this.userAgent);
276
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
277
- const respBody = await executeHttpCall({
278
- request: httpReq,
279
- httpClient,
280
- logger: this.logger,
281
- });
282
- resp = parseResponse(respBody, unmarshalRegisteredModelInfoSchema);
283
- };
284
- await executeCall(call, options);
285
- if (resp === undefined) {
286
- throw new Error('operation completed without a result.');
287
- }
288
- return resp;
289
- }
290
- /**
291
- * List model versions. You can list model versions under a particular schema,
292
- * or list all model versions in the current metastore.
293
- *
294
- * The returned models are filtered based on the privileges of the calling user.
295
- * For example, the metastore admin is able to list all the model versions.
296
- * A regular user needs to be the owner or have the **EXECUTE** privilege
297
- * on the parent registered model to receive the model versions in the response.
298
- * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
299
- * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
300
- *
301
- * There is no guarantee of a specific ordering of the elements in the response. The
302
- * elements in the response will not contain any aliases or tags.
303
- *
304
- * PAGINATION BEHAVIOR: The API is by default paginated, a page may contain zero results while still providing a next_page_token.
305
- * Clients must continue reading pages until next_page_token is absent, which is the only indication that the end of results has been reached.
306
- */
307
- async listModelVersions(req, options) {
308
- const { host, workspaceId, httpClient } = await this.resolveConfig();
309
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}/versions`;
310
- const params = new URLSearchParams();
311
- if (req.maxResults !== undefined) {
312
- params.append('max_results', String(req.maxResults));
313
- }
314
- if (req.pageToken !== undefined) {
315
- params.append('page_token', req.pageToken);
316
- }
317
- if (req.includeBrowse !== undefined) {
318
- params.append('include_browse', String(req.includeBrowse));
319
- }
320
- const query = params.toString();
321
- const fullUrl = query !== '' ? `${url}?${query}` : url;
322
- let resp;
323
- const call = async (callSignal) => {
324
- const headers = new Headers();
325
- if (workspaceId !== undefined) {
326
- headers.set('X-Databricks-Workspace-Id', workspaceId);
327
- }
328
- headers.set('User-Agent', this.userAgent);
329
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
330
- const respBody = await executeHttpCall({
331
- request: httpReq,
332
- httpClient,
333
- logger: this.logger,
334
- });
335
- resp = parseResponse(respBody, unmarshalListModelVersionsResponseSchema);
336
- };
337
- await executeCall(call, options);
338
- if (resp === undefined) {
339
- throw new Error('operation completed without a result.');
340
- }
341
- return resp;
342
- }
343
- async *listModelVersionsIter(req, options) {
344
- const pageReq = { ...req };
345
- for (;;) {
346
- const resp = await this.listModelVersions(pageReq, options);
347
- for (const item of resp.modelVersions ?? []) {
348
- yield item;
349
- }
350
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
351
- return;
352
- }
353
- pageReq.pageToken = resp.nextPageToken;
354
- }
355
- }
356
- /**
357
- * List registered models. You can list registered models under a particular schema,
358
- * or list all registered models in the current metastore.
359
- *
360
- * The returned models are filtered based on the privileges of the calling user.
361
- * For example, the metastore admin is able to list all the registered models.
362
- * A regular user needs to be the owner or have the **EXECUTE** privilege
363
- * on the registered model to receive the registered models in the response.
364
- * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
365
- * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
366
- *
367
- * There is no guarantee of a specific ordering of the elements in the response.
368
- *
369
- * PAGINATION BEHAVIOR: The API is by default paginated, a page may contain zero results while still providing a next_page_token.
370
- * Clients must continue reading pages until next_page_token is absent, which is the only indication that the end of results has been reached.
371
- */
372
- async listRegisteredModels(req, options) {
373
- const { host, workspaceId, httpClient } = await this.resolveConfig();
374
- const url = `${host}/api/2.1/unity-catalog/models`;
375
- const params = new URLSearchParams();
376
- if (req.catalogName !== undefined) {
377
- params.append('catalog_name', req.catalogName);
378
- }
379
- if (req.schemaName !== undefined) {
380
- params.append('schema_name', req.schemaName);
381
- }
382
- if (req.includeBrowse !== undefined) {
383
- params.append('include_browse', String(req.includeBrowse));
384
- }
385
- if (req.maxResults !== undefined) {
386
- params.append('max_results', String(req.maxResults));
387
- }
388
- if (req.pageToken !== undefined) {
389
- params.append('page_token', req.pageToken);
390
- }
391
- const query = params.toString();
392
- const fullUrl = query !== '' ? `${url}?${query}` : url;
393
- let resp;
394
- const call = async (callSignal) => {
395
- const headers = new Headers();
396
- if (workspaceId !== undefined) {
397
- headers.set('X-Databricks-Workspace-Id', workspaceId);
398
- }
399
- headers.set('User-Agent', this.userAgent);
400
- const httpReq = buildHttpRequest('GET', fullUrl, headers, callSignal);
401
- const respBody = await executeHttpCall({
402
- request: httpReq,
403
- httpClient,
404
- logger: this.logger,
405
- });
406
- resp = parseResponse(respBody, unmarshalListRegisteredModelsResponseSchema);
407
- };
408
- await executeCall(call, options);
409
- if (resp === undefined) {
410
- throw new Error('operation completed without a result.');
411
- }
412
- return resp;
413
- }
414
- async *listRegisteredModelsIter(req, options) {
415
- const pageReq = { ...req };
416
- for (;;) {
417
- const resp = await this.listRegisteredModels(pageReq, options);
418
- for (const item of resp.registeredModels ?? []) {
419
- yield item;
420
- }
421
- if (resp.nextPageToken === undefined || resp.nextPageToken === '') {
422
- return;
423
- }
424
- pageReq.pageToken = resp.nextPageToken;
425
- }
426
- }
427
- /**
428
- * Set an alias on the specified registered model.
429
- *
430
- * The caller must be a metastore admin or an owner of the registered model.
431
- * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
432
- * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
433
- */
434
- async setRegisteredModelAlias(req, options) {
435
- const { host, workspaceId, httpClient } = await this.resolveConfig();
436
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}/aliases/${req.aliasArg ?? ''}`;
437
- const body = marshalRequest(req, marshalSetRegisteredModelAliasRequestSchema);
438
- let resp;
439
- const call = async (callSignal) => {
440
- const headers = new Headers({ 'Content-Type': 'application/json' });
441
- if (workspaceId !== undefined) {
442
- headers.set('X-Databricks-Workspace-Id', workspaceId);
443
- }
444
- headers.set('User-Agent', this.userAgent);
445
- const httpReq = buildHttpRequest('PUT', url, headers, callSignal, body);
446
- const respBody = await executeHttpCall({
447
- request: httpReq,
448
- httpClient,
449
- logger: this.logger,
450
- });
451
- resp = parseResponse(respBody, unmarshalRegisteredModelAliasInfoSchema);
452
- };
453
- await executeCall(call, options);
454
- if (resp === undefined) {
455
- throw new Error('operation completed without a result.');
456
- }
457
- return resp;
458
- }
459
- /**
460
- * Updates the specified model version.
461
- *
462
- * The caller must be a metastore admin or an owner of the parent registered model.
463
- * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
464
- * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
465
- *
466
- * Currently only the comment of the model version can be updated.
467
- */
468
- async updateModelVersion(req, options) {
469
- const { host, workspaceId, httpClient } = await this.resolveConfig();
470
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}/versions/${String(req.versionArg ?? '')}`;
471
- const body = marshalRequest(req, marshalUpdateModelVersionRequestSchema);
472
- let resp;
473
- const call = async (callSignal) => {
474
- const headers = new Headers({ 'Content-Type': 'application/json' });
475
- if (workspaceId !== undefined) {
476
- headers.set('X-Databricks-Workspace-Id', workspaceId);
477
- }
478
- headers.set('User-Agent', this.userAgent);
479
- const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
480
- const respBody = await executeHttpCall({
481
- request: httpReq,
482
- httpClient,
483
- logger: this.logger,
484
- });
485
- resp = parseResponse(respBody, unmarshalModelVersionInfoSchema);
486
- };
487
- await executeCall(call, options);
488
- if (resp === undefined) {
489
- throw new Error('operation completed without a result.');
490
- }
491
- return resp;
492
- }
493
- /**
494
- * Updates the specified registered model.
495
- *
496
- * The caller must be a metastore admin or an owner of the registered model.
497
- * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
498
- * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
499
- *
500
- * Currently only the name, the owner or the comment of the registered model can be updated.
501
- */
502
- async updateRegisteredModel(req, options) {
503
- const { host, workspaceId, httpClient } = await this.resolveConfig();
504
- const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ''}`;
505
- const body = marshalRequest(req, marshalUpdateRegisteredModelRequestSchema);
506
- let resp;
507
- const call = async (callSignal) => {
508
- const headers = new Headers({ 'Content-Type': 'application/json' });
509
- if (workspaceId !== undefined) {
510
- headers.set('X-Databricks-Workspace-Id', workspaceId);
511
- }
512
- headers.set('User-Agent', this.userAgent);
513
- const httpReq = buildHttpRequest('PATCH', url, headers, callSignal, body);
514
- const respBody = await executeHttpCall({
515
- request: httpReq,
516
- httpClient,
517
- logger: this.logger,
518
- });
519
- resp = parseResponse(respBody, unmarshalRegisteredModelInfoSchema);
520
- };
521
- await executeCall(call, options);
522
- if (resp === undefined) {
523
- throw new Error('operation completed without a result.');
524
- }
525
- return resp;
526
- }
527
- }
14
+ var RegisteredModelsClient = class {
15
+ options;
16
+ logger;
17
+ userAgent;
18
+ config;
19
+ constructor(options) {
20
+ this.options = options;
21
+ this.logger = options.logger ?? new NoOpLogger();
22
+ this.userAgent = createDefault().with(PACKAGE_SEGMENT).with({
23
+ key: "sdk-js-auth",
24
+ value: VERSION
25
+ }).with({
26
+ key: "auth",
27
+ value: options.credentials?.name() ?? "default"
28
+ }).toString();
29
+ }
30
+ resolveConfig() {
31
+ this.config ??= resolveClientConfig(this.options);
32
+ return this.config;
33
+ }
34
+ /**
35
+ * Creates a new registered model in Unity Catalog.
36
+ *
37
+ * File storage for model versions in the registered model
38
+ * will be located in the default location which is specified by the parent schema,
39
+ * or the parent catalog, or the Metastore.
40
+ *
41
+ * For registered model creation to succeed, the user must satisfy the following conditions:
42
+ * - The caller must be a metastore admin, or be the owner of the parent catalog and schema,
43
+ * or have the **USE_CATALOG** privilege on the parent catalog
44
+ * and the **USE_SCHEMA** privilege on the parent schema.
45
+ * - The caller must have the **CREATE MODEL** or **CREATE FUNCTION** privilege on the parent schema.
46
+ */
47
+ async createRegisteredModel(req, options) {
48
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
49
+ const url = `${host}/api/2.1/unity-catalog/models`;
50
+ const body = marshalRequest(req, marshalCreateRegisteredModelRequestSchema);
51
+ let resp;
52
+ const call = async (callSignal) => {
53
+ const headers = new Headers({ "Content-Type": "application/json" });
54
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
55
+ headers.set("User-Agent", this.userAgent);
56
+ resp = parseResponse(await executeHttpCall({
57
+ request: buildHttpRequest("POST", url, headers, callSignal, body),
58
+ httpClient,
59
+ logger: this.logger
60
+ }), unmarshalRegisteredModelInfoSchema);
61
+ };
62
+ await executeCall(call, options);
63
+ if (resp === void 0) throw new Error("operation completed without a result.");
64
+ return resp;
65
+ }
66
+ /**
67
+ * Deletes a model version from the specified registered model. Any aliases assigned to the
68
+ * model version will also be deleted.
69
+ *
70
+ * The caller must be a metastore admin or an owner of the parent registered model.
71
+ * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
72
+ * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
73
+ */
74
+ async deleteModelVersion(req, options) {
75
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
76
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}/versions/${String(req.versionArg ?? "")}`;
77
+ let resp;
78
+ const call = async (callSignal) => {
79
+ const headers = new Headers();
80
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
81
+ headers.set("User-Agent", this.userAgent);
82
+ resp = parseResponse(await executeHttpCall({
83
+ request: buildHttpRequest("DELETE", url, headers, callSignal),
84
+ httpClient,
85
+ logger: this.logger
86
+ }), unmarshalDeleteModelVersionResponseSchema);
87
+ };
88
+ await executeCall(call, options);
89
+ if (resp === void 0) throw new Error("operation completed without a result.");
90
+ return resp;
91
+ }
92
+ /**
93
+ * Deletes a registered model and all its model versions from the specified parent catalog and schema.
94
+ *
95
+ * The caller must be a metastore admin or an owner of the registered model.
96
+ * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
97
+ * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
98
+ */
99
+ async deleteRegisteredModel(req, options) {
100
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
101
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}`;
102
+ let resp;
103
+ const call = async (callSignal) => {
104
+ const headers = new Headers();
105
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
106
+ headers.set("User-Agent", this.userAgent);
107
+ resp = parseResponse(await executeHttpCall({
108
+ request: buildHttpRequest("DELETE", url, headers, callSignal),
109
+ httpClient,
110
+ logger: this.logger
111
+ }), unmarshalDeleteRegisteredModelResponseSchema);
112
+ };
113
+ await executeCall(call, options);
114
+ if (resp === void 0) throw new Error("operation completed without a result.");
115
+ return resp;
116
+ }
117
+ /**
118
+ * Deletes a registered model alias.
119
+ *
120
+ * The caller must be a metastore admin or an owner of the registered model.
121
+ * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
122
+ * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
123
+ */
124
+ async deleteRegisteredModelAlias(req, options) {
125
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
126
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}/aliases/${req.aliasArg ?? ""}`;
127
+ let resp;
128
+ const call = async (callSignal) => {
129
+ const headers = new Headers();
130
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
131
+ headers.set("User-Agent", this.userAgent);
132
+ resp = parseResponse(await executeHttpCall({
133
+ request: buildHttpRequest("DELETE", url, headers, callSignal),
134
+ httpClient,
135
+ logger: this.logger
136
+ }), unmarshalDeleteRegisteredModelAliasResponseSchema);
137
+ };
138
+ await executeCall(call, options);
139
+ if (resp === void 0) throw new Error("operation completed without a result.");
140
+ return resp;
141
+ }
142
+ /**
143
+ * Get a model version.
144
+ *
145
+ * The caller must be a metastore admin or an owner of (or have the **EXECUTE**
146
+ * privilege on) the parent registered model. For the latter case, the caller must also be the owner
147
+ * or have the **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** privilege
148
+ * on the parent schema.
149
+ */
150
+ async getModelVersion(req, options) {
151
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
152
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}/versions/${String(req.versionArg ?? "")}`;
153
+ const params = new URLSearchParams();
154
+ if (req.includeAliases !== void 0) params.append("include_aliases", String(req.includeAliases));
155
+ if (req.includeBrowse !== void 0) params.append("include_browse", String(req.includeBrowse));
156
+ const query = params.toString();
157
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
158
+ let resp;
159
+ const call = async (callSignal) => {
160
+ const headers = new Headers();
161
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
162
+ headers.set("User-Agent", this.userAgent);
163
+ resp = parseResponse(await executeHttpCall({
164
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
165
+ httpClient,
166
+ logger: this.logger
167
+ }), unmarshalModelVersionInfoSchema);
168
+ };
169
+ await executeCall(call, options);
170
+ if (resp === void 0) throw new Error("operation completed without a result.");
171
+ return resp;
172
+ }
173
+ /**
174
+ * Get a model version by alias.
175
+ *
176
+ * The caller must be a metastore admin or an owner of (or have the **EXECUTE**
177
+ * privilege on) the registered model. For the latter case, the caller must also be the owner
178
+ * or have the **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** privilege
179
+ * on the parent schema.
180
+ */
181
+ async getModelVersionByAlias(req, options) {
182
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
183
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}/aliases/${req.aliasArg ?? ""}`;
184
+ const params = new URLSearchParams();
185
+ if (req.includeAliases !== void 0) params.append("include_aliases", String(req.includeAliases));
186
+ const query = params.toString();
187
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
188
+ let resp;
189
+ const call = async (callSignal) => {
190
+ const headers = new Headers();
191
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
192
+ headers.set("User-Agent", this.userAgent);
193
+ resp = parseResponse(await executeHttpCall({
194
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
195
+ httpClient,
196
+ logger: this.logger
197
+ }), unmarshalModelVersionInfoSchema);
198
+ };
199
+ await executeCall(call, options);
200
+ if (resp === void 0) throw new Error("operation completed without a result.");
201
+ return resp;
202
+ }
203
+ /**
204
+ * Get a registered model.
205
+ *
206
+ * The caller must be a metastore admin or an owner of (or have the **EXECUTE**
207
+ * privilege on) the registered model. For the latter case, the caller must also be the owner
208
+ * or have the **USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA** privilege
209
+ * on the parent schema.
210
+ */
211
+ async getRegisteredModel(req, options) {
212
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
213
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}`;
214
+ const params = new URLSearchParams();
215
+ if (req.includeAliases !== void 0) params.append("include_aliases", String(req.includeAliases));
216
+ if (req.includeBrowse !== void 0) params.append("include_browse", String(req.includeBrowse));
217
+ const query = params.toString();
218
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
219
+ let resp;
220
+ const call = async (callSignal) => {
221
+ const headers = new Headers();
222
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
223
+ headers.set("User-Agent", this.userAgent);
224
+ resp = parseResponse(await executeHttpCall({
225
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
226
+ httpClient,
227
+ logger: this.logger
228
+ }), unmarshalRegisteredModelInfoSchema);
229
+ };
230
+ await executeCall(call, options);
231
+ if (resp === void 0) throw new Error("operation completed without a result.");
232
+ return resp;
233
+ }
234
+ /**
235
+ * List model versions. You can list model versions under a particular schema,
236
+ * or list all model versions in the current metastore.
237
+ *
238
+ * The returned models are filtered based on the privileges of the calling user.
239
+ * For example, the metastore admin is able to list all the model versions.
240
+ * A regular user needs to be the owner or have the **EXECUTE** privilege
241
+ * on the parent registered model to receive the model versions in the response.
242
+ * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
243
+ * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
244
+ *
245
+ * There is no guarantee of a specific ordering of the elements in the response. The
246
+ * elements in the response will not contain any aliases or tags.
247
+ *
248
+ * PAGINATION BEHAVIOR: The API is by default paginated, a page may contain zero results while still providing a next_page_token.
249
+ * Clients must continue reading pages until next_page_token is absent, which is the only indication that the end of results has been reached.
250
+ */
251
+ async listModelVersions(req, options) {
252
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
253
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}/versions`;
254
+ const params = new URLSearchParams();
255
+ if (req.maxResults !== void 0) params.append("max_results", String(req.maxResults));
256
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
257
+ if (req.includeBrowse !== void 0) params.append("include_browse", String(req.includeBrowse));
258
+ const query = params.toString();
259
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
260
+ let resp;
261
+ const call = async (callSignal) => {
262
+ const headers = new Headers();
263
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
264
+ headers.set("User-Agent", this.userAgent);
265
+ resp = parseResponse(await executeHttpCall({
266
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
267
+ httpClient,
268
+ logger: this.logger
269
+ }), unmarshalListModelVersionsResponseSchema);
270
+ };
271
+ await executeCall(call, options);
272
+ if (resp === void 0) throw new Error("operation completed without a result.");
273
+ return resp;
274
+ }
275
+ async *listModelVersionsIter(req, options) {
276
+ const pageReq = { ...req };
277
+ for (;;) {
278
+ const resp = await this.listModelVersions(pageReq, options);
279
+ for (const item of resp.modelVersions ?? []) yield item;
280
+ if (resp.nextPageToken === void 0 || resp.nextPageToken === "") return;
281
+ pageReq.pageToken = resp.nextPageToken;
282
+ }
283
+ }
284
+ /**
285
+ * List registered models. You can list registered models under a particular schema,
286
+ * or list all registered models in the current metastore.
287
+ *
288
+ * The returned models are filtered based on the privileges of the calling user.
289
+ * For example, the metastore admin is able to list all the registered models.
290
+ * A regular user needs to be the owner or have the **EXECUTE** privilege
291
+ * on the registered model to receive the registered models in the response.
292
+ * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
293
+ * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
294
+ *
295
+ * There is no guarantee of a specific ordering of the elements in the response.
296
+ *
297
+ * PAGINATION BEHAVIOR: The API is by default paginated, a page may contain zero results while still providing a next_page_token.
298
+ * Clients must continue reading pages until next_page_token is absent, which is the only indication that the end of results has been reached.
299
+ */
300
+ async listRegisteredModels(req, options) {
301
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
302
+ const url = `${host}/api/2.1/unity-catalog/models`;
303
+ const params = new URLSearchParams();
304
+ if (req.catalogName !== void 0) params.append("catalog_name", req.catalogName);
305
+ if (req.schemaName !== void 0) params.append("schema_name", req.schemaName);
306
+ if (req.includeBrowse !== void 0) params.append("include_browse", String(req.includeBrowse));
307
+ if (req.maxResults !== void 0) params.append("max_results", String(req.maxResults));
308
+ if (req.pageToken !== void 0) params.append("page_token", req.pageToken);
309
+ const query = params.toString();
310
+ const fullUrl = query !== "" ? `${url}?${query}` : url;
311
+ let resp;
312
+ const call = async (callSignal) => {
313
+ const headers = new Headers();
314
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
315
+ headers.set("User-Agent", this.userAgent);
316
+ resp = parseResponse(await executeHttpCall({
317
+ request: buildHttpRequest("GET", fullUrl, headers, callSignal),
318
+ httpClient,
319
+ logger: this.logger
320
+ }), unmarshalListRegisteredModelsResponseSchema);
321
+ };
322
+ await executeCall(call, options);
323
+ if (resp === void 0) throw new Error("operation completed without a result.");
324
+ return resp;
325
+ }
326
+ async *listRegisteredModelsIter(req, options) {
327
+ const pageReq = { ...req };
328
+ for (;;) {
329
+ const resp = await this.listRegisteredModels(pageReq, options);
330
+ for (const item of resp.registeredModels ?? []) yield item;
331
+ if (resp.nextPageToken === void 0 || resp.nextPageToken === "") return;
332
+ pageReq.pageToken = resp.nextPageToken;
333
+ }
334
+ }
335
+ /**
336
+ * Set an alias on the specified registered model.
337
+ *
338
+ * The caller must be a metastore admin or an owner of the registered model.
339
+ * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
340
+ * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
341
+ */
342
+ async setRegisteredModelAlias(req, options) {
343
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
344
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}/aliases/${req.aliasArg ?? ""}`;
345
+ const body = marshalRequest(req, marshalSetRegisteredModelAliasRequestSchema);
346
+ let resp;
347
+ const call = async (callSignal) => {
348
+ const headers = new Headers({ "Content-Type": "application/json" });
349
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
350
+ headers.set("User-Agent", this.userAgent);
351
+ resp = parseResponse(await executeHttpCall({
352
+ request: buildHttpRequest("PUT", url, headers, callSignal, body),
353
+ httpClient,
354
+ logger: this.logger
355
+ }), unmarshalRegisteredModelAliasInfoSchema);
356
+ };
357
+ await executeCall(call, options);
358
+ if (resp === void 0) throw new Error("operation completed without a result.");
359
+ return resp;
360
+ }
361
+ /**
362
+ * Updates the specified model version.
363
+ *
364
+ * The caller must be a metastore admin or an owner of the parent registered model.
365
+ * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
366
+ * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
367
+ *
368
+ * Currently only the comment of the model version can be updated.
369
+ */
370
+ async updateModelVersion(req, options) {
371
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
372
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}/versions/${String(req.versionArg ?? "")}`;
373
+ const body = marshalRequest(req, marshalUpdateModelVersionRequestSchema);
374
+ let resp;
375
+ const call = async (callSignal) => {
376
+ const headers = new Headers({ "Content-Type": "application/json" });
377
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
378
+ headers.set("User-Agent", this.userAgent);
379
+ resp = parseResponse(await executeHttpCall({
380
+ request: buildHttpRequest("PATCH", url, headers, callSignal, body),
381
+ httpClient,
382
+ logger: this.logger
383
+ }), unmarshalModelVersionInfoSchema);
384
+ };
385
+ await executeCall(call, options);
386
+ if (resp === void 0) throw new Error("operation completed without a result.");
387
+ return resp;
388
+ }
389
+ /**
390
+ * Updates the specified registered model.
391
+ *
392
+ * The caller must be a metastore admin or an owner of the registered model.
393
+ * For the latter case, the caller must also be the owner or have the **USE_CATALOG**
394
+ * privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent schema.
395
+ *
396
+ * Currently only the name, the owner or the comment of the registered model can be updated.
397
+ */
398
+ async updateRegisteredModel(req, options) {
399
+ const { host, workspaceId, httpClient } = await this.resolveConfig();
400
+ const url = `${host}/api/2.1/unity-catalog/models/${req.fullNameArg ?? ""}`;
401
+ const body = marshalRequest(req, marshalUpdateRegisteredModelRequestSchema);
402
+ let resp;
403
+ const call = async (callSignal) => {
404
+ const headers = new Headers({ "Content-Type": "application/json" });
405
+ if (workspaceId !== void 0) headers.set("X-Databricks-Workspace-Id", workspaceId);
406
+ headers.set("User-Agent", this.userAgent);
407
+ resp = parseResponse(await executeHttpCall({
408
+ request: buildHttpRequest("PATCH", url, headers, callSignal, body),
409
+ httpClient,
410
+ logger: this.logger
411
+ }), unmarshalRegisteredModelInfoSchema);
412
+ };
413
+ await executeCall(call, options);
414
+ if (resp === void 0) throw new Error("operation completed without a result.");
415
+ return resp;
416
+ }
417
+ };
418
+
419
+ //#endregion
420
+ export { RegisteredModelsClient };
528
421
  //# sourceMappingURL=client.js.map