@notionhq/custom-blocks 0.3.4 → 0.3.5
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/README.md +2 -0
- package/dist/bridge/SandboxBridge.d.ts +28 -507
- package/dist/bridge/SandboxBridge.d.ts.map +1 -1
- package/dist/bridge/SandboxBridge.js +89 -686
- package/dist/bridge/getBridge.d.ts +3 -0
- package/dist/bridge/getBridge.d.ts.map +1 -0
- package/dist/bridge/getBridge.js +8 -0
- package/dist/bridge/{SandboxInitialization.d.ts → initialization/SandboxInitialization.d.ts} +5 -6
- package/dist/bridge/initialization/SandboxInitialization.d.ts.map +1 -0
- package/dist/bridge/{SandboxInitialization.js → initialization/SandboxInitialization.js} +6 -12
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.js +2 -2
- package/dist/context/applyContextMessage.d.ts +6 -0
- package/dist/context/applyContextMessage.d.ts.map +1 -0
- package/dist/context/applyContextMessage.js +35 -0
- package/dist/{bridge/appearance.d.ts → context/backgroundColors.d.ts} +1 -1
- package/dist/context/backgroundColors.d.ts.map +1 -0
- package/dist/context/getBlockId.d.ts +7 -0
- package/dist/context/getBlockId.d.ts.map +1 -0
- package/dist/context/getBlockId.js +8 -0
- package/dist/context/getContrastMode.d.ts +7 -0
- package/dist/context/getContrastMode.d.ts.map +1 -0
- package/dist/context/getContrastMode.js +8 -0
- package/dist/context/getInitializedHostState.d.ts +3 -0
- package/dist/context/getInitializedHostState.d.ts.map +1 -0
- package/dist/context/getInitializedHostState.js +8 -0
- package/dist/context/getPage.d.ts +7 -0
- package/dist/context/getPage.d.ts.map +1 -0
- package/dist/context/getPage.js +8 -0
- package/dist/context/getParent.d.ts +7 -0
- package/dist/context/getParent.d.ts.map +1 -0
- package/dist/context/getParent.js +8 -0
- package/dist/context/getTheme.d.ts +7 -0
- package/dist/context/getTheme.d.ts.map +1 -0
- package/dist/context/getTheme.js +8 -0
- package/dist/context/hostState.d.ts +15 -0
- package/dist/context/hostState.d.ts.map +1 -0
- package/dist/context/index.d.ts +42 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +41 -0
- package/dist/context/react/useBlockId.d.ts +11 -0
- package/dist/context/react/useBlockId.d.ts.map +1 -0
- package/dist/context/react/useBlockId.js +14 -0
- package/dist/context/react/useContrastMode.d.ts +11 -0
- package/dist/context/react/useContrastMode.d.ts.map +1 -0
- package/dist/context/react/useContrastMode.js +14 -0
- package/dist/context/react/usePage.d.ts +12 -0
- package/dist/context/react/usePage.d.ts.map +1 -0
- package/dist/context/react/usePage.js +15 -0
- package/dist/context/react/useParent.d.ts +12 -0
- package/dist/context/react/useParent.d.ts.map +1 -0
- package/dist/context/react/useParent.js +15 -0
- package/dist/context/react/useTheme.d.ts +11 -0
- package/dist/context/react/useTheme.d.ts.map +1 -0
- package/dist/context/react/useTheme.js +14 -0
- package/dist/context/subscribeToBlockId.d.ts +8 -0
- package/dist/context/subscribeToBlockId.d.ts.map +1 -0
- package/dist/context/subscribeToBlockId.js +8 -0
- package/dist/context/subscribeToContext.d.ts +12 -0
- package/dist/context/subscribeToContext.d.ts.map +1 -0
- package/dist/context/subscribeToContext.js +35 -0
- package/dist/context/subscribeToContrastMode.d.ts +8 -0
- package/dist/context/subscribeToContrastMode.d.ts.map +1 -0
- package/dist/context/subscribeToContrastMode.js +8 -0
- package/dist/context/subscribeToPage.d.ts +8 -0
- package/dist/context/subscribeToPage.d.ts.map +1 -0
- package/dist/context/subscribeToPage.js +8 -0
- package/dist/context/subscribeToParent.d.ts +8 -0
- package/dist/context/subscribeToParent.d.ts.map +1 -0
- package/dist/context/subscribeToParent.js +8 -0
- package/dist/context/subscribeToTheme.d.ts +8 -0
- package/dist/context/subscribeToTheme.d.ts.map +1 -0
- package/dist/context/subscribeToTheme.js +8 -0
- package/dist/context/syncDocumentAppearance.d.ts +14 -0
- package/dist/context/syncDocumentAppearance.d.ts.map +1 -0
- package/dist/context/syncDocumentAppearance.js +22 -0
- package/dist/dataSources/bridge/applyDataSourceBindings.d.ts +4 -0
- package/dist/dataSources/bridge/applyDataSourceBindings.d.ts.map +1 -0
- package/dist/dataSources/bridge/applyDataSourceBindings.js +17 -0
- package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts +17 -0
- package/dist/dataSources/bridge/resolveDataSourceQuery.d.ts.map +1 -0
- package/dist/{bridge/dataSources/query.js → dataSources/bridge/resolveDataSourceQuery.js} +13 -17
- package/dist/dataSources/bridge/resolveDataSources.d.ts +15 -0
- package/dist/dataSources/bridge/resolveDataSources.d.ts.map +1 -0
- package/dist/{bridge/dataSources/resolve.js → dataSources/bridge/resolveDataSources.js} +10 -11
- package/dist/{bridge/dataSources → dataSources/bridge}/resolveSorts.d.ts +3 -3
- package/dist/dataSources/bridge/resolveSorts.d.ts.map +1 -0
- package/dist/{bridge/dataSources → dataSources/bridge}/resolveSorts.js +3 -3
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.d.ts +16 -0
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.d.ts.map +1 -0
- package/dist/dataSources/bridge/reuseDataSourcesForUnchangedBindings.js +19 -0
- package/dist/dataSources/createDataSourcePage.d.ts +4 -0
- package/dist/dataSources/createDataSourcePage.d.ts.map +1 -0
- package/dist/dataSources/createDataSourcePage.js +40 -0
- package/dist/dataSources/dataSourceInaccessibleError.d.ts +4 -0
- package/dist/dataSources/dataSourceInaccessibleError.d.ts.map +1 -0
- package/dist/dataSources/dataSourceInaccessibleError.js +9 -0
- package/dist/{bridge/dataSources/queryFilter.d.ts → dataSources/filters/resolveFilter.d.ts} +4 -4
- package/dist/dataSources/filters/resolveFilter.d.ts.map +1 -0
- package/dist/{bridge/dataSources/queryFilter.js → dataSources/filters/resolveFilter.js} +8 -4
- package/dist/dataSources/filters/types.d.ts +66 -0
- package/dist/dataSources/filters/types.d.ts.map +1 -0
- package/dist/dataSources/getDataSourcePage.d.ts +4 -0
- package/dist/dataSources/getDataSourcePage.d.ts.map +1 -0
- package/dist/dataSources/getDataSourcePage.js +18 -0
- package/dist/dataSources/index.d.ts +9 -0
- package/dist/dataSources/index.d.ts.map +1 -0
- package/dist/dataSources/index.js +8 -0
- package/dist/{bridge/dataSources → dataSources/properties}/resolvePropertyAddress.d.ts +1 -1
- package/dist/dataSources/properties/resolvePropertyAddress.d.ts.map +1 -0
- package/dist/{bridge/dataSources/resolveProperty.d.ts → dataSources/properties/resolvePropertyWriteMapForDataSource.d.ts} +4 -4
- package/dist/dataSources/properties/resolvePropertyWriteMapForDataSource.d.ts.map +1 -0
- package/dist/{bridge/dataSources/resolveProperty.js → dataSources/properties/resolvePropertyWriteMapForDataSource.js} +2 -2
- package/dist/dataSources/queryDataSource.d.ts +3 -0
- package/dist/dataSources/queryDataSource.d.ts.map +1 -0
- package/dist/dataSources/queryDataSource.js +56 -0
- package/dist/dataSources/react/useDataSource.d.ts.map +1 -0
- package/dist/{react → dataSources/react}/useDataSource.js +2 -2
- package/dist/dataSources/resolvePageDataSource.d.ts +16 -0
- package/dist/dataSources/resolvePageDataSource.d.ts.map +1 -0
- package/dist/dataSources/resolvePageDataSource.js +43 -0
- package/dist/{bridge/dataSources/subscribe.d.ts → dataSources/subscribeToDataSource.d.ts} +3 -3
- package/dist/dataSources/subscribeToDataSource.d.ts.map +1 -0
- package/dist/dataSources/subscribeToDataSource.js +109 -0
- package/dist/dataSources/types.d.ts +47 -0
- package/dist/dataSources/types.d.ts.map +1 -0
- package/dist/dataSources/types.js +1 -0
- package/dist/index.d.ts +38 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/initialization/NotInIframeError.d.ts +12 -0
- package/dist/initialization/NotInIframeError.d.ts.map +1 -0
- package/dist/{initTypes.js → initialization/NotInIframeError.js} +3 -3
- package/dist/initialization/getInitBindingError.d.ts +5 -0
- package/dist/initialization/getInitBindingError.d.ts.map +1 -0
- package/dist/initialization/getInitBindingError.js +26 -0
- package/dist/{init.d.ts → initialization/initCustomBlock.d.ts} +2 -3
- package/dist/initialization/initCustomBlock.d.ts.map +1 -0
- package/dist/{init.js → initialization/initCustomBlock.js} +2 -3
- package/dist/{react → initialization/react}/useCustomBlockInit.d.ts +2 -2
- package/dist/initialization/react/useCustomBlockInit.d.ts.map +1 -0
- package/dist/{react → initialization/react}/useCustomBlockInit.js +1 -1
- package/dist/initialization/resolveInitialState.d.ts +13 -0
- package/dist/initialization/resolveInitialState.d.ts.map +1 -0
- package/dist/initialization/resolveInitialState.js +28 -0
- package/dist/initialization/types.d.ts +20 -0
- package/dist/initialization/types.d.ts.map +1 -0
- package/dist/initialization/types.js +1 -0
- package/dist/layout/autoResize.d.ts.map +1 -0
- package/dist/{autoResize.js → layout/autoResize.js} +2 -2
- package/dist/layout/getInitialContentHeight.d.ts +2 -0
- package/dist/layout/getInitialContentHeight.d.ts.map +1 -0
- package/dist/layout/getInitialContentHeight.js +10 -0
- package/dist/layout/postResize.d.ts +2 -0
- package/dist/layout/postResize.d.ts.map +1 -0
- package/dist/layout/postResize.js +12 -0
- package/dist/manifest/getManifest.d.ts +7 -0
- package/dist/manifest/getManifest.d.ts.map +1 -0
- package/dist/manifest/getManifest.js +8 -0
- package/dist/manifest/react/useManifest.d.ts +15 -0
- package/dist/manifest/react/useManifest.d.ts.map +1 -0
- package/dist/manifest/react/useManifest.js +18 -0
- package/dist/{bridge → manifest}/readLocalManifest.d.ts +3 -3
- package/dist/manifest/readLocalManifest.d.ts.map +1 -0
- package/dist/{bridge → manifest}/readLocalManifest.js +2 -2
- package/dist/manifest/subscribeToManifest.d.ts +8 -0
- package/dist/manifest/subscribeToManifest.d.ts.map +1 -0
- package/dist/manifest/subscribeToManifest.js +8 -0
- package/dist/manifest/types.d.ts +6 -0
- package/dist/manifest/types.d.ts.map +1 -0
- package/dist/manifest/types.js +1 -0
- package/dist/navigation/index.d.ts +5 -0
- package/dist/navigation/index.d.ts.map +1 -0
- package/dist/navigation/index.js +4 -0
- package/dist/navigation/openExternalUrl.d.ts +4 -0
- package/dist/navigation/openExternalUrl.d.ts.map +1 -0
- package/dist/navigation/openExternalUrl.js +5 -0
- package/dist/navigation/types.d.ts +4 -0
- package/dist/navigation/types.d.ts.map +1 -0
- package/dist/navigation/types.js +1 -0
- package/dist/pages/bridge/buildCreatePageRequest.d.ts +16 -0
- package/dist/pages/bridge/buildCreatePageRequest.d.ts.map +1 -0
- package/dist/pages/bridge/buildCreatePageRequest.js +38 -0
- package/dist/pages/bridge/getPageForDataSource.d.ts +9 -0
- package/dist/pages/bridge/getPageForDataSource.d.ts.map +1 -0
- package/dist/pages/bridge/getPageForDataSource.js +13 -0
- package/dist/pages/bridge/makeUpdatePageByKey.d.ts +8 -0
- package/dist/pages/bridge/makeUpdatePageByKey.d.ts.map +1 -0
- package/dist/{bridge/page.js → pages/bridge/makeUpdatePageByKey.js} +0 -12
- package/dist/pages/bridge/resolveCreatePageDestination.d.ts +24 -0
- package/dist/pages/bridge/resolveCreatePageDestination.d.ts.map +1 -0
- package/dist/pages/bridge/resolveCreatePageDestination.js +45 -0
- package/dist/pages/bridge/sendCreatePageRequest.d.ts +11 -0
- package/dist/pages/bridge/sendCreatePageRequest.d.ts.map +1 -0
- package/dist/pages/bridge/sendCreatePageRequest.js +12 -0
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts +77 -0
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.d.ts.map +1 -0
- package/dist/pages/bridge/toNotionPageFieldsFromBridgePage.js +25 -0
- package/dist/pages/bridge/toNotionPageFromBridgePage.d.ts +11 -0
- package/dist/pages/bridge/toNotionPageFromBridgePage.d.ts.map +1 -0
- package/dist/pages/bridge/toNotionPageFromBridgePage.js +12 -0
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts +4 -0
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.d.ts.map +1 -0
- package/dist/pages/bridge/toNotionPagePropertyFromBridgeProperty.js +92 -0
- package/dist/pages/bridge/updateNotionPageFromBridgePage.d.ts +4 -0
- package/dist/pages/bridge/updateNotionPageFromBridgePage.d.ts.map +1 -0
- package/dist/pages/bridge/updateNotionPageFromBridgePage.js +4 -0
- package/dist/pages/bridge/updatePage.d.ts +12 -0
- package/dist/pages/bridge/updatePage.d.ts.map +1 -0
- package/dist/pages/bridge/updatePage.js +60 -0
- package/dist/pages/createPage.d.ts +3 -0
- package/dist/pages/createPage.d.ts.map +1 -0
- package/dist/pages/createPage.js +27 -0
- package/dist/pages/getPage.d.ts +7 -0
- package/dist/pages/getPage.d.ts.map +1 -0
- package/dist/pages/getPage.js +11 -0
- package/dist/pages/index.d.ts +9 -0
- package/dist/pages/index.d.ts.map +1 -0
- package/dist/pages/index.js +8 -0
- package/dist/pages/makeNotionPage.d.ts +11 -0
- package/dist/pages/makeNotionPage.d.ts.map +1 -0
- package/dist/pages/makeNotionPage.js +34 -0
- package/dist/pages/openPage.d.ts +7 -0
- package/dist/pages/openPage.d.ts.map +1 -0
- package/dist/pages/openPage.js +7 -0
- package/dist/pages/parent.d.ts +7 -0
- package/dist/pages/parent.d.ts.map +1 -0
- package/dist/pages/parent.js +1 -0
- package/dist/pages/properties/getPropertyById.d.ts +6 -0
- package/dist/pages/properties/getPropertyById.d.ts.map +1 -0
- package/dist/pages/properties/getPropertyById.js +3 -0
- package/dist/pages/properties/getPropertyByKey.d.ts +9 -0
- package/dist/pages/properties/getPropertyByKey.d.ts.map +1 -0
- package/dist/pages/properties/getPropertyByKey.js +16 -0
- package/dist/pages/types.d.ts +208 -0
- package/dist/pages/types.d.ts.map +1 -0
- package/dist/pages/types.js +1 -0
- package/dist/protocol/{messages/updatePage.d.ts → compatibility/protocol3To5/bridgePage.d.ts} +32 -22
- package/dist/protocol/compatibility/protocol3To5/bridgePage.js +21 -0
- package/dist/protocol/{dataSources → compatibility/protocol3To5}/dataSourcePage.js +1 -1
- package/dist/protocol/{dataSources → compatibility/protocol3To5}/dataSourceValue.js +2 -2
- package/dist/protocol/context/containingPage.d.ts +31 -0
- package/dist/protocol/context/containingPage.js +18 -0
- package/dist/protocol/{messages → context/messages}/pageChanged.js +1 -1
- package/dist/protocol/{parent.d.ts → context/parent.d.ts} +10 -0
- package/dist/protocol/context/parent.js +31 -0
- package/dist/protocol/dataSources/bridgeDataSourceBinding.d.ts +164 -0
- package/dist/protocol/dataSources/bridgeDataSourceBinding.js +25 -0
- package/dist/protocol/dataSources/bridgeDataSourceBindings.d.ts +148 -0
- package/dist/protocol/dataSources/bridgeDataSourceBindings.js +3 -0
- package/dist/protocol/dataSources/collectionPointer.d.ts +7 -0
- package/dist/protocol/dataSources/collectionPointer.js +7 -0
- package/dist/protocol/dataSources/collectionSchema.d.ts +144 -0
- package/dist/protocol/dataSources/collectionSchema.js +12 -0
- package/dist/protocol/dataSources/errors.d.ts +2 -2
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilter.d.ts +505 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilter.js +8 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.d.ts +253 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceFilterCondition.js +69 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceSort.d.ts +11 -0
- package/dist/protocol/dataSources/filters/bridgeDataSourceSort.js +8 -0
- package/dist/protocol/dataSources/filters/checkboxFilterOperator.d.ts +7 -0
- package/dist/protocol/dataSources/filters/checkboxFilterOperator.js +5 -0
- package/dist/protocol/dataSources/filters/containsFilterOperator.d.ts +13 -0
- package/dist/protocol/dataSources/filters/containsFilterOperator.js +9 -0
- package/dist/protocol/dataSources/filters/createdByFilterOperator.d.ts +17 -0
- package/dist/protocol/dataSources/filters/createdByFilterOperator.js +11 -0
- package/dist/protocol/dataSources/filters/dateFilterOperator.d.ts +47 -0
- package/dist/protocol/dataSources/filters/dateFilterOperator.js +73 -0
- package/dist/protocol/dataSources/filters/emptyOperator.d.ts +6 -0
- package/dist/protocol/dataSources/filters/emptyOperator.js +5 -0
- package/dist/protocol/dataSources/filters/numberFilterOperator.d.ts +19 -0
- package/dist/protocol/dataSources/filters/numberFilterOperator.js +11 -0
- package/dist/protocol/dataSources/filters/optionFilterOperator.d.ts +11 -0
- package/dist/protocol/dataSources/filters/optionFilterOperator.js +8 -0
- package/dist/protocol/dataSources/filters/peopleFilterOperator.d.ts +23 -0
- package/dist/protocol/dataSources/filters/peopleFilterOperator.js +11 -0
- package/dist/protocol/dataSources/filters/relationFilterOperator.d.ts +11 -0
- package/dist/protocol/dataSources/filters/relationFilterOperator.js +12 -0
- package/dist/protocol/dataSources/filters/statusFilterOperator.d.ts +15 -0
- package/dist/protocol/dataSources/filters/statusFilterOperator.js +7 -0
- package/dist/protocol/dataSources/filters/statusGroupFilterOperator.d.ts +9 -0
- package/dist/protocol/dataSources/filters/statusGroupFilterOperator.js +18 -0
- package/dist/protocol/dataSources/filters/stringOrStringArray.d.ts +2 -0
- package/dist/protocol/dataSources/filters/stringOrStringArray.js +5 -0
- package/dist/protocol/dataSources/filters/textFilterOperator.d.ts +19 -0
- package/dist/protocol/dataSources/filters/textFilterOperator.js +11 -0
- package/dist/protocol/dataSources/makeBridgeDataSourceBinding.d.ts +6 -0
- package/dist/protocol/dataSources/makeBridgeDataSourceBinding.js +6 -0
- package/dist/protocol/{messages → dataSources/messages}/dataSourcesChanged.d.ts +1 -0
- package/dist/protocol/{messages → dataSources/messages}/dataSourcesChanged.js +2 -2
- package/dist/protocol/{messages/queryDataSourceResult.d.ts → dataSources/messages/queryDataSource.d.ts} +525 -2
- package/dist/protocol/{messages/queryDataSourceResult.js → dataSources/messages/queryDataSource.js} +22 -2
- package/dist/protocol/dataSources/notionDataSource.d.ts +309 -0
- package/dist/protocol/dataSources/notionDataSource.js +38 -0
- package/dist/protocol/dataSources/resolveDataSourceBinding.d.ts +32 -0
- package/dist/protocol/dataSources/resolveDataSourceBinding.js +33 -0
- package/dist/protocol/{messages → handshake}/connect.d.ts +4 -0
- package/dist/protocol/{messages → handshake}/connect.js +2 -2
- package/dist/protocol/{messages → handshake}/init.d.ts +6 -1
- package/dist/protocol/{messages → handshake}/init.js +10 -10
- package/dist/protocol/{messages → handshake}/initResult.d.ts +1 -1
- package/dist/protocol/{messages → handshake}/isInitHandshakeMessage.d.ts +2 -2
- package/dist/protocol/index.d.ts +150 -54
- package/dist/protocol/index.js +73 -54
- package/dist/protocol/manifest/capabilities.d.ts +37 -0
- package/dist/protocol/manifest/capabilities.js +13 -0
- package/dist/protocol/{manifest.d.ts → manifest/manifest.d.ts} +12 -2
- package/dist/protocol/{manifest.js → manifest/manifest.js} +8 -1
- package/dist/protocol/messages/hostToSandbox.d.ts +12 -0
- package/dist/protocol/messages/hostToSandbox.js +15 -15
- package/dist/protocol/messages/messagePayload.d.ts +1 -1
- package/dist/protocol/messages/sandboxToHost.d.ts +232 -8
- package/dist/protocol/messages/sandboxToHost.js +12 -12
- package/dist/protocol/{messages → navigation}/openExternalUrl.d.ts +1 -1
- package/dist/protocol/{messages/createPage.d.ts → pages/bridgePage.d.ts} +67 -65
- package/dist/protocol/pages/bridgePage.js +25 -0
- package/dist/protocol/pages/makeBridgePage.d.ts +4 -0
- package/dist/protocol/pages/makeBridgePage.js +12 -0
- package/dist/protocol/{messages/createPageResult.d.ts → pages/messages/createPage.d.ts} +500 -2
- package/dist/protocol/pages/messages/createPage.js +104 -0
- package/dist/protocol/{messages → pages/messages}/getPage.d.ts +2 -2
- package/dist/protocol/{messages → pages/messages}/getPage.js +4 -3
- package/dist/protocol/{messages → pages/messages}/openPage.d.ts +2 -2
- package/dist/protocol/{messages → pages/messages}/openPage.js +1 -1
- package/dist/protocol/{messages/updatePageResult.d.ts → pages/messages/updatePage.d.ts} +272 -2
- package/dist/protocol/{messages/updatePageResult.js → pages/messages/updatePage.js} +26 -2
- package/dist/protocol/pages/pageAppearance.d.ts +62 -0
- package/dist/protocol/pages/pageAppearance.js +34 -0
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.d.ts +433 -0
- package/dist/protocol/pages/properties/bridgePagePropertyMaps.js +4 -0
- package/dist/protocol/pages/properties/bridgePagePropertyValue.d.ts +217 -0
- package/dist/protocol/pages/properties/bridgePagePropertyValue.js +144 -0
- package/dist/protocol/pages/properties/dateInput.d.ts +45 -0
- package/dist/protocol/pages/properties/dateInput.js +23 -0
- package/dist/protocol/pages/properties/fileInput.d.ts +16 -0
- package/dist/protocol/pages/properties/fileInput.js +16 -0
- package/dist/protocol/pages/properties/metadataActor.d.ts +6 -0
- package/dist/protocol/pages/properties/metadataActor.js +7 -0
- package/dist/protocol/pages/properties/placeInput.d.ts +10 -0
- package/dist/protocol/pages/properties/placeInput.js +10 -0
- package/dist/protocol/pages/properties/relationInput.d.ts +5 -0
- package/dist/protocol/pages/properties/relationInput.js +2 -0
- package/dist/protocol/pages/properties/richText.d.ts +3 -0
- package/dist/protocol/pages/properties/richText.js +2 -0
- package/dist/protocol/pages/properties/selectOption.d.ts +13 -0
- package/dist/protocol/pages/properties/selectOption.js +16 -0
- package/dist/protocol/pages/properties/userInput.d.ts +10 -0
- package/dist/protocol/pages/properties/userInput.js +13 -0
- package/dist/protocol/users/bridgeUser.d.ts +12 -0
- package/dist/protocol/users/bridgeUser.js +12 -0
- package/dist/protocol/users/{user.d.ts → bridgeUserList.d.ts} +2 -15
- package/dist/protocol/users/bridgeUserList.js +10 -0
- package/dist/protocol/users/makeBridgeUser.d.ts +4 -0
- package/dist/protocol/users/makeBridgeUser.js +11 -0
- package/dist/protocol/{messages → users/messages}/currentUserChanged.js +2 -2
- package/dist/protocol/{messages → users/messages}/getUser.d.ts +2 -2
- package/dist/protocol/{messages → users/messages}/getUser.js +3 -2
- package/dist/protocol/{messages → users/messages}/listUsers.d.ts +2 -2
- package/dist/protocol/{messages → users/messages}/listUsers.js +2 -2
- package/dist/protocol/users/userId.d.ts +3 -0
- package/dist/protocol/users/userId.js +2 -0
- package/dist/protocol/{errors.d.ts → utils/errors.d.ts} +6 -0
- package/dist/protocol/utils/errors.js +11 -0
- package/dist/protocol/utils/nullableStringSchema.d.ts +2 -0
- package/dist/protocol/utils/nullableStringSchema.js +2 -0
- package/dist/react/DebugMessageLog.d.ts.map +1 -1
- package/dist/react/DebugMessageLog.js +3 -2
- package/dist/react/InitializationErrorDetails.d.ts +7 -0
- package/dist/react/InitializationErrorDetails.d.ts.map +1 -0
- package/dist/react/InitializationErrorDetails.js +9 -0
- package/{src/react/NotionCustomBlock.css → dist/react/InitializationErrorScreen.css} +0 -20
- package/dist/react/MissingHostCommand.d.ts +2 -0
- package/dist/react/MissingHostCommand.d.ts.map +1 -0
- package/dist/react/MissingHostCommand.js +20 -0
- package/dist/react/MissingHostScreen.css +85 -0
- package/dist/react/MissingHostScreen.d.ts +7 -0
- package/dist/react/MissingHostScreen.d.ts.map +1 -0
- package/dist/react/MissingHostScreen.js +7 -0
- package/dist/react/NotionCustomBlock.d.ts +2 -2
- package/dist/react/NotionCustomBlock.d.ts.map +1 -1
- package/dist/react/NotionCustomBlock.js +14 -35
- package/dist/react/NotionTokenScope.d.ts.map +1 -1
- package/dist/react/NotionTokenScope.js +2 -1
- package/dist/react/index.d.ts +14 -5
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +11 -5
- package/dist/users/bridge/toNotionUserFromBridgeUser.d.ts +4 -0
- package/dist/users/bridge/toNotionUserFromBridgeUser.d.ts.map +1 -0
- package/dist/users/bridge/toNotionUserFromBridgeUser.js +10 -0
- package/dist/users/getCurrentUser.d.ts +7 -0
- package/dist/users/getCurrentUser.d.ts.map +1 -0
- package/dist/users/getCurrentUser.js +8 -0
- package/dist/users/getUser.d.ts +7 -0
- package/dist/users/getUser.d.ts.map +1 -0
- package/dist/users/getUser.js +11 -0
- package/dist/users/index.d.ts +7 -0
- package/dist/users/index.d.ts.map +1 -0
- package/dist/users/index.js +6 -0
- package/dist/users/listUsers.d.ts +6 -0
- package/dist/users/listUsers.d.ts.map +1 -0
- package/dist/users/listUsers.js +19 -0
- package/dist/users/react/useCurrentUser.d.ts +12 -0
- package/dist/users/react/useCurrentUser.d.ts.map +1 -0
- package/dist/users/react/useCurrentUser.js +15 -0
- package/dist/users/subscribeToCurrentUser.d.ts +8 -0
- package/dist/users/subscribeToCurrentUser.d.ts.map +1 -0
- package/dist/users/subscribeToCurrentUser.js +8 -0
- package/dist/users/types.d.ts +41 -0
- package/dist/users/types.d.ts.map +1 -0
- package/dist/users/types.js +1 -0
- package/dist/utils/notifyListener.d.ts.map +1 -0
- package/dist/utils/typeUtils.d.ts.map +1 -0
- package/dist/utils/typeUtils.js +1 -0
- package/dist/{utils.d.ts → utils/unreachable.d.ts} +1 -1
- package/dist/utils/unreachable.d.ts.map +1 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/{version.js → utils/version.js} +1 -1
- package/docs/block-location.md +3 -2
- package/docs/capabilities.md +111 -0
- package/docs/data-sources.md +6 -2
- package/docs/deployment.md +2 -1
- package/docs/errors.md +9 -0
- package/docs/lifecycle.md +6 -6
- package/docs/pages.md +0 -3
- package/docs/users.md +3 -0
- package/package.json +1 -1
- package/src/bridge/SandboxBridge.ts +159 -899
- package/src/bridge/getBridge.ts +10 -0
- package/src/bridge/{SandboxInitialization.ts → initialization/SandboxInitialization.ts} +11 -21
- package/src/bridge.ts +2 -2
- package/src/context/applyContextMessage.ts +55 -0
- package/src/context/getBlockId.ts +10 -0
- package/src/context/getContrastMode.ts +10 -0
- package/src/context/getInitializedHostState.ts +14 -0
- package/src/context/getPage.ts +10 -0
- package/src/context/getParent.ts +10 -0
- package/src/context/getTheme.ts +10 -0
- package/src/context/hostState.ts +17 -0
- package/src/context/index.ts +42 -0
- package/src/context/react/useBlockId.ts +16 -0
- package/src/context/react/useContrastMode.ts +16 -0
- package/src/context/react/usePage.ts +17 -0
- package/src/context/react/useParent.ts +17 -0
- package/src/context/react/useTheme.ts +16 -0
- package/src/context/subscribeToBlockId.ts +13 -0
- package/src/context/subscribeToContext.ts +42 -0
- package/src/context/subscribeToContrastMode.ts +13 -0
- package/src/context/subscribeToPage.ts +13 -0
- package/src/context/subscribeToParent.ts +13 -0
- package/src/context/subscribeToTheme.ts +13 -0
- package/src/context/syncDocumentAppearance.ts +31 -0
- package/src/dataSources/bridge/applyDataSourceBindings.ts +25 -0
- package/src/{bridge/dataSources/query.ts → dataSources/bridge/resolveDataSourceQuery.ts} +26 -41
- package/src/dataSources/bridge/resolveDataSources.ts +44 -0
- package/src/{bridge/dataSources → dataSources/bridge}/resolveSorts.ts +8 -10
- package/src/dataSources/bridge/reuseDataSourcesForUnchangedBindings.ts +32 -0
- package/src/dataSources/createDataSourcePage.ts +46 -0
- package/src/dataSources/dataSourceInaccessibleError.ts +13 -0
- package/src/{bridge/dataSources/queryFilter.ts → dataSources/filters/resolveFilter.ts} +14 -16
- package/src/dataSources/filters/types.ts +77 -0
- package/src/dataSources/getDataSourcePage.ts +24 -0
- package/src/dataSources/index.ts +9 -0
- package/src/{bridge/dataSources → dataSources/properties}/resolvePropertyAddress.ts +1 -1
- package/src/{bridge/dataSources/resolveProperty.ts → dataSources/properties/resolvePropertyWriteMapForDataSource.ts} +5 -5
- package/src/dataSources/queryDataSource.ts +62 -0
- package/src/{react → dataSources/react}/useDataSource.ts +2 -2
- package/src/dataSources/resolvePageDataSource.ts +57 -0
- package/src/dataSources/subscribeToDataSource.ts +143 -0
- package/src/dataSources/types.ts +53 -0
- package/src/index.ts +70 -68
- package/src/initialization/NotInIframeError.ts +23 -0
- package/src/initialization/getInitBindingError.ts +39 -0
- package/src/initialization/initCustomBlock.ts +10 -0
- package/src/{react → initialization/react}/useCustomBlockInit.ts +3 -2
- package/src/initialization/resolveInitialState.ts +37 -0
- package/src/initialization/types.ts +20 -0
- package/src/{autoResize.ts → layout/autoResize.ts} +2 -2
- package/src/layout/getInitialContentHeight.ts +10 -0
- package/src/layout/postResize.ts +15 -0
- package/src/manifest/getManifest.ts +10 -0
- package/src/manifest/react/useManifest.ts +20 -0
- package/src/{bridge → manifest}/readLocalManifest.ts +5 -7
- package/src/manifest/subscribeToManifest.ts +13 -0
- package/src/manifest/types.ts +7 -0
- package/src/navigation/index.ts +5 -0
- package/src/navigation/openExternalUrl.ts +9 -0
- package/src/navigation/types.ts +10 -0
- package/src/pages/bridge/buildCreatePageRequest.ts +49 -0
- package/src/pages/bridge/getPageForDataSource.ts +25 -0
- package/src/pages/bridge/makeUpdatePageByKey.ts +25 -0
- package/src/pages/bridge/resolveCreatePageDestination.ts +75 -0
- package/src/pages/bridge/sendCreatePageRequest.ts +22 -0
- package/src/pages/bridge/toNotionPageFieldsFromBridgePage.ts +28 -0
- package/src/pages/bridge/toNotionPageFromBridgePage.ts +22 -0
- package/src/pages/bridge/toNotionPagePropertyFromBridgeProperty.ts +97 -0
- package/src/pages/bridge/updateNotionPageFromBridgePage.ts +10 -0
- package/src/pages/bridge/updatePage.ts +90 -0
- package/src/pages/createPage.ts +31 -0
- package/src/pages/getPage.ts +14 -0
- package/src/pages/index.ts +9 -0
- package/src/pages/makeNotionPage.ts +55 -0
- package/src/pages/openPage.ts +13 -0
- package/src/pages/parent.ts +14 -0
- package/src/pages/properties/getPropertyById.ts +12 -0
- package/src/pages/properties/getPropertyByKey.ts +30 -0
- package/src/pages/types.ts +189 -0
- package/src/react/DebugMessageLog.tsx +6 -2
- package/src/react/InitializationErrorDetails.tsx +30 -0
- package/{dist/react/NotionCustomBlock.css → src/react/InitializationErrorScreen.css} +0 -20
- package/src/react/MissingHostCommand.tsx +49 -0
- package/src/react/MissingHostScreen.css +85 -0
- package/src/react/MissingHostScreen.tsx +34 -0
- package/src/react/NotionCustomBlock.tsx +17 -55
- package/src/react/NotionTokenScope.tsx +2 -1
- package/src/react/index.ts +14 -22
- package/src/users/bridge/toNotionUserFromBridgeUser.ts +13 -0
- package/src/users/getCurrentUser.ts +10 -0
- package/src/users/getUser.ts +14 -0
- package/src/users/index.ts +7 -0
- package/src/users/listUsers.ts +23 -0
- package/src/users/react/useCurrentUser.ts +17 -0
- package/src/users/subscribeToCurrentUser.ts +13 -0
- package/src/users/types.ts +36 -0
- package/dist/autoResize.d.ts.map +0 -1
- package/dist/bridge/SandboxInitialization.d.ts.map +0 -1
- package/dist/bridge/appearance.d.ts.map +0 -1
- package/dist/bridge/dataSources/query.d.ts +0 -27
- package/dist/bridge/dataSources/query.d.ts.map +0 -1
- package/dist/bridge/dataSources/queryFilter.d.ts.map +0 -1
- package/dist/bridge/dataSources/resolve.d.ts +0 -14
- package/dist/bridge/dataSources/resolve.d.ts.map +0 -1
- package/dist/bridge/dataSources/resolveProperty.d.ts.map +0 -1
- package/dist/bridge/dataSources/resolvePropertyAddress.d.ts.map +0 -1
- package/dist/bridge/dataSources/resolveSorts.d.ts.map +0 -1
- package/dist/bridge/dataSources/subscribe.d.ts.map +0 -1
- package/dist/bridge/dataSources/subscribe.js +0 -76
- package/dist/bridge/hostState.d.ts +0 -42
- package/dist/bridge/hostState.d.ts.map +0 -1
- package/dist/bridge/hostState.js +0 -8
- package/dist/bridge/notifyListener.d.ts.map +0 -1
- package/dist/bridge/page.d.ts +0 -18
- package/dist/bridge/page.d.ts.map +0 -1
- package/dist/bridge/readLocalManifest.d.ts.map +0 -1
- package/dist/bridge/sandboxClient.d.ts +0 -66
- package/dist/bridge/sandboxClient.d.ts.map +0 -1
- package/dist/bridge/sandboxClient.js +0 -158
- package/dist/customBlock.d.ts +0 -97
- package/dist/customBlock.d.ts.map +0 -1
- package/dist/customBlock.js +0 -157
- package/dist/dataSources.d.ts +0 -8
- package/dist/dataSources.d.ts.map +0 -1
- package/dist/dataSources.js +0 -105
- package/dist/init.d.ts.map +0 -1
- package/dist/initTypes.d.ts +0 -31
- package/dist/initTypes.d.ts.map +0 -1
- package/dist/protocol/dataSources/dataSource.d.ts +0 -786
- package/dist/protocol/dataSources/dataSource.js +0 -66
- package/dist/protocol/errors.js +0 -6
- package/dist/protocol/messages/createPage.js +0 -51
- package/dist/protocol/messages/createPageResult.js +0 -43
- package/dist/protocol/messages/queryDataSource.d.ts +0 -1470
- package/dist/protocol/messages/queryDataSource.js +0 -254
- package/dist/protocol/messages/updatePage.js +0 -23
- package/dist/protocol/pages/page.d.ts +0 -1422
- package/dist/protocol/pages/page.js +0 -318
- package/dist/protocol/parent.js +0 -13
- package/dist/protocol/users/user.js +0 -20
- package/dist/react/standalonePreview.d.ts +0 -2
- package/dist/react/standalonePreview.d.ts.map +0 -1
- package/dist/react/standalonePreview.js +0 -36
- package/dist/react/useCustomBlockInit.d.ts.map +0 -1
- package/dist/react/useDataSource.d.ts.map +0 -1
- package/dist/react/useHostState.d.ts +0 -2
- package/dist/react/useHostState.d.ts.map +0 -1
- package/dist/react/useHostState.js +0 -5
- package/dist/react/useRuntimeState.d.ts +0 -78
- package/dist/react/useRuntimeState.d.ts.map +0 -1
- package/dist/react/useRuntimeState.js +0 -86
- package/dist/typeUtils.d.ts.map +0 -1
- package/dist/types.d.ts +0 -204
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/src/bridge/dataSources/resolve.ts +0 -50
- package/src/bridge/dataSources/subscribe.ts +0 -124
- package/src/bridge/hostState.ts +0 -59
- package/src/bridge/page.ts +0 -47
- package/src/bridge/sandboxClient.ts +0 -225
- package/src/customBlock.ts +0 -193
- package/src/dataSources.ts +0 -136
- package/src/init.ts +0 -15
- package/src/initTypes.ts +0 -43
- package/src/react/standalonePreview.ts +0 -41
- package/src/react/useHostState.ts +0 -9
- package/src/react/useRuntimeState.ts +0 -118
- package/src/types.ts +0 -284
- /package/dist/{bridge/appearance.js → context/backgroundColors.js} +0 -0
- /package/dist/{typeUtils.js → context/hostState.js} +0 -0
- /package/dist/{types.js → dataSources/filters/types.js} +0 -0
- /package/dist/{bridge/dataSources → dataSources/properties}/resolvePropertyAddress.js +0 -0
- /package/dist/{react → dataSources/react}/useDataSource.d.ts +0 -0
- /package/dist/{autoResize.d.ts → layout/autoResize.d.ts} +0 -0
- /package/dist/protocol/{dataSources → compatibility/protocol3To5}/dataSourcePage.d.ts +0 -0
- /package/dist/protocol/{dataSources → compatibility/protocol3To5}/dataSourceValue.d.ts +0 -0
- /package/dist/protocol/{contrast.d.ts → context/contrast.d.ts} +0 -0
- /package/dist/protocol/{contrast.js → context/contrast.js} +0 -0
- /package/dist/protocol/{messages → context/messages}/contrastModeChanged.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/contrastModeChanged.js +0 -0
- /package/dist/protocol/{messages → context/messages}/pageChanged.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/parentChanged.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/parentChanged.js +0 -0
- /package/dist/protocol/{messages → context/messages}/resize.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/resize.js +0 -0
- /package/dist/protocol/{messages → context/messages}/themeChanged.d.ts +0 -0
- /package/dist/protocol/{messages → context/messages}/themeChanged.js +0 -0
- /package/dist/protocol/{theme.d.ts → context/theme.d.ts} +0 -0
- /package/dist/protocol/{theme.js → context/theme.js} +0 -0
- /package/dist/protocol/{messages → dataSources/messages}/unsubscribeDataSourceQuery.d.ts +0 -0
- /package/dist/protocol/{messages → dataSources/messages}/unsubscribeDataSourceQuery.js +0 -0
- /package/dist/protocol/dataSources/{dateValue.d.ts → properties/dateValue.d.ts} +0 -0
- /package/dist/protocol/dataSources/{dateValue.js → properties/dateValue.js} +0 -0
- /package/dist/protocol/dataSources/{propertySchema.d.ts → properties/propertySchema.d.ts} +0 -0
- /package/dist/protocol/dataSources/{propertySchema.js → properties/propertySchema.js} +0 -0
- /package/dist/protocol/{messages → handshake}/initResult.js +0 -0
- /package/dist/protocol/{messages → handshake}/isInitHandshakeMessage.js +0 -0
- /package/dist/protocol/{messages → navigation}/openExternalUrl.js +0 -0
- /package/dist/protocol/{messages → users/messages}/currentUserChanged.d.ts +0 -0
- /package/dist/protocol/{ids.d.ts → utils/ids.d.ts} +0 -0
- /package/dist/protocol/{ids.js → utils/ids.js} +0 -0
- /package/dist/protocol/{isLocalBlockServerUrl.d.ts → utils/isLocalBlockServerUrl.d.ts} +0 -0
- /package/dist/protocol/{isLocalBlockServerUrl.js → utils/isLocalBlockServerUrl.js} +0 -0
- /package/dist/protocol/{protocolVersion.d.ts → utils/protocolVersion.d.ts} +0 -0
- /package/dist/protocol/{protocolVersion.js → utils/protocolVersion.js} +0 -0
- /package/dist/protocol/{dataSources → utils}/recordPointer.d.ts +0 -0
- /package/dist/protocol/{dataSources → utils}/recordPointer.js +0 -0
- /package/dist/{bridge → utils}/notifyListener.d.ts +0 -0
- /package/dist/{bridge → utils}/notifyListener.js +0 -0
- /package/dist/{typeUtils.d.ts → utils/typeUtils.d.ts} +0 -0
- /package/dist/{utils.js → utils/unreachable.js} +0 -0
- /package/dist/{version.d.ts → utils/version.d.ts} +0 -0
- /package/src/{bridge/appearance.ts → context/backgroundColors.ts} +0 -0
- /package/src/{bridge → utils}/notifyListener.ts +0 -0
- /package/src/{typeUtils.ts → utils/typeUtils.ts} +0 -0
- /package/src/{utils.ts → utils/unreachable.ts} +0 -0
- /package/src/{version.ts → utils/version.ts} +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { BridgeDataSourceBindings } from "@notionhq/custom-blocks-protocol/dataSources/bridgeDataSourceBindings.js"
|
|
2
|
+
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
3
|
+
import { resolveDataSourceBinding } from "@notionhq/custom-blocks-protocol/dataSources/resolveDataSourceBinding.js"
|
|
4
|
+
import type { BridgeCustomBlockManifest } from "@notionhq/custom-blocks-protocol/manifest/manifest.js"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Builds the public {@link NotionDataSource} list the SDK exposes to consumers.
|
|
8
|
+
*
|
|
9
|
+
* Combines the host-supplied bindings (database pointers + schemas) with the manifest's declared
|
|
10
|
+
* data source keys. The host owns every mapping; the SDK validates supplied IDs but never infers
|
|
11
|
+
* omitted bindings.
|
|
12
|
+
*/
|
|
13
|
+
export function resolveDataSources(args: {
|
|
14
|
+
manifest: BridgeCustomBlockManifest
|
|
15
|
+
dataSourceBindings: BridgeDataSourceBindings
|
|
16
|
+
}): NotionDataSource[] {
|
|
17
|
+
return Object.entries(args.manifest.dataSources).map(
|
|
18
|
+
([key, manifestDataSource]) => {
|
|
19
|
+
const binding = args.dataSourceBindings[key]
|
|
20
|
+
const collectionProperties =
|
|
21
|
+
binding?.collectionSchema?.propertiesById ?? {}
|
|
22
|
+
|
|
23
|
+
const resolvedBinding = resolveDataSourceBinding({
|
|
24
|
+
manifestDataSource,
|
|
25
|
+
collectionSchema: binding?.collectionSchema,
|
|
26
|
+
propertyIdsByKey: binding?.propertyIdsByKey,
|
|
27
|
+
})
|
|
28
|
+
const propertyIdsByKey: Record<string, string | undefined> = {}
|
|
29
|
+
for (const property of resolvedBinding.properties) {
|
|
30
|
+
propertyIdsByKey[property.propertyKey] =
|
|
31
|
+
property.status === "mapped" ? property.propertyId : undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
key,
|
|
36
|
+
collectionPointer: binding?.collectionPointer,
|
|
37
|
+
collectionSchema: binding?.collectionSchema,
|
|
38
|
+
propertyIdsByKey,
|
|
39
|
+
propertySchemasById: collectionProperties,
|
|
40
|
+
...(binding?.inaccessible === true && { inaccessible: true }),
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
)
|
|
44
|
+
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { BridgeDataSourceSort } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceSort.js"
|
|
2
|
+
import { CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceSort.js"
|
|
3
|
+
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
4
|
+
import { CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES } from "@notionhq/custom-blocks-protocol/dataSources/properties/propertySchema.js"
|
|
3
5
|
import { notionSortDirectionSchema } from "@notionhq/custom-blocks-protocol/dataSources/sortDirection.js"
|
|
4
|
-
import {
|
|
5
|
-
CUSTOM_BLOCK_DATA_SOURCE_QUERY_MAX_SORTS,
|
|
6
|
-
type ResolvedCustomBlockDataSourceSort,
|
|
7
|
-
} from "@notionhq/custom-blocks-protocol/messages/queryDataSource.js"
|
|
8
6
|
import * as v from "valibot"
|
|
9
|
-
import { resolvePropertyAddress } from "
|
|
7
|
+
import { resolvePropertyAddress } from "../properties/resolvePropertyAddress.js"
|
|
10
8
|
|
|
11
9
|
const supportedDataSourceSortPropertyTypes = new Set<string>(
|
|
12
10
|
CUSTOM_BLOCK_DATA_SOURCE_SORTABLE_PROPERTY_TYPES,
|
|
@@ -16,7 +14,7 @@ export function resolveSorts(
|
|
|
16
14
|
sorts: unknown,
|
|
17
15
|
dataSource: NotionDataSource,
|
|
18
16
|
):
|
|
19
|
-
| { status: "ok"; sorts?:
|
|
17
|
+
| { status: "ok"; sorts?: BridgeDataSourceSort[] }
|
|
20
18
|
| { status: "error"; error: string } {
|
|
21
19
|
if (sorts === undefined) {
|
|
22
20
|
return { status: "ok" }
|
|
@@ -37,7 +35,7 @@ export function resolveSorts(
|
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
const resolvedSorts:
|
|
38
|
+
const resolvedSorts: BridgeDataSourceSort[] = []
|
|
41
39
|
const seenPropertyIds = new Set<string>()
|
|
42
40
|
for (const sort of sorts) {
|
|
43
41
|
const resolved = resolveSort(sort, dataSource)
|
|
@@ -60,7 +58,7 @@ function resolveSort(
|
|
|
60
58
|
sort: unknown,
|
|
61
59
|
dataSource: NotionDataSource,
|
|
62
60
|
):
|
|
63
|
-
| { status: "ok"; sort:
|
|
61
|
+
| { status: "ok"; sort: BridgeDataSourceSort }
|
|
64
62
|
| { status: "error"; error: string } {
|
|
65
63
|
if (typeof sort !== "object" || sort === null || Array.isArray(sort)) {
|
|
66
64
|
return {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BridgeDataSourceBindings } from "@notionhq/custom-blocks-protocol/dataSources/bridgeDataSourceBindings.js"
|
|
2
|
+
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `postMessage` cloning creates new objects even for bindings that did not change. Preserve their
|
|
6
|
+
* resolved object identity so React effects only run for changed bindings.
|
|
7
|
+
*
|
|
8
|
+
* This comparison runs when the host sends an update instead of on every component render. Bindings
|
|
9
|
+
* are validated JSON-like bridge payloads, so serialization is sufficient here.
|
|
10
|
+
*/
|
|
11
|
+
export function reuseDataSourcesForUnchangedBindings(args: {
|
|
12
|
+
previousDataSources: NotionDataSource[]
|
|
13
|
+
previousBindings: BridgeDataSourceBindings
|
|
14
|
+
nextDataSources: NotionDataSource[]
|
|
15
|
+
nextBindings: BridgeDataSourceBindings
|
|
16
|
+
}): NotionDataSource[] {
|
|
17
|
+
const previousDataSourcesByKey = new Map(
|
|
18
|
+
args.previousDataSources.map(dataSource => [dataSource.key, dataSource]),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
return args.nextDataSources.map(dataSource => {
|
|
22
|
+
const previousDataSource = previousDataSourcesByKey.get(dataSource.key)
|
|
23
|
+
if (
|
|
24
|
+
previousDataSource !== undefined &&
|
|
25
|
+
JSON.stringify(args.previousBindings[dataSource.key]) ===
|
|
26
|
+
JSON.stringify(args.nextBindings[dataSource.key])
|
|
27
|
+
) {
|
|
28
|
+
return previousDataSource
|
|
29
|
+
}
|
|
30
|
+
return dataSource
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getBridge } from "../bridge/getBridge.js"
|
|
2
|
+
import { buildCreatePageRequest } from "../pages/bridge/buildCreatePageRequest.js"
|
|
3
|
+
import { sendCreatePageRequest } from "../pages/bridge/sendCreatePageRequest.js"
|
|
4
|
+
import type { CreatePageArgs } from "../pages/types.js"
|
|
5
|
+
import { resolvePageDataSource } from "./resolvePageDataSource.js"
|
|
6
|
+
import type { DataSourcesPageResult } from "./types.js"
|
|
7
|
+
|
|
8
|
+
export async function createDataSourcePage(
|
|
9
|
+
key: string,
|
|
10
|
+
payload: Omit<CreatePageArgs, "parent" | "position">,
|
|
11
|
+
): Promise<DataSourcesPageResult> {
|
|
12
|
+
const bridge = getBridge()
|
|
13
|
+
const resolved = resolvePageDataSource({
|
|
14
|
+
hostState: bridge.getHostState(),
|
|
15
|
+
key,
|
|
16
|
+
})
|
|
17
|
+
if (resolved.status === "error") {
|
|
18
|
+
return resolved
|
|
19
|
+
}
|
|
20
|
+
const { dataSource, dataSourceId } = resolved
|
|
21
|
+
const { properties } = payload
|
|
22
|
+
const prepared = buildCreatePageRequest({
|
|
23
|
+
destination: {
|
|
24
|
+
type: "data_source_id",
|
|
25
|
+
data_source_id: dataSourceId,
|
|
26
|
+
dataSource,
|
|
27
|
+
},
|
|
28
|
+
properties,
|
|
29
|
+
})
|
|
30
|
+
if (prepared.status === "error") {
|
|
31
|
+
return prepared
|
|
32
|
+
}
|
|
33
|
+
const result = await sendCreatePageRequest({
|
|
34
|
+
bridge,
|
|
35
|
+
request: prepared.request,
|
|
36
|
+
dataSource,
|
|
37
|
+
})
|
|
38
|
+
if (result.status === "error") {
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
status: "success",
|
|
43
|
+
page: result.page,
|
|
44
|
+
propertyIdsByKey: dataSource.propertyIdsByKey,
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CustomBlockDataSourceResolutionErrorInfo } from "@notionhq/custom-blocks-protocol/dataSources/errors.js"
|
|
2
|
+
|
|
3
|
+
/** The error for a call that uses a bound data source the viewer can't read. */
|
|
4
|
+
export function dataSourceInaccessibleError(
|
|
5
|
+
key: string,
|
|
6
|
+
): CustomBlockDataSourceResolutionErrorInfo {
|
|
7
|
+
return {
|
|
8
|
+
code: "data_source_inaccessible",
|
|
9
|
+
message: `You don't have access to data source "${key}".`,
|
|
10
|
+
// The viewer needs access to the data source before the call can succeed.
|
|
11
|
+
isRetryable: false,
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,24 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
resolvedCustomBlockDataSourcePropertyFilterSchema,
|
|
7
|
-
} from "@notionhq/custom-blocks-protocol/messages/queryDataSource.js"
|
|
1
|
+
import type { BridgeDataSourceFilter } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilter.js"
|
|
2
|
+
import type { BridgeDataSourceFilterCondition } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilterCondition.js"
|
|
3
|
+
import { bridgeDataSourceFilterConditionSchema } from "@notionhq/custom-blocks-protocol/dataSources/filters/bridgeDataSourceFilterCondition.js"
|
|
4
|
+
import { customBlockRelativeDateValueSchema } from "@notionhq/custom-blocks-protocol/dataSources/filters/dateFilterOperator.js"
|
|
5
|
+
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
8
6
|
import * as v from "valibot"
|
|
9
|
-
import { resolvePropertyAddress } from "
|
|
7
|
+
import { resolvePropertyAddress } from "../properties/resolvePropertyAddress.js"
|
|
10
8
|
|
|
11
9
|
const MAX_DATA_SOURCE_QUERY_FILTER_CHILDREN = 25
|
|
12
10
|
|
|
13
11
|
type ResolvePropertyFilterResult =
|
|
14
|
-
| { status: "ok"; filter:
|
|
12
|
+
| { status: "ok"; filter: BridgeDataSourceFilterCondition }
|
|
15
13
|
| { status: "error"; error: string }
|
|
16
14
|
|
|
17
15
|
export function resolveFilter(
|
|
18
16
|
filter: unknown,
|
|
19
17
|
dataSource: NotionDataSource,
|
|
20
18
|
):
|
|
21
|
-
| { status: "ok"; filter?:
|
|
19
|
+
| { status: "ok"; filter?: BridgeDataSourceFilter }
|
|
22
20
|
| { status: "error"; error: string } {
|
|
23
21
|
if (filter === undefined) {
|
|
24
22
|
return { status: "ok" }
|
|
@@ -46,7 +44,7 @@ export function resolveFilter(
|
|
|
46
44
|
error: `Data source query filter "and" may contain at most ${MAX_DATA_SOURCE_QUERY_FILTER_CHILDREN} children.`,
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
|
-
const and:
|
|
47
|
+
const and: BridgeDataSourceFilterCondition[] = []
|
|
50
48
|
for (const child of filterObject.and) {
|
|
51
49
|
const resolved = resolvePropertyFilter(child, dataSource)
|
|
52
50
|
if (resolved.status === "error") {
|
|
@@ -115,13 +113,13 @@ function parsePropertyFilter(args: {
|
|
|
115
113
|
value: unknown
|
|
116
114
|
}): ResolvePropertyFilterResult {
|
|
117
115
|
const { propertyId, branch, value } = args
|
|
118
|
-
const parsed = v.safeParse(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
116
|
+
const parsed = v.safeParse(bridgeDataSourceFilterConditionSchema, {
|
|
117
|
+
propertyId,
|
|
118
|
+
[branch]: value,
|
|
119
|
+
})
|
|
122
120
|
if (!parsed.success) {
|
|
123
121
|
if (
|
|
124
|
-
|
|
122
|
+
bridgeDataSourceFilterConditionSchema.options.every(
|
|
125
123
|
schema => !Object.hasOwn(schema.entries, branch),
|
|
126
124
|
)
|
|
127
125
|
) {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { CustomBlockCheckboxFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/checkboxFilterOperator.js"
|
|
2
|
+
import type { CustomBlockContainsFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/containsFilterOperator.js"
|
|
3
|
+
import type { CustomBlockCreatedByFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/createdByFilterOperator.js"
|
|
4
|
+
import type { CustomBlockDateFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/dateFilterOperator.js"
|
|
5
|
+
import type { CustomBlockNumberFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/numberFilterOperator.js"
|
|
6
|
+
import type { CustomBlockOptionFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/optionFilterOperator.js"
|
|
7
|
+
import type {
|
|
8
|
+
CustomBlockPeopleFilterOperator,
|
|
9
|
+
CustomBlockPersonFilterValue,
|
|
10
|
+
} from "@notionhq/custom-blocks-protocol/dataSources/filters/peopleFilterOperator.js"
|
|
11
|
+
import type { CustomBlockRelationFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/relationFilterOperator.js"
|
|
12
|
+
import type { CustomBlockStatusFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/statusFilterOperator.js"
|
|
13
|
+
import type { CustomBlockTextFilterOperator } from "@notionhq/custom-blocks-protocol/dataSources/filters/textFilterOperator.js"
|
|
14
|
+
import type { NotionSortDirection } from "@notionhq/custom-blocks-protocol/dataSources/sortDirection.js"
|
|
15
|
+
import type { ExclusiveUnion } from "../../utils/typeUtils.js"
|
|
16
|
+
|
|
17
|
+
export type NotionDataSourceTextFilterOperator =
|
|
18
|
+
ExclusiveUnion<CustomBlockTextFilterOperator>
|
|
19
|
+
|
|
20
|
+
export type NotionDataSourceNumberFilterOperator =
|
|
21
|
+
ExclusiveUnion<CustomBlockNumberFilterOperator>
|
|
22
|
+
|
|
23
|
+
export type NotionDataSourceCheckboxFilterOperator =
|
|
24
|
+
ExclusiveUnion<CustomBlockCheckboxFilterOperator>
|
|
25
|
+
|
|
26
|
+
export type NotionDataSourceOptionFilterOperator =
|
|
27
|
+
ExclusiveUnion<CustomBlockOptionFilterOperator>
|
|
28
|
+
|
|
29
|
+
export type NotionDataSourceStatusFilterOperator =
|
|
30
|
+
ExclusiveUnion<CustomBlockStatusFilterOperator>
|
|
31
|
+
|
|
32
|
+
export type NotionDataSourceContainsFilterOperator =
|
|
33
|
+
ExclusiveUnion<CustomBlockContainsFilterOperator>
|
|
34
|
+
|
|
35
|
+
export type NotionDataSourceDateFilterOperator =
|
|
36
|
+
ExclusiveUnion<CustomBlockDateFilterOperator>
|
|
37
|
+
|
|
38
|
+
export type NotionDataSourceCreatedByFilterOperator =
|
|
39
|
+
ExclusiveUnion<CustomBlockCreatedByFilterOperator>
|
|
40
|
+
|
|
41
|
+
export type NotionDataSourcePersonFilterValue = CustomBlockPersonFilterValue
|
|
42
|
+
|
|
43
|
+
export type NotionDataSourcePeopleFilterOperator =
|
|
44
|
+
ExclusiveUnion<CustomBlockPeopleFilterOperator>
|
|
45
|
+
|
|
46
|
+
export type NotionDataSourceRelationFilterOperator =
|
|
47
|
+
ExclusiveUnion<CustomBlockRelationFilterOperator>
|
|
48
|
+
|
|
49
|
+
export type NotionDataSourcePropertyAddress =
|
|
50
|
+
| { key: string; propertyId?: never }
|
|
51
|
+
| { propertyId: string; key?: never }
|
|
52
|
+
|
|
53
|
+
export type NotionDataSourcePropertyFilter = NotionDataSourcePropertyAddress &
|
|
54
|
+
ExclusiveUnion<
|
|
55
|
+
| { title: NotionDataSourceTextFilterOperator }
|
|
56
|
+
| { rich_text: NotionDataSourceTextFilterOperator }
|
|
57
|
+
| { url: NotionDataSourceTextFilterOperator }
|
|
58
|
+
| { email: NotionDataSourceTextFilterOperator }
|
|
59
|
+
| { phone_number: NotionDataSourceTextFilterOperator }
|
|
60
|
+
| { number: NotionDataSourceNumberFilterOperator }
|
|
61
|
+
| { checkbox: NotionDataSourceCheckboxFilterOperator }
|
|
62
|
+
| { select: NotionDataSourceOptionFilterOperator }
|
|
63
|
+
| { multi_select: NotionDataSourceContainsFilterOperator }
|
|
64
|
+
| { status: NotionDataSourceStatusFilterOperator }
|
|
65
|
+
| { date: NotionDataSourceDateFilterOperator }
|
|
66
|
+
| { people: NotionDataSourcePeopleFilterOperator }
|
|
67
|
+
| { relation: NotionDataSourceRelationFilterOperator }
|
|
68
|
+
| { created_by: NotionDataSourceCreatedByFilterOperator }
|
|
69
|
+
>
|
|
70
|
+
|
|
71
|
+
export type NotionDataSourceSort = NotionDataSourcePropertyAddress & {
|
|
72
|
+
direction: NotionSortDirection
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type NotionDataSourceFilter = ExclusiveUnion<
|
|
76
|
+
NotionDataSourcePropertyFilter | { and: NotionDataSourcePropertyFilter[] }
|
|
77
|
+
>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { NotionPageId } from "@notionhq/custom-blocks-protocol/utils/ids.js"
|
|
2
|
+
import { getBridge } from "../bridge/getBridge.js"
|
|
3
|
+
import { getPageForDataSource } from "../pages/bridge/getPageForDataSource.js"
|
|
4
|
+
import { resolvePageDataSource } from "./resolvePageDataSource.js"
|
|
5
|
+
import type { DataSourcesPageResult } from "./types.js"
|
|
6
|
+
|
|
7
|
+
export async function getDataSourcePage(
|
|
8
|
+
key: string,
|
|
9
|
+
pageId: NotionPageId,
|
|
10
|
+
): Promise<DataSourcesPageResult> {
|
|
11
|
+
const bridge = getBridge()
|
|
12
|
+
const resolved = resolvePageDataSource({
|
|
13
|
+
hostState: bridge.getHostState(),
|
|
14
|
+
key,
|
|
15
|
+
})
|
|
16
|
+
if (resolved.status === "error") {
|
|
17
|
+
return resolved
|
|
18
|
+
}
|
|
19
|
+
const { dataSource } = resolved
|
|
20
|
+
const result = await getPageForDataSource(bridge, { pageId, dataSource })
|
|
21
|
+
return result.status === "error"
|
|
22
|
+
? result
|
|
23
|
+
: { ...result, propertyIdsByKey: dataSource.propertyIdsByKey }
|
|
24
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createDataSourcePage } from "./createDataSourcePage.js"
|
|
2
|
+
import { getDataSourcePage } from "./getDataSourcePage.js"
|
|
3
|
+
import { queryDataSource } from "./queryDataSource.js"
|
|
4
|
+
|
|
5
|
+
export const dataSources = {
|
|
6
|
+
getPage: getDataSourcePage,
|
|
7
|
+
create: createDataSourcePage,
|
|
8
|
+
query: queryDataSource,
|
|
9
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/
|
|
1
|
+
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
2
2
|
|
|
3
3
|
export function resolvePropertyAddress(
|
|
4
4
|
value: Record<string, unknown>,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/dataSource.js"
|
|
2
1
|
import type {
|
|
3
2
|
CustomBlockPropertyErrorCode,
|
|
4
3
|
CustomBlockPropertyErrorInfo,
|
|
5
4
|
} from "@notionhq/custom-blocks-protocol/dataSources/errors.js"
|
|
6
|
-
import type {
|
|
7
|
-
import {
|
|
5
|
+
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
6
|
+
import type { CreatePageMessage } from "@notionhq/custom-blocks-protocol/pages/messages/createPage.js"
|
|
7
|
+
import { bridgePagePropertyValueSchema } from "@notionhq/custom-blocks-protocol/pages/properties/bridgePagePropertyValue.js"
|
|
8
8
|
import * as v from "valibot"
|
|
9
|
-
import type { NotionPagePropertyInputMap } from "../../types.js"
|
|
9
|
+
import type { NotionPagePropertyInputMap } from "../../pages/types.js"
|
|
10
10
|
|
|
11
11
|
export type PropertyWriteMapResolutionResult =
|
|
12
12
|
| { status: "success"; properties: CreatePageMessage["properties"] }
|
|
@@ -79,7 +79,7 @@ export function resolvePropertyWriteMapForDataSource(args: {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
const parsedValue = v.safeParse(
|
|
82
|
+
const parsedValue = v.safeParse(bridgePagePropertyValueSchema, {
|
|
83
83
|
...value,
|
|
84
84
|
id: propertyId,
|
|
85
85
|
})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CustomBlockInitializationError } from "@notionhq/custom-blocks-protocol/handshake/init.js"
|
|
2
|
+
import { getBridge } from "../bridge/getBridge.js"
|
|
3
|
+
import { subscribeToDataSource } from "./subscribeToDataSource.js"
|
|
4
|
+
import type { DataSourceQueryOptions, DataSourcesQueryResult } from "./types.js"
|
|
5
|
+
|
|
6
|
+
export async function queryDataSource(
|
|
7
|
+
key: string,
|
|
8
|
+
options?: DataSourceQueryOptions,
|
|
9
|
+
): Promise<DataSourcesQueryResult> {
|
|
10
|
+
const bridge = getBridge()
|
|
11
|
+
if (bridge.getHostState().status !== "initialized") {
|
|
12
|
+
try {
|
|
13
|
+
await bridge.initialize()
|
|
14
|
+
} catch (error) {
|
|
15
|
+
if (bridge.getHostState().status !== "initialized") {
|
|
16
|
+
return {
|
|
17
|
+
status: "error",
|
|
18
|
+
error:
|
|
19
|
+
error instanceof CustomBlockInitializationError
|
|
20
|
+
? {
|
|
21
|
+
code: error.code,
|
|
22
|
+
message: error.message,
|
|
23
|
+
isRetryable: error.isRetryable,
|
|
24
|
+
}
|
|
25
|
+
: {
|
|
26
|
+
code: "unknown_error",
|
|
27
|
+
message:
|
|
28
|
+
error instanceof Error ? error.message : String(error),
|
|
29
|
+
isRetryable: false,
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return new Promise(resolve => {
|
|
36
|
+
let completed = false
|
|
37
|
+
let unsubscribe = () => {}
|
|
38
|
+
unsubscribe = subscribeToDataSource({
|
|
39
|
+
key,
|
|
40
|
+
options,
|
|
41
|
+
onSnapshot: snapshot => {
|
|
42
|
+
if (snapshot.isLoading || completed) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
completed = true
|
|
46
|
+
unsubscribe()
|
|
47
|
+
resolve({ status: "success", ...snapshot })
|
|
48
|
+
},
|
|
49
|
+
onError: error => {
|
|
50
|
+
if (completed) {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
completed = true
|
|
54
|
+
unsubscribe()
|
|
55
|
+
resolve({ status: "error", error })
|
|
56
|
+
},
|
|
57
|
+
})
|
|
58
|
+
if (completed) {
|
|
59
|
+
unsubscribe()
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from "react"
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { customBlock } from "../../context/index.js"
|
|
3
|
+
import { getDataSourceQueryOptionsIdentity } from "../bridge/resolveDataSourceQuery.js"
|
|
4
4
|
import type { UseDataSourceOptions, UseDataSourceResult } from "../types.js"
|
|
5
5
|
|
|
6
6
|
const EMPTY_DATA_SOURCE_RESULT: UseDataSourceResult = {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CustomBlockDataSourceResolutionErrorInfo } from "@notionhq/custom-blocks-protocol/dataSources/errors.js"
|
|
2
|
+
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
3
|
+
import type { NotionDataSourceId } from "@notionhq/custom-blocks-protocol/utils/ids.js"
|
|
4
|
+
import type { CustomBlockHostState } from "../context/hostState.js"
|
|
5
|
+
import { dataSourceInaccessibleError } from "./dataSourceInaccessibleError.js"
|
|
6
|
+
|
|
7
|
+
export function resolvePageDataSource(args: {
|
|
8
|
+
hostState: CustomBlockHostState
|
|
9
|
+
key: string
|
|
10
|
+
}):
|
|
11
|
+
| {
|
|
12
|
+
status: "success"
|
|
13
|
+
dataSource: NotionDataSource
|
|
14
|
+
dataSourceId: NotionDataSourceId
|
|
15
|
+
}
|
|
16
|
+
| { status: "error"; error: CustomBlockDataSourceResolutionErrorInfo } {
|
|
17
|
+
const { hostState, key } = args
|
|
18
|
+
if (hostState.status !== "initialized") {
|
|
19
|
+
return {
|
|
20
|
+
status: "error",
|
|
21
|
+
error: {
|
|
22
|
+
code: "unknown_data_source_key",
|
|
23
|
+
message: `Cannot resolve data source key "${key}" before the host has initialized the SDK.`,
|
|
24
|
+
isRetryable: false,
|
|
25
|
+
},
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const dataSource = hostState.dataSources.find(source => source.key === key)
|
|
29
|
+
if (dataSource === undefined) {
|
|
30
|
+
return {
|
|
31
|
+
status: "error",
|
|
32
|
+
error: {
|
|
33
|
+
code: "unknown_data_source_key",
|
|
34
|
+
message: `Unknown data source key "${key}". Known keys: [${hostState.dataSources.map(source => source.key).join(", ")}].`,
|
|
35
|
+
isRetryable: false,
|
|
36
|
+
},
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (dataSource.inaccessible === true) {
|
|
40
|
+
return { status: "error", error: dataSourceInaccessibleError(key) }
|
|
41
|
+
}
|
|
42
|
+
if (dataSource.collectionPointer === undefined) {
|
|
43
|
+
return {
|
|
44
|
+
status: "error",
|
|
45
|
+
error: {
|
|
46
|
+
code: "unmapped_data_source",
|
|
47
|
+
message: `Data source "${key}" has not been mapped to a database yet.`,
|
|
48
|
+
isRetryable: false,
|
|
49
|
+
},
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
status: "success",
|
|
54
|
+
dataSource,
|
|
55
|
+
dataSourceId: dataSource.collectionPointer.id,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CustomBlockQueryDataSourceErrorInfo,
|
|
3
|
+
QueryDataSourceResultMessage,
|
|
4
|
+
} from "@notionhq/custom-blocks-protocol/dataSources/messages/queryDataSource.js"
|
|
5
|
+
import type { NotionDataSource } from "@notionhq/custom-blocks-protocol/dataSources/notionDataSource.js"
|
|
6
|
+
import { getBridge } from "../bridge/getBridge.js"
|
|
7
|
+
import { makeNotionPage } from "../pages/makeNotionPage.js"
|
|
8
|
+
import { notifyListener } from "../utils/notifyListener.js"
|
|
9
|
+
import { resolveDataSourceQuery } from "./bridge/resolveDataSourceQuery.js"
|
|
10
|
+
import type { SubscribeToDataSourceArgs } from "./types.js"
|
|
11
|
+
|
|
12
|
+
export function subscribeToDataSource(
|
|
13
|
+
args: SubscribeToDataSourceArgs,
|
|
14
|
+
): () => void
|
|
15
|
+
/** @deprecated Pass onError in the first argument instead. */
|
|
16
|
+
export function subscribeToDataSource(
|
|
17
|
+
args: SubscribeToDataSourceArgs,
|
|
18
|
+
onError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
|
|
19
|
+
): () => void
|
|
20
|
+
export function subscribeToDataSource(
|
|
21
|
+
{
|
|
22
|
+
key,
|
|
23
|
+
onSnapshot,
|
|
24
|
+
onError: providedOnError,
|
|
25
|
+
options: providedOptions = {},
|
|
26
|
+
}: SubscribeToDataSourceArgs,
|
|
27
|
+
legacyOnError?: (error: CustomBlockQueryDataSourceErrorInfo) => void,
|
|
28
|
+
): () => void {
|
|
29
|
+
const onError = providedOnError ?? legacyOnError
|
|
30
|
+
const options = structuredClone(providedOptions)
|
|
31
|
+
const bridge = getBridge()
|
|
32
|
+
const subscriptionId = `data-source:${globalThis.crypto.randomUUID()}`
|
|
33
|
+
let active = true
|
|
34
|
+
let dataSource: NotionDataSource | undefined
|
|
35
|
+
let result: QueryDataSourceResultMessage | undefined
|
|
36
|
+
let bindingSignature: string | null | undefined
|
|
37
|
+
|
|
38
|
+
const deliverSnapshot = (isLoading: boolean) => {
|
|
39
|
+
const source = dataSource
|
|
40
|
+
const snapshot = {
|
|
41
|
+
items:
|
|
42
|
+
result?.status === "success" && source !== undefined
|
|
43
|
+
? result.items.map(bridgePage =>
|
|
44
|
+
makeNotionPage({ bridgePage, dataSource: source, bridge }),
|
|
45
|
+
)
|
|
46
|
+
: [],
|
|
47
|
+
propertyIdsByKey: source?.propertyIdsByKey ?? {},
|
|
48
|
+
isLoading,
|
|
49
|
+
hasMore: result?.status === "success" && result.hasMore,
|
|
50
|
+
}
|
|
51
|
+
notifyListener(() => onSnapshot(snapshot))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const deliverError = (error: CustomBlockQueryDataSourceErrorInfo) => {
|
|
55
|
+
if (onError !== undefined) {
|
|
56
|
+
notifyListener(() => onError(error))
|
|
57
|
+
} else {
|
|
58
|
+
deliverSnapshot(false)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const handleHostChange = () => {
|
|
63
|
+
if (!active) {
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
const hostState = bridge.getHostState()
|
|
67
|
+
if (hostState.status !== "initialized") {
|
|
68
|
+
deliverSnapshot(false)
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const nextSource = hostState.dataSources.find(source => source.key === key)
|
|
73
|
+
// Context updates and unchanged bindings preserve object identity. Skip
|
|
74
|
+
// after initial validation if the object has not changed.
|
|
75
|
+
if (bindingSignature !== undefined && nextSource === dataSource) {
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
const signature =
|
|
79
|
+
nextSource === undefined ? null : JSON.stringify(nextSource)
|
|
80
|
+
if (signature === bindingSignature) {
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
const backingSourceChanged =
|
|
84
|
+
bindingSignature !== undefined &&
|
|
85
|
+
dataSource?.collectionPointer?.id !== nextSource?.collectionPointer?.id
|
|
86
|
+
bindingSignature = signature
|
|
87
|
+
dataSource = nextSource
|
|
88
|
+
if (backingSourceChanged) {
|
|
89
|
+
result = undefined
|
|
90
|
+
}
|
|
91
|
+
const resolved = resolveDataSourceQuery({
|
|
92
|
+
dataSources: hostState.dataSources,
|
|
93
|
+
key,
|
|
94
|
+
options,
|
|
95
|
+
})
|
|
96
|
+
if (resolved.status === "error") {
|
|
97
|
+
// A new backing source must clear previously delivered rows even when validation fails.
|
|
98
|
+
if (backingSourceChanged && onError !== undefined) {
|
|
99
|
+
deliverSnapshot(false)
|
|
100
|
+
}
|
|
101
|
+
deliverError(resolved.error)
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
bridge.postToHost({
|
|
105
|
+
type: "queryDataSource",
|
|
106
|
+
subscriptionId,
|
|
107
|
+
...resolved.query,
|
|
108
|
+
})
|
|
109
|
+
deliverSnapshot(true)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const unsubscribeResults = bridge.subscribeToDataSourceQueryResults(
|
|
113
|
+
subscriptionId,
|
|
114
|
+
message => {
|
|
115
|
+
result = message
|
|
116
|
+
if (message.status === "error") {
|
|
117
|
+
deliverError(message.error)
|
|
118
|
+
} else {
|
|
119
|
+
deliverSnapshot(false)
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
const unsubscribeHost = bridge.subscribe(handleHostChange)
|
|
124
|
+
try {
|
|
125
|
+
handleHostChange()
|
|
126
|
+
} catch (error) {
|
|
127
|
+
unsubscribe()
|
|
128
|
+
throw error
|
|
129
|
+
}
|
|
130
|
+
return unsubscribe
|
|
131
|
+
|
|
132
|
+
function unsubscribe() {
|
|
133
|
+
if (!active) {
|
|
134
|
+
return
|
|
135
|
+
}
|
|
136
|
+
active = false
|
|
137
|
+
unsubscribeHost()
|
|
138
|
+
unsubscribeResults()
|
|
139
|
+
if (bindingSignature !== undefined) {
|
|
140
|
+
bridge.postToHost({ type: "unsubscribeDataSourceQuery", subscriptionId })
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|