Skip to content

Commit

Permalink
typesafe ⭐
Browse files Browse the repository at this point in the history
  • Loading branch information
sksmta authored Apr 25, 2021
1 parent 8f2798b commit dcd5103
Show file tree
Hide file tree
Showing 17 changed files with 388 additions and 0 deletions.
5 changes: 5 additions & 0 deletions typings/mongo/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const base: typeof import("./source/base");
export const database: typeof import("./source/index");
export const HiveErr: typeof import("./source/err");
export const schema: (connection: any, name: any) => any;
export const util: typeof import("./source/util");
48 changes: 48 additions & 0 deletions typings/mongo/source/base.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export = Base;
declare class Base extends EventEmitter {
/**
*Mongoose connection base.
* @param {string} mongodbURL Mongodb Database URL.
* @param {object} connectionOptions Mongodb connection options
*/
constructor(mongodbURL: string, connectionOptions?: object);
/**
* Mongoose connection options
* @type {ConnectionOptions}
*/
options: any;
/**
* Returns mongodb connection
* @type {MongooseConnection}
*/
connection: any;
/**
* Timestamp when database became ready
* @type {Date}
*/
readyAt: Date;
/**
* Creates mongodb connection
* @returns {MongooseConnection}
* @ignore
*/
_create(url: any): any;
dbURL: string;
/**
* Destroys database
* @ignore
*/
_destroyDatabase(): void;
/**
* Current database url
* @type {string}
*/
get url(): string;
/**
* Returns database connection state
* @type {("DISCONNECTED"|"CONNECTED"|"CONNECTING"|"DISCONNECTING")}
*/
get state(): "DISCONNECTED" | "CONNECTED" | "CONNECTING" | "DISCONNECTING";
}
import EventEmitter_1 = require("events");
import EventEmitter = EventEmitter_1.EventEmitter;
4 changes: 4 additions & 0 deletions typings/mongo/source/err.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export = HiveErr;
declare class HiveErr extends Error {
constructor(message: any, name?: any);
}
215 changes: 215 additions & 0 deletions typings/mongo/source/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
export = database;
declare class database extends Base {
/**
* @param {string}
* @param {string}
* @param {object}
*/
constructor(mongodbURL: any, name: any, connectionOptions?: {});
/**
* @type {MongooseDocument}
*/
schema: any;
/**
* @param {string} key
* @param {any} value
* @returns {Promise<any>}
*/
init(key: string, value: any): Promise<any>;
/**
* @param {string} key
*/
del(key: string): Promise<boolean>;
/**
* @param {string} key
*/
exists(key: string): Promise<boolean>;
/**
* @param {string} key
*/
has(key: string): Promise<boolean>;
/**
* @param {string} key
*/
get(key: string): Promise<any>;
/**
* @param {string} key
*/
fetch(key: string): Promise<any>;
/**
* @typedef {object} Data
* @property {string} ID
* @property {any} data
*/
/**
* @param {number} limit
*/
fetchArray(limit?: number): Promise<any>;
getArray(limit: any): Promise<any>;
/**
* @param {number} limit
*/
fetchAll(limit: number): Promise<any>;
delAll(): Promise<boolean>;
/**
* @param {string} key
* @param {string} operator
* @param {number} value
*/
math(key: string, operator: string, value: number): Promise<any>;
/**
* @param {string} key
* @param {number} Value
*/
add(key: string, value: any): Promise<any>;
/**
* @param {string} key
* @param {number} value
*/
subtract(key: string, value: number): Promise<any>;
/**
* @type {number}
*/
get uptime(): number;
/**
* @param {string} fileName
* @param {string} path
*/
export(fileName?: string, path?: string): Promise<any>;
/**
* @param {Array} data
* @param {object} ops
* @param {boolean}
* @param {boolean}
*/
import(data?: any[], ops?: object): Promise<any>;
disconnect(): void;
connect(url: any): any;
get name(): any;
_read(): Promise<number>;
_write(): Promise<number>;
/**
* @typedef {object} DatabaseLatency
* @property {number} read Read latency
* @property {number} write Write latency
* @property {number} average Average latency
*/
fetchLatency(): Promise<{
read: number;
write: number;
average: number;
}>;
ping(): Promise<{
read: number;
write: number;
average: number;
}>;
/**
* @param {string} key
* @param {object} ops
*/
startsWith(key: string, ops: object): Promise<any[]>;
/**
* Resolves data type
* @param {string} key key
* @example console.log(await db.type("foo"));
* @returns {Promise<"string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array">}
*/
datatype(key: string): Promise<"string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | "array">;
/**
* Returns array of the keys
* @example const keys = await db.keyarray();
* console.log(keys);
* @returns {Promise<string[]>}
*/
keyArray(): Promise<string[]>;
/**
* Returns array of the values
* @example const data = await db.valueArray();
* console.log(data);
* @returns {Promise<any[]>}
*/
valueArray(): Promise<any[]>;
/**
* Pushes an item into array
* @param {string} key key
* @param {any|any[]} value Value to push
* @example db.push("users", "John"); // -> ["John"]
* db.push("users", ["Milo", "Simon", "Kyle"]); // -> ["John", "Milo", "Simon", "Kyle"]
* @returns {Promise<any>}
*/
push(key: string, value: any | any[]): Promise<any>;
/**
* Removes an item from array
* @param {string} key key
* @param {any|any[]} value item to remove
* @param {boolean} [multiple=true] if it should pull multiple items. Defaults to `true`.
* <warn>Currently, you can use `multiple` with `non array` pulls only.</warn>
* @example db.pull("users", "John"); // -> ["Milo", "Simon", "Kyle"]
* db.pull("users", ["Milo", "Simon"]); // -> ["Kyle"]
* @returns {Promise<any>}
*/
delFromArray(key: string, value: any | any[], multiple?: boolean): Promise<any>;
/**
* Returns entries count of current model
* @returns {Promise<number>}
* @example const entries = await db.entries();
* console.log(`There are total ${entries} entries!`);
*/
entries(): Promise<number>;
/**
* Returns raw data from current model
* @param {object} params Search params
* @returns {Promise<MongooseDocument>}
* @example const raw = await db.raw();
* console.log(raw);
*/
raw(params: object): Promise<any>;
/**
* Returns random entry from the database
* @param {number} n Number entries to return
* @returns {Promise<any[]>}
* @example const random = await db.random();
* console.log(random);
*/
random(n?: number): Promise<any[]>;
/**
* This method acts like `quick.db#table`. It will return new instance of itself.
* @param {string} name Model name
* @returns {Database}
*/
table(name: string): any;
/**
* This method exports **QuickMongo** data to **Quick.db**
* @param {any} quickdb Quick.db instance
* @returns {Promise<any[]>}
* @example const data = await db.exportToQuickDB(quickdb);
*/
/**
* Returns **QuickMongo Util**
* @example const parsed = db.utils.parseKey("foo.bar");
* console.log(parsed);
* @type {Util}
*/
get utils(): Util;
/**
* Updates current model and uses new one
* @param {string} name model name to use
* @returns {MongooseDocument}
*/
updateModel(name: string): any;
/**
* Allows you to eval code using `this` keyword.
* @param {string} code
*/
_eval(code: string): any;
}
declare namespace database {
export { Data };
}
import Base = require("./base");
import Util = require("./util");
type Data = {
ID: string;
data: any;
};
2 changes: 2 additions & 0 deletions typings/mongo/source/schema.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function _exports(connection: any, name: any): any;
export = _exports;
76 changes: 76 additions & 0 deletions typings/mongo/source/util.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
export = Util;
declare class Util {
/**
* Returns true if provided key is valid
* @param {any} str Anything to test
* @returns {boolean}
*/
static isKey(str: any): boolean;
/**
* Returns true if the given data is valid
* @param {any} data Any data
* @returns {boolean}
*/
static isValue(data: any): boolean;
/**
* @typedef {object} KEY
* @property {string | undefined} key Parsed Key
* @property {string | undefined} target Parsed target
*/
/**
* Returns target & key from the given string (quickdb style)
* @param {string} key key to parse
* @example Util.parseKey("myitem.items");
* // -> { key: "myitems", target: "items" }
* @returns {KEY}
*/
static parseKey(key: string): KEY;
/**
* Sort data
* @param {string} key Key
* @param {Array} data Data
* @param {object} ops options
* @example Util.sort("user_", {...}, { sort: ".data" });
* @returns {any[]}
*/
static sort(key: string, data: any[], ops: object): any[];
/**
* Data resolver
* @param {string} key Data key
* @param {any} data Data
* @param {any} value value
* @example Util.setData("user.items", {...}, ["pen"]);
* @returns {any}
*/
static setData(key: string, data: any, value: any): any;
/**
* Data resolver
* @param {string} key Data key
* @param {any} data Data
* @param {any} value value
* @example Util.unsetData("user.items", {...});
* @returns {any}
*/
static unsetData(key: string, data: any): any;
/**
* Data resolver
* @param {string} key Key
* @param {any} data Data
* @example Util.getData("user.items", {...});
* @returns {any}
*/
static getData(key: string, data: any): any;
}
declare namespace Util {
export { KEY };
}
type KEY = {
/**
* Parsed Key
*/
key: string | undefined;
/**
* Parsed target
*/
target: string | undefined;
};
16 changes: 16 additions & 0 deletions typings/postgres/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Pool, PoolConfig, QueryResult } from "pg";
export interface PostgresOptions {
schema: string;
}
export declare class Postgres {
pool: Pool;
options: PostgresOptions;
constructor(config: PoolConfig, options?: PostgresOptions);
fetchArray(): Promise<any>;
exists(key: string): Promise<boolean>;
init(key: string, val: any): Promise<boolean>;
get(key: string): Promise<any>;
delete(key: string): Promise<boolean>;
push(key: string, element: any): Promise<boolean>;
search(query: string, data?: Array<any>): Promise<QueryResult>;
}
1 change: 1 addition & 0 deletions typings/postgres/main.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Postgres, PostgresOptions } from './index';
2 changes: 2 additions & 0 deletions typings/sqlite/src/functions/add.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function _exports(db: any, params: any, options: any): any;
export = _exports;
5 changes: 5 additions & 0 deletions typings/sqlite/src/functions/array.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare function _exports(db: any, params: any, options: any): {
ID: any;
data: any;
}[];
export = _exports;
2 changes: 2 additions & 0 deletions typings/sqlite/src/functions/datatype.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function _exports(db: any, params: any, options: any): "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
export = _exports;
2 changes: 2 additions & 0 deletions typings/sqlite/src/functions/del.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function _exports(db: any, params: any, options: any): boolean;
export = _exports;
2 changes: 2 additions & 0 deletions typings/sqlite/src/functions/fetch.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function _exports(db: any, params: any, options: any): any;
export = _exports;
2 changes: 2 additions & 0 deletions typings/sqlite/src/functions/has.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function _exports(db: any, params: any, options: any): boolean;
export = _exports;
2 changes: 2 additions & 0 deletions typings/sqlite/src/functions/init.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function _exports(db: any, params: any, options: any): any;
export = _exports;
Loading

0 comments on commit dcd5103

Please sign in to comment.