nodedb-json
Version:
A lightweight JSON-based database for Node.js with TypeScript support, indexing, and complex query capabilities
34 lines (33 loc) • 1.35 kB
TypeScript
import type { IndexOptions } from './index-definitions.js';
export type AnyValue = any;
export type DbSchema = object;
export type SchemaKey<TSchema extends DbSchema> = Extract<keyof TSchema, string>;
export type SchemaValue<TValue> = unknown extends TValue ? any : TValue;
export type CollectionKey<TSchema extends DbSchema> = {
[K in SchemaKey<TSchema>]: TSchema[K] extends readonly unknown[] ? K : never;
}[SchemaKey<TSchema>];
export type ArrayItem<TValue> = TValue extends readonly (infer TItem)[] ? TItem : never;
export type CollectionItem<TSchema extends DbSchema, K extends CollectionKey<TSchema>> = ArrayItem<TSchema[K]>;
export type PredicateFunction<T> = (item: T) => boolean;
export type UpdaterObject<T = Record<string, any>> = Partial<T>;
export interface CloseOptions {
force?: boolean;
}
export interface DbOptions<TSchema extends DbSchema = Record<string, any>> {
autoSave?: boolean;
createIfNotExists?: boolean;
defaultValue?: Partial<TSchema>;
enableIndexing?: boolean;
autoIndex?: boolean;
indexValueMode?: 'strict' | 'coerce';
indexes?: IndexOptions;
persistIndexes?: boolean;
indexMetaPath?: string;
atomicWrites?: boolean;
backupOnWrite?: boolean;
backupPath?: string;
tempPath?: string;
fileLock?: boolean;
lockPath?: string;
staleLockMs?: number;
}