Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lokidb/full-text-search

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lokidb/full-text-search - npm Package Compare versions

Comparing version 2.0.0-beta.7 to 2.0.0-beta.8

types/loki/src/avl_index.d.ts

4

package.json

@@ -13,5 +13,5 @@ {

"optionalDependencies": {
"@lokidb/loki": "2.0.0-beta.7"
"@lokidb/loki": "2.0.0-beta.8"
},
"version": "2.0.0-beta.7"
"version": "2.0.0-beta.8"
}
/**
* @hidden
*/
import { Loki } from "../loki/src";
import { Loki } from "../loki/src/loki";
export interface StorageAdapter {

@@ -6,0 +6,0 @@ loadDatabase(dbname: string): Promise<any>;

@@ -5,2 +5,3 @@ import { LokiEventEmitter } from "./event_emitter";

import { DynamicView } from "./dynamic_view";
import { IRangedIndex } from "./ranged_indexes";
import { CloneMethod } from "./clone";

@@ -10,3 +11,2 @@ import { Doc, Dict } from "../../common/types";

import { Analyzer } from "../../full-text-search/src/analyzer/analyzer";
export { CloneMethod } from "./clone";
/**

@@ -18,9 +18,14 @@ * Collection class that handles documents of same type

*/
export declare class Collection<TData extends object = object, TNested extends object = object> extends LokiEventEmitter {
export declare class Collection<TData extends object = object, TNested extends object = object, T extends TData & TNested = TData & TNested> extends LokiEventEmitter {
name: string;
_data: Doc<TData & TNested>[];
_data: Doc<T>[];
private _idIndex;
_binaryIndices: {
[P in keyof (TData & TNested)]?: Collection.BinaryIndex;
_rangedIndexes: {
[P in keyof T]?: Collection.RangedIndexMeta;
};
_lokimap: {
[$loki: number]: Doc<T>;
};
_unindexedSortComparator: string;
_defaultLokiOperatorPackage: string;
/**

@@ -32,3 +37,3 @@ * Unique constraints contain duplicate object references, so they are not persisted.

unique: {
[P in keyof (TData & TNested)]?: UniqueIndex<TData & TNested>;
[P in keyof T]?: UniqueIndex;
};

@@ -40,3 +45,3 @@ };

*/
_transforms: Dict<Collection.Transform<TData, TNested>[]>;
_transforms: Dict<Collection.Transform<T>[]>;
/**

@@ -50,7 +55,2 @@ * In autosave scenarios we will use collection level dirty flags to determine whether save is needed.

/**
* If set to true we will optimally keep indices 'fresh' during insert/update/remove ops (never dirty/never needs rebuild).
* If you frequently intersperse insert/update/remove ops between find ops this will likely be significantly faster option.
*/
_adaptiveBinaryIndices: boolean;
/**
* Is collection transactional.

@@ -80,7 +80,5 @@ */

/**
* By default, if you insert a document into a collection with binary indices, if those indexed properties contain
* a DateTime we will convert to epoch time format so that (across serializations) its value position will be the
* same 'after' serialization as it was 'before'.
* By default, if you insert a document with a Date value for an indexed property, we will convert that value to number.
*/
private _serializableIndices;
private _serializableIndexes;
/**

@@ -112,4 +110,3 @@ * Name of path of used nested properties.

* @param {string[]} [options.exact=[]] - array of property names to define exact constraints for
* @param {string[]} [options.indices=[]] - array property names to define binary indexes for
* @param {boolean} [options.adaptiveBinaryIndices=true] - collection indices will be actively rebuilt rather than lazily
* @param {RangedIndexOptions} [options.rangedIndexes] - configuration object for ranged indexes
* @param {boolean} [options.asyncListeners=false] - whether listeners are invoked asynchronously

@@ -120,3 +117,3 @@ * @param {boolean} [options.disableMeta=false] - set to true to disable meta property on documents

* @param {boolean} [options.clone=false] - specify whether inserts and queries clone to/from user
* @param {boolean} [options.serializableIndices =true] - converts date values on binary indexed property values are serializable
* @param {boolean} [options.serializableIndexes=true] - converts date values on binary indexed property values are serializable
* @param {string} [options.cloneMethod="deep"] - the clone method

@@ -126,2 +123,4 @@ * @param {number} [options.transactional=false] - ?

* @param {number} [options.ttlInterval=] - time interval for clearing out 'aged' documents; not set by default
* @param {string} [options.unindexedSortComparator="js"] "js", "abstract", "abstract-date", "loki" or other registered comparator name
* @param {string} [options.defaultLokiOperatorPackage="js"] "js", "loki", "comparator" (or user defined) query ops package
* @param {FullTextSearch.FieldOptions} [options.fullTextSearch=] - the full-text search options

@@ -132,3 +131,3 @@ * @see {@link Loki#addCollection} for normal creation of collections

toJSON(): Collection.Serialized;
static fromJSONObject(obj: Collection.Serialized, options?: Collection.DeserializeOptions): Collection<any, object>;
static fromJSONObject(obj: Collection.Serialized, options?: Collection.DeserializeOptions): Collection<any, object, any>;
/**

@@ -139,3 +138,3 @@ * Adds a named collection transform to the collection

*/
addTransform(name: string, transform: Collection.Transform<TData, TNested>[]): void;
addTransform(name: string, transform: Collection.Transform<T>[]): void;
/**

@@ -145,3 +144,3 @@ * Retrieves a named transform from the collection.

*/
getTransform(name: string): Collection.Transform<TData, TNested>[];
getTransform(name: string): Collection.Transform<T>[];
/**

@@ -152,3 +151,3 @@ * Updates a named collection transform to the collection

*/
setTransform(name: string, transform: Collection.Transform<TData, TNested>[]): void;
setTransform(name: string, transform: Collection.Transform<T>[]): void;
/**

@@ -165,55 +164,17 @@ * Removes a named collection transform from the collection

/**
* Ensure binary index on a certain field.
* @param {string} field - the field name
* @param {boolean} [force=false] - flag indicating whether to construct index immediately
* Ensure rangedIndex of a field.
* @param field
* @param indexTypeName
* @param comparatorName
*/
ensureIndex(field: keyof (TData & TNested), force?: boolean): void;
ensureIndex(field: string, indexTypeName?: string, comparatorName?: string): void;
/**
* Perform checks to determine validity/consistency of a binary index.
* @param {string} field - the field name of the binary-indexed to check
* @param {object=} options - optional configuration object
* @param {boolean} [options.randomSampling=false] - whether (faster) random sampling should be used
* @param {number} [options.randomSamplingFactor=0.10] - percentage of total rows to randomly sample
* @param {boolean} [options.repair=false] - whether to fix problems if they are encountered
* @returns {boolean} whether the index was found to be valid (before optional correcting).
* @example
* // full test
* var valid = coll.checkIndex('name');
* // full test with repair (if issues found)
* valid = coll.checkIndex('name', { repair: true });
* // random sampling (default is 10% of total document count)
* valid = coll.checkIndex('name', { randomSampling: true });
* // random sampling (sample 20% of total document count)
* valid = coll.checkIndex('name', { randomSampling: true, randomSamplingFactor: 0.20 });
* // random sampling (implied boolean)
* valid = coll.checkIndex('name', { randomSamplingFactor: 0.20 });
* // random sampling with repair (if issues found)
* valid = coll.checkIndex('name', { repair: true, randomSampling: true });
* Ensure rangedIndex of a field.
* @param field Property to create an index on (need to look into contraining on keyof T)
* @param indexTypeName Name of IndexType factory within (global?) hashmap to create IRangedIndex from
* @param comparatorName Name of Comparator within (global?) hashmap
*/
checkIndex(field: keyof (TData & TNested), options?: Collection.CheckIndexOptions): boolean;
ensureRangedIndex(field: string, indexTypeName?: string, comparatorName?: string): void;
ensureUniqueIndex(field: keyof T): UniqueIndex;
/**
* Perform checks to determine validity/consistency of all binary indices
* @param {object=} options - optional configuration object
* @param {boolean} [options.randomSampling=false] - whether (faster) random sampling should be used
* @param {number} [options.randomSamplingFactor=0.10] - percentage of total rows to randomly sample
* @param {boolean} [options.repair=false] - whether to fix problems if they are encountered
* @returns {string[]} array of index names where problems were found
* @example
* // check all indices on a collection, returns array of invalid index names
* var result = coll.checkAllIndexes({ repair: true, randomSampling: true, randomSamplingFactor: 0.15 });
* if (result.length > 0) {
* results.forEach(function(name) {
* console.log('problem encountered with index : ' + name);
* });
* }
*/
checkAllIndexes(options?: Collection.CheckIndexOptions): (keyof TData & TNested)[];
ensureUniqueIndex(field: keyof (TData & TNested)): UniqueIndex<TData & TNested>;
/**
* Ensure all binary indices.
*/
ensureAllIndexes(force?: boolean): void;
flagBinaryIndexesDirty(): void;
flagBinaryIndexDirty(index: keyof (TData & TNested)): void;
/**
* Quickly determine number of documents in collection (or query)

@@ -223,3 +184,3 @@ * @param {object} query - (optional) query object to count results of

*/
count(query?: ResultSet.Query<Doc<TData & TNested>>): number;
count(query?: ResultSet.Query<Doc<T>>): number;
/**

@@ -238,3 +199,3 @@ * Rebuild idIndex

**/
addDynamicView(name: string, options?: DynamicView.Options): DynamicView<TData, TNested>;
addDynamicView(name: string, options?: DynamicView.Options): DynamicView<T>;
/**

@@ -250,3 +211,3 @@ * Remove a dynamic view from the collection

**/
getDynamicView(name: string): DynamicView<TData, TNested>;
getDynamicView(name: string): DynamicView<T>;
/**

@@ -257,3 +218,3 @@ * Applies a 'mongo-like' find query object and passes all results to an update function.

*/
findAndUpdate(filterObject: ResultSet.Query<Doc<TData & TNested>>, updateFunction: (obj: Doc<TData>) => any): void;
findAndUpdate(filterObject: ResultSet.Query<Doc<T>>, updateFunction: (obj: Doc<T>) => any): void;
/**

@@ -263,3 +224,3 @@ * Applies a 'mongo-like' find query object removes all documents which match that filter.

*/
findAndRemove(filterObject: ResultSet.Query<Doc<TData & TNested>>): void;
findAndRemove(filterObject: ResultSet.Query<Doc<T>>): void;
/**

@@ -270,4 +231,4 @@ * Adds object(s) to collection, ensure object(s) have meta properties, clone it if necessary, etc.

*/
insert(doc: TData): Doc<TData & TNested>;
insert(doc: TData[]): Doc<TData & TNested>[];
insert(doc: TData): Doc<T>;
insert(doc: TData[]): Doc<T>[];
/**

@@ -279,3 +240,3 @@ * Adds a single object, ensures it has meta properties, clone it if necessary, etc.

*/
insertOne(doc: TData, bulkInsert?: boolean): Doc<TData & TNested>;
insertOne(doc: TData, bulkInsert?: boolean): Doc<T>;
/**

@@ -287,3 +248,3 @@ * Refers nested properties of an object to the root of it.

*/
_defineNestedProperties<T extends object>(data: T): T & TNested;
_defineNestedProperties<U extends TData>(data: U): U & TNested;
/**

@@ -300,3 +261,3 @@ * Empties the collection.

*/
update(doc: Doc<TData & TNested> | Doc<TData & TNested>[]): void;
update(doc: Doc<T> | Doc<T>[]): void;
/**

@@ -311,3 +272,3 @@ * Add object to collection

*/
updateWhere(filterFunction: (obj: Doc<TData & TNested>) => boolean, updateFunction: (obj: Doc<TData & TNested>) => Doc<TData & TNested>): void;
updateWhere(filterFunction: (obj: Doc<T>) => boolean, updateFunction: (obj: Doc<T>) => Doc<T>): void;
/**

@@ -317,3 +278,3 @@ * Remove all documents matching supplied filter function.

*/
removeWhere(filterFunction: (obj: Doc<TData & TNested>) => boolean): void;
removeWhere(filterFunction: (obj: Doc<T>) => boolean): void;
removeDataOnly(): void;

@@ -324,3 +285,3 @@ /**

*/
remove(doc: number | Doc<TData & TNested> | Doc<TData & TNested>[]): void;
remove(doc: number | Doc<T> | Doc<T>[]): void;
/**

@@ -364,63 +325,5 @@ * Returns all changes.

*/
get(id: number): Doc<TData & TNested>;
get(id: number, returnPosition: boolean): Doc<TData & TNested> | [Doc<TData & TNested>, number];
get(id: number): Doc<T>;
get(id: number, returnPosition: boolean): Doc<T> | [Doc<T>, number];
/**
* Perform binary range lookup for the data[dataPosition][binaryIndexName] property value
* Since multiple documents may contain the same value (which the index is sorted on),
* we hone in on range and then linear scan range to find exact index array position.
* @param {int} dataPosition : data array index/position
* @param {string} binaryIndexName : index to search for dataPosition in
*/
getBinaryIndexPosition(dataPosition: number, binaryIndexName: keyof (TData & TNested)): number;
/**
* Adaptively insert a selected item to the index.
* @param {int} dataPosition : coll.data array index/position
* @param {string} binaryIndexName : index to search for dataPosition in
*/
adaptiveBinaryIndexInsert(dataPosition: number, binaryIndexName: keyof (TData & TNested)): void;
/**
* Adaptively update a selected item within an index.
* @param {int} dataPosition : coll.data array index/position
* @param {string} binaryIndexName : index to search for dataPosition in
*/
adaptiveBinaryIndexUpdate(dataPosition: number, binaryIndexName: keyof (TData & TNested)): void;
/**
* Adaptively remove a selected item from the index.
* @param {number} dataPosition : coll.data array index/position
* @param {string} binaryIndexName : index to search for dataPosition in
* @param {boolean} removedFromIndexOnly - remove from index only
*/
adaptiveBinaryIndexRemove(dataPosition: number, binaryIndexName: keyof (TData & TNested), removedFromIndexOnly?: boolean): void;
/**
* Internal method used for index maintenance and indexed searching.
* Calculates the beginning of an index range for a given value.
* For index maintainance (adaptive:true), we will return a valid index position to insert to.
* For querying (adaptive:false/undefined), we will :
* return lower bound/index of range of that value (if found)
* return next lower index position if not found (hole)
* If index is empty it is assumed to be handled at higher level, so
* this method assumes there is at least 1 document in index.
*
* @param {string} prop - name of property which has binary index
* @param {any} val - value to find within index
* @param {bool?} adaptive - if true, we will return insert position
*/
private _calculateRangeStart(prop, val, adaptive?);
/**
* Internal method used for indexed $between. Given a prop (index name), and a value
* (which may or may not yet exist) this will find the final position of that upper range value.
*/
private _calculateRangeEnd(prop, val);
/**
* Binary Search utility method to find range/segment of values matching criteria.
* this is used for collection.find() and first find filter of ResultSet/dynview
* slightly different than get() binary search in that get() hones in on 1 value,
* but we have to hone in on many (range)
* @param {string} op - operation, such as $eq
* @param {string} prop - name of property to calculate range for
* @param {object} val - value to use for range calculation.
* @returns {array} [start, end] index array positions
*/
calculateRange(op: string, prop: keyof (TData & TNested), val: any): [number, number];
/**
* Retrieve doc by Unique index

@@ -431,3 +334,3 @@ * @param {string} field - name of uniquely indexed property to use when doing lookup

*/
by(field: keyof (TData & TNested), value: any): Doc<TData & TNested>;
by(field: keyof T, value: any): Doc<T>;
/**

@@ -438,3 +341,3 @@ * Find one object by index property, by property equal to value

*/
findOne(query: ResultSet.Query<Doc<TData & TNested>>): Doc<TData & TNested>;
findOne(query: ResultSet.Query<Doc<T>>): Doc<T>;
/**

@@ -448,3 +351,3 @@ * Chain method, used for beginning a series of chained find() and/or view() operations

*/
chain(transform?: string | Collection.Transform<TData, TNested>[], parameters?: object): ResultSet<TData, TNested>;
chain(transform?: string | Collection.Transform<T>[], parameters?: object): ResultSet<T>;
/**

@@ -457,3 +360,3 @@ * Find method, api is similar to mongodb.

*/
find(query?: ResultSet.Query<Doc<TData & TNested>>): Doc<TData & TNested>[];
find(query?: ResultSet.Query<Doc<T>>): Doc<T>[];
/**

@@ -463,3 +366,3 @@ * Find object by unindexed field by property equal to value,

*/
findOneUnindexed(prop: string, value: any): Doc<TData & TNested>;
findOneUnindexed(prop: string, value: any): Doc<T>;
/**

@@ -489,3 +392,3 @@ * Transaction methods

*/
where(fun: (obj: Doc<TData & TNested>) => boolean): Doc<TData & TNested>[];
where(fun: (obj: Doc<T>) => boolean): Doc<T>[];
/**

@@ -497,3 +400,3 @@ * Map Reduce operation

*/
mapReduce<T, U>(mapFunction: (value: Doc<TData & TNested>, index: number, array: Doc<TData & TNested>[]) => T, reduceFunction: (array: T[]) => U): U;
mapReduce<U1, U2>(mapFunction: (value: Doc<T>, index: number, array: Doc<T>[]) => U1, reduceFunction: (array: U1[]) => U2): U2;
/**

@@ -535,3 +438,3 @@ * Join two collections on specified properties

*/
extract(field: keyof (TData & TNested)): any[];
extract(field: keyof T): any[];
/**

@@ -542,3 +445,3 @@ * Finds the minimum value of a field.

*/
min(field: keyof (TData & TNested)): number;
min(field: keyof T): number;
/**

@@ -549,3 +452,3 @@ * Finds the maximum value of a field.

*/
max(field: keyof (TData & TNested)): number;
max(field: keyof T): number;
/**

@@ -556,3 +459,3 @@ * Finds the minimum value and its index of a field.

*/
minRecord(field: keyof (TData & TNested)): {
minRecord(field: keyof T): {
index: number;

@@ -566,3 +469,3 @@ value: number;

*/
maxRecord(field: keyof (TData & TNested)): {
maxRecord(field: keyof T): {
index: number;

@@ -576,3 +479,3 @@ value: number;

*/
extractNumerical(field: keyof (TData & TNested)): number[];
extractNumerical(field: keyof T): number[];
/**

@@ -583,3 +486,3 @@ * Calculates the average numerical value of a field

*/
avg(field: keyof (TData & TNested)): number;
avg(field: keyof T): number;
/**

@@ -590,3 +493,3 @@ * Calculate the standard deviation of a field.

*/
stdDev(field: keyof (TData & TNested)): number;
stdDev(field: keyof T): number;
/**

@@ -597,3 +500,3 @@ * Calculates the mode of a field.

*/
mode(field: keyof (TData & TNested)): number;
mode(field: keyof T): number;
/**

@@ -604,9 +507,11 @@ * Calculates the median of a field.

*/
median(field: keyof (TData & TNested)): number;
median(field: keyof T): number;
}
export declare namespace Collection {
interface Options<TData extends object, TNested extends object = {}> {
unique?: (keyof (TData & TNested))[];
indices?: (keyof (TData & TNested))[];
adaptiveBinaryIndices?: boolean;
interface Options<TData extends object, TNested extends object = {}, T extends object = TData & TNested> {
unique?: (keyof T)[];
unindexedSortComparator?: string;
defaultLokiOperatorPackage?: string;
rangedIndexes?: RangedIndexOptions;
serializableIndexes?: boolean;
asyncListeners?: boolean;

@@ -628,2 +533,5 @@ disableMeta?: boolean;

}
interface RangedIndexOptions {
[prop: string]: RangedIndexMeta;
}
interface DeserializeOptions {

@@ -641,2 +549,7 @@ retainDirtyFlags?: boolean;

}
interface RangedIndexMeta {
index?: IRangedIndex<any>;
indexTypeName?: string;
comparatorName?: string;
}
interface Change {

@@ -649,2 +562,4 @@ name: string;

name: string;
unindexedSortComparator: string;
defaultLokiOperatorPackage: string;
_dynamicViews: DynamicView[];

@@ -657,3 +572,3 @@ _nestedProperties: {

transforms: Dict<Transform[]>;
binaryIndices: Dict<Collection.BinaryIndex>;
rangedIndexes: RangedIndexOptions;
_data: Doc<any>[];

@@ -663,3 +578,2 @@ idIndex: number[];

_dirty: boolean;
adaptiveBinaryIndices: boolean;
transactional: boolean;

@@ -680,18 +594,18 @@ asyncListeners: boolean;

}
type Transform<TData extends object = object, TNested extends object = object> = {
type Transform<T extends object = object> = {
type: "find";
value: ResultSet.Query<Doc<TData & TNested>> | string;
value: ResultSet.Query<Doc<T>> | string;
} | {
type: "where";
value: ((obj: Doc<TData & TNested>) => boolean) | string;
value: ((obj: Doc<T>) => boolean) | string;
} | {
type: "simplesort";
property: keyof (TData & TNested);
property: keyof T;
options?: boolean | ResultSet.SimpleSortOptions;
} | {
type: "compoundsort";
value: (keyof (TData & TNested) | [keyof (TData & TNested), boolean])[];
value: (keyof T | [keyof T, boolean])[];
} | {
type: "sort";
value: (a: Doc<TData & TNested>, b: Doc<TData & TNested>) => number;
value: (a: Doc<T>, b: Doc<T>) => number;
} | {

@@ -708,3 +622,3 @@ type: "sortByScoring";

type: "map";
value: (obj: Doc<TData & TNested>, index: number, array: Doc<TData & TNested>[]) => any;
value: (obj: Doc<T>, index: number, array: Doc<T>[]) => any;
dataOptions?: ResultSet.DataOptions;

@@ -720,7 +634,7 @@ } | {

type: "mapReduce";
mapFunction: (item: Doc<TData & TNested>, index: number, array: Doc<TData & TNested>[]) => any;
mapFunction: (item: Doc<T>, index: number, array: Doc<T>[]) => any;
reduceFunction: (array: any[]) => any;
} | {
type: "update";
value: (obj: Doc<TData & TNested>) => any;
value: (obj: Doc<T>) => any;
} | {

@@ -727,0 +641,0 @@ type: "remove";

@@ -24,3 +24,3 @@ import { LokiEventEmitter } from "./event_emitter";

*/
export declare class DynamicView<TData extends object = object, TNested extends object = object> extends LokiEventEmitter {
export declare class DynamicView<T extends object = object> extends LokiEventEmitter {
readonly name: string;

@@ -51,3 +51,3 @@ private _collection;

*/
constructor(collection: Collection<TData, TNested>, name: string, options?: DynamicView.Options);
constructor(collection: Collection<T>, name: string, options?: DynamicView.Options);
/**

@@ -72,3 +72,3 @@ * Internally used immediately after deserialization (loading)

*/
branchResultSet(transform?: string | Collection.Transform<TData, TNested>[], parameters?: object): ResultSet<TData, TNested>;
branchResultSet(transform?: string | Collection.Transform<T>[], parameters?: object): ResultSet<T>;
/**

@@ -98,3 +98,3 @@ * Override of toJSON to avoid circular references.

*/
applySort(comparefun: (lhs: Doc<TData & TNested>, rhs: Doc<TData & TNested>) => number): this;
applySort(comparefun: (lhs: Doc<T>, rhs: Doc<T>) => number): this;
/**

@@ -112,3 +112,3 @@ * Used to specify a property used for view translation.

*/
applySimpleSort(field: keyof (TData & TNested), options?: boolean | ResultSet.SimpleSortOptions): this;
applySimpleSort(field: keyof T, options?: boolean | ResultSet.SimpleSortOptions): this;
/**

@@ -126,3 +126,3 @@ * Allows sorting a ResultSet based on multiple columns.

*/
applySortCriteria(criteria: (keyof (TData & TNested) | [keyof (TData & TNested), boolean])[]): this;
applySortCriteria(criteria: (keyof T | [keyof T, boolean])[]): this;
/**

@@ -176,3 +176,3 @@ * Used to apply a sort by the latest full-text-search scoring.

*/
applyFilter(filter: DynamicView.Filter<TData, TNested>): this;
applyFilter(filter: DynamicView.Filter<T>): this;
/**

@@ -192,3 +192,3 @@ * applyFind() - Adds or updates a mongo-style query option in the DynamicView filter pipeline

*/
applyWhere(fun: (obj: Doc<TData & TNested>) => boolean, uid?: string | number): this;
applyWhere(fun: (obj: Doc<T>) => boolean, uid?: string | number): this;
/**

@@ -216,3 +216,3 @@ * Remove the specified filter from the DynamicView filter pipeline

*/
data(options?: ResultSet.DataOptions): Doc<TData & TNested>[];
data(options?: ResultSet.DataOptions): Doc<T>[];
/**

@@ -252,3 +252,3 @@ * When the view is not sorted we may still wish to be notified of rebuild events.

*/
mapReduce<T, U>(mapFunction: (item: TData, index: number, array: TData[]) => T, reduceFunction: (array: T[]) => U): U;
mapReduce<U1, U2>(mapFunction: (item: T, index: number, array: T[]) => U1, reduceFunction: (array: U1[]) => U2): U2;
}

@@ -277,11 +277,11 @@ export declare namespace DynamicView {

}
type Filter<TData extends object = object, TNested extends object = object> = {
type Filter<T extends object = object> = {
type: "find";
val: ResultSet.Query<Doc<TData & TNested>>;
val: ResultSet.Query<Doc<T>>;
uid: number | string;
} | {
type: "where";
val: (obj: Doc<TData & TNested>) => boolean;
val: (obj: Doc<T>) => boolean;
uid: number | string;
};
}
import { LokiEventEmitter } from "./event_emitter";
import { Collection } from "./collection";
import { Doc, StorageAdapter } from "../../common/types";
import { IComparatorMap } from "./comparators";
import { IRangedIndexFactoryMap } from "./ranged_indexes";
import { ILokiOperatorPackageMap } from "./operator_packages";
export declare class Loki extends LokiEventEmitter {

@@ -28,2 +31,5 @@ filename: string;

* @param {string} [options.destructureDelimiter="$<\n"] - string delimiter used for destructured serialization
* @param {IComparatorMap} [options.comparatorMap] allows injecting or overriding registered comparators
* @param {IRangedIndexFactoryMap} [options.rangedIndexFactoryMap] allows injecting or overriding registered ranged index factories
* @param {ILokiOperatorPackageMap} [options.lokiOperatorPackageMap] allows injecting or overriding registered loki operator packages
*/

@@ -284,2 +290,5 @@ constructor(filename?: string, options?: Loki.Options);

destructureDelimiter?: string;
comparatorMap?: IComparatorMap;
rangedIndexFactoryMap?: IRangedIndexFactoryMap;
lokiOperatorPackageMap?: ILokiOperatorPackageMap;
}

@@ -286,0 +295,0 @@ interface PersistenceOptions {

@@ -7,39 +7,2 @@ import { Collection } from "./collection";

/**
* @hidden
*/
export declare const LokiOps: {
$eq(a: any, b: any): boolean;
$aeq(a: any, b: any): boolean;
$ne(a: any, b: any): boolean;
$dteq(a: any, b: any): boolean;
$gt(a: any, b: any): boolean;
$gte(a: any, b: any): boolean;
$lt(a: any, b: any): boolean;
$lte(a: any, b: any): boolean;
$between(a: any, range: [any, any]): boolean;
$jgt(a: any, b: any): boolean;
$jgte(a: any, b: any): boolean;
$jlt(a: any, b: any): boolean;
$jlte(a: any, b: any): boolean;
$jbetween(a: any, range: [any, any]): boolean;
$in(a: any, b: any): boolean;
$nin(a: any, b: any): boolean;
$keyin(a: string, b: object): boolean;
$nkeyin(a: string, b: object): boolean;
$definedin(a: string, b: object): boolean;
$undefinedin(a: string, b: object): boolean;
$regex(a: string, b: RegExp): boolean;
$containsNone(a: any, b: any): boolean;
$containsAny(a: any, b: any): boolean;
$contains(a: any, b: any): boolean;
$type(a: any, b: any): boolean;
$finite(a: number, b: boolean): boolean;
$size(a: any, b: any): boolean;
$len(a: any, b: any): boolean;
$where(a: any, b: any): boolean;
$not(a: any, b: any): boolean;
$and(a: any, b: any): boolean;
$or(a: any, b: any): boolean;
};
/**
* ResultSet class allowing chainable queries. Intended to be instanced internally.

@@ -57,4 +20,4 @@ * Collection.find(), Collection.where(), and Collection.chain() instantiate this.

*/
export declare class ResultSet<TData extends object = object, TNested extends object = object> {
_collection: Collection<TData, TNested>;
export declare class ResultSet<T extends object = object> {
_collection: Collection<T>;
_filteredRows: number[];

@@ -67,3 +30,3 @@ _filterInitialized: boolean;

*/
constructor(collection: Collection<TData, TNested>);
constructor(collection: Collection<T>);
/**

@@ -77,3 +40,3 @@ * Reset the ResultSet to its initial state.

*/
toJSON(): ResultSet<TData, TNested>;
toJSON(): ResultSet<T>;
/**

@@ -96,3 +59,3 @@ * Allows you to limit the number of documents passed to next chain operation.

*/
copy(): ResultSet<TData, TNested>;
copy(): ResultSet<T>;
/**

@@ -104,3 +67,3 @@ * Executes a named collection transform or raw array of transform steps against the ResultSet.

*/
transform(transform: string | Collection.Transform<TData, TNested>[], parameters?: object): this;
transform(transform: string | Collection.Transform<T>[], parameters?: object): this;
/**

@@ -117,3 +80,3 @@ * User supplied compare function is provided two documents to compare. (chainable)

*/
sort(comparefun: (a: Doc<TData & TNested>, b: Doc<TData & TNested>) => number): this;
sort(comparefun: (a: Doc<T>, b: Doc<T>) => number): this;
/**

@@ -125,8 +88,6 @@ * Simpler, loose evaluation for user to sort based on a property name. (chainable).

* @param {boolean} [options.desc=false] - whether to sort descending
* @param {boolean} [options.disableIndexIntersect=false] - whether we should explicitly not use array intersection.
* @param {boolean} [options.forceIndexIntersect=false] - force array intersection (if binary index exists).
* @param {boolean} [options.useJavascriptSorting=false] - whether results are sorted via basic javascript sort.
* @param {string} [options.sortComparator] override default with name of comparator registered in ComparatorMap
* @returns {ResultSet} Reference to this ResultSet, sorted, for future chain operations.
*/
simplesort(propname: keyof (TData & TNested), options?: boolean | ResultSet.SimpleSortOptions): this;
simplesort(propname: keyof T, options?: boolean | ResultSet.SimpleSortOptions): this;
/**

@@ -142,3 +103,3 @@ * Allows sorting a ResultSet based on multiple columns.

*/
compoundsort(properties: (keyof (TData & TNested) | [keyof (TData & TNested), boolean])[]): this;
compoundsort(properties: (keyof T | [keyof T, boolean])[]): this;
/**

@@ -171,4 +132,4 @@ * Helper function for compoundsort(), performing individual object comparisons

*/
findOr(expressionArray: ResultSet.Query<Doc<TData & TNested>>[]): this;
$or(expressionArray: ResultSet.Query<Doc<TData & TNested>>[]): this;
findOr(expressionArray: ResultSet.Query<Doc<T>>[]): this;
$or(expressionArray: ResultSet.Query<Doc<T>>[]): this;
/**

@@ -182,4 +143,4 @@ * Oversee the operation of AND'ed query expressions.

*/
findAnd(expressionArray: ResultSet.Query<Doc<TData & TNested>>[]): this;
$and(expressionArray: ResultSet.Query<Doc<TData & TNested>>[]): this;
findAnd(expressionArray: ResultSet.Query<Doc<T>>[]): this;
$and(expressionArray: ResultSet.Query<Doc<T>>[]): this;
/**

@@ -192,3 +153,3 @@ * Used for querying via a mongo-style query object.

*/
find(query?: ResultSet.Query<Doc<TData & TNested>>, firstOnly?: boolean): this;
find(query?: ResultSet.Query<Doc<T>>, firstOnly?: boolean): this;
/**

@@ -199,3 +160,3 @@ * Used for filtering via a javascript filter function.

*/
where(fun: (obj: Doc<TData & TNested>) => boolean): this;
where(fun: (obj: Doc<T>) => boolean): this;
/**

@@ -217,3 +178,3 @@ * Returns the number of documents in the ResultSet.

*/
data(options?: ResultSet.DataOptions): Doc<TData & TNested>[];
data(options?: ResultSet.DataOptions): Doc<T>[];
/**

@@ -224,3 +185,3 @@ * Used to run an update operation on all documents currently in the ResultSet.

*/
update(updateFunction: (obj: Doc<TData & TNested>) => Doc<TData & TNested>): this;
update(updateFunction: (obj: Doc<T>) => Doc<T>): this;
/**

@@ -238,3 +199,3 @@ * Removes all document objects which are currently in ResultSet from collection (as well as ResultSet)

*/
mapReduce<T, U>(mapFunction: (item: Doc<TData & TNested>, index: number, array: Doc<TData & TNested>[]) => T, reduceFunction: (array: T[]) => U): U;
mapReduce<U1, U2>(mapFunction: (item: Doc<T>, index: number, array: Doc<T>[]) => U1, reduceFunction: (array: U1[]) => U2): U2;
/**

@@ -253,3 +214,3 @@ * Left joining two sets of data. Join keys can be defined or calculated properties

*/
eqJoin(joinData: Collection<any> | ResultSet<any> | any[], leftJoinKey: string | ((obj: any) => string), rightJoinKey: string | ((obj: any) => string), mapFun?: (left: any, right: any) => any, dataOptions?: ResultSet.DataOptions): ResultSet<any, any>;
eqJoin(joinData: Collection<any> | ResultSet<any> | any[], leftJoinKey: string | ((obj: any) => string), rightJoinKey: string | ((obj: any) => string), mapFun?: (left: any, right: any) => any, dataOptions?: ResultSet.DataOptions): ResultSet<any>;
/**

@@ -264,3 +225,3 @@ * Applies a map function into a new collection for further chaining.

*/
map<U extends object>(mapFun: (obj: Doc<TData & TNested>, index: number, array: Doc<TData & TNested>[]) => U, dataOptions?: ResultSet.DataOptions): ResultSet<U>;
map<U extends object>(mapFun: (obj: Doc<T>, index: number, array: Doc<T>[]) => U, dataOptions?: ResultSet.DataOptions): ResultSet<U>;
}

@@ -275,5 +236,3 @@ export declare namespace ResultSet {

desc?: boolean;
disableIndexIntersect?: boolean;
forceIndexIntersect?: boolean;
useJavascriptSorting?: boolean;
sortComparator?: string;
}

@@ -284,8 +243,4 @@ type ContainsHelperType<R> = R extends string ? string | string[] : R extends any[] ? R[number] | R[number][] : R extends object ? keyof R | (keyof R)[] : never;

} | {
$aeq?: R;
} | {
$ne?: R;
} | {
$dteq?: Date;
} | {
$gt?: R;

@@ -330,12 +285,2 @@ } | {

$where?: (val?: R) => boolean;
} | {
$jgt?: R;
} | {
$jgte?: R;
} | {
$jlt?: R;
} | {
$jlte?: R;
} | {
$jbetween?: [R, R];
};

@@ -342,0 +287,0 @@ type Query<T> = {

@@ -1,37 +0,36 @@

import { Doc } from "../../common/types";
export declare class UniqueIndex<T extends object = object> {
export declare class UniqueIndex {
private _field;
private _keyMap;
private _lokiMap;
private _valMap;
/**
* Constructs an unique index object.
* @param {number|string} propertyField - the property field to index
* @param {string} propertyField - the property field to index
*/
constructor(propertyField: keyof T);
constructor(propertyField: string);
/**
* Sets a document's unique index.
* @param {Doc} doc - the document
* @param {number} row - the data row of the document
* @param {number} id loki id to associate with value
* @param {*} value value to associate with id
*/
set(doc: Doc<T>, row: number): void;
set(id: number, value: any): void;
/**
* Returns the data row of an unique index.
* @param {number|string} index - the index
* @returns {number | string} - the row
* Returns the $loki id of an unique value.
* @param {*} value the value to retrieve a loki id match for
*/
get(index: keyof T): number;
get(value: any): number;
/**
* Updates a document's unique index.
* @param {Object} doc - the document
* @param {number} row - the data row of the document
* @param {number} id (loki) id of document to update the value to
* @param {*} value value to associate with loki id
*/
update(doc: Doc<T>, row: number): void;
update(id: number, value: any): void;
/**
* Removes an unique index.
* @param {number|string} index - the unique index
* @param {number} id (loki) id to remove from index
*/
remove(index: number | string): void;
remove(id: number): void;
/**
* Clears all unique indexes.
* Clears the unique index.
*/
clear(): void;
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc