@@ -316,7 +316,27 @@ export const fireQuerySync = (args: FireQueryArgs): QueryResult[] => {
316316 } ) ) ;
317317} ;
318318
319- const PROP_NAME_RE = new RegExp ( / \: \w + \/ \w + \b / , "g" ) ;
319+ const PROP_NAME_RE = / : \w + \/ \w + \b / g;
320+
321+ const renamePropsInResult = (
322+ result : json | null ,
323+ mapping : Record < string , string > ,
324+ ) : json | null => {
325+ const rename = ( x : json | null ) : json | null => {
326+ if ( Array . isArray ( x ) ) return x . map ( rename ) ;
327+ if ( x === null || x === undefined ) return x ;
328+ if ( typeof x === "object" ) {
329+ return Object . fromEntries (
330+ Object . entries ( x as object ) . map ( ( [ k , v ] ) => [
331+ mapping [ k ] || k ,
332+ rename ( v ) ,
333+ ] ) ,
334+ ) ;
335+ }
336+ return x ;
337+ } ;
338+ return rename ( result ) ;
339+ } ;
320340
321341const fireQuery : FireQuery = async ( _args ) => {
322342 const { isCustomEnabled, customNode, local, ...args } = _args ;
@@ -364,20 +384,10 @@ const fireQuery: FireQuery = async (_args) => {
364384 // no name conflict, safe to use async query
365385 // BUT it returns non-namespaced names, so substitute prop names back
366386 queryResults = await window . roamAlphaAPI . data . async . q ( query , ...inputs ) ;
367- const renameProps = ( x : json | null ) : json | null => {
368- if ( Array . isArray ( x ) ) return x . map ( renameProps ) ;
369- if ( x === null || x === undefined ) return x ;
370- if ( typeof x === "object" ) {
371- return Object . fromEntries (
372- Object . entries ( x as object ) . map ( ( [ k , v ] ) => [
373- propNamesSub [ k ] || k ,
374- renameProps ( v ) , // eslint-disable-line @typescript-eslint/no-unsafe-argument
375- ] ) ,
376- ) ;
377- }
378- return x ;
379- } ;
380- queryResults = renameProps ( queryResults as json ) as unknown [ ] [ ] ;
387+ queryResults = renamePropsInResult (
388+ queryResults as json ,
389+ propNamesSub ,
390+ ) as unknown [ ] [ ] ;
381391 } else {
382392 // more janky but safer
383393 queryResults = window . roamAlphaAPI . data . fast . q ( query , ...inputs ) ;
0 commit comments