// Type definitions for mongo-curry v0.1.1 // Project: https://gitlab.com/Creplav/mongo-curry // Definitions by: Tim Rohrer // Gratitude for: @BobobUnicorn#9999 in Discord The Coding Den import * as MongoDB from "mongodb" type FindAllItemsInCollection = (collection: MongoDB.Colection) => () => Promise[]>; type FindItemByIdInCollection = (collection: MongoDB.Collection) => (id: MongoDB.ObjectId) => Promise | null>; type FindItemByValueInCollection = (collection: MongoDB.Collection) => (valueObject: Record) => Promise | null>; type InsertItemIntoCollection = (collection: MongoDB.Collection) => (item: TSchema) => Promise>; type InsertItemsIntoCollection = (collection: MongoDB.Collection) => (validation: (items: TSchema[]) => boolean) => (items: TSchema[]) => Promise | "BAD DATA">; type UpdateItemInCollection = (collection: MongoDB.Collection) => (item: TSchema) => Promise; type UpdateItemsInCollection = (collection: MongoDB.Collection) => (validation: (items: TSchema[]) => boolean) => (items: TSchema[]) => Promise; type DeleteItemFromCollection = (collection: MongoDB.Collection) => (id: MongoDB.ObjectId) => Promise; type ClearCollection = (collection: MongoDB.Collection) => () => Promise; /** Serves as a "lookup" function so dbRequest functions can determine the result type given a specific schema type. */ type DbRequestApply = TFunc extends typeof findAllItemsInCollection ? FindAllItemsInCollection : TFunc extends typeof findItemByIdInCollection ? FindItemByIdInCollection : TFunc extends typeof findItemByValueInCollection ? FindItemByValueInCollection : TFunc extends typeof insertItemIntoCollection ? InsertItemIntoCollection : TFunc extends typeof insertItemsIntoCollection ? InsertItemsIntoCollection : TFunc extends typeof updateItemInCollection ? UpdateItemInCollection : TFunc extends typeof updateItemsInCollection ? UpdateItemsInCollection : TFunc extends typeof deleteItemFromCollection ? DeleteItemFromCollection : TFunc extends typeof clearCollection ? ClearCollection : never; declare type DbRequest = typeof findAllItemsInCollection | typeof findItemByIdInCollection | typeof findItemByValueInCollection | typeof insertItemIntoCollection | typeof insertItemsIntoCollection | typeof updateItemInCollection | typeof updateItemsInCollection | typeof deleteItemFromCollection | typeof clearCollection; export declare function config({ DB_URL, DB_PORT, DB_NAME, TEST_DB_NAME }: { DB_URL: string; DB_PORT: number; DB_NAME: string; TEST_DB_NAME: string; }): void; export declare function pingDB(useTestDb?: boolean): number; export declare function executeDBRequest(dbCollection: string, useTestDb?: boolean): (dbRequest: TDbRequest) => (...requestParams: Parameters>>) => ReturnType>>; export declare function storageActionOn(collection: MongoDB.Collection): (dbRequest: TDbRequest) => (...requestParams: Parameters>>) => ReturnType>>; export declare function findAllItemsInCollection(collection: MongoDB.Collection): () => Promise[]>; export declare function findItemByIdInCollection(collection: MongoDB.Collection): (id: MongoDB.ObjectId) => Promise | null>; export declare function findItemByValueInCollection(collection: MongoDB.Collection): (valueObject: Record) => Promise | null>; export declare function insertItemIntoCollection(collection: MongoDB.Collection): (item: TSchema) => Promise>; export declare function insertItemsIntoCollection(collection: MongoDB.Collection): (validation: (items: TSchema[]) => boolean) => (items: TSchema[]) => Promise | "BAD DATA">; export declare function updateItemInCollection(collection: MongoDB.Collection): (item: TSchema) => Promise; export declare function updateItemsInCollection(collection: MongoDB.Collection): (validation: (items: TSchema[]) => boolean) => (items: TSchema[]) => Promise; export declare function deleteItemFromCollection(collection: MongoDB.Collection): (id: MongoDB.ObjectId) => Promise; export declare function clearCollection(collection: MongoDB.Collection): () => Promise;