@blocknote/core 0.51.4 → 0.52.0
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/dist/BlockNoteExtension-B_IEJHS8.js +38 -0
- package/dist/BlockNoteExtension-B_IEJHS8.js.map +1 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs +2 -0
- package/dist/BlockNoteExtension-M0znTzxP.cjs.map +1 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs +2 -0
- package/dist/ThreadStore-Bx-gSEh1.cjs.map +1 -0
- package/dist/ThreadStore-et9wB5Xt.js +11 -0
- package/dist/ThreadStore-et9wB5Xt.js.map +1 -0
- package/dist/UserStore-DCG6lsla.cjs +2 -0
- package/dist/UserStore-DCG6lsla.cjs.map +1 -0
- package/dist/UserStore-QbbPFj0z.js +73 -0
- package/dist/UserStore-QbbPFj0z.js.map +1 -0
- package/dist/blocknote.cjs +1 -1
- package/dist/blocknote.js +6 -7
- package/dist/blocks-BqHv0xhc.cjs +12 -0
- package/dist/blocks-BqHv0xhc.cjs.map +1 -0
- package/dist/{blocks-DGsP5WKr.js → blocks-CiuUGa1E.js} +1093 -994
- package/dist/blocks-CiuUGa1E.js.map +1 -0
- package/dist/blocks.cjs +1 -1
- package/dist/blocks.js +2 -2
- package/dist/comments.cjs +1 -1
- package/dist/comments.cjs.map +1 -1
- package/dist/comments.js +75 -340
- package/dist/comments.js.map +1 -1
- package/dist/{en-Cj5r8sW_.cjs → en-C5Z4Ag9_.cjs} +2 -2
- package/dist/en-C5Z4Ag9_.cjs.map +1 -0
- package/dist/{en-B9hMApn4.js → en-CGKXfWma.js} +9 -1
- package/dist/en-CGKXfWma.js.map +1 -0
- package/dist/{extensions-Co4y7P63.js → extensions-CrUGDOks.js} +655 -583
- package/dist/extensions-CrUGDOks.js.map +1 -0
- package/dist/extensions-Ghr9QqqR.cjs +52 -0
- package/dist/extensions-Ghr9QqqR.cjs.map +1 -0
- package/dist/extensions.cjs +1 -1
- package/dist/extensions.js +4 -4
- package/dist/locales.cjs +1 -1
- package/dist/locales.cjs.map +1 -1
- package/dist/locales.js +177 -1
- package/dist/locales.js.map +1 -1
- package/dist/{src-Bcud0PIg.js → src-DTF83Cl9.js} +1243 -1297
- package/dist/src-DTF83Cl9.js.map +1 -0
- package/dist/src-OfbaVbMw.cjs +21 -0
- package/dist/src-OfbaVbMw.cjs.map +1 -0
- package/dist/style.css +1 -1
- package/dist/webpack-stats.json +1 -1
- package/dist/y.cjs +2 -0
- package/dist/y.cjs.map +1 -0
- package/dist/y.js +989 -0
- package/dist/y.js.map +1 -0
- package/dist/yjs.cjs +1 -1
- package/dist/yjs.cjs.map +1 -1
- package/dist/yjs.js +535 -14
- package/dist/yjs.js.map +1 -1
- package/package.json +46 -19
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/insertBlocks/insertBlocks.ts +1 -1
- package/src/api/blockManipulation/commands/mergeBlocks/mergeBlocks.test.ts +3 -3
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.test.ts +25 -20
- package/src/api/blockManipulation/commands/moveBlocks/moveBlocks.ts +39 -29
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.test.ts +2 -2
- package/src/api/blockManipulation/commands/nestBlock/nestBlock.ts +4 -8
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.test.ts +1 -1
- package/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.ts +21 -9
- package/src/api/blockManipulation/commands/splitBlock/splitBlock.test.ts +6 -5
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.test.ts +362 -4
- package/src/api/blockManipulation/commands/updateBlock/updateBlock.ts +240 -30
- package/src/api/blockManipulation/getBlock/getBlock.ts +4 -9
- package/src/api/blockManipulation/selections/selection.ts +3 -6
- package/src/api/blockManipulation/selections/textCursorPosition.ts +10 -10
- package/src/api/blockManipulation/setupTestEnv.ts +1 -1
- package/src/api/blockManipulation/tables/tables.test.ts +1 -1
- package/src/api/clipboard/fromClipboard/fileDropExtension.ts +1 -1
- package/src/api/clipboard/fromClipboard/handleFileInsertion.ts +8 -4
- package/src/api/clipboard/fromClipboard/pasteExtension.ts +1 -1
- package/src/api/exporters/html/util/serializeBlocksExternalHTML.ts +2 -1
- package/src/api/exporters/markdown/htmlToMarkdown.ts +79 -43
- package/src/api/getBlockInfoFromPos.test.ts +256 -0
- package/src/api/getBlockInfoFromPos.ts +53 -15
- package/src/api/getBlocksChangedByTransaction.test.ts +2 -1
- package/src/api/getBlocksChangedByTransaction.ts +6 -6
- package/src/api/nodeConversions/blockToNode.test.ts +113 -0
- package/src/api/nodeConversions/blockToNode.ts +15 -3
- package/src/api/nodeConversions/fragmentToBlocks.ts +2 -4
- package/src/api/nodeConversions/nodeToBlock.ts +28 -58
- package/src/api/nodeUtil.ts +6 -2
- package/src/api/parsers/html/parseHTML.ts +1 -1
- package/src/api/parsers/html/util/nestedLists.test.ts +1 -1
- package/src/api/parsers/markdown/detectMarkdown.test.ts +1 -1
- package/src/api/parsers/markdown/markdownToHtml.ts +228 -82
- package/src/api/pmUtil.ts +18 -1
- package/src/api/positionMapping.test.ts +20 -345
- package/src/api/positionMapping.ts +13 -83
- package/src/blocks/Audio/block.ts +1 -1
- package/src/blocks/Code/block.test.ts +14 -7
- package/src/blocks/Code/block.ts +2 -2
- package/src/blocks/Image/block.ts +1 -1
- package/src/blocks/ListItem/CheckListItem/block.test.ts +1 -1
- package/src/blocks/ListItem/ListItemKeyboardShortcuts.ts +2 -2
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts +4 -11
- package/src/blocks/ListItem/NumberedListItem/IndexingPlugin.ts +47 -50
- package/src/blocks/Table/TableExtension.test.ts +9 -6
- package/src/blocks/Table/TableExtension.ts +20 -6
- package/src/blocks/Table/block.ts +18 -5
- package/src/blocks/Video/block.ts +1 -1
- package/src/blocks/utils/listItemEnterHandler.ts +3 -2
- package/src/comments/extension.ts +30 -21
- package/src/comments/index.ts +0 -3
- package/src/comments/mark.ts +4 -0
- package/src/comments/threadstore/ThreadStore.ts +4 -8
- package/src/comments/types.ts +0 -8
- package/src/editor/Block.css +307 -3
- package/src/editor/BlockNoteEditor.test.ts +21 -18
- package/src/editor/BlockNoteEditor.ts +22 -57
- package/src/editor/BlockNoteExtension.test.ts +1 -1
- package/src/editor/managers/BlockManager.ts +1 -1
- package/src/editor/managers/ExtensionManager/ExtensionManager.test.ts +249 -0
- package/src/editor/managers/ExtensionManager/extensions.ts +7 -18
- package/src/editor/managers/ExtensionManager/index.ts +168 -68
- package/src/editor/managers/StateManager.ts +4 -3
- package/src/editor/performance.test.ts +14 -1
- package/src/editor/transformPasted.test.ts +1 -1
- package/src/extensions/Placeholder/Placeholder.ts +1 -0
- package/src/extensions/PositionMapping/PositionMapping.ts +68 -0
- package/src/extensions/PreviousBlockType/PreviousBlockType.test.ts +14 -1
- package/src/extensions/PreviousBlockType/PreviousBlockType.ts +14 -11
- package/src/extensions/SideMenu/SideMenu.ts +9 -2
- package/src/extensions/SuggestionMenu/SuggestionMenu.test.ts +1 -1
- package/src/extensions/TableHandles/TableHandles.ts +18 -20
- package/src/extensions/TrailingNode/TrailingNode.ts +33 -1
- package/src/extensions/Versioning/Versioning.test.ts +435 -0
- package/src/extensions/Versioning/Versioning.ts +628 -0
- package/src/extensions/Versioning/inMemoryVersioning.test.ts +469 -0
- package/src/extensions/Versioning/inMemoryVersioning.ts +263 -0
- package/src/extensions/Versioning/index.ts +2 -0
- package/src/extensions/index.ts +6 -9
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.ts +155 -0
- package/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.ts +6 -8
- package/src/extensions/tiptap-extensions/Link/helpers/autolink.ts +9 -9
- package/src/extensions/tiptap-extensions/Link/helpers/linkDetector.ts +8 -10
- package/src/extensions/tiptap-extensions/Link/helpers/whitespace.ts +2 -2
- package/src/extensions/tiptap-extensions/Link/link.test.ts +26 -22
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.ts +187 -0
- package/src/extensions/tiptap-extensions/UniqueID/UniqueID.ts +37 -24
- package/src/extensions/tiptap-extensions/index.ts +1 -25
- package/src/i18n/locales/ar.ts +9 -0
- package/src/i18n/locales/de.ts +9 -0
- package/src/i18n/locales/en.ts +10 -1
- package/src/i18n/locales/es.ts +9 -0
- package/src/i18n/locales/fa.ts +11 -1
- package/src/i18n/locales/fr.ts +9 -0
- package/src/i18n/locales/he.ts +10 -1
- package/src/i18n/locales/hr.ts +10 -0
- package/src/i18n/locales/is.ts +10 -0
- package/src/i18n/locales/it.ts +9 -0
- package/src/i18n/locales/ja.ts +9 -0
- package/src/i18n/locales/ko.ts +9 -0
- package/src/i18n/locales/nl.ts +10 -0
- package/src/i18n/locales/no.ts +10 -0
- package/src/i18n/locales/pl.ts +9 -0
- package/src/i18n/locales/pt.ts +10 -0
- package/src/i18n/locales/ru.ts +10 -0
- package/src/i18n/locales/sk.ts +10 -1
- package/src/i18n/locales/uk.ts +9 -0
- package/src/i18n/locales/uz.ts +9 -0
- package/src/i18n/locales/vi.ts +9 -0
- package/src/i18n/locales/zh-tw.ts +9 -0
- package/src/i18n/locales/zh.ts +9 -0
- package/src/index.ts +2 -0
- package/src/pm-nodes/BlockContainer.ts +4 -1
- package/src/pm-nodes/BlockGroup.ts +4 -1
- package/src/pm-nodes/Doc.ts +4 -1
- package/src/pm-nodes/suggestionMarks.ts +43 -0
- package/src/schema/blocks/createSpec.test.ts +123 -0
- package/src/schema/blocks/createSpec.ts +82 -24
- package/src/schema/blocks/extendBlockSpec.test.ts +188 -0
- package/src/schema/blocks/internal.ts +13 -43
- package/src/schema/blocks/types.ts +69 -22
- package/src/schema/contentTypePropagation.test.ts +182 -0
- package/src/schema/index.ts +1 -0
- package/src/schema/inlineContent/internal.ts +1 -1
- package/src/schema/inlineContent/types.ts +3 -3
- package/src/schema/markGroups.ts +50 -0
- package/src/user/UserStore.ts +199 -0
- package/src/user/createUserStore.test.ts +126 -0
- package/src/user/index.ts +2 -0
- package/src/user/userColors.ts +72 -0
- package/src/util/string.ts +1 -1
- package/src/util/topo-sort.test.ts +1 -1
- package/src/util/typescript.ts +2 -1
- package/src/vite-env.d.ts +1 -1
- package/src/y/README.md +5 -0
- package/src/{comments/threadstore/yjs → y/comments}/RESTYjsThreadStore.ts +8 -14
- package/src/y/comments/YjsThreadStore.test.ts +295 -0
- package/src/y/comments/YjsThreadStore.ts +358 -0
- package/src/y/comments/YjsThreadStoreBase.ts +50 -0
- package/src/y/comments/index.ts +3 -0
- package/src/y/comments/yjsHelpers.ts +125 -0
- package/src/y/extensions/AttributionExtension.test.ts +86 -0
- package/src/y/extensions/AttributionExtension.ts +378 -0
- package/src/y/extensions/DiffVersioningExtension.test.ts +193 -0
- package/src/y/extensions/DiffVersioningExtension.ts +228 -0
- package/src/y/extensions/ForkYDoc.test.ts +253 -0
- package/src/y/extensions/ForkYDoc.ts +108 -0
- package/src/y/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/y/extensions/RelativePositionMapping.ts +49 -0
- package/src/y/extensions/Suggestions.ts +174 -0
- package/src/y/extensions/Versioning.test.ts +395 -0
- package/src/y/extensions/Versioning.ts +115 -0
- package/src/y/extensions/YAttributionMarks.ts +320 -0
- package/src/{extensions/Collaboration → y/extensions}/YCursorPlugin.ts +15 -7
- package/src/y/extensions/YSync.ts +125 -0
- package/src/y/extensions/blockMatchNodes.ts +182 -0
- package/src/y/extensions/index.ts +156 -0
- package/src/y/index.ts +4 -0
- package/src/y/utils.test.ts +1042 -0
- package/src/y/utils.ts +242 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all-after.json +50 -0
- package/src/y/versioning/__test__/fixtures/activity-all.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-all.json +20 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.bin +0 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-after.json +32 -0
- package/src/y/versioning/__test__/fixtures/activity-filtered-before.json +1 -0
- package/src/y/versioning/__test__/fixtures/changeset.bin +0 -0
- package/src/y/versioning/__test__/fixtures/patch-response.json +4 -0
- package/src/y/versioning/__test__/yhub.test.ts +752 -0
- package/src/y/versioning/index.ts +1 -0
- package/src/y/versioning/yhub.ts +631 -0
- package/src/yjs/README.md +5 -0
- package/src/yjs/comments/RESTYjsThreadStore.ts +166 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.test.ts +3 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.ts +7 -3
- package/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.ts +3 -3
- package/src/yjs/comments/index.ts +3 -0
- package/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.ts +5 -1
- package/src/yjs/extensions/FixUpSchema.test.ts +421 -0
- package/src/yjs/extensions/FixUpSchema.ts +88 -0
- package/src/yjs/extensions/ForkYDoc.test.ts +216 -0
- package/src/{extensions/Collaboration → yjs/extensions}/ForkYDoc.ts +38 -57
- package/src/yjs/extensions/RelativePositionMapping.test.ts +418 -0
- package/src/yjs/extensions/RelativePositionMapping.ts +71 -0
- package/src/yjs/extensions/Versioning.test.ts +549 -0
- package/src/yjs/extensions/Versioning.ts +83 -0
- package/src/yjs/extensions/YCursorPlugin.ts +201 -0
- package/src/{extensions/Collaboration → yjs/extensions}/YSync.ts +1 -1
- package/src/yjs/extensions/index.ts +89 -0
- package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.test.ts +1 -1
- package/src/yjs/index.ts +2 -0
- package/src/yjs/utils.test.ts +5 -15
- package/src/yjs/utils.ts +36 -0
- package/types/src/api/blockManipulation/commands/replaceBlocks/replaceBlocks.d.ts +3 -1
- package/types/src/api/blockManipulation/selections/selection.d.ts +1 -1
- package/types/src/api/getBlockInfoFromPos.d.ts +5 -9
- package/types/src/api/nodeConversions/nodeToBlock.d.ts +4 -6
- package/types/src/api/pmUtil.d.ts +12 -1
- package/types/src/blocks/Audio/block.d.ts +2 -2
- package/types/src/blocks/Code/block.d.ts +2 -2
- package/types/src/blocks/File/block.d.ts +2 -2
- package/types/src/blocks/Heading/block.d.ts +21 -21
- package/types/src/blocks/Image/block.d.ts +3 -3
- package/types/src/blocks/ListItem/CheckListItem/block.d.ts +6 -6
- package/types/src/blocks/ListItem/NumberedListItem/block.d.ts +6 -6
- package/types/src/blocks/Video/block.d.ts +3 -3
- package/types/src/blocks/defaultBlocks.d.ts +17 -17
- package/types/src/comments/extension.d.ts +18 -5
- package/types/src/comments/index.d.ts +0 -3
- package/types/src/comments/threadstore/ThreadStore.d.ts +4 -8
- package/types/src/comments/types.d.ts +0 -8
- package/types/src/editor/BlockNoteEditor.d.ts +8 -9
- package/types/src/editor/managers/BlockManager.d.ts +1 -1
- package/types/src/editor/managers/ExtensionManager/extensions.d.ts +2 -2
- package/types/src/editor/managers/ExtensionManager/index.d.ts +13 -0
- package/types/src/editor/managers/SelectionManager.d.ts +1 -1
- package/types/src/extensions/PositionMapping/PositionMapping.d.ts +4 -0
- package/types/src/extensions/TableHandles/TableHandles.d.ts +6 -6
- package/types/src/extensions/Versioning/Versioning.d.ts +352 -0
- package/types/src/extensions/Versioning/Versioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.d.ts +37 -0
- package/types/src/extensions/Versioning/inMemoryVersioning.test.d.ts +1 -0
- package/types/src/extensions/Versioning/index.d.ts +2 -0
- package/types/src/extensions/index.d.ts +6 -9
- package/types/src/extensions/tiptap-extensions/KeyboardShortcuts/KeyboardShortcutsExtension.test.d.ts +1 -0
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.d.ts +6 -1
- package/types/src/extensions/tiptap-extensions/UniqueID/UniqueID.test.d.ts +4 -0
- package/types/src/extensions/tiptap-extensions/index.d.ts +1 -5
- package/types/src/i18n/locales/en.d.ts +9 -1
- package/types/src/i18n/locales/fa.d.ts +9 -1
- package/types/src/i18n/locales/sk.d.ts +9 -1
- package/types/src/index.d.ts +2 -0
- package/types/src/pm-nodes/suggestionMarks.d.ts +26 -0
- package/types/src/schema/blocks/createSpec.d.ts +4 -4
- package/types/src/schema/blocks/createSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/extendBlockSpec.test.d.ts +1 -0
- package/types/src/schema/blocks/internal.d.ts +5 -7
- package/types/src/schema/blocks/types.d.ts +22 -14
- package/types/src/schema/contentTypePropagation.test.d.ts +1 -0
- package/types/src/schema/index.d.ts +1 -0
- package/types/src/schema/inlineContent/types.d.ts +3 -3
- package/types/src/schema/markGroups.d.ts +33 -0
- package/types/src/user/UserStore.d.ts +105 -0
- package/types/src/user/createUserStore.test.d.ts +1 -0
- package/types/src/user/index.d.ts +2 -0
- package/types/src/user/userColors.d.ts +36 -0
- package/types/src/y/comments/RESTYjsThreadStore.d.ts +77 -0
- package/types/src/y/comments/YjsThreadStore.d.ts +79 -0
- package/types/src/y/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/y/comments/YjsThreadStoreBase.d.ts +15 -0
- package/types/src/y/comments/index.d.ts +3 -0
- package/types/src/y/comments/yjsHelpers.d.ts +13 -0
- package/types/src/y/extensions/AttributionExtension.d.ts +74 -0
- package/types/src/y/extensions/AttributionExtension.test.d.ts +1 -0
- package/types/src/y/extensions/DiffVersioningExtension.d.ts +69 -0
- package/types/src/y/extensions/DiffVersioningExtension.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → y/extensions}/ForkYDoc.d.ts +4 -2
- package/types/src/y/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/y/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/y/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/y/extensions/Suggestions.d.ts +36 -0
- package/types/src/y/extensions/Versioning.d.ts +17 -0
- package/types/src/y/extensions/Versioning.test.d.ts +1 -0
- package/types/src/y/extensions/YAttributionMarks.d.ts +67 -0
- package/types/src/y/extensions/YCursorPlugin.d.ts +14 -0
- package/types/src/y/extensions/YSync.d.ts +32 -0
- package/types/src/y/extensions/blockMatchNodes.d.ts +25 -0
- package/types/src/y/extensions/index.d.ts +189 -0
- package/types/src/y/index.d.ts +4 -0
- package/types/src/y/utils.d.ts +82 -0
- package/types/src/y/utils.test.d.ts +1 -0
- package/types/src/y/versioning/__test__/yhub.test.d.ts +1 -0
- package/types/src/y/versioning/index.d.ts +1 -0
- package/types/src/y/versioning/yhub.d.ts +87 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/RESTYjsThreadStore.d.ts +6 -10
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStore.d.ts +3 -3
- package/types/src/yjs/comments/YjsThreadStore.test.d.ts +1 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/YjsThreadStoreBase.d.ts +3 -3
- package/types/src/yjs/comments/index.d.ts +3 -0
- package/types/src/{comments/threadstore/yjs → yjs/comments}/yjsHelpers.d.ts +1 -1
- package/types/src/yjs/extensions/FixUpSchema.d.ts +3 -0
- package/types/src/yjs/extensions/FixUpSchema.test.d.ts +1 -0
- package/types/src/yjs/extensions/ForkYDoc.d.ts +27 -0
- package/types/src/yjs/extensions/ForkYDoc.test.d.ts +1 -0
- package/types/src/yjs/extensions/RelativePositionMapping.d.ts +4 -0
- package/types/src/yjs/extensions/RelativePositionMapping.test.d.ts +1 -0
- package/types/src/yjs/extensions/Versioning.d.ts +26 -0
- package/types/src/yjs/extensions/Versioning.test.d.ts +1 -0
- package/types/src/{extensions/Collaboration → yjs/extensions}/YCursorPlugin.d.ts +5 -2
- package/types/src/{extensions/Collaboration → yjs/extensions}/YSync.d.ts +1 -1
- package/types/src/{extensions/Collaboration/Collaboration.d.ts → yjs/extensions/index.d.ts} +36 -15
- package/types/src/yjs/extensions/schemaMigration/migrationRules/moveColorAttributes.test.d.ts +1 -0
- package/types/src/yjs/index.d.ts +2 -0
- package/types/src/yjs/utils.d.ts +5 -0
- package/dist/BlockNoteExtension-B6RhuQ3V.js +0 -27
- package/dist/BlockNoteExtension-B6RhuQ3V.js.map +0 -1
- package/dist/BlockNoteExtension-ab0REuob.cjs +0 -2
- package/dist/BlockNoteExtension-ab0REuob.cjs.map +0 -1
- package/dist/EventEmitter-CuPnGDYt.js +0 -22
- package/dist/EventEmitter-CuPnGDYt.js.map +0 -1
- package/dist/EventEmitter-DHdSnYCD.cjs +0 -2
- package/dist/EventEmitter-DHdSnYCD.cjs.map +0 -1
- package/dist/ShowSelection-BsHFfdMi.js +0 -29
- package/dist/ShowSelection-BsHFfdMi.js.map +0 -1
- package/dist/ShowSelection-DhXglbt8.cjs +0 -2
- package/dist/ShowSelection-DhXglbt8.cjs.map +0 -1
- package/dist/blocks-Bm6IfL1R.cjs +0 -11
- package/dist/blocks-Bm6IfL1R.cjs.map +0 -1
- package/dist/blocks-DGsP5WKr.js.map +0 -1
- package/dist/en-B9hMApn4.js.map +0 -1
- package/dist/en-Cj5r8sW_.cjs.map +0 -1
- package/dist/extensions-Co4y7P63.js.map +0 -1
- package/dist/extensions-IJK3t0sz.cjs +0 -52
- package/dist/extensions-IJK3t0sz.cjs.map +0 -1
- package/dist/src-B6rlChSc.cjs +0 -21
- package/dist/src-B6rlChSc.cjs.map +0 -1
- package/dist/src-Bcud0PIg.js.map +0 -1
- package/src/comments/userstore/UserStore.ts +0 -72
- package/src/extensions/Collaboration/Collaboration.ts +0 -55
- package/src/extensions/Collaboration/ForkYDoc.test.ts +0 -179
- package/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.ts +0 -175
- package/types/src/comments/userstore/UserStore.d.ts +0 -31
- package/types/src/extensions/tiptap-extensions/Suggestions/SuggestionMarks.d.ts +0 -4
- /package/src/{extensions/Collaboration → yjs/extensions}/YUndo.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor-forked.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-editor.json +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap-forked.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/__snapshots__/fork-yjs-snap.html +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.ts +0 -0
- /package/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.ts +0 -0
- /package/types/src/{comments/threadstore/yjs/YjsThreadStore.test.d.ts → api/getBlockInfoFromPos.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/ForkYDoc.test.d.ts → api/nodeConversions/blockToNode.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration/schemaMigration/migrationRules/moveColorAttributes.test.d.ts → editor/managers/ExtensionManager/ExtensionManager.test.d.ts} +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/YUndo.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/SchemaMigration.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/index.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/migrationRule.d.ts +0 -0
- /package/types/src/{extensions/Collaboration → yjs/extensions}/schemaMigration/migrationRules/moveColorAttributes.d.ts +0 -0
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
import {
|
|
2
|
+
afterEach,
|
|
3
|
+
beforeEach,
|
|
4
|
+
describe,
|
|
5
|
+
expect,
|
|
6
|
+
it,
|
|
7
|
+
vi,
|
|
8
|
+
} from "vite-plus/test";
|
|
9
|
+
import { encodeAny } from "lib0/buffer";
|
|
10
|
+
import * as Y from "@y/y";
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
CURRENT_VERSION_ID,
|
|
14
|
+
type VersionSnapshot,
|
|
15
|
+
} from "../../../extensions/Versioning/index.js";
|
|
16
|
+
import { createYHubVersioningEndpoints } from "../yhub.js";
|
|
17
|
+
import { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
|
|
18
|
+
import { createExtension } from "../../../editor/BlockNoteExtension.js";
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Fixture data — version entries now carry an `id` custom attribution (UUID).
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
const VERSION_ENTRY_1 = {
|
|
25
|
+
from: 1782218082853,
|
|
26
|
+
to: 1782218082853,
|
|
27
|
+
by: "user-1",
|
|
28
|
+
customAttributions: [
|
|
29
|
+
{ k: "type", v: "version" },
|
|
30
|
+
{ k: "id", v: "uuid-version-1" },
|
|
31
|
+
{ k: "name", v: "Test Version 1" },
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const VERSION_ENTRY_2 = {
|
|
36
|
+
from: 1782218211312,
|
|
37
|
+
to: 1782218211312,
|
|
38
|
+
by: "user-2, user-3",
|
|
39
|
+
customAttributions: [
|
|
40
|
+
{ k: "type", v: "version" },
|
|
41
|
+
{ k: "id", v: "uuid-version-2" },
|
|
42
|
+
{ k: "name", v: "Test Version 2" },
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// Snapshots as produced by `list()` (see `activityToSnapshot`): the activity
|
|
47
|
+
// entry's `to` timestamp becomes both `createdAt` and `updatedAt`. The
|
|
48
|
+
// changeset/rollback APIs are now driven by these timestamps directly, so the
|
|
49
|
+
// endpoints no longer make an activity lookup to resolve them. The entry's
|
|
50
|
+
// comma-separated `by` user-ids are split into the snapshot's raw `by` array.
|
|
51
|
+
const SNAPSHOT_1: VersionSnapshot = {
|
|
52
|
+
id: "uuid-version-1",
|
|
53
|
+
name: "Test Version 1",
|
|
54
|
+
createdAt: VERSION_ENTRY_1.to,
|
|
55
|
+
updatedAt: VERSION_ENTRY_1.to,
|
|
56
|
+
by: ["user-1"],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const SNAPSHOT_2: VersionSnapshot = {
|
|
60
|
+
id: "uuid-version-2",
|
|
61
|
+
name: "Test Version 2",
|
|
62
|
+
createdAt: VERSION_ENTRY_2.to,
|
|
63
|
+
updatedAt: VERSION_ENTRY_2.to,
|
|
64
|
+
by: ["user-2", "user-3"],
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const PATCH_RESPONSE = { success: true, message: "Document updated" };
|
|
68
|
+
|
|
69
|
+
function makeChangeset(
|
|
70
|
+
opts: { nextDoc?: boolean; attributions?: boolean } = {},
|
|
71
|
+
) {
|
|
72
|
+
const doc = new Y.Doc();
|
|
73
|
+
const frag = doc.get("default", "XmlFragment");
|
|
74
|
+
frag.insert(0, ["hello"]);
|
|
75
|
+
return {
|
|
76
|
+
prevDoc: Y.encodeStateAsUpdate(new Y.Doc()),
|
|
77
|
+
...(opts.nextDoc !== false ? { nextDoc: Y.encodeStateAsUpdate(doc) } : {}),
|
|
78
|
+
...(opts.attributions ? { attributions: new Uint8Array([0]) } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// Helpers
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
const BASE_URL = "https://yhub.test";
|
|
87
|
+
const ORG = "test-org";
|
|
88
|
+
const DOC_ID = "test-doc";
|
|
89
|
+
|
|
90
|
+
// The factory returns a callback that receives the editor instance (used to
|
|
91
|
+
// stamp `create`d snapshots with the current cursor user's id). Author ids are
|
|
92
|
+
// passed through raw on `VersionSnapshot.by` — resolving them to user info is
|
|
93
|
+
// the view layer's job, not the endpoints'. These tests create a bare editor
|
|
94
|
+
// with no collaboration extensions, so `create` gets no author id.
|
|
95
|
+
function makeEndpoints() {
|
|
96
|
+
const editor = BlockNoteEditor.create();
|
|
97
|
+
return createYHubVersioningEndpoints({
|
|
98
|
+
baseUrl: BASE_URL,
|
|
99
|
+
org: ORG,
|
|
100
|
+
docId: DOC_ID,
|
|
101
|
+
activityLimit: 50,
|
|
102
|
+
})(editor);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// A lightweight stand-in for the real `ySync` extension. `getVersionNamesMap`
|
|
106
|
+
// in yhub.ts reads the live collaboration doc exclusively via
|
|
107
|
+
// `editor.getExtension("ySync")?.fragment.doc`, so a stub that just exposes the
|
|
108
|
+
// fragment is enough to exercise the mutable `__bn_version_names` name store
|
|
109
|
+
// without wiring up the full collaboration/prosemirror sync machinery.
|
|
110
|
+
const ySyncStub = (fragment: Y.Type) =>
|
|
111
|
+
createExtension({ key: "ySync", fragment } as any);
|
|
112
|
+
|
|
113
|
+
// Build endpoints against an editor that has a `ySync` extension whose fragment
|
|
114
|
+
// belongs to `doc`, so the mutable version-name store on `doc` is reachable.
|
|
115
|
+
function makeCollabEndpoints(doc: Y.Doc) {
|
|
116
|
+
const fragment = doc.get("default", "XmlFragment") as unknown as Y.Type;
|
|
117
|
+
(fragment as any).insert(0, ["hello"]);
|
|
118
|
+
const editor = BlockNoteEditor.create({
|
|
119
|
+
extensions: [ySyncStub(fragment)],
|
|
120
|
+
});
|
|
121
|
+
const endpoints = createYHubVersioningEndpoints({
|
|
122
|
+
baseUrl: BASE_URL,
|
|
123
|
+
org: ORG,
|
|
124
|
+
docId: DOC_ID,
|
|
125
|
+
})(editor);
|
|
126
|
+
return { endpoints, fragment };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function mockFetchResponse(body: unknown, status = 200) {
|
|
130
|
+
const encoded = encodeAny(body);
|
|
131
|
+
return new Response(encoded as Blob | BufferSource, {
|
|
132
|
+
status,
|
|
133
|
+
statusText: status === 200 ? "OK" : "Error",
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function makeFragment(): Y.Type {
|
|
138
|
+
const doc = new Y.Doc();
|
|
139
|
+
const frag = doc.get("default", "XmlFragment");
|
|
140
|
+
frag.insert(0, ["test content"]);
|
|
141
|
+
return frag;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ---------------------------------------------------------------------------
|
|
145
|
+
// Tests
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
describe("createYHubVersioningEndpoints", () => {
|
|
149
|
+
let fetchSpy: ReturnType<typeof vi.spyOn>;
|
|
150
|
+
|
|
151
|
+
beforeEach(() => {
|
|
152
|
+
fetchSpy = vi.spyOn(globalThis, "fetch");
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
afterEach(() => {
|
|
156
|
+
vi.restoreAllMocks();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// -------------------------------------------------------------------------
|
|
160
|
+
// list
|
|
161
|
+
// -------------------------------------------------------------------------
|
|
162
|
+
describe("list", () => {
|
|
163
|
+
it("returns version-tagged entries using the id attribution as snapshot id", async () => {
|
|
164
|
+
fetchSpy.mockResolvedValueOnce(
|
|
165
|
+
mockFetchResponse([VERSION_ENTRY_2, VERSION_ENTRY_1]),
|
|
166
|
+
);
|
|
167
|
+
// Current-version probe: latest edit of any kind, then latest version
|
|
168
|
+
// marker. Both are VERSION_ENTRY_2, so latest edit == latest marker → no
|
|
169
|
+
// synthetic "current version" entry.
|
|
170
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
171
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
172
|
+
|
|
173
|
+
const endpoints = makeEndpoints();
|
|
174
|
+
const snapshots = await endpoints.list();
|
|
175
|
+
|
|
176
|
+
expect(snapshots).toHaveLength(2);
|
|
177
|
+
expect(snapshots[0].id).toBe("uuid-version-2");
|
|
178
|
+
expect(snapshots[0].name).toBe("Test Version 2");
|
|
179
|
+
// The comma-separated `by` user-ids are split into a raw id array —
|
|
180
|
+
// never resolved to usernames here (that's the view layer's job).
|
|
181
|
+
expect(snapshots[0].by).toEqual(["user-2", "user-3"]);
|
|
182
|
+
expect(snapshots[0].secondaryLabel).toBeUndefined();
|
|
183
|
+
expect(snapshots[1].id).toBe("uuid-version-1");
|
|
184
|
+
expect(snapshots[1].name).toBe("Test Version 1");
|
|
185
|
+
expect(snapshots[1].by).toEqual(["user-1"]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("fetches the full activity timeline (no type:version filter) with grouping defaults", async () => {
|
|
189
|
+
// 1: full activity timeline. 2: latest edit of any kind. 3: latest
|
|
190
|
+
// version marker (the current-version probe makes both 2 & 3).
|
|
191
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
192
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
193
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
194
|
+
|
|
195
|
+
const endpoints = makeEndpoints();
|
|
196
|
+
await endpoints.list();
|
|
197
|
+
|
|
198
|
+
expect(fetchSpy).toHaveBeenCalledTimes(3);
|
|
199
|
+
const versionUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
200
|
+
expect(versionUrl.pathname).toBe(`/activity/${ORG}/${DOC_ID}`);
|
|
201
|
+
// The `type:version` overlay filter is dropped so history entries are
|
|
202
|
+
// returned too.
|
|
203
|
+
expect(versionUrl.searchParams.get("withCustomAttributions")).toBe(null);
|
|
204
|
+
expect(versionUrl.searchParams.get("customAttributions")).toBe("true");
|
|
205
|
+
// Grouping default is applied.
|
|
206
|
+
expect(versionUrl.searchParams.get("groupMaxGap")).toBe("10000");
|
|
207
|
+
|
|
208
|
+
// Probe A: the latest entry of *any* type (no marker filter).
|
|
209
|
+
const latestUrl = new URL(fetchSpy.mock.calls[1][0] as string);
|
|
210
|
+
expect(latestUrl.pathname).toBe(`/activity/${ORG}/${DOC_ID}`);
|
|
211
|
+
expect(latestUrl.searchParams.get("limit")).toBe("1");
|
|
212
|
+
expect(latestUrl.searchParams.has("withCustomAttributions")).toBe(false);
|
|
213
|
+
|
|
214
|
+
// Probe B: the latest *version marker*, server-filtered to `type:version`
|
|
215
|
+
// so grouping/mergeUsers can't conflate it with a later edit.
|
|
216
|
+
const markerUrl = new URL(fetchSpy.mock.calls[2][0] as string);
|
|
217
|
+
expect(markerUrl.pathname).toBe(`/activity/${ORG}/${DOC_ID}`);
|
|
218
|
+
expect(markerUrl.searchParams.get("limit")).toBe("1");
|
|
219
|
+
expect(markerUrl.searchParams.get("withCustomAttributions")).toBe(
|
|
220
|
+
"type:version",
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("forwards group + groupMaxDuration params when configured", async () => {
|
|
225
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
226
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
227
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
228
|
+
|
|
229
|
+
const endpoints = createYHubVersioningEndpoints({
|
|
230
|
+
baseUrl: BASE_URL,
|
|
231
|
+
org: ORG,
|
|
232
|
+
docId: DOC_ID,
|
|
233
|
+
activityLimit: 50,
|
|
234
|
+
group: true,
|
|
235
|
+
groupMaxDuration: 5000,
|
|
236
|
+
})(BlockNoteEditor.create());
|
|
237
|
+
await endpoints.list();
|
|
238
|
+
|
|
239
|
+
const versionUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
240
|
+
expect(versionUrl.searchParams.get("group")).toBe("true");
|
|
241
|
+
expect(versionUrl.searchParams.get("groupMaxDuration")).toBe("5000");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("omits group params by default while keeping the groupMaxGap default", async () => {
|
|
245
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
246
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
247
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
248
|
+
|
|
249
|
+
// `makeEndpoints` builds the factory with no group/groupMaxDuration opts.
|
|
250
|
+
const endpoints = makeEndpoints();
|
|
251
|
+
await endpoints.list();
|
|
252
|
+
|
|
253
|
+
const versionUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
254
|
+
expect(versionUrl.searchParams.get("group")).toBe(null);
|
|
255
|
+
expect(versionUrl.searchParams.get("groupMaxDuration")).toBe(null);
|
|
256
|
+
expect(versionUrl.searchParams.get("groupMaxGap")).toBe("10000");
|
|
257
|
+
// mergeUsers is only forwarded when explicitly configured.
|
|
258
|
+
expect(versionUrl.searchParams.get("mergeUsers")).toBe(null);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("maps both named version entries and plain history entries", async () => {
|
|
262
|
+
const namedEntry = {
|
|
263
|
+
from: 2000,
|
|
264
|
+
to: 2000,
|
|
265
|
+
by: "user-1",
|
|
266
|
+
customAttributions: [
|
|
267
|
+
{ k: "type", v: "version" },
|
|
268
|
+
{ k: "id", v: "v1" },
|
|
269
|
+
{ k: "name", v: "Named" },
|
|
270
|
+
],
|
|
271
|
+
};
|
|
272
|
+
const historyEntry = {
|
|
273
|
+
from: 1000,
|
|
274
|
+
to: 1000,
|
|
275
|
+
by: "user-2",
|
|
276
|
+
};
|
|
277
|
+
fetchSpy.mockResolvedValueOnce(
|
|
278
|
+
mockFetchResponse([namedEntry, historyEntry]),
|
|
279
|
+
);
|
|
280
|
+
// Current-version probe: latest edit == latest marker == `namedEntry`, so
|
|
281
|
+
// no synthetic current row.
|
|
282
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([namedEntry]));
|
|
283
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([namedEntry]));
|
|
284
|
+
|
|
285
|
+
const endpoints = makeEndpoints();
|
|
286
|
+
const snapshots = await endpoints.list();
|
|
287
|
+
|
|
288
|
+
const named = snapshots.find((s) => s.name === "Named");
|
|
289
|
+
expect(named).toBeDefined();
|
|
290
|
+
expect(named!.id).toBe("v1");
|
|
291
|
+
|
|
292
|
+
// `historyEntry` is at index 1 in the mocked entries array, so its
|
|
293
|
+
// history id embeds that index: `history-<to>-<index>`.
|
|
294
|
+
const history = snapshots.find((s) => s.id === "history-1000-1");
|
|
295
|
+
expect(history).toBeDefined();
|
|
296
|
+
expect(history!.name).toBeUndefined();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("returns empty array when no versions exist", async () => {
|
|
300
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
301
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
302
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
303
|
+
|
|
304
|
+
const endpoints = makeEndpoints();
|
|
305
|
+
const snapshots = await endpoints.list();
|
|
306
|
+
|
|
307
|
+
expect(snapshots).toEqual([]);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("sorts snapshots newest-first", async () => {
|
|
311
|
+
fetchSpy.mockResolvedValueOnce(
|
|
312
|
+
mockFetchResponse([VERSION_ENTRY_1, VERSION_ENTRY_2]),
|
|
313
|
+
);
|
|
314
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
315
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
316
|
+
|
|
317
|
+
const endpoints = makeEndpoints();
|
|
318
|
+
const snapshots = await endpoints.list();
|
|
319
|
+
|
|
320
|
+
expect(snapshots[0].createdAt).toBeGreaterThan(snapshots[1].createdAt);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("silently skips entries without an id attribution", async () => {
|
|
324
|
+
const noIdEntry = {
|
|
325
|
+
from: 1782218082853,
|
|
326
|
+
to: 1782218082853,
|
|
327
|
+
by: "Bad Entry",
|
|
328
|
+
customAttributions: [{ k: "type", v: "version" }],
|
|
329
|
+
};
|
|
330
|
+
fetchSpy.mockResolvedValueOnce(
|
|
331
|
+
mockFetchResponse([VERSION_ENTRY_1, noIdEntry]),
|
|
332
|
+
);
|
|
333
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_1]));
|
|
334
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_1]));
|
|
335
|
+
|
|
336
|
+
const endpoints = makeEndpoints();
|
|
337
|
+
const snapshots = await endpoints.list();
|
|
338
|
+
|
|
339
|
+
expect(snapshots).toHaveLength(1);
|
|
340
|
+
expect(snapshots[0].id).toBe("uuid-version-1");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("prefers the mutable __bn_version_names name over the attribution name", async () => {
|
|
344
|
+
const doc = new Y.Doc();
|
|
345
|
+
// The `ySync` extension's fragment belongs to `doc`, so the mutable
|
|
346
|
+
// name store on `doc` is what `getVersionNamesMap` reads.
|
|
347
|
+
const { endpoints } = makeCollabEndpoints(doc);
|
|
348
|
+
|
|
349
|
+
// Rename version "v1" in the mutable store on the live doc.
|
|
350
|
+
doc.get("__bn_version_names").setAttr("v1", "Renamed");
|
|
351
|
+
|
|
352
|
+
const versionEntry = {
|
|
353
|
+
from: 1782218082853,
|
|
354
|
+
to: 1782218082853,
|
|
355
|
+
by: "user-1",
|
|
356
|
+
customAttributions: [
|
|
357
|
+
{ k: "type", v: "version" },
|
|
358
|
+
{ k: "id", v: "v1" },
|
|
359
|
+
{ k: "name", v: "Original" },
|
|
360
|
+
],
|
|
361
|
+
};
|
|
362
|
+
// 1: activity fetch. 2 & 3: current-version probe (latest edit, latest
|
|
363
|
+
// marker) — same entry both times, so no newer edit and no current row.
|
|
364
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([versionEntry]));
|
|
365
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([versionEntry]));
|
|
366
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([versionEntry]));
|
|
367
|
+
|
|
368
|
+
const snapshots = await endpoints.list();
|
|
369
|
+
|
|
370
|
+
expect(snapshots).toHaveLength(1);
|
|
371
|
+
expect(snapshots[0].id).toBe("v1");
|
|
372
|
+
expect(snapshots[0].name).toBe("Renamed");
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("falls back to the attribution name when the store has no entry", async () => {
|
|
376
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_1]));
|
|
377
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_1]));
|
|
378
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_1]));
|
|
379
|
+
|
|
380
|
+
const endpoints = makeEndpoints();
|
|
381
|
+
const snapshots = await endpoints.list();
|
|
382
|
+
|
|
383
|
+
expect(snapshots).toHaveLength(1);
|
|
384
|
+
expect(snapshots[0].name).toBe("Test Version 1");
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("prepends a 'current version' entry when there are edits beyond the latest version", async () => {
|
|
388
|
+
// A more recent edit than VERSION_ENTRY_2, by a different author.
|
|
389
|
+
const latestEdit = {
|
|
390
|
+
from: 1782218300000,
|
|
391
|
+
to: 1782218300000,
|
|
392
|
+
by: "user-4",
|
|
393
|
+
};
|
|
394
|
+
// 1: activity list. 2: latest edit of any kind (the newer edit). 3: latest
|
|
395
|
+
// version marker (VERSION_ENTRY_2). Since latestEdit.to > VERSION_ENTRY_2.to
|
|
396
|
+
// a synthetic current-version row is prepended.
|
|
397
|
+
fetchSpy.mockResolvedValueOnce(
|
|
398
|
+
mockFetchResponse([VERSION_ENTRY_2, VERSION_ENTRY_1]),
|
|
399
|
+
);
|
|
400
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([latestEdit]));
|
|
401
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
402
|
+
|
|
403
|
+
const endpoints = makeEndpoints();
|
|
404
|
+
const snapshots = await endpoints.list();
|
|
405
|
+
|
|
406
|
+
expect(snapshots).toHaveLength(3);
|
|
407
|
+
expect(snapshots[0].id).toBe(CURRENT_VERSION_ID);
|
|
408
|
+
expect(snapshots[0].createdAt).toBe(latestEdit.to);
|
|
409
|
+
expect(snapshots[0].by).toEqual(["user-4"]);
|
|
410
|
+
expect(snapshots[0].secondaryLabel).toBeUndefined();
|
|
411
|
+
// The real version markers follow, newest-first.
|
|
412
|
+
expect(snapshots[1].id).toBe("uuid-version-2");
|
|
413
|
+
expect(snapshots[2].id).toBe("uuid-version-1");
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it("prepends 'current version' even when the newest activity entry is a history edit (regression: grouping absorbing the marker)", async () => {
|
|
417
|
+
// This is the exact regression the self-contained current-version probe
|
|
418
|
+
// fixes: `list()` maps the whole timeline, so its newest snapshot is a
|
|
419
|
+
// plain edit — deriving the latest-version time from that list would make
|
|
420
|
+
// the guard compare a value against itself and never surface a current
|
|
421
|
+
// row. Because the marker is fetched independently (probe 3), the edit is
|
|
422
|
+
// correctly recognised as newer than the latest *version marker*.
|
|
423
|
+
const historyEdit = {
|
|
424
|
+
from: 1782218300000,
|
|
425
|
+
to: 1782218300000,
|
|
426
|
+
by: "user-9",
|
|
427
|
+
};
|
|
428
|
+
// 1: activity list — newest entry is the history edit, not a marker.
|
|
429
|
+
fetchSpy.mockResolvedValueOnce(
|
|
430
|
+
mockFetchResponse([historyEdit, VERSION_ENTRY_2, VERSION_ENTRY_1]),
|
|
431
|
+
);
|
|
432
|
+
// 2: latest edit of any kind → the history edit.
|
|
433
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([historyEdit]));
|
|
434
|
+
// 3: latest version marker → VERSION_ENTRY_2 (older than the edit).
|
|
435
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([VERSION_ENTRY_2]));
|
|
436
|
+
|
|
437
|
+
const endpoints = makeEndpoints();
|
|
438
|
+
const snapshots = await endpoints.list();
|
|
439
|
+
|
|
440
|
+
expect(snapshots[0].id).toBe(CURRENT_VERSION_ID);
|
|
441
|
+
expect(snapshots[0].createdAt).toBe(historyEdit.to);
|
|
442
|
+
expect(snapshots[0].by).toEqual(["user-9"]);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("forwards the mergeUsers param when configured", async () => {
|
|
446
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
447
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
448
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse([]));
|
|
449
|
+
|
|
450
|
+
const endpoints = createYHubVersioningEndpoints({
|
|
451
|
+
baseUrl: BASE_URL,
|
|
452
|
+
org: ORG,
|
|
453
|
+
docId: DOC_ID,
|
|
454
|
+
mergeUsers: true,
|
|
455
|
+
})(BlockNoteEditor.create());
|
|
456
|
+
await endpoints.list();
|
|
457
|
+
|
|
458
|
+
const versionUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
459
|
+
expect(versionUrl.searchParams.get("mergeUsers")).toBe("true");
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
// -------------------------------------------------------------------------
|
|
464
|
+
// create
|
|
465
|
+
// -------------------------------------------------------------------------
|
|
466
|
+
describe("create", () => {
|
|
467
|
+
it("PATCHes with type:version, id, and name attributions and returns optimistic snapshot", async () => {
|
|
468
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(PATCH_RESPONSE));
|
|
469
|
+
|
|
470
|
+
const endpoints = makeEndpoints();
|
|
471
|
+
const snapshot = await endpoints.create!(makeFragment(), {
|
|
472
|
+
name: "My Version",
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
// Only one fetch call (PATCH) — no activity fetch
|
|
476
|
+
expect(fetchSpy).toHaveBeenCalledOnce();
|
|
477
|
+
const [patchUrl, patchInit] = fetchSpy.mock.calls[0];
|
|
478
|
+
expect(patchUrl).toBe(`${BASE_URL}/ydoc/${ORG}/${DOC_ID}`);
|
|
479
|
+
expect(patchInit.method).toBe("PATCH");
|
|
480
|
+
expect(patchInit.body).toBeInstanceOf(Uint8Array);
|
|
481
|
+
|
|
482
|
+
// Optimistic snapshot has a UUID id and the provided name. With no
|
|
483
|
+
// yCursor extension there's no current user to attribute it to.
|
|
484
|
+
expect(snapshot.id).toMatch(/^[0-9a-f-]+$/);
|
|
485
|
+
expect(snapshot.name).toBe("My Version");
|
|
486
|
+
expect(snapshot.createdAt).toBeGreaterThan(0);
|
|
487
|
+
expect(snapshot.by).toBeUndefined();
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it("stamps the optimistic snapshot with the cursor user's id", async () => {
|
|
491
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(PATCH_RESPONSE));
|
|
492
|
+
|
|
493
|
+
// Stub the editor so the yCursor extension reports a current user.
|
|
494
|
+
const editor = {
|
|
495
|
+
getExtension: (key: string) =>
|
|
496
|
+
key === "yCursor"
|
|
497
|
+
? {
|
|
498
|
+
getUser: () => ({ id: "user-1", name: "Alice", color: "#f00" }),
|
|
499
|
+
}
|
|
500
|
+
: undefined,
|
|
501
|
+
} as unknown as BlockNoteEditor<any, any, any>;
|
|
502
|
+
const endpoints = createYHubVersioningEndpoints({
|
|
503
|
+
baseUrl: BASE_URL,
|
|
504
|
+
org: ORG,
|
|
505
|
+
docId: DOC_ID,
|
|
506
|
+
})(editor);
|
|
507
|
+
|
|
508
|
+
const snapshot = await endpoints.create!(makeFragment(), {
|
|
509
|
+
name: "My Version",
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
expect(snapshot.by).toBe("user-1");
|
|
513
|
+
// The PATCH is attributed to the same user.
|
|
514
|
+
const patchUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
515
|
+
expect(patchUrl.searchParams.get("userid")).toBe("user-1");
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it("creates a version without a name", async () => {
|
|
519
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(PATCH_RESPONSE));
|
|
520
|
+
|
|
521
|
+
const endpoints = makeEndpoints();
|
|
522
|
+
const snapshot = await endpoints.create!(makeFragment());
|
|
523
|
+
|
|
524
|
+
expect(snapshot.name).toBeUndefined();
|
|
525
|
+
expect(snapshot.id).toMatch(/^[0-9a-f-]+$/);
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it("writes the version name into the __bn_version_names Y.Map on create", async () => {
|
|
529
|
+
const doc = new Y.Doc();
|
|
530
|
+
const { endpoints, fragment } = makeCollabEndpoints(doc);
|
|
531
|
+
|
|
532
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ success: true }));
|
|
533
|
+
|
|
534
|
+
const snapshot = await endpoints.create!(fragment as any, {
|
|
535
|
+
name: "My Version",
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
const names = doc.get("__bn_version_names");
|
|
539
|
+
expect(names.getAttr(snapshot.id as string)).toBe("My Version");
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it("throws when the fragment is not attached to a doc", async () => {
|
|
543
|
+
const endpoints = makeEndpoints();
|
|
544
|
+
const detached = { doc: null } as unknown as Y.Type;
|
|
545
|
+
await expect(
|
|
546
|
+
endpoints.create!(detached, { name: "fail" }),
|
|
547
|
+
).rejects.toThrow("not attached to a Y.Doc");
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
it("getContent works on the returned snapshot without an extra lookup", async () => {
|
|
551
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(PATCH_RESPONSE));
|
|
552
|
+
const cs = makeChangeset();
|
|
553
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(cs));
|
|
554
|
+
|
|
555
|
+
const endpoints = makeEndpoints();
|
|
556
|
+
const snapshot = await endpoints.create!(makeFragment(), {
|
|
557
|
+
name: "new",
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
const content = await endpoints.getContent(snapshot);
|
|
561
|
+
expect(content).toBeInstanceOf(Uint8Array);
|
|
562
|
+
// PATCH + changeset — the timestamp comes from the snapshot itself, so
|
|
563
|
+
// there's no activity lookup.
|
|
564
|
+
expect(fetchSpy).toHaveBeenCalledTimes(2);
|
|
565
|
+
const url = new URL(fetchSpy.mock.calls[1][0] as string);
|
|
566
|
+
expect(url.searchParams.get("to")).toBe(String(snapshot.createdAt));
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
|
|
570
|
+
// -------------------------------------------------------------------------
|
|
571
|
+
// getContent
|
|
572
|
+
// -------------------------------------------------------------------------
|
|
573
|
+
describe("getContent", () => {
|
|
574
|
+
it("fetches the changeset by to=<snapshot.createdAt> with no activity lookup", async () => {
|
|
575
|
+
// changeset fetch
|
|
576
|
+
const cs = makeChangeset();
|
|
577
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(cs));
|
|
578
|
+
|
|
579
|
+
const endpoints = makeEndpoints();
|
|
580
|
+
const content = await endpoints.getContent(SNAPSHOT_1);
|
|
581
|
+
|
|
582
|
+
expect(content).toBeInstanceOf(Uint8Array);
|
|
583
|
+
expect(content.byteLength).toBeGreaterThan(0);
|
|
584
|
+
|
|
585
|
+
// The snapshot carries its own timestamp, so only the changeset is fetched.
|
|
586
|
+
expect(fetchSpy).toHaveBeenCalledOnce();
|
|
587
|
+
|
|
588
|
+
// changeset reconstructed by timestamp, NOT by custom attribution
|
|
589
|
+
const url = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
590
|
+
expect(url.pathname).toBe(`/changeset/${ORG}/${DOC_ID}`);
|
|
591
|
+
expect(url.searchParams.get("ydoc")).toBe("true");
|
|
592
|
+
expect(url.searchParams.get("to")).toBe(String(SNAPSHOT_1.createdAt));
|
|
593
|
+
expect(url.searchParams.has("from")).toBe(false);
|
|
594
|
+
expect(url.searchParams.has("withCustomAttributions")).toBe(false);
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
it("throws when changeset has no nextDoc", async () => {
|
|
598
|
+
fetchSpy.mockResolvedValueOnce(
|
|
599
|
+
mockFetchResponse({ prevDoc: new Uint8Array() }),
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
const endpoints = makeEndpoints();
|
|
603
|
+
await expect(endpoints.getContent(SNAPSHOT_1)).rejects.toThrow(
|
|
604
|
+
"no document state",
|
|
605
|
+
);
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
// -------------------------------------------------------------------------
|
|
610
|
+
// getAttributions
|
|
611
|
+
// -------------------------------------------------------------------------
|
|
612
|
+
describe("getAttributions", () => {
|
|
613
|
+
it("fetches attributions between two versions", async () => {
|
|
614
|
+
const endpoints = makeEndpoints();
|
|
615
|
+
|
|
616
|
+
// changeset fetch (timestamps come straight from the snapshots)
|
|
617
|
+
const cs = makeChangeset({ attributions: true });
|
|
618
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(cs));
|
|
619
|
+
|
|
620
|
+
try {
|
|
621
|
+
await endpoints.getAttributions!(SNAPSHOT_2, SNAPSHOT_1);
|
|
622
|
+
} catch {
|
|
623
|
+
// Expected — mock attributions aren't valid Y.ContentMap
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Only the changeset is fetched — no activity lookups.
|
|
627
|
+
expect(fetchSpy).toHaveBeenCalledOnce();
|
|
628
|
+
const url = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
629
|
+
expect(url.searchParams.get("from")).toBe(String(SNAPSHOT_1.createdAt));
|
|
630
|
+
expect(url.searchParams.get("to")).toBe(String(SNAPSHOT_2.createdAt));
|
|
631
|
+
expect(url.searchParams.get("attributions")).toBe("true");
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
it("uses from=0 when compareTo is omitted", async () => {
|
|
635
|
+
const endpoints = makeEndpoints();
|
|
636
|
+
|
|
637
|
+
// changeset fetch
|
|
638
|
+
const cs = makeChangeset({ attributions: true });
|
|
639
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(cs));
|
|
640
|
+
|
|
641
|
+
try {
|
|
642
|
+
await endpoints.getAttributions!(SNAPSHOT_1);
|
|
643
|
+
} catch {
|
|
644
|
+
// Expected
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
const url = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
648
|
+
expect(url.searchParams.get("from")).toBe("0");
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
it("throws when changeset has no attributions", async () => {
|
|
652
|
+
const endpoints = makeEndpoints();
|
|
653
|
+
|
|
654
|
+
// changeset without attributions
|
|
655
|
+
fetchSpy.mockResolvedValueOnce(
|
|
656
|
+
mockFetchResponse({ nextDoc: new Uint8Array() }),
|
|
657
|
+
);
|
|
658
|
+
|
|
659
|
+
await expect(endpoints.getAttributions!(SNAPSHOT_1)).rejects.toThrow(
|
|
660
|
+
"no attributions",
|
|
661
|
+
);
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
// -------------------------------------------------------------------------
|
|
666
|
+
// restore
|
|
667
|
+
// -------------------------------------------------------------------------
|
|
668
|
+
describe("restore", () => {
|
|
669
|
+
it("fetches content and issues rollback (no backup)", async () => {
|
|
670
|
+
const endpoints = makeEndpoints();
|
|
671
|
+
const cs = makeChangeset();
|
|
672
|
+
|
|
673
|
+
// 1: GET /changeset (getContentAt via to=<snapshot.createdAt>)
|
|
674
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse(cs));
|
|
675
|
+
// 2: POST /rollback
|
|
676
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ success: true }));
|
|
677
|
+
|
|
678
|
+
const content = await endpoints.restore!(makeFragment(), SNAPSHOT_1);
|
|
679
|
+
|
|
680
|
+
// No backup PATCH and no activity lookup — just changeset + rollback.
|
|
681
|
+
expect(fetchSpy).toHaveBeenCalledTimes(2);
|
|
682
|
+
|
|
683
|
+
// 1st call: GET changeset by timestamp
|
|
684
|
+
const csUrl = new URL(fetchSpy.mock.calls[0][0] as string);
|
|
685
|
+
expect(csUrl.pathname).toBe(`/changeset/${ORG}/${DOC_ID}`);
|
|
686
|
+
expect(csUrl.searchParams.get("to")).toBe(String(SNAPSHOT_1.createdAt));
|
|
687
|
+
|
|
688
|
+
// 2nd call: POST rollback
|
|
689
|
+
const [rollbackUrl, rollbackInit] = fetchSpy.mock.calls[1];
|
|
690
|
+
expect(rollbackUrl).toContain(`/rollback/${ORG}/${DOC_ID}`);
|
|
691
|
+
expect(rollbackInit.method).toBe("POST");
|
|
692
|
+
|
|
693
|
+
expect(content).toBeInstanceOf(Uint8Array);
|
|
694
|
+
});
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
// -------------------------------------------------------------------------
|
|
698
|
+
// rename
|
|
699
|
+
// -------------------------------------------------------------------------
|
|
700
|
+
describe("rename", () => {
|
|
701
|
+
it("provides a rename endpoint", () => {
|
|
702
|
+
const endpoints = makeEndpoints();
|
|
703
|
+
expect(typeof endpoints.rename).toBe("function");
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
it("rename sets the name in the Y.Map", async () => {
|
|
707
|
+
const doc = new Y.Doc();
|
|
708
|
+
const { endpoints, fragment } = makeCollabEndpoints(doc);
|
|
709
|
+
|
|
710
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ success: true }));
|
|
711
|
+
const snapshot = await endpoints.create!(fragment as any, {
|
|
712
|
+
name: "Old",
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
await endpoints.rename!(snapshot, "New");
|
|
716
|
+
|
|
717
|
+
const names = doc.get("__bn_version_names");
|
|
718
|
+
expect(names.getAttr(snapshot.id as string)).toBe("New");
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
it("rename with no name clears the entry", async () => {
|
|
722
|
+
const doc = new Y.Doc();
|
|
723
|
+
const { endpoints, fragment } = makeCollabEndpoints(doc);
|
|
724
|
+
|
|
725
|
+
fetchSpy.mockResolvedValueOnce(mockFetchResponse({ success: true }));
|
|
726
|
+
const snapshot = await endpoints.create!(fragment as any, {
|
|
727
|
+
name: "Old",
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
await endpoints.rename!(snapshot, undefined);
|
|
731
|
+
|
|
732
|
+
const names = doc.get("__bn_version_names");
|
|
733
|
+
expect(names.hasAttr(snapshot.id as string)).toBe(false);
|
|
734
|
+
});
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// -------------------------------------------------------------------------
|
|
738
|
+
// error handling
|
|
739
|
+
// -------------------------------------------------------------------------
|
|
740
|
+
describe("error handling", () => {
|
|
741
|
+
it("throws on non-OK HTTP responses", async () => {
|
|
742
|
+
fetchSpy.mockResolvedValueOnce(
|
|
743
|
+
new Response("Not Found", { status: 404, statusText: "Not Found" }),
|
|
744
|
+
);
|
|
745
|
+
|
|
746
|
+
const endpoints = makeEndpoints();
|
|
747
|
+
await expect(endpoints.list()).rejects.toThrow(
|
|
748
|
+
"YHub request failed: 404",
|
|
749
|
+
);
|
|
750
|
+
});
|
|
751
|
+
});
|
|
752
|
+
});
|