mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
chore(deps): upgrade orama to 3.0.1
Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
9cd6003619
commit
cd7434ea3b
4 changed files with 23 additions and 37 deletions
|
@ -16,8 +16,8 @@ const customJestConfig = {
|
||||||
moduleNameMapper: {
|
moduleNameMapper: {
|
||||||
// Handle module aliases (this will be automatically configured for you soon)
|
// Handle module aliases (this will be automatically configured for you soon)
|
||||||
'^@/components/(.*)$': '<rootDir>/src/components/$1',
|
'^@/components/(.*)$': '<rootDir>/src/components/$1',
|
||||||
// fix uuid / jest problem https://github.com/uuidjs/uuid/pull/616
|
// fix ESM loading of orama breaking jest
|
||||||
'^uuid$': require.resolve('uuid')
|
'^@orama/orama$': require.resolve('@orama/orama')
|
||||||
},
|
},
|
||||||
roots: ['<rootDir>/src'],
|
roots: ['<rootDir>/src'],
|
||||||
testEnvironment: 'jsdom',
|
testEnvironment: 'jsdom',
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
"@hedgedoc/html-to-react": "workspace:html-to-react",
|
"@hedgedoc/html-to-react": "workspace:html-to-react",
|
||||||
"@hedgedoc/markdown-it-plugins": "workspace:markdown-it-plugins",
|
"@hedgedoc/markdown-it-plugins": "workspace:markdown-it-plugins",
|
||||||
"@mrdrogdrog/optional": "1.2.1",
|
"@mrdrogdrog/optional": "1.2.1",
|
||||||
"@orama/orama": "2.0.23",
|
"@orama/orama": "3.0.1",
|
||||||
"@react-hook/resize-observer": "2.0.2",
|
"@react-hook/resize-observer": "2.0.2",
|
||||||
"@redux-devtools/core": "4.0.0",
|
"@redux-devtools/core": "4.0.0",
|
||||||
"@reduxjs/toolkit": "2.3.0",
|
"@reduxjs/toolkit": "2.3.0",
|
||||||
|
|
|
@ -4,10 +4,9 @@
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useMemo, useState } from 'react'
|
||||||
import { create, insert, search } from '@orama/orama'
|
import type { Orama, Results } from '@orama/orama'
|
||||||
import { useAsync } from 'react-use'
|
import { create, insertMultiple, search } from '@orama/orama'
|
||||||
import { Logger } from '../../utils/logger'
|
|
||||||
|
|
||||||
export interface CheatsheetSearchIndexEntry {
|
export interface CheatsheetSearchIndexEntry {
|
||||||
readonly id: string
|
readonly id: string
|
||||||
|
@ -17,8 +16,6 @@ export interface CheatsheetSearchIndexEntry {
|
||||||
readonly extensionId: string
|
readonly extensionId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const logger = new Logger('Cheatsheet Search')
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate document search index and provide functions to search.
|
* Generate document search index and provide functions to search.
|
||||||
*
|
*
|
||||||
|
@ -32,12 +29,8 @@ export const useCheatsheetSearch = (
|
||||||
): CheatsheetSearchIndexEntry[] => {
|
): CheatsheetSearchIndexEntry[] => {
|
||||||
const [results, setResults] = useState<CheatsheetSearchIndexEntry[]>([])
|
const [results, setResults] = useState<CheatsheetSearchIndexEntry[]>([])
|
||||||
|
|
||||||
const {
|
const searchIndex = useMemo(() => {
|
||||||
value: searchIndex,
|
const db = create({
|
||||||
loading: searchIndexLoading,
|
|
||||||
error: searchIndexError
|
|
||||||
} = useAsync(async () => {
|
|
||||||
const db = await create({
|
|
||||||
schema: {
|
schema: {
|
||||||
id: 'string',
|
id: 'string',
|
||||||
title: 'string',
|
title: 'string',
|
||||||
|
@ -46,19 +39,15 @@ export const useCheatsheetSearch = (
|
||||||
extensionId: 'string'
|
extensionId: 'string'
|
||||||
} as const
|
} as const
|
||||||
})
|
})
|
||||||
const adds = entries.map((entry) => {
|
void insertMultiple(db, entries)
|
||||||
logger.debug('Add to search entry:', entry)
|
return db as Orama<CheatsheetSearchIndexEntry>
|
||||||
return insert(db, entry)
|
|
||||||
})
|
|
||||||
await Promise.all(adds)
|
|
||||||
return db
|
|
||||||
}, [entries])
|
}, [entries])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (searchIndexLoading || searchIndexError !== undefined || searchIndex === undefined || searchTerm === '') {
|
if (searchIndex === undefined || searchTerm === '') {
|
||||||
return setResults(entries)
|
return setResults(entries)
|
||||||
}
|
}
|
||||||
search(searchIndex, {
|
const rawResults = search(searchIndex, {
|
||||||
term: searchTerm,
|
term: searchTerm,
|
||||||
tolerance: 1,
|
tolerance: 1,
|
||||||
properties: ['title', 'description', 'example'],
|
properties: ['title', 'description', 'example'],
|
||||||
|
@ -66,15 +55,12 @@ export const useCheatsheetSearch = (
|
||||||
title: 3,
|
title: 3,
|
||||||
description: 2,
|
description: 2,
|
||||||
example: 1
|
example: 1
|
||||||
}
|
},
|
||||||
})
|
limit: entries.length
|
||||||
.then((results) => {
|
}) as Results<CheatsheetSearchIndexEntry>
|
||||||
setResults(results.hits.map((entry) => entry.document))
|
const results = rawResults.hits.map((entry) => entry.document)
|
||||||
})
|
setResults(results)
|
||||||
.catch((error) => {
|
}, [entries, searchIndex, searchTerm])
|
||||||
logger.error(error)
|
|
||||||
})
|
|
||||||
}, [entries, searchIndexError, searchIndexLoading, searchIndex, searchTerm])
|
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -2703,7 +2703,7 @@ __metadata:
|
||||||
"@hedgedoc/markdown-it-plugins": "workspace:markdown-it-plugins"
|
"@hedgedoc/markdown-it-plugins": "workspace:markdown-it-plugins"
|
||||||
"@mrdrogdrog/optional": "npm:1.2.1"
|
"@mrdrogdrog/optional": "npm:1.2.1"
|
||||||
"@next/bundle-analyzer": "npm:14.2.7"
|
"@next/bundle-analyzer": "npm:14.2.7"
|
||||||
"@orama/orama": "npm:2.0.23"
|
"@orama/orama": "npm:3.0.1"
|
||||||
"@react-hook/resize-observer": "npm:2.0.2"
|
"@react-hook/resize-observer": "npm:2.0.2"
|
||||||
"@redux-devtools/core": "npm:4.0.0"
|
"@redux-devtools/core": "npm:4.0.0"
|
||||||
"@reduxjs/toolkit": "npm:2.3.0"
|
"@reduxjs/toolkit": "npm:2.3.0"
|
||||||
|
@ -4372,10 +4372,10 @@ __metadata:
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@orama/orama@npm:2.0.23":
|
"@orama/orama@npm:3.0.1":
|
||||||
version: 2.0.23
|
version: 3.0.1
|
||||||
resolution: "@orama/orama@npm:2.0.23"
|
resolution: "@orama/orama@npm:3.0.1"
|
||||||
checksum: 10c0/b65f57e338c5cfe6498cec5917a952ce783aef202f20ef27d8f55f40e175737a616b09ccbb7ebedb3cd24250504a2295caa950c8777cbc21309ee430584c1ed3
|
checksum: 10c0/ef344c95c62be21b7a4ef745db8bb2d2f4da00db4ee8f382a8641de13759457f6c4a21ab3602dbda22b610459e163fa47ff95d97bf5a1bad4b60a760e6bee07c
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue