forked from WorldBrain/Memex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory-storex.ts
More file actions
37 lines (34 loc) · 1.21 KB
/
memory-storex.ts
File metadata and controls
37 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import UrlField from './storage/url-field'
import schemaPatcher from './storage/dexie-schema'
import collections from './old-schema'
import initStorex from './storex'
import inMemoryDb from '@worldbrain/storex-backend-dexie/lib/in-memory'
import { suggestObjects } from './search/suggest'
import { StorageManager } from './types'
import { plugins } from './storex-plugins'
import stemmerSelector from './stemmers'
export default () => {
const idbImplementation = inMemoryDb()
return initStorex<StorageManager>({
stemmerSelector,
collections,
schemaPatcher,
dbName: 'test',
customFields: [{ key: 'url', field: UrlField }],
backendPlugins: plugins,
idbImplementation,
modifyInstance(storex: StorageManager) {
const oldMethod = storex.collection.bind(storex)
storex.collection = (name: string) => ({
...oldMethod(name),
suggestObjects: (query, opts) =>
suggestObjects(async () => storex.backend['dexieInstance'])(
name,
query,
opts,
),
})
return storex
},
})
}