diff --git a/src/runtime/composables/surreal-db.ts b/src/runtime/composables/surreal-db.ts index edf48d1..51cfd80 100644 --- a/src/runtime/composables/surreal-db.ts +++ b/src/runtime/composables/surreal-db.ts @@ -4,6 +4,8 @@ import { hash } from 'ohash' import type { Overrides, + RpcMethods, + RpcParams, RpcRequest, RpcResponse, SurrealRpcOptions, @@ -18,6 +20,8 @@ import { useSurrealRPC, } from '#imports' +type MROGParam, N extends number> = MaybeRefOrGetter[N]> + export function useSurrealDB(overrides?: Overrides) { const { $surrealFetch, $surrealFetchOptionsOverride, $surrealRPC } = useNuxtApp() @@ -32,15 +36,15 @@ export function useSurrealDB(overrides?: Overrides) { // query [ sql, vars ] async function $query( - sql: RpcRequest['params'][0], - opts?: Overrides & { vars?: RpcRequest['params'][1] }, + sql: MROGParam, + opts?: Overrides & { vars?: MROGParam }, ) { const { vars, ...ovr } = opts || {} - return $surrealRPC({ method: 'query', params: [sql, vars] }, ovr) + return $surrealRPC({ method: 'query', params: [toValue(sql), toValue(vars)] }, ovr) } async function query( - sql: MaybeRefOrGetter['params'][0]>, - options?: SurrealRpcOptions & { vars?: MaybeRefOrGetter['params'][1]> }, + sql: MROGParam, + options?: SurrealRpcOptions & { vars?: MROGParam }, ): Promise | null, FetchError | null>> { const { key, vars, watch, ...opts } = options || {} @@ -56,13 +60,13 @@ export function useSurrealDB(overrides?: Overrides) { // select [ thing ] async function $select( - thing: RpcRequest['params'][0], + thing: MROGParam, ovr?: Overrides, ) { - return $surrealRPC({ method: 'select', params: [thing] }, ovr) + return $surrealRPC({ method: 'select', params: [toValue(thing)] }, ovr) } async function select( - thing: MaybeRefOrGetter['params'][0]>, + thing: MROGParam, options?: SurrealRpcOptions, ): Promise | null, FetchError | null>> { const { key, watch, ...opts } = options || {}