Skip to content

Commit 9fb005c

Browse files
vroldanbetsnyk-bottstirrat15
authored
[Snyk] Upgrade flexsearch from 0.7.43 to 0.8.143 (#344)
* fix: upgrade flexsearch from 0.7.43 to 0.8.143 Snyk has created this PR to upgrade flexsearch from 0.7.43 to 0.8.143. See this package in npm: flexsearch See this project in Snyk: https://app.snyk.io/org/authzed/project/ba1f5e2c-3779-4576-a375-1b68f7cd2dae?utm_source=github&utm_medium=referral&page=upgrade-pr * update pnpm lock --------- Co-authored-by: snyk-bot <snyk-bot@snyk.io> Co-authored-by: Tanner Stirrat <tstirrat@gmail.com>
1 parent 9c5b192 commit 9fb005c

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_modules/*
33
.vercel
44
.next
55
.env*
6+
tsconfig.tsbuildinfo
67

78
# Generated
89
public/robots.txt

components/nextra/Flexsearch.tsx

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import cn from 'clsx';
2525
// flexsearch types are incorrect, they were overwritten in tsconfig.json
26-
import FlexSearch from 'flexsearch';
26+
import { Document } from 'flexsearch';
2727
import { useRouter } from 'next/router';
2828
import type { SearchData } from 'nextra';
2929
import type { ReactElement, ReactNode } from 'react';
@@ -36,38 +36,30 @@ import { SearchResult } from './types';
3636
// Diff: Inlined definitions
3737
export const DEFAULT_LOCALE = 'en-US';
3838

39-
type SectionIndex = FlexSearch.Document<
40-
{
39+
type SectionIndex = {
4140
id: string;
4241
url: string;
4342
title: string;
4443
pageId: string;
4544
content: string;
4645
display?: string;
47-
},
48-
['title', 'content', 'url', 'display']
49-
>;
46+
}
5047

51-
type PageIndex = FlexSearch.Document<
52-
{
48+
type PageIndex = {
5349
id: number;
5450
title: string;
5551
content: string;
56-
},
57-
['title']
58-
>;
52+
}
5953

6054
// Diff: Additional index for blog posts
61-
type BlogIndex = FlexSearch.Document<
55+
type BlogIndex =
6256
{
6357
id: number;
6458
title: string;
6559
content: string;
6660
url: string;
6761
summary: string;
68-
},
69-
['title', 'url', 'summary']
70-
>;
62+
}
7163

7264
type Result = {
7365
_page_rk: number;
@@ -79,11 +71,13 @@ type Result = {
7971

8072
// This can be global for better caching.
8173
const indexes: {
82-
[locale: string]: [PageIndex, SectionIndex];
74+
// tuple is PageIndex, SectionIndex
75+
[locale: string]: [Document, Document];
8376
} = {};
8477

8578
// Diff: Index for blog posts
86-
const blogIndex: BlogIndex = new FlexSearch.Document({
79+
// Associated type is BlogIndex
80+
const blogIndex = new Document({
8781
cache: 100,
8882
tokenize: 'forward',
8983
document: {
@@ -134,7 +128,8 @@ const loadIndexesImpl = async (
134128
// Diff: Load blog data
135129
const blogData = await loadBlogData(basePath);
136130

137-
const pageIndex: PageIndex = new FlexSearch.Document({
131+
// Associated type is PageIndex
132+
const pageIndex = new Document({
138133
cache: 100,
139134
tokenize: 'full',
140135
document: {
@@ -149,7 +144,8 @@ const loadIndexesImpl = async (
149144
},
150145
});
151146

152-
const sectionIndex: SectionIndex = new FlexSearch.Document({
147+
// Associated type is SectionIndex
148+
const sectionIndex = new Document({
153149
cache: 100,
154150
tokenize: 'full',
155151
document: {
@@ -232,7 +228,7 @@ export function Flexsearch({
232228

233229
// Show the results for the top 5 pages
234230
const pageResults =
235-
pageIndex.search<true>(search, 5, {
231+
pageIndex.search(search, 5, {
236232
enrich: true,
237233
suggest: true,
238234
})[0]?.result || [];
@@ -247,7 +243,7 @@ export function Flexsearch({
247243

248244
// Show the top 5 results for each page
249245
const sectionResults =
250-
sectionIndex.search<true>(search, 5, {
246+
sectionIndex.search(search, 5, {
251247
enrich: true,
252248
suggest: true,
253249
tag: `page_${result.id}`,
@@ -324,7 +320,7 @@ export function Flexsearch({
324320
}));
325321

326322
const blogResults =
327-
blogIndex.search<true>(search, 5, {
323+
blogIndex.search(search, 5, {
328324
enrich: true,
329325
suggest: true,
330326
})[0]?.result || [];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"class-variance-authority": "^0.7.0",
2727
"clsx": "^2.1.1",
2828
"escape-string-regexp": "^5.0.0",
29-
"flexsearch": "^0.7.43",
29+
"flexsearch": "^0.8.143",
3030
"js-yaml": "^4.1.0",
3131
"next": "^14.2.7",
3232
"next-sitemap": "^4.2.3",

pnpm-lock.yaml

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"isolatedModules": true,
1616
"jsx": "preserve",
1717
"paths": {
18-
"@/*": ["./*"],
18+
"@/*": ["./*"]
1919
}
2020
},
2121
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],

0 commit comments

Comments
 (0)