Line data Source code
1 : import * as dashql from '@ankoh/dashql-core';
2 :
3 : import { generateFunctionScriptHeader } from './catalog_function_sql_generator.js';
4 : import { CatalogSource } from './catalog_sql_generator.js';
5 : import { publishCatalogBatchSync } from './catalog_batch.js';
6 :
7 : import prefetchedHyperFunctionsSql from '../../../static/catalog/hyper/dashql-catalog-functions.sql?raw';
8 :
9 1 : export const PREFETCHED_HYPER_FUNCTIONS_SQL = prefetchedHyperFunctionsSql;
10 :
11 1 : export function qualifyPrefetchedHyperFunctions(databaseName: string, updatedAt: Date = new Date()): string {
12 1 : const quotedDatabase = `"${databaseName.replace(/"/g, '""')}"`;
13 1 : const functions = PREFETCHED_HYPER_FUNCTIONS_SQL.replace(
14 1 : /"hyper"\./g,
15 1 : `${quotedDatabase}.`,
16 1 : );
17 1 : return `${generateFunctionScriptHeader(CatalogSource.Hyper, updatedAt)}${functions}`;
18 1 : }
19 :
20 1 : export async function fetchPrefetchedHyperFunctions(signal?: AbortSignal): Promise<string> {
21 1 : signal?.throwIfAborted();
22 1 : return PREFETCHED_HYPER_FUNCTIONS_SQL;
23 1 : }
24 :
25 1 : export function loadPrefetchedHyperFunctions(
26 1 : dql: dashql.DashQL,
27 1 : catalog: dashql.DashQLCatalog,
28 1 : catalogFunctionScript: dashql.DashQLScript,
29 1 : sql: string,
30 1 : ): number {
31 1 : return publishCatalogBatchSync(dql, catalog, [{
32 1 : script: catalogFunctionScript, text: sql, requireFunctions: true,
33 1 : }])[0].functions;
34 1 : }
|