roamjs-components 0.86.0-alpha → 0.86.0-alpha.3
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/components/AutocompleteInput.d.ts +28 -0
- package/components/AutocompleteInput.js +121 -0
- package/components/AutocompleteInput.js.map +1 -0
- package/components/BlockErrorBoundary.d.ts +16 -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 +11 -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 +202 -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/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/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/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/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 +18 -10
- 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 +250 -0
- package/types/index.js +5 -0
- package/types/index.js.map +1 -0
- package/types/native.d.ts +402 -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} +4 -4
- 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/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
- /package/{src/date/index.ts → date/index.d.ts} +0 -0
- /package/{src/dom/index.ts → dom/index.d.ts} +0 -0
- /package/{src/events/index.ts → events/index.d.ts} +0 -0
- /package/{src/hooks/index.ts → hooks/index.d.ts} +0 -0
- /package/{src/writes/index.ts → writes/index.d.ts} +0 -0
|
@@ -1,1489 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DatalogClause,
|
|
3
|
-
DatalogConstant,
|
|
4
|
-
DatalogVariable,
|
|
5
|
-
PullBlock,
|
|
6
|
-
} from "../types/native";
|
|
7
|
-
import { parseEDNString } from "edn-data";
|
|
8
|
-
import nanoid from "nanoid";
|
|
9
|
-
import { JSDOM } from "jsdom";
|
|
10
|
-
|
|
11
|
-
type Graph = {
|
|
12
|
-
state: Record<number, PullBlock>;
|
|
13
|
-
uids: Record<string, number>;
|
|
14
|
-
titles: Record<string, number>;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type EDNValue =
|
|
18
|
-
| { key: string }
|
|
19
|
-
| { sym: string }
|
|
20
|
-
| string
|
|
21
|
-
| EDNValue[]
|
|
22
|
-
| { list: EDNValue[] }
|
|
23
|
-
| { map: [EDNValue, EDNValue][] };
|
|
24
|
-
|
|
25
|
-
const initMockGraph = (): Graph => ({
|
|
26
|
-
state: {},
|
|
27
|
-
uids: {},
|
|
28
|
-
titles: {},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const getDbId = () => Math.ceil(Math.random() * 1000000);
|
|
32
|
-
|
|
33
|
-
type Aggregate = { type: "aggregate" };
|
|
34
|
-
type DatalogPullOption =
|
|
35
|
-
| { type: "as-expr"; value: string }
|
|
36
|
-
| { type: "limit-expr" }
|
|
37
|
-
| { type: "default-expr" };
|
|
38
|
-
type DatalogPullAttr =
|
|
39
|
-
| DatalogConstant
|
|
40
|
-
| { type: "wildcard"; value: "*" }
|
|
41
|
-
| {
|
|
42
|
-
type: "map-spec";
|
|
43
|
-
entries: {
|
|
44
|
-
key: string | DatalogPullOption;
|
|
45
|
-
value: "..." | DatalogPullAttr[];
|
|
46
|
-
}[];
|
|
47
|
-
}
|
|
48
|
-
| { type: "attr-expr"; name: string; option: DatalogPullOption };
|
|
49
|
-
type DatalogPullExpr = {
|
|
50
|
-
type: "pull";
|
|
51
|
-
variable: DatalogVariable;
|
|
52
|
-
pattern:
|
|
53
|
-
| { type: "pattern-name"; value: string }
|
|
54
|
-
| { type: "pattern-data-literal"; value: DatalogPullAttr[] };
|
|
55
|
-
};
|
|
56
|
-
type DatalogFindElem = DatalogVariable | DatalogPullExpr | Aggregate;
|
|
57
|
-
type DatalogFind = { type: "rel"; elements: DatalogFindElem[] };
|
|
58
|
-
|
|
59
|
-
type NodeAssignment = { id: number };
|
|
60
|
-
type Assignment = Record<string, NodeAssignment | string | number | RegExp>;
|
|
61
|
-
const isNode = (v: Assignment[string]): v is NodeAssignment =>
|
|
62
|
-
typeof v === "object" && v !== null && !(v instanceof RegExp);
|
|
63
|
-
|
|
64
|
-
type QueryResult = Record<string, unknown> | Record<string, unknown>[];
|
|
65
|
-
const resolvePattern = (
|
|
66
|
-
pattern: DatalogPullAttr[],
|
|
67
|
-
result: QueryResult,
|
|
68
|
-
graph: Graph
|
|
69
|
-
): unknown =>
|
|
70
|
-
Array.isArray(result)
|
|
71
|
-
? result.map((r) => resolvePattern(pattern, r, graph))
|
|
72
|
-
: pattern.some((pat) => pat.type === "wildcard")
|
|
73
|
-
? result
|
|
74
|
-
: Object.fromEntries(
|
|
75
|
-
pattern.flatMap((pat): [string, unknown][] => {
|
|
76
|
-
if (pat.type === "constant") {
|
|
77
|
-
return [[pat.value, result[pat.value as keyof PullBlock]]];
|
|
78
|
-
} else if (pat.type === "attr-expr") {
|
|
79
|
-
if (pat.option.type === "as-expr") {
|
|
80
|
-
return [[pat.option.value, result[pat.name as keyof PullBlock]]];
|
|
81
|
-
} else {
|
|
82
|
-
throw new Error(
|
|
83
|
-
`Unexpected pull attribute expression type: ${pat.option.type}`
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
} else if (pat.type === "map-spec") {
|
|
87
|
-
return pat.entries.map(({ key, value }) => {
|
|
88
|
-
const k =
|
|
89
|
-
typeof key === "string"
|
|
90
|
-
? key
|
|
91
|
-
: key.type === "as-expr"
|
|
92
|
-
? key.value
|
|
93
|
-
: "";
|
|
94
|
-
const nestedResult = result[k] as QueryResult | undefined;
|
|
95
|
-
if (!nestedResult) return [k, []];
|
|
96
|
-
if (value === "...") {
|
|
97
|
-
const nestedResults = (
|
|
98
|
-
Array.isArray(nestedResult) ? nestedResult : [nestedResult]
|
|
99
|
-
)
|
|
100
|
-
.map((a) => a[":db/id"])
|
|
101
|
-
.filter((id): id is number => typeof id === "number")
|
|
102
|
-
.map((id) => graph.state[id]);
|
|
103
|
-
return [k, resolvePattern(pattern, nestedResults, graph)];
|
|
104
|
-
} else {
|
|
105
|
-
return [k, resolvePattern(value, nestedResult, graph)];
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
} else {
|
|
109
|
-
throw new Error(`Unexpected pull pattern type: ${pat.type}`);
|
|
110
|
-
}
|
|
111
|
-
})
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
const fireQuery = ({
|
|
115
|
-
graph,
|
|
116
|
-
find,
|
|
117
|
-
where,
|
|
118
|
-
}: {
|
|
119
|
-
graph: Graph;
|
|
120
|
-
find: DatalogFind;
|
|
121
|
-
// return-map-spec?
|
|
122
|
-
with?: DatalogVariable[];
|
|
123
|
-
// inputs?
|
|
124
|
-
where: DatalogClause[];
|
|
125
|
-
}) => {
|
|
126
|
-
const getAssignments = (
|
|
127
|
-
where: DatalogClause[],
|
|
128
|
-
initialVars = [] as string[]
|
|
129
|
-
) => {
|
|
130
|
-
return where.reduce(
|
|
131
|
-
(programs, clause, index) => {
|
|
132
|
-
if (programs.assignments.size === 0 && index > 0) return programs;
|
|
133
|
-
const reconcile = (matches: Assignment[], vars: string[]) => {
|
|
134
|
-
vars.forEach((v) => programs.vars.add(v));
|
|
135
|
-
programs.assignments = new Set(
|
|
136
|
-
Array.from(
|
|
137
|
-
new Set(
|
|
138
|
-
(programs.assignments.size === 0 && index === 0
|
|
139
|
-
? matches
|
|
140
|
-
: Array.from(programs.assignments).flatMap((dict) =>
|
|
141
|
-
matches.map((dic) => ({
|
|
142
|
-
...dict,
|
|
143
|
-
...dic,
|
|
144
|
-
}))
|
|
145
|
-
)
|
|
146
|
-
).map((a) =>
|
|
147
|
-
// remove duplicate assignments
|
|
148
|
-
JSON.stringify(
|
|
149
|
-
Object.entries(a).sort(([ka], [kb]) => ka.localeCompare(kb))
|
|
150
|
-
)
|
|
151
|
-
)
|
|
152
|
-
)
|
|
153
|
-
).map((s) => Object.fromEntries(JSON.parse(s)))
|
|
154
|
-
);
|
|
155
|
-
};
|
|
156
|
-
if (clause.type === "data-pattern") {
|
|
157
|
-
const [source, relation, target] = clause.arguments;
|
|
158
|
-
if (source.type !== "variable") {
|
|
159
|
-
throw new Error("Expected source type to be variable");
|
|
160
|
-
}
|
|
161
|
-
const sourceVar = source.value;
|
|
162
|
-
if (relation.type !== "constant") {
|
|
163
|
-
throw new Error("Expected relation type to be constant");
|
|
164
|
-
}
|
|
165
|
-
const rel = relation.value;
|
|
166
|
-
const targetString = target.value.replace(/^"/, "").replace(/"$/, "");
|
|
167
|
-
const targetVar = target.value;
|
|
168
|
-
if (programs.vars.has(sourceVar)) {
|
|
169
|
-
const newAssignments = Array.from(programs.assignments).flatMap(
|
|
170
|
-
(dict): Assignment[] => {
|
|
171
|
-
const sourceEntry = dict[sourceVar];
|
|
172
|
-
if (!isNode(sourceEntry)) {
|
|
173
|
-
throw new Error(
|
|
174
|
-
"Expected the source variable to map to a node"
|
|
175
|
-
);
|
|
176
|
-
return [];
|
|
177
|
-
}
|
|
178
|
-
const sourceId = sourceEntry.id;
|
|
179
|
-
if (rel === ":block/refs") {
|
|
180
|
-
throw new Error("TODO");
|
|
181
|
-
// if (target.type !== "variable") {
|
|
182
|
-
// throw new Error(
|
|
183
|
-
// "Expected target for :block/refs to be a variable"
|
|
184
|
-
// );
|
|
185
|
-
// return [];
|
|
186
|
-
// }
|
|
187
|
-
// const targetEntry = dict[targetVar];
|
|
188
|
-
// const refs = (
|
|
189
|
-
// isNode(targetEntry)
|
|
190
|
-
// ? [targetEntry.id]
|
|
191
|
-
// : graph.edges.referencesByUid[sourceId] || []
|
|
192
|
-
// ).map((ref) => ({
|
|
193
|
-
// ...dict,
|
|
194
|
-
// [targetVar]: { uid: ref },
|
|
195
|
-
// }));
|
|
196
|
-
// if (refs.length) programs.vars.add(targetVar);
|
|
197
|
-
// return refs;
|
|
198
|
-
} else if (rel === ":block/page") {
|
|
199
|
-
// if (target.type !== "variable") {
|
|
200
|
-
// throw new Error(
|
|
201
|
-
// "Expected target for :block/page to be a variable"
|
|
202
|
-
// );
|
|
203
|
-
// return [];
|
|
204
|
-
// }
|
|
205
|
-
// const targetEntry = dict[targetVar];
|
|
206
|
-
// if (graph.edges.pagesByUid[sourceId]) {
|
|
207
|
-
// return [];
|
|
208
|
-
// } else if (isNode(targetEntry)) {
|
|
209
|
-
// return targetEntry.id ===
|
|
210
|
-
// graph.edges.blocksPageByUid[sourceId]
|
|
211
|
-
// ? [dict]
|
|
212
|
-
// : [];
|
|
213
|
-
// } else {
|
|
214
|
-
// programs.vars.add(targetVar);
|
|
215
|
-
// return [
|
|
216
|
-
// {
|
|
217
|
-
// ...dict,
|
|
218
|
-
// [targetVar]: {
|
|
219
|
-
// uid: graph.edges.blocksPageByUid[sourceId],
|
|
220
|
-
// },
|
|
221
|
-
// },
|
|
222
|
-
// ];
|
|
223
|
-
// }
|
|
224
|
-
throw new Error("TODO");
|
|
225
|
-
} else if (rel === ":node/title") {
|
|
226
|
-
const sourceTitle = graph.state[sourceId]?.[":node/title"];
|
|
227
|
-
if (target.type === "constant") {
|
|
228
|
-
if (graph.titles[targetString] === sourceId) {
|
|
229
|
-
return [dict];
|
|
230
|
-
} else {
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
} else if (target.type === "underscore") {
|
|
234
|
-
return [dict];
|
|
235
|
-
} else if (!sourceTitle) {
|
|
236
|
-
return [];
|
|
237
|
-
} else {
|
|
238
|
-
programs.vars.add(targetVar);
|
|
239
|
-
return [
|
|
240
|
-
{
|
|
241
|
-
...dict,
|
|
242
|
-
[targetVar]: sourceTitle,
|
|
243
|
-
},
|
|
244
|
-
];
|
|
245
|
-
}
|
|
246
|
-
} else if (rel === ":block/children") {
|
|
247
|
-
if (target.type !== "variable") {
|
|
248
|
-
throw new Error(
|
|
249
|
-
"Expected target for :block/children to be a variable"
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
const targetEntry = dict[targetVar];
|
|
253
|
-
const children = (
|
|
254
|
-
isNode(targetEntry)
|
|
255
|
-
? [targetEntry.id]
|
|
256
|
-
: (graph.state[sourceId]?.[":block/children"] || []).map(
|
|
257
|
-
(c) => c[":db/id"] || 0
|
|
258
|
-
)
|
|
259
|
-
).map((id) => ({
|
|
260
|
-
...dict,
|
|
261
|
-
[targetVar]: { id },
|
|
262
|
-
}));
|
|
263
|
-
if (children.length) programs.vars.add(targetVar);
|
|
264
|
-
return children;
|
|
265
|
-
} else if (rel === ":block/parents") {
|
|
266
|
-
if (target.type !== "variable") {
|
|
267
|
-
throw new Error(
|
|
268
|
-
"Expected target for :block/parents to be a variable"
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
const targetEntry = dict[targetVar];
|
|
272
|
-
const ancestors = (
|
|
273
|
-
isNode(targetEntry)
|
|
274
|
-
? [targetEntry.id]
|
|
275
|
-
: (graph.state[sourceId]?.[":block/parents"] || []).map(
|
|
276
|
-
(d) => d[":db/id"] || 0
|
|
277
|
-
)
|
|
278
|
-
).map((id) => ({
|
|
279
|
-
...dict,
|
|
280
|
-
[targetVar]: { id },
|
|
281
|
-
}));
|
|
282
|
-
if (ancestors.length) programs.vars.add(targetVar);
|
|
283
|
-
return ancestors;
|
|
284
|
-
} else if (rel === ":block/string") {
|
|
285
|
-
// if (target.type === "constant") {
|
|
286
|
-
// if (graph.edges.blocksByUid[sourceId] === targetString) {
|
|
287
|
-
// return [dict];
|
|
288
|
-
// } else {
|
|
289
|
-
// return [];
|
|
290
|
-
// }
|
|
291
|
-
// } else if (target.type === "underscore") {
|
|
292
|
-
// return [dict];
|
|
293
|
-
// } else {
|
|
294
|
-
// programs.vars.add(targetVar);
|
|
295
|
-
// return [
|
|
296
|
-
// {
|
|
297
|
-
// ...dict,
|
|
298
|
-
// [targetVar]: graph.edges.blocksByUid[sourceId],
|
|
299
|
-
// },
|
|
300
|
-
// ];
|
|
301
|
-
// }
|
|
302
|
-
throw new Error("TODO");
|
|
303
|
-
} else if (rel === ":block/heading") {
|
|
304
|
-
// if (target.type === "constant") {
|
|
305
|
-
// if (
|
|
306
|
-
// graph.edges.headingsByUid[sourceId] ===
|
|
307
|
-
// Number(targetString)
|
|
308
|
-
// ) {
|
|
309
|
-
// return [dict];
|
|
310
|
-
// } else {
|
|
311
|
-
// return [];
|
|
312
|
-
// }
|
|
313
|
-
// } else if (target.type === "underscore") {
|
|
314
|
-
// return [dict];
|
|
315
|
-
// } else {
|
|
316
|
-
// programs.vars.add(targetVar);
|
|
317
|
-
// return [
|
|
318
|
-
// {
|
|
319
|
-
// ...dict,
|
|
320
|
-
// [targetVar]: graph.edges.headingsByUid[sourceId],
|
|
321
|
-
// },
|
|
322
|
-
// ];
|
|
323
|
-
// }
|
|
324
|
-
throw new Error("TODO");
|
|
325
|
-
} else if (rel === ":create/user") {
|
|
326
|
-
// if (target.type !== "variable") {
|
|
327
|
-
// throw new Error(
|
|
328
|
-
// "Expected target for :create/user to be a variable"
|
|
329
|
-
// );
|
|
330
|
-
// return [];
|
|
331
|
-
// }
|
|
332
|
-
// const targetEntry = dict[targetVar];
|
|
333
|
-
// const userId = graph.edges.createUserByUid[sourceId];
|
|
334
|
-
// if (isNode(targetEntry)) {
|
|
335
|
-
// return targetEntry.id === userId ? [dict] : [];
|
|
336
|
-
// } else {
|
|
337
|
-
// programs.vars.add(targetVar);
|
|
338
|
-
// return [
|
|
339
|
-
// {
|
|
340
|
-
// ...dict,
|
|
341
|
-
// [targetVar]: { uid: userId },
|
|
342
|
-
// },
|
|
343
|
-
// ];
|
|
344
|
-
// }
|
|
345
|
-
throw new Error("TODO");
|
|
346
|
-
} else if (rel === ":edit/user") {
|
|
347
|
-
// if (target.type !== "variable") {
|
|
348
|
-
// throw new Error(
|
|
349
|
-
// "Expected target for :edit/user to be a variable"
|
|
350
|
-
// );
|
|
351
|
-
// return [];
|
|
352
|
-
// }
|
|
353
|
-
// const targetEntry = dict[targetVar];
|
|
354
|
-
// const userId = graph.edges.editUserByUid[sourceId];
|
|
355
|
-
// if (isNode(targetEntry)) {
|
|
356
|
-
// return targetEntry.id === userId ? [dict] : [];
|
|
357
|
-
// } else {
|
|
358
|
-
// programs.vars.add(targetVar);
|
|
359
|
-
// return [
|
|
360
|
-
// {
|
|
361
|
-
// ...dict,
|
|
362
|
-
// [targetVar]: { uid: userId },
|
|
363
|
-
// },
|
|
364
|
-
// ];
|
|
365
|
-
// }
|
|
366
|
-
throw new Error("TODO");
|
|
367
|
-
} else if (rel === ":create/time") {
|
|
368
|
-
// if (target.type === "constant") {
|
|
369
|
-
// if (
|
|
370
|
-
// graph.edges.createTimeByUid[sourceId] ===
|
|
371
|
-
// Number(targetString)
|
|
372
|
-
// ) {
|
|
373
|
-
// return [dict];
|
|
374
|
-
// } else {
|
|
375
|
-
// return [];
|
|
376
|
-
// }
|
|
377
|
-
// } else if (target.type === "underscore") {
|
|
378
|
-
// return [dict];
|
|
379
|
-
// } else {
|
|
380
|
-
// programs.vars.add(targetVar);
|
|
381
|
-
// return [
|
|
382
|
-
// {
|
|
383
|
-
// ...dict,
|
|
384
|
-
// [targetVar]: graph.edges.createTimeByUid[sourceId],
|
|
385
|
-
// },
|
|
386
|
-
// ];
|
|
387
|
-
// }
|
|
388
|
-
throw new Error("TODO");
|
|
389
|
-
} else if (rel === ":edit/time") {
|
|
390
|
-
// if (target.type === "constant") {
|
|
391
|
-
// if (
|
|
392
|
-
// graph.edges.editTimeByUid[sourceId] ===
|
|
393
|
-
// Number(targetString)
|
|
394
|
-
// ) {
|
|
395
|
-
// return [dict];
|
|
396
|
-
// } else {
|
|
397
|
-
// return [];
|
|
398
|
-
// }
|
|
399
|
-
// } else if (target.type === "underscore") {
|
|
400
|
-
// return [dict];
|
|
401
|
-
// } else {
|
|
402
|
-
// programs.vars.add(targetVar);
|
|
403
|
-
// return [
|
|
404
|
-
// {
|
|
405
|
-
// ...dict,
|
|
406
|
-
// [targetVar]: graph.edges.editTimeByUid[sourceId],
|
|
407
|
-
// },
|
|
408
|
-
// ];
|
|
409
|
-
// }
|
|
410
|
-
throw new Error("TODO");
|
|
411
|
-
} else if (rel === ":user/display-name") {
|
|
412
|
-
// if (target.type === "constant") {
|
|
413
|
-
// if (
|
|
414
|
-
// graph.edges.userDisplayByUid[sourceId] === targetString
|
|
415
|
-
// ) {
|
|
416
|
-
// return [dict];
|
|
417
|
-
// } else {
|
|
418
|
-
// return [];
|
|
419
|
-
// }
|
|
420
|
-
// } else if (target.type === "underscore") {
|
|
421
|
-
// return [dict];
|
|
422
|
-
// } else {
|
|
423
|
-
// programs.vars.add(targetVar);
|
|
424
|
-
// return [
|
|
425
|
-
// {
|
|
426
|
-
// ...dict,
|
|
427
|
-
// [targetVar]: graph.edges.userDisplayByUid[sourceId],
|
|
428
|
-
// },
|
|
429
|
-
// ];
|
|
430
|
-
// }
|
|
431
|
-
throw new Error("TODO");
|
|
432
|
-
} else {
|
|
433
|
-
throw new Error(`Unknown rel: ${rel}`);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
);
|
|
437
|
-
programs.assignments = new Set(newAssignments);
|
|
438
|
-
} else if (
|
|
439
|
-
target.type === "variable" &&
|
|
440
|
-
programs.vars.has(targetVar)
|
|
441
|
-
) {
|
|
442
|
-
const newAssignments = Array.from(programs.assignments).flatMap(
|
|
443
|
-
(_dict) => {
|
|
444
|
-
// const targetEntry = dict[targetVar];
|
|
445
|
-
if (rel === ":block/refs") {
|
|
446
|
-
// if (!isNode(targetEntry)) {
|
|
447
|
-
// throw new Error(
|
|
448
|
-
// "Expected the target variable to map to a node in :block/refs"
|
|
449
|
-
// );
|
|
450
|
-
// return [];
|
|
451
|
-
// }
|
|
452
|
-
// const targetId = targetEntry.id;
|
|
453
|
-
// const refs = (
|
|
454
|
-
// graph.edges.linkedReferencesByUid[targetId] || []
|
|
455
|
-
// ).map((ref) => ({
|
|
456
|
-
// ...dict,
|
|
457
|
-
// [v]: { uid: ref },
|
|
458
|
-
// }));
|
|
459
|
-
// if (refs.length) programs.vars.add(v);
|
|
460
|
-
// return refs;
|
|
461
|
-
throw new Error("TODO");
|
|
462
|
-
} else if (rel === ":block/page") {
|
|
463
|
-
// if (!isNode(targetEntry)) {
|
|
464
|
-
// throw new Error(
|
|
465
|
-
// "Expected the target variable to map to a node in :block/page"
|
|
466
|
-
// );
|
|
467
|
-
// return [];
|
|
468
|
-
// }
|
|
469
|
-
// const targetId = targetEntry.id;
|
|
470
|
-
// if (!graph.edges.pagesByUid[targetId]) {
|
|
471
|
-
// return [];
|
|
472
|
-
// } else {
|
|
473
|
-
// const children = Array.from(
|
|
474
|
-
// graph.edges.descendantsByUid[targetId] || []
|
|
475
|
-
// ).map((d) => ({
|
|
476
|
-
// ...dict,
|
|
477
|
-
// [v]: { uid: d },
|
|
478
|
-
// }));
|
|
479
|
-
// if (children.length) programs.vars.add(v);
|
|
480
|
-
// return children;
|
|
481
|
-
// }
|
|
482
|
-
throw new Error("TODO");
|
|
483
|
-
} else if (rel === ":node/title") {
|
|
484
|
-
// if (typeof targetEntry !== "string") {
|
|
485
|
-
// throw new Error(
|
|
486
|
-
// "Expected the target variable to map to a string in :block/refs"
|
|
487
|
-
// );
|
|
488
|
-
// return [];
|
|
489
|
-
// }
|
|
490
|
-
// const page = graph.edges.pageUidByTitle[targetEntry];
|
|
491
|
-
// if (page) {
|
|
492
|
-
// programs.vars.add(v);
|
|
493
|
-
// return [
|
|
494
|
-
// {
|
|
495
|
-
// ...dict,
|
|
496
|
-
// [v]: { uid: page },
|
|
497
|
-
// },
|
|
498
|
-
// ];
|
|
499
|
-
// }
|
|
500
|
-
// return [];
|
|
501
|
-
throw new Error("TODO");
|
|
502
|
-
} else if (rel === ":block/children") {
|
|
503
|
-
// if (!isNode(targetEntry)) {
|
|
504
|
-
// throw new Error(
|
|
505
|
-
// "Expected the target variable to map to a node in :block/children"
|
|
506
|
-
// );
|
|
507
|
-
// }
|
|
508
|
-
// const targetId = targetEntry.id;
|
|
509
|
-
// const parent = graph.edges.parentByUid[targetId];
|
|
510
|
-
// if (parent) {
|
|
511
|
-
// programs.vars.add(v);
|
|
512
|
-
// return [
|
|
513
|
-
// {
|
|
514
|
-
// ...dict,
|
|
515
|
-
// [v]: { uid: parent },
|
|
516
|
-
// },
|
|
517
|
-
// ];
|
|
518
|
-
// } else {
|
|
519
|
-
// return [];
|
|
520
|
-
// }
|
|
521
|
-
throw new Error("TODO");
|
|
522
|
-
} else if (rel === ":block/parents") {
|
|
523
|
-
// if (!isNode(targetEntry)) {
|
|
524
|
-
// throw new Error(
|
|
525
|
-
// "Expected the target variable to map to a node in :block/parents"
|
|
526
|
-
// );
|
|
527
|
-
// return [];
|
|
528
|
-
// }
|
|
529
|
-
// const targetId = targetEntry.id;
|
|
530
|
-
// const ancestors = Array.from(
|
|
531
|
-
// graph.edges.ancestorsByUid[targetId] || []
|
|
532
|
-
// ).map((child) => ({
|
|
533
|
-
// ...dict,
|
|
534
|
-
// [v]: { uid: child },
|
|
535
|
-
// }));
|
|
536
|
-
// if (ancestors.length) programs.vars.add(v);
|
|
537
|
-
// return ancestors;
|
|
538
|
-
throw new Error("TODO");
|
|
539
|
-
} else if (rel === ":block/string") {
|
|
540
|
-
// if (typeof targetEntry !== "string") {
|
|
541
|
-
// throw new Error(
|
|
542
|
-
// "Expected the target variable to map to a string in :block/string"
|
|
543
|
-
// );
|
|
544
|
-
// return [];
|
|
545
|
-
// }
|
|
546
|
-
// const blocks = Object.entries(graph.edges.blocksByUid)
|
|
547
|
-
// .filter(([_, v]) => v === targetEntry)
|
|
548
|
-
// .map(([child]) => ({
|
|
549
|
-
// ...dict,
|
|
550
|
-
// [v]: { uid: child },
|
|
551
|
-
// }));
|
|
552
|
-
// if (blocks.length) programs.vars.add(v);
|
|
553
|
-
// return blocks;
|
|
554
|
-
throw new Error("TODO");
|
|
555
|
-
} else if (rel === ":block/heading") {
|
|
556
|
-
// if (typeof targetEntry !== "number") {
|
|
557
|
-
// throw new Error(
|
|
558
|
-
// "Expected the target variable to map to a number in :block/heading"
|
|
559
|
-
// );
|
|
560
|
-
// return [];
|
|
561
|
-
// }
|
|
562
|
-
// const blocks = Object.entries(graph.edges.headingsByUid)
|
|
563
|
-
// .filter(([_, v]) => v === targetEntry)
|
|
564
|
-
// .map(([child]) => ({
|
|
565
|
-
// ...dict,
|
|
566
|
-
// [v]: { uid: child },
|
|
567
|
-
// }));
|
|
568
|
-
// if (blocks.length) programs.vars.add(v);
|
|
569
|
-
// return blocks;
|
|
570
|
-
throw new Error("TODO");
|
|
571
|
-
} else if (rel === ":create/user") {
|
|
572
|
-
// if (!isNode(targetEntry)) {
|
|
573
|
-
// throw new Error(
|
|
574
|
-
// "Expected the target variable to map to a node in :create/user"
|
|
575
|
-
// );
|
|
576
|
-
// }
|
|
577
|
-
// const targetId = targetEntry.id;
|
|
578
|
-
// const children = Object.keys(graph.edges.createUserByUid)
|
|
579
|
-
// .filter(
|
|
580
|
-
// (node) => graph.edges.createUserByUid[node] === targetId
|
|
581
|
-
// )
|
|
582
|
-
// .map((d) => ({
|
|
583
|
-
// ...dict,
|
|
584
|
-
// [v]: { uid: d },
|
|
585
|
-
// }));
|
|
586
|
-
// if (children.length) programs.vars.add(v);
|
|
587
|
-
// return children;
|
|
588
|
-
throw new Error("TODO");
|
|
589
|
-
} else if (rel === ":edit/user") {
|
|
590
|
-
// if (!isNode(targetEntry)) {
|
|
591
|
-
// throw new Error(
|
|
592
|
-
// "Expected the target variable to map to a node in :edit/user"
|
|
593
|
-
// );
|
|
594
|
-
// }
|
|
595
|
-
// const targetId = targetEntry.id;
|
|
596
|
-
// const children = Object.keys(graph.edges.editUserByUid)
|
|
597
|
-
// .filter(
|
|
598
|
-
// (node) =>
|
|
599
|
-
// graph.edges.editUserByUid[Number(node)] === targetId
|
|
600
|
-
// )
|
|
601
|
-
// .map((d) => ({
|
|
602
|
-
// ...dict,
|
|
603
|
-
// [v]: { uid: d },
|
|
604
|
-
// }));
|
|
605
|
-
// if (children.length) programs.vars.add(v);
|
|
606
|
-
// return children;
|
|
607
|
-
throw new Error("TODO");
|
|
608
|
-
} else if (rel === ":create/time") {
|
|
609
|
-
// if (typeof targetEntry !== "number") {
|
|
610
|
-
// throw new Error(
|
|
611
|
-
// "Expected the target variable to map to a number in :create/time"
|
|
612
|
-
// );
|
|
613
|
-
// }
|
|
614
|
-
// const blocks = Object.entries(graph.edges.createTimeByUid)
|
|
615
|
-
// .filter(([_, v]) => v === targetEntry)
|
|
616
|
-
// .map(([child]) => ({
|
|
617
|
-
// ...dict,
|
|
618
|
-
// [v]: { uid: child },
|
|
619
|
-
// }));
|
|
620
|
-
// if (blocks.length) programs.vars.add(v);
|
|
621
|
-
// return blocks;
|
|
622
|
-
throw new Error("TODO");
|
|
623
|
-
} else if (rel === ":edit/time") {
|
|
624
|
-
// if (typeof targetEntry !== "number") {
|
|
625
|
-
// throw new Error(
|
|
626
|
-
// "Expected the target variable to map to a number in :edit/time"
|
|
627
|
-
// );
|
|
628
|
-
// }
|
|
629
|
-
// const blocks = Object.entries(graph.edges.editTimeByUid)
|
|
630
|
-
// .filter(([_, v]) => v === targetEntry)
|
|
631
|
-
// .map(([child]) => ({
|
|
632
|
-
// ...dict,
|
|
633
|
-
// [v]: { uid: child },
|
|
634
|
-
// }));
|
|
635
|
-
// if (blocks.length) programs.vars.add(v);
|
|
636
|
-
// return blocks;
|
|
637
|
-
throw new Error("TODO");
|
|
638
|
-
} else if (rel === ":user/display-name") {
|
|
639
|
-
// if (typeof targetEntry !== "string") {
|
|
640
|
-
// throw new Error(
|
|
641
|
-
// "Expected the target variable to map to a string in :block/refs"
|
|
642
|
-
// );
|
|
643
|
-
// }
|
|
644
|
-
// const displayName = targetEntry
|
|
645
|
-
// .replace(/^"/, "")
|
|
646
|
-
// .replace(/"$/, "");
|
|
647
|
-
// const user = graph.edges.userUidByDisplay[displayName];
|
|
648
|
-
// if (user) {
|
|
649
|
-
// programs.vars.add(v);
|
|
650
|
-
// return [
|
|
651
|
-
// {
|
|
652
|
-
// ...dict,
|
|
653
|
-
// [v]: { uid: user },
|
|
654
|
-
// },
|
|
655
|
-
// ];
|
|
656
|
-
// }
|
|
657
|
-
// return [];
|
|
658
|
-
throw new Error("TODO");
|
|
659
|
-
} else {
|
|
660
|
-
throw new Error(`Unknown rel: ${rel}`);
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
);
|
|
664
|
-
programs.assignments = new Set(newAssignments);
|
|
665
|
-
} else {
|
|
666
|
-
const matches: Assignment[] | Error =
|
|
667
|
-
rel === ":children/view-type"
|
|
668
|
-
? target.type === "constant"
|
|
669
|
-
? Object.values(graph.uids)
|
|
670
|
-
.filter(
|
|
671
|
-
(id) =>
|
|
672
|
-
graph.state[id][":children/view-type"] !==
|
|
673
|
-
targetString
|
|
674
|
-
)
|
|
675
|
-
.map((id) => ({ [sourceVar]: { id } }))
|
|
676
|
-
: target.type === "underscore"
|
|
677
|
-
? Object.values(graph.uids).map((id) => ({
|
|
678
|
-
[sourceVar]: { id },
|
|
679
|
-
}))
|
|
680
|
-
: Object.values(graph.uids).map((id) => ({
|
|
681
|
-
[sourceVar]: { id },
|
|
682
|
-
[targetVar]:
|
|
683
|
-
graph.state[id][":children/view-type"] || ":bullet",
|
|
684
|
-
}))
|
|
685
|
-
: rel === ":block/uid"
|
|
686
|
-
? target.type === "constant"
|
|
687
|
-
? [{ [sourceVar]: { id: graph.uids[target.value] } }]
|
|
688
|
-
: target.type === "underscore"
|
|
689
|
-
? Object.values(graph.uids).map((id) => ({
|
|
690
|
-
[sourceVar]: { id },
|
|
691
|
-
}))
|
|
692
|
-
: Object.entries(graph.uids).map(([uid, id]) => ({
|
|
693
|
-
[sourceVar]: { id },
|
|
694
|
-
[targetVar]: uid,
|
|
695
|
-
}))
|
|
696
|
-
: new Error(`Unknown rel: ${rel}`);
|
|
697
|
-
/*
|
|
698
|
-
rel === ":block/refs"
|
|
699
|
-
? target.type !== "variable"
|
|
700
|
-
? []
|
|
701
|
-
: Object.entries(graph.edges.referencesByUid).flatMap(
|
|
702
|
-
([source, refs]) =>
|
|
703
|
-
refs.map((ref) => ({
|
|
704
|
-
[v]: { uid: source },
|
|
705
|
-
[targetVar]: { uid: ref },
|
|
706
|
-
}))
|
|
707
|
-
)
|
|
708
|
-
: rel === ":block/page"
|
|
709
|
-
? target.type !== "variable"
|
|
710
|
-
? []
|
|
711
|
-
: Object.entries(graph.edges.blocksPageByUid).map(
|
|
712
|
-
([b, p]) => ({
|
|
713
|
-
[v]: { uid: b },
|
|
714
|
-
[targetVar]: { uid: p },
|
|
715
|
-
})
|
|
716
|
-
)
|
|
717
|
-
: rel === ":node/title"
|
|
718
|
-
? target.type === "constant"
|
|
719
|
-
? graph.edges.pageUidByTitle[targetString]
|
|
720
|
-
? [
|
|
721
|
-
{
|
|
722
|
-
[v]: {
|
|
723
|
-
uid: graph.edges.pageUidByTitle[targetString],
|
|
724
|
-
},
|
|
725
|
-
},
|
|
726
|
-
]
|
|
727
|
-
: []
|
|
728
|
-
: target.type === "underscore"
|
|
729
|
-
? Object.values(graph.edges.pageUidByTitle).map((uid) => ({
|
|
730
|
-
[v]: { uid },
|
|
731
|
-
}))
|
|
732
|
-
: Object.entries(graph.edges.pageUidByTitle).map(
|
|
733
|
-
([title, uid]) => ({
|
|
734
|
-
[v]: { uid },
|
|
735
|
-
[targetVar]: title,
|
|
736
|
-
})
|
|
737
|
-
)
|
|
738
|
-
: rel === ":block/children"
|
|
739
|
-
? target.type !== "variable"
|
|
740
|
-
? []
|
|
741
|
-
: Object.entries(graph.edges.childrenByUid).flatMap(
|
|
742
|
-
([source, refs]) =>
|
|
743
|
-
refs.map((ref) => ({
|
|
744
|
-
[v]: { uid: source },
|
|
745
|
-
[targetVar]: { uid: ref },
|
|
746
|
-
}))
|
|
747
|
-
)
|
|
748
|
-
: rel === ":block/parents"
|
|
749
|
-
? target.type !== "variable"
|
|
750
|
-
? []
|
|
751
|
-
: Object.entries(graph.edges.ancestorsByUid).flatMap(
|
|
752
|
-
([source, refs]) =>
|
|
753
|
-
Array.from(refs).map((ref) => ({
|
|
754
|
-
[v]: { uid: source },
|
|
755
|
-
[targetVar]: { uid: ref },
|
|
756
|
-
}))
|
|
757
|
-
)
|
|
758
|
-
: rel === ":block/string"
|
|
759
|
-
? target.type === "constant"
|
|
760
|
-
? Object.entries(graph.edges.blocksByUid)
|
|
761
|
-
.filter(([_, text]) => text !== targetString)
|
|
762
|
-
.map(([uid]) => ({ [v]: { uid } }))
|
|
763
|
-
: target.type === "underscore"
|
|
764
|
-
? Object.keys(graph.edges.blocksByUid).map((uid) => ({
|
|
765
|
-
[v]: { uid },
|
|
766
|
-
}))
|
|
767
|
-
: Object.entries(graph.edges.blocksByUid).map(
|
|
768
|
-
([uid, text]) => ({
|
|
769
|
-
[v]: { uid },
|
|
770
|
-
[targetVar]: text,
|
|
771
|
-
})
|
|
772
|
-
)
|
|
773
|
-
: rel === ":block/heading"
|
|
774
|
-
? target.type === "constant"
|
|
775
|
-
? Object.entries(graph.edges.headingsByUid)
|
|
776
|
-
.filter(([_, text]) => text !== Number(targetString))
|
|
777
|
-
.map(([uid]) => ({ [v]: { uid } }))
|
|
778
|
-
: target.type === "underscore"
|
|
779
|
-
? Object.keys(graph.edges.headingsByUid).map((uid) => ({
|
|
780
|
-
[v]: { uid },
|
|
781
|
-
}))
|
|
782
|
-
: Object.entries(graph.edges.headingsByUid).map(
|
|
783
|
-
([uid, text]) => ({
|
|
784
|
-
[v]: { uid },
|
|
785
|
-
[targetVar]: text,
|
|
786
|
-
})
|
|
787
|
-
)
|
|
788
|
-
: rel === ":create/user"
|
|
789
|
-
? target.type !== "variable"
|
|
790
|
-
? []
|
|
791
|
-
: Object.entries(graph.edges.createUserByUid).map(
|
|
792
|
-
([b, p]) => ({
|
|
793
|
-
[v]: { uid: b },
|
|
794
|
-
[targetVar]: { uid: p },
|
|
795
|
-
})
|
|
796
|
-
)
|
|
797
|
-
: rel === ":edit/user"
|
|
798
|
-
? target.type !== "variable"
|
|
799
|
-
? []
|
|
800
|
-
: Object.entries(graph.edges.editUserByUid).map(([b, p]) => ({
|
|
801
|
-
[v]: { uid: b },
|
|
802
|
-
[targetVar]: { uid: p },
|
|
803
|
-
}))
|
|
804
|
-
: rel === ":create/time"
|
|
805
|
-
? target.type === "constant"
|
|
806
|
-
? Object.entries(graph.edges.createTimeByUid)
|
|
807
|
-
.filter(([_, text]) => text !== Number(targetString))
|
|
808
|
-
.map(([uid]) => ({ [v]: { uid } }))
|
|
809
|
-
: target.type === "underscore"
|
|
810
|
-
? Object.keys(graph.edges.createTimeByUid).map((uid) => ({
|
|
811
|
-
[v]: { uid },
|
|
812
|
-
}))
|
|
813
|
-
: Object.entries(graph.edges.createTimeByUid).map(
|
|
814
|
-
([uid, text]) => ({
|
|
815
|
-
[v]: { uid },
|
|
816
|
-
[targetVar]: text,
|
|
817
|
-
})
|
|
818
|
-
)
|
|
819
|
-
: rel === ":edit/time"
|
|
820
|
-
? target.type === "constant"
|
|
821
|
-
? Object.entries(graph.edges.editTimeByUid)
|
|
822
|
-
.filter(([_, text]) => text !== Number(targetString))
|
|
823
|
-
.map(([uid]) => ({ [v]: { uid } }))
|
|
824
|
-
: target.type === "underscore"
|
|
825
|
-
? Object.keys(graph.edges.editTimeByUid).map((uid) => ({
|
|
826
|
-
[v]: { uid },
|
|
827
|
-
}))
|
|
828
|
-
: Object.entries(graph.edges.editTimeByUid).map(
|
|
829
|
-
([uid, text]) => ({
|
|
830
|
-
[v]: { uid },
|
|
831
|
-
[targetVar]: text,
|
|
832
|
-
})
|
|
833
|
-
)
|
|
834
|
-
: rel === ":user/display-name"
|
|
835
|
-
? target.type === "constant"
|
|
836
|
-
? graph.edges.userUidByDisplay[targetString]
|
|
837
|
-
? [
|
|
838
|
-
{
|
|
839
|
-
[v]: {
|
|
840
|
-
uid: graph.edges.userUidByDisplay[targetString],
|
|
841
|
-
},
|
|
842
|
-
},
|
|
843
|
-
]
|
|
844
|
-
: []
|
|
845
|
-
: target.type === "underscore"
|
|
846
|
-
? Object.values(graph.edges.userUidByDisplay).map((uid) => ({
|
|
847
|
-
[v]: { uid },
|
|
848
|
-
}))
|
|
849
|
-
: Object.entries(graph.edges.userUidByDisplay).map(
|
|
850
|
-
([title, uid]) => ({
|
|
851
|
-
[v]: { uid },
|
|
852
|
-
[targetVar]: title,
|
|
853
|
-
})
|
|
854
|
-
)*/
|
|
855
|
-
if (matches instanceof Error) {
|
|
856
|
-
throw matches;
|
|
857
|
-
}
|
|
858
|
-
reconcile(
|
|
859
|
-
matches,
|
|
860
|
-
target.type === "variable" ? [sourceVar, targetVar] : [sourceVar]
|
|
861
|
-
);
|
|
862
|
-
}
|
|
863
|
-
} else if (
|
|
864
|
-
clause.type === "or-clause" ||
|
|
865
|
-
clause.type === "or-join-clause"
|
|
866
|
-
) {
|
|
867
|
-
let matches: Assignment[] = [];
|
|
868
|
-
for (const cls of clause.clauses) {
|
|
869
|
-
const assignments = getAssignments(
|
|
870
|
-
[cls],
|
|
871
|
-
Array.from(programs.vars)
|
|
872
|
-
);
|
|
873
|
-
if (assignments.size) {
|
|
874
|
-
matches = Array.from(assignments);
|
|
875
|
-
break;
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
const vars =
|
|
879
|
-
clause.type === "or-join-clause"
|
|
880
|
-
? clause.variables.map((v) => v.value)
|
|
881
|
-
: Object.keys(matches[0] || {});
|
|
882
|
-
const varSet = new Set(vars);
|
|
883
|
-
matches.forEach((a) => {
|
|
884
|
-
Object.keys(a).forEach((k) => {
|
|
885
|
-
if (!varSet.has(k)) {
|
|
886
|
-
delete a[k];
|
|
887
|
-
}
|
|
888
|
-
});
|
|
889
|
-
});
|
|
890
|
-
reconcile(matches, vars);
|
|
891
|
-
} else if (clause.type === "and-clause") {
|
|
892
|
-
const matches = Array.from(
|
|
893
|
-
getAssignments(clause.clauses, Array.from(programs.vars))
|
|
894
|
-
);
|
|
895
|
-
reconcile(matches, Object.keys(matches[0] || {}));
|
|
896
|
-
} else if (clause.type === "pred-expr") {
|
|
897
|
-
if (clause.pred === "clojure.string/includes?") {
|
|
898
|
-
const [variable, constant] = clause.arguments;
|
|
899
|
-
if (variable?.type !== "variable") {
|
|
900
|
-
throw new Error(
|
|
901
|
-
"Expected type to be variable for first clojure.string/includes? argument."
|
|
902
|
-
);
|
|
903
|
-
}
|
|
904
|
-
const v = variable.value;
|
|
905
|
-
if (!programs.vars.has(v)) {
|
|
906
|
-
throw new Error(
|
|
907
|
-
"Expected first clojure.string/includes? argument to be predefined variable."
|
|
908
|
-
);
|
|
909
|
-
}
|
|
910
|
-
if (constant?.type !== "constant") {
|
|
911
|
-
throw new Error(
|
|
912
|
-
"Expected type to be constant for second clojure.string/includes? argument."
|
|
913
|
-
);
|
|
914
|
-
}
|
|
915
|
-
const newAssignments = Array.from(programs.assignments).flatMap(
|
|
916
|
-
(dict) => {
|
|
917
|
-
const sourceEntry = dict[v];
|
|
918
|
-
if (typeof sourceEntry !== "string") {
|
|
919
|
-
throw new Error("Expected the variable to map to a string");
|
|
920
|
-
}
|
|
921
|
-
if (
|
|
922
|
-
sourceEntry.includes(
|
|
923
|
-
constant.value.replace(/^"/, "").replace(/"$/, "")
|
|
924
|
-
)
|
|
925
|
-
) {
|
|
926
|
-
return [dict];
|
|
927
|
-
} else {
|
|
928
|
-
return [];
|
|
929
|
-
}
|
|
930
|
-
}
|
|
931
|
-
);
|
|
932
|
-
programs.assignments = new Set(newAssignments);
|
|
933
|
-
} else if (clause.pred === "clojure.string/starts-with?") {
|
|
934
|
-
const [variable, constant] = clause.arguments;
|
|
935
|
-
const v = variable.value;
|
|
936
|
-
if (variable?.type !== "variable") {
|
|
937
|
-
throw new Error(
|
|
938
|
-
"Expected type to be variable for first clojure.string/starts-with? argument."
|
|
939
|
-
);
|
|
940
|
-
}
|
|
941
|
-
if (!programs.vars.has(v)) {
|
|
942
|
-
throw new Error(
|
|
943
|
-
"Expected first clojure.string/starts-with? argument to be predefined variable."
|
|
944
|
-
);
|
|
945
|
-
}
|
|
946
|
-
if (constant?.type !== "constant") {
|
|
947
|
-
throw new Error(
|
|
948
|
-
"Expected type to be constant for second clojure.string/starts-with? argument."
|
|
949
|
-
);
|
|
950
|
-
}
|
|
951
|
-
const newAssignments = Array.from(programs.assignments).flatMap(
|
|
952
|
-
(dict) => {
|
|
953
|
-
const sourceEntry = dict[v];
|
|
954
|
-
if (typeof sourceEntry !== "string") {
|
|
955
|
-
throw new Error("Expected the variable to map to a string");
|
|
956
|
-
return [];
|
|
957
|
-
}
|
|
958
|
-
if (
|
|
959
|
-
sourceEntry.startsWith(
|
|
960
|
-
constant.value.replace(/^"/, "").replace(/"$/, "")
|
|
961
|
-
)
|
|
962
|
-
) {
|
|
963
|
-
return [dict];
|
|
964
|
-
} else {
|
|
965
|
-
return [];
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
);
|
|
969
|
-
programs.assignments = new Set(newAssignments);
|
|
970
|
-
} else if (clause.pred === "clojure.string/ends-with?") {
|
|
971
|
-
const [variable, constant] = clause.arguments;
|
|
972
|
-
const v = variable.value;
|
|
973
|
-
if (variable?.type !== "variable") {
|
|
974
|
-
throw new Error(
|
|
975
|
-
"Expected type to be variable for first clojure.string/ends-with? argument."
|
|
976
|
-
);
|
|
977
|
-
}
|
|
978
|
-
if (!programs.vars.has(v)) {
|
|
979
|
-
throw new Error(
|
|
980
|
-
"Expected first clojure.string/ends-with? argument to be predefined variable."
|
|
981
|
-
);
|
|
982
|
-
}
|
|
983
|
-
if (constant?.type !== "constant") {
|
|
984
|
-
throw new Error(
|
|
985
|
-
"Expected type to be constant for second clojure.string/ends-with? argument."
|
|
986
|
-
);
|
|
987
|
-
}
|
|
988
|
-
const newAssignments = Array.from(programs.assignments).flatMap(
|
|
989
|
-
(dict) => {
|
|
990
|
-
const sourceEntry = dict[v];
|
|
991
|
-
if (typeof sourceEntry !== "string") {
|
|
992
|
-
throw new Error("Expected the variable to map to a string");
|
|
993
|
-
}
|
|
994
|
-
if (
|
|
995
|
-
sourceEntry.endsWith(
|
|
996
|
-
constant.value.replace(/^"/, "").replace(/"$/, "")
|
|
997
|
-
)
|
|
998
|
-
) {
|
|
999
|
-
return [dict];
|
|
1000
|
-
} else {
|
|
1001
|
-
return [];
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
);
|
|
1005
|
-
programs.assignments = new Set(newAssignments);
|
|
1006
|
-
} else if (clause.pred === "re-find") {
|
|
1007
|
-
const [regex, variable] = clause.arguments;
|
|
1008
|
-
const v = variable.value;
|
|
1009
|
-
const r = regex.value;
|
|
1010
|
-
if (variable?.type !== "variable") {
|
|
1011
|
-
throw new Error(
|
|
1012
|
-
"Expected type to be variable for first re-find argument."
|
|
1013
|
-
);
|
|
1014
|
-
}
|
|
1015
|
-
if (!programs.vars.has(v)) {
|
|
1016
|
-
throw new Error(
|
|
1017
|
-
"Expected first re-find argument to be predefined variable."
|
|
1018
|
-
);
|
|
1019
|
-
}
|
|
1020
|
-
if (regex?.type !== "variable") {
|
|
1021
|
-
throw new Error(
|
|
1022
|
-
"Expected type to be variable for second re-find argument."
|
|
1023
|
-
);
|
|
1024
|
-
}
|
|
1025
|
-
if (!programs.vars.has(r)) {
|
|
1026
|
-
throw new Error(
|
|
1027
|
-
"Expected second re-find argument to be predefined variable."
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
const newAssignments = Array.from(programs.assignments).filter(
|
|
1031
|
-
(dict) => {
|
|
1032
|
-
const regexEntry = dict[r];
|
|
1033
|
-
if (!(regexEntry instanceof RegExp)) {
|
|
1034
|
-
throw new Error("Expected the variable to map to a regexp");
|
|
1035
|
-
}
|
|
1036
|
-
const targetEntry = dict[v];
|
|
1037
|
-
if (typeof targetEntry !== "string") {
|
|
1038
|
-
throw new Error("Expected the variable to map to a string");
|
|
1039
|
-
}
|
|
1040
|
-
return regexEntry.test(targetEntry);
|
|
1041
|
-
}
|
|
1042
|
-
);
|
|
1043
|
-
programs.assignments = new Set(newAssignments);
|
|
1044
|
-
} else if (clause.pred === ">") {
|
|
1045
|
-
const [left, right] = clause.arguments;
|
|
1046
|
-
const l = left.value;
|
|
1047
|
-
const r = right.value;
|
|
1048
|
-
if (left?.type === "variable" && !programs.vars.has(l)) {
|
|
1049
|
-
throw new Error(
|
|
1050
|
-
"If left argument is a variable, it must be predefined"
|
|
1051
|
-
);
|
|
1052
|
-
}
|
|
1053
|
-
if (right?.type === "variable" && !programs.vars.has(r)) {
|
|
1054
|
-
throw new Error(
|
|
1055
|
-
"If right argument is a variable, it must be predefined"
|
|
1056
|
-
);
|
|
1057
|
-
}
|
|
1058
|
-
const newAssignments = Array.from(programs.assignments).filter(
|
|
1059
|
-
(dict) => {
|
|
1060
|
-
const leftValue =
|
|
1061
|
-
left.type === "constant" ? Number(left.value) : dict[r];
|
|
1062
|
-
if (typeof leftValue !== "number") {
|
|
1063
|
-
throw new Error("Left argument must be a number");
|
|
1064
|
-
}
|
|
1065
|
-
const rightValue =
|
|
1066
|
-
right.type === "constant" ? Number(right.value) : dict[r];
|
|
1067
|
-
if (typeof rightValue !== "number") {
|
|
1068
|
-
throw new Error("Right argument must be a number");
|
|
1069
|
-
}
|
|
1070
|
-
return leftValue > rightValue;
|
|
1071
|
-
}
|
|
1072
|
-
);
|
|
1073
|
-
programs.assignments = new Set(newAssignments);
|
|
1074
|
-
} else if (clause.pred === "<") {
|
|
1075
|
-
const [left, right] = clause.arguments;
|
|
1076
|
-
const l = left.value;
|
|
1077
|
-
const r = right.value;
|
|
1078
|
-
if (left?.type === "variable" && !programs.vars.has(l)) {
|
|
1079
|
-
throw new Error(
|
|
1080
|
-
"If left argument is a variable, it must be predefined"
|
|
1081
|
-
);
|
|
1082
|
-
}
|
|
1083
|
-
if (right?.type === "variable" && !programs.vars.has(r)) {
|
|
1084
|
-
throw new Error(
|
|
1085
|
-
"If right argument is a variable, it must be predefined"
|
|
1086
|
-
);
|
|
1087
|
-
}
|
|
1088
|
-
const newAssignments = Array.from(programs.assignments).filter(
|
|
1089
|
-
(dict) => {
|
|
1090
|
-
const leftValue =
|
|
1091
|
-
left.type === "constant" ? Number(left.value) : dict[r];
|
|
1092
|
-
if (typeof leftValue !== "number") {
|
|
1093
|
-
throw new Error("Left argument must be a number");
|
|
1094
|
-
}
|
|
1095
|
-
const rightValue =
|
|
1096
|
-
right.type === "constant" ? Number(right.value) : dict[r];
|
|
1097
|
-
if (typeof rightValue !== "number") {
|
|
1098
|
-
throw new Error("Right argument must be a number");
|
|
1099
|
-
}
|
|
1100
|
-
return leftValue < rightValue;
|
|
1101
|
-
}
|
|
1102
|
-
);
|
|
1103
|
-
programs.assignments = new Set(newAssignments);
|
|
1104
|
-
} else {
|
|
1105
|
-
throw new Error(`Unexpected predicate ${clause.pred}`);
|
|
1106
|
-
}
|
|
1107
|
-
} else if (clause.type === "fn-expr") {
|
|
1108
|
-
if (clause.fn === "re-pattern") {
|
|
1109
|
-
const [constant] = clause.arguments;
|
|
1110
|
-
if (constant?.type !== "constant") {
|
|
1111
|
-
throw new Error(
|
|
1112
|
-
"Expected type to be constant for first re-pattern argument."
|
|
1113
|
-
);
|
|
1114
|
-
}
|
|
1115
|
-
const { binding } = clause;
|
|
1116
|
-
if (binding.type !== "bind-scalar") {
|
|
1117
|
-
throw new Error(
|
|
1118
|
-
"Expected type to be scalar for first re-pattern binding."
|
|
1119
|
-
);
|
|
1120
|
-
}
|
|
1121
|
-
const newAssignments = Array.from(programs.assignments).map(
|
|
1122
|
-
(dict) => {
|
|
1123
|
-
return {
|
|
1124
|
-
...dict,
|
|
1125
|
-
[binding.variable.value]: new RegExp(
|
|
1126
|
-
constant.value.replace(/^"/, "").replace(/"$/, "")
|
|
1127
|
-
),
|
|
1128
|
-
};
|
|
1129
|
-
}
|
|
1130
|
-
);
|
|
1131
|
-
programs.assignments = new Set(newAssignments);
|
|
1132
|
-
} else {
|
|
1133
|
-
throw new Error(`Unexpected fn name ${clause.fn}`);
|
|
1134
|
-
}
|
|
1135
|
-
} else {
|
|
1136
|
-
throw new Error(`Unexpected type ${clause.type}`);
|
|
1137
|
-
}
|
|
1138
|
-
return programs;
|
|
1139
|
-
},
|
|
1140
|
-
{
|
|
1141
|
-
assignments: new Set<Assignment>([]),
|
|
1142
|
-
vars: new Set<string>(initialVars),
|
|
1143
|
-
}
|
|
1144
|
-
).assignments;
|
|
1145
|
-
};
|
|
1146
|
-
const assignments = getAssignments(where);
|
|
1147
|
-
const results = Array.from(assignments).map((res) =>
|
|
1148
|
-
find.elements.map((el) => {
|
|
1149
|
-
if (el.type === "variable") {
|
|
1150
|
-
const node = res[el.value];
|
|
1151
|
-
if (isNode(node)) {
|
|
1152
|
-
return node.id;
|
|
1153
|
-
} else if (node instanceof RegExp) {
|
|
1154
|
-
return node.source;
|
|
1155
|
-
} else {
|
|
1156
|
-
return node;
|
|
1157
|
-
}
|
|
1158
|
-
} else if (el.type === "pull") {
|
|
1159
|
-
const node = res[el.variable.value];
|
|
1160
|
-
if (typeof node === "undefined") {
|
|
1161
|
-
throw new Error(
|
|
1162
|
-
`Failed to find ${el.variable.value} in result: ${JSON.stringify(
|
|
1163
|
-
res
|
|
1164
|
-
)}`
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
if (el.pattern.type === "pattern-data-literal") {
|
|
1168
|
-
if (isNode(node)) {
|
|
1169
|
-
const result = graph.state[node.id];
|
|
1170
|
-
return resolvePattern(el.pattern.value, result, graph);
|
|
1171
|
-
} else {
|
|
1172
|
-
throw new Error(
|
|
1173
|
-
`Unexpected pull variable: ${el.variable.value} - ${node}`
|
|
1174
|
-
);
|
|
1175
|
-
}
|
|
1176
|
-
} else {
|
|
1177
|
-
throw new Error(
|
|
1178
|
-
`Unexpected pull element pattern type: ${el.pattern.type}`
|
|
1179
|
-
);
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
throw new Error(`Unexpected Find element type: ${el.type}`);
|
|
1183
|
-
})
|
|
1184
|
-
);
|
|
1185
|
-
return results;
|
|
1186
|
-
};
|
|
1187
|
-
|
|
1188
|
-
const mockQuery = ({ graph, query }: { graph: Graph; query: string }) => {
|
|
1189
|
-
const data = parseEDNString(query) as EDNValue[];
|
|
1190
|
-
const findIndex = data.findIndex(
|
|
1191
|
-
(d) => typeof d === "object" && "key" in d && d.key === "find"
|
|
1192
|
-
);
|
|
1193
|
-
const whereIndex = data.findIndex(
|
|
1194
|
-
(d) => typeof d === "object" && "key" in d && d.key === "where"
|
|
1195
|
-
);
|
|
1196
|
-
const findPattern = data.slice(findIndex + 1, whereIndex);
|
|
1197
|
-
const find: DatalogFind = {
|
|
1198
|
-
type: "rel",
|
|
1199
|
-
elements: findPattern.map((p): DatalogFind["elements"][number] => {
|
|
1200
|
-
if (typeof p !== "object") {
|
|
1201
|
-
throw new Error(
|
|
1202
|
-
`Unexpected type for datalog find, looking for object: ${JSON.stringify(
|
|
1203
|
-
p
|
|
1204
|
-
)}`
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
if ("sym" in p) return { type: "variable" as const, value: p.sym };
|
|
1208
|
-
if ("list" in p) {
|
|
1209
|
-
const [pull, name, attrs] = p.list;
|
|
1210
|
-
if (
|
|
1211
|
-
typeof pull !== "object" ||
|
|
1212
|
-
!("sym" in pull) ||
|
|
1213
|
-
pull.sym !== "pull"
|
|
1214
|
-
) {
|
|
1215
|
-
throw new Error(
|
|
1216
|
-
`Expected first edn value to be a pull symbol. Found: ${JSON.stringify(
|
|
1217
|
-
p
|
|
1218
|
-
)}`
|
|
1219
|
-
);
|
|
1220
|
-
}
|
|
1221
|
-
if (typeof name !== "object" || !("sym" in name)) {
|
|
1222
|
-
throw new Error(
|
|
1223
|
-
`Expected second edn value to be a pull symbol. Found: ${JSON.stringify(
|
|
1224
|
-
p
|
|
1225
|
-
)}`
|
|
1226
|
-
);
|
|
1227
|
-
}
|
|
1228
|
-
if (!Array.isArray(attrs)) {
|
|
1229
|
-
throw new Error(
|
|
1230
|
-
`Expected third edn value to be an array. Found: ${JSON.stringify(
|
|
1231
|
-
p
|
|
1232
|
-
)}`
|
|
1233
|
-
);
|
|
1234
|
-
}
|
|
1235
|
-
return {
|
|
1236
|
-
type: "pull",
|
|
1237
|
-
variable: { type: "variable", value: name.sym.replace(/^\?/, "") },
|
|
1238
|
-
pattern: {
|
|
1239
|
-
type: "pattern-data-literal",
|
|
1240
|
-
value: attrs.map((attr): DatalogPullAttr => {
|
|
1241
|
-
if (typeof attr === "object" && "key" in attr) {
|
|
1242
|
-
return {
|
|
1243
|
-
type: "constant",
|
|
1244
|
-
value: `:${attr.key}`,
|
|
1245
|
-
};
|
|
1246
|
-
}
|
|
1247
|
-
if (Array.isArray(attr)) {
|
|
1248
|
-
const [name, expr, option] = attr;
|
|
1249
|
-
if (typeof name !== "object" || !("key" in name)) {
|
|
1250
|
-
throw new Error(
|
|
1251
|
-
`Expected attribute expression to start with key. Found: ${JSON.stringify(
|
|
1252
|
-
attr
|
|
1253
|
-
)}`
|
|
1254
|
-
);
|
|
1255
|
-
}
|
|
1256
|
-
if (
|
|
1257
|
-
typeof expr !== "object" ||
|
|
1258
|
-
!("key" in expr) ||
|
|
1259
|
-
!["as", "limit", "default"].includes(expr.key)
|
|
1260
|
-
) {
|
|
1261
|
-
throw new Error(
|
|
1262
|
-
`Expected attribute expression to have second key :as, :limit, or :default. Found: ${JSON.stringify(
|
|
1263
|
-
attr
|
|
1264
|
-
)}`
|
|
1265
|
-
);
|
|
1266
|
-
}
|
|
1267
|
-
if (typeof option !== "string") {
|
|
1268
|
-
throw new Error(
|
|
1269
|
-
`Expected attribute expression to end with literal. Found: ${JSON.stringify(
|
|
1270
|
-
attr
|
|
1271
|
-
)}`
|
|
1272
|
-
);
|
|
1273
|
-
}
|
|
1274
|
-
const pullOption: DatalogPullOption | undefined =
|
|
1275
|
-
expr.key === "as"
|
|
1276
|
-
? { type: "as-expr", value: option }
|
|
1277
|
-
: undefined; // should be impossible
|
|
1278
|
-
if (!pullOption) {
|
|
1279
|
-
throw new Error(
|
|
1280
|
-
`Expected attribute expression to be an \`as\` key. Found: ${JSON.stringify(
|
|
1281
|
-
expr
|
|
1282
|
-
)}`
|
|
1283
|
-
);
|
|
1284
|
-
}
|
|
1285
|
-
return {
|
|
1286
|
-
type: "attr-expr",
|
|
1287
|
-
name: `:${name.key}`,
|
|
1288
|
-
option: pullOption,
|
|
1289
|
-
};
|
|
1290
|
-
}
|
|
1291
|
-
if (typeof attr === "object" && "map" in attr) {
|
|
1292
|
-
return {
|
|
1293
|
-
type: "map-spec",
|
|
1294
|
-
entries: attr.map.map((entry) => {
|
|
1295
|
-
const [key, value] = entry;
|
|
1296
|
-
if (typeof key !== "object" || !("key" in key)) {
|
|
1297
|
-
throw new Error(
|
|
1298
|
-
`Unexpected pattern map key. Found: ${JSON.stringify(
|
|
1299
|
-
entry
|
|
1300
|
-
)}`
|
|
1301
|
-
);
|
|
1302
|
-
}
|
|
1303
|
-
if (
|
|
1304
|
-
typeof value !== "object" ||
|
|
1305
|
-
!("sym" in value) ||
|
|
1306
|
-
value.sym !== "..."
|
|
1307
|
-
) {
|
|
1308
|
-
throw new Error(
|
|
1309
|
-
`Unexpected pattern map value. Found: ${JSON.stringify(
|
|
1310
|
-
entry
|
|
1311
|
-
)}`
|
|
1312
|
-
);
|
|
1313
|
-
}
|
|
1314
|
-
return {
|
|
1315
|
-
key: `:${key.key}`,
|
|
1316
|
-
value: value.sym,
|
|
1317
|
-
};
|
|
1318
|
-
}),
|
|
1319
|
-
};
|
|
1320
|
-
}
|
|
1321
|
-
throw new Error(
|
|
1322
|
-
`Unexpected pattern literal attribute. Found: ${JSON.stringify(
|
|
1323
|
-
attr
|
|
1324
|
-
)}`
|
|
1325
|
-
);
|
|
1326
|
-
}),
|
|
1327
|
-
},
|
|
1328
|
-
};
|
|
1329
|
-
}
|
|
1330
|
-
throw new Error(
|
|
1331
|
-
`Unexpected object for datalog find: ${JSON.stringify(p)}`
|
|
1332
|
-
);
|
|
1333
|
-
}),
|
|
1334
|
-
};
|
|
1335
|
-
const wherePattern = data.slice(whereIndex + 1);
|
|
1336
|
-
const toDatalog = (e: EDNValue): DatalogClause => {
|
|
1337
|
-
if (Array.isArray(e)) {
|
|
1338
|
-
if (e.length === 3) {
|
|
1339
|
-
return {
|
|
1340
|
-
type: "data-pattern",
|
|
1341
|
-
arguments: e.map((a) => {
|
|
1342
|
-
if (typeof a === "object") {
|
|
1343
|
-
if ("key" in a) {
|
|
1344
|
-
return {
|
|
1345
|
-
type: "constant",
|
|
1346
|
-
value: `:${a.key}`,
|
|
1347
|
-
};
|
|
1348
|
-
} else if ("sym" in a) {
|
|
1349
|
-
return {
|
|
1350
|
-
type: "variable",
|
|
1351
|
-
value: a.sym.slice(1),
|
|
1352
|
-
};
|
|
1353
|
-
} else {
|
|
1354
|
-
throw new Error(
|
|
1355
|
-
`Expected data-pattern argument to come from non array EDN: ${JSON.stringify(
|
|
1356
|
-
a
|
|
1357
|
-
)}`
|
|
1358
|
-
);
|
|
1359
|
-
}
|
|
1360
|
-
} else {
|
|
1361
|
-
return {
|
|
1362
|
-
type: "constant",
|
|
1363
|
-
value: a,
|
|
1364
|
-
};
|
|
1365
|
-
}
|
|
1366
|
-
}),
|
|
1367
|
-
};
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
throw new Error(`Unknown value for datalog clause: ${JSON.stringify(e)}`);
|
|
1371
|
-
};
|
|
1372
|
-
const where = wherePattern.map(toDatalog);
|
|
1373
|
-
return fireQuery({ graph, find, where });
|
|
1374
|
-
};
|
|
1375
|
-
|
|
1376
|
-
const mockRoamEnvironment = () => {
|
|
1377
|
-
const graph = initMockGraph();
|
|
1378
|
-
const dom = new JSDOM();
|
|
1379
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1380
|
-
// @ts-ignore
|
|
1381
|
-
global.window = dom.window;
|
|
1382
|
-
global.document = dom.window.document;
|
|
1383
|
-
global.window.roamAlphaAPI = {
|
|
1384
|
-
...global.window.roamAlphaAPI,
|
|
1385
|
-
pull: (_, id) => {
|
|
1386
|
-
const pick = (node: PullBlock) => {
|
|
1387
|
-
// TODO - process exp
|
|
1388
|
-
return node;
|
|
1389
|
-
};
|
|
1390
|
-
if (Array.isArray(id)) {
|
|
1391
|
-
const [attr, val] = id;
|
|
1392
|
-
if (attr === ":block/uid") {
|
|
1393
|
-
return pick(graph.state[graph.uids[val]]);
|
|
1394
|
-
} else if (attr === ":node/title") {
|
|
1395
|
-
return pick(graph.state[graph.titles[val]]);
|
|
1396
|
-
} else {
|
|
1397
|
-
throw new Error(`Attr is not supported: ${attr}`);
|
|
1398
|
-
}
|
|
1399
|
-
} else if (typeof id === "number") {
|
|
1400
|
-
return pick(graph.state[id]);
|
|
1401
|
-
} else {
|
|
1402
|
-
throw new Error(`Id is not supported: ${id}`);
|
|
1403
|
-
}
|
|
1404
|
-
},
|
|
1405
|
-
q: (query, ..._params) => {
|
|
1406
|
-
return mockQuery({ graph, query });
|
|
1407
|
-
},
|
|
1408
|
-
createBlock: async (action) => {
|
|
1409
|
-
if (!action.block) throw new Error(`block field is required`);
|
|
1410
|
-
if (!action.location) throw new Error(`location field is required`);
|
|
1411
|
-
const parent = graph.uids[action.location["parent-uid"]];
|
|
1412
|
-
if (!parent)
|
|
1413
|
-
throw new Error(
|
|
1414
|
-
`Could not find parent by uid: ${action.location["parent-uid"]}`
|
|
1415
|
-
);
|
|
1416
|
-
const parentBlock = graph.state[parent];
|
|
1417
|
-
const id = getDbId();
|
|
1418
|
-
const block = {
|
|
1419
|
-
":block/string": action.block.string,
|
|
1420
|
-
":block/uid":
|
|
1421
|
-
action.block.uid || window.roamAlphaAPI.util.generateUID(),
|
|
1422
|
-
":block/parents": ([{ ":db/id": parent }] as PullBlock[]).concat(
|
|
1423
|
-
parentBlock[":block/parents"] || []
|
|
1424
|
-
),
|
|
1425
|
-
":db/id": id,
|
|
1426
|
-
":block/order": action.location.order,
|
|
1427
|
-
};
|
|
1428
|
-
graph.uids[block[":block/uid"]] = id;
|
|
1429
|
-
parentBlock[":block/children"] = (
|
|
1430
|
-
parentBlock[":block/children"] || []
|
|
1431
|
-
).concat({ ":db/id": id });
|
|
1432
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
1433
|
-
// @ts-ignore
|
|
1434
|
-
graph.state[id] = block;
|
|
1435
|
-
},
|
|
1436
|
-
updateBlock: async (action) => {
|
|
1437
|
-
if (!action.block) throw new Error(`block field is required`);
|
|
1438
|
-
if (!action.block.uid) throw new Error(`block uid is required`);
|
|
1439
|
-
const block = graph.uids[action.block.uid];
|
|
1440
|
-
if (!block) {
|
|
1441
|
-
throw new Error(`Could not find block by uid: ${action.block.uid}`);
|
|
1442
|
-
}
|
|
1443
|
-
if (typeof action.block.string !== "undefined") {
|
|
1444
|
-
graph.state[block][":block/string"] = action.block.string;
|
|
1445
|
-
}
|
|
1446
|
-
if (typeof action.block.open !== "undefined") {
|
|
1447
|
-
graph.state[block][":block/open"] = action.block.open;
|
|
1448
|
-
}
|
|
1449
|
-
if (typeof action.block.heading !== "undefined") {
|
|
1450
|
-
graph.state[block][":block/heading"] = action.block.heading;
|
|
1451
|
-
}
|
|
1452
|
-
if (typeof action.block["text-align"] !== "undefined") {
|
|
1453
|
-
graph.state[block][":block/text-align"] = action.block["text-align"];
|
|
1454
|
-
}
|
|
1455
|
-
if (typeof action.block["children-view-type"] !== "undefined") {
|
|
1456
|
-
graph.state[block][
|
|
1457
|
-
":children/view-type"
|
|
1458
|
-
] = `:${action.block["children-view-type"]}`;
|
|
1459
|
-
}
|
|
1460
|
-
},
|
|
1461
|
-
createPage: async (action) => {
|
|
1462
|
-
if (!action.page) throw new Error(`page field is required`);
|
|
1463
|
-
if (!action.page.title) throw new Error(`page title field is required`);
|
|
1464
|
-
const id = getDbId();
|
|
1465
|
-
const page = {
|
|
1466
|
-
":node/title": action.page.title,
|
|
1467
|
-
":block/uid": action.page.uid || window.roamAlphaAPI.util.generateUID(),
|
|
1468
|
-
":db/id": id,
|
|
1469
|
-
};
|
|
1470
|
-
graph.titles[action.page.title] = id;
|
|
1471
|
-
graph.uids[page[":block/uid"]] = id;
|
|
1472
|
-
graph.state[id] = page;
|
|
1473
|
-
},
|
|
1474
|
-
};
|
|
1475
|
-
global.window.roamAlphaAPI.data = {
|
|
1476
|
-
...global.window.roamAlphaAPI.data,
|
|
1477
|
-
fast: {
|
|
1478
|
-
q: (query, ..._params) => {
|
|
1479
|
-
return mockQuery({ graph, query });
|
|
1480
|
-
},
|
|
1481
|
-
},
|
|
1482
|
-
};
|
|
1483
|
-
global.window.roamAlphaAPI.util = {
|
|
1484
|
-
...global.window.roamAlphaAPI.util,
|
|
1485
|
-
generateUID: () => nanoid().slice(0, 9),
|
|
1486
|
-
};
|
|
1487
|
-
};
|
|
1488
|
-
|
|
1489
|
-
export default mockRoamEnvironment;
|