harperdb
Version:
HarperDB is a distributed database, caching service, streaming broker, and application development platform focused on performance and ease of use.
50 lines (49 loc) • 2.48 kB
TypeScript
/**
* This module is responsible for handling metadata encoding and decoding in database records, which is
* used for local timestamps (that lmdb-js can assign during a transaction for guaranteed monotonic
* assignment across threads) and can be used for storing residency information as well. This
* patches the primary store to properly get the metadata and assign it to the entries.
*/
import { Encoder } from 'msgpackr';
import './blob.ts';
export type Entry = {
key: any;
value: any;
version: number;
localTime: number;
expiresAt: number;
metadataFlags: number;
deref?: () => any;
};
export declare const TIMESTAMP_PLACEHOLDER: Uint8Array<ArrayBuffer>;
export declare const LAST_TIMESTAMP_PLACEHOLDER: Uint8Array<ArrayBuffer>;
export declare const PREVIOUS_TIMESTAMP_PLACEHOLDER: Uint8Array<ArrayBuffer>;
export declare const NEW_TIMESTAMP_PLACEHOLDER: Uint8Array<ArrayBuffer>;
export declare const LOCAL_TIMESTAMP: unique symbol;
export declare const METADATA: unique symbol;
export declare const ENTRY: unique symbol;
export declare const NO_TIMESTAMP = 0;
export declare const TIMESTAMP_ASSIGN_NEW = 0;
export declare const TIMESTAMP_ASSIGN_LAST = 1;
export declare const TIMESTAMP_ASSIGN_PREVIOUS = 3;
export declare const TIMESTAMP_RECORD_PREVIOUS = 4;
export declare const HAS_EXPIRATION = 16;
export declare const HAS_RESIDENCY_ID = 32;
export declare const PENDING_LOCAL_TIME = 1;
export declare const HAS_STRUCTURE_UPDATE = 256;
export declare const entryMap: WeakMap<any, Entry>;
export declare let lastMetadata: Entry | null;
export declare class RecordEncoder extends Encoder {
constructor(options: any);
decode(buffer: any, options: any): any;
}
export declare function handleLocalTimeForGets(store: any, rootStore: any): any;
export declare function recordUpdater(store: any, tableId: any, auditStore: any): (id: any, record: any, existingEntry: any, newVersion: any, assignMetadata?: number, // when positive, this has a set of metadata flags for the record
audit?: boolean, // true -> audit this record. false -> do not. null -> retain any audit timestamp
options?: any, type?: string, resolveRecord?: boolean, // indicates that we are resolving (from source) record that was previously invalidated
auditRecord?: any) => Promise<void>;
export declare function removeEntry(store: any, entry: any, existingVersion?: number): any;
export interface RecordObject {
getUpdatedTime(): number;
getExpiresAt(): number;
}