@databricks/sdk-uc-workspacebindings 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.
@@ -0,0 +1,193 @@
1
+ // Code generated from API definition by Databricks SDK Generator. DO NOT EDIT.
2
+
3
+ import {z} from 'zod';
4
+
5
+ /** Using `BINDING_TYPE_` prefix here to avoid conflict with `TableOperation` enum in `credentials_common.proto`. */
6
+ export enum BindingType {
7
+ BINDING_TYPE_UNSPECIFIED = 'BINDING_TYPE_UNSPECIFIED',
8
+ BINDING_TYPE_READ_WRITE = 'BINDING_TYPE_READ_WRITE',
9
+ BINDING_TYPE_READ_ONLY = 'BINDING_TYPE_READ_ONLY',
10
+ }
11
+
12
+ export interface GetCatalogWorkspaceBindingsRequest {
13
+ /** The name of the catalog. */
14
+ catalogName?: string | undefined;
15
+ }
16
+
17
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
18
+ export interface GetCatalogWorkspaceBindingsRequest_Response {
19
+ /** A list of workspace IDs */
20
+ workspaces?: bigint[] | undefined;
21
+ }
22
+
23
+ export interface GetWorkspaceBindingsRequest {
24
+ /** The type of the securable to bind to a workspace (catalog, storage_credential, credential, or external_location). */
25
+ securableType?: string | undefined;
26
+ /** The name of the securable. */
27
+ securableFullName?: string | undefined;
28
+ /**
29
+ * Maximum number of workspace bindings to return.
30
+ * - When set to 0, the page length is set to a server configured value (recommended);
31
+ * - When set to a value greater than 0, the page length is the minimum of this value and a server configured value;
32
+ * - When set to a value less than 0, an invalid parameter error is returned;
33
+ * - If not set, all the workspace bindings are returned (not recommended).
34
+ */
35
+ maxResults?: number | undefined;
36
+ /** Opaque pagination token to go to next page based on previous query. */
37
+ pageToken?: string | undefined;
38
+ }
39
+
40
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
41
+ export interface GetWorkspaceBindingsRequest_Response {
42
+ /** List of workspace bindings */
43
+ bindings?: WorkspaceBindingInfo[] | undefined;
44
+ /**
45
+ * Opaque token to retrieve the next page of results. Absent if there are no more pages.
46
+ * __page_token__ should be set to this value for the next request (for the next page of results).
47
+ */
48
+ nextPageToken?: string | undefined;
49
+ }
50
+
51
+ export interface UpdateCatalogWorkspaceBindingsRequest {
52
+ /** The name of the catalog. */
53
+ catalogName?: string | undefined;
54
+ /** A list of workspace IDs. */
55
+ assignWorkspaces?: bigint[] | undefined;
56
+ /** A list of workspace IDs. */
57
+ unassignWorkspaces?: bigint[] | undefined;
58
+ }
59
+
60
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
61
+ export interface UpdateCatalogWorkspaceBindingsRequest_Response {
62
+ /** A list of workspace IDs */
63
+ workspaces?: bigint[] | undefined;
64
+ }
65
+
66
+ export interface UpdateWorkspaceBindingsRequest {
67
+ /** The type of the securable to bind to a workspace (catalog, storage_credential, credential, or external_location). */
68
+ securableType?: string | undefined;
69
+ /** The name of the securable. */
70
+ securableFullName?: string | undefined;
71
+ /**
72
+ * List of workspace bindings to add. If a binding for the workspace already exists with a
73
+ * different binding_type, adding it again with a new binding_type will update the existing
74
+ * binding (e.g., from READ_WRITE to READ_ONLY).
75
+ */
76
+ add?: WorkspaceBindingInfo[] | undefined;
77
+ /** List of workspace bindings to remove. */
78
+ remove?: WorkspaceBindingInfo[] | undefined;
79
+ }
80
+
81
+ /** A list of workspace IDs that are bound to the securable */
82
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
83
+ export interface UpdateWorkspaceBindingsRequest_Response {
84
+ /** List of workspace bindings. */
85
+ bindings?: WorkspaceBindingInfo[] | undefined;
86
+ }
87
+
88
+ export interface WorkspaceBindingInfo {
89
+ /** Required */
90
+ workspaceId?: bigint | undefined;
91
+ /** One of READ_WRITE/READ_ONLY. Default is READ_WRITE. */
92
+ bindingType?: BindingType | undefined;
93
+ }
94
+
95
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
96
+ export const unmarshalGetCatalogWorkspaceBindingsRequest_ResponseSchema: z.ZodType<GetCatalogWorkspaceBindingsRequest_Response> =
97
+ z
98
+ .object({
99
+ workspaces: z
100
+ .array(z.union([z.number(), z.bigint()]).transform(v => BigInt(v)))
101
+ .optional(),
102
+ })
103
+ .transform(d => ({
104
+ workspaces: d.workspaces,
105
+ }));
106
+
107
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
108
+ export const unmarshalGetWorkspaceBindingsRequest_ResponseSchema: z.ZodType<GetWorkspaceBindingsRequest_Response> =
109
+ z
110
+ .object({
111
+ bindings: z
112
+ .array(z.lazy(() => unmarshalWorkspaceBindingInfoSchema))
113
+ .optional(),
114
+ next_page_token: z.string().optional(),
115
+ })
116
+ .transform(d => ({
117
+ bindings: d.bindings,
118
+ nextPageToken: d.next_page_token,
119
+ }));
120
+
121
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
122
+ export const unmarshalUpdateCatalogWorkspaceBindingsRequest_ResponseSchema: z.ZodType<UpdateCatalogWorkspaceBindingsRequest_Response> =
123
+ z
124
+ .object({
125
+ workspaces: z
126
+ .array(z.union([z.number(), z.bigint()]).transform(v => BigInt(v)))
127
+ .optional(),
128
+ })
129
+ .transform(d => ({
130
+ workspaces: d.workspaces,
131
+ }));
132
+
133
+ // eslint-disable-next-line @typescript-eslint/naming-convention -- Proto-style nested message name.
134
+ export const unmarshalUpdateWorkspaceBindingsRequest_ResponseSchema: z.ZodType<UpdateWorkspaceBindingsRequest_Response> =
135
+ z
136
+ .object({
137
+ bindings: z
138
+ .array(z.lazy(() => unmarshalWorkspaceBindingInfoSchema))
139
+ .optional(),
140
+ })
141
+ .transform(d => ({
142
+ bindings: d.bindings,
143
+ }));
144
+
145
+ export const unmarshalWorkspaceBindingInfoSchema: z.ZodType<WorkspaceBindingInfo> =
146
+ z
147
+ .object({
148
+ workspace_id: z
149
+ .union([z.number(), z.bigint()])
150
+ .transform(v => BigInt(v))
151
+ .optional(),
152
+ binding_type: z.enum(BindingType).optional(),
153
+ })
154
+ .transform(d => ({
155
+ workspaceId: d.workspace_id,
156
+ bindingType: d.binding_type,
157
+ }));
158
+
159
+ export const marshalUpdateCatalogWorkspaceBindingsRequestSchema: z.ZodType = z
160
+ .object({
161
+ catalogName: z.string().optional(),
162
+ assignWorkspaces: z.array(z.bigint()).optional(),
163
+ unassignWorkspaces: z.array(z.bigint()).optional(),
164
+ })
165
+ .transform(d => ({
166
+ catalog_name: d.catalogName,
167
+ assign_workspaces: d.assignWorkspaces,
168
+ unassign_workspaces: d.unassignWorkspaces,
169
+ }));
170
+
171
+ export const marshalUpdateWorkspaceBindingsRequestSchema: z.ZodType = z
172
+ .object({
173
+ securableType: z.string().optional(),
174
+ securableFullName: z.string().optional(),
175
+ add: z.array(z.lazy(() => marshalWorkspaceBindingInfoSchema)).optional(),
176
+ remove: z.array(z.lazy(() => marshalWorkspaceBindingInfoSchema)).optional(),
177
+ })
178
+ .transform(d => ({
179
+ securable_type: d.securableType,
180
+ securable_full_name: d.securableFullName,
181
+ add: d.add,
182
+ remove: d.remove,
183
+ }));
184
+
185
+ export const marshalWorkspaceBindingInfoSchema: z.ZodType = z
186
+ .object({
187
+ workspaceId: z.bigint().optional(),
188
+ bindingType: z.enum(BindingType).optional(),
189
+ })
190
+ .transform(d => ({
191
+ workspace_id: d.workspaceId,
192
+ binding_type: d.bindingType,
193
+ }));
@@ -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
+ }
@@ -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 = {};