roamjs-components 0.85.2 → 0.85.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +29 -29
- package/components/AutocompleteInput.d.ts +28 -0
- package/components/AutocompleteInput.js +121 -0
- package/components/AutocompleteInput.js.map +1 -0
- package/components/BlockErrorBoundary.d.ts +15 -0
- package/components/BlockErrorBoundary.js +28 -0
- package/components/BlockErrorBoundary.js.map +1 -0
- package/components/BlockInput.d.ts +13 -0
- package/components/BlockInput.js +56 -0
- package/components/BlockInput.js.map +1 -0
- package/components/ComponentContainer.d.ts +10 -0
- package/components/ComponentContainer.js +38 -0
- package/components/ComponentContainer.js.map +1 -0
- package/components/ConfigPage.d.ts +35 -0
- package/components/ConfigPage.js +160 -0
- package/components/ConfigPage.js.map +1 -0
- package/components/ConfigPanels/BlockPanel.d.ts +3 -0
- package/components/ConfigPanels/BlockPanel.js +43 -0
- package/components/ConfigPanels/BlockPanel.js.map +1 -0
- package/components/ConfigPanels/BlocksPanel.d.ts +3 -0
- package/components/ConfigPanels/BlocksPanel.js +69 -0
- package/components/ConfigPanels/BlocksPanel.js.map +1 -0
- package/components/ConfigPanels/CustomPanel.d.ts +3 -0
- package/components/ConfigPanels/CustomPanel.js +25 -0
- package/components/ConfigPanels/CustomPanel.js.map +1 -0
- package/components/ConfigPanels/FlagPanel.d.ts +3 -0
- package/components/ConfigPanels/FlagPanel.js +32 -0
- package/components/ConfigPanels/FlagPanel.js.map +1 -0
- package/components/ConfigPanels/MultiChildPanel.d.ts +9 -0
- package/components/ConfigPanels/MultiChildPanel.js +59 -0
- package/components/ConfigPanels/MultiChildPanel.js.map +1 -0
- package/components/ConfigPanels/MultiTextPanel.d.ts +3 -0
- package/components/ConfigPanels/MultiTextPanel.js +15 -0
- package/components/ConfigPanels/MultiTextPanel.js.map +1 -0
- package/components/ConfigPanels/NumberPanel.d.ts +3 -0
- package/components/ConfigPanels/NumberPanel.js +26 -0
- package/components/ConfigPanels/NumberPanel.js.map +1 -0
- package/components/ConfigPanels/OauthPanel.d.ts +3 -0
- package/components/ConfigPanels/OauthPanel.js +82 -0
- package/components/ConfigPanels/OauthPanel.js.map +1 -0
- package/components/ConfigPanels/PagesPanel.d.ts +3 -0
- package/components/ConfigPanels/PagesPanel.js +12 -0
- package/components/ConfigPanels/PagesPanel.js.map +1 -0
- package/components/ConfigPanels/SelectPanel.d.ts +3 -0
- package/components/ConfigPanels/SelectPanel.js +28 -0
- package/components/ConfigPanels/SelectPanel.js.map +1 -0
- package/components/ConfigPanels/TextPanel.d.ts +3 -0
- package/components/ConfigPanels/TextPanel.js +29 -0
- package/components/ConfigPanels/TextPanel.js.map +1 -0
- package/components/ConfigPanels/TimePanel.d.ts +3 -0
- package/components/ConfigPanels/TimePanel.js +35 -0
- package/components/ConfigPanels/TimePanel.js.map +1 -0
- package/components/ConfigPanels/getBrandColors.d.ts +7 -0
- package/components/ConfigPanels/getBrandColors.js +29 -0
- package/components/ConfigPanels/getBrandColors.js.map +1 -0
- package/components/ConfigPanels/types.d.ts +84 -0
- package/components/ConfigPanels/types.js +3 -0
- package/components/ConfigPanels/types.js.map +1 -0
- package/components/ConfigPanels/useSingleChildValue.d.ts +13 -0
- package/components/ConfigPanels/useSingleChildValue.js +44 -0
- package/components/ConfigPanels/useSingleChildValue.js.map +1 -0
- package/components/CursorMenu.d.ts +21 -0
- package/components/CursorMenu.js +182 -0
- package/components/CursorMenu.js.map +1 -0
- package/components/Description.d.ts +5 -0
- package/components/Description.js +17 -0
- package/components/Description.js.map +1 -0
- package/components/ExtensionApiContext.d.ts +31 -0
- package/components/ExtensionApiContext.js +17 -0
- package/components/ExtensionApiContext.js.map +1 -0
- package/components/ExternalLogin.d.ts +18 -0
- package/components/ExternalLogin.js +142 -0
- package/components/ExternalLogin.js.map +1 -0
- package/components/Filter.d.ts +15 -0
- package/components/Filter.js +143 -0
- package/components/Filter.js.map +1 -0
- package/components/FormDialog.d.ts +55 -0
- package/components/FormDialog.js +224 -0
- package/components/FormDialog.js.map +1 -0
- package/components/Loading.d.ts +4 -0
- package/components/Loading.js +36 -0
- package/components/Loading.js.map +1 -0
- package/components/MenuItemSelect.d.ts +17 -0
- package/components/MenuItemSelect.js +24 -0
- package/components/MenuItemSelect.js.map +1 -0
- package/components/OauthPanel.d.ts +7 -0
- package/components/OauthPanel.js +31 -0
- package/components/OauthPanel.js.map +1 -0
- package/components/OauthSelect.d.ts +5 -0
- package/components/OauthSelect.js +26 -0
- package/components/OauthSelect.js.map +1 -0
- package/components/PageInput.d.ts +6 -0
- package/components/PageInput.js +14 -0
- package/components/PageInput.js.map +1 -0
- package/components/PageLink.d.ts +6 -0
- package/components/PageLink.js +32 -0
- package/components/PageLink.js.map +1 -0
- package/components/ProgressDialog.d.ts +11 -0
- package/components/ProgressDialog.js +61 -0
- package/components/ProgressDialog.js.map +1 -0
- package/components/SimpleAlert.d.ts +15 -0
- package/components/SimpleAlert.js +48 -0
- package/components/SimpleAlert.js.map +1 -0
- package/components/Toast.d.ts +15 -0
- package/components/Toast.js +51 -0
- package/components/Toast.js.map +1 -0
- package/components/index.d.ts +0 -0
- package/components/index.js +5 -0
- package/components/index.js.map +1 -0
- package/components.d.ts +5 -0
- package/components.js +171 -0
- package/components.js.map +1 -0
- package/date/constants.d.ts +3 -0
- package/date/constants.js +20 -0
- package/date/constants.js.map +1 -0
- package/{src/date/index.ts → date/index.d.ts} +3 -3
- package/date/index.js +10 -0
- package/date/index.js.map +1 -0
- package/date/parseNlpDate.d.ts +5 -0
- package/date/parseNlpDate.js +227 -0
- package/date/parseNlpDate.js.map +1 -0
- package/date/parseRoamDateUid.d.ts +2 -0
- package/date/parseRoamDateUid.js +8 -0
- package/date/parseRoamDateUid.js.map +1 -0
- package/dom/addBlockCommand.d.ts +5 -0
- package/dom/addBlockCommand.js +54 -0
- package/dom/addBlockCommand.js.map +1 -0
- package/dom/addKeyboardTriggers.d.ts +11 -0
- package/dom/addKeyboardTriggers.js +39 -0
- package/dom/addKeyboardTriggers.js.map +1 -0
- package/dom/addOldRoamJSDependency.d.ts +2 -0
- package/dom/addOldRoamJSDependency.js +11 -0
- package/dom/addOldRoamJSDependency.js.map +1 -0
- package/dom/addRoamJSDependency.d.ts +2 -0
- package/dom/addRoamJSDependency.js +9 -0
- package/dom/addRoamJSDependency.js.map +1 -0
- package/dom/addScriptAsDependency.d.ts +6 -0
- package/dom/addScriptAsDependency.js +17 -0
- package/dom/addScriptAsDependency.js.map +1 -0
- package/dom/addStyle.d.ts +2 -0
- package/dom/addStyle.js +15 -0
- package/dom/addStyle.js.map +1 -0
- package/dom/constants.d.ts +1 -0
- package/dom/constants.js +5 -0
- package/dom/constants.js.map +1 -0
- package/dom/createBlockObserver.d.ts +7 -0
- package/dom/createBlockObserver.js +44 -0
- package/dom/createBlockObserver.js.map +1 -0
- package/dom/createButtonObserver.d.ts +6 -0
- package/dom/createButtonObserver.js +22 -0
- package/dom/createButtonObserver.js.map +1 -0
- package/dom/createDivObserver.d.ts +2 -0
- package/dom/createDivObserver.js +14 -0
- package/dom/createDivObserver.js.map +1 -0
- package/dom/createHTMLObserver.d.ts +8 -0
- package/dom/createHTMLObserver.js +25 -0
- package/dom/createHTMLObserver.js.map +1 -0
- package/dom/createHashtagObserver.d.ts +5 -0
- package/dom/createHashtagObserver.js +17 -0
- package/dom/createHashtagObserver.js.map +1 -0
- package/dom/createIconButton.d.ts +2 -0
- package/dom/createIconButton.js +13 -0
- package/dom/createIconButton.js.map +1 -0
- package/dom/createObserver.d.ts +2 -0
- package/dom/createObserver.js +10 -0
- package/dom/createObserver.js.map +1 -0
- package/dom/createOverlayObserver.d.ts +2 -0
- package/dom/createOverlayObserver.js +7 -0
- package/dom/createOverlayObserver.js.map +1 -0
- package/dom/createPageObserver.d.ts +2 -0
- package/dom/createPageObserver.js +35 -0
- package/dom/createPageObserver.js.map +1 -0
- package/dom/createPageTitleObserver.d.ts +6 -0
- package/dom/createPageTitleObserver.js +32 -0
- package/dom/createPageTitleObserver.js.map +1 -0
- package/dom/elToTitle.d.ts +2 -0
- package/dom/elToTitle.js +23 -0
- package/dom/elToTitle.js.map +1 -0
- package/dom/genericError.d.ts +3 -0
- package/dom/genericError.js +12 -0
- package/dom/genericError.js.map +1 -0
- package/dom/getActiveUids.d.ts +3 -0
- package/dom/getActiveUids.js +7 -0
- package/dom/getActiveUids.js.map +1 -0
- package/dom/getBlockUidFromTarget.d.ts +2 -0
- package/dom/getBlockUidFromTarget.js +34 -0
- package/dom/getBlockUidFromTarget.js.map +1 -0
- package/dom/getCurrentPageUid.d.ts +2 -0
- package/dom/getCurrentPageUid.js +9 -0
- package/dom/getCurrentPageUid.js.map +1 -0
- package/dom/getDomRefs.d.ts +2 -0
- package/dom/getDomRefs.js +13 -0
- package/dom/getDomRefs.js.map +1 -0
- package/dom/getDropUidOffset.d.ts +5 -0
- package/dom/getDropUidOffset.js +28 -0
- package/dom/getDropUidOffset.js.map +1 -0
- package/dom/getMutatedNodes.d.ts +7 -0
- package/dom/getMutatedNodes.js +12 -0
- package/dom/getMutatedNodes.js.map +1 -0
- package/dom/getPageTitleByHtmlElement.d.ts +2 -0
- package/dom/getPageTitleByHtmlElement.js +13 -0
- package/dom/getPageTitleByHtmlElement.js.map +1 -0
- package/dom/getPageTitleValueByHtmlElement.d.ts +2 -0
- package/dom/getPageTitleValueByHtmlElement.js +10 -0
- package/dom/getPageTitleValueByHtmlElement.js.map +1 -0
- package/dom/getReferenceBlockUid.d.ts +2 -0
- package/dom/getReferenceBlockUid.js +19 -0
- package/dom/getReferenceBlockUid.js.map +1 -0
- package/dom/getRoamUrl.d.ts +2 -0
- package/dom/getRoamUrl.js +5 -0
- package/dom/getRoamUrl.js.map +1 -0
- package/dom/getRoamUrlByPage.d.ts +2 -0
- package/dom/getRoamUrlByPage.js +11 -0
- package/dom/getRoamUrlByPage.js.map +1 -0
- package/dom/getUids.d.ts +3 -0
- package/dom/getUids.js +9 -0
- package/dom/getUids.js.map +1 -0
- package/dom/getUidsFromButton.d.ts +3 -0
- package/dom/getUidsFromButton.js +9 -0
- package/dom/getUidsFromButton.js.map +1 -0
- package/dom/getUidsFromId.d.ts +5 -0
- package/dom/getUidsFromId.js +16 -0
- package/dom/getUidsFromId.js.map +1 -0
- package/{src/dom/index.ts → dom/index.d.ts} +30 -30
- package/dom/index.js +64 -0
- package/dom/index.js.map +1 -0
- package/dom/parseRoamBlocksToHtml.d.ts +11 -0
- package/dom/parseRoamBlocksToHtml.js +80 -0
- package/dom/parseRoamBlocksToHtml.js.map +1 -0
- package/dom/resolveRefs.d.ts +2 -0
- package/dom/resolveRefs.js +25 -0
- package/dom/resolveRefs.js.map +1 -0
- package/{src/events/index.ts → events/index.d.ts} +1 -1
- package/events/index.js +9 -0
- package/events/index.js.map +1 -0
- package/events/watchOnce.d.ts +3 -0
- package/events/watchOnce.js +13 -0
- package/events/watchOnce.js.map +1 -0
- package/{src/hooks/index.ts → hooks/index.d.ts} +2 -2
- package/hooks/index.js +11 -0
- package/hooks/index.js.map +1 -0
- package/hooks/useArrowKeyDown.d.ts +10 -0
- package/hooks/useArrowKeyDown.js +55 -0
- package/hooks/useArrowKeyDown.js.map +1 -0
- package/hooks/useSubTree.d.ts +3 -0
- package/hooks/useSubTree.js +12 -0
- package/hooks/useSubTree.js.map +1 -0
- package/marked/index.d.ts +25 -0
- package/marked/index.js +568 -0
- package/marked/index.js.map +1 -0
- package/package.json +116 -116
- package/queries/compileDatalog.d.ts +3 -0
- package/queries/compileDatalog.js +64 -0
- package/queries/compileDatalog.js.map +1 -0
- package/queries/getAllBlockUids.d.ts +2 -0
- package/queries/getAllBlockUids.js +7 -0
- package/queries/getAllBlockUids.js.map +1 -0
- package/queries/getAllBlockUidsAndTexts.d.ts +5 -0
- package/queries/getAllBlockUidsAndTexts.js +7 -0
- package/queries/getAllBlockUidsAndTexts.js.map +1 -0
- package/queries/getAllPageNames.d.ts +2 -0
- package/queries/getAllPageNames.js +7 -0
- package/queries/getAllPageNames.js.map +1 -0
- package/queries/getAttributeValueByBlockAndName.d.ts +5 -0
- package/queries/getAttributeValueByBlockAndName.js +12 -0
- package/queries/getAttributeValueByBlockAndName.js.map +1 -0
- package/queries/getBasicTreeByParentUid.d.ts +3 -0
- package/queries/getBasicTreeByParentUid.js +14 -0
- package/queries/getBasicTreeByParentUid.js.map +1 -0
- package/queries/getBlockUidAndTextIncludingText.d.ts +5 -0
- package/queries/getBlockUidAndTextIncludingText.js +8 -0
- package/queries/getBlockUidAndTextIncludingText.js.map +1 -0
- package/queries/getBlockUidByTextOnPage.d.ts +5 -0
- package/queries/getBlockUidByTextOnPage.js +8 -0
- package/queries/getBlockUidByTextOnPage.js.map +1 -0
- package/queries/getBlockUidsAndTextsReferencingPage.d.ts +5 -0
- package/queries/getBlockUidsAndTextsReferencingPage.js +10 -0
- package/queries/getBlockUidsAndTextsReferencingPage.js.map +1 -0
- package/queries/getBlockUidsByPageTitle.d.ts +2 -0
- package/queries/getBlockUidsByPageTitle.js +9 -0
- package/queries/getBlockUidsByPageTitle.js.map +1 -0
- package/queries/getBlockUidsReferencingBlock.d.ts +2 -0
- package/queries/getBlockUidsReferencingBlock.js +5 -0
- package/queries/getBlockUidsReferencingBlock.js.map +1 -0
- package/queries/getBlockUidsReferencingPage.d.ts +2 -0
- package/queries/getBlockUidsReferencingPage.js +7 -0
- package/queries/getBlockUidsReferencingPage.js.map +1 -0
- package/queries/getBlockUidsWithParentUid.d.ts +2 -0
- package/queries/getBlockUidsWithParentUid.js +7 -0
- package/queries/getBlockUidsWithParentUid.js.map +1 -0
- package/queries/getChildrenLengthByPageUid.d.ts +2 -0
- package/queries/getChildrenLengthByPageUid.js +9 -0
- package/queries/getChildrenLengthByPageUid.js.map +1 -0
- package/queries/getChildrenLengthByParentUid.d.ts +2 -0
- package/queries/getChildrenLengthByParentUid.js +8 -0
- package/queries/getChildrenLengthByParentUid.js.map +1 -0
- package/queries/getCreateTimeByBlockUid.d.ts +2 -0
- package/queries/getCreateTimeByBlockUid.js +8 -0
- package/queries/getCreateTimeByBlockUid.js.map +1 -0
- package/queries/getCurrentUser.d.ts +2 -0
- package/queries/getCurrentUser.js +12 -0
- package/queries/getCurrentUser.js.map +1 -0
- package/queries/getCurrentUserDisplayName.d.ts +2 -0
- package/queries/getCurrentUserDisplayName.js +11 -0
- package/queries/getCurrentUserDisplayName.js.map +1 -0
- package/queries/getCurrentUserEmail.d.ts +2 -0
- package/queries/getCurrentUserEmail.js +14 -0
- package/queries/getCurrentUserEmail.js.map +1 -0
- package/queries/getCurrentUserUid.d.ts +2 -0
- package/queries/getCurrentUserUid.js +14 -0
- package/queries/getCurrentUserUid.js.map +1 -0
- package/queries/getDisplayNameByEmail.d.ts +2 -0
- package/queries/getDisplayNameByEmail.js +8 -0
- package/queries/getDisplayNameByEmail.js.map +1 -0
- package/queries/getDisplayNameByUid.d.ts +2 -0
- package/queries/getDisplayNameByUid.js +8 -0
- package/queries/getDisplayNameByUid.js.map +1 -0
- package/queries/getEditTimeByBlockUid.d.ts +2 -0
- package/queries/getEditTimeByBlockUid.js +8 -0
- package/queries/getEditTimeByBlockUid.js.map +1 -0
- package/queries/getEditedUserEmailByBlockUid.d.ts +2 -0
- package/queries/getEditedUserEmailByBlockUid.js +8 -0
- package/queries/getEditedUserEmailByBlockUid.js.map +1 -0
- package/queries/getFirstChildTextByBlockUid.d.ts +2 -0
- package/queries/getFirstChildTextByBlockUid.js +8 -0
- package/queries/getFirstChildTextByBlockUid.js.map +1 -0
- package/queries/getFirstChildUidByBlockUid.d.ts +2 -0
- package/queries/getFirstChildUidByBlockUid.js +7 -0
- package/queries/getFirstChildUidByBlockUid.js.map +1 -0
- package/queries/getFullTreeByParentUid.d.ts +3 -0
- package/queries/getFullTreeByParentUid.js +52 -0
- package/queries/getFullTreeByParentUid.js.map +1 -0
- package/queries/getLinkedPageTitlesUnderUid.d.ts +2 -0
- package/queries/getLinkedPageTitlesUnderUid.js +7 -0
- package/queries/getLinkedPageTitlesUnderUid.js.map +1 -0
- package/queries/getNthChildUidByBlockUid.d.ts +5 -0
- package/queries/getNthChildUidByBlockUid.js +8 -0
- package/queries/getNthChildUidByBlockUid.js.map +1 -0
- package/queries/getOrderByBlockUid.d.ts +2 -0
- package/queries/getOrderByBlockUid.js +8 -0
- package/queries/getOrderByBlockUid.js.map +1 -0
- package/queries/getPageTitleByBlockUid.d.ts +2 -0
- package/queries/getPageTitleByBlockUid.js +8 -0
- package/queries/getPageTitleByBlockUid.js.map +1 -0
- package/queries/getPageTitleByPageUid.d.ts +2 -0
- package/queries/getPageTitleByPageUid.js +13 -0
- package/queries/getPageTitleByPageUid.js.map +1 -0
- package/queries/getPageTitleReferencesByPageTitle.d.ts +2 -0
- package/queries/getPageTitleReferencesByPageTitle.js +7 -0
- package/queries/getPageTitleReferencesByPageTitle.js.map +1 -0
- package/queries/getPageTitlesAndBlockUidsReferencingPage.d.ts +5 -0
- package/queries/getPageTitlesAndBlockUidsReferencingPage.js +10 -0
- package/queries/getPageTitlesAndBlockUidsReferencingPage.js.map +1 -0
- package/queries/getPageTitlesAndUidsDirectlyReferencingPage.d.ts +5 -0
- package/queries/getPageTitlesAndUidsDirectlyReferencingPage.js +10 -0
- package/queries/getPageTitlesAndUidsDirectlyReferencingPage.js.map +1 -0
- package/queries/getPageTitlesReferencingBlockUid.d.ts +2 -0
- package/queries/getPageTitlesReferencingBlockUid.js +5 -0
- package/queries/getPageTitlesReferencingBlockUid.js.map +1 -0
- package/queries/getPageTitlesStartingWithPrefix.d.ts +2 -0
- package/queries/getPageTitlesStartingWithPrefix.js +7 -0
- package/queries/getPageTitlesStartingWithPrefix.js.map +1 -0
- package/queries/getPageUidByBlockUid.d.ts +2 -0
- package/queries/getPageUidByBlockUid.js +8 -0
- package/queries/getPageUidByBlockUid.js.map +1 -0
- package/queries/getPageUidByPageTitle.d.ts +2 -0
- package/queries/getPageUidByPageTitle.js +10 -0
- package/queries/getPageUidByPageTitle.js.map +1 -0
- package/queries/getPageViewType.d.ts +3 -0
- package/queries/getPageViewType.js +10 -0
- package/queries/getPageViewType.js.map +1 -0
- package/queries/getParentTextByBlockUid.d.ts +2 -0
- package/queries/getParentTextByBlockUid.js +8 -0
- package/queries/getParentTextByBlockUid.js.map +1 -0
- package/queries/getParentTextByBlockUidAndTag.d.ts +5 -0
- package/queries/getParentTextByBlockUidAndTag.js +8 -0
- package/queries/getParentTextByBlockUidAndTag.js.map +1 -0
- package/queries/getParentUidByBlockUid.d.ts +2 -0
- package/queries/getParentUidByBlockUid.js +8 -0
- package/queries/getParentUidByBlockUid.js.map +1 -0
- package/queries/getParentUidsOfBlockUid.d.ts +2 -0
- package/queries/getParentUidsOfBlockUid.js +5 -0
- package/queries/getParentUidsOfBlockUid.js.map +1 -0
- package/queries/getSettingsByEmail.d.ts +3 -0
- package/queries/getSettingsByEmail.js +8 -0
- package/queries/getSettingsByEmail.js.map +1 -0
- package/queries/getShallowTreeByParentUid.d.ts +5 -0
- package/queries/getShallowTreeByParentUid.js +10 -0
- package/queries/getShallowTreeByParentUid.js.map +1 -0
- package/queries/getTextByBlockUid.d.ts +2 -0
- package/queries/getTextByBlockUid.js +10 -0
- package/queries/getTextByBlockUid.js.map +1 -0
- package/queries/index.d.ts +0 -0
- package/queries/index.js +5 -0
- package/queries/index.js.map +1 -0
- package/queries/isLiveBlock.d.ts +2 -0
- package/queries/isLiveBlock.js +5 -0
- package/queries/isLiveBlock.js.map +1 -0
- package/queries/isTagOnPage.d.ts +5 -0
- package/queries/isTagOnPage.js +10 -0
- package/queries/isTagOnPage.js.map +1 -0
- package/queries/normalizePageTitle.d.ts +2 -0
- package/queries/normalizePageTitle.js +5 -0
- package/queries/normalizePageTitle.js.map +1 -0
- package/scripts/index.d.ts +1 -0
- package/scripts/index.js +27 -0
- package/scripts/index.js.map +1 -0
- package/scripts/publishToRoamDepot.d.ts +7 -0
- package/scripts/publishToRoamDepot.js +114 -0
- package/scripts/publishToRoamDepot.js.map +1 -0
- package/testing/mockRoamEnvironment.d.ts +2 -0
- package/testing/mockRoamEnvironment.js +1254 -0
- package/testing/mockRoamEnvironment.js.map +1 -0
- package/types/index.d.ts +389 -0
- package/types/index.js +5 -0
- package/types/index.js.map +1 -0
- package/types/native.d.ts +405 -0
- package/types/native.js +5 -0
- package/types/native.js.map +1 -0
- package/types/query-builder.d.ts +10 -0
- package/types/query-builder.js +3 -0
- package/types/query-builder.js.map +1 -0
- package/types/smartblocks.d.ts +35 -0
- package/types/smartblocks.js +3 -0
- package/types/smartblocks.js.map +1 -0
- package/util/addInputSetting.d.ts +7 -0
- package/util/addInputSetting.js +26 -0
- package/util/addInputSetting.js.map +1 -0
- package/util/apiDelete.d.ts +2 -0
- package/util/apiDelete.js +7 -0
- package/util/apiDelete.js.map +1 -0
- package/util/apiGet.d.ts +2 -0
- package/util/apiGet.js +7 -0
- package/util/apiGet.js.map +1 -0
- package/util/apiPost.d.ts +2 -0
- package/util/apiPost.js +7 -0
- package/util/apiPost.js.map +1 -0
- package/util/apiPut.d.ts +2 -0
- package/util/apiPut.js +7 -0
- package/util/apiPut.js.map +1 -0
- package/util/createOverlayRender.d.ts +4 -0
- package/util/createOverlayRender.js +7 -0
- package/util/createOverlayRender.js.map +1 -0
- package/util/createTagRegex.d.ts +2 -0
- package/util/createTagRegex.js +8 -0
- package/util/createTagRegex.js.map +1 -0
- package/util/dispatchToRegistry.d.ts +3 -0
- package/util/dispatchToRegistry.js +8 -0
- package/util/dispatchToRegistry.js.map +1 -0
- package/util/env.d.ts +4 -0
- package/util/env.js +48 -0
- package/util/env.js.map +1 -0
- package/util/extensionApiContext.d.ts +29 -0
- package/util/extensionApiContext.js +18 -0
- package/util/extensionApiContext.js.map +1 -0
- package/util/extensionDeprecatedWarning.d.ts +5 -0
- package/util/extensionDeprecatedWarning.js +40 -0
- package/util/extensionDeprecatedWarning.js.map +1 -0
- package/util/extractRef.d.ts +2 -0
- package/util/extractRef.js +9 -0
- package/util/extractRef.js.map +1 -0
- package/util/extractTag.d.ts +2 -0
- package/util/extractTag.js +16 -0
- package/util/extractTag.js.map +1 -0
- package/util/focusMainWindowBlock.d.ts +2 -0
- package/util/focusMainWindowBlock.js +13 -0
- package/util/focusMainWindowBlock.js.map +1 -0
- package/util/getAuthorizationHeader.d.ts +2 -0
- package/util/getAuthorizationHeader.js +13 -0
- package/util/getAuthorizationHeader.js.map +1 -0
- package/util/getLocalStorageKey.d.ts +2 -0
- package/util/getLocalStorageKey.js +5 -0
- package/util/getLocalStorageKey.js.map +1 -0
- package/util/getOauth.d.ts +2 -0
- package/util/getOauth.js +53 -0
- package/util/getOauth.js.map +1 -0
- package/util/getOauthAccounts.d.ts +2 -0
- package/util/getOauthAccounts.js +23 -0
- package/util/getOauthAccounts.js.map +1 -0
- package/util/getRenderRoot.d.ts +2 -0
- package/util/getRenderRoot.js +19 -0
- package/util/getRenderRoot.js.map +1 -0
- package/util/getSettingIntFromTree.d.ts +7 -0
- package/util/getSettingIntFromTree.js +12 -0
- package/util/getSettingIntFromTree.js.map +1 -0
- package/util/getSettingValueFromTree.d.ts +8 -0
- package/util/getSettingValueFromTree.js +15 -0
- package/util/getSettingValueFromTree.js.map +1 -0
- package/util/getSettingValuesFromTree.d.ts +7 -0
- package/util/getSettingValuesFromTree.js +13 -0
- package/util/getSettingValuesFromTree.js.map +1 -0
- package/util/getSubTree.d.ts +8 -0
- package/util/getSubTree.js +20 -0
- package/util/getSubTree.js.map +1 -0
- package/util/getToken.d.ts +2 -0
- package/util/getToken.js +11 -0
- package/util/getToken.js.map +1 -0
- package/util/getTokenFromTree.d.ts +3 -0
- package/util/getTokenFromTree.js +5 -0
- package/util/getTokenFromTree.js.map +1 -0
- package/util/getWorkerClient.d.ts +12 -0
- package/util/getWorkerClient.js +42 -0
- package/util/getWorkerClient.js.map +1 -0
- package/util/handleBodyFetch.d.ts +3 -0
- package/util/handleBodyFetch.js +22 -0
- package/util/handleBodyFetch.js.map +1 -0
- package/util/handleFetch.d.ts +13 -0
- package/util/handleFetch.js +41 -0
- package/util/handleFetch.js.map +1 -0
- package/util/handleUrlFetch.d.ts +3 -0
- package/util/handleUrlFetch.js +20 -0
- package/util/handleUrlFetch.js.map +1 -0
- package/util/idToTitle.d.ts +2 -0
- package/util/idToTitle.js +9 -0
- package/util/idToTitle.js.map +1 -0
- package/{src/util/index.ts → util/index.d.ts} +24 -24
- package/util/index.js +55 -0
- package/util/index.js.map +1 -0
- package/util/isControl.d.ts +2 -0
- package/util/isControl.js +5 -0
- package/util/isControl.js.map +1 -0
- package/util/localStorageGet.d.ts +2 -0
- package/util/localStorageGet.js +9 -0
- package/util/localStorageGet.js.map +1 -0
- package/util/localStorageRemove.d.ts +2 -0
- package/util/localStorageRemove.js +7 -0
- package/util/localStorageRemove.js.map +1 -0
- package/util/localStorageSet.d.ts +2 -0
- package/util/localStorageSet.js +9 -0
- package/util/localStorageSet.js.map +1 -0
- package/util/registerExperimentalMode.d.ts +6 -0
- package/util/registerExperimentalMode.js +66 -0
- package/util/registerExperimentalMode.js.map +1 -0
- package/util/registerSmartBlocksCommand.d.ts +3 -0
- package/util/registerSmartBlocksCommand.js +24 -0
- package/util/registerSmartBlocksCommand.js.map +1 -0
- package/util/removeFromRegistry.d.ts +3 -0
- package/util/removeFromRegistry.js +8 -0
- package/util/removeFromRegistry.js.map +1 -0
- package/util/renderOverlay.d.ts +12 -0
- package/util/renderOverlay.js +49 -0
- package/util/renderOverlay.js.map +1 -0
- package/util/renderWithUnmount.d.ts +4 -0
- package/util/renderWithUnmount.js +45 -0
- package/util/renderWithUnmount.js.map +1 -0
- package/util/runExtension.d.ts +11 -0
- package/util/runExtension.js +175 -0
- package/util/runExtension.js.map +1 -0
- package/util/setInputSetting.d.ts +7 -0
- package/util/setInputSetting.js +38 -0
- package/util/setInputSetting.js.map +1 -0
- package/util/setInputSettings.d.ts +7 -0
- package/util/setInputSettings.js +29 -0
- package/util/setInputSettings.js.map +1 -0
- package/util/stripUid.d.ts +3 -0
- package/util/stripUid.js +11 -0
- package/util/stripUid.js.map +1 -0
- package/util/toConfigPageName.d.ts +2 -0
- package/util/toConfigPageName.js +5 -0
- package/util/toConfigPageName.js.map +1 -0
- package/util/toFlexRegex.d.ts +2 -0
- package/util/toFlexRegex.js +5 -0
- package/util/toFlexRegex.js.map +1 -0
- package/writes/clearBlockById.d.ts +2 -0
- package/writes/clearBlockById.js +18 -0
- package/writes/clearBlockById.js.map +1 -0
- package/writes/clearBlockByUid.d.ts +2 -0
- package/writes/clearBlockByUid.js +17 -0
- package/writes/clearBlockByUid.js.map +1 -0
- package/writes/createBlock.d.ts +8 -0
- package/writes/createBlock.js +29 -0
- package/writes/createBlock.js.map +1 -0
- package/writes/createPage.d.ts +7 -0
- package/writes/createPage.js +21 -0
- package/writes/createPage.js.map +1 -0
- package/writes/deleteBlock.d.ts +2 -0
- package/writes/deleteBlock.js +11 -0
- package/writes/deleteBlock.js.map +1 -0
- package/{src/writes/index.ts → writes/index.d.ts} +8 -8
- package/writes/index.js +23 -0
- package/writes/index.js.map +1 -0
- package/writes/openBlockInSidebar.d.ts +2 -0
- package/writes/openBlockInSidebar.js +14 -0
- package/writes/openBlockInSidebar.js.map +1 -0
- package/writes/submitActions.d.ts +8 -0
- package/writes/submitActions.js +37 -0
- package/writes/submitActions.js.map +1 -0
- package/writes/updateActiveBlock.d.ts +2 -0
- package/writes/updateActiveBlock.js +18 -0
- package/writes/updateActiveBlock.js.map +1 -0
- package/writes/updateBlock.d.ts +5 -0
- package/writes/updateBlock.js +24 -0
- package/writes/updateBlock.js.map +1 -0
- package/.eslintrc.json +0 -19
- package/.github/workflows/main.yaml +0 -34
- package/docs/components.md +0 -32
- package/docs/date.md +0 -13
- package/docs/dom.md +0 -58
- package/docs/events.md +0 -16
- package/docs/hooks.md +0 -15
- package/docs/marked.md +0 -56
- package/docs/queries.md +0 -24
- package/docs/scripts.md +0 -20
- package/docs/types.md +0 -32
- package/docs/util.md +0 -38
- package/docs/writes.md +0 -23
- package/patches/dotenv+16.3.1.patch +0 -12
- package/src/components/AutocompleteInput.tsx +0 -248
- package/src/components/BlockErrorBoundary.tsx +0 -35
- package/src/components/BlockInput.tsx +0 -117
- package/src/components/ComponentContainer.tsx +0 -69
- package/src/components/ConfigPage.tsx +0 -320
- package/src/components/ConfigPanels/BlockPanel.tsx +0 -60
- package/src/components/ConfigPanels/BlocksPanel.tsx +0 -100
- package/src/components/ConfigPanels/CustomPanel.tsx +0 -41
- package/src/components/ConfigPanels/FlagPanel.tsx +0 -48
- package/src/components/ConfigPanels/MultiChildPanel.tsx +0 -99
- package/src/components/ConfigPanels/MultiTextPanel.tsx +0 -23
- package/src/components/ConfigPanels/NumberPanel.tsx +0 -36
- package/src/components/ConfigPanels/OauthPanel.tsx +0 -127
- package/src/components/ConfigPanels/PagesPanel.tsx +0 -19
- package/src/components/ConfigPanels/SelectPanel.tsx +0 -46
- package/src/components/ConfigPanels/TextPanel.tsx +0 -44
- package/src/components/ConfigPanels/TimePanel.tsx +0 -45
- package/src/components/ConfigPanels/getBrandColors.tsx +0 -31
- package/src/components/ConfigPanels/types.ts +0 -111
- package/src/components/ConfigPanels/useSingleChildValue.tsx +0 -63
- package/src/components/CursorMenu.tsx +0 -286
- package/src/components/Description.tsx +0 -31
- package/src/components/ExtensionApiContext.tsx +0 -24
- package/src/components/ExternalLogin.tsx +0 -190
- package/src/components/Filter.tsx +0 -313
- package/src/components/FormDialog.tsx +0 -503
- package/src/components/Loading.tsx +0 -33
- package/src/components/MenuItemSelect.tsx +0 -88
- package/src/components/OauthPanel.tsx +0 -62
- package/src/components/OauthSelect.tsx +0 -40
- package/src/components/PageInput.tsx +0 -17
- package/src/components/PageLink.tsx +0 -50
- package/src/components/ProgressDialog.tsx +0 -85
- package/src/components/SimpleAlert.tsx +0 -103
- package/src/components/Toast.tsx +0 -85
- package/src/components/index.ts +0 -5
- package/src/components.tsx +0 -242
- package/src/date/constants.ts +0 -19
- package/src/date/parseNlpDate.ts +0 -255
- package/src/date/parseRoamDateUid.ts +0 -6
- package/src/dom/addBlockCommand.ts +0 -59
- package/src/dom/addKeyboardTriggers.ts +0 -52
- package/src/dom/addOldRoamJSDependency.ts +0 -10
- package/src/dom/addRoamJSDependency.ts +0 -7
- package/src/dom/addScriptAsDependency.ts +0 -24
- package/src/dom/addStyle.ts +0 -11
- package/src/dom/constants.ts +0 -1
- package/src/dom/createBlockObserver.ts +0 -44
- package/src/dom/createButtonObserver.ts +0 -31
- package/src/dom/createDivObserver.ts +0 -15
- package/src/dom/createHTMLObserver.ts +0 -44
- package/src/dom/createHashtagObserver.ts +0 -22
- package/src/dom/createIconButton.ts +0 -13
- package/src/dom/createObserver.ts +0 -15
- package/src/dom/createOverlayObserver.ts +0 -7
- package/src/dom/createPageObserver.ts +0 -37
- package/src/dom/createPageTitleObserver.ts +0 -43
- package/src/dom/elToTitle.ts +0 -21
- package/src/dom/genericError.ts +0 -13
- package/src/dom/getActiveUids.ts +0 -6
- package/src/dom/getBlockUidFromTarget.ts +0 -39
- package/src/dom/getCurrentPageUid.ts +0 -5
- package/src/dom/getDomRefs.ts +0 -15
- package/src/dom/getDropUidOffset.ts +0 -36
- package/src/dom/getMutatedNodes.ts +0 -31
- package/src/dom/getPageTitleByHtmlElement.ts +0 -19
- package/src/dom/getPageTitleValueByHtmlElement.ts +0 -8
- package/src/dom/getReferenceBlockUid.ts +0 -22
- package/src/dom/getRoamUrl.ts +0 -6
- package/src/dom/getRoamUrlByPage.ts +0 -9
- package/src/dom/getUids.ts +0 -9
- package/src/dom/getUidsFromButton.ts +0 -9
- package/src/dom/getUidsFromId.ts +0 -13
- package/src/dom/parseRoamBlocksToHtml.ts +0 -118
- package/src/dom/resolveRefs.ts +0 -31
- package/src/events/watchOnce.ts +0 -17
- package/src/hooks/useArrowKeyDown.ts +0 -72
- package/src/hooks/useSubTree.ts +0 -16
- package/src/marked/index.ts +0 -619
- package/src/queries/compileDatalog.ts +0 -81
- package/src/queries/getAllBlockUids.ts +0 -6
- package/src/queries/getAllBlockUidsAndTexts.ts +0 -6
- package/src/queries/getAllPageNames.ts +0 -6
- package/src/queries/getAttributeValueByBlockAndName.ts +0 -23
- package/src/queries/getBasicTreeByParentUid.ts +0 -21
- package/src/queries/getBlockUidAndTextIncludingText.ts +0 -15
- package/src/queries/getBlockUidByTextOnPage.ts +0 -12
- package/src/queries/getBlockUidsAndTextsReferencingPage.ts +0 -18
- package/src/queries/getBlockUidsByPageTitle.ts +0 -12
- package/src/queries/getBlockUidsReferencingBlock.ts +0 -10
- package/src/queries/getBlockUidsReferencingPage.ts +0 -13
- package/src/queries/getBlockUidsWithParentUid.ts +0 -10
- package/src/queries/getChildrenLengthByPageUid.ts +0 -7
- package/src/queries/getChildrenLengthByParentUid.ts +0 -6
- package/src/queries/getCreateTimeByBlockUid.ts +0 -6
- package/src/queries/getCurrentUser.ts +0 -12
- package/src/queries/getCurrentUserDisplayName.ts +0 -9
- package/src/queries/getCurrentUserEmail.ts +0 -12
- package/src/queries/getCurrentUserUid.ts +0 -12
- package/src/queries/getDisplayNameByEmail.ts +0 -6
- package/src/queries/getDisplayNameByUid.ts +0 -6
- package/src/queries/getEditTimeByBlockUid.ts +0 -6
- package/src/queries/getEditedUserEmailByBlockUid.ts +0 -6
- package/src/queries/getFirstChildTextByBlockUid.ts +0 -8
- package/src/queries/getFirstChildUidByBlockUid.ts +0 -6
- package/src/queries/getFullTreeByParentUid.ts +0 -60
- package/src/queries/getLinkedPageTitlesUnderUid.ts +0 -8
- package/src/queries/getNthChildUidByBlockUid.ts +0 -16
- package/src/queries/getOrderByBlockUid.ts +0 -6
- package/src/queries/getPageTitleByBlockUid.ts +0 -8
- package/src/queries/getPageTitleByPageUid.ts +0 -11
- package/src/queries/getPageTitleReferencesByPageTitle.ts +0 -13
- package/src/queries/getPageTitlesAndBlockUidsReferencingPage.ts +0 -18
- package/src/queries/getPageTitlesAndUidsDirectlyReferencingPage.ts +0 -18
- package/src/queries/getPageTitlesReferencingBlockUid.ts +0 -10
- package/src/queries/getPageTitlesStartingWithPrefix.ts +0 -8
- package/src/queries/getPageUidByBlockUid.ts +0 -8
- package/src/queries/getPageUidByPageTitle.ts +0 -10
- package/src/queries/getPageViewType.ts +0 -11
- package/src/queries/getParentTextByBlockUid.ts +0 -6
- package/src/queries/getParentTextByBlockUidAndTag.ts +0 -12
- package/src/queries/getParentUidByBlockUid.ts +0 -10
- package/src/queries/getParentUidsOfBlockUid.ts +0 -10
- package/src/queries/getSettingsByEmail.ts +0 -8
- package/src/queries/getShallowTreeByParentUid.ts +0 -17
- package/src/queries/getTextByBlockUid.ts +0 -8
- package/src/queries/index.ts +0 -5
- package/src/queries/isLiveBlock.ts +0 -4
- package/src/queries/isTagOnPage.ts +0 -12
- package/src/queries/normalizePageTitle.ts +0 -4
- package/src/scripts/index.ts +0 -2
- package/src/scripts/publishToRoamDepot.ts +0 -163
- package/src/testing/mockRoamEnvironment.ts +0 -1489
- package/src/types/index.ts +0 -260
- package/src/types/native.ts +0 -495
- package/src/types/query-builder.ts +0 -10
- package/src/types/smartblocks.ts +0 -39
- package/src/util/addInputSetting.ts +0 -33
- package/src/util/apiDelete.ts +0 -5
- package/src/util/apiGet.ts +0 -5
- package/src/util/apiPost.ts +0 -5
- package/src/util/apiPut.ts +0 -5
- package/src/util/createOverlayRender.ts +0 -12
- package/src/util/createTagRegex.ts +0 -7
- package/src/util/dispatchToRegistry.ts +0 -11
- package/src/util/env.ts +0 -44
- package/src/util/extensionApiContext.ts +0 -17
- package/src/util/extensionDeprecatedWarning.ts +0 -57
- package/src/util/extractRef.ts +0 -8
- package/src/util/extractTag.ts +0 -15
- package/src/util/focusMainWindowBlock.ts +0 -13
- package/src/util/getAuthorizationHeader.ts +0 -11
- package/src/util/getLocalStorageKey.ts +0 -4
- package/src/util/getOauth.ts +0 -57
- package/src/util/getOauthAccounts.ts +0 -26
- package/src/util/getRenderRoot.ts +0 -17
- package/src/util/getSettingIntFromTree.ts +0 -18
- package/src/util/getSettingValueFromTree.ts +0 -23
- package/src/util/getSettingValuesFromTree.ts +0 -20
- package/src/util/getSubTree.ts +0 -31
- package/src/util/getToken.ts +0 -12
- package/src/util/getTokenFromTree.ts +0 -6
- package/src/util/getWorkerClient.ts +0 -55
- package/src/util/handleBodyFetch.ts +0 -38
- package/src/util/handleFetch.ts +0 -70
- package/src/util/handleUrlFetch.ts +0 -30
- package/src/util/idToTitle.ts +0 -8
- package/src/util/isControl.ts +0 -4
- package/src/util/localStorageGet.ts +0 -6
- package/src/util/localStorageRemove.ts +0 -6
- package/src/util/localStorageSet.ts +0 -6
- package/src/util/registerExperimentalMode.ts +0 -76
- package/src/util/registerSmartBlocksCommand.ts +0 -23
- package/src/util/removeFromRegistry.ts +0 -11
- package/src/util/renderOverlay.ts +0 -69
- package/src/util/renderWithUnmount.ts +0 -50
- package/src/util/runExtension.ts +0 -206
- package/src/util/setInputSetting.ts +0 -46
- package/src/util/setInputSettings.ts +0 -37
- package/src/util/stripUid.ts +0 -10
- package/src/util/toConfigPageName.ts +0 -3
- package/src/util/toFlexRegex.ts +0 -7
- package/src/writes/clearBlockById.ts +0 -17
- package/src/writes/clearBlockByUid.ts +0 -16
- package/src/writes/createBlock.ts +0 -50
- package/src/writes/createPage.ts +0 -30
- package/src/writes/deleteBlock.ts +0 -9
- package/src/writes/openBlockInSidebar.ts +0 -13
- package/src/writes/submitActions.ts +0 -54
- package/src/writes/updateActiveBlock.ts +0 -17
- package/src/writes/updateBlock.ts +0 -33
- package/tests/backend.test.tsx +0 -28
- package/tests/date.test.ts +0 -26
- package/tests/dom.test.tsx +0 -10
- package/tests/index.test.tsx +0 -25
- package/tests/marked.test.ts +0 -474
- package/tests/util/createTagRegex.test.ts +0 -63
- package/tests/util/extractTag.test.ts +0 -17
- package/tests/util/toFlexRegex.test.ts +0 -7
- package/tsconfig.json +0 -26
|
@@ -0,0 +1,1254 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const edn_data_1 = require("edn-data");
|
|
5
|
+
const nanoid_1 = tslib_1.__importDefault(require("nanoid"));
|
|
6
|
+
const jsdom_1 = require("jsdom");
|
|
7
|
+
const initMockGraph = () => ({
|
|
8
|
+
state: {},
|
|
9
|
+
uids: {},
|
|
10
|
+
titles: {},
|
|
11
|
+
});
|
|
12
|
+
const getDbId = () => Math.ceil(Math.random() * 1000000);
|
|
13
|
+
const isNode = (v) => typeof v === "object" && v !== null && !(v instanceof RegExp);
|
|
14
|
+
const resolvePattern = (pattern, result, graph) => Array.isArray(result)
|
|
15
|
+
? result.map((r) => resolvePattern(pattern, r, graph))
|
|
16
|
+
: pattern.some((pat) => pat.type === "wildcard")
|
|
17
|
+
? result
|
|
18
|
+
: Object.fromEntries(pattern.flatMap((pat) => {
|
|
19
|
+
if (pat.type === "constant") {
|
|
20
|
+
return [[pat.value, result[pat.value]]];
|
|
21
|
+
}
|
|
22
|
+
else if (pat.type === "attr-expr") {
|
|
23
|
+
if (pat.option.type === "as-expr") {
|
|
24
|
+
return [[pat.option.value, result[pat.name]]];
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error(`Unexpected pull attribute expression type: ${pat.option.type}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (pat.type === "map-spec") {
|
|
31
|
+
return pat.entries.map(({ key, value }) => {
|
|
32
|
+
const k = typeof key === "string"
|
|
33
|
+
? key
|
|
34
|
+
: key.type === "as-expr"
|
|
35
|
+
? key.value
|
|
36
|
+
: "";
|
|
37
|
+
const nestedResult = result[k];
|
|
38
|
+
if (!nestedResult)
|
|
39
|
+
return [k, []];
|
|
40
|
+
if (value === "...") {
|
|
41
|
+
const nestedResults = (Array.isArray(nestedResult) ? nestedResult : [nestedResult])
|
|
42
|
+
.map((a) => a[":db/id"])
|
|
43
|
+
.filter((id) => typeof id === "number")
|
|
44
|
+
.map((id) => graph.state[id]);
|
|
45
|
+
return [k, resolvePattern(pattern, nestedResults, graph)];
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return [k, resolvePattern(value, nestedResult, graph)];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new Error(`Unexpected pull pattern type: ${pat.type}`);
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
const fireQuery = ({ graph, find, where, }) => {
|
|
57
|
+
const getAssignments = (where, initialVars = []) => {
|
|
58
|
+
return where.reduce((programs, clause, index) => {
|
|
59
|
+
if (programs.assignments.size === 0 && index > 0)
|
|
60
|
+
return programs;
|
|
61
|
+
const reconcile = (matches, vars) => {
|
|
62
|
+
vars.forEach((v) => programs.vars.add(v));
|
|
63
|
+
programs.assignments = new Set(Array.from(new Set((programs.assignments.size === 0 && index === 0
|
|
64
|
+
? matches
|
|
65
|
+
: Array.from(programs.assignments).flatMap((dict) => matches.map((dic) => (Object.assign(Object.assign({}, dict), dic))))).map((a) =>
|
|
66
|
+
// remove duplicate assignments
|
|
67
|
+
JSON.stringify(Object.entries(a).sort(([ka], [kb]) => ka.localeCompare(kb)))))).map((s) => Object.fromEntries(JSON.parse(s))));
|
|
68
|
+
};
|
|
69
|
+
if (clause.type === "data-pattern") {
|
|
70
|
+
const [source, relation, target] = clause.arguments;
|
|
71
|
+
if (source.type !== "variable") {
|
|
72
|
+
throw new Error("Expected source type to be variable");
|
|
73
|
+
}
|
|
74
|
+
const sourceVar = source.value;
|
|
75
|
+
if (relation.type !== "constant") {
|
|
76
|
+
throw new Error("Expected relation type to be constant");
|
|
77
|
+
}
|
|
78
|
+
const rel = relation.value;
|
|
79
|
+
const targetString = target.value.replace(/^"/, "").replace(/"$/, "");
|
|
80
|
+
const targetVar = target.value;
|
|
81
|
+
if (programs.vars.has(sourceVar)) {
|
|
82
|
+
const newAssignments = Array.from(programs.assignments).flatMap((dict) => {
|
|
83
|
+
var _a, _b, _c;
|
|
84
|
+
const sourceEntry = dict[sourceVar];
|
|
85
|
+
if (!isNode(sourceEntry)) {
|
|
86
|
+
throw new Error("Expected the source variable to map to a node");
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
const sourceId = sourceEntry.id;
|
|
90
|
+
if (rel === ":block/refs") {
|
|
91
|
+
throw new Error("TODO");
|
|
92
|
+
// if (target.type !== "variable") {
|
|
93
|
+
// throw new Error(
|
|
94
|
+
// "Expected target for :block/refs to be a variable"
|
|
95
|
+
// );
|
|
96
|
+
// return [];
|
|
97
|
+
// }
|
|
98
|
+
// const targetEntry = dict[targetVar];
|
|
99
|
+
// const refs = (
|
|
100
|
+
// isNode(targetEntry)
|
|
101
|
+
// ? [targetEntry.id]
|
|
102
|
+
// : graph.edges.referencesByUid[sourceId] || []
|
|
103
|
+
// ).map((ref) => ({
|
|
104
|
+
// ...dict,
|
|
105
|
+
// [targetVar]: { uid: ref },
|
|
106
|
+
// }));
|
|
107
|
+
// if (refs.length) programs.vars.add(targetVar);
|
|
108
|
+
// return refs;
|
|
109
|
+
}
|
|
110
|
+
else if (rel === ":block/page") {
|
|
111
|
+
// if (target.type !== "variable") {
|
|
112
|
+
// throw new Error(
|
|
113
|
+
// "Expected target for :block/page to be a variable"
|
|
114
|
+
// );
|
|
115
|
+
// return [];
|
|
116
|
+
// }
|
|
117
|
+
// const targetEntry = dict[targetVar];
|
|
118
|
+
// if (graph.edges.pagesByUid[sourceId]) {
|
|
119
|
+
// return [];
|
|
120
|
+
// } else if (isNode(targetEntry)) {
|
|
121
|
+
// return targetEntry.id ===
|
|
122
|
+
// graph.edges.blocksPageByUid[sourceId]
|
|
123
|
+
// ? [dict]
|
|
124
|
+
// : [];
|
|
125
|
+
// } else {
|
|
126
|
+
// programs.vars.add(targetVar);
|
|
127
|
+
// return [
|
|
128
|
+
// {
|
|
129
|
+
// ...dict,
|
|
130
|
+
// [targetVar]: {
|
|
131
|
+
// uid: graph.edges.blocksPageByUid[sourceId],
|
|
132
|
+
// },
|
|
133
|
+
// },
|
|
134
|
+
// ];
|
|
135
|
+
// }
|
|
136
|
+
throw new Error("TODO");
|
|
137
|
+
}
|
|
138
|
+
else if (rel === ":node/title") {
|
|
139
|
+
const sourceTitle = (_a = graph.state[sourceId]) === null || _a === void 0 ? void 0 : _a[":node/title"];
|
|
140
|
+
if (target.type === "constant") {
|
|
141
|
+
if (graph.titles[targetString] === sourceId) {
|
|
142
|
+
return [dict];
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (target.type === "underscore") {
|
|
149
|
+
return [dict];
|
|
150
|
+
}
|
|
151
|
+
else if (!sourceTitle) {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
programs.vars.add(targetVar);
|
|
156
|
+
return [
|
|
157
|
+
Object.assign(Object.assign({}, dict), { [targetVar]: sourceTitle }),
|
|
158
|
+
];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
else if (rel === ":block/children") {
|
|
162
|
+
if (target.type !== "variable") {
|
|
163
|
+
throw new Error("Expected target for :block/children to be a variable");
|
|
164
|
+
}
|
|
165
|
+
const targetEntry = dict[targetVar];
|
|
166
|
+
const children = (isNode(targetEntry)
|
|
167
|
+
? [targetEntry.id]
|
|
168
|
+
: (((_b = graph.state[sourceId]) === null || _b === void 0 ? void 0 : _b[":block/children"]) || []).map((c) => c[":db/id"] || 0)).map((id) => (Object.assign(Object.assign({}, dict), { [targetVar]: { id } })));
|
|
169
|
+
if (children.length)
|
|
170
|
+
programs.vars.add(targetVar);
|
|
171
|
+
return children;
|
|
172
|
+
}
|
|
173
|
+
else if (rel === ":block/parents") {
|
|
174
|
+
if (target.type !== "variable") {
|
|
175
|
+
throw new Error("Expected target for :block/parents to be a variable");
|
|
176
|
+
}
|
|
177
|
+
const targetEntry = dict[targetVar];
|
|
178
|
+
const ancestors = (isNode(targetEntry)
|
|
179
|
+
? [targetEntry.id]
|
|
180
|
+
: (((_c = graph.state[sourceId]) === null || _c === void 0 ? void 0 : _c[":block/parents"]) || []).map((d) => d[":db/id"] || 0)).map((id) => (Object.assign(Object.assign({}, dict), { [targetVar]: { id } })));
|
|
181
|
+
if (ancestors.length)
|
|
182
|
+
programs.vars.add(targetVar);
|
|
183
|
+
return ancestors;
|
|
184
|
+
}
|
|
185
|
+
else if (rel === ":block/string") {
|
|
186
|
+
// if (target.type === "constant") {
|
|
187
|
+
// if (graph.edges.blocksByUid[sourceId] === targetString) {
|
|
188
|
+
// return [dict];
|
|
189
|
+
// } else {
|
|
190
|
+
// return [];
|
|
191
|
+
// }
|
|
192
|
+
// } else if (target.type === "underscore") {
|
|
193
|
+
// return [dict];
|
|
194
|
+
// } else {
|
|
195
|
+
// programs.vars.add(targetVar);
|
|
196
|
+
// return [
|
|
197
|
+
// {
|
|
198
|
+
// ...dict,
|
|
199
|
+
// [targetVar]: graph.edges.blocksByUid[sourceId],
|
|
200
|
+
// },
|
|
201
|
+
// ];
|
|
202
|
+
// }
|
|
203
|
+
throw new Error("TODO");
|
|
204
|
+
}
|
|
205
|
+
else if (rel === ":block/heading") {
|
|
206
|
+
// if (target.type === "constant") {
|
|
207
|
+
// if (
|
|
208
|
+
// graph.edges.headingsByUid[sourceId] ===
|
|
209
|
+
// Number(targetString)
|
|
210
|
+
// ) {
|
|
211
|
+
// return [dict];
|
|
212
|
+
// } else {
|
|
213
|
+
// return [];
|
|
214
|
+
// }
|
|
215
|
+
// } else if (target.type === "underscore") {
|
|
216
|
+
// return [dict];
|
|
217
|
+
// } else {
|
|
218
|
+
// programs.vars.add(targetVar);
|
|
219
|
+
// return [
|
|
220
|
+
// {
|
|
221
|
+
// ...dict,
|
|
222
|
+
// [targetVar]: graph.edges.headingsByUid[sourceId],
|
|
223
|
+
// },
|
|
224
|
+
// ];
|
|
225
|
+
// }
|
|
226
|
+
throw new Error("TODO");
|
|
227
|
+
}
|
|
228
|
+
else if (rel === ":create/user") {
|
|
229
|
+
// if (target.type !== "variable") {
|
|
230
|
+
// throw new Error(
|
|
231
|
+
// "Expected target for :create/user to be a variable"
|
|
232
|
+
// );
|
|
233
|
+
// return [];
|
|
234
|
+
// }
|
|
235
|
+
// const targetEntry = dict[targetVar];
|
|
236
|
+
// const userId = graph.edges.createUserByUid[sourceId];
|
|
237
|
+
// if (isNode(targetEntry)) {
|
|
238
|
+
// return targetEntry.id === userId ? [dict] : [];
|
|
239
|
+
// } else {
|
|
240
|
+
// programs.vars.add(targetVar);
|
|
241
|
+
// return [
|
|
242
|
+
// {
|
|
243
|
+
// ...dict,
|
|
244
|
+
// [targetVar]: { uid: userId },
|
|
245
|
+
// },
|
|
246
|
+
// ];
|
|
247
|
+
// }
|
|
248
|
+
throw new Error("TODO");
|
|
249
|
+
}
|
|
250
|
+
else if (rel === ":edit/user") {
|
|
251
|
+
// if (target.type !== "variable") {
|
|
252
|
+
// throw new Error(
|
|
253
|
+
// "Expected target for :edit/user to be a variable"
|
|
254
|
+
// );
|
|
255
|
+
// return [];
|
|
256
|
+
// }
|
|
257
|
+
// const targetEntry = dict[targetVar];
|
|
258
|
+
// const userId = graph.edges.editUserByUid[sourceId];
|
|
259
|
+
// if (isNode(targetEntry)) {
|
|
260
|
+
// return targetEntry.id === userId ? [dict] : [];
|
|
261
|
+
// } else {
|
|
262
|
+
// programs.vars.add(targetVar);
|
|
263
|
+
// return [
|
|
264
|
+
// {
|
|
265
|
+
// ...dict,
|
|
266
|
+
// [targetVar]: { uid: userId },
|
|
267
|
+
// },
|
|
268
|
+
// ];
|
|
269
|
+
// }
|
|
270
|
+
throw new Error("TODO");
|
|
271
|
+
}
|
|
272
|
+
else if (rel === ":create/time") {
|
|
273
|
+
// if (target.type === "constant") {
|
|
274
|
+
// if (
|
|
275
|
+
// graph.edges.createTimeByUid[sourceId] ===
|
|
276
|
+
// Number(targetString)
|
|
277
|
+
// ) {
|
|
278
|
+
// return [dict];
|
|
279
|
+
// } else {
|
|
280
|
+
// return [];
|
|
281
|
+
// }
|
|
282
|
+
// } else if (target.type === "underscore") {
|
|
283
|
+
// return [dict];
|
|
284
|
+
// } else {
|
|
285
|
+
// programs.vars.add(targetVar);
|
|
286
|
+
// return [
|
|
287
|
+
// {
|
|
288
|
+
// ...dict,
|
|
289
|
+
// [targetVar]: graph.edges.createTimeByUid[sourceId],
|
|
290
|
+
// },
|
|
291
|
+
// ];
|
|
292
|
+
// }
|
|
293
|
+
throw new Error("TODO");
|
|
294
|
+
}
|
|
295
|
+
else if (rel === ":edit/time") {
|
|
296
|
+
// if (target.type === "constant") {
|
|
297
|
+
// if (
|
|
298
|
+
// graph.edges.editTimeByUid[sourceId] ===
|
|
299
|
+
// Number(targetString)
|
|
300
|
+
// ) {
|
|
301
|
+
// return [dict];
|
|
302
|
+
// } else {
|
|
303
|
+
// return [];
|
|
304
|
+
// }
|
|
305
|
+
// } else if (target.type === "underscore") {
|
|
306
|
+
// return [dict];
|
|
307
|
+
// } else {
|
|
308
|
+
// programs.vars.add(targetVar);
|
|
309
|
+
// return [
|
|
310
|
+
// {
|
|
311
|
+
// ...dict,
|
|
312
|
+
// [targetVar]: graph.edges.editTimeByUid[sourceId],
|
|
313
|
+
// },
|
|
314
|
+
// ];
|
|
315
|
+
// }
|
|
316
|
+
throw new Error("TODO");
|
|
317
|
+
}
|
|
318
|
+
else if (rel === ":user/display-name") {
|
|
319
|
+
// if (target.type === "constant") {
|
|
320
|
+
// if (
|
|
321
|
+
// graph.edges.userDisplayByUid[sourceId] === targetString
|
|
322
|
+
// ) {
|
|
323
|
+
// return [dict];
|
|
324
|
+
// } else {
|
|
325
|
+
// return [];
|
|
326
|
+
// }
|
|
327
|
+
// } else if (target.type === "underscore") {
|
|
328
|
+
// return [dict];
|
|
329
|
+
// } else {
|
|
330
|
+
// programs.vars.add(targetVar);
|
|
331
|
+
// return [
|
|
332
|
+
// {
|
|
333
|
+
// ...dict,
|
|
334
|
+
// [targetVar]: graph.edges.userDisplayByUid[sourceId],
|
|
335
|
+
// },
|
|
336
|
+
// ];
|
|
337
|
+
// }
|
|
338
|
+
throw new Error("TODO");
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
throw new Error(`Unknown rel: ${rel}`);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
programs.assignments = new Set(newAssignments);
|
|
345
|
+
}
|
|
346
|
+
else if (target.type === "variable" &&
|
|
347
|
+
programs.vars.has(targetVar)) {
|
|
348
|
+
const newAssignments = Array.from(programs.assignments).flatMap((_dict) => {
|
|
349
|
+
// const targetEntry = dict[targetVar];
|
|
350
|
+
if (rel === ":block/refs") {
|
|
351
|
+
// if (!isNode(targetEntry)) {
|
|
352
|
+
// throw new Error(
|
|
353
|
+
// "Expected the target variable to map to a node in :block/refs"
|
|
354
|
+
// );
|
|
355
|
+
// return [];
|
|
356
|
+
// }
|
|
357
|
+
// const targetId = targetEntry.id;
|
|
358
|
+
// const refs = (
|
|
359
|
+
// graph.edges.linkedReferencesByUid[targetId] || []
|
|
360
|
+
// ).map((ref) => ({
|
|
361
|
+
// ...dict,
|
|
362
|
+
// [v]: { uid: ref },
|
|
363
|
+
// }));
|
|
364
|
+
// if (refs.length) programs.vars.add(v);
|
|
365
|
+
// return refs;
|
|
366
|
+
throw new Error("TODO");
|
|
367
|
+
}
|
|
368
|
+
else if (rel === ":block/page") {
|
|
369
|
+
// if (!isNode(targetEntry)) {
|
|
370
|
+
// throw new Error(
|
|
371
|
+
// "Expected the target variable to map to a node in :block/page"
|
|
372
|
+
// );
|
|
373
|
+
// return [];
|
|
374
|
+
// }
|
|
375
|
+
// const targetId = targetEntry.id;
|
|
376
|
+
// if (!graph.edges.pagesByUid[targetId]) {
|
|
377
|
+
// return [];
|
|
378
|
+
// } else {
|
|
379
|
+
// const children = Array.from(
|
|
380
|
+
// graph.edges.descendantsByUid[targetId] || []
|
|
381
|
+
// ).map((d) => ({
|
|
382
|
+
// ...dict,
|
|
383
|
+
// [v]: { uid: d },
|
|
384
|
+
// }));
|
|
385
|
+
// if (children.length) programs.vars.add(v);
|
|
386
|
+
// return children;
|
|
387
|
+
// }
|
|
388
|
+
throw new Error("TODO");
|
|
389
|
+
}
|
|
390
|
+
else if (rel === ":node/title") {
|
|
391
|
+
// if (typeof targetEntry !== "string") {
|
|
392
|
+
// throw new Error(
|
|
393
|
+
// "Expected the target variable to map to a string in :block/refs"
|
|
394
|
+
// );
|
|
395
|
+
// return [];
|
|
396
|
+
// }
|
|
397
|
+
// const page = graph.edges.pageUidByTitle[targetEntry];
|
|
398
|
+
// if (page) {
|
|
399
|
+
// programs.vars.add(v);
|
|
400
|
+
// return [
|
|
401
|
+
// {
|
|
402
|
+
// ...dict,
|
|
403
|
+
// [v]: { uid: page },
|
|
404
|
+
// },
|
|
405
|
+
// ];
|
|
406
|
+
// }
|
|
407
|
+
// return [];
|
|
408
|
+
throw new Error("TODO");
|
|
409
|
+
}
|
|
410
|
+
else if (rel === ":block/children") {
|
|
411
|
+
// if (!isNode(targetEntry)) {
|
|
412
|
+
// throw new Error(
|
|
413
|
+
// "Expected the target variable to map to a node in :block/children"
|
|
414
|
+
// );
|
|
415
|
+
// }
|
|
416
|
+
// const targetId = targetEntry.id;
|
|
417
|
+
// const parent = graph.edges.parentByUid[targetId];
|
|
418
|
+
// if (parent) {
|
|
419
|
+
// programs.vars.add(v);
|
|
420
|
+
// return [
|
|
421
|
+
// {
|
|
422
|
+
// ...dict,
|
|
423
|
+
// [v]: { uid: parent },
|
|
424
|
+
// },
|
|
425
|
+
// ];
|
|
426
|
+
// } else {
|
|
427
|
+
// return [];
|
|
428
|
+
// }
|
|
429
|
+
throw new Error("TODO");
|
|
430
|
+
}
|
|
431
|
+
else if (rel === ":block/parents") {
|
|
432
|
+
// if (!isNode(targetEntry)) {
|
|
433
|
+
// throw new Error(
|
|
434
|
+
// "Expected the target variable to map to a node in :block/parents"
|
|
435
|
+
// );
|
|
436
|
+
// return [];
|
|
437
|
+
// }
|
|
438
|
+
// const targetId = targetEntry.id;
|
|
439
|
+
// const ancestors = Array.from(
|
|
440
|
+
// graph.edges.ancestorsByUid[targetId] || []
|
|
441
|
+
// ).map((child) => ({
|
|
442
|
+
// ...dict,
|
|
443
|
+
// [v]: { uid: child },
|
|
444
|
+
// }));
|
|
445
|
+
// if (ancestors.length) programs.vars.add(v);
|
|
446
|
+
// return ancestors;
|
|
447
|
+
throw new Error("TODO");
|
|
448
|
+
}
|
|
449
|
+
else if (rel === ":block/string") {
|
|
450
|
+
// if (typeof targetEntry !== "string") {
|
|
451
|
+
// throw new Error(
|
|
452
|
+
// "Expected the target variable to map to a string in :block/string"
|
|
453
|
+
// );
|
|
454
|
+
// return [];
|
|
455
|
+
// }
|
|
456
|
+
// const blocks = Object.entries(graph.edges.blocksByUid)
|
|
457
|
+
// .filter(([_, v]) => v === targetEntry)
|
|
458
|
+
// .map(([child]) => ({
|
|
459
|
+
// ...dict,
|
|
460
|
+
// [v]: { uid: child },
|
|
461
|
+
// }));
|
|
462
|
+
// if (blocks.length) programs.vars.add(v);
|
|
463
|
+
// return blocks;
|
|
464
|
+
throw new Error("TODO");
|
|
465
|
+
}
|
|
466
|
+
else if (rel === ":block/heading") {
|
|
467
|
+
// if (typeof targetEntry !== "number") {
|
|
468
|
+
// throw new Error(
|
|
469
|
+
// "Expected the target variable to map to a number in :block/heading"
|
|
470
|
+
// );
|
|
471
|
+
// return [];
|
|
472
|
+
// }
|
|
473
|
+
// const blocks = Object.entries(graph.edges.headingsByUid)
|
|
474
|
+
// .filter(([_, v]) => v === targetEntry)
|
|
475
|
+
// .map(([child]) => ({
|
|
476
|
+
// ...dict,
|
|
477
|
+
// [v]: { uid: child },
|
|
478
|
+
// }));
|
|
479
|
+
// if (blocks.length) programs.vars.add(v);
|
|
480
|
+
// return blocks;
|
|
481
|
+
throw new Error("TODO");
|
|
482
|
+
}
|
|
483
|
+
else if (rel === ":create/user") {
|
|
484
|
+
// if (!isNode(targetEntry)) {
|
|
485
|
+
// throw new Error(
|
|
486
|
+
// "Expected the target variable to map to a node in :create/user"
|
|
487
|
+
// );
|
|
488
|
+
// }
|
|
489
|
+
// const targetId = targetEntry.id;
|
|
490
|
+
// const children = Object.keys(graph.edges.createUserByUid)
|
|
491
|
+
// .filter(
|
|
492
|
+
// (node) => graph.edges.createUserByUid[node] === targetId
|
|
493
|
+
// )
|
|
494
|
+
// .map((d) => ({
|
|
495
|
+
// ...dict,
|
|
496
|
+
// [v]: { uid: d },
|
|
497
|
+
// }));
|
|
498
|
+
// if (children.length) programs.vars.add(v);
|
|
499
|
+
// return children;
|
|
500
|
+
throw new Error("TODO");
|
|
501
|
+
}
|
|
502
|
+
else if (rel === ":edit/user") {
|
|
503
|
+
// if (!isNode(targetEntry)) {
|
|
504
|
+
// throw new Error(
|
|
505
|
+
// "Expected the target variable to map to a node in :edit/user"
|
|
506
|
+
// );
|
|
507
|
+
// }
|
|
508
|
+
// const targetId = targetEntry.id;
|
|
509
|
+
// const children = Object.keys(graph.edges.editUserByUid)
|
|
510
|
+
// .filter(
|
|
511
|
+
// (node) =>
|
|
512
|
+
// graph.edges.editUserByUid[Number(node)] === targetId
|
|
513
|
+
// )
|
|
514
|
+
// .map((d) => ({
|
|
515
|
+
// ...dict,
|
|
516
|
+
// [v]: { uid: d },
|
|
517
|
+
// }));
|
|
518
|
+
// if (children.length) programs.vars.add(v);
|
|
519
|
+
// return children;
|
|
520
|
+
throw new Error("TODO");
|
|
521
|
+
}
|
|
522
|
+
else if (rel === ":create/time") {
|
|
523
|
+
// if (typeof targetEntry !== "number") {
|
|
524
|
+
// throw new Error(
|
|
525
|
+
// "Expected the target variable to map to a number in :create/time"
|
|
526
|
+
// );
|
|
527
|
+
// }
|
|
528
|
+
// const blocks = Object.entries(graph.edges.createTimeByUid)
|
|
529
|
+
// .filter(([_, v]) => v === targetEntry)
|
|
530
|
+
// .map(([child]) => ({
|
|
531
|
+
// ...dict,
|
|
532
|
+
// [v]: { uid: child },
|
|
533
|
+
// }));
|
|
534
|
+
// if (blocks.length) programs.vars.add(v);
|
|
535
|
+
// return blocks;
|
|
536
|
+
throw new Error("TODO");
|
|
537
|
+
}
|
|
538
|
+
else if (rel === ":edit/time") {
|
|
539
|
+
// if (typeof targetEntry !== "number") {
|
|
540
|
+
// throw new Error(
|
|
541
|
+
// "Expected the target variable to map to a number in :edit/time"
|
|
542
|
+
// );
|
|
543
|
+
// }
|
|
544
|
+
// const blocks = Object.entries(graph.edges.editTimeByUid)
|
|
545
|
+
// .filter(([_, v]) => v === targetEntry)
|
|
546
|
+
// .map(([child]) => ({
|
|
547
|
+
// ...dict,
|
|
548
|
+
// [v]: { uid: child },
|
|
549
|
+
// }));
|
|
550
|
+
// if (blocks.length) programs.vars.add(v);
|
|
551
|
+
// return blocks;
|
|
552
|
+
throw new Error("TODO");
|
|
553
|
+
}
|
|
554
|
+
else if (rel === ":user/display-name") {
|
|
555
|
+
// if (typeof targetEntry !== "string") {
|
|
556
|
+
// throw new Error(
|
|
557
|
+
// "Expected the target variable to map to a string in :block/refs"
|
|
558
|
+
// );
|
|
559
|
+
// }
|
|
560
|
+
// const displayName = targetEntry
|
|
561
|
+
// .replace(/^"/, "")
|
|
562
|
+
// .replace(/"$/, "");
|
|
563
|
+
// const user = graph.edges.userUidByDisplay[displayName];
|
|
564
|
+
// if (user) {
|
|
565
|
+
// programs.vars.add(v);
|
|
566
|
+
// return [
|
|
567
|
+
// {
|
|
568
|
+
// ...dict,
|
|
569
|
+
// [v]: { uid: user },
|
|
570
|
+
// },
|
|
571
|
+
// ];
|
|
572
|
+
// }
|
|
573
|
+
// return [];
|
|
574
|
+
throw new Error("TODO");
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
throw new Error(`Unknown rel: ${rel}`);
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
programs.assignments = new Set(newAssignments);
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
const matches = rel === ":children/view-type"
|
|
584
|
+
? target.type === "constant"
|
|
585
|
+
? Object.values(graph.uids)
|
|
586
|
+
.filter((id) => graph.state[id][":children/view-type"] !==
|
|
587
|
+
targetString)
|
|
588
|
+
.map((id) => ({ [sourceVar]: { id } }))
|
|
589
|
+
: target.type === "underscore"
|
|
590
|
+
? Object.values(graph.uids).map((id) => ({
|
|
591
|
+
[sourceVar]: { id },
|
|
592
|
+
}))
|
|
593
|
+
: Object.values(graph.uids).map((id) => ({
|
|
594
|
+
[sourceVar]: { id },
|
|
595
|
+
[targetVar]: graph.state[id][":children/view-type"] || ":bullet",
|
|
596
|
+
}))
|
|
597
|
+
: rel === ":block/uid"
|
|
598
|
+
? target.type === "constant"
|
|
599
|
+
? [{ [sourceVar]: { id: graph.uids[target.value] } }]
|
|
600
|
+
: target.type === "underscore"
|
|
601
|
+
? Object.values(graph.uids).map((id) => ({
|
|
602
|
+
[sourceVar]: { id },
|
|
603
|
+
}))
|
|
604
|
+
: Object.entries(graph.uids).map(([uid, id]) => ({
|
|
605
|
+
[sourceVar]: { id },
|
|
606
|
+
[targetVar]: uid,
|
|
607
|
+
}))
|
|
608
|
+
: new Error(`Unknown rel: ${rel}`);
|
|
609
|
+
/*
|
|
610
|
+
rel === ":block/refs"
|
|
611
|
+
? target.type !== "variable"
|
|
612
|
+
? []
|
|
613
|
+
: Object.entries(graph.edges.referencesByUid).flatMap(
|
|
614
|
+
([source, refs]) =>
|
|
615
|
+
refs.map((ref) => ({
|
|
616
|
+
[v]: { uid: source },
|
|
617
|
+
[targetVar]: { uid: ref },
|
|
618
|
+
}))
|
|
619
|
+
)
|
|
620
|
+
: rel === ":block/page"
|
|
621
|
+
? target.type !== "variable"
|
|
622
|
+
? []
|
|
623
|
+
: Object.entries(graph.edges.blocksPageByUid).map(
|
|
624
|
+
([b, p]) => ({
|
|
625
|
+
[v]: { uid: b },
|
|
626
|
+
[targetVar]: { uid: p },
|
|
627
|
+
})
|
|
628
|
+
)
|
|
629
|
+
: rel === ":node/title"
|
|
630
|
+
? target.type === "constant"
|
|
631
|
+
? graph.edges.pageUidByTitle[targetString]
|
|
632
|
+
? [
|
|
633
|
+
{
|
|
634
|
+
[v]: {
|
|
635
|
+
uid: graph.edges.pageUidByTitle[targetString],
|
|
636
|
+
},
|
|
637
|
+
},
|
|
638
|
+
]
|
|
639
|
+
: []
|
|
640
|
+
: target.type === "underscore"
|
|
641
|
+
? Object.values(graph.edges.pageUidByTitle).map((uid) => ({
|
|
642
|
+
[v]: { uid },
|
|
643
|
+
}))
|
|
644
|
+
: Object.entries(graph.edges.pageUidByTitle).map(
|
|
645
|
+
([title, uid]) => ({
|
|
646
|
+
[v]: { uid },
|
|
647
|
+
[targetVar]: title,
|
|
648
|
+
})
|
|
649
|
+
)
|
|
650
|
+
: rel === ":block/children"
|
|
651
|
+
? target.type !== "variable"
|
|
652
|
+
? []
|
|
653
|
+
: Object.entries(graph.edges.childrenByUid).flatMap(
|
|
654
|
+
([source, refs]) =>
|
|
655
|
+
refs.map((ref) => ({
|
|
656
|
+
[v]: { uid: source },
|
|
657
|
+
[targetVar]: { uid: ref },
|
|
658
|
+
}))
|
|
659
|
+
)
|
|
660
|
+
: rel === ":block/parents"
|
|
661
|
+
? target.type !== "variable"
|
|
662
|
+
? []
|
|
663
|
+
: Object.entries(graph.edges.ancestorsByUid).flatMap(
|
|
664
|
+
([source, refs]) =>
|
|
665
|
+
Array.from(refs).map((ref) => ({
|
|
666
|
+
[v]: { uid: source },
|
|
667
|
+
[targetVar]: { uid: ref },
|
|
668
|
+
}))
|
|
669
|
+
)
|
|
670
|
+
: rel === ":block/string"
|
|
671
|
+
? target.type === "constant"
|
|
672
|
+
? Object.entries(graph.edges.blocksByUid)
|
|
673
|
+
.filter(([_, text]) => text !== targetString)
|
|
674
|
+
.map(([uid]) => ({ [v]: { uid } }))
|
|
675
|
+
: target.type === "underscore"
|
|
676
|
+
? Object.keys(graph.edges.blocksByUid).map((uid) => ({
|
|
677
|
+
[v]: { uid },
|
|
678
|
+
}))
|
|
679
|
+
: Object.entries(graph.edges.blocksByUid).map(
|
|
680
|
+
([uid, text]) => ({
|
|
681
|
+
[v]: { uid },
|
|
682
|
+
[targetVar]: text,
|
|
683
|
+
})
|
|
684
|
+
)
|
|
685
|
+
: rel === ":block/heading"
|
|
686
|
+
? target.type === "constant"
|
|
687
|
+
? Object.entries(graph.edges.headingsByUid)
|
|
688
|
+
.filter(([_, text]) => text !== Number(targetString))
|
|
689
|
+
.map(([uid]) => ({ [v]: { uid } }))
|
|
690
|
+
: target.type === "underscore"
|
|
691
|
+
? Object.keys(graph.edges.headingsByUid).map((uid) => ({
|
|
692
|
+
[v]: { uid },
|
|
693
|
+
}))
|
|
694
|
+
: Object.entries(graph.edges.headingsByUid).map(
|
|
695
|
+
([uid, text]) => ({
|
|
696
|
+
[v]: { uid },
|
|
697
|
+
[targetVar]: text,
|
|
698
|
+
})
|
|
699
|
+
)
|
|
700
|
+
: rel === ":create/user"
|
|
701
|
+
? target.type !== "variable"
|
|
702
|
+
? []
|
|
703
|
+
: Object.entries(graph.edges.createUserByUid).map(
|
|
704
|
+
([b, p]) => ({
|
|
705
|
+
[v]: { uid: b },
|
|
706
|
+
[targetVar]: { uid: p },
|
|
707
|
+
})
|
|
708
|
+
)
|
|
709
|
+
: rel === ":edit/user"
|
|
710
|
+
? target.type !== "variable"
|
|
711
|
+
? []
|
|
712
|
+
: Object.entries(graph.edges.editUserByUid).map(([b, p]) => ({
|
|
713
|
+
[v]: { uid: b },
|
|
714
|
+
[targetVar]: { uid: p },
|
|
715
|
+
}))
|
|
716
|
+
: rel === ":create/time"
|
|
717
|
+
? target.type === "constant"
|
|
718
|
+
? Object.entries(graph.edges.createTimeByUid)
|
|
719
|
+
.filter(([_, text]) => text !== Number(targetString))
|
|
720
|
+
.map(([uid]) => ({ [v]: { uid } }))
|
|
721
|
+
: target.type === "underscore"
|
|
722
|
+
? Object.keys(graph.edges.createTimeByUid).map((uid) => ({
|
|
723
|
+
[v]: { uid },
|
|
724
|
+
}))
|
|
725
|
+
: Object.entries(graph.edges.createTimeByUid).map(
|
|
726
|
+
([uid, text]) => ({
|
|
727
|
+
[v]: { uid },
|
|
728
|
+
[targetVar]: text,
|
|
729
|
+
})
|
|
730
|
+
)
|
|
731
|
+
: rel === ":edit/time"
|
|
732
|
+
? target.type === "constant"
|
|
733
|
+
? Object.entries(graph.edges.editTimeByUid)
|
|
734
|
+
.filter(([_, text]) => text !== Number(targetString))
|
|
735
|
+
.map(([uid]) => ({ [v]: { uid } }))
|
|
736
|
+
: target.type === "underscore"
|
|
737
|
+
? Object.keys(graph.edges.editTimeByUid).map((uid) => ({
|
|
738
|
+
[v]: { uid },
|
|
739
|
+
}))
|
|
740
|
+
: Object.entries(graph.edges.editTimeByUid).map(
|
|
741
|
+
([uid, text]) => ({
|
|
742
|
+
[v]: { uid },
|
|
743
|
+
[targetVar]: text,
|
|
744
|
+
})
|
|
745
|
+
)
|
|
746
|
+
: rel === ":user/display-name"
|
|
747
|
+
? target.type === "constant"
|
|
748
|
+
? graph.edges.userUidByDisplay[targetString]
|
|
749
|
+
? [
|
|
750
|
+
{
|
|
751
|
+
[v]: {
|
|
752
|
+
uid: graph.edges.userUidByDisplay[targetString],
|
|
753
|
+
},
|
|
754
|
+
},
|
|
755
|
+
]
|
|
756
|
+
: []
|
|
757
|
+
: target.type === "underscore"
|
|
758
|
+
? Object.values(graph.edges.userUidByDisplay).map((uid) => ({
|
|
759
|
+
[v]: { uid },
|
|
760
|
+
}))
|
|
761
|
+
: Object.entries(graph.edges.userUidByDisplay).map(
|
|
762
|
+
([title, uid]) => ({
|
|
763
|
+
[v]: { uid },
|
|
764
|
+
[targetVar]: title,
|
|
765
|
+
})
|
|
766
|
+
)*/
|
|
767
|
+
if (matches instanceof Error) {
|
|
768
|
+
throw matches;
|
|
769
|
+
}
|
|
770
|
+
reconcile(matches, target.type === "variable" ? [sourceVar, targetVar] : [sourceVar]);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
else if (clause.type === "or-clause" ||
|
|
774
|
+
clause.type === "or-join-clause") {
|
|
775
|
+
let matches = [];
|
|
776
|
+
for (const cls of clause.clauses) {
|
|
777
|
+
const assignments = getAssignments([cls], Array.from(programs.vars));
|
|
778
|
+
if (assignments.size) {
|
|
779
|
+
matches = Array.from(assignments);
|
|
780
|
+
break;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
const vars = clause.type === "or-join-clause"
|
|
784
|
+
? clause.variables.map((v) => v.value)
|
|
785
|
+
: Object.keys(matches[0] || {});
|
|
786
|
+
const varSet = new Set(vars);
|
|
787
|
+
matches.forEach((a) => {
|
|
788
|
+
Object.keys(a).forEach((k) => {
|
|
789
|
+
if (!varSet.has(k)) {
|
|
790
|
+
delete a[k];
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
reconcile(matches, vars);
|
|
795
|
+
}
|
|
796
|
+
else if (clause.type === "and-clause") {
|
|
797
|
+
const matches = Array.from(getAssignments(clause.clauses, Array.from(programs.vars)));
|
|
798
|
+
reconcile(matches, Object.keys(matches[0] || {}));
|
|
799
|
+
}
|
|
800
|
+
else if (clause.type === "pred-expr") {
|
|
801
|
+
if (clause.pred === "clojure.string/includes?") {
|
|
802
|
+
const [variable, constant] = clause.arguments;
|
|
803
|
+
if ((variable === null || variable === void 0 ? void 0 : variable.type) !== "variable") {
|
|
804
|
+
throw new Error("Expected type to be variable for first clojure.string/includes? argument.");
|
|
805
|
+
}
|
|
806
|
+
const v = variable.value;
|
|
807
|
+
if (!programs.vars.has(v)) {
|
|
808
|
+
throw new Error("Expected first clojure.string/includes? argument to be predefined variable.");
|
|
809
|
+
}
|
|
810
|
+
if ((constant === null || constant === void 0 ? void 0 : constant.type) !== "constant") {
|
|
811
|
+
throw new Error("Expected type to be constant for second clojure.string/includes? argument.");
|
|
812
|
+
}
|
|
813
|
+
const newAssignments = Array.from(programs.assignments).flatMap((dict) => {
|
|
814
|
+
const sourceEntry = dict[v];
|
|
815
|
+
if (typeof sourceEntry !== "string") {
|
|
816
|
+
throw new Error("Expected the variable to map to a string");
|
|
817
|
+
}
|
|
818
|
+
if (sourceEntry.includes(constant.value.replace(/^"/, "").replace(/"$/, ""))) {
|
|
819
|
+
return [dict];
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
return [];
|
|
823
|
+
}
|
|
824
|
+
});
|
|
825
|
+
programs.assignments = new Set(newAssignments);
|
|
826
|
+
}
|
|
827
|
+
else if (clause.pred === "clojure.string/starts-with?") {
|
|
828
|
+
const [variable, constant] = clause.arguments;
|
|
829
|
+
const v = variable.value;
|
|
830
|
+
if ((variable === null || variable === void 0 ? void 0 : variable.type) !== "variable") {
|
|
831
|
+
throw new Error("Expected type to be variable for first clojure.string/starts-with? argument.");
|
|
832
|
+
}
|
|
833
|
+
if (!programs.vars.has(v)) {
|
|
834
|
+
throw new Error("Expected first clojure.string/starts-with? argument to be predefined variable.");
|
|
835
|
+
}
|
|
836
|
+
if ((constant === null || constant === void 0 ? void 0 : constant.type) !== "constant") {
|
|
837
|
+
throw new Error("Expected type to be constant for second clojure.string/starts-with? argument.");
|
|
838
|
+
}
|
|
839
|
+
const newAssignments = Array.from(programs.assignments).flatMap((dict) => {
|
|
840
|
+
const sourceEntry = dict[v];
|
|
841
|
+
if (typeof sourceEntry !== "string") {
|
|
842
|
+
throw new Error("Expected the variable to map to a string");
|
|
843
|
+
return [];
|
|
844
|
+
}
|
|
845
|
+
if (sourceEntry.startsWith(constant.value.replace(/^"/, "").replace(/"$/, ""))) {
|
|
846
|
+
return [dict];
|
|
847
|
+
}
|
|
848
|
+
else {
|
|
849
|
+
return [];
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
programs.assignments = new Set(newAssignments);
|
|
853
|
+
}
|
|
854
|
+
else if (clause.pred === "clojure.string/ends-with?") {
|
|
855
|
+
const [variable, constant] = clause.arguments;
|
|
856
|
+
const v = variable.value;
|
|
857
|
+
if ((variable === null || variable === void 0 ? void 0 : variable.type) !== "variable") {
|
|
858
|
+
throw new Error("Expected type to be variable for first clojure.string/ends-with? argument.");
|
|
859
|
+
}
|
|
860
|
+
if (!programs.vars.has(v)) {
|
|
861
|
+
throw new Error("Expected first clojure.string/ends-with? argument to be predefined variable.");
|
|
862
|
+
}
|
|
863
|
+
if ((constant === null || constant === void 0 ? void 0 : constant.type) !== "constant") {
|
|
864
|
+
throw new Error("Expected type to be constant for second clojure.string/ends-with? argument.");
|
|
865
|
+
}
|
|
866
|
+
const newAssignments = Array.from(programs.assignments).flatMap((dict) => {
|
|
867
|
+
const sourceEntry = dict[v];
|
|
868
|
+
if (typeof sourceEntry !== "string") {
|
|
869
|
+
throw new Error("Expected the variable to map to a string");
|
|
870
|
+
}
|
|
871
|
+
if (sourceEntry.endsWith(constant.value.replace(/^"/, "").replace(/"$/, ""))) {
|
|
872
|
+
return [dict];
|
|
873
|
+
}
|
|
874
|
+
else {
|
|
875
|
+
return [];
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
programs.assignments = new Set(newAssignments);
|
|
879
|
+
}
|
|
880
|
+
else if (clause.pred === "re-find") {
|
|
881
|
+
const [regex, variable] = clause.arguments;
|
|
882
|
+
const v = variable.value;
|
|
883
|
+
const r = regex.value;
|
|
884
|
+
if ((variable === null || variable === void 0 ? void 0 : variable.type) !== "variable") {
|
|
885
|
+
throw new Error("Expected type to be variable for first re-find argument.");
|
|
886
|
+
}
|
|
887
|
+
if (!programs.vars.has(v)) {
|
|
888
|
+
throw new Error("Expected first re-find argument to be predefined variable.");
|
|
889
|
+
}
|
|
890
|
+
if ((regex === null || regex === void 0 ? void 0 : regex.type) !== "variable") {
|
|
891
|
+
throw new Error("Expected type to be variable for second re-find argument.");
|
|
892
|
+
}
|
|
893
|
+
if (!programs.vars.has(r)) {
|
|
894
|
+
throw new Error("Expected second re-find argument to be predefined variable.");
|
|
895
|
+
}
|
|
896
|
+
const newAssignments = Array.from(programs.assignments).filter((dict) => {
|
|
897
|
+
const regexEntry = dict[r];
|
|
898
|
+
if (!(regexEntry instanceof RegExp)) {
|
|
899
|
+
throw new Error("Expected the variable to map to a regexp");
|
|
900
|
+
}
|
|
901
|
+
const targetEntry = dict[v];
|
|
902
|
+
if (typeof targetEntry !== "string") {
|
|
903
|
+
throw new Error("Expected the variable to map to a string");
|
|
904
|
+
}
|
|
905
|
+
return regexEntry.test(targetEntry);
|
|
906
|
+
});
|
|
907
|
+
programs.assignments = new Set(newAssignments);
|
|
908
|
+
}
|
|
909
|
+
else if (clause.pred === ">") {
|
|
910
|
+
const [left, right] = clause.arguments;
|
|
911
|
+
const l = left.value;
|
|
912
|
+
const r = right.value;
|
|
913
|
+
if ((left === null || left === void 0 ? void 0 : left.type) === "variable" && !programs.vars.has(l)) {
|
|
914
|
+
throw new Error("If left argument is a variable, it must be predefined");
|
|
915
|
+
}
|
|
916
|
+
if ((right === null || right === void 0 ? void 0 : right.type) === "variable" && !programs.vars.has(r)) {
|
|
917
|
+
throw new Error("If right argument is a variable, it must be predefined");
|
|
918
|
+
}
|
|
919
|
+
const newAssignments = Array.from(programs.assignments).filter((dict) => {
|
|
920
|
+
const leftValue = left.type === "constant" ? Number(left.value) : dict[r];
|
|
921
|
+
if (typeof leftValue !== "number") {
|
|
922
|
+
throw new Error("Left argument must be a number");
|
|
923
|
+
}
|
|
924
|
+
const rightValue = right.type === "constant" ? Number(right.value) : dict[r];
|
|
925
|
+
if (typeof rightValue !== "number") {
|
|
926
|
+
throw new Error("Right argument must be a number");
|
|
927
|
+
}
|
|
928
|
+
return leftValue > rightValue;
|
|
929
|
+
});
|
|
930
|
+
programs.assignments = new Set(newAssignments);
|
|
931
|
+
}
|
|
932
|
+
else if (clause.pred === "<") {
|
|
933
|
+
const [left, right] = clause.arguments;
|
|
934
|
+
const l = left.value;
|
|
935
|
+
const r = right.value;
|
|
936
|
+
if ((left === null || left === void 0 ? void 0 : left.type) === "variable" && !programs.vars.has(l)) {
|
|
937
|
+
throw new Error("If left argument is a variable, it must be predefined");
|
|
938
|
+
}
|
|
939
|
+
if ((right === null || right === void 0 ? void 0 : right.type) === "variable" && !programs.vars.has(r)) {
|
|
940
|
+
throw new Error("If right argument is a variable, it must be predefined");
|
|
941
|
+
}
|
|
942
|
+
const newAssignments = Array.from(programs.assignments).filter((dict) => {
|
|
943
|
+
const leftValue = left.type === "constant" ? Number(left.value) : dict[r];
|
|
944
|
+
if (typeof leftValue !== "number") {
|
|
945
|
+
throw new Error("Left argument must be a number");
|
|
946
|
+
}
|
|
947
|
+
const rightValue = right.type === "constant" ? Number(right.value) : dict[r];
|
|
948
|
+
if (typeof rightValue !== "number") {
|
|
949
|
+
throw new Error("Right argument must be a number");
|
|
950
|
+
}
|
|
951
|
+
return leftValue < rightValue;
|
|
952
|
+
});
|
|
953
|
+
programs.assignments = new Set(newAssignments);
|
|
954
|
+
}
|
|
955
|
+
else {
|
|
956
|
+
throw new Error(`Unexpected predicate ${clause.pred}`);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
else if (clause.type === "fn-expr") {
|
|
960
|
+
if (clause.fn === "re-pattern") {
|
|
961
|
+
const [constant] = clause.arguments;
|
|
962
|
+
if ((constant === null || constant === void 0 ? void 0 : constant.type) !== "constant") {
|
|
963
|
+
throw new Error("Expected type to be constant for first re-pattern argument.");
|
|
964
|
+
}
|
|
965
|
+
const { binding } = clause;
|
|
966
|
+
if (binding.type !== "bind-scalar") {
|
|
967
|
+
throw new Error("Expected type to be scalar for first re-pattern binding.");
|
|
968
|
+
}
|
|
969
|
+
const newAssignments = Array.from(programs.assignments).map((dict) => {
|
|
970
|
+
return Object.assign(Object.assign({}, dict), { [binding.variable.value]: new RegExp(constant.value.replace(/^"/, "").replace(/"$/, "")) });
|
|
971
|
+
});
|
|
972
|
+
programs.assignments = new Set(newAssignments);
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
throw new Error(`Unexpected fn name ${clause.fn}`);
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
else {
|
|
979
|
+
throw new Error(`Unexpected type ${clause.type}`);
|
|
980
|
+
}
|
|
981
|
+
return programs;
|
|
982
|
+
}, {
|
|
983
|
+
assignments: new Set([]),
|
|
984
|
+
vars: new Set(initialVars),
|
|
985
|
+
}).assignments;
|
|
986
|
+
};
|
|
987
|
+
const assignments = getAssignments(where);
|
|
988
|
+
const results = Array.from(assignments).map((res) => find.elements.map((el) => {
|
|
989
|
+
if (el.type === "variable") {
|
|
990
|
+
const node = res[el.value];
|
|
991
|
+
if (isNode(node)) {
|
|
992
|
+
return node.id;
|
|
993
|
+
}
|
|
994
|
+
else if (node instanceof RegExp) {
|
|
995
|
+
return node.source;
|
|
996
|
+
}
|
|
997
|
+
else {
|
|
998
|
+
return node;
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
else if (el.type === "pull") {
|
|
1002
|
+
const node = res[el.variable.value];
|
|
1003
|
+
if (typeof node === "undefined") {
|
|
1004
|
+
throw new Error(`Failed to find ${el.variable.value} in result: ${JSON.stringify(res)}`);
|
|
1005
|
+
}
|
|
1006
|
+
if (el.pattern.type === "pattern-data-literal") {
|
|
1007
|
+
if (isNode(node)) {
|
|
1008
|
+
const result = graph.state[node.id];
|
|
1009
|
+
return resolvePattern(el.pattern.value, result, graph);
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
throw new Error(`Unexpected pull variable: ${el.variable.value} - ${node}`);
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
throw new Error(`Unexpected pull element pattern type: ${el.pattern.type}`);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
throw new Error(`Unexpected Find element type: ${el.type}`);
|
|
1020
|
+
}));
|
|
1021
|
+
return results;
|
|
1022
|
+
};
|
|
1023
|
+
const mockQuery = ({ graph, query }) => {
|
|
1024
|
+
const data = (0, edn_data_1.parseEDNString)(query);
|
|
1025
|
+
const findIndex = data.findIndex((d) => typeof d === "object" && "key" in d && d.key === "find");
|
|
1026
|
+
const whereIndex = data.findIndex((d) => typeof d === "object" && "key" in d && d.key === "where");
|
|
1027
|
+
const findPattern = data.slice(findIndex + 1, whereIndex);
|
|
1028
|
+
const find = {
|
|
1029
|
+
type: "rel",
|
|
1030
|
+
elements: findPattern.map((p) => {
|
|
1031
|
+
if (typeof p !== "object") {
|
|
1032
|
+
throw new Error(`Unexpected type for datalog find, looking for object: ${JSON.stringify(p)}`);
|
|
1033
|
+
}
|
|
1034
|
+
if ("sym" in p)
|
|
1035
|
+
return { type: "variable", value: p.sym };
|
|
1036
|
+
if ("list" in p) {
|
|
1037
|
+
const [pull, name, attrs] = p.list;
|
|
1038
|
+
if (typeof pull !== "object" ||
|
|
1039
|
+
!("sym" in pull) ||
|
|
1040
|
+
pull.sym !== "pull") {
|
|
1041
|
+
throw new Error(`Expected first edn value to be a pull symbol. Found: ${JSON.stringify(p)}`);
|
|
1042
|
+
}
|
|
1043
|
+
if (typeof name !== "object" || !("sym" in name)) {
|
|
1044
|
+
throw new Error(`Expected second edn value to be a pull symbol. Found: ${JSON.stringify(p)}`);
|
|
1045
|
+
}
|
|
1046
|
+
if (!Array.isArray(attrs)) {
|
|
1047
|
+
throw new Error(`Expected third edn value to be an array. Found: ${JSON.stringify(p)}`);
|
|
1048
|
+
}
|
|
1049
|
+
return {
|
|
1050
|
+
type: "pull",
|
|
1051
|
+
variable: { type: "variable", value: name.sym.replace(/^\?/, "") },
|
|
1052
|
+
pattern: {
|
|
1053
|
+
type: "pattern-data-literal",
|
|
1054
|
+
value: attrs.map((attr) => {
|
|
1055
|
+
if (typeof attr === "object" && "key" in attr) {
|
|
1056
|
+
return {
|
|
1057
|
+
type: "constant",
|
|
1058
|
+
value: `:${attr.key}`,
|
|
1059
|
+
};
|
|
1060
|
+
}
|
|
1061
|
+
if (Array.isArray(attr)) {
|
|
1062
|
+
const [name, expr, option] = attr;
|
|
1063
|
+
if (typeof name !== "object" || !("key" in name)) {
|
|
1064
|
+
throw new Error(`Expected attribute expression to start with key. Found: ${JSON.stringify(attr)}`);
|
|
1065
|
+
}
|
|
1066
|
+
if (typeof expr !== "object" ||
|
|
1067
|
+
!("key" in expr) ||
|
|
1068
|
+
!["as", "limit", "default"].includes(expr.key)) {
|
|
1069
|
+
throw new Error(`Expected attribute expression to have second key :as, :limit, or :default. Found: ${JSON.stringify(attr)}`);
|
|
1070
|
+
}
|
|
1071
|
+
if (typeof option !== "string") {
|
|
1072
|
+
throw new Error(`Expected attribute expression to end with literal. Found: ${JSON.stringify(attr)}`);
|
|
1073
|
+
}
|
|
1074
|
+
const pullOption = expr.key === "as"
|
|
1075
|
+
? { type: "as-expr", value: option }
|
|
1076
|
+
: undefined; // should be impossible
|
|
1077
|
+
if (!pullOption) {
|
|
1078
|
+
throw new Error(`Expected attribute expression to be an \`as\` key. Found: ${JSON.stringify(expr)}`);
|
|
1079
|
+
}
|
|
1080
|
+
return {
|
|
1081
|
+
type: "attr-expr",
|
|
1082
|
+
name: `:${name.key}`,
|
|
1083
|
+
option: pullOption,
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
if (typeof attr === "object" && "map" in attr) {
|
|
1087
|
+
return {
|
|
1088
|
+
type: "map-spec",
|
|
1089
|
+
entries: attr.map.map((entry) => {
|
|
1090
|
+
const [key, value] = entry;
|
|
1091
|
+
if (typeof key !== "object" || !("key" in key)) {
|
|
1092
|
+
throw new Error(`Unexpected pattern map key. Found: ${JSON.stringify(entry)}`);
|
|
1093
|
+
}
|
|
1094
|
+
if (typeof value !== "object" ||
|
|
1095
|
+
!("sym" in value) ||
|
|
1096
|
+
value.sym !== "...") {
|
|
1097
|
+
throw new Error(`Unexpected pattern map value. Found: ${JSON.stringify(entry)}`);
|
|
1098
|
+
}
|
|
1099
|
+
return {
|
|
1100
|
+
key: `:${key.key}`,
|
|
1101
|
+
value: value.sym,
|
|
1102
|
+
};
|
|
1103
|
+
}),
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
throw new Error(`Unexpected pattern literal attribute. Found: ${JSON.stringify(attr)}`);
|
|
1107
|
+
}),
|
|
1108
|
+
},
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
throw new Error(`Unexpected object for datalog find: ${JSON.stringify(p)}`);
|
|
1112
|
+
}),
|
|
1113
|
+
};
|
|
1114
|
+
const wherePattern = data.slice(whereIndex + 1);
|
|
1115
|
+
const toDatalog = (e) => {
|
|
1116
|
+
if (Array.isArray(e)) {
|
|
1117
|
+
if (e.length === 3) {
|
|
1118
|
+
return {
|
|
1119
|
+
type: "data-pattern",
|
|
1120
|
+
arguments: e.map((a) => {
|
|
1121
|
+
if (typeof a === "object") {
|
|
1122
|
+
if ("key" in a) {
|
|
1123
|
+
return {
|
|
1124
|
+
type: "constant",
|
|
1125
|
+
value: `:${a.key}`,
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
else if ("sym" in a) {
|
|
1129
|
+
return {
|
|
1130
|
+
type: "variable",
|
|
1131
|
+
value: a.sym.slice(1),
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
else {
|
|
1135
|
+
throw new Error(`Expected data-pattern argument to come from non array EDN: ${JSON.stringify(a)}`);
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
else {
|
|
1139
|
+
return {
|
|
1140
|
+
type: "constant",
|
|
1141
|
+
value: a,
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
}),
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
throw new Error(`Unknown value for datalog clause: ${JSON.stringify(e)}`);
|
|
1149
|
+
};
|
|
1150
|
+
const where = wherePattern.map(toDatalog);
|
|
1151
|
+
return fireQuery({ graph, find, where });
|
|
1152
|
+
};
|
|
1153
|
+
const mockRoamEnvironment = () => {
|
|
1154
|
+
const graph = initMockGraph();
|
|
1155
|
+
const dom = new jsdom_1.JSDOM();
|
|
1156
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1157
|
+
// @ts-ignore
|
|
1158
|
+
global.window = dom.window;
|
|
1159
|
+
global.document = dom.window.document;
|
|
1160
|
+
global.window.roamAlphaAPI = Object.assign(Object.assign({}, global.window.roamAlphaAPI), { pull: (_, id) => {
|
|
1161
|
+
const pick = (node) => {
|
|
1162
|
+
// TODO - process exp
|
|
1163
|
+
return node;
|
|
1164
|
+
};
|
|
1165
|
+
if (Array.isArray(id)) {
|
|
1166
|
+
const [attr, val] = id;
|
|
1167
|
+
if (attr === ":block/uid") {
|
|
1168
|
+
return pick(graph.state[graph.uids[val]]);
|
|
1169
|
+
}
|
|
1170
|
+
else if (attr === ":node/title") {
|
|
1171
|
+
return pick(graph.state[graph.titles[val]]);
|
|
1172
|
+
}
|
|
1173
|
+
else {
|
|
1174
|
+
throw new Error(`Attr is not supported: ${attr}`);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
else if (typeof id === "number") {
|
|
1178
|
+
return pick(graph.state[id]);
|
|
1179
|
+
}
|
|
1180
|
+
else {
|
|
1181
|
+
throw new Error(`Id is not supported: ${id}`);
|
|
1182
|
+
}
|
|
1183
|
+
}, q: (query, ..._params) => {
|
|
1184
|
+
return mockQuery({ graph, query });
|
|
1185
|
+
}, createBlock: (action) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
1186
|
+
if (!action.block)
|
|
1187
|
+
throw new Error(`block field is required`);
|
|
1188
|
+
if (!action.location)
|
|
1189
|
+
throw new Error(`location field is required`);
|
|
1190
|
+
const parent = graph.uids[action.location["parent-uid"]];
|
|
1191
|
+
if (!parent)
|
|
1192
|
+
throw new Error(`Could not find parent by uid: ${action.location["parent-uid"]}`);
|
|
1193
|
+
const parentBlock = graph.state[parent];
|
|
1194
|
+
const id = getDbId();
|
|
1195
|
+
const block = {
|
|
1196
|
+
":block/string": action.block.string,
|
|
1197
|
+
":block/uid": action.block.uid || window.roamAlphaAPI.util.generateUID(),
|
|
1198
|
+
":block/parents": [{ ":db/id": parent }].concat(parentBlock[":block/parents"] || []),
|
|
1199
|
+
":db/id": id,
|
|
1200
|
+
":block/order": action.location.order,
|
|
1201
|
+
};
|
|
1202
|
+
graph.uids[block[":block/uid"]] = id;
|
|
1203
|
+
parentBlock[":block/children"] = (parentBlock[":block/children"] || []).concat({ ":db/id": id });
|
|
1204
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1205
|
+
// @ts-ignore
|
|
1206
|
+
graph.state[id] = block;
|
|
1207
|
+
}), updateBlock: (action) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
1208
|
+
if (!action.block)
|
|
1209
|
+
throw new Error(`block field is required`);
|
|
1210
|
+
if (!action.block.uid)
|
|
1211
|
+
throw new Error(`block uid is required`);
|
|
1212
|
+
const block = graph.uids[action.block.uid];
|
|
1213
|
+
if (!block) {
|
|
1214
|
+
throw new Error(`Could not find block by uid: ${action.block.uid}`);
|
|
1215
|
+
}
|
|
1216
|
+
if (typeof action.block.string !== "undefined") {
|
|
1217
|
+
graph.state[block][":block/string"] = action.block.string;
|
|
1218
|
+
}
|
|
1219
|
+
if (typeof action.block.open !== "undefined") {
|
|
1220
|
+
graph.state[block][":block/open"] = action.block.open;
|
|
1221
|
+
}
|
|
1222
|
+
if (typeof action.block.heading !== "undefined") {
|
|
1223
|
+
graph.state[block][":block/heading"] = action.block.heading;
|
|
1224
|
+
}
|
|
1225
|
+
if (typeof action.block["text-align"] !== "undefined") {
|
|
1226
|
+
graph.state[block][":block/text-align"] = action.block["text-align"];
|
|
1227
|
+
}
|
|
1228
|
+
if (typeof action.block["children-view-type"] !== "undefined") {
|
|
1229
|
+
graph.state[block][":children/view-type"] = `:${action.block["children-view-type"]}`;
|
|
1230
|
+
}
|
|
1231
|
+
}), createPage: (action) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
1232
|
+
if (!action.page)
|
|
1233
|
+
throw new Error(`page field is required`);
|
|
1234
|
+
if (!action.page.title)
|
|
1235
|
+
throw new Error(`page title field is required`);
|
|
1236
|
+
const id = getDbId();
|
|
1237
|
+
const page = {
|
|
1238
|
+
":node/title": action.page.title,
|
|
1239
|
+
":block/uid": action.page.uid || window.roamAlphaAPI.util.generateUID(),
|
|
1240
|
+
":db/id": id,
|
|
1241
|
+
};
|
|
1242
|
+
graph.titles[action.page.title] = id;
|
|
1243
|
+
graph.uids[page[":block/uid"]] = id;
|
|
1244
|
+
graph.state[id] = page;
|
|
1245
|
+
}) });
|
|
1246
|
+
global.window.roamAlphaAPI.data = Object.assign(Object.assign({}, global.window.roamAlphaAPI.data), { fast: {
|
|
1247
|
+
q: (query, ..._params) => {
|
|
1248
|
+
return mockQuery({ graph, query });
|
|
1249
|
+
},
|
|
1250
|
+
} });
|
|
1251
|
+
global.window.roamAlphaAPI.util = Object.assign(Object.assign({}, global.window.roamAlphaAPI.util), { generateUID: () => (0, nanoid_1.default)().slice(0, 9) });
|
|
1252
|
+
};
|
|
1253
|
+
exports.default = mockRoamEnvironment;
|
|
1254
|
+
//# sourceMappingURL=mockRoamEnvironment.js.map
|