Fix typecheck datatable and ducklake in TS

This commit is contained in:
Diego Imbert
2025-12-01 11:26:09 +01:00
parent f3dea5da2d
commit a893f9c92a
3 changed files with 60 additions and 18 deletions
+18
View File
@@ -2789,6 +2789,24 @@ paths:
items:
type: string
/w/{workspace}/workspaces/list_datatables:
get:
summary: list Datatables
operationId: listDataTables
tags:
- workspace
parameters:
- $ref: "#/components/parameters/WorkspaceId"
responses:
"200":
description: status
content:
application/json:
schema:
type: array
items:
type: string
/w/{workspace}/workspaces/edit_ducklake_config:
post:
summary: edit ducklake settings
+23
View File
@@ -127,6 +127,7 @@ pub fn workspaced_service() -> Router {
)
.route("/edit_ducklake_config", post(edit_ducklake_config))
.route("/list_ducklakes", get(list_ducklakes))
.route("/list_datatables", get(list_datatables))
.route("/edit_datatable_config", post(edit_datatable_config))
.route("/edit_git_sync_config", post(edit_git_sync_config))
.route("/edit_git_sync_repository", post(edit_git_sync_repository))
@@ -1165,6 +1166,28 @@ async fn list_ducklakes(
Ok(Json(ducklakes))
}
async fn list_datatables(
_authed: ApiAuthed,
Extension(db): Extension<DB>,
Path(w_id): Path<String>,
) -> JsonResult<Vec<String>> {
let datatables = sqlx::query_scalar!(
r#"
SELECT jsonb_object_keys(ws.datatable->'datatables') AS datatable_name
FROM workspace_settings ws
WHERE ws.workspace_id = $1
"#,
&w_id
)
.fetch_all(&db)
.await?
.into_iter()
.filter_map(|s| s)
.collect();
Ok(Json(datatables))
}
async fn edit_ducklake_config(
authed: ApiAuthed,
Extension(db): Extension<DB>,
+19 -18
View File
@@ -44,8 +44,8 @@
type Preview,
ResourceService,
type ScriptLang,
SettingService,
UserService
UserService,
WorkspaceService
} from '$lib/gen'
import type { Text } from 'yjs'
import {
@@ -1464,17 +1464,17 @@
ata?.(deps)
}
let customInstanceDbs = resource([], SettingService.listCustomInstanceDbs)
let customTsTypesData = resource([], async () => {
let datatables = await WorkspaceService.listDataTables({ workspace: $workspaceStore ?? '' })
let ducklakes = await WorkspaceService.listDucklakes({ workspace: $workspaceStore ?? '' })
return { datatables, ducklakes }
})
function setTypescriptCustomTypes() {
if (!customTsTypesData.current) return
if (lang !== 'typescript') return
if (!Object.keys(customInstanceDbs.current ?? {}).length) return
const ducklakeNames = Object.entries(customInstanceDbs.current ?? {})
.filter(([_, { tag }]) => tag === 'ducklake')
.map(([name, _]) => name)
const datatableNames = Object.entries(customInstanceDbs.current ?? {})
.filter(([_, { tag }]) => tag === 'datatable')
.map(([name, _]) => name)
const ducklakeNames = customTsTypesData.current.ducklakes
const datatableNames = customTsTypesData.current.datatables
const ducklakeNameType = ducklakeNames.length
? ducklakeNames.map((name) => JSON.stringify(name)).join(' | ')
@@ -1482,19 +1482,20 @@
const datatableNameType = datatableNames.length
? datatableNames.map((name) => JSON.stringify(name)).join(' | ')
: 'string'
const isDucklakeOptional = ducklakeNames.includes('main')
const isDataTableOptional = datatableNames.includes('main')
languages.typescript.typescriptDefaults.addExtraLib(
let disposeTs = languages.typescript.typescriptDefaults.addExtraLib(
`declare module 'windmill-client' {
// Completely replace the module's types
export function ducklake(name: ${ducklakeNameType}): SqlTemplateFunction;
export function datatable(name: ${datatableNameType}): SqlTemplateFunction;
export function ducklake(name${isDucklakeOptional ? '?' : ''}: ${ducklakeNameType}): SqlTemplateFunction;
export function datatable(name${isDataTableOptional ? '?' : ''}: ${datatableNameType}): SqlTemplateFunction;
}`,
'ts:custom_wmill_types.d.ts'
)
console.log('added custom windmill types', {
ducklakeNameType,
datatableNameType
})
return () => {
disposeTs.dispose()
}
}
async function setTypescriptRTNamespace() {
@@ -1805,7 +1806,7 @@
})
})
watch([() => lang, () => customInstanceDbs.current], setTypescriptCustomTypes)
watch([() => customTsTypesData.current], setTypescriptCustomTypes)
</script>
<svelte:window onkeydown={onKeyDown} />