Skip to content

Commit

Permalink
Merge branch 'main' into feat/typing
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Aug 27, 2023
2 parents 1f3e69b + fc6e863 commit 329d7f1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
17 changes: 9 additions & 8 deletions packages/orama/src/methods/create.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { formatElapsedTime, getDocumentIndexId, getDocumentProperties, validateSchema } from '../components/defaults.js'
import { createDocumentsStore } from '../components/documents-store.js'
import { DocumentsStore, createDocumentsStore } from '../components/documents-store.js'
import { FUNCTION_COMPONENTS, OBJECT_COMPONENTS, SINGLE_OR_ARRAY_COMPONENTS } from '../components/hooks.js'
import { createIndex } from '../components/index.js'
import { Index, createIndex } from '../components/index.js'
import { createInternalDocumentIDStore } from '../components/internal-document-id-store.js'
import { createSorter } from '../components/sorter.js'
import { Sorter, createSorter } from '../components/sorter.js'
import { createTokenizer } from '../components/tokenizer/index.js'
import { createError } from '../errors.js'
import {
AfterSearch,
AnySchema,
ArrayCallbackComponents,
Components,
FunctionComponents,
Expand Down Expand Up @@ -84,11 +85,11 @@ function validateComponents<OramaSchema, TIndex, TDocumentStore, TSorter, TOrama
}

export async function create<
const OramaSchema,
TIndex,
TDocumentStore,
TSorter,
ResultOrama extends Orama<OramaSchema, TIndex, TDocumentStore, TSorter>> ({
const OramaSchema extends AnySchema,
TIndex = Index,
TDocumentStore = DocumentsStore,
TSorter = Sorter,
ResultOrama extends Orama<OramaSchema, TIndex, TDocumentStore, TSorter> = Orama<OramaSchema, TIndex, TDocumentStore, TSorter>> ({
schema,
sort,
language,
Expand Down
4 changes: 4 additions & 0 deletions packages/orama/src/methods/serialization.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { AnyOrama } from '../types.js'
import { Language } from '../index.js'

export interface RawData {
internalDocumentIDStore: unknown
index: unknown
docs: unknown
sorting: unknown
language: Language
}

export async function load<T extends AnyOrama>(orama: T, raw: RawData): Promise<void> {
orama.internalDocumentIDStore.load(orama, raw.internalDocumentIDStore)
orama.data.index = await orama.index.load(orama.internalDocumentIDStore, raw.index)
orama.data.docs = await orama.documentsStore.load(orama.internalDocumentIDStore, raw.docs)
orama.data.sorting = await orama.sorter.load(orama.internalDocumentIDStore, raw.sorting)
orama.tokenizer.language = raw.language
}

export async function save<T extends AnyOrama>(orama: T): Promise<RawData> {
Expand All @@ -20,5 +23,6 @@ export async function save<T extends AnyOrama>(orama: T): Promise<RawData> {
index: await orama.index.save(orama.data.index),
docs: await orama.documentsStore.save(orama.data.docs),
sorting: await orama.sorter.save(orama.data.sorting),
language: orama.tokenizer.language,
}
}
5 changes: 4 additions & 1 deletion packages/orama/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { DocumentsStore } from './components/documents-store.js'
import { Index } from './components/index.js'
import { DocumentID, InternalDocumentID, InternalDocumentIDStore } from './components/internal-document-id-store.js'
import { Sorter } from './components/sorter.js'
import { Language } from './components/tokenizer/languages.js'

export type Nullable<T> = T | null
Expand Down Expand Up @@ -805,7 +808,7 @@ export type PickInferGeneric<T, Default> = T extends AnyGeneric<infer Generic>
: never
: never

export type Orama<TSchema, TIndex, TDocumentStore, TSorter> = FunctionComponents<TSchema> &
export type Orama<TSchema, TIndex = Index, TDocumentStore = DocumentsStore, TSorter = Sorter> = FunctionComponents<TSchema> &
Internals<TSchema, AnyGenericIndex<TIndex>, AnyGenericDocumentStore<TDocumentStore>, AnyGenericSorter<TSorter>> &
ArrayCallbackComponents<any> &
OramaID
Expand Down
2 changes: 1 addition & 1 deletion packages/orama/tests/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import t from 'tap'
import { create, insert, getByID, update, updateMultiple, count } from '../src/index.js'
import { count, create, getByID, insert, update, updateMultiple } from '../src/index.js'

t.test('update method', t => {
t.plan(1)
Expand Down

0 comments on commit 329d7f1

Please sign in to comment.