Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/roam/src/utils/conceptConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,21 @@ export const discourseNodeSchemaToLocalConcept = (
node: DiscourseNode,
): LocalConceptDataInput => {
const titleParts = node.text.split("/");
const label = titleParts[titleParts.length - 1] ?? node.text;
const result: LocalConceptDataInput = {
space_id: context.spaceId,
name: node.text,
source_local_id: node.type,
is_schema: true,
literal_content: {
label,
},
/* eslint-enable @typescript-eslint/naming-convention */
...getNodeExtraData(node.type),
};
if (node.template !== undefined)
result.literal_content = {
label: titleParts[titleParts.length - 1],
label,
template: templateToText(node.template),
};
return result;
Expand Down
9 changes: 4 additions & 5 deletions apps/roam/src/utils/convertRoamNodeToFullContent.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import type { CrossAppNode } from "@repo/database/crossAppNodeContract";
import { buildFullMarkdown } from "./convertRoamNodeToFullContent";

/**
* Typed example for ENG-1848 ("tests or fixtures cover representative Roam
* block content becoming `full` markdown"). This is not a concrete test; it
* documents the `tree.children` shape returned by `getFullTreeByParentUid` for
* a real Roam claim page and type-checks the generated markdown against the
* contract.
* Typed example for ENG-1848 full markdown coverage. This is not a concrete
* test; it documents the `tree.children` shape returned by
* `getFullTreeByParentUid` for a real Roam claim page and type-checks the
* generated markdown against the contract.
*
* Derived from:
* https://roamresearch.com/#/app/plugin-testing-akamatsulab2/page/dnHNmYwe5
Expand Down
46 changes: 46 additions & 0 deletions apps/roam/src/utils/convertRoamNodeToFullContent.simple.example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import type { TreeNode } from "roamjs-components/types";
import type { CrossAppNode } from "@repo/database/crossAppNodeContract";
import { buildFullMarkdown } from "./convertRoamNodeToFullContent";

/**
* Small typed example for ENG-1848/ENG-1852 full markdown validation. The Roam
* app has no unit-test runner, so this keeps a compact in-memory tree that
* type-checks the generated markdown against the shared cross-app contract.
*/

const block = (text: string, children: TreeNode[] = []): TreeNode => ({
text,
children,
order: 0,
parents: [],
uid: "",
heading: 0,
open: true,
viewType: "bullet",
blockViewType: "outline",
editTime: new Date(0),
textAlign: "left",
props: { imageResize: {}, iframe: {} },
});

const title = "Sleep improves memory consolidation";

const blocks: TreeNode[] = [
block(
"Multiple studies show that sleep after learning strengthens memory traces.",
),
block("Supporting evidence:", [block("[[EVD]] - Rasch & Born 2013")]),
];

export const roamClaimFullMarkdownSimpleExample: {
title: string;
blocks: TreeNode[];
full: CrossAppNode["content"]["full"];
} = {
title,
blocks,
full: {
format: "text/markdown",
value: buildFullMarkdown({ title, blocks }),
},
};
12 changes: 10 additions & 2 deletions apps/roam/src/utils/convertRoamNodeToFullContent.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { toMarkdown } from "./pageToMarkdown";
import { type RoamDiscourseNodeData } from "./getAllDiscourseNodesSince";
import { type DiscourseNode } from "./getDiscourseNodes";
import getFullTreeByParentUid from "roamjs-components/queries/getFullTreeByParentUid";
import getPageViewType from "roamjs-components/queries/getPageViewType";
import type { TreeNode, ViewType } from "roamjs-components/types";
import type { LocalContentDataInput } from "@repo/database/inputTypes";

export type RoamFullContentNode = {
author_local_id: string;
source_local_id: string;
created: string | number;
last_modified: string | number;
text: string;
node_title?: string;
};

const FULL_MARKDOWN_OPTS = {
refs: true,
embeds: true,
Expand Down Expand Up @@ -38,7 +46,7 @@ export const buildFullMarkdown = ({
export const convertRoamNodeToFullContent = ({
nodes,
}: {
nodes: RoamDiscourseNodeData[];
nodes: RoamFullContentNode[];
}): LocalContentDataInput[] =>
nodes.flatMap((node) => {
try {
Expand Down
Loading