UNPKG

unified-query

Version:

Composable search input with autocompletion and a rich query-language parser for the Unified Data System

77 lines (76 loc) 1.71 kB
export const KINDS = [ 'self', 'note', 'log', 'idea', 'task', 'issue', 'image', 'concept', 'session', 'goal', 'collection', 'project', 'space', 'book', 'highlight', 'article', 'person', 'post', 'comment', 'equation', 'video', 'question', 'review', 'aichat', 'aiprompt', 'airesponse', ]; /** * `@kind` analyser * • Accepts only string tokens. * • Each string must be present in the KINDS allow-list. */ export function analyzeKind(seg) { const kinds = []; const errors = []; for (const tok of seg.tokens) { if (tok.kind === 'string') { if (KINDS.includes(tok.value)) { kinds.push(tok.value); } else { errors.push(unsupportedErr(tok)); } continue; } errors.push(invalidTokErr(tok)); } seg.errors.push(...errors); return { keyword: 'kind', parsed: kinds, from: seg.from, to: seg.to, raw: seg.raw, }; } /* -------------------------------------------------------------------------- */ /* helpers */ /* -------------------------------------------------------------------------- */ function unsupportedErr(tok) { return { message: `unsupported kind "${tok.raw}"`, token: tok.raw, from: tok.from, to: tok.to, }; } function invalidTokErr(tok) { return { message: `invalid token "${tok.raw}" for @kind (expects string kinds)`, token: tok.raw, from: tok.from, to: tok.to, }; }