New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

firestorm-db

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firestorm-db - npm Package Compare versions

Comparing version 1.10.3 to 1.11.0

13

package.json
{
"name": "firestorm-db",
"version": "1.10.3",
"version": "1.11.0",
"description": "Self hosted Firestore-like database with API endpoints based on micro bulk operations",

@@ -16,3 +16,3 @@ "main": "src/index.js",

"types": "npx tsc",
"prettier": "prettier \"{,!(node_modules)/**/}*.js\" --config .prettierrc --write",
"prettier": "prettier \"{,!(node_modules)/**/}*.{js,ts}\" --config .prettierrc --write",
"cov": "npm run php_stop ; npm run php_start && nyc --reporter=text mocha tests/**/*.spec.js; npm run php_stop"

@@ -43,5 +43,3 @@ },

"dependencies": {
"axios": "^1.6.0",
"firestorm-db": "^1.10.2",
"type-fest": "^4.6.0"
"axios": "^1.6.2"
},

@@ -57,6 +55,7 @@ "devDependencies": {

"nyc": "^15.1.0",
"prettier": "^3.0.3",
"prettier": "^3.1.1",
"recursive-copy": "^2.0.14",
"typescript": "^5.2.2"
"type-fest": "^4.8.3",
"typescript": "^5.3.3"
}
}

@@ -28,3 +28,3 @@ <div align="center">

First, you need to configure the address of the API, and your token if needed:
First, you need to configure your API address, and your token if needed:

@@ -53,3 +53,3 @@ ```js

userCollection
.read_raw()
.readRaw()
.then((res) => console.log(res))

@@ -63,4 +63,4 @@ .catch((err) => console.error(err));

- The name of the collection as a `String`.
- The method adder, which allows to inject methods to the get methods results. This would be a `Function` taking the element as an argument.
- The name of the collection as a `String`.
- The method adder, which allows to inject methods to the get methods results. This would be a `Function` taking the element as an argument.

@@ -98,5 +98,5 @@ ```js

Search method can take one or more options to filter entries in a collection. A search option studies a `field` with a `criteria` and compares it to a `value`. On string values you can now use the boolean `ignoreCase` option.
The search method can take one or more options to filter entries in a collection. A search option studies a `field` with a `criteria` and compares it to a `value`. You can also use the boolean `ignoreCase` option for string values.
Not all criterias are available depending the field type. There are more options available than the firestore `where` command, allowing you to get better and faster search results.
Not all criteria are available depending the field type. There are more options available than the firestore `where` command, allowing you to get better and faster search results.

@@ -210,3 +210,3 @@ ### All search options available

You can now use the wrapper functions in order to upload, get and delete a file.
You can use the wrapper functions in order to upload, get and delete a file.
If the folder is accessible from server url, you can directly type its address.

@@ -216,3 +216,3 @@

The PHP scripts creates folders and files. So if the PHP user doesn't have the rights to write, the script will fail.
The PHP scripts create folders and files, so the script will fail if the PHP user doesn't have write permissions.
You can give rights to a folder with the following command:

@@ -263,4 +263,4 @@

