windmill-client 1.813.0 → 1.815.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/core/OpenAPI.mjs +1 -1
- package/dist/index.js +197 -18
- package/dist/services.gen.d.ts +100 -12
- package/dist/services.gen.mjs +181 -12
- package/dist/sqlUtils.d.ts +10 -1
- package/dist/sqlUtils.mjs +15 -5
- package/dist/types.gen.d.ts +432 -31
- package/package.json +1 -1
package/dist/services.gen.mjs
CHANGED
|
@@ -357,6 +357,20 @@ var UserService = class {
|
|
|
357
357
|
});
|
|
358
358
|
}
|
|
359
359
|
/**
|
|
360
|
+
* consume a single-use login link from its confirmation page, set the session cookie and answer where to go
|
|
361
|
+
* @param data The data for the request.
|
|
362
|
+
* @param data.token
|
|
363
|
+
* @returns unknown the post-login destination, or /user/login_link_expired when the link is used, expired or unknown
|
|
364
|
+
* @throws ApiError
|
|
365
|
+
*/
|
|
366
|
+
static confirmLoginLink(data) {
|
|
367
|
+
return request(OpenAPI, {
|
|
368
|
+
method: "POST",
|
|
369
|
+
url: "/auth/login_link/{token}",
|
|
370
|
+
path: { token: data.token }
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
360
374
|
* reset password using token
|
|
361
375
|
* @param data The data for the request.
|
|
362
376
|
* @param data.requestBody token and new password
|
|
@@ -2734,6 +2748,63 @@ var WorkspaceService = class {
|
|
|
2734
2748
|
});
|
|
2735
2749
|
}
|
|
2736
2750
|
/**
|
|
2751
|
+
* get who may connect to a data table as which role
|
|
2752
|
+
* @param data The data for the request.
|
|
2753
|
+
* @param data.workspace
|
|
2754
|
+
* @param data.datatableName
|
|
2755
|
+
* @returns DatatablePermissions the data table's roles and their tenants
|
|
2756
|
+
* @throws ApiError
|
|
2757
|
+
*/
|
|
2758
|
+
static getDatatablePermissions(data) {
|
|
2759
|
+
return request(OpenAPI, {
|
|
2760
|
+
method: "GET",
|
|
2761
|
+
url: "/w/{workspace}/workspaces/datatable_permissions/{datatable_name}",
|
|
2762
|
+
path: {
|
|
2763
|
+
workspace: data.workspace,
|
|
2764
|
+
datatable_name: data.datatableName
|
|
2765
|
+
}
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
/**
|
|
2769
|
+
* set who may connect to a data table as which role
|
|
2770
|
+
* @param data The data for the request.
|
|
2771
|
+
* @param data.workspace
|
|
2772
|
+
* @param data.datatableName
|
|
2773
|
+
* @param data.requestBody
|
|
2774
|
+
* @returns string status
|
|
2775
|
+
* @throws ApiError
|
|
2776
|
+
*/
|
|
2777
|
+
static setDatatablePermissions(data) {
|
|
2778
|
+
return request(OpenAPI, {
|
|
2779
|
+
method: "POST",
|
|
2780
|
+
url: "/w/{workspace}/workspaces/datatable_permissions/{datatable_name}",
|
|
2781
|
+
path: {
|
|
2782
|
+
workspace: data.workspace,
|
|
2783
|
+
datatable_name: data.datatableName
|
|
2784
|
+
},
|
|
2785
|
+
body: data.requestBody,
|
|
2786
|
+
mediaType: "application/json"
|
|
2787
|
+
});
|
|
2788
|
+
}
|
|
2789
|
+
/**
|
|
2790
|
+
* list the data table roles the caller may connect as
|
|
2791
|
+
* @param data The data for the request.
|
|
2792
|
+
* @param data.workspace
|
|
2793
|
+
* @param data.datatableName
|
|
2794
|
+
* @returns unknown usable roles
|
|
2795
|
+
* @throws ApiError
|
|
2796
|
+
*/
|
|
2797
|
+
static listUsableDatatableRoles(data) {
|
|
2798
|
+
return request(OpenAPI, {
|
|
2799
|
+
method: "GET",
|
|
2800
|
+
url: "/w/{workspace}/workspaces/datatable_usable_roles/{datatable_name}",
|
|
2801
|
+
path: {
|
|
2802
|
+
workspace: data.workspace,
|
|
2803
|
+
datatable_name: data.datatableName
|
|
2804
|
+
}
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
/**
|
|
2737
2808
|
* list schemas of all connected Datatables
|
|
2738
2809
|
* @param data The data for the request.
|
|
2739
2810
|
* @param data.workspace
|
|
@@ -3260,6 +3331,24 @@ var WorkspaceService = class {
|
|
|
3260
3331
|
});
|
|
3261
3332
|
}
|
|
3262
3333
|
/**
|
|
3334
|
+
* choose whether new forks of this workspace start with its admins and developers
|
|
3335
|
+
* When on, every fork created from this workspace gets the workspace's admins and developers as members, with the role they hold here; operators, disabled users and service accounts are left out. The setting is copied into each fork, so forks of a fork follow it too. Off by default. Workspace-admin gated.
|
|
3336
|
+
* @param data The data for the request.
|
|
3337
|
+
* @param data.workspace
|
|
3338
|
+
* @param data.requestBody Whether new forks start with this workspace's admins and developers
|
|
3339
|
+
* @returns string status
|
|
3340
|
+
* @throws ApiError
|
|
3341
|
+
*/
|
|
3342
|
+
static editAddAdminsAndDevelopersToForks(data) {
|
|
3343
|
+
return request(OpenAPI, {
|
|
3344
|
+
method: "POST",
|
|
3345
|
+
url: "/w/{workspace}/workspaces/edit_add_admins_and_developers_to_forks",
|
|
3346
|
+
path: { workspace: data.workspace },
|
|
3347
|
+
body: data.requestBody,
|
|
3348
|
+
mediaType: "application/json"
|
|
3349
|
+
});
|
|
3350
|
+
}
|
|
3351
|
+
/**
|
|
3263
3352
|
* set the key guest JWTs are verified against for this workspace
|
|
3264
3353
|
* A guest JWT (`jwt_guest_`) is minted by the embedding customer's own backend and verified against this key: a PEM public key (RS/ES family, HS* refused) or a JWKS URL, at most one. Both empty clears the workspace key; off cloud, verification then falls back to the instance issuer (`JWT_EXT_JWKS_URL`) if one is set, else no guest JWT is accepted (`guest_access_enabled` is the on/off switch). Workspace-admin gated. The key is validated before it is stored. Setting a key is refused with a 400 where guests are unavailable (the shared cloud); clearing one always works.
|
|
3265
3354
|
* @param data The data for the request.
|
|
@@ -3778,6 +3867,63 @@ var SettingService = class {
|
|
|
3778
3867
|
});
|
|
3779
3868
|
}
|
|
3780
3869
|
/**
|
|
3870
|
+
* list the instance's data table roles
|
|
3871
|
+
* @returns InstanceDatatableRole the instance role catalog
|
|
3872
|
+
* @throws ApiError
|
|
3873
|
+
*/
|
|
3874
|
+
static listInstanceDatatableRoles() {
|
|
3875
|
+
return request(OpenAPI, {
|
|
3876
|
+
method: "GET",
|
|
3877
|
+
url: "/settings/datatable_roles"
|
|
3878
|
+
});
|
|
3879
|
+
}
|
|
3880
|
+
/**
|
|
3881
|
+
* create a data table role on the instance's Postgres cluster
|
|
3882
|
+
* @param data The data for the request.
|
|
3883
|
+
* @param data.requestBody
|
|
3884
|
+
* @returns InstanceDatatableRole the created role
|
|
3885
|
+
* @throws ApiError
|
|
3886
|
+
*/
|
|
3887
|
+
static createInstanceDatatableRole(data) {
|
|
3888
|
+
return request(OpenAPI, {
|
|
3889
|
+
method: "POST",
|
|
3890
|
+
url: "/settings/datatable_roles",
|
|
3891
|
+
body: data.requestBody,
|
|
3892
|
+
mediaType: "application/json"
|
|
3893
|
+
});
|
|
3894
|
+
}
|
|
3895
|
+
/**
|
|
3896
|
+
* rename a data table role or turn its login on and off
|
|
3897
|
+
* @param data The data for the request.
|
|
3898
|
+
* @param data.id
|
|
3899
|
+
* @param data.requestBody
|
|
3900
|
+
* @returns InstanceDatatableRole the updated role
|
|
3901
|
+
* @throws ApiError
|
|
3902
|
+
*/
|
|
3903
|
+
static updateInstanceDatatableRole(data) {
|
|
3904
|
+
return request(OpenAPI, {
|
|
3905
|
+
method: "POST",
|
|
3906
|
+
url: "/settings/datatable_roles/{id}",
|
|
3907
|
+
path: { id: data.id },
|
|
3908
|
+
body: data.requestBody,
|
|
3909
|
+
mediaType: "application/json"
|
|
3910
|
+
});
|
|
3911
|
+
}
|
|
3912
|
+
/**
|
|
3913
|
+
* drop a data table role from the cluster and from every workspace that named it
|
|
3914
|
+
* @param data The data for the request.
|
|
3915
|
+
* @param data.id
|
|
3916
|
+
* @returns unknown deleted
|
|
3917
|
+
* @throws ApiError
|
|
3918
|
+
*/
|
|
3919
|
+
static deleteInstanceDatatableRole(data) {
|
|
3920
|
+
return request(OpenAPI, {
|
|
3921
|
+
method: "DELETE",
|
|
3922
|
+
url: "/settings/datatable_roles/{id}",
|
|
3923
|
+
path: { id: data.id }
|
|
3924
|
+
});
|
|
3925
|
+
}
|
|
3926
|
+
/**
|
|
3781
3927
|
* Runs CREATE DATABASE on the Windmill Postgres and grants access to the custom_instance_user
|
|
3782
3928
|
* @param data The data for the request.
|
|
3783
3929
|
* @param data.name The name of the database to create
|
|
@@ -8412,7 +8558,7 @@ var JobService = class {
|
|
|
8412
8558
|
*
|
|
8413
8559
|
* @param data.jobId The job id to assign to the created job. if missing, job is chosen randomly using the ULID scheme. If a job id already exists in the queue or as a completed job, the request to create one will fail (Bad Request)
|
|
8414
8560
|
* @param data.skipPreprocessor skip the preprocessor
|
|
8415
|
-
* @param data.memoryId
|
|
8561
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8416
8562
|
* @returns unknown job result
|
|
8417
8563
|
* @throws ApiError
|
|
8418
8564
|
*/
|
|
@@ -8448,7 +8594,7 @@ var JobService = class {
|
|
|
8448
8594
|
*
|
|
8449
8595
|
* @param data.jobId The job id to assign to the created job. if missing, job is chosen randomly using the ULID scheme. If a job id already exists in the queue or as a completed job, the request to create one will fail (Bad Request)
|
|
8450
8596
|
* @param data.skipPreprocessor skip the preprocessor
|
|
8451
|
-
* @param data.memoryId
|
|
8597
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8452
8598
|
* @returns unknown job result
|
|
8453
8599
|
* @throws ApiError
|
|
8454
8600
|
*/
|
|
@@ -8486,7 +8632,7 @@ var JobService = class {
|
|
|
8486
8632
|
*
|
|
8487
8633
|
* @param data.jobId The job id to assign to the created job. if missing, job is chosen randomly using the ULID scheme. If a job id already exists in the queue or as a completed job, the request to create one will fail (Bad Request)
|
|
8488
8634
|
* @param data.skipPreprocessor skip the preprocessor
|
|
8489
|
-
* @param data.memoryId
|
|
8635
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8490
8636
|
* @returns unknown job result
|
|
8491
8637
|
* @throws ApiError
|
|
8492
8638
|
*/
|
|
@@ -8521,7 +8667,7 @@ var JobService = class {
|
|
|
8521
8667
|
*
|
|
8522
8668
|
* @param data.jobId The job id to assign to the created job. if missing, job is chosen randomly using the ULID scheme. If a job id already exists in the queue or as a completed job, the request to create one will fail (Bad Request)
|
|
8523
8669
|
* @param data.skipPreprocessor skip the preprocessor
|
|
8524
|
-
* @param data.memoryId
|
|
8670
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8525
8671
|
* @param data.pollDelayMs delay between polling for job updates in milliseconds
|
|
8526
8672
|
* @returns string server-sent events stream of job updates
|
|
8527
8673
|
* @throws ApiError
|
|
@@ -8561,7 +8707,7 @@ var JobService = class {
|
|
|
8561
8707
|
*
|
|
8562
8708
|
* @param data.jobId The job id to assign to the created job. if missing, job is chosen randomly using the ULID scheme. If a job id already exists in the queue or as a completed job, the request to create one will fail (Bad Request)
|
|
8563
8709
|
* @param data.skipPreprocessor skip the preprocessor
|
|
8564
|
-
* @param data.memoryId
|
|
8710
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8565
8711
|
* @param data.pollDelayMs delay between polling for job updates in milliseconds
|
|
8566
8712
|
* @returns string server-sent events stream of job updates
|
|
8567
8713
|
* @throws ApiError
|
|
@@ -8598,7 +8744,7 @@ var JobService = class {
|
|
|
8598
8744
|
*
|
|
8599
8745
|
* @param data.jobId The job id to assign to the created job. if missing, job is chosen randomly using the ULID scheme. If a job id already exists in the queue or as a completed job, the request to create one will fail (Bad Request)
|
|
8600
8746
|
* @param data.skipPreprocessor skip the preprocessor
|
|
8601
|
-
* @param data.memoryId
|
|
8747
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8602
8748
|
* @param data.pollDelayMs delay between polling for job updates in milliseconds
|
|
8603
8749
|
* @returns string server-sent events stream of job updates
|
|
8604
8750
|
* @throws ApiError
|
|
@@ -8638,7 +8784,7 @@ var JobService = class {
|
|
|
8638
8784
|
*
|
|
8639
8785
|
* @param data.jobId The job id to assign to the created job. if missing, job is chosen randomly using the ULID scheme. If a job id already exists in the queue or as a completed job, the request to create one will fail (Bad Request)
|
|
8640
8786
|
* @param data.skipPreprocessor skip the preprocessor
|
|
8641
|
-
* @param data.memoryId
|
|
8787
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8642
8788
|
* @param data.pollDelayMs delay between polling for job updates in milliseconds
|
|
8643
8789
|
* @returns string server-sent events stream of job updates
|
|
8644
8790
|
* @throws ApiError
|
|
@@ -8908,7 +9054,7 @@ var JobService = class {
|
|
|
8908
9054
|
* Header's key lowercased and '-'' replaced to '_' such that 'Content-Type' becomes the 'content_type' arg key
|
|
8909
9055
|
*
|
|
8910
9056
|
* @param data.invisibleToOwner make the run invisible to the the flow owner (default false)
|
|
8911
|
-
* @param data.memoryId
|
|
9057
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8912
9058
|
* @returns string job created
|
|
8913
9059
|
* @throws ApiError
|
|
8914
9060
|
*/
|
|
@@ -8951,7 +9097,7 @@ var JobService = class {
|
|
|
8951
9097
|
* Header's key lowercased and '-'' replaced to '_' such that 'Content-Type' becomes the 'content_type' arg key
|
|
8952
9098
|
*
|
|
8953
9099
|
* @param data.invisibleToOwner make the run invisible to the the flow owner (default false)
|
|
8954
|
-
* @param data.memoryId
|
|
9100
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
8955
9101
|
* @returns string job created
|
|
8956
9102
|
* @throws ApiError
|
|
8957
9103
|
*/
|
|
@@ -9266,7 +9412,7 @@ var JobService = class {
|
|
|
9266
9412
|
*
|
|
9267
9413
|
* @param data.invisibleToOwner make the run invisible to the the script owner (default false)
|
|
9268
9414
|
* @param data.jobId The job id to assign to the created job. if missing, job is chosen randomly using the ULID scheme. If a job id already exists in the queue or as a completed job, the request to create one will fail (Bad Request)
|
|
9269
|
-
* @param data.memoryId
|
|
9415
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
9270
9416
|
* @returns string job created
|
|
9271
9417
|
* @throws ApiError
|
|
9272
9418
|
*/
|
|
@@ -9290,7 +9436,7 @@ var JobService = class {
|
|
|
9290
9436
|
* @param data The data for the request.
|
|
9291
9437
|
* @param data.workspace
|
|
9292
9438
|
* @param data.requestBody preview
|
|
9293
|
-
* @param data.memoryId
|
|
9439
|
+
* @param data.memoryId Memory id for the flow's AI agent steps. A uuid is used as is; any other string is hashed within the workspace and flow, so the same string always names the same memory of that flow.
|
|
9294
9440
|
* @returns unknown job result
|
|
9295
9441
|
* @throws ApiError
|
|
9296
9442
|
*/
|
|
@@ -11065,6 +11211,7 @@ var FlowConversationsService = class {
|
|
|
11065
11211
|
* @param data.page which page to return (start at 1, default 1)
|
|
11066
11212
|
* @param data.perPage number of items to return for a given page (default 30, max 100)
|
|
11067
11213
|
* @param data.flowPath filter conversations by flow path
|
|
11214
|
+
* @param data.kind which conversations to list - the flow editor's test chats, the deployed flow's own (the default), or both
|
|
11068
11215
|
* @returns FlowConversation flow conversations list
|
|
11069
11216
|
* @throws ApiError
|
|
11070
11217
|
*/
|
|
@@ -11076,11 +11223,33 @@ var FlowConversationsService = class {
|
|
|
11076
11223
|
query: {
|
|
11077
11224
|
page: data.page,
|
|
11078
11225
|
per_page: data.perPage,
|
|
11079
|
-
flow_path: data.flowPath
|
|
11226
|
+
flow_path: data.flowPath,
|
|
11227
|
+
kind: data.kind
|
|
11080
11228
|
}
|
|
11081
11229
|
});
|
|
11082
11230
|
}
|
|
11083
11231
|
/**
|
|
11232
|
+
* rename flow conversation
|
|
11233
|
+
* @param data The data for the request.
|
|
11234
|
+
* @param data.workspace
|
|
11235
|
+
* @param data.conversationId conversation id
|
|
11236
|
+
* @param data.requestBody
|
|
11237
|
+
* @returns string flow conversation updated
|
|
11238
|
+
* @throws ApiError
|
|
11239
|
+
*/
|
|
11240
|
+
static updateFlowConversation(data) {
|
|
11241
|
+
return request(OpenAPI, {
|
|
11242
|
+
method: "POST",
|
|
11243
|
+
url: "/w/{workspace}/flow_conversations/update/{conversation_id}",
|
|
11244
|
+
path: {
|
|
11245
|
+
workspace: data.workspace,
|
|
11246
|
+
conversation_id: data.conversationId
|
|
11247
|
+
},
|
|
11248
|
+
body: data.requestBody,
|
|
11249
|
+
mediaType: "application/json"
|
|
11250
|
+
});
|
|
11251
|
+
}
|
|
11252
|
+
/**
|
|
11084
11253
|
* delete flow conversation
|
|
11085
11254
|
* @param data The data for the request.
|
|
11086
11255
|
* @param data.workspace
|
package/dist/sqlUtils.d.ts
CHANGED
|
@@ -55,9 +55,15 @@ export interface SqlTemplateFunction {
|
|
|
55
55
|
export interface DatatableSqlTemplateFunction extends SqlTemplateFunction {
|
|
56
56
|
query<T = any>(sql: string, ...params: any[]): SqlStatement<T>;
|
|
57
57
|
}
|
|
58
|
+
export interface DatatableOptions {
|
|
59
|
+
/** The data table role to connect as. Omit to get the data table's default role. */
|
|
60
|
+
role?: string;
|
|
61
|
+
}
|
|
58
62
|
/**
|
|
59
63
|
* Create a SQL template function for PostgreSQL/datatable queries
|
|
60
64
|
* @param name - Database/datatable name (default: "main")
|
|
65
|
+
* @param opts.role - Connect as this data table role instead of the data table's default one.
|
|
66
|
+
* Only meaningful on a data table under roles, and only for a role you are a tenant of.
|
|
61
67
|
* @returns SQL template function for building parameterized queries
|
|
62
68
|
* @example
|
|
63
69
|
* let sql = wmill.datatable()
|
|
@@ -67,8 +73,11 @@ export interface DatatableSqlTemplateFunction extends SqlTemplateFunction {
|
|
|
67
73
|
* SELECT * FROM friends
|
|
68
74
|
* WHERE name = ${name} AND age = ${age}::int
|
|
69
75
|
* `.fetch()
|
|
76
|
+
* @example
|
|
77
|
+
* // Read through a restricted role
|
|
78
|
+
* let sql = wmill.datatable("main", { role: "analytics" })
|
|
70
79
|
*/
|
|
71
|
-
export declare function datatable(name?: string): DatatableSqlTemplateFunction;
|
|
80
|
+
export declare function datatable(name?: string, opts?: DatatableOptions): DatatableSqlTemplateFunction;
|
|
72
81
|
/**
|
|
73
82
|
* Create a SQL template function for DuckDB/ducklake queries
|
|
74
83
|
* @param name - DuckDB database name, optionally with a schema as `name:schema` (default: "main")
|
package/dist/sqlUtils.mjs
CHANGED
|
@@ -13,11 +13,14 @@ var RawSql = class {
|
|
|
13
13
|
this.value = value;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
const ROLE_NAME_RE = /^[A-Za-z0-9_-]{1,63}$/;
|
|
17
|
+
function datatableProvider(name, schema, role) {
|
|
18
|
+
if (role !== void 0 && !ROLE_NAME_RE.test(role)) throw new Error(`Invalid data table role '${role}': only letters, digits, '_' and '-' are allowed`);
|
|
17
19
|
return {
|
|
18
20
|
providerName: "datatable",
|
|
19
21
|
language: "postgresql",
|
|
20
22
|
extraArgs: { database: `datatable://${name}` },
|
|
23
|
+
annotations: () => role !== void 0 ? `-- role ${role}\n` : "",
|
|
21
24
|
formatArgDecl: (argNum) => `-- $${argNum} arg${argNum}`,
|
|
22
25
|
formatArgUsage: (argNum, explicitType, inferredType) => explicitType !== void 0 ? `$${argNum}` : `$${argNum}::${inferredType}`,
|
|
23
26
|
preamble: () => schema ? `SET search_path TO "${schema}";\n` : ""
|
|
@@ -28,6 +31,7 @@ function ducklakeProvider(name, schema) {
|
|
|
28
31
|
providerName: "ducklake",
|
|
29
32
|
language: "duckdb",
|
|
30
33
|
extraArgs: {},
|
|
34
|
+
annotations: () => "",
|
|
31
35
|
formatArgDecl: (argNum, argType) => `-- $arg${argNum} (${argType})`,
|
|
32
36
|
formatArgUsage: (argNum) => `$arg${argNum}`,
|
|
33
37
|
preamble: () => `ATTACH 'ducklake://${name}' AS dl;USE dl${schema ? `."${schema}"` : ""};\n`
|
|
@@ -115,7 +119,8 @@ function buildSqlTemplateFunction(provider) {
|
|
|
115
119
|
let argType = parseTypeAnnotation(strings[info.originalIndex], strings[info.originalIndex + 1]) || inferSqlType(info.value);
|
|
116
120
|
return provider.formatArgDecl(info.argNum, argType);
|
|
117
121
|
});
|
|
118
|
-
let content =
|
|
122
|
+
let content = provider.annotations();
|
|
123
|
+
content += argDecls.length ? argDecls.join("\n") + "\n" : "";
|
|
119
124
|
content += provider.preamble();
|
|
120
125
|
let contentBody = "";
|
|
121
126
|
for (let i = 0; i < strings.length; i++) {
|
|
@@ -143,6 +148,8 @@ function buildSqlTemplateFunction(provider) {
|
|
|
143
148
|
/**
|
|
144
149
|
* Create a SQL template function for PostgreSQL/datatable queries
|
|
145
150
|
* @param name - Database/datatable name (default: "main")
|
|
151
|
+
* @param opts.role - Connect as this data table role instead of the data table's default one.
|
|
152
|
+
* Only meaningful on a data table under roles, and only for a role you are a tenant of.
|
|
146
153
|
* @returns SQL template function for building parameterized queries
|
|
147
154
|
* @example
|
|
148
155
|
* let sql = wmill.datatable()
|
|
@@ -152,15 +159,18 @@ function buildSqlTemplateFunction(provider) {
|
|
|
152
159
|
* SELECT * FROM friends
|
|
153
160
|
* WHERE name = ${name} AND age = ${age}::int
|
|
154
161
|
* `.fetch()
|
|
162
|
+
* @example
|
|
163
|
+
* // Read through a restricted role
|
|
164
|
+
* let sql = wmill.datatable("main", { role: "analytics" })
|
|
155
165
|
*/
|
|
156
|
-
function datatable(name = "main") {
|
|
166
|
+
function datatable(name = "main", opts) {
|
|
157
167
|
let { name: n, schema } = parseName(name);
|
|
158
|
-
let provider = datatableProvider(n, schema);
|
|
168
|
+
let provider = datatableProvider(n, schema, opts?.role);
|
|
159
169
|
let sqlFn = buildSqlTemplateFunction(provider);
|
|
160
170
|
sqlFn.query = (sqlString, ...params) => {
|
|
161
171
|
let argDecls = params.map((v, i) => `-- $${i + 1} arg${i + 1} (${inferSqlType(v)})`).join("\n");
|
|
162
172
|
let contentBody = sqlString;
|
|
163
|
-
let content = (argDecls ? argDecls + "\n" : "") + provider.preamble() + sqlString;
|
|
173
|
+
let content = provider.annotations() + (argDecls ? argDecls + "\n" : "") + provider.preamble() + sqlString;
|
|
164
174
|
let args = {
|
|
165
175
|
...Object.fromEntries(params.map((v, i) => [`arg${i + 1}`, serializeArgValue(v)])),
|
|
166
176
|
...provider.extraArgs
|