Skip to content

Commit 204b73b

Browse files
committed
correction, coderabbit nits
1 parent e1a40c3 commit 204b73b

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

apps/roam/src/utils/fireQuery.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

321341
const 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);

apps/roam/src/utils/getExportTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ const getExportTypes = ({
374374
);
375375
};
376376
const getRelationData = () =>
377-
getRelationDataUtil(allRelations, nodeLabelByType);
377+
getRelationDataUtil({ allRelations, nodeLabelByType, local: true });
378378

379379
const getJsonData = async () => {
380380
const grammar = allRelations.map(({ label, destination, source }) => ({

0 commit comments

Comments
 (0)