getPromise
.then((filecontent) => {
console.log(filecontent); // 'but your kids are gonna love it.
.then((fileContent) => {
console.log(fileContent); // 'but your kids are gonna love it.
})

@@ -309,3 +309,3 @@ .catch((err) => {

All Firestorm methods correspond to an equivalent Axios request. Read requests are GET request and write requests are POST requests with a JSON data.
All Firestorm methods correspond to an equivalent Axios request. Read requests are GET request and write requests are POST requests with provided JSON data.

@@ -312,0 +312,0 @@ You always have the same first keys and the one key per method:

try {
if (typeof process === "object") {
var axios = require("axios").default;
}
if (typeof process === "object") var axios = require("axios").default;
} catch (_error) {}

@@ -9,6 +7,6 @@

* @typedef {Object} SearchOption
* @property {String} field The field you want to search in
* @property {string} field The field you want to search in
* @property {"!=" | "==" | ">=" | "<=" | "<" | ">" | "in" | "includes" | "startsWith" | "endsWith" | "array-contains" | "array-contains-any" | "array-length-(eq|df|gt|lt|ge|le)" } criteria filter criteria
* @property {String | Number | Boolean | Array } value the value you want to compare
* @property {Boolean} ignoreCase Ignore case on search string
* @property {string | number | boolean | Array } value the value you want to compare
* @property {boolean} ignoreCase Ignore case on search string
*/

@@ -18,6 +16,6 @@

* @typedef {Object} EditObject
* @property {String | Number } id the affected element
* @property {String} field The field you want to edit
* @property {string | number } id the affected element
* @property {string} field The field you want to edit
* @property {"set" | "remove" | "append" | "increment" | "decrement" | "array-push" | "array-delete" | "array-splice"} operation Wanted operation on field
* @property {String | Number | Boolean | Array } [value] // the value you want to compare
* @property {string | number | boolean | Array } [value] // the value you want to compare
*/

@@ -27,10 +25,6 @@

* @typedef {Object} SelectOption
* @property {Array<String>} fields Chosen fields to eventually return
* @property {Array<string>} fields Chosen fields to eventually return
*/
/**
* @import {AxiosPromise} from 'axios'
*/
/**
* @ignore

@@ -72,3 +66,3 @@ */

* @ignore
* @param {Promise<T>} request The Axios concerned request
* @param {Promise<import("axios").AxiosPromise>} request The Axios concerned request
*/

@@ -90,12 +84,13 @@ const __extract_data = (request) => {

* Class representing a collection
* @template T
*/
class Collection {
/**
* @param {String} name The name of the Collection
* @param {Function?} addMethods Additional methods and data to add to the objects
* @param {string} name The name of the Collection
* @param {Function} [addMethods] Additional methods and data to add to the objects
*/
constructor(name, addMethods = (el) => el) {
if (name === undefined) throw new Exception("Collection must have a name");
if (name === undefined) throw new SyntaxError("Collection must have a name");
if (typeof addMethods !== "function")
throw new Exception("Collection must have a addMethods of type function");
throw new TypeError("Collection must have an addMethods of type Function");
this.addMethods = addMethods;

@@ -109,3 +104,3 @@ this.collectionName = name;

* @ignore
* @param {AxiosPromise} req Incoming request
* @param {import("axios").AxiosPromise} req Incoming request
* @returns {Object|Object[]}

@@ -153,3 +148,3 @@ */

data: data,
})
})
: axios.post(readAddress(), data);

@@ -161,3 +156,3 @@ return this.__extract_data(request);

* Get an element from the collection
* @param {String|Number} id The entry ID
* @param {string | number} id The entry ID
* @returns {Promise<T>} Result entry you may be looking for

@@ -176,3 +171,3 @@ */

/**
* @returns {String} returns sha1 hash of the file. can be used to see if same file content without downloading the file for example
* @returns {string} returns sha1 hash of the file. can be used to see if same file content without downloading the file for example
*/

@@ -189,3 +184,3 @@ sha1() {

* @param {SearchOption[]} searchOptions Array of search options
* @param {(Number|false|true)?} random Random result seed, disabled by default, but can activated with true or a given seed
* @param {(number | false | true)} [random] Random result seed, disabled by default, but can activated with true or a given seed
* @returns {Promise<T[]>}

@@ -261,3 +256,3 @@ */

* Search specific keys through collection
* @param {String[]|Number[]} keys Wanted keys
* @param {string[] | number[]} keys Wanted keys
* @returns {Promise<T[]>} Search results

@@ -289,6 +284,13 @@ */

/**
* @deprecated use readRaw instead
*/
read_raw() {
return this.readRaw();
}
/**
* Returns the whole content of the file
* @returns {Promise} // the get promise of the collection raw file content
*/
read_raw() {
readRaw() {
return new Promise((resolve, reject) => {

@@ -337,5 +339,5 @@ this.__get_request({

* Returns random max entries offsets with a given seed
* @param {Integer} max
* @param {Integer} seed
* @param {Integer} offset
* @param {number} max integer
* @param {number} seed integer
* @param {number} offset integer
* @returns {Promise} entries

@@ -383,8 +385,8 @@ */

/**
* creates write requests with given value
* Creates write requests with given value
* @private
* @ignore
* @param {String} command The write command you want
* @param {Object?} value The value for this command
* @param {Boolean | undefined} multiple if I need to delete multiple
* @param {string} command The write command you want
* @param {Object} [value] The value for this command
* @param {boolean | undefined} multiple if I need to delete multiple
* @returns {Object} Write data object

@@ -428,5 +430,5 @@ */

*/
write_raw(value) {
writeRaw(value) {
if (value === undefined || value === null) {
return Promise.reject(new Error("write_raw value must not be undefined or null"));
return Promise.reject(new Error("writeRaw value must not be undefined or null"));
}

@@ -437,2 +439,12 @@ return this.__extract_data(axios.post(writeAddress(), this.__write_data("write_raw", value)));

/**
* Writes the raw JSON file
* @param {Object} value
* @deprecated use writeRaw instead
* @returns {Promise<any>}
*/
write_raw(value) {
return this.writeRaw(value);
}
/**
* Add automatically a value to the JSON

@@ -477,3 +489,3 @@ * @param {Object} value The value to add

* Remove entry with its key from the JSON
* @param {String | Number} key The key from the entry to remove
* @param {string | number} key The key from the entry to remove
* @returns {Promise<any>}

@@ -487,3 +499,3 @@ */

* Remove entry with their keys from the JSON
* @param {String[] | Number[]} keys The key from the entries to remove
* @param {string[] | number[]} keys The key from the entries to remove
* @returns {Promise<any>}

@@ -497,3 +509,3 @@ */

* Sets an entry in the JSON
* @param {String} key The key of the value you want to set
* @param {string} key The key of the value you want to set
* @param {Object} value The value you want for this key

@@ -510,3 +522,3 @@ * @returns {Promise<any>}

* Sets multiple entries in the JSON
* @param {String[]} keys The array of keys of the values you want to set
* @param {string[]} keys The array of keys of the values you want to set
* @param {Object[]} values The values you want for these keys

@@ -547,7 +559,7 @@ * @returns {Promise<any>}

/**
* @param {String} newValue The new address value
* @returns {String} The stored address value
* @param {string} newValue The new address value
* @returns {string} The stored address value
* @memberof firestorm
*/
address: function (newValue = undefined) {
address(newValue = undefined) {
if (newValue === undefined) return readAddress();

@@ -560,6 +572,6 @@ if (newValue) _address = newValue;

/**
* @param {String} newValue The new write token
* @returns {String} The stored write token
* @param {string} newValue The new write token
* @returns {string} The stored write token
*/
token: function (newValue = undefined) {
token(newValue = undefined) {
if (newValue === undefined) return writeToken();

@@ -571,7 +583,7 @@ if (newValue) _token = newValue;

/**
* @param {String} name Collection name to get
* @param {string} name Collection name to get
* @param {Function} addMethods Additional methods and data to add to the objects
* @returns {Collection}
*/
collection: function (name, addMethods = (el) => el) {
collection(name, addMethods = (el) => el) {
return new Collection(name, addMethods);

@@ -582,5 +594,5 @@ },

*
* @param {String} name Table name to get
* @param {string} name Table name to get
*/
table: function (name) {
table(name) {
return this.collection(name);

@@ -597,3 +609,3 @@ },

* @memberof firestorm
* @type {object}
* @type {Object}
* @namespace firestorm.files

@@ -605,9 +617,9 @@ */

* @memberof firestorm.files
* @param {String} path File path wanted
* @param {string} path File path wanted
*/
get: function (path) {
get(path) {
return __extract_data(
axios.get(fileAddress(), {
params: {
path: path,
path,
},

@@ -624,3 +636,3 @@ }),

*/
upload: function (form) {
upload(form) {
form.append("token", firestorm.token());

@@ -637,9 +649,9 @@ return axios.post(fileAddress(), form, {

* @memberof firestorm.files
* @param {String} path File path to delete
* @param {string} path File path to delete
* @returns {Promise} http response
*/
delete: function (path) {
delete(path) {
return axios.delete(fileAddress(), {
data: {
path: path,
path,
token: firestorm.token(),

@@ -653,7 +665,5 @@ },

try {
if (typeof process === "object") {
module.exports = firestorm;
}
if (typeof process === "object") module.exports = firestorm;
} catch (_error) {
// normal browser
}

@@ -1,277 +0,302 @@

export type number_criteria =
| "==" /** test if the value is equal to the provided value */
| "!=" /** test if the value is not equal to the provided value */
| "<" /** test if the value is less than the provided value */
| "<=" /** test if the value is less than or equal to the provided value */
| ">" /** test if the value is greater than the provided value */
| ">=" /** test if the value is greater than or equal to the provided value */
| "in" /** test if the value is in the given array */
;
export type NumberCriteria =
| "==" /** test if the value is equal to the provided value */
| "!=" /** test if the value is not equal to the provided value */
| "<" /** test if the value is less than the provided value */
| "<=" /** test if the value is less than or equal to the provided value */
| ">" /** test if the value is greater than the provided value */
| ">=" /** test if the value is greater than or equal to the provided value */
| "in" /** test if the value is in the given array */;
export type string_criteria =
| "==" /** test if the string value is equal to the provided value */
| "!=" /** test if the string value is not equal to the provided value */
| "<" /** test if the string value length is less than the provided value */
| "<=" /** test if the string value length is less than or equal to the provided value */
| ">" /** test if the string value length is greater than the provided value */
| ">=" /** test if the string value length is greater than or equal to the provided value */
| "in" /** test if the string value is in the given array */
| "includes" /** test if the string value includes the provided value */
| "contains" /** same as "includes" */
| "startsWith" /** test if the string value starts with the provided value */
| "endsWith" /** test if the string value ends with the provided value */
;
export type StringCriteria =
| "==" /** test if the string value is equal to the provided value */
| "!=" /** test if the string value is not equal to the provided value */
| "<" /** test if the string value length is less than the provided value */
| "<=" /** test if the string value length is less than or equal to the provided value */
| ">" /** test if the string value length is greater than the provided value */
| ">=" /** test if the string value length is greater than or equal to the provided value */
| "in" /** test if the string value is in the given array */
| "includes" /** test if the string value includes the provided value */
| "contains" /** same as "includes" */
| "startsWith" /** test if the string value starts with the provided value */
| "endsWith" /** test if the string value ends with the provided value */;
export type array_criteria =
| "array-contains" /** test if the value is in the given array */
| "array-contains-any" /** test if the any value of the array is in the given array */
| "array-length-eq" /** test if the array length is equal to the provided value */
| "array-length-df" /** test if the array length is different from the provided value */
| "array-length-gt" /** test if the array length is greater than the provided value */
| "array-length-lt" /** test if the array length is less than the provided value */
| "array-length-ge" /** test if the array length is greater than or equal to the provided value */
| "array-length-le" /** test if the array length is less than or equal to the provided value */
;
export type ArrayCriteria =
| "array-contains" /** test if the value is in the given array */
| "array-contains-any" /** test if the any value of the array is in the given array */
| "array-length-eq" /** test if the array length is equal to the provided value */
| "array-length-df" /** test if the array length is different from the provided value */
| "array-length-gt" /** test if the array length is greater than the provided value */
| "array-length-lt" /** test if the array length is less than the provided value */
| "array-length-ge" /** test if the array length is greater than or equal to the provided value */
| "array-length-le" /** test if the array length is less than or equal to the provided value */;
export type boolean_criteria =
| "!=" /** test if the value is not equal to the provided value */
| "==" /** test if the value is equal to the provided value */
;
export type BooleanCriteria =
| "!=" /** test if the value is not equal to the provided value */
| "==" /** test if the value is equal to the provided value */;
export type all_criteria =
| string_criteria /** criteria applying to strings */
| array_criteria /** criteria applying to arrays */
| boolean_criteria /** criteria applying to boolean */
| number_criteria /** criteria applying to numbers */
;
export type AllCriteria =
| StringCriteria /** criteria applying to strings */
| ArrayCriteria /** criteria applying to arrays */
| BooleanCriteria /** criteria applying to boolean */
| NumberCriteria /** criteria applying to numbers */;
export type Criteria<T> =
| T extends Function ? never : never /** methods are not allowed in the field (they are not saved in the collection JSON file) */
| T extends Array<unknown> ? array_criteria : never
| T extends string ? string_criteria : never
| T extends number ? number_criteria : never
| T extends boolean ? boolean_criteria : never
export type Criteria<T> = T extends Function
? never
:
| never /** methods are not allowed in the field (they are not saved in the collection JSON file) */
| T extends Array<unknown>
? ArrayCriteria
: never | T extends string
? StringCriteria
: never | T extends number
? NumberCriteria
: never | T extends boolean
? BooleanCriteria
: never;
export type any_operation =
| "set" /** @param {T} value - set the field to the given value */
| "remove" /** @param {null|undefined|any} value - remove the field */
;
export type AnyOperation =
| "set" /** @param value - set the field to the given value */
| "remove" /** @param value - remove the field */;
export type string_operation =
| "append" /** @param {string} value - append the given value to the field */
;
export type StringOperation = "append" /** @param value - append the given value to the field */;
export type number_operation =
| "increment" /** @param {number?} value - increment the field by the given value, or by one */
| "decrement" /** @param {number?} value - decrement the field by the given value, or by one */
;
export type NumberOperation =
| "increment" /** @param value - increment the field by the given value, or by one */
| "decrement" /** @param value - decrement the field by the given value, or by one */;
export type array_operation =
| "array-push" /** @param {any} value - push the given value to the field */
| "array-delete" /** @param {number} index - delete the value at the given index @see https://www.php.net/manual/fr/function.array-splice */
| "array-splice" /** @param {number[]} indexes - remove certains elements of the array field @see https://www.php.net/manual/fr/function.array-splice */
;
export type ArrayOperation =
| "array-push" /** @param value - push the given value to the field */
| "array-delete" /** @param index - delete the value at the given index @see https://www.php.net/manual/fr/function.array-splice */
| "array-splice" /** @param indexes - remove certain elements of the array field @see https://www.php.net/manual/fr/function.array-splice */;
type _operation<T> =
| T extends string ? string_operation : never
| T extends number ? number_operation : never
| T extends Array<unknown> ? array_operation : never
| T extends object|Function ? never : never
;
type _Operation<T> = T extends string
? StringOperation
: never | T extends number
? NumberOperation
: never | T extends Array<unknown>
? ArrayOperation
: never | T extends object | Function
? never
: never;
export type Operation<T> = {
[K in keyof T]: _operation<T[K]>
}[keyof T] | any_operation;
export type Operation<T> =
| {
[K in keyof T]: _Operation<T[K]>;
}[keyof T]
| AnyOperation;
type BaseEditField<T> = {
[K in keyof T]: {
id: number|string;
}
[K in keyof T]: {
id: number | string;
};
}[keyof T];
type Field<P, T> = {
[K in keyof T]: T[K] extends P ? K : never;
[K in keyof T]: T[K] extends P ? K : never;
}[keyof T];
export type EditField<T> = {
[K in keyof T]: BaseEditField<T> & ({
field: K | string;
operation: "remove";
} | {
field: Field<Boolean, T>;
operation: "invert";
} | {
field: Field<Number,T>;
operation: "increment" | "decrement";
value?: Number;
} | {
field: Field<T[K], T> | String;
operation: "set";
value: T[K] | any;
} | {
field: Field<Array<unknown>, T>;
operation: "array-push";
value: T[K];
} | {
field: Field<Array<unknown>, T>;
operation: "array-delete",
value: Number
} | {
field: Field<Array<unknown>, T>;
operation: "array-slice",
value: [Number, Number]
})
[K in keyof T]: BaseEditField<T> &
(
| {
field: K | string;
operation: "remove";
}
| {
field: Field<boolean, T>;
operation: "invert";
}
| {
field: Field<number, T>;
operation: "increment" | "decrement";
value?: Number;
}
| {
field: Field<T[K], T> | string;
operation: "set";
value: T[K] | any;
}
| {
field: Field<Array<unknown>, T>;
operation: "array-push";
value: T[K];
}
| {
field: Field<Array<unknown>, T>;
operation: "array-delete";
value: number;
}
| {
field: Field<Array<unknown>, T>;
operation: "array-slice";
value: [number, number];
}
);
}[keyof T];
export type SearchOption<T> = {
[K in keyof T]: {
/** the field to be searched for */
field: K;
/** the criteria to be used to search for the field */
criteria: Criteria<T[K]>;
/** the value to be searched for */
value?: any;
/** is it case sensitive? (default: true) */
ignoreCase?: boolean;
}
[K in keyof T]: {
/** the field to be searched for */
field: Path<T>;
/** the criteria to be used to search for the field */
criteria: Criteria<T[K]>;
/** the value to be searched for */
value?: any;
/** is it case sensitive? (default: true) */
ignoreCase?: boolean;
};
}[keyof T];
export interface SelectOption<T> {
/** Chosen fields to eventually return */
fields: Array<keyof T | "id">;
/** Chosen fields to eventually return */
fields: Array<keyof T | "id">;
}
export interface CollectionMethods<T> {
(collectionElement: T): T;
(collectionElement: Collection<T> & T): Collection<T> & T;
}
export interface Raw<T> {
[key: string]: T;
}
export type NoMethods<T> = {
[K in keyof T]: T[K] extends Function ? K : never;
[K in keyof T]: T[K] extends Function ? K : never;
}[keyof T];
export class Collection<T> {
/**
* @param {String} name - The name of the collection
* @param {Function?} addMethods - The methods you want to add to the collection
*/
public constructor(name: string, addMethods?: CollectionMethods<T>);
/**
* @param name - The name of the collection
* @param addMethods - The methods you want to add to the collection
*/
public constructor(name: string, addMethods?: CollectionMethods<T>);
/**
* Get an element from the collection
* @param {String|Number} id - The id of the element you want to get
*/
public get(id: string|number): Promise<T>;
/**
* Get an element from the collection
* @param id - The id of the element you want to get
*/
public get(id: string | number): Promise<T>;
/**
* Get the sha1 hash of the file.
* - Can be used to see if same file content without downloading the file for example
* @returns {String} The sha1 hash of the file
*/
public sha1(): string;
/**
* Get the sha1 hash of the file.
* - Can be used to see if same file content without downloading the file for example
* @returns The sha1 hash of the file
*/
public sha1(): string;
/**
* Search trough the collection
* @param {SearchOption<T & {id: String|Number}>[]} options - Array of searched options
* @param {(Number|Boolean)?} random - Random result seed, disabled by default, but can activated with true or a given seed
* @returns {Promise<T[]>} The found elements
*/
public search(options: SearchOption<T & { id: string|number }>[], random?: boolean|number): Promise<T[]>;
/**
* Search through the collection
* @param options - Array of searched options
* @param random - Random result seed, disabled by default, but can activated with true or a given seed
* @returns The found elements
*/
public search(
options: SearchOption<T & { id: string | number }>[],
random?: boolean | number,
): Promise<T[]>;
/**
* Search specific keys through the collection
* @param {String[]|Number[]} keys - Array of keys to search
* @returns {Promise<T[]>} The found elements
*/
public searchKeys(keys: string[]|number[]): Promise<T[]>;
/**
* Search specific keys through the collection
* @param keys - Array of keys to search
* @returns The found elements
*/
public searchKeys(keys: string[] | number[]): Promise<T[]>;
/**
* Returns the whole content of the file
* @returns {Promise<Raw<T>>}
*/
public read_raw(): Promise<Raw<T>>;
/**
* Returns the whole content of the file
* @returns The entire collection
*/
public readRaw(): Promise<Record<string, T>>;
/**
* Get only selected elements from the collection
* @param {SelectOption<T>} option - The option you want to select
* @returns {Promise<any[]>} Only selected elements from T
*/
public select(option: SelectOption<T>): Promise<any[]>;
/**
* Returns the whole content of the file
* @deprecated Use readRaw instead
* @returns The entire collection
*/
public read_raw(): Promise<Record<string, T>>;
/**
* Get random max entries offset with a given seed
* @param {Integer} max - The maximum number of entries
* @param {Integer} seed - The seed to use
* @param {Integer} offset - The offset to use
* @returns {Promise<T[]>} The found elements
*/
public random(max: number, seed: number, offset: number): Promise<T[]>;
/**
* Get only selected elements from the collection
* @param option - The option you want to select
* @returns Only selected elements from T
*/
public select(option: SelectOption<T>): Promise<any[]>;
/**
* Write the whole content in the JSON file
* @param {Raw<T>} value - The value to write
* @returns {Promise<String>}
*/
public write_raw(value: Raw<T>): Promise<string>;
/**
* Get random max entries offset with a given seed
* @param max - The maximum number of entries
* @param seed - The seed to use
* @param offset - The offset to use
* @returns The found elements
*/
public random(max: number, seed: number, offset: number): Promise<T[]>;
/**
* Add automatically a value to the JSON file
* @param {Omit<T, NoMethods<T>>} value - The value, without methods, to add
* @returns {Promise<String>} The id of the added element
*/
public add(value: Omit<T, NoMethods<T>>): Promise<string>;
/**
* Write the whole content in the JSON file
* @param value - The value to write
* @returns The written elements
*/
public writeRaw(value: Record<string, T>): Promise<string>;
/**
* Add automatically multiple values to the JSON file
* @param {Omit<T, NoMethods<T>>[]} values - The values, without methods, to add
* @returns {Promise<String[]>} The ids of the added elements
*/
public addBulk(values: Omit<T, NoMethods<T>>[]): Promise<string[]>;
/**
* Write the whole content in the JSON file
* @param value - The value to write
* @deprecated Use writeRaw instead
* @returns The written elements
*/
public write_raw(value: Record<string, T>): Promise<string>;
/**
* Remove an element from the collection by its id
* @param {String|Number} id - The id of the element you want to remove
* @returns {Promise<String>}
*/
public remove(id: string|number): Promise<string>;
/**
* Add automatically a value to the JSON file
* @param value - The value, without methods, to add
* @returns The id of the added element
*/
public add(value: Writable<T>): Promise<string>;
/**
* Remove multiple elements from the collection by their ids
* @param {String[]|Number[]} ids - The ids of the elements you want to remove
* @returns {Promise<String>}
*/
public removeBulk(ids: string[]|number[]): Promise<string>;
/**
* Add automatically multiple values to the JSON file
* @param values - The values, without methods, to add
* @returns The ids of the added elements
*/
public addBulk(values: Writable<T>[]): Promise<string[]>;
/**
* Set a value in the collection by its id
* @param {String|Number} id - The id of the element you want to edit
* @param {Omit<T, NoMethods<T>>} value - The value, without methods, you want to edit
* @returns {Promise<String>} The edited element
*/
public set(id: string|number, value: Omit<T, NoMethods<T>>): Promise<string>;
/**
* Remove an element from the collection by its id
* @param id - The id of the element you want to remove
* @returns The id of the removed element
*/
public remove(id: string | number): Promise<string>;
/**
* Set multiple values in the collection by their ids
* @param {String[]|Number[]} ids - The ids of the elements you want to edit
* @param {Omit<T, NoMethods<T>>[]} values - The values, without methods, you want to edit
* @returns {Promise<String>} The edited elements
*/
public setBulk(ids: string[]|number[], values: Omit<T, NoMethods<T>>[]): Promise<string>;
/**
* Remove multiple elements from the collection by their ids
* @param ids - The ids of the elements you want to remove
* @returns The ids of the removed elements
*/
public removeBulk(ids: string[] | number[]): Promise<string>;
/**
* Edit one field of the collection
* @param {EditObject<T>} edit - The edit object
* @returns {Promise<T>} The edited element
*/
public editField(edit: EditField<T>): Promise<T>;
/**
* Set a value in the collection by its id
* @param id - The id of the element you want to edit
* @param value - The value, without methods, you want to edit
* @returns The edited element
*/
public set(id: string | number, value: Writable<T>): Promise<string>;
/**
* Change one field from multiple elements of the collection
* @param {EditObject<T>[]} edits - The edit objects
* @returns {Promise<T[]>} The edited elements
*/
public editFieldBulk(edits: EditField<T>[]): Promise<T[]>;
/**
* Set multiple values in the collection by their ids
* @param ids - The ids of the elements you want to edit
* @param values - The values, without methods, you want to edit
* @returns The edited elements
*/
public setBulk(ids: string[] | number[], values: Writable<T>[]): Promise<string>;
/**
* Edit one field of the collection
* @param edit - The edit object
* @returns The edited element
*/
public editField(edit: EditField<T>): Promise<T>;
/**
* Change one field from multiple elements of the collection
* @param edits - The edit objects
* @returns The edited elements
*/
public editFieldBulk(edits: EditField<T>[]): Promise<T[]>;
}

@@ -282,6 +307,9 @@

// don't need ID field when adding keys, and settings keys has a separate id argument
type Writable<T> = Omit<Omit<T, NoMethods<T>>, "id">;
/**
* Change the current firestorm address
* @param {String} value - The new firestorm address
* @returns {String} The stored firestorm address
* @param value - The new firestorm address
* @returns The stored firestorm address
*/

@@ -291,4 +319,4 @@ export function address(value?: string): string;

/**
* @param {String} value - The new firestorm write token
* @returns {String} The stored firestorm write token
* @param value - The new firestorm write token
* @returns The stored firestorm write token
*/

@@ -298,5 +326,5 @@ export function token(value: string): string;

/**
* @param {String} value - The new firestorm read token
* @param {CollectionMethods<T>} addMethods - Additional methods you want to add to the collection
* @returns {Collection<T>} The collection
* @param value - The new firestorm read token
* @param addMethods - Additional methods you want to add to the collection
* @returns The collection
*/

@@ -306,27 +334,54 @@ export function collection<T>(value: string, addMethods?: CollectionMethods<T>): Collection<T>;

/**
* @param {String} table - The table name to get
* @param table - The table name to get
*/
export function table(table: string): Promise<any>;
/** we need to use an abstract class here because `delete` is reserved otherwise */
export abstract class files {
/**
* Get file back
* @param path - The file path wanted
*/
static get: (path: string) => any;
export interface files {
/**
* Get file back
* @param {String} path - The file path wanted
*/
get: (path: string) => any;
/**
* Upload file
* @param form - The form data with path, filename & file
* @returns http response
*/
static upload: (form: FormData) => Promise<any>;
/**
* Upload file
* @param {FormData} form - The form data with path, filename & file
* @returns {Promise<any>} http response
*/
upload: (form: FormData) => Promise<any>;
/**
* Deletes a file given its path
* @param path - The file path to delete
* @returns http response
*/
static delete: (path: string) => Promise<any>;
}
/**
* Deletes a file given its path
* @param {String} path - The file path to delete
* @returns {Promise<any>} http response
*/
delete: (path: string) => Promise<any>;
}
/**
* taken from https://github.com/toonvanstrijp/nestjs-i18n/blob/3fc33c105a68b112ed7af6237c5f49902d0864b6/src/types.ts#L27
* allows for recursive keyof usage
*/
type IsAny<T> = unknown extends T ? ([keyof T] extends [never] ? false : true) : false;
type PathImpl<T, Key extends keyof T> = Key extends string
? IsAny<T[Key]> extends true
? never
: T[Key] extends Record<string, any>
?
| `${Key}.${PathImpl<T[Key], Exclude<keyof T[Key], keyof any[]>> & string}`
| `${Key}.${Exclude<keyof T[Key], keyof any[]> & string}`
: never
: never;
type PathImpl2<T> = PathImpl<T, keyof T> | keyof T;
export type Path<T> = keyof T extends string
? PathImpl2<T> extends infer P
? P extends string | keyof T
? P
: keyof T
: keyof T
: never;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc