Signal-Desktop/ts/types/IndexedDB.ts

23 lines
886 B
TypeScript
Raw Permalink Normal View History

2020-10-30 20:34:04 +00:00
// Copyright 2018-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
// IndexedDB doesnt support boolean indexes so we map `true` to 1 and `false`
// to `0`, i.e. `IndexableBoolean`.
// N.B. Using `undefined` allows excluding an entry from an index. Useful
// when index size is a consideration or one only needs to query for `true`,
// i.e. `IndexablePresence`.
2018-04-15 01:08:36 +00:00
export type IndexableBoolean = IndexableFalse | IndexableTrue;
export type IndexablePresence = undefined | IndexableTrue;
2018-04-15 01:08:36 +00:00
type IndexableFalse = 0;
type IndexableTrue = 1;
2018-04-15 01:08:36 +00:00
export const INDEXABLE_FALSE: IndexableFalse = 0;
export const INDEXABLE_TRUE: IndexableTrue = 1;
export const toIndexableBoolean = (value: boolean): IndexableBoolean =>
2018-04-15 01:08:36 +00:00
value ? INDEXABLE_TRUE : INDEXABLE_FALSE;
export const toIndexablePresence = (value: boolean): IndexablePresence =>
value ? INDEXABLE_TRUE : undefined;