diff --git a/src/services/attributes.ts b/src/services/attributes.ts index 25b54724b..eff0f4697 100644 --- a/src/services/attributes.ts +++ b/src/services/attributes.ts @@ -9,7 +9,7 @@ import BUILTIN_ATTRIBUTES from "./builtin_attributes.js"; import BNote from "../becca/entities/bnote.js"; import { AttributeRow } from '../becca/entities/rows.js'; -const ATTRIBUTE_TYPES = ['label', 'relation']; +const ATTRIBUTE_TYPES = new Set(['label', 'relation']); function getNotesWithLabel(name: string, value?: string): BNote[] { const query = attributeFormatter.formatAttrForSearch({type: 'label', name, value}, value !== undefined); @@ -99,7 +99,7 @@ function getAttributeNames(type: string, nameLike: string) { } function isAttributeType(type: string): boolean { - return ATTRIBUTE_TYPES.includes(type); + return ATTRIBUTE_TYPES.has(type); } function isAttributeDangerous(type: string, name: string): boolean { diff --git a/src/services/search/expressions/note_content_fulltext.ts b/src/services/search/expressions/note_content_fulltext.ts index d81f42dcd..bc92cf26c 100644 --- a/src/services/search/expressions/note_content_fulltext.ts +++ b/src/services/search/expressions/note_content_fulltext.ts @@ -13,7 +13,7 @@ import { normalize } from "../../utils.js"; import sql from "../../sql.js"; -const ALLOWED_OPERATORS = ['=', '!=', '*=*', '*=', '=*', '%=']; +const ALLOWED_OPERATORS = new Set(['=', '!=', '*=*', '*=', '=*', '%=']); const cachedRegexes: Record = {}; @@ -50,8 +50,8 @@ class NoteContentFulltextExp extends Expression { } execute(inputNoteSet: NoteSet, executionContext: {}, searchContext: SearchContext) { - if (!ALLOWED_OPERATORS.includes(this.operator)) { - searchContext.addError(`Note content can be searched only with operators: ${ALLOWED_OPERATORS.join(", ")}, operator ${this.operator} given.`); + if (!ALLOWED_OPERATORS.has(this.operator)) { + searchContext.addError(`Note content can be searched only with operators: ${Array.from(ALLOWED_OPERATORS).join(", ")}, operator ${this.operator} given.`); return inputNoteSet; } diff --git a/src/services/search/services/parse.ts b/src/services/search/services/parse.ts index d83f4fd39..5cd408d6b 100644 --- a/src/services/search/services/parse.ts +++ b/src/services/search/services/parse.ts @@ -44,7 +44,7 @@ function getFulltext(_tokens: TokenData[], searchContext: SearchContext) { } } -const OPERATORS = [ +const OPERATORS = new Set([ "=", "!=", "*=*", @@ -55,14 +55,14 @@ const OPERATORS = [ "<", "<=", "%=" -]; +]); function isOperator(token: TokenData) { if (Array.isArray(token)) { return false; } - return OPERATORS.includes(token.token); + return OPERATORS.has(token.token); } function getExpression(tokens: TokenData[], searchContext: SearchContext, level = 0) { diff --git a/src/services/utils.ts b/src/services/utils.ts index b4155bc33..040cefc02 100644 --- a/src/services/utils.ts +++ b/src/services/utils.ts @@ -152,19 +152,19 @@ export function getContentDisposition(filename: string) { return `file; filename="${sanitizedFilename}"; filename*=UTF-8''${sanitizedFilename}`; } -const STRING_MIME_TYPES = [ +const STRING_MIME_TYPES = new Set([ "application/javascript", "application/x-javascript", "application/json", "application/x-sql", "image/svg+xml" -]; +]); export function isStringNote(type: string | undefined, mime: string) { // render and book are string note in the sense that they are expected to contain empty string return (type && ["text", "code", "relationMap", "search", "render", "book", "mermaid", "canvas"].includes(type)) || mime.startsWith('text/') - || STRING_MIME_TYPES.includes(mime); + || STRING_MIME_TYPES.has(mime); } export function quoteRegex(url: string) {