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,cAAcjD,EAAoB+C,CAAC,CAAG/C,EAAoBwC,CAAC,CAACD,GAG/D,EAEA,IAAIW,EAAqB1I,WAAW,uBAA0B,CAAGA,WAAW,uBAA0B,EAAI,EAAE,CACxG2I,EAA6BD,EAAmBpG,IAAI,CAACsG,IAAI,CAACF,EAC9DA,CAAAA,EAAmBpG,IAAI,CAvBJ,IAClB,GAAI,CAAC+D,EAAUwC,EAAaC,EAAQ,CAAGhJ,EACvC,IAAI,IAAI2F,KAAYoD,EAChBrD,EAAoB8B,CAAC,CAACuB,EAAapD,IACrCD,CAAAA,EAAoBO,CAAC,CAACN,EAAS,CAAGoD,CAAW,CAACpD,EAAS,EAIzD,IADGqD,GAASA,EAAQtD,GACda,EAASI,MAAM,EACpB+B,CAAe,CAACnC,EAAS0C,GAAG,GAAG,CAAG,EACnCJ,EAA2B7I,EAC5B,C,WCpBA,IAAIkJ,EAAOxD,EAAoBQ,CAAC,CAChCR,EAAoBQ,CAAC,CAAG,IAChB2B,QAAQC,GAAG,CAAC,CAAC,KAAK,IAAI,KAAK,KAAK,CAAC9E,GAAG,CAAC0C,EAAoBkC,CAAC,CAAElC,IAAsByD,IAAI,CAACD,E,KCDrExD,EAAoBQ,CAAC,E","sources":["webpack://@affine/web/../core/src/modules/docs-search/worker/in-worker.ts","webpack://@affine/web/webpack/bootstrap","webpack://@affine/web/webpack/runtime/chunk loaded","webpack://@affine/web/webpack/runtime/define property getters","webpack://@affine/web/webpack/runtime/ensure chunk","webpack://@affine/web/webpack/runtime/get javascript chunk filename","webpack://@affine/web/webpack/runtime/get mini-css chunk filename","webpack://@affine/web/webpack/runtime/hasOwnProperty shorthand","webpack://@affine/web/webpack/runtime/publicPath","webpack://@affine/web/webpack/runtime/importScripts chunk loading","webpack://@affine/web/webpack/runtime/startup chunk dependencies","webpack://@affine/web/webpack/startup"],"sourcesContent":["import type { AffineTextAttributes } from '@blocksuite/blocks';\nimport type { DeltaInsert } from '@blocksuite/inline';\nimport { Document } from '@toeverything/infra';\nimport { toHexString } from 'lib0/buffer.js';\nimport { digest as lib0Digest } from 'lib0/hash/sha256';\nimport { difference } from 'lodash-es';\nimport {\n applyUpdate,\n Array as YArray,\n Doc as YDoc,\n Map as YMap,\n type Text as YText,\n} from 'yjs';\n\nimport type { BlockIndexSchema, docIndexSchema } from '../schema';\nimport type {\n WorkerIngoingMessage,\n WorkerInput,\n WorkerOutgoingMessage,\n WorkerOutput,\n} from './types';\n\nlet cachedRootDoc: { doc: YDoc; hash: string } | null = null;\n\nasync function digest(data: Uint8Array) {\n if (\n globalThis.crypto &&\n globalThis.crypto.subtle &&\n typeof globalThis.crypto.subtle.digest === 'function'\n ) {\n return new Uint8Array(\n await globalThis.crypto.subtle.digest('SHA-256', data)\n );\n }\n return lib0Digest(data);\n}\n\nasync function crawlingDocData({\n docBuffer,\n storageDocId,\n rootDocBuffer,\n}: WorkerInput & { type: 'doc' }): Promise {\n if (isEmptyUpdate(rootDocBuffer)) {\n console.warn('[worker]: Empty root doc buffer');\n return {};\n }\n\n const rootDocBufferHash = toHexString(await digest(rootDocBuffer));\n\n let yRootDoc;\n if (cachedRootDoc && cachedRootDoc.hash === rootDocBufferHash) {\n yRootDoc = cachedRootDoc.doc;\n } else {\n yRootDoc = new YDoc();\n applyUpdate(yRootDoc, rootDocBuffer);\n cachedRootDoc = { doc: yRootDoc, hash: rootDocBufferHash };\n }\n\n let docId = null;\n for (const [id, subdoc] of yRootDoc.getMap('spaces')) {\n if (subdoc instanceof YDoc && storageDocId === subdoc.guid) {\n docId = id;\n break;\n }\n }\n\n if (docId === null) {\n return {};\n }\n\n const ydoc = new YDoc();\n\n if (!isEmptyUpdate(docBuffer)) {\n applyUpdate(ydoc, docBuffer);\n }\n\n let docExists: boolean | null = null;\n\n (\n yRootDoc.getMap('meta').get('pages') as YArray> | undefined\n )?.forEach(page => {\n if (page.get('id') === docId) {\n docExists = !(page.get('trash') ?? false);\n }\n });\n\n if (!docExists) {\n return {\n deletedDoc: [docId],\n };\n } else {\n const blocks = ydoc.getMap('blocks');\n\n if (blocks.size === 0) {\n return {};\n }\n\n let docTitle = '';\n\n const blockDocuments: Document[] = [];\n\n for (const block of blocks.values()) {\n const flavour = block.get('sys:flavour')?.toString();\n const blockId = block.get('sys:id')?.toString();\n\n if (!flavour || !blockId) {\n continue;\n }\n\n if (flavour === 'affine:page') {\n docTitle = block.get('prop:title').toString();\n blockDocuments.push(\n Document.from(`${docId}:${blockId}`, {\n docId,\n flavour,\n blockId,\n content: docTitle,\n })\n );\n }\n\n if (\n flavour === 'affine:paragraph' ||\n flavour === 'affine:list' ||\n flavour === 'affine:code'\n ) {\n const text = block.get('prop:text') as YText;\n if (!text) {\n continue;\n }\n\n const deltas: DeltaInsert[] = text.toDelta();\n const ref = deltas\n .map(delta => {\n if (\n delta.attributes &&\n delta.attributes.reference &&\n delta.attributes.reference.pageId\n ) {\n return delta.attributes.reference.pageId;\n }\n return null;\n })\n .filter((link): link is string => !!link);\n\n blockDocuments.push(\n Document.from(`${docId}:${blockId}`, {\n docId,\n flavour,\n blockId,\n content: text.toString(),\n ref,\n })\n );\n }\n\n if (\n flavour === 'affine:embed-linked-doc' ||\n flavour === 'affine:embed-synced-doc'\n ) {\n const pageId = block.get('prop:pageId');\n if (typeof pageId === 'string') {\n blockDocuments.push(\n Document.from(`${docId}:${blockId}`, {\n docId,\n flavour,\n blockId,\n ref: pageId,\n })\n );\n }\n }\n\n if (flavour === 'affine:attachment' || flavour === 'affine:image') {\n const blobId = block.get('prop:sourceId');\n if (typeof blobId === 'string') {\n blockDocuments.push(\n Document.from(`${docId}:${blockId}`, {\n docId,\n flavour,\n blockId,\n blob: [blobId],\n })\n );\n }\n }\n\n if (flavour === 'affine:surface') {\n const texts = [];\n\n const elementsObj = block.get('prop:elements');\n if (\n !(\n elementsObj instanceof YMap &&\n elementsObj.get('type') === '$blocksuite:internal:native$'\n )\n ) {\n continue;\n }\n const elements = elementsObj.get('value') as YMap;\n if (!(elements instanceof YMap)) {\n continue;\n }\n\n for (const element of elements.values()) {\n if (!(element instanceof YMap)) {\n continue;\n }\n const text = element.get('text') as YText;\n if (!text) {\n continue;\n }\n\n texts.push(text.toString());\n }\n\n blockDocuments.push(\n Document.from(`${docId}:${blockId}`, {\n docId,\n flavour,\n blockId,\n content: texts,\n })\n );\n }\n\n if (flavour === 'affine:database') {\n const texts = [];\n const columnsObj = block.get('prop:columns');\n if (!(columnsObj instanceof YArray)) {\n continue;\n }\n for (const column of columnsObj) {\n if (!(column instanceof YMap)) {\n continue;\n }\n if (typeof column.get('name') === 'string') {\n texts.push(column.get('name'));\n }\n\n const data = column.get('data');\n if (!(data instanceof YMap)) {\n continue;\n }\n const options = data.get('options');\n if (!(options instanceof YArray)) {\n continue;\n }\n for (const option of options) {\n if (!(option instanceof YMap)) {\n continue;\n }\n const value = option.get('value');\n if (typeof value === 'string') {\n texts.push(value);\n }\n }\n }\n\n blockDocuments.push(\n Document.from(`${docId}:${blockId}`, {\n docId,\n flavour,\n blockId,\n content: texts,\n })\n );\n }\n }\n\n return {\n addedDoc: [\n {\n id: docId,\n doc: Document.from(docId, {\n title: docTitle,\n }),\n blocks: blockDocuments,\n },\n ],\n };\n }\n}\n\nfunction crawlingRootDocData({\n allIndexedDocs,\n rootDocBuffer,\n}: WorkerInput & {\n type: 'rootDoc';\n}): WorkerOutput {\n const ydoc = new YDoc();\n\n applyUpdate(ydoc, rootDocBuffer);\n\n const docs = ydoc.getMap('meta').get('pages') as\n | YArray>\n | undefined;\n\n if (!docs) {\n return {};\n }\n\n const availableDocs = [];\n\n for (const page of docs) {\n const docId = page.get('id');\n\n if (typeof docId !== 'string') {\n continue;\n }\n\n const inTrash = page.get('trash') ?? false;\n\n if (!inTrash) {\n availableDocs.push(docId);\n }\n }\n\n const needDelete = difference(allIndexedDocs, availableDocs);\n const needAdd = difference(availableDocs, allIndexedDocs);\n\n return {\n reindexDoc: [...needAdd, ...needDelete].map(docId => ({\n docId,\n storageDocId: ydoc.getMap('spaces').get(docId)?.guid ?? docId,\n })),\n };\n}\n\nglobalThis.onmessage = async (event: MessageEvent) => {\n const message = event.data;\n if (message.type === 'init') {\n postMessage({ type: 'init', msgId: message.msgId });\n return;\n }\n if (message.type === 'run') {\n const { input } = message;\n try {\n let data;\n if (input.type === 'rootDoc') {\n data = crawlingRootDocData(input);\n } else {\n data = await crawlingDocData(input);\n }\n\n postMessage({ type: 'done', msgId: message.msgId, output: data });\n } catch (error) {\n postMessage({\n type: 'failed',\n msgId: message.msgId,\n error: error instanceof Error ? error.message : error + '',\n });\n }\n }\n};\n\ndeclare function postMessage(message: WorkerOutgoingMessage): void;\n\nfunction isEmptyUpdate(binary: Uint8Array) {\n return (\n binary.byteLength === 0 ||\n (binary.byteLength === 2 && binary[0] === 0 && binary[1] === 0)\n );\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n// expose the modules object (__webpack_modules__)\n__webpack_require__.m = __webpack_modules__;\n\n// the startup function\n__webpack_require__.x = () => {\n\t// Load entry module and return exports\n\t// This entry module depends on other loaded chunks and execution need to be delayed\n\tvar __webpack_exports__ = __webpack_require__.O(undefined, [4922,861,9574,8674], () => (__webpack_require__(97735)))\n\t__webpack_exports__ = __webpack_require__.O(__webpack_exports__);\n\treturn __webpack_exports__;\n};\n\n","var deferred = [];\n__webpack_require__.O = (result, chunkIds, fn, priority) => {\n\tif(chunkIds) {\n\t\tpriority = priority || 0;\n\t\tfor(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];\n\t\tdeferred[i] = [chunkIds, fn, priority];\n\t\treturn;\n\t}\n\tvar notFulfilled = Infinity;\n\tfor (var i = 0; i < deferred.length; i++) {\n\t\tvar [chunkIds, fn, priority] = deferred[i];\n\t\tvar fulfilled = true;\n\t\tfor (var j = 0; j < chunkIds.length; j++) {\n\t\t\tif ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {\n\t\t\t\tchunkIds.splice(j--, 1);\n\t\t\t} else {\n\t\t\t\tfulfilled = false;\n\t\t\t\tif(priority < notFulfilled) notFulfilled = priority;\n\t\t\t}\n\t\t}\n\t\tif(fulfilled) {\n\t\t\tdeferred.splice(i--, 1)\n\t\t\tvar r = fn();\n\t\t\tif (r !== undefined) result = r;\n\t\t}\n\t}\n\treturn result;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.f = {};\n// This file contains only the entry chunk.\n// The chunk loading function for additional chunks\n__webpack_require__.e = (chunkId) => {\n\treturn Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {\n\t\t__webpack_require__.f[key](chunkId, promises);\n\t\treturn promises;\n\t}, []));\n};","// This function allow to reference async chunks and sibling chunks for the entrypoint\n__webpack_require__.u = (chunkId) => {\n\t// return url for filenames not based on template\n\tif (chunkId === 4922) return \"js/chunk.npm-async-lodash-es.27a23701.js\";\n\tif (chunkId === 861) return \"js/chunk.npm-async-lib0.9b0cd4f1.js\";\n\tif (chunkId === 9574) return \"js/chunk.npm-async-yjs.5ef92592.js\";\n\t// return url for filenames based on template\n\treturn \"js/\" + chunkId + \".\" + \"65285e27\" + \".js\";\n};","// This function allow to reference async chunks and sibling chunks for the entrypoint\n__webpack_require__.miniCssF = (chunkId) => {\n\t// return url for filenames based on template\n\treturn undefined;\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","__webpack_require__.p = \"/\";","// no baseURI\n\n// object to store loaded chunks\n// \"1\" means \"already loaded\"\nvar installedChunks = {\n\t3941: 1\n};\n\n// importScripts chunk loading\nvar installChunk = (data) => {\n\tvar [chunkIds, moreModules, runtime] = data;\n\tfor(var moduleId in moreModules) {\n\t\tif(__webpack_require__.o(moreModules, moduleId)) {\n\t\t\t__webpack_require__.m[moduleId] = moreModules[moduleId];\n\t\t}\n\t}\n\tif(runtime) runtime(__webpack_require__);\n\twhile(chunkIds.length)\n\t\tinstalledChunks[chunkIds.pop()] = 1;\n\tparentChunkLoadingFunction(data);\n};\n__webpack_require__.f.i = (chunkId, promises) => {\n\t// \"1\" is the signal for \"already loaded\"\n\tif(!installedChunks[chunkId]) {\n\t\tif(true) { // all chunks have JS\n\t\t\timportScripts(__webpack_require__.p + __webpack_require__.u(chunkId));\n\t\t}\n\t}\n};\n\nvar chunkLoadingGlobal = globalThis[\"webpackChunk_affine_web\"] = globalThis[\"webpackChunk_affine_web\"] || [];\nvar parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);\nchunkLoadingGlobal.push = installChunk;\n\n// no HMR\n\n// no HMR manifest","var next = __webpack_require__.x;\n__webpack_require__.x = () => {\n\treturn Promise.all([4922,861,9574,8674].map(__webpack_require__.e, __webpack_require__)).then(next);\n};","// run startup\nvar __webpack_exports__ = __webpack_require__.x();\n"],"names":["cachedRootDoc","digest","data","crypto","globalThis","subtle","Uint8Array","lib0Digest","crawlingDocData","docBuffer","storageDocId","rootDocBuffer","yRootDoc","isEmptyUpdate","console","warn","rootDocBufferHash","toHexString","hash","doc","YDoc","applyUpdate","docId","id","subdoc","getMap","guid","ydoc","docExists","get","forEach","page","deletedDoc","blocks","size","docTitle","blockDocuments","block","values","flavour","toString","blockId","push","Document","from","content","text","ref","deltas","toDelta","map","delta","attributes","reference","pageId","filter","link","blobId","blob","texts","elementsObj","YMap","elements","element","columnsObj","YArray","column","options","option","value","addedDoc","title","binary","byteLength","onmessage","event","message","type","postMessage","msgId","input","crawlingRootDocData","allIndexedDocs","docs","availableDocs","needDelete","difference","reindexDoc","output","error","Error","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","exports","module","__webpack_modules__","m","x","__webpack_exports__","O","deferred","result","chunkIds","fn","priority","i","length","notFulfilled","Infinity","fulfilled","j","Object","keys","every","key","splice","r","d","definition","o","defineProperty","enumerable","f","e","Promise","all","reduce","promises","chunkId","u","miniCssF","obj","prop","prototype","hasOwnProperty","call","p","installedChunks","importScripts","chunkLoadingGlobal","parentChunkLoadingFunction","bind","moreModules","runtime","pop","next","then"],"sourceRoot":""}