Skip to content

Commit 7ad6552

Browse files
authored
SDK: Generate SCIM, Commands and Libraries from OpenAPI (#122)
1 parent e729aa2 commit 7ad6552

File tree

31 files changed

+1785
-797
lines changed

31 files changed

+1785
-797
lines changed

packages/databricks-sdk-js/src/api-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class ApiClient {
3232
constructor(
3333
private readonly product: string,
3434
private readonly productVersion: string,
35-
private credentialProvider = fromDefaultChain
35+
readonly credentialProvider = fromDefaultChain
3636
) {
3737
this.agent = new https.Agent({
3838
keepAlive: true,
@@ -68,7 +68,8 @@ export class ApiClient {
6868
"Content-Type": "text/json",
6969
};
7070

71-
let url = credentials.host;
71+
// create a copy of the URL, so that we can modify it
72+
let url = new URL(credentials.host.toString());
7273
url.pathname = path;
7374

7475
let options: any = {

packages/databricks-sdk-js/src/apis/.codegen.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
"Workspace",
77
"Dbfs",
88
"Permissions",
9-
"Workspace Conf"
9+
"Workspace Conf",
10+
"Users",
11+
"Groups",
12+
"CurrentUser",
13+
"Service Principals",
14+
"ManagedLibraries",
15+
"Command Execution"
1016
],
1117
"formatter": "yarn fix",
1218
"packages": {

packages/databricks-sdk-js/src/apis/.codegen/api.ts.tmpl

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,26 @@ export class {{$s.PascalName}}Service {
4848
* {{.CamelName}} and wait to reach {{range $i, $e := .Wait.Success}}{{if $i}} or {{end}}{{.Content}}{{end}} state
4949
* {{if .Wait.Failure}} or fail on reaching {{range $i, $e := .Wait.Failure}}{{if $i}} or {{end}}{{.Content}}{{end}} state{{end}}
5050
*/
51-
async {{.CamelName}}AndWait({request, timeout, cancellationToken, onProgress= async (newPollResponse) => {}}:{
52-
{{if .Request}}request: model.{{.Request.PascalName}}{{end}},
53-
timeout?: Time,
54-
cancellationToken?: CancellationToken,
55-
onProgress?: (newPollResponse: model.{{if .Wait.Poll.Response}}{{.Wait.Poll.Response.PascalName}}{{else}}{{.Wait.Poll.EmptyResponseName.PascalName}}{{end}}) => Promise<void>
56-
}): Promise<model.{{if .Wait.Poll.Response}}{{.Wait.Poll.Response.PascalName}}{{else}}{{.Wait.Poll.EmptyResponseName.PascalName}}{{end}}> {
57-
const response = await this.{{.CamelName}}(request);
51+
async {{.CamelName}}AndWait({{if .Request}}{{.Request.CamelName}}: model.{{.Request.PascalName}}{{end}},
52+
options?: {
53+
timeout?: Time,
54+
cancellationToken?: CancellationToken,
55+
onProgress?: (newPollResponse: model.{{if .Wait.Poll.Response}}{{.Wait.Poll.Response.PascalName}}{{else}}{{.Wait.Poll.EmptyResponseName.PascalName}}{{end}}) => Promise<void>
56+
}
57+
): Promise<model.{{if .Wait.Poll.Response}}{{.Wait.Poll.Response.PascalName}}{{else}}{{.Wait.Poll.EmptyResponseName.PascalName}}{{end}}> {
58+
59+
options = options || {};
60+
options.onProgress =
61+
options.onProgress || (async (newPollResponse) => {});
62+
let {cancellationToken, timeout, onProgress} = options;
63+
64+
{{if .Wait.ForceBindRequest}}{{else if .Response}}const {{.Response.CamelName}} = {{end}}await this.{{.CamelName}}({{.Request.CamelName}});
5865

5966
return await retry<model.{{if .Wait.Poll.Response}}{{.Wait.Poll.Response.PascalName}}{{else}}{{.Wait.Poll.EmptyResponseName.PascalName}}{{end}}>({
60-
timeout: timeout,
67+
timeout,
6168
fn: async () => {
6269
const pollResponse = await this.{{.Wait.Poll.CamelName}}({ {{$e := .}}{{range .Wait.Binding}}
63-
{{.Bind.SnakeName}}: {{if $e.Wait.ForceBindRequest}}request{{else if $e.Response}}response{{else}}request{{end}}.{{.Bind.SnakeName}}{{end}}!
70+
{{.PollField.Name}}: {{.Bind.Of.CamelName}}.{{.Bind.Name}}!,{{end}}
6471
}, cancellationToken)
6572
if(cancellationToken?.isCancellationRequested) {
6673
throw new {{$s.PascalName}}Error("{{.CamelName}}AndWait", "cancelled");

packages/databricks-sdk-js/src/apis/.codegen/model.ts.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
{{if .Comment "" 80}}/**
1212
{{.Comment " * " 80}}
1313
*/
14-
{{end}}{{.SnakeName}}{{if not .Required}}?{{end}}: {{template "type" .Entity}};{{end}}
14+
{{end}}{{.Name}}{{if not .Required}}?{{end}}: {{template "type" .Entity}};{{end}}
1515
}
1616
{{else if .MapValue}}export type {{.PascalName}} = {{template "type" .}};
1717
{{else if .Enum}}export type {{.PascalName}} =

packages/databricks-sdk-js/src/apis/clusters/api.ts

Lines changed: 112 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,27 @@ export class ClustersService {
7878
* create and wait to reach RUNNING state
7979
* or fail on reaching ERROR state
8080
*/
81-
async createAndWait({
82-
request,
83-
timeout,
84-
cancellationToken,
85-
onProgress = async (newPollResponse) => {},
86-
}: {
87-
request: model.CreateCluster;
88-
timeout?: Time;
89-
cancellationToken?: CancellationToken;
90-
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
91-
}): Promise<model.ClusterInfo> {
92-
const response = await this.create(request);
81+
async createAndWait(
82+
createCluster: model.CreateCluster,
83+
options?: {
84+
timeout?: Time;
85+
cancellationToken?: CancellationToken;
86+
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
87+
}
88+
): Promise<model.ClusterInfo> {
89+
options = options || {};
90+
options.onProgress =
91+
options.onProgress || (async (newPollResponse) => {});
92+
let {cancellationToken, timeout, onProgress} = options;
93+
94+
const createClusterResponse = await this.create(createCluster);
9395

9496
return await retry<model.ClusterInfo>({
95-
timeout: timeout,
97+
timeout,
9698
fn: async () => {
9799
const pollResponse = await this.get(
98100
{
99-
cluster_id: response.cluster_id!,
101+
cluster_id: createClusterResponse.cluster_id!,
100102
},
101103
cancellationToken
102104
);
@@ -152,25 +154,27 @@ export class ClustersService {
152154
* delete and wait to reach TERMINATED state
153155
* or fail on reaching ERROR state
154156
*/
155-
async deleteAndWait({
156-
request,
157-
timeout,
158-
cancellationToken,
159-
onProgress = async (newPollResponse) => {},
160-
}: {
161-
request: model.DeleteCluster;
162-
timeout?: Time;
163-
cancellationToken?: CancellationToken;
164-
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
165-
}): Promise<model.ClusterInfo> {
166-
const response = await this.delete(request);
157+
async deleteAndWait(
158+
deleteCluster: model.DeleteCluster,
159+
options?: {
160+
timeout?: Time;
161+
cancellationToken?: CancellationToken;
162+
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
163+
}
164+
): Promise<model.ClusterInfo> {
165+
options = options || {};
166+
options.onProgress =
167+
options.onProgress || (async (newPollResponse) => {});
168+
let {cancellationToken, timeout, onProgress} = options;
169+
170+
await this.delete(deleteCluster);
167171

168172
return await retry<model.ClusterInfo>({
169-
timeout: timeout,
173+
timeout,
170174
fn: async () => {
171175
const pollResponse = await this.get(
172176
{
173-
cluster_id: request.cluster_id!,
177+
cluster_id: deleteCluster.cluster_id!,
174178
},
175179
cancellationToken
176180
);
@@ -235,25 +239,27 @@ export class ClustersService {
235239
* edit and wait to reach RUNNING state
236240
* or fail on reaching ERROR state
237241
*/
238-
async editAndWait({
239-
request,
240-
timeout,
241-
cancellationToken,
242-
onProgress = async (newPollResponse) => {},
243-
}: {
244-
request: model.EditCluster;
245-
timeout?: Time;
246-
cancellationToken?: CancellationToken;
247-
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
248-
}): Promise<model.ClusterInfo> {
249-
const response = await this.edit(request);
242+
async editAndWait(
243+
editCluster: model.EditCluster,
244+
options?: {
245+
timeout?: Time;
246+
cancellationToken?: CancellationToken;
247+
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
248+
}
249+
): Promise<model.ClusterInfo> {
250+
options = options || {};
251+
options.onProgress =
252+
options.onProgress || (async (newPollResponse) => {});
253+
let {cancellationToken, timeout, onProgress} = options;
254+
255+
await this.edit(editCluster);
250256

251257
return await retry<model.ClusterInfo>({
252-
timeout: timeout,
258+
timeout,
253259
fn: async () => {
254260
const pollResponse = await this.get(
255261
{
256-
cluster_id: request.cluster_id!,
262+
cluster_id: editCluster.cluster_id!,
257263
},
258264
cancellationToken
259265
);
@@ -328,25 +334,27 @@ export class ClustersService {
328334
* get and wait to reach RUNNING state
329335
* or fail on reaching ERROR state
330336
*/
331-
async getAndWait({
332-
request,
333-
timeout,
334-
cancellationToken,
335-
onProgress = async (newPollResponse) => {},
336-
}: {
337-
request: model.GetRequest;
338-
timeout?: Time;
339-
cancellationToken?: CancellationToken;
340-
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
341-
}): Promise<model.ClusterInfo> {
342-
const response = await this.get(request);
337+
async getAndWait(
338+
getRequest: model.GetRequest,
339+
options?: {
340+
timeout?: Time;
341+
cancellationToken?: CancellationToken;
342+
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
343+
}
344+
): Promise<model.ClusterInfo> {
345+
options = options || {};
346+
options.onProgress =
347+
options.onProgress || (async (newPollResponse) => {});
348+
let {cancellationToken, timeout, onProgress} = options;
349+
350+
const clusterInfo = await this.get(getRequest);
343351

344352
return await retry<model.ClusterInfo>({
345-
timeout: timeout,
353+
timeout,
346354
fn: async () => {
347355
const pollResponse = await this.get(
348356
{
349-
cluster_id: response.cluster_id!,
357+
cluster_id: clusterInfo.cluster_id!,
350358
},
351359
cancellationToken
352360
);
@@ -506,25 +514,27 @@ export class ClustersService {
506514
* resize and wait to reach RUNNING state
507515
* or fail on reaching ERROR state
508516
*/
509-
async resizeAndWait({
510-
request,
511-
timeout,
512-
cancellationToken,
513-
onProgress = async (newPollResponse) => {},
514-
}: {
515-
request: model.ResizeCluster;
516-
timeout?: Time;
517-
cancellationToken?: CancellationToken;
518-
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
519-
}): Promise<model.ClusterInfo> {
520-
const response = await this.resize(request);
517+
async resizeAndWait(
518+
resizeCluster: model.ResizeCluster,
519+
options?: {
520+
timeout?: Time;
521+
cancellationToken?: CancellationToken;
522+
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
523+
}
524+
): Promise<model.ClusterInfo> {
525+
options = options || {};
526+
options.onProgress =
527+
options.onProgress || (async (newPollResponse) => {});
528+
let {cancellationToken, timeout, onProgress} = options;
529+
530+
await this.resize(resizeCluster);
521531

522532
return await retry<model.ClusterInfo>({
523-
timeout: timeout,
533+
timeout,
524534
fn: async () => {
525535
const pollResponse = await this.get(
526536
{
527-
cluster_id: request.cluster_id!,
537+
cluster_id: resizeCluster.cluster_id!,
528538
},
529539
cancellationToken
530540
);
@@ -578,25 +588,27 @@ export class ClustersService {
578588
* restart and wait to reach RUNNING state
579589
* or fail on reaching ERROR state
580590
*/
581-
async restartAndWait({
582-
request,
583-
timeout,
584-
cancellationToken,
585-
onProgress = async (newPollResponse) => {},
586-
}: {
587-
request: model.RestartCluster;
588-
timeout?: Time;
589-
cancellationToken?: CancellationToken;
590-
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
591-
}): Promise<model.ClusterInfo> {
592-
const response = await this.restart(request);
591+
async restartAndWait(
592+
restartCluster: model.RestartCluster,
593+
options?: {
594+
timeout?: Time;
595+
cancellationToken?: CancellationToken;
596+
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
597+
}
598+
): Promise<model.ClusterInfo> {
599+
options = options || {};
600+
options.onProgress =
601+
options.onProgress || (async (newPollResponse) => {});
602+
let {cancellationToken, timeout, onProgress} = options;
603+
604+
await this.restart(restartCluster);
593605

594606
return await retry<model.ClusterInfo>({
595-
timeout: timeout,
607+
timeout,
596608
fn: async () => {
597609
const pollResponse = await this.get(
598610
{
599-
cluster_id: request.cluster_id!,
611+
cluster_id: restartCluster.cluster_id!,
600612
},
601613
cancellationToken
602614
);
@@ -674,25 +686,27 @@ export class ClustersService {
674686
* start and wait to reach RUNNING state
675687
* or fail on reaching ERROR state
676688
*/
677-
async startAndWait({
678-
request,
679-
timeout,
680-
cancellationToken,
681-
onProgress = async (newPollResponse) => {},
682-
}: {
683-
request: model.StartCluster;
684-
timeout?: Time;
685-
cancellationToken?: CancellationToken;
686-
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
687-
}): Promise<model.ClusterInfo> {
688-
const response = await this.start(request);
689+
async startAndWait(
690+
startCluster: model.StartCluster,
691+
options?: {
692+
timeout?: Time;
693+
cancellationToken?: CancellationToken;
694+
onProgress?: (newPollResponse: model.ClusterInfo) => Promise<void>;
695+
}
696+
): Promise<model.ClusterInfo> {
697+
options = options || {};
698+
options.onProgress =
699+
options.onProgress || (async (newPollResponse) => {});
700+
let {cancellationToken, timeout, onProgress} = options;
701+
702+
await this.start(startCluster);
689703

690704
return await retry<model.ClusterInfo>({
691-
timeout: timeout,
705+
timeout,
692706
fn: async () => {
693707
const pollResponse = await this.get(
694708
{
695-
cluster_id: request.cluster_id!,
709+
cluster_id: startCluster.cluster_id!,
696710
},
697711
cancellationToken
698712
);

0 commit comments

Comments
 (0)