localdb-ces6q 0.0.5 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LocalDB.js +7 -0
- package/package.json +1 -1
- package/types.d.ts +5 -1
package/LocalDB.js
CHANGED
@@ -138,6 +138,13 @@ export class LocalDB {
|
|
138
138
|
fieldIndexes[field] = new BTree(docs.map((d) => [d, d]), (a, b) => comparator(a[field], b[field]));
|
139
139
|
}
|
140
140
|
}
|
141
|
+
const { indexes } = config;
|
142
|
+
if (indexes) {
|
143
|
+
for (const name in indexes) {
|
144
|
+
const { compare } = indexes[name];
|
145
|
+
fieldIndexes[name] = new BTree(docs.map((d) => [d, d]), compare);
|
146
|
+
}
|
147
|
+
}
|
141
148
|
this._indexes[col] = fieldIndexes;
|
142
149
|
}
|
143
150
|
deleteCollection(col) {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
@@ -29,12 +29,16 @@ export type ICollectionFieldsConfig<Doc extends IDocument> = {
|
|
29
29
|
index?: 'asc' | 'desc';
|
30
30
|
};
|
31
31
|
};
|
32
|
+
export interface IDocumentIndexConfig<Doc extends IDocument> {
|
33
|
+
fields: Array<KeyOf<Doc>>;
|
34
|
+
compare: (a: Doc, b: Doc) => number;
|
35
|
+
}
|
32
36
|
export interface ICollectionConfig<CollectionTypes extends Record<string, IDocument>, Doc extends IDocument> {
|
33
37
|
localStorageKey?: string;
|
34
38
|
localStorageSetWait?: number;
|
35
39
|
remoteStorageKey?: string;
|
36
40
|
remoteStorageSetWait?: number;
|
37
|
-
indexes?:
|
41
|
+
indexes?: Record<string, IDocumentIndexConfig<Doc>>;
|
38
42
|
idFields?: Array<KeyOf<Doc>>;
|
39
43
|
fields: ICollectionFieldsConfig<Doc>;
|
40
44
|
computes?: Array<{
|