UNPKG

sided-db

Version:

Minimal wrapper of MongoDB

60 lines 2.77 kB
import { Collection, MongoClient, WithId, Document } from 'mongodb'; export declare type BSONValueRaw = string | number | boolean | null; export declare type BSONValue = BSONValueRaw | Array<BSONValueRaw> | { [key: string]: BSONValueRaw; }; export declare class Module<T extends { [key: string]: BSONValue; }> { private name; private collection; readonly moduleName: WithId<Document>; constructor(module: WithId<Document>, collection: Collection); set<T extends BSONValue>(key: string, value: T): Promise<T>; get(key: keyof T): Promise<BSONValue | undefined>; keys(): Promise<string[]>; values(): Promise<BSONValue[]>; entries(): Promise<[string, BSONValue][]>; delete(key: string): Promise<import("mongodb").UpdateResult>; clear(): Promise<import("mongodb").DeleteResult>; has(key: string): Promise<boolean>; size(): Promise<number>; empty(): Promise<boolean>; forEach(callback: (value: BSONValue, key: string) => unknown): Promise<void>; forEachAsync(callback: (value: BSONValue, key: string) => Promise<unknown>): Promise<void>; map(callback: (value: BSONValue, index: number, array: BSONValue[]) => BSONValue): Promise<BSONValue[]>; filter(callback: (value: BSONValue, index: number, array: BSONValue[]) => boolean): Promise<BSONValue[]>; some(callback: (value: BSONValue, index: number, array: BSONValue[]) => boolean): Promise<boolean>; every(callback: (value: BSONValue, index: number, array: BSONValue[]) => boolean): Promise<boolean>; reduce(callback: (previousValue: BSONValue, currentValue: BSONValue, currentIndex: number, array: BSONValue[]) => BSONValue, initialValue?: BSONValue): Promise<BSONValue>; obj(): Promise<T>; increment(key: string, value: number): Promise<import("mongodb").UpdateResult>; at(index: number): Promise<BSONValue | undefined>; hasAll(...keys: string[]): Promise<boolean>; hasAny(...keys: string[]): Promise<boolean>; } export declare class User { private readonly client; private readonly userid; private readonly collection; constructor(client: MongoClient, userid: string, options: UserDBOptions); listModules(): Promise<string[]>; getAllModules(): Promise<WithId<Document>[]>; module(module_name: string): Promise<Module<{ [key: string]: BSONValue; }>>; } export declare type UserDBOptions = { db?: string; }; export declare class UserDB { private readonly client; private readonly url; connected: boolean; db: string | undefined; constructor(url: string, options: UserDBOptions); static connect(url: string, options: UserDBOptions): Promise<UserDB>; connect(): Promise<void>; getUser(userid: string): User; } //# sourceMappingURL=index.d.ts.map