Resolved conflicts after rebase - running prettier
This commit is contained in:
Родитель
c1a322ee3a
Коммит
c600e90e38
|
@ -51,18 +51,18 @@ export function breakAndNormalizeSearchPhrase(phrase: string): string[] {
|
|||
// Deburr and tolower before using words since words breaks on CaseChanges.
|
||||
const wordInPhrase = words(
|
||||
deburr(phrase).toLowerCase(),
|
||||
_whitespaceRegexMatch
|
||||
_whitespaceRegexMatch,
|
||||
);
|
||||
// map(mapKeys is faster than uniq since it's just a pile of strings.
|
||||
const uniqueWordas = map(mapKeys(wordInPhrase), (_value, key) =>
|
||||
sqlCompat(key)
|
||||
sqlCompat(key),
|
||||
);
|
||||
return filter(uniqueWordas, (word) => !!lodashTrim(word));
|
||||
}
|
||||
|
||||
export function getFullTextIndexWordsForItem(
|
||||
keyPath: string,
|
||||
item: any
|
||||
item: any,
|
||||
): string[] {
|
||||
const rawString = getValueForSingleKeypath(item, keyPath);
|
||||
|
||||
|
@ -74,7 +74,7 @@ export abstract class DbIndexFTSFromRangeQueries implements DbIndex {
|
|||
|
||||
constructor(
|
||||
protected _indexSchema: IndexSchema | undefined,
|
||||
protected _primaryKeyPath: string | string[]
|
||||
protected _primaryKeyPath: string | string[],
|
||||
) {
|
||||
this._keyPath = this._indexSchema
|
||||
? this._indexSchema.keyPath
|
||||
|
@ -84,11 +84,11 @@ export abstract class DbIndexFTSFromRangeQueries implements DbIndex {
|
|||
fullTextSearch(
|
||||
searchPhrase: string,
|
||||
resolution: FullTextTermResolution = FullTextTermResolution.And,
|
||||
limit?: number
|
||||
limit?: number,
|
||||
): Promise<ItemType[]> {
|
||||
if (!this._indexSchema || !this._indexSchema.fullText) {
|
||||
return Promise.reject(
|
||||
"fullTextSearch performed against non-fullText index!"
|
||||
"fullTextSearch performed against non-fullText index!",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -107,8 +107,8 @@ export abstract class DbIndexFTSFromRangeQueries implements DbIndex {
|
|||
const uniquers = attempt(() => {
|
||||
return map(results, (resultSet) =>
|
||||
keyBy(resultSet, (item) =>
|
||||
getSerializedKeyForKeypath(item, this._primaryKeyPath)
|
||||
)
|
||||
getSerializedKeyForKeypath(item, this._primaryKeyPath),
|
||||
),
|
||||
);
|
||||
});
|
||||
if (isError(uniquers)) {
|
||||
|
@ -126,7 +126,7 @@ export abstract class DbIndexFTSFromRangeQueries implements DbIndex {
|
|||
if (resolution === FullTextTermResolution.And) {
|
||||
const [first, ...others] = uniquers;
|
||||
const dic = pickBy(first, (_value, key) =>
|
||||
every(others, (set) => key in set)
|
||||
every(others, (set) => key in set),
|
||||
) as Dictionary<ItemType>;
|
||||
const data = values(dic);
|
||||
if (limit) {
|
||||
|
@ -142,14 +142,14 @@ export abstract class DbIndexFTSFromRangeQueries implements DbIndex {
|
|||
abstract getAll(
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]>;
|
||||
abstract getMultiple(keyOrKeys: KeyType | KeyType[]): Promise<ItemType[]>;
|
||||
abstract getOnly(
|
||||
key: KeyType,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]>;
|
||||
abstract getRange(
|
||||
keyLowRange: KeyType,
|
||||
|
@ -158,13 +158,13 @@ export abstract class DbIndexFTSFromRangeQueries implements DbIndex {
|
|||
highRangeExclusive?: boolean,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]>;
|
||||
abstract getKeysForRange(
|
||||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<any[]>;
|
||||
abstract countAll(): Promise<number>;
|
||||
abstract countOnly(key: KeyType): Promise<number>;
|
||||
|
@ -172,6 +172,6 @@ export abstract class DbIndexFTSFromRangeQueries implements DbIndex {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<number>;
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ export class InMemoryProvider extends DbProvider {
|
|||
constructor(
|
||||
mapType?: OrderedMapType,
|
||||
supportsRollback = false,
|
||||
logger?: IObjectStoreProviderLogger
|
||||
logger?: IObjectStoreProviderLogger,
|
||||
) {
|
||||
super();
|
||||
this._mapType = mapType;
|
||||
|
@ -86,7 +86,7 @@ export class InMemoryProvider extends DbProvider {
|
|||
dbName: string,
|
||||
schema: DbSchema,
|
||||
wipeIfExists: boolean,
|
||||
verbose: boolean
|
||||
verbose: boolean,
|
||||
): Promise<void> {
|
||||
super.open(dbName, schema, wipeIfExists, verbose);
|
||||
|
||||
|
@ -110,7 +110,7 @@ export class InMemoryProvider extends DbProvider {
|
|||
|
||||
openTransaction(
|
||||
storeNames: string[],
|
||||
writeNeeded: boolean
|
||||
writeNeeded: boolean,
|
||||
): Promise<DbTransaction> {
|
||||
return this._lockHelper!!!.openTransaction(storeNames, writeNeeded).then(
|
||||
(token: any) =>
|
||||
|
@ -120,8 +120,8 @@ export class InMemoryProvider extends DbProvider {
|
|||
token,
|
||||
writeNeeded,
|
||||
this._supportsRollback!,
|
||||
this.logger
|
||||
)
|
||||
this.logger,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ class InMemoryTransaction implements DbTransaction {
|
|||
private _transToken: TransactionToken,
|
||||
private _writeNeeded: boolean,
|
||||
private _supportsRollback: boolean,
|
||||
private logger: IObjectStoreProviderLogger
|
||||
private logger: IObjectStoreProviderLogger,
|
||||
) {
|
||||
// Close the transaction on the next tick. By definition, anything is completed synchronously here, so after an event tick
|
||||
// goes by, there can't have been anything pending.
|
||||
|
@ -176,10 +176,10 @@ class InMemoryTransaction implements DbTransaction {
|
|||
abort(): void {
|
||||
if (!this._supportsRollback) {
|
||||
this.logger.error(
|
||||
"Unable to abort transaction since provider doesn't support rollback"
|
||||
"Unable to abort transaction since provider doesn't support rollback",
|
||||
);
|
||||
throw new Error(
|
||||
"Unable to abort transaction since provider doesn't support rollback"
|
||||
"Unable to abort transaction since provider doesn't support rollback",
|
||||
);
|
||||
}
|
||||
this._stores.forEach((store) => {
|
||||
|
@ -193,7 +193,7 @@ class InMemoryTransaction implements DbTransaction {
|
|||
|
||||
this._lockHelper.transactionFailed(
|
||||
this._transToken,
|
||||
"InMemoryTransaction Aborted"
|
||||
"InMemoryTransaction Aborted",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ class InMemoryTransaction implements DbTransaction {
|
|||
getStore(storeName: string): DbStore {
|
||||
if (!includes(arrayify(this._transToken.storeNames), storeName)) {
|
||||
throw new Error(
|
||||
"Store not found in transaction-scoped store list: " + storeName
|
||||
"Store not found in transaction-scoped store list: " + storeName,
|
||||
);
|
||||
}
|
||||
if (this._stores.has(storeName)) {
|
||||
|
@ -217,7 +217,7 @@ class InMemoryTransaction implements DbTransaction {
|
|||
const ims = new InMemoryStore(
|
||||
this,
|
||||
store,
|
||||
this._writeNeeded && this._supportsRollback
|
||||
this._writeNeeded && this._supportsRollback,
|
||||
);
|
||||
this._stores.set(storeName, ims);
|
||||
return ims;
|
||||
|
@ -237,7 +237,7 @@ class InMemoryStore implements DbStore {
|
|||
constructor(
|
||||
private _trans: InMemoryTransaction,
|
||||
storeInfo: StoreData,
|
||||
private _supportsRollback: boolean
|
||||
private _supportsRollback: boolean,
|
||||
) {
|
||||
this._storeSchema = storeInfo.schema;
|
||||
if (this._supportsRollback) {
|
||||
|
@ -258,7 +258,7 @@ class InMemoryStore implements DbStore {
|
|||
internal_rollbackPendingData(): void {
|
||||
if (!this._supportsRollback) {
|
||||
throw new Error(
|
||||
"Unable to rollback since InMemoryStore was created with supportsRollback = false"
|
||||
"Unable to rollback since InMemoryStore was created with supportsRollback = false",
|
||||
);
|
||||
}
|
||||
this._mergedData.clear();
|
||||
|
@ -273,8 +273,8 @@ class InMemoryStore implements DbStore {
|
|||
this._mergedData,
|
||||
index,
|
||||
this._storeSchema.primaryKeyPath,
|
||||
this._mapType
|
||||
)
|
||||
this._mapType,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -294,7 +294,7 @@ class InMemoryStore implements DbStore {
|
|||
const joinedKeys = attempt(() => {
|
||||
return formListOfSerializedKeys(
|
||||
keyOrKeys,
|
||||
this._storeSchema.primaryKeyPath
|
||||
this._storeSchema.primaryKeyPath,
|
||||
);
|
||||
});
|
||||
if (isError(joinedKeys)) {
|
||||
|
@ -302,7 +302,7 @@ class InMemoryStore implements DbStore {
|
|||
}
|
||||
|
||||
return Promise.resolve(
|
||||
compact(map(joinedKeys, (key) => this._mergedData.get(key)))
|
||||
compact(map(joinedKeys, (key) => this._mergedData.get(key))),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -314,7 +314,7 @@ class InMemoryStore implements DbStore {
|
|||
each(arrayify(itemOrItems), (item) => {
|
||||
let pk = getSerializedKeyForKeypath(
|
||||
item,
|
||||
this._storeSchema.primaryKeyPath
|
||||
this._storeSchema.primaryKeyPath,
|
||||
)!!!;
|
||||
const existingItem = this._mergedData.get(pk);
|
||||
if (existingItem) {
|
||||
|
@ -322,7 +322,7 @@ class InMemoryStore implements DbStore {
|
|||
this._removeFromIndices(
|
||||
pk,
|
||||
existingItem,
|
||||
/** RemovePrimaryKey */ false
|
||||
/** RemovePrimaryKey */ false,
|
||||
);
|
||||
}
|
||||
this._mergedData.set(pk, item);
|
||||
|
@ -348,7 +348,7 @@ class InMemoryStore implements DbStore {
|
|||
const joinedKeys = attempt(() => {
|
||||
return formListOfSerializedKeys(
|
||||
keyOrKeys,
|
||||
this._storeSchema.primaryKeyPath
|
||||
this._storeSchema.primaryKeyPath,
|
||||
);
|
||||
});
|
||||
if (isError(joinedKeys)) {
|
||||
|
@ -363,7 +363,7 @@ class InMemoryStore implements DbStore {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<void> {
|
||||
if (!this._trans.internal_isOpen()) {
|
||||
return Promise.reject<void>("InMemoryTransaction already closed");
|
||||
|
@ -379,7 +379,7 @@ class InMemoryStore implements DbStore {
|
|||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
)
|
||||
.then((keys) => {
|
||||
return this._removeInternal(keys);
|
||||
|
@ -394,8 +394,8 @@ class InMemoryStore implements DbStore {
|
|||
this._mergedData,
|
||||
undefined as any,
|
||||
this._storeSchema.primaryKeyPath,
|
||||
this._mapType
|
||||
)
|
||||
this._mapType,
|
||||
),
|
||||
);
|
||||
}
|
||||
const index = this._indices.get("pk")!!!;
|
||||
|
@ -406,7 +406,7 @@ class InMemoryStore implements DbStore {
|
|||
openIndex(indexName: string): DbIndex {
|
||||
let indexSchema = find(
|
||||
this._storeSchema.indexes,
|
||||
(idx) => idx.name === indexName
|
||||
(idx) => idx.name === indexName,
|
||||
);
|
||||
if (!indexSchema) {
|
||||
throw new Error("Index not found: " + indexName);
|
||||
|
@ -419,8 +419,8 @@ class InMemoryStore implements DbStore {
|
|||
this._mergedData,
|
||||
indexSchema,
|
||||
this._storeSchema.primaryKeyPath,
|
||||
this._mapType
|
||||
)
|
||||
this._mapType,
|
||||
),
|
||||
);
|
||||
}
|
||||
const index = this._indices.get(indexSchema.name)!!!;
|
||||
|
@ -441,8 +441,8 @@ class InMemoryStore implements DbStore {
|
|||
this._mergedData,
|
||||
index,
|
||||
this._storeSchema.primaryKeyPath,
|
||||
this._mapType
|
||||
)
|
||||
this._mapType,
|
||||
),
|
||||
);
|
||||
});
|
||||
return Promise.resolve<void>(void 0);
|
||||
|
@ -467,7 +467,7 @@ class InMemoryStore implements DbStore {
|
|||
private _removeFromIndices(
|
||||
key: string,
|
||||
item: ItemType,
|
||||
removePrimaryKey: boolean
|
||||
removePrimaryKey: boolean,
|
||||
) {
|
||||
// Don't need to remove from primary key on Puts because set is enough
|
||||
// 1. If it's an existing key then it will get overwritten
|
||||
|
@ -487,7 +487,7 @@ class InMemoryStore implements DbStore {
|
|||
each(indexKeys, (indexKey: string) => ind.remove(indexKey));
|
||||
} else {
|
||||
each(indexKeys, (idxKey: string) =>
|
||||
ind.remove({ idxKey, primaryKey: key })
|
||||
ind.remove({ idxKey, primaryKey: key }),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -502,7 +502,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
_mergedData: Map<string, ItemType>,
|
||||
indexSchema: IndexSchema,
|
||||
primaryKeyPath: KeyPathType,
|
||||
mapType?: OrderedMapType
|
||||
mapType?: OrderedMapType,
|
||||
) {
|
||||
super(indexSchema, primaryKeyPath);
|
||||
this._indexTree = createOrderedMap(mapType);
|
||||
|
@ -518,14 +518,14 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
if (this._indexSchema && this._indexSchema!!!.fullText) {
|
||||
keys = map(
|
||||
getFullTextIndexWordsForItem(<string>this._keyPath, item),
|
||||
(val) => serializeKeyToString(val, <string>this._keyPath)
|
||||
(val) => serializeKeyToString(val, <string>this._keyPath),
|
||||
);
|
||||
} else if (this._indexSchema && this._indexSchema!!!.multiEntry) {
|
||||
// Have to extract the multiple entries into this alternate table...
|
||||
const valsRaw = getValueForSingleKeypath(item, <string>this._keyPath);
|
||||
if (valsRaw) {
|
||||
keys = map(arrayify(valsRaw), (val) =>
|
||||
serializeKeyToString(val, <string>this._keyPath)
|
||||
serializeKeyToString(val, <string>this._keyPath),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -537,7 +537,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
// Warning: This function can throw, make sure to trap.
|
||||
public put(
|
||||
itemOrItems: ItemType | ItemType[],
|
||||
skipTransactionOnCreation?: boolean
|
||||
skipTransactionOnCreation?: boolean,
|
||||
): void {
|
||||
if (!skipTransactionOnCreation && !this._trans!.internal_isOpen()) {
|
||||
throw new Error("InMemoryTransaction already closed");
|
||||
|
@ -593,7 +593,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
*/
|
||||
public remove(
|
||||
key: string | { primaryKey: string; idxKey: string },
|
||||
skipTransactionOnCreation?: boolean
|
||||
skipTransactionOnCreation?: boolean,
|
||||
) {
|
||||
if (!skipTransactionOnCreation && !this._trans!.internal_isOpen()) {
|
||||
throw new Error("InMemoryTransaction already closed");
|
||||
|
@ -610,7 +610,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
const idxItemsWithoutItem = idxItems.filter((idxItem) => {
|
||||
const idxItemPrimaryKeyVal = getSerializedKeyForKeypath(
|
||||
idxItem,
|
||||
this._primaryKeyPath
|
||||
this._primaryKeyPath,
|
||||
)!!!;
|
||||
return idxItemPrimaryKeyVal !== key.primaryKey;
|
||||
});
|
||||
|
@ -629,7 +629,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
getAll(
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
const definedLimit = limit
|
||||
? limit
|
||||
|
@ -672,7 +672,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
item.key,
|
||||
definedLimit - i,
|
||||
(item.value?.length || 0) - count,
|
||||
reverse
|
||||
reverse,
|
||||
);
|
||||
|
||||
values.forEach((v, j) => {
|
||||
|
@ -703,7 +703,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
key: KeyType,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
return this.getRange(
|
||||
key,
|
||||
|
@ -712,7 +712,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
false,
|
||||
reverseOrSortOrder,
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -723,7 +723,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
highRangeExclusive?: boolean,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
const values = attempt(() => {
|
||||
const reverse =
|
||||
|
@ -776,8 +776,8 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
key,
|
||||
limit - values.length,
|
||||
Math.abs(offset),
|
||||
reverse
|
||||
)
|
||||
reverse,
|
||||
),
|
||||
);
|
||||
|
||||
if (offset < 0) {
|
||||
|
@ -799,14 +799,14 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<any[]> {
|
||||
const keys = attempt(() => {
|
||||
return this._getKeysForRange(
|
||||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
});
|
||||
if (isError(keys)) {
|
||||
|
@ -827,7 +827,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
key: string,
|
||||
limit: number,
|
||||
offset: number,
|
||||
reverse: boolean
|
||||
reverse: boolean,
|
||||
): ItemType[] {
|
||||
if (limit <= 0) {
|
||||
return [];
|
||||
|
@ -862,7 +862,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): string[] {
|
||||
const keyLow = serializeKeyToString(keyLowRange, this._keyPath);
|
||||
const keyHigh = serializeKeyToString(keyHighRange, this._keyPath);
|
||||
|
@ -889,7 +889,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): number {
|
||||
const keyLow = serializeKeyToString(keyLowRange, this._keyPath);
|
||||
const keyHigh = serializeKeyToString(keyHighRange, this._keyPath);
|
||||
|
@ -943,7 +943,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<number> {
|
||||
if (this.isUniqueIndex()) {
|
||||
const keys = attempt(() => {
|
||||
|
@ -951,7 +951,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -966,7 +966,7 @@ class InMemoryIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
explicitDbFactory?: IDBFactory,
|
||||
explicitDbFactorySupportsCompoundKeys?: boolean,
|
||||
handleOnClose?: OnCloseHandler,
|
||||
logger?: IObjectStoreProviderLogger
|
||||
logger?: IObjectStoreProviderLogger,
|
||||
) {
|
||||
super();
|
||||
|
||||
|
@ -149,7 +149,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
dbName: string,
|
||||
schema: DbSchema,
|
||||
wipeIfExists: boolean,
|
||||
verbose: boolean
|
||||
verbose: boolean,
|
||||
): Promise<void> {
|
||||
// Note: DbProvider returns null instead of a promise that needs waiting for.
|
||||
super.open(dbName, schema, wipeIfExists, verbose);
|
||||
|
@ -170,7 +170,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
// Don't care
|
||||
this.logWriter.error(
|
||||
`Wiping db failed, message: ${e?.message}. Ignoring and proceeding further`,
|
||||
{ dbName }
|
||||
{ dbName },
|
||||
);
|
||||
}
|
||||
this.logWriter.log(`Wiping db success`, { dbName });
|
||||
|
@ -204,7 +204,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
isActualUpgrade = true;
|
||||
// Clear all stores if it's past the usable version
|
||||
this.logWriter.log(
|
||||
`Old version detected (${event.oldVersion}), clearing all data`
|
||||
`Old version detected (${event.oldVersion}), clearing all data`,
|
||||
);
|
||||
each(db.objectStoreNames, (name) => {
|
||||
db.deleteObjectStore(name);
|
||||
|
@ -231,7 +231,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
let store: IDBObjectStore;
|
||||
const storeExistedBefore = includes(
|
||||
db.objectStoreNames,
|
||||
storeSchema.name
|
||||
storeSchema.name,
|
||||
);
|
||||
if (!storeExistedBefore) {
|
||||
// store doesn't exist yet
|
||||
|
@ -256,7 +256,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
let nuke = false;
|
||||
const indexSchema = find(
|
||||
storeSchema.indexes,
|
||||
(idx) => idx.name === indexName
|
||||
(idx) => idx.name === indexName,
|
||||
);
|
||||
if (!indexSchema || !isObject(indexSchema)) {
|
||||
nuke = true;
|
||||
|
@ -310,7 +310,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
});
|
||||
let indexStore = db.createObjectStore(
|
||||
storeSchema.name + "_" + indexSchema.name,
|
||||
{ autoIncrement: true }
|
||||
{ autoIncrement: true },
|
||||
);
|
||||
indexStore.createIndex("key", "key");
|
||||
indexStore.createIndex("refkey", "refkey");
|
||||
|
@ -331,7 +331,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
IndexPrefix + indexSchema.name,
|
||||
{
|
||||
unique: indexSchema.unique,
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
this.logWriter.log(`Creating index`, {
|
||||
|
@ -355,7 +355,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
{
|
||||
unique: false,
|
||||
multiEntry: true,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
if (storeExistedBefore && !indexSchema.doNotBackfill) {
|
||||
|
@ -394,7 +394,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
fakeToken,
|
||||
schema,
|
||||
this._fakeComplicatedKeys,
|
||||
this.logWriter
|
||||
this.logWriter,
|
||||
);
|
||||
const tStore = iTrans.getStore(storeSchema.name);
|
||||
|
||||
|
@ -408,7 +408,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
const err = attempt(() => {
|
||||
const item = removeFullTextMetadataAndReturn(
|
||||
storeSchema,
|
||||
(cursor as any).value
|
||||
(cursor as any).value,
|
||||
);
|
||||
|
||||
thisIndexPutters.push(tStore.put(item));
|
||||
|
@ -421,10 +421,10 @@ export class IndexedDbProvider extends DbProvider {
|
|||
(err) => {
|
||||
this.logWriter.error(
|
||||
`Error when iterating over cursor on idb index, message: ${err?.message}`,
|
||||
{ storeName: storeSchema.name }
|
||||
{ storeName: storeSchema.name },
|
||||
);
|
||||
}
|
||||
)
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -439,7 +439,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
if (isActualMigration) {
|
||||
this.logWriter.log(
|
||||
`Waiting for migrationPutters: ${migrationPutters.length} to complete for db`,
|
||||
{ dbName }
|
||||
{ dbName },
|
||||
);
|
||||
}
|
||||
return Promise.all(migrationPutters).then(() => {
|
||||
|
@ -489,7 +489,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
this.logWriter.log(
|
||||
`Database version too new, Wiping: ${
|
||||
err.target.error.message || err.target.error.name
|
||||
}`
|
||||
}`,
|
||||
);
|
||||
|
||||
return this.open(dbName, schema, true, verbose);
|
||||
|
@ -502,7 +502,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
}
|
||||
);
|
||||
return Promise.reject<void>(err);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -547,7 +547,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
|
||||
openTransaction(
|
||||
storeNames: string[],
|
||||
writeNeeded: boolean
|
||||
writeNeeded: boolean,
|
||||
): Promise<DbTransaction> {
|
||||
if (!this._db) {
|
||||
return Promise.reject("Can't openTransaction, database is closed");
|
||||
|
@ -564,7 +564,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
each(storeNames, (storeName) => {
|
||||
let storeSchema = find(
|
||||
this._schema!!!.stores,
|
||||
(s) => s.name === storeName
|
||||
(s) => s.name === storeName,
|
||||
);
|
||||
if (!storeSchema) {
|
||||
missingStores.push(storeName);
|
||||
|
@ -580,7 +580,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
});
|
||||
if (missingStores.length > 0) {
|
||||
return Promise.reject(
|
||||
"Can't find store(s): " + missingStores.join(",")
|
||||
"Can't find store(s): " + missingStores.join(","),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -590,7 +590,7 @@ export class IndexedDbProvider extends DbProvider {
|
|||
const trans = attempt(() => {
|
||||
return this._db!!!.transaction(
|
||||
intStoreNames,
|
||||
writeNeeded ? "readwrite" : "readonly"
|
||||
writeNeeded ? "readwrite" : "readonly",
|
||||
);
|
||||
});
|
||||
if (isError(trans)) {
|
||||
|
@ -604,10 +604,10 @@ export class IndexedDbProvider extends DbProvider {
|
|||
transToken,
|
||||
this._schema!!!,
|
||||
this._fakeComplicatedKeys,
|
||||
this.logWriter
|
||||
)
|
||||
this.logWriter,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -622,10 +622,10 @@ class IndexedDbTransaction implements DbTransaction {
|
|||
private _transToken: TransactionToken,
|
||||
private _schema: DbSchema,
|
||||
private _fakeComplicatedKeys: boolean,
|
||||
private logWriter: LogWriter
|
||||
private logWriter: LogWriter,
|
||||
) {
|
||||
this._stores = map(this._transToken.storeNames, (storeName) =>
|
||||
this._trans.objectStore(storeName)
|
||||
this._trans.objectStore(storeName),
|
||||
);
|
||||
|
||||
if (lockHelper) {
|
||||
|
@ -646,7 +646,7 @@ class IndexedDbTransaction implements DbTransaction {
|
|||
|
||||
this._trans.onerror = () => {
|
||||
history.push(
|
||||
"error-" + (this._trans.error ? this._trans.error.message : "")
|
||||
"error-" + (this._trans.error ? this._trans.error.message : ""),
|
||||
);
|
||||
|
||||
if (history.length > 1) {
|
||||
|
@ -654,7 +654,7 @@ class IndexedDbTransaction implements DbTransaction {
|
|||
"IndexedDbTransaction Errored after Resolution, Swallowing. Error: " +
|
||||
(this._trans.error ? this._trans.error.message : undefined) +
|
||||
", History: " +
|
||||
history.join(",")
|
||||
history.join(","),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -664,13 +664,13 @@ class IndexedDbTransaction implements DbTransaction {
|
|||
"IndexedDbTransaction OnError: " +
|
||||
(this._trans.error ? this._trans.error.message : undefined) +
|
||||
", History: " +
|
||||
history.join(",")
|
||||
history.join(","),
|
||||
);
|
||||
};
|
||||
|
||||
this._trans.onabort = () => {
|
||||
history.push(
|
||||
"abort-" + (this._trans.error ? this._trans.error.message : "")
|
||||
"abort-" + (this._trans.error ? this._trans.error.message : ""),
|
||||
);
|
||||
|
||||
if (history.length > 1) {
|
||||
|
@ -678,7 +678,7 @@ class IndexedDbTransaction implements DbTransaction {
|
|||
"IndexedDbTransaction Aborted after Resolution, Swallowing. Error: " +
|
||||
(this._trans.error ? this._trans.error.message : undefined) +
|
||||
", History: " +
|
||||
history.join(",")
|
||||
history.join(","),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
@ -688,7 +688,7 @@ class IndexedDbTransaction implements DbTransaction {
|
|||
"IndexedDbTransaction Aborted, Error: " +
|
||||
(this._trans.error ? this._trans.error.message : undefined) +
|
||||
", History: " +
|
||||
history.join(",")
|
||||
history.join(","),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
@ -707,7 +707,7 @@ class IndexedDbTransaction implements DbTransaction {
|
|||
each(storeSchema.indexes, (indexSchema) => {
|
||||
if (indexSchema.multiEntry || indexSchema.fullText) {
|
||||
indexStores.push(
|
||||
this._trans.objectStore(storeSchema.name + "_" + indexSchema.name)
|
||||
this._trans.objectStore(storeSchema.name + "_" + indexSchema.name),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -717,7 +717,7 @@ class IndexedDbTransaction implements DbTransaction {
|
|||
store,
|
||||
indexStores,
|
||||
storeSchema,
|
||||
this._fakeComplicatedKeys
|
||||
this._fakeComplicatedKeys,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -755,7 +755,7 @@ class IndexedDbStore implements DbStore {
|
|||
private _store: IDBObjectStore,
|
||||
private _indexStores: IDBObjectStore[],
|
||||
private _schema: StoreSchema,
|
||||
private _fakeComplicatedKeys: boolean
|
||||
private _fakeComplicatedKeys: boolean,
|
||||
) {
|
||||
// NOP
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ class IndexedDbStore implements DbStore {
|
|||
}
|
||||
|
||||
return IndexedDbProvider.WrapRequest(this._store.get(key)).then((val) =>
|
||||
removeFullTextMetadataAndReturn(this._schema, val)
|
||||
removeFullTextMetadataAndReturn(this._schema, val),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -787,7 +787,7 @@ class IndexedDbStore implements DbStore {
|
|||
isCompoundKeyPath(this._schema.primaryKeyPath)
|
||||
) {
|
||||
return map(keys, (key) =>
|
||||
serializeKeyToString(key, this._schema.primaryKeyPath)
|
||||
serializeKeyToString(key, this._schema.primaryKeyPath),
|
||||
);
|
||||
}
|
||||
return keys;
|
||||
|
@ -799,9 +799,9 @@ class IndexedDbStore implements DbStore {
|
|||
return Promise.all(
|
||||
map(keys, (key) =>
|
||||
IndexedDbProvider.WrapRequest(this._store.get(key)).then((val) =>
|
||||
removeFullTextMetadataAndReturn(this._schema, val)
|
||||
)
|
||||
)
|
||||
removeFullTextMetadataAndReturn(this._schema, val),
|
||||
),
|
||||
),
|
||||
).then(compact);
|
||||
}
|
||||
|
||||
|
@ -821,7 +821,7 @@ class IndexedDbStore implements DbStore {
|
|||
fakedPk = true;
|
||||
(item as any)["nsp_pk"] = getSerializedKeyForKeypath(
|
||||
item,
|
||||
this._schema.primaryKeyPath
|
||||
this._schema.primaryKeyPath,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -829,20 +829,20 @@ class IndexedDbStore implements DbStore {
|
|||
if (index.multiEntry || index.fullText) {
|
||||
let indexStore = find(
|
||||
this._indexStores,
|
||||
(store) => store.name === this._schema.name + "_" + index.name
|
||||
(store) => store.name === this._schema.name + "_" + index.name,
|
||||
)!!!;
|
||||
|
||||
let keys: any[];
|
||||
if (index.fullText) {
|
||||
keys = getFullTextIndexWordsForItem(
|
||||
<string>index.keyPath,
|
||||
item
|
||||
item,
|
||||
);
|
||||
} else {
|
||||
// Get each value of the multientry and put it into the index store
|
||||
const valsRaw = getValueForSingleKeypath(
|
||||
item,
|
||||
<string>index.keyPath
|
||||
<string>index.keyPath,
|
||||
);
|
||||
// It might be an array of multiple entries, so just always go with array-based logic
|
||||
keys = arrayify(valsRaw);
|
||||
|
@ -854,7 +854,7 @@ class IndexedDbStore implements DbStore {
|
|||
// serialization if the multientry keys ALSO are compound.
|
||||
if (isCompoundKeyPath(index.keyPath)) {
|
||||
keys = map(keys, (val) =>
|
||||
serializeKeyToString(val, <string>index.keyPath)
|
||||
serializeKeyToString(val, <string>index.keyPath),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -865,7 +865,7 @@ class IndexedDbStore implements DbStore {
|
|||
if (isArray(this._schema.primaryKeyPath)) {
|
||||
refKey = serializeKeyToString(
|
||||
refKey,
|
||||
this._schema.primaryKeyPath
|
||||
this._schema.primaryKeyPath,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
@ -891,12 +891,12 @@ class IndexedDbStore implements DbStore {
|
|||
refkey: refKey,
|
||||
};
|
||||
return IndexedDbProvider.WrapRequest(
|
||||
indexStore.put(indexObj)
|
||||
indexStore.put(indexObj),
|
||||
).then(() => void 0);
|
||||
});
|
||||
return Promise.all(iputters);
|
||||
})
|
||||
.then(noop)
|
||||
.then(noop),
|
||||
);
|
||||
} else if (isCompoundKeyPath(index.keyPath)) {
|
||||
(item as any)[IndexPrefix + index.name] =
|
||||
|
@ -924,7 +924,7 @@ class IndexedDbStore implements DbStore {
|
|||
}
|
||||
|
||||
promises.push(
|
||||
IndexedDbProvider.WrapRequest(req).then(() => void 0)
|
||||
IndexedDbProvider.WrapRequest(req).then(() => void 0),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -951,7 +951,7 @@ class IndexedDbStore implements DbStore {
|
|||
isCompoundKeyPath(this._schema.primaryKeyPath)
|
||||
) {
|
||||
return map(keys, (key) =>
|
||||
serializeKeyToString(key, this._schema.primaryKeyPath)
|
||||
serializeKeyToString(key, this._schema.primaryKeyPath),
|
||||
);
|
||||
}
|
||||
return keys;
|
||||
|
@ -966,7 +966,7 @@ class IndexedDbStore implements DbStore {
|
|||
this._fakeComplicatedKeys &&
|
||||
some(
|
||||
this._schema.indexes,
|
||||
(index) => index.multiEntry || index.fullText
|
||||
(index) => index.multiEntry || index.fullText,
|
||||
)
|
||||
) {
|
||||
// If we're faking keys and there's any multientry indexes, we have to do the way more complicated version...
|
||||
|
@ -980,7 +980,7 @@ class IndexedDbStore implements DbStore {
|
|||
let indexStore = find(
|
||||
this._indexStores,
|
||||
(store) =>
|
||||
store.name === this._schema.name + "_" + index.name
|
||||
store.name === this._schema.name + "_" + index.name,
|
||||
)!!!;
|
||||
const refKey = attempt(() => {
|
||||
// We need to reference the PK of the actual row we're using here, so calculate the actual PK -- if it's
|
||||
|
@ -988,12 +988,12 @@ class IndexedDbStore implements DbStore {
|
|||
// raw value.
|
||||
const tempRefKey = getKeyForKeypath(
|
||||
item,
|
||||
this._schema.primaryKeyPath
|
||||
this._schema.primaryKeyPath,
|
||||
)!!!;
|
||||
return isArray(this._schema.primaryKeyPath)
|
||||
? serializeKeyToString(
|
||||
tempRefKey,
|
||||
this._schema.primaryKeyPath
|
||||
this._schema.primaryKeyPath,
|
||||
)
|
||||
: tempRefKey;
|
||||
});
|
||||
|
@ -1009,23 +1009,23 @@ class IndexedDbStore implements DbStore {
|
|||
cursorReq,
|
||||
(cursor) => {
|
||||
cursor["delete"]();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
// Also remember to nuke the item from the actual store
|
||||
promises.push(
|
||||
IndexedDbProvider.WrapRequest(this._store["delete"](key))
|
||||
IndexedDbProvider.WrapRequest(this._store["delete"](key)),
|
||||
);
|
||||
return Promise.all(promises).then(noop);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return IndexedDbProvider.WrapRequest(this._store["delete"](key));
|
||||
})
|
||||
}),
|
||||
).then(noop);
|
||||
}
|
||||
|
||||
|
@ -1034,7 +1034,7 @@ class IndexedDbStore implements DbStore {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<void> {
|
||||
const index = attempt(() => {
|
||||
return indexName ? this.openIndex(indexName) : this.openPrimaryKey();
|
||||
|
@ -1047,7 +1047,7 @@ class IndexedDbStore implements DbStore {
|
|||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
)
|
||||
.then((keys) => {
|
||||
this.remove(keys);
|
||||
|
@ -1057,7 +1057,7 @@ class IndexedDbStore implements DbStore {
|
|||
openIndex(indexName: string): DbIndex {
|
||||
const indexSchema = find(
|
||||
this._schema.indexes,
|
||||
(idx) => idx.name === indexName
|
||||
(idx) => idx.name === indexName,
|
||||
);
|
||||
if (!indexSchema) {
|
||||
throw new Error("Index not found: " + indexName);
|
||||
|
@ -1070,11 +1070,11 @@ class IndexedDbStore implements DbStore {
|
|||
const store = find(
|
||||
this._indexStores,
|
||||
(indexStore) =>
|
||||
indexStore.name === this._schema.name + "_" + indexSchema.name
|
||||
indexStore.name === this._schema.name + "_" + indexSchema.name,
|
||||
);
|
||||
if (!store) {
|
||||
throw new Error(
|
||||
"Indexstore not found: " + this._schema.name + "_" + indexSchema.name
|
||||
"Indexstore not found: " + this._schema.name + "_" + indexSchema.name,
|
||||
);
|
||||
}
|
||||
return new IndexedDbIndex(
|
||||
|
@ -1082,7 +1082,7 @@ class IndexedDbStore implements DbStore {
|
|||
indexSchema,
|
||||
this._schema.primaryKeyPath,
|
||||
this._fakeComplicatedKeys,
|
||||
this._store
|
||||
this._store,
|
||||
);
|
||||
} else {
|
||||
const index = this._store.index(indexName);
|
||||
|
@ -1093,7 +1093,7 @@ class IndexedDbStore implements DbStore {
|
|||
index,
|
||||
indexSchema,
|
||||
this._schema.primaryKeyPath,
|
||||
this._fakeComplicatedKeys
|
||||
this._fakeComplicatedKeys,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1103,7 +1103,7 @@ class IndexedDbStore implements DbStore {
|
|||
this._store,
|
||||
undefined,
|
||||
this._schema.primaryKeyPath,
|
||||
this._fakeComplicatedKeys
|
||||
this._fakeComplicatedKeys,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1114,7 +1114,7 @@ class IndexedDbStore implements DbStore {
|
|||
}
|
||||
|
||||
let promises = map(storesToClear, (store) =>
|
||||
IndexedDbProvider.WrapRequest(store.clear())
|
||||
IndexedDbProvider.WrapRequest(store.clear()),
|
||||
);
|
||||
|
||||
return Promise.all(promises).then(noop);
|
||||
|
@ -1130,7 +1130,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
indexSchema: IndexSchema | undefined,
|
||||
primaryKeyPath: KeyPathType,
|
||||
private _fakeComplicatedKeys: boolean,
|
||||
private _fakedOriginalStore?: IDBObjectStore
|
||||
private _fakedOriginalStore?: IDBObjectStore,
|
||||
) {
|
||||
super(indexSchema, primaryKeyPath);
|
||||
}
|
||||
|
@ -1138,20 +1138,20 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
private _resolveCursorResult(
|
||||
req: IDBRequest,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
if (this._fakeComplicatedKeys && this._fakedOriginalStore) {
|
||||
// Get based on the keys from the index store, which have refkeys that point back to the original store
|
||||
return IndexedDbIndex.getFromCursorRequest<{ key: string; refkey: any }>(
|
||||
req,
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
).then((rets) => {
|
||||
// Now get the original items using the refkeys from the index store, which are PKs on the main store
|
||||
const getters = map(rets, (ret) =>
|
||||
IndexedDbProvider.WrapRequest(
|
||||
this._fakedOriginalStore!!!.get(ret.refkey)
|
||||
)
|
||||
this._fakedOriginalStore!!!.get(ret.refkey),
|
||||
),
|
||||
);
|
||||
return Promise.all(getters);
|
||||
});
|
||||
|
@ -1163,7 +1163,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
getAll(
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
const reverse =
|
||||
reverseOrSortOrder === true ||
|
||||
|
@ -1175,7 +1175,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
!this._fakeComplicatedKeys
|
||||
) {
|
||||
return IndexedDbProvider.WrapRequest(
|
||||
this._store.getAll(undefined, limit)
|
||||
this._store.getAll(undefined, limit),
|
||||
);
|
||||
}
|
||||
// ************************* Don't change this null to undefined, IE chokes on it... *****************************
|
||||
|
@ -1189,7 +1189,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
key: KeyType,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
const keyRange = attempt(() => {
|
||||
return this._getKeyRangeForOnly(key);
|
||||
|
@ -1224,7 +1224,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
// when dealing with fakeComplicatedKeys, the store tries to store key and refkey, not the entire object.
|
||||
// therefore it calls getOnly to get the whole object through openCursor
|
||||
return Promise.all(map(keys, (key) => this.getOnly(key))).then((vals) =>
|
||||
compact(flatten(vals))
|
||||
compact(flatten(vals)),
|
||||
);
|
||||
}
|
||||
// Warning: This function can throw, make sure to trap.
|
||||
|
@ -1242,14 +1242,14 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
highRangeExclusive?: boolean,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
const keyRange = attempt(() => {
|
||||
return this._getKeyRangeForRange(
|
||||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
});
|
||||
if (isError(keyRange)) {
|
||||
|
@ -1276,7 +1276,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): IDBKeyRange {
|
||||
if (this._fakeComplicatedKeys && isCompoundKeyPath(this._keyPath)) {
|
||||
// IE has to switch to hacky pre-joined-compound-keys
|
||||
|
@ -1284,14 +1284,14 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
serializeKeyToString(keyLowRange, this._keyPath),
|
||||
serializeKeyToString(keyHighRange, this._keyPath),
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
}
|
||||
return IDBKeyRange.bound(
|
||||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1316,14 +1316,14 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<number> {
|
||||
let keyRange = attempt(() => {
|
||||
return this._getKeyRangeForRange(
|
||||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
});
|
||||
if (isError(keyRange)) {
|
||||
|
@ -1338,14 +1338,14 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<any[]> {
|
||||
const keyRange = attempt(() => {
|
||||
return this._getKeyRangeForRange(
|
||||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
});
|
||||
if (isError(keyRange)) {
|
||||
|
@ -1353,7 +1353,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
}
|
||||
if (this._store.getAllKeys && !this._fakeComplicatedKeys) {
|
||||
return IndexedDbProvider.WrapRequest<any[]>(
|
||||
this._store.getAllKeys(keyRange)
|
||||
this._store.getAllKeys(keyRange),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1369,7 +1369,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
static getFromCursorRequest<T>(
|
||||
req: IDBRequest,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<T[]> {
|
||||
let outList: T[] = [];
|
||||
return this.iterateOverCursorRequest(
|
||||
|
@ -1379,7 +1379,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
outList.push((cursor as any).value);
|
||||
},
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
).then(() => {
|
||||
return outList;
|
||||
});
|
||||
|
@ -1400,7 +1400,7 @@ class IndexedDbIndex extends DbIndexFTSFromRangeQueries {
|
|||
req: IDBRequest,
|
||||
func: (cursor: IDBCursor) => void,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
let count = 0;
|
||||
|
|
|
@ -94,14 +94,14 @@ export interface DbIndex {
|
|||
getAll(
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]>;
|
||||
getMultiple(keyOrKeys: KeyType | KeyType[]): Promise<ItemType[]>;
|
||||
getOnly(
|
||||
key: KeyType,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]>;
|
||||
getRange(
|
||||
keyLowRange: KeyType,
|
||||
|
@ -110,13 +110,13 @@ export interface DbIndex {
|
|||
highRangeExclusive?: boolean,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]>;
|
||||
getKeysForRange(
|
||||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<any[]>;
|
||||
countAll(): Promise<number>;
|
||||
countOnly(key: KeyType): Promise<number>;
|
||||
|
@ -124,12 +124,12 @@ export interface DbIndex {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<number>;
|
||||
fullTextSearch(
|
||||
searchPhrase: string,
|
||||
resolution?: FullTextTermResolution,
|
||||
limit?: number
|
||||
limit?: number,
|
||||
): Promise<ItemType[]>;
|
||||
}
|
||||
|
||||
|
@ -145,7 +145,7 @@ export interface DbStore {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<void>;
|
||||
|
||||
openPrimaryKey(): DbIndex;
|
||||
|
@ -179,7 +179,7 @@ export abstract class DbProvider {
|
|||
dbName: string,
|
||||
schema: DbSchema,
|
||||
_wipeIfExists: boolean,
|
||||
verbose: boolean
|
||||
verbose: boolean,
|
||||
): Promise<void> {
|
||||
// virtual call
|
||||
this._dbName = dbName;
|
||||
|
@ -196,7 +196,7 @@ export abstract class DbProvider {
|
|||
// Undefined for storeNames means ALL stores.
|
||||
abstract openTransaction(
|
||||
storeNames: string[] | undefined,
|
||||
writeNeeded: boolean
|
||||
writeNeeded: boolean,
|
||||
): Promise<DbTransaction>;
|
||||
|
||||
deleteDatabase(): Promise<void> {
|
||||
|
@ -224,7 +224,7 @@ export abstract class DbProvider {
|
|||
|
||||
private _getStoreTransaction(
|
||||
storeName: string,
|
||||
readWrite: boolean
|
||||
readWrite: boolean,
|
||||
): Promise<DbStore> {
|
||||
return this.openTransaction([storeName], readWrite).then((trans) => {
|
||||
const store = attempt(() => {
|
||||
|
@ -247,12 +247,12 @@ export abstract class DbProvider {
|
|||
getMultiple(
|
||||
storeName: string,
|
||||
keyOrKeys: KeyType | KeyType[],
|
||||
indexName?: string
|
||||
indexName?: string,
|
||||
): Promise<ItemType[]> {
|
||||
return this._getStoreIndexTransaction(storeName, false, indexName).then(
|
||||
(index) => {
|
||||
return index.getMultiple(keyOrKeys);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ export abstract class DbProvider {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<void> {
|
||||
return this._getStoreTransaction(storeName, true).then((store) => {
|
||||
return store.removeRange(
|
||||
|
@ -282,7 +282,7 @@ export abstract class DbProvider {
|
|||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ export abstract class DbProvider {
|
|||
private _getStoreIndexTransaction(
|
||||
storeName: string,
|
||||
readWrite: boolean,
|
||||
indexName: string | undefined
|
||||
indexName: string | undefined,
|
||||
): Promise<DbIndex> {
|
||||
return this._getStoreTransaction(storeName, readWrite).then((store) => {
|
||||
const index = attempt(() => {
|
||||
|
@ -308,12 +308,12 @@ export abstract class DbProvider {
|
|||
indexName: string | undefined,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
return this._getStoreIndexTransaction(storeName, false, indexName).then(
|
||||
(index) => {
|
||||
return index.getAll(reverseOrSortOrder, limit, offset);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -323,12 +323,12 @@ export abstract class DbProvider {
|
|||
key: KeyType,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
return this._getStoreIndexTransaction(storeName, false, indexName).then(
|
||||
(index) => {
|
||||
return index.getOnly(key, reverseOrSortOrder, limit, offset);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ export abstract class DbProvider {
|
|||
highRangeExclusive?: boolean,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ItemType[]> {
|
||||
return this._getStoreIndexTransaction(storeName, false, indexName).then(
|
||||
(index) => {
|
||||
|
@ -352,9 +352,9 @@ export abstract class DbProvider {
|
|||
highRangeExclusive,
|
||||
reverseOrSortOrder,
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -362,19 +362,19 @@ export abstract class DbProvider {
|
|||
return this._getStoreIndexTransaction(storeName, false, indexName).then(
|
||||
(index) => {
|
||||
return index.countAll();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
countOnly(
|
||||
storeName: string,
|
||||
indexName: string | undefined,
|
||||
key: KeyType
|
||||
key: KeyType,
|
||||
): Promise<number> {
|
||||
return this._getStoreIndexTransaction(storeName, false, indexName).then(
|
||||
(index) => {
|
||||
return index.countOnly(key);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ export abstract class DbProvider {
|
|||
keyLowRange: KeyType,
|
||||
keyHighRange: KeyType,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<number> {
|
||||
return this._getStoreIndexTransaction(storeName, false, indexName).then(
|
||||
(index) => {
|
||||
|
@ -392,9 +392,9 @@ export abstract class DbProvider {
|
|||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -403,12 +403,12 @@ export abstract class DbProvider {
|
|||
indexName: string,
|
||||
searchPhrase: string,
|
||||
resolution: FullTextTermResolution = FullTextTermResolution.And,
|
||||
limit?: number
|
||||
limit?: number,
|
||||
): Promise<ItemType[]> {
|
||||
return this._getStoreIndexTransaction(storeName, false, indexName).then(
|
||||
(index) => {
|
||||
return index.fullTextSearch(searchPhrase, resolution, limit);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -420,7 +420,7 @@ export function openListOfProviders(
|
|||
dbName: string,
|
||||
schema: DbSchema,
|
||||
wipeIfExists: boolean,
|
||||
verbose: boolean
|
||||
verbose: boolean,
|
||||
): Promise<DbProvider> {
|
||||
return new Promise<DbProvider>((resolve, reject) => {
|
||||
let providerIndex = 0;
|
||||
|
@ -441,7 +441,7 @@ export function openListOfProviders(
|
|||
errorList.push(err);
|
||||
providerIndex++;
|
||||
tryNext();
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ export function arrayify<T>(obj: T | T[]): T[] {
|
|||
|
||||
export function trimArray<TValue>(
|
||||
array: Array<TValue>,
|
||||
trimLength: number
|
||||
trimLength: number,
|
||||
): Array<TValue> {
|
||||
if (trimLength < 0 || array.length < trimLength) {
|
||||
return array.slice();
|
||||
|
@ -77,7 +77,7 @@ const keypathJoinerString = "%&";
|
|||
// for compound (or non-compound) values.
|
||||
export function getSerializedKeyForKeypath(
|
||||
obj: any,
|
||||
keyPathRaw: KeyPathType
|
||||
keyPathRaw: KeyPathType,
|
||||
): string | undefined {
|
||||
const values = getKeyForKeypath(obj, keyPathRaw);
|
||||
if (values === undefined) {
|
||||
|
@ -89,7 +89,7 @@ export function getSerializedKeyForKeypath(
|
|||
|
||||
export function getKeyForKeypath(
|
||||
obj: any,
|
||||
keyPathRaw: KeyPathType
|
||||
keyPathRaw: KeyPathType,
|
||||
): KeyType | undefined {
|
||||
const keyPathArray = arrayify(keyPathRaw);
|
||||
|
||||
|
@ -117,7 +117,7 @@ export function isCompoundKeyPath(keyPath: KeyPathType) {
|
|||
|
||||
export function formListOfKeys(
|
||||
keyOrKeys: KeyType | KeyType[],
|
||||
keyPath: KeyPathType
|
||||
keyPath: KeyPathType,
|
||||
): any[] {
|
||||
if (isCompoundKeyPath(keyPath)) {
|
||||
if (!isArray(keyOrKeys)) {
|
||||
|
@ -126,7 +126,7 @@ export function formListOfKeys(
|
|||
JSON.stringify(keyPath) +
|
||||
") but a non-compound keyOrKeys (" +
|
||||
JSON.stringify(keyOrKeys) +
|
||||
")"
|
||||
")",
|
||||
);
|
||||
}
|
||||
if (!isArray(keyOrKeys[0])) {
|
||||
|
@ -159,7 +159,7 @@ export function serializeValueToOrderableString(val: KeyComponentType): string {
|
|||
throw new Error(
|
||||
"Type '" +
|
||||
type +
|
||||
"' unsupported at this time. Only numbers, Dates, and strings are currently supported."
|
||||
"' unsupported at this time. Only numbers, Dates, and strings are currently supported.",
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -201,12 +201,12 @@ export function serializeNumberToOrderableString(n: number) {
|
|||
|
||||
export function serializeKeyToString(
|
||||
key: KeyType,
|
||||
keyPath: KeyPathType
|
||||
keyPath: KeyPathType,
|
||||
): string {
|
||||
if (isCompoundKeyPath(keyPath)) {
|
||||
if (isArray(key)) {
|
||||
return map(key, (k) => serializeValueToOrderableString(k)).join(
|
||||
keypathJoinerString
|
||||
keypathJoinerString,
|
||||
);
|
||||
} else {
|
||||
throw new Error(
|
||||
|
@ -214,7 +214,7 @@ export function serializeKeyToString(
|
|||
JSON.stringify(keyPath) +
|
||||
") but a non-compound key (" +
|
||||
JSON.stringify(key) +
|
||||
")"
|
||||
")",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -224,7 +224,7 @@ export function serializeKeyToString(
|
|||
JSON.stringify(keyPath) +
|
||||
") but a compound key (" +
|
||||
JSON.stringify(key) +
|
||||
")"
|
||||
")",
|
||||
);
|
||||
} else {
|
||||
return serializeValueToOrderableString(key);
|
||||
|
@ -234,9 +234,9 @@ export function serializeKeyToString(
|
|||
|
||||
export function formListOfSerializedKeys(
|
||||
keyOrKeys: KeyType | KeyType[],
|
||||
keyPath: KeyPathType
|
||||
keyPath: KeyPathType,
|
||||
): string[] {
|
||||
return map(formListOfKeys(keyOrKeys, keyPath), (key) =>
|
||||
serializeKeyToString(key, keyPath)
|
||||
serializeKeyToString(key, keyPath),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -29,12 +29,12 @@ export type DBStore<Name extends string, ObjectType, KeyFormat> = string & {
|
|||
};
|
||||
export type DBIndex<
|
||||
Store extends DBStore<string, any, any>,
|
||||
IndexKeyFormat
|
||||
IndexKeyFormat,
|
||||
> = string & { store?: Store; indexKeyFormat?: IndexKeyFormat };
|
||||
|
||||
export class SimpleTransactionIndexHelper<
|
||||
ObjectType extends ItemType,
|
||||
IndexKeyFormat extends KeyType
|
||||
IndexKeyFormat extends KeyType,
|
||||
> {
|
||||
constructor(protected _index: DbIndex) {
|
||||
// Nothing to see here
|
||||
|
@ -43,12 +43,12 @@ export class SimpleTransactionIndexHelper<
|
|||
getAll(
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ObjectType[]> {
|
||||
let promise = this._index.getAll(
|
||||
reverseOrSortOrder,
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
) as Promise<ObjectType[]>;
|
||||
return ErrorCatcher ? promise.catch(ErrorCatcher) : promise;
|
||||
}
|
||||
|
@ -57,13 +57,13 @@ export class SimpleTransactionIndexHelper<
|
|||
key: IndexKeyFormat,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ObjectType[]> {
|
||||
let promise = this._index.getOnly(
|
||||
key,
|
||||
reverseOrSortOrder,
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
) as Promise<ObjectType[]>;
|
||||
return ErrorCatcher ? promise.catch(ErrorCatcher) : promise;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ export class SimpleTransactionIndexHelper<
|
|||
highRangeExclusive?: boolean,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ObjectType[]> {
|
||||
let promise = this._index.getRange(
|
||||
keyLowRange,
|
||||
|
@ -84,7 +84,7 @@ export class SimpleTransactionIndexHelper<
|
|||
highRangeExclusive,
|
||||
reverseOrSortOrder,
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
) as Promise<ObjectType[]>;
|
||||
return ErrorCatcher ? promise.catch(ErrorCatcher) : promise;
|
||||
}
|
||||
|
@ -103,13 +103,13 @@ export class SimpleTransactionIndexHelper<
|
|||
keyLowRange: IndexKeyFormat,
|
||||
keyHighRange: IndexKeyFormat,
|
||||
lowRangeExclusive?: boolean,
|
||||
highRangeExclusive?: boolean
|
||||
highRangeExclusive?: boolean,
|
||||
): Promise<number> {
|
||||
let promise = this._index.countRange(
|
||||
keyLowRange,
|
||||
keyHighRange,
|
||||
lowRangeExclusive,
|
||||
highRangeExclusive
|
||||
highRangeExclusive,
|
||||
);
|
||||
return ErrorCatcher ? promise.catch(ErrorCatcher) : promise;
|
||||
}
|
||||
|
@ -117,13 +117,13 @@ export class SimpleTransactionIndexHelper<
|
|||
fullTextSearch(
|
||||
searchPhrase: string,
|
||||
resolution?: FullTextTermResolution,
|
||||
limit?: number
|
||||
limit?: number,
|
||||
): Promise<ObjectType[]> {
|
||||
// Sanitize input by removing parens, the plugin on RN explodes
|
||||
let promise = this._index.fullTextSearch(
|
||||
searchPhrase.replace(FullTextSanitizeRegex, ""),
|
||||
resolution,
|
||||
limit
|
||||
limit,
|
||||
) as Promise<ObjectType[]>;
|
||||
return ErrorCatcher ? promise.catch(ErrorCatcher) : promise;
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ export class SimpleTransactionIndexHelper<
|
|||
export class SimpleTransactionStoreHelper<
|
||||
StoreName extends string,
|
||||
ObjectType extends ItemType,
|
||||
KeyFormat extends KeyType
|
||||
KeyFormat extends KeyType,
|
||||
> {
|
||||
constructor(
|
||||
protected _store: DbStore,
|
||||
|
@ -140,7 +140,7 @@ export class SimpleTransactionStoreHelper<
|
|||
StoreName,
|
||||
ObjectType,
|
||||
KeyFormat
|
||||
>
|
||||
>,
|
||||
) {
|
||||
// Nothing to see here
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ export class SimpleTransactionStoreHelper<
|
|||
key: KeyFormat,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ObjectType[]> {
|
||||
let promise = this._store
|
||||
.openPrimaryKey()
|
||||
|
@ -176,7 +176,7 @@ export class SimpleTransactionStoreHelper<
|
|||
highRangeExclusive?: boolean,
|
||||
reverseOrSortOrder?: boolean | QuerySortOrder,
|
||||
limit?: number,
|
||||
offset?: number
|
||||
offset?: number,
|
||||
): Promise<ObjectType[]> {
|
||||
let promise = this._store
|
||||
.openPrimaryKey()
|
||||
|
@ -187,7 +187,7 @@ export class SimpleTransactionStoreHelper<
|
|||
highRangeExclusive,
|
||||
reverseOrSortOrder,
|
||||
limit,
|
||||
offset
|
||||
offset,
|
||||
) as Promise<ObjectType[]>;
|
||||
return ErrorCatcher ? promise.catch(ErrorCatcher) : promise;
|
||||
}
|
||||
|
@ -201,16 +201,16 @@ export class SimpleTransactionStoreHelper<
|
|||
indexName: DBIndex<
|
||||
DBStore<StoreName, ObjectType, KeyFormat>,
|
||||
IndexKeyFormat
|
||||
>
|
||||
>,
|
||||
): SimpleTransactionIndexHelper<ObjectType, IndexKeyFormat> {
|
||||
return new SimpleTransactionIndexHelper<ObjectType, IndexKeyFormat>(
|
||||
this._store.openIndex(indexName)
|
||||
this._store.openIndex(indexName),
|
||||
);
|
||||
}
|
||||
|
||||
openPrimaryKey(): SimpleTransactionIndexHelper<ObjectType, KeyFormat> {
|
||||
return new SimpleTransactionIndexHelper<ObjectType, KeyFormat>(
|
||||
this._store.openPrimaryKey()
|
||||
this._store.openPrimaryKey(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ export class Deferred<T> {
|
|||
this._promise = new Promise((resolve, reject) => {
|
||||
this._reject = reject;
|
||||
this._resolve = resolve as (
|
||||
value?: T | PromiseLike<T> | undefined
|
||||
value?: T | PromiseLike<T> | undefined,
|
||||
) => void;
|
||||
});
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ export class TransactionLockHelper {
|
|||
|
||||
constructor(
|
||||
private _schema: DbSchema,
|
||||
private _supportsDiscreteTransactions: boolean
|
||||
private _supportsDiscreteTransactions: boolean,
|
||||
) {
|
||||
each(this._schema.stores, (store) => {
|
||||
this._exclusiveLocks[store.name] = false;
|
||||
|
@ -100,18 +100,18 @@ export class TransactionLockHelper {
|
|||
|
||||
openTransaction(
|
||||
storeNames: string[] | undefined,
|
||||
exclusive: boolean
|
||||
exclusive: boolean,
|
||||
): Promise<TransactionToken> {
|
||||
if (storeNames) {
|
||||
const missingStore = find(
|
||||
storeNames,
|
||||
(name) => !some(this._schema.stores, (store) => name === store.name)
|
||||
(name) => !some(this._schema.stores, (store) => name === store.name),
|
||||
);
|
||||
if (missingStore) {
|
||||
return Promise.reject(
|
||||
"Opened a transaction with a store name (" +
|
||||
missingStore +
|
||||
") not defined in your schema!"
|
||||
") not defined in your schema!",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ export class TransactionLockHelper {
|
|||
transactionComplete(token: TransactionToken) {
|
||||
const pendingTransIndex = findIndex(
|
||||
this._pendingTransactions,
|
||||
(trans) => trans.token === token
|
||||
(trans) => trans.token === token,
|
||||
);
|
||||
if (pendingTransIndex !== -1) {
|
||||
const pendingTrans = this._pendingTransactions[pendingTransIndex];
|
||||
|
@ -157,13 +157,13 @@ export class TransactionLockHelper {
|
|||
"Completing a transaction that has already been completed. Stores: " +
|
||||
token.storeNames.join(",") +
|
||||
", HadSuccess: " +
|
||||
pendingTrans.hadSuccess
|
||||
pendingTrans.hadSuccess,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
"Completing a transaction that is no longer tracked. Stores: " +
|
||||
token.storeNames.join(",")
|
||||
token.storeNames.join(","),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ export class TransactionLockHelper {
|
|||
transactionFailed(token: TransactionToken, message: string) {
|
||||
const pendingTransIndex = findIndex(
|
||||
this._pendingTransactions,
|
||||
(trans) => trans.token === token
|
||||
(trans) => trans.token === token,
|
||||
);
|
||||
if (pendingTransIndex !== -1) {
|
||||
const pendingTrans = this._pendingTransactions[pendingTransIndex];
|
||||
|
@ -191,7 +191,7 @@ export class TransactionLockHelper {
|
|||
", HadSuccess: " +
|
||||
pendingTrans.hadSuccess +
|
||||
", Message: " +
|
||||
message
|
||||
message,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -199,7 +199,7 @@ export class TransactionLockHelper {
|
|||
"Failing a transaction that is no longer tracked. Stores: " +
|
||||
token.storeNames.join(",") +
|
||||
", message: " +
|
||||
message
|
||||
message,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ export class TransactionLockHelper {
|
|||
each(token.storeNames, (storeName) => {
|
||||
if (!this._exclusiveLocks[storeName]) {
|
||||
throw new Error(
|
||||
"Missing expected exclusive lock for store: " + storeName
|
||||
"Missing expected exclusive lock for store: " + storeName,
|
||||
);
|
||||
}
|
||||
this._exclusiveLocks[storeName] = false;
|
||||
|
@ -220,7 +220,7 @@ export class TransactionLockHelper {
|
|||
each(token.storeNames, (storeName) => {
|
||||
if (!(this._readOnlyCounts[storeName] > 0)) {
|
||||
throw new Error(
|
||||
"Missing expected readonly lock for store: " + storeName
|
||||
"Missing expected readonly lock for store: " + storeName,
|
||||
);
|
||||
}
|
||||
this._readOnlyCounts[storeName]--;
|
||||
|
@ -258,7 +258,7 @@ export class TransactionLockHelper {
|
|||
trans.token.storeNames,
|
||||
(storeName) =>
|
||||
this._exclusiveLocks[storeName] ||
|
||||
(trans.token.exclusive && this._readOnlyCounts[storeName] > 0)
|
||||
(trans.token.exclusive && this._readOnlyCounts[storeName] > 0),
|
||||
)
|
||||
) {
|
||||
i++;
|
||||
|
|
|
@ -36,7 +36,7 @@ export class BTreeOrderedMap<K = any, V = any> implements IOrderedMap<K, V> {
|
|||
}
|
||||
|
||||
public *entriesReversed(
|
||||
highestKey?: K
|
||||
highestKey?: K,
|
||||
): IterableIterator<IKeyValuePair<K, V>> {
|
||||
for (const value of this._tree.entriesReversed(highestKey)) {
|
||||
yield this.toKeyValue(value);
|
||||
|
|
|
@ -43,7 +43,7 @@ export class RBTreeOrderedMap<K = any, V = any> implements IOrderedMap<K, V> {
|
|||
}
|
||||
|
||||
public entriesReversed(
|
||||
_highestKey?: K
|
||||
_highestKey?: K,
|
||||
): IterableIterator<IKeyValuePair<K, V>> {
|
||||
return iterateFromLast(this._tree);
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ describe("LogWriter", () => {
|
|||
});
|
||||
assert(
|
||||
output ===
|
||||
`Create store. dbName: settings, storeName: flags, indexName: test`
|
||||
`Create store. dbName: settings, storeName: flags, indexName: test`,
|
||||
);
|
||||
|
||||
// warn
|
||||
|
@ -48,7 +48,7 @@ describe("LogWriter", () => {
|
|||
});
|
||||
assert(
|
||||
output ===
|
||||
`Create store. dbName: settings, storeName: flags, indexName: test`
|
||||
`Create store. dbName: settings, storeName: flags, indexName: test`,
|
||||
);
|
||||
|
||||
// error
|
||||
|
@ -65,7 +65,7 @@ describe("LogWriter", () => {
|
|||
});
|
||||
assert(
|
||||
output ===
|
||||
`Create store. dbName: settings, storeName: flags, indexName: test`
|
||||
`Create store. dbName: settings, storeName: flags, indexName: test`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -20,7 +20,7 @@ export function cmdToString(
|
|||
k: number,
|
||||
v: number,
|
||||
arrIndex: number,
|
||||
flag: boolean
|
||||
flag: boolean,
|
||||
) {
|
||||
switch (cmd) {
|
||||
case "GET":
|
||||
|
@ -45,7 +45,7 @@ function exceptLast<T>(arr: T[]): T[] {
|
|||
export function produceRepro(
|
||||
history: HistoryList,
|
||||
comp: TestingComparator,
|
||||
fileName: string | undefined
|
||||
fileName: string | undefined,
|
||||
) {
|
||||
let outFileName = fileName;
|
||||
if (fileName === "") {
|
||||
|
@ -73,7 +73,7 @@ describe("${outFileName}", () => {
|
|||
}
|
||||
// last result will have the "assert"
|
||||
result += `${FOUR_INDENT}assert.deepEqual(${cmdToString(
|
||||
..._.last(history)!
|
||||
..._.last(history)!,
|
||||
)}, ${JSON.stringify(finalResult(history, comp))});\n`;
|
||||
result += `\
|
||||
});
|
||||
|
@ -84,7 +84,7 @@ describe("${outFileName}", () => {
|
|||
console.log("Writing generated test case to " + outFileName);
|
||||
fs.writeFileSync(
|
||||
path.resolve("./src/tests/sorted-btree/generated", outFileName),
|
||||
result
|
||||
result,
|
||||
);
|
||||
} else {
|
||||
console.log("\n\n", result);
|
||||
|
|
|
@ -23,7 +23,7 @@ function runOpOnMap(
|
|||
k: number,
|
||||
v: number,
|
||||
arrIndex: number,
|
||||
flag: boolean
|
||||
flag: boolean,
|
||||
) {
|
||||
switch (cmd) {
|
||||
case "GET":
|
||||
|
@ -46,7 +46,7 @@ export function runOp(
|
|||
k: number,
|
||||
v: number,
|
||||
arrIndex: number,
|
||||
flag: boolean
|
||||
flag: boolean,
|
||||
) {
|
||||
try {
|
||||
const bTreeResult = runOpOnMap(bTree, cmd, k, v, arrIndex, flag);
|
||||
|
@ -72,7 +72,7 @@ export function finalResult(history: HistoryList, comp: TestingComparator) {
|
|||
function removeIdempotentOperations(history: HistoryList) {
|
||||
const idempotentCommands = ["GET", "GET_INDEX", "GET_RANGE"];
|
||||
const relevantOperations = history.filter(
|
||||
([cmd]) => !idempotentCommands.includes(cmd)
|
||||
([cmd]) => !idempotentCommands.includes(cmd),
|
||||
);
|
||||
const lastOp = _.last(history);
|
||||
if (lastOp !== _.last(relevantOperations)) {
|
||||
|
@ -111,7 +111,7 @@ function* shrinkHistory(history: HistoryList): IterableIterator<HistoryList> {
|
|||
|
||||
function runAndShrink(
|
||||
history: HistoryList,
|
||||
comp: TestingComparator
|
||||
comp: TestingComparator,
|
||||
):
|
||||
| { failed: true; history: HistoryList; numChecked: number }
|
||||
| { failed: false; numChecked: number } {
|
||||
|
@ -131,7 +131,7 @@ function runAndShrink(
|
|||
|
||||
export function findShrunkHistory(
|
||||
history: HistoryList,
|
||||
comp: TestingComparator
|
||||
comp: TestingComparator,
|
||||
) {
|
||||
const startTime = process.hrtime();
|
||||
const relevantHistory = removeIdempotentOperations(history);
|
||||
|
|
|
@ -39,7 +39,7 @@ export default class SortedArray implements ISortedTestingMap {
|
|||
getIndex(
|
||||
index: number,
|
||||
isReversed: boolean,
|
||||
startKey: number
|
||||
startKey: number,
|
||||
): [number, number] | undefined {
|
||||
let i = index;
|
||||
let entry;
|
||||
|
|
|
@ -26,7 +26,7 @@ export default class SortedBTree implements ISortedTestingMap {
|
|||
getIndex(
|
||||
index: number,
|
||||
isReversed: boolean,
|
||||
startKey: number
|
||||
startKey: number,
|
||||
): [number, number] | undefined {
|
||||
let i = index;
|
||||
if (i >= this.tree.size) return undefined;
|
||||
|
|
|
@ -41,7 +41,7 @@ function genRandBool() {
|
|||
|
||||
function genRandIndex(arrLength: number, outOfBoundsPercentage: number) {
|
||||
return Math.floor(
|
||||
Math.random() * (arrLength * (1 + outOfBoundsPercentage / 100))
|
||||
Math.random() * (arrLength * (1 + outOfBoundsPercentage / 100)),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -49,25 +49,25 @@ function shrinkAndExit(
|
|||
history: HistoryList,
|
||||
comp: TestingComparator,
|
||||
keyRange: number,
|
||||
repeatIdx: number
|
||||
repeatIdx: number,
|
||||
) {
|
||||
console.log("Attempting to shrink history...");
|
||||
const shrunkHistory = findShrunkHistory(history, comp);
|
||||
|
||||
const decreasePct = Number(
|
||||
(1 - shrunkHistory.length / history.length) * 100
|
||||
(1 - shrunkHistory.length / history.length) * 100,
|
||||
).toPrecision(2);
|
||||
console.log(
|
||||
"Minimal repro of size",
|
||||
shrunkHistory.length,
|
||||
`(${decreasePct}% decrease)`
|
||||
`(${decreasePct}% decrease)`,
|
||||
);
|
||||
console.log(
|
||||
"Details of this failure: keyRange",
|
||||
keyRange,
|
||||
"- ran",
|
||||
repeatIdx + 1,
|
||||
"rounds"
|
||||
"rounds",
|
||||
);
|
||||
const shouldWriteToFile = process.env.CI !== "true";
|
||||
shouldWriteToFile
|
||||
|
@ -103,7 +103,7 @@ for (const keyRange of KEY_RANGES) {
|
|||
console.log(
|
||||
"Repro detection time: %ds %dms",
|
||||
detectionTime[0],
|
||||
detectionTime[1] / 1000000
|
||||
detectionTime[1] / 1000000,
|
||||
);
|
||||
shrinkAndExit(history, comp, keyRange, repeatIdx);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ for (const keyRange of KEY_RANGES) {
|
|||
console.log(
|
||||
"Repro detection time: %ds %dms",
|
||||
detectionTime[0],
|
||||
detectionTime[1] / 1000000
|
||||
detectionTime[1] / 1000000,
|
||||
);
|
||||
shrinkAndExit(history, comp, keyRange, repeatIdx);
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ for (const keyRange of KEY_RANGES) {
|
|||
console.log(
|
||||
"Repro detection time: %ds %dms",
|
||||
detectionTime[0],
|
||||
detectionTime[1] / 1000000
|
||||
detectionTime[1] / 1000000,
|
||||
);
|
||||
shrinkAndExit(history, comp, keyRange, repeatIdx);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ export interface ISortedTestingMap {
|
|||
getIndex(
|
||||
index: number,
|
||||
isReversed: boolean,
|
||||
startKey: number
|
||||
startKey: number,
|
||||
): [number, number] | undefined;
|
||||
|
||||
set(k: number, v: number): boolean;
|
||||
|
|
Загрузка…
Ссылка в новой задаче