@push.rocks/smartdata
Version:
An advanced library for NoSQL data organization and manipulation using TypeScript with support for MongoDB, data validation, collections, and custom data types.
132 lines (131 loc) • 4.49 kB
TypeScript
import * as plugins from './smartdata.plugins.js';
import { SmartdataDbCursor } from './smartdata.classes.cursor.js';
import { type IManager, SmartdataCollection } from './smartdata.classes.collection.js';
import { SmartdataDbWatcher } from './smartdata.classes.watcher.js';
export type TDocCreation = 'db' | 'new' | 'mixed';
export declare function globalSvDb(): (target: SmartDataDbDoc<unknown, unknown>, key: string) => void;
/**
* saveable - saveable decorator to be used on class properties
*/
export declare function svDb(): (target: SmartDataDbDoc<unknown, unknown>, key: string) => void;
/**
* unique index - decorator to mark a unique index
*/
export declare function unI(): (target: SmartDataDbDoc<unknown, unknown>, key: string) => void;
export declare const convertFilterForMongoDb: (filterArg: {
[key: string]: any;
}) => {
[key: string]: any;
};
export declare class SmartDataDbDoc<T extends TImplements, TImplements, TManager extends IManager = any> {
/**
* the collection object an Doc belongs to
*/
static collection: SmartdataCollection<any>;
collection: SmartdataCollection<any>;
static defaultManager: any;
static manager: any;
manager: TManager;
static createInstanceFromMongoDbNativeDoc<T>(this: plugins.tsclass.typeFest.Class<T>, mongoDbNativeDocArg: any): T;
/**
* gets all instances as array
* @param this
* @param filterArg
* @returns
*/
static getInstances<T>(this: plugins.tsclass.typeFest.Class<T>, filterArg: plugins.tsclass.typeFest.PartialDeep<T>): Promise<T[]>;
/**
* gets the first matching instance
* @param this
* @param filterArg
* @returns
*/
static getInstance<T>(this: plugins.tsclass.typeFest.Class<T>, filterArg: plugins.tsclass.typeFest.PartialDeep<T>): Promise<T>;
/**
* get a unique id prefixed with the class name
*/
static getNewId<T = any>(this: plugins.tsclass.typeFest.Class<T>, lengthArg?: number): Promise<string>;
/**
* get cursor
* @returns
*/
static getCursor<T>(this: plugins.tsclass.typeFest.Class<T>, filterArg: plugins.tsclass.typeFest.PartialDeep<T>): Promise<SmartdataDbCursor<T>>;
/**
* watch the collection
* @param this
* @param filterArg
* @param forEachFunction
*/
static watch<T>(this: plugins.tsclass.typeFest.Class<T>, filterArg: plugins.tsclass.typeFest.PartialDeep<T>): Promise<SmartdataDbWatcher<T>>;
/**
* run a function for all instances
* @returns
*/
static forEach<T>(this: plugins.tsclass.typeFest.Class<T>, filterArg: plugins.tsclass.typeFest.PartialDeep<T>, forEachFunction: (itemArg: T) => Promise<any>): Promise<void>;
/**
* returns a count of the documents in the collection
*/
static getCount<T>(this: plugins.tsclass.typeFest.Class<T>, filterArg?: plugins.tsclass.typeFest.PartialDeep<T>): Promise<number>;
/**
* how the Doc in memory was created, may prove useful later.
*/
creationStatus: TDocCreation;
/**
* updated from db in any case where doc comes from db
*/
_createdAt: string;
/**
* will be updated everytime the doc is saved
*/
_updatedAt: string;
/**
* an array of saveable properties of ALL doc
*/
globalSaveableProperties: string[];
/**
* unique indexes
*/
uniqueIndexes: string[];
/**
* an array of saveable properties of a specific doc
*/
saveableProperties: string[];
/**
* name
*/
name: string;
/**
* primary id in the database
*/
dbDocUniqueId: string;
/**
* class constructor
*/
constructor();
/**
* saves this instance but not any connected items
* may lead to data inconsistencies, but is faster
*/
save(): Promise<any>;
/**
* deletes a document from the database
*/
delete(): Promise<void>;
/**
* also store any referenced objects to DB
* better for data consistency
*/
saveDeep(savedMapArg?: plugins.lik.ObjectMap<SmartDataDbDoc<any, any>>): void;
/**
* updates an object from db
*/
updateFromDb(): Promise<void>;
/**
* creates a saveable object so the instance can be persisted as json in the database
*/
createSavableObject(): Promise<TImplements>;
/**
* creates an identifiable object for operations that require filtering
*/
createIdentifiableObject(): Promise<any>;
}