From cdd0ec1064ff6a06fd509fbfee84450e815496d4 Mon Sep 17 00:00:00 2001 From: Tommaso Allevi Date: Fri, 11 Oct 2024 15:38:06 +0200 Subject: [PATCH] Update --- benchmarks/package.json | 1 - packages/orama/src/methods/create.ts | 12 +++++++++--- packages/orama/src/types.ts | 2 +- packages/plugin-pt15/src/index.ts | 16 ++++------------ packages/plugin-pt15/test/index.test.ts | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/benchmarks/package.json b/benchmarks/package.json index 67220ae2..ef396429 100644 --- a/benchmarks/package.json +++ b/benchmarks/package.json @@ -14,7 +14,6 @@ "orama_211": "npm:@orama/orama@2.1.1", "orama_300_rc_2": "npm:@orama/orama@3.0.0-rc-2", "orama_latest": "file:../packages/orama", - "@orama/plugin-qps": "file:../packages/plugin-qps", "@orama/stopwords": "file:../packages/stopwords", "@orama/plugin-pt15": "file:../packages/plugin-pt15" }, diff --git a/packages/orama/src/methods/create.ts b/packages/orama/src/methods/create.ts index 99a401c2..cee687c1 100644 --- a/packages/orama/src/methods/create.ts +++ b/packages/orama/src/methods/create.ts @@ -8,11 +8,13 @@ import { Sorter, createSorter } from '../components/sorter.js' import { createTokenizer } from '../components/tokenizer/index.js' import { createError } from '../errors.js' import { + AnySchema, Components, FunctionComponents, IDocumentsStore, IIndex, ISorter, + ObjectComponents, Orama, OramaPlugin, SorterConfig, @@ -70,7 +72,7 @@ function validateComponents< } export function create< - OramaSchema, + OramaSchema extends AnySchema, TIndex = IIndex, TDocumentStore = IDocumentsStore, TSorter = ISorter @@ -94,14 +96,18 @@ export function create< continue; } - const pluginComponents = plugin.getComponents(schema); + const pluginComponents = plugin.getComponents(schema) as Partial>; const keys = Object.keys(pluginComponents) for (const key of keys) { - if (components[key]) { + if (components![key]) { throw createError('PLUGIN_COMPONENT_CONFLICT', key, plugin.name) } } + components = { + ...components, + ...pluginComponents + } } if (!id) { diff --git a/packages/orama/src/types.ts b/packages/orama/src/types.ts index 928b2dae..3e0c5c1c 100644 --- a/packages/orama/src/types.ts +++ b/packages/orama/src/types.ts @@ -1315,7 +1315,7 @@ export type OramaPluginSync = { beforeUpdateMultiple?: (orama: T, docs: AnyDocument[]) => SyncOrAsyncValue afterUpdateMultiple?: (orama: T, docs: AnyDocument[]) => SyncOrAsyncValue afterCreate?: (orama: T) => SyncOrAsyncValue - getComponents?: (schema: T['schema']) => SyncOrAsyncValue> + getComponents?: , TDocumentStore, TSorter>(schema: AnySchema) => SyncOrAsyncValue>> } export type OramaPluginAsync = Promise> diff --git a/packages/plugin-pt15/src/index.ts b/packages/plugin-pt15/src/index.ts index 668a77f5..bd673f3c 100644 --- a/packages/plugin-pt15/src/index.ts +++ b/packages/plugin-pt15/src/index.ts @@ -1,32 +1,24 @@ -import type { create, AnyOrama, SearchableType, IIndex, AnyIndexStore, SearchableValue, Tokenizer, OnlyStrings, FlattenSchemaProperty, TokenScore, WhereCondition, OramaPluginSync } from '@orama/orama' +import type { AnyOrama, SearchableType, IIndex, AnyIndexStore, SearchableValue, Tokenizer, OnlyStrings, FlattenSchemaProperty, TokenScore, WhereCondition, OramaPluginSync, AnySchema, ObjectComponents } from '@orama/orama' import { index as Index, internalDocumentIDStore } from '@orama/orama/components' import { PT15IndexStore, insertString, recursiveCreate, PositionsStorage, searchString } from './algorithm.js'; type InternalDocumentID = internalDocumentIDStore.InternalDocumentID; type InternalDocumentIDStore = internalDocumentIDStore.InternalDocumentIDStore; - -type CreateParams = Parameters>>[0] -type Component = NonNullable -type IndexParameter = NonNullable type DocumentID = internalDocumentIDStore.DocumentID; - export function pluginPT15(): OramaPluginSync { return { name: 'orama-plugin-pt15', - getComponents: function getComponents(schema: T['schema']) { + getComponents: function getComponents(schema: AnySchema) { return createComponents(schema) - } + }, } } -function createComponents(schema: T['schema']): { - index: IndexParameter, -} { - +function createComponents(schema: AnySchema): Partial> { return { index: { create: function create() { diff --git a/packages/plugin-pt15/test/index.test.ts b/packages/plugin-pt15/test/index.test.ts index 1ec346f2..aa53b949 100644 --- a/packages/plugin-pt15/test/index.test.ts +++ b/packages/plugin-pt15/test/index.test.ts @@ -36,7 +36,7 @@ t.test('get_position', async t => { t.equal(get_position(49, 50), 14) }) -t.test('plugin-position', async t => { +t.test('plugin-pt15', async t => { const db = create({ schema: { name: 'string',