node-json-db: Provides its own types (#39482)

This commit is contained in:
Alexander T
2019-11-07 11:15:24 -08:00
committed by Nathan Shively-Sanders
parent 974e3815b6
commit 0855261c30
5 changed files with 6 additions and 236 deletions
+6
View File
@@ -2760,6 +2760,12 @@
"sourceRepoURL": "https://github.com/nock/nock",
"asOfVersion": "11.1.0"
},
{
"libraryName": "node-json-db",
"typingsPackageName": "node-json-db",
"sourceRepoURL": "https://github.com/Belphemur/node-json-db",
"asOfVersion": "0.9.2"
},
{
"libraryName": "node-cache",
"typingsPackageName": "node-cache",
-57
View File
@@ -1,57 +0,0 @@
// Type definitions for node-json-db
// Project: https://github.com/Belphemur/node-json-db
// Definitions by: Ilya Kuznetsov <https://github.com/kuzn-ilya>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class JsonDB {
/**
* Create the JSON database
* @param filename where to save the data base
* @param saveOnPush saving on modification of the data
* @param humanReadable is the json file humand readable
* @returns {JsonDB}
* @constructor
*/
constructor(filename: string, saveOnPush?: boolean, humanReadable?: boolean);
/**
* Get the deta stored in the data base
* @param dataPath path leading to the data
* @returns {*}
*/
getData(dataPath: string): any;
/**
* Pushing data into the database
* @param dataPath path leading to the data
* @param data data to push
* @param override overriding or not the data, if not, it will merge them
*/
push(dataPath: string, data: any, override?: boolean): void;
/**
* Delete the data
* @param dataPath path leading to the data
*/
delete(dataPath: string): void;
/**
* Reload the database from the file
*/
reload(): void;
/**
* Manually load the database
* It is automatically called when the first getData is done
*/
load(): void;
/**
* Manually save the database
* By default you can't save the database if it's not loaded
* @param force force the save of the database
*/
save(force?: boolean): void;
}
export = JsonDB;
-75
View File
@@ -1,75 +0,0 @@
import JsonDB = require('node-json-db');
// The second argument is used to tell the DB to save after each push
// If you put false, you'll have to call the save() method.
// The third argument is to ask JsonDB to save the database in an human readable format. (default false)
let db = new JsonDB("myDataBase", true, false);
// Pushing the data into the database
// With the wanted DataPath
// By default the push will override the old value
db.push("/test1", "super test");
// It also create automatically the hierarchy when pushing new data for a DataPath that doesn't exists
db.push("/test2/my/test", 5);
// You can also push directly objects
db.push("/test3", {
test: "test",
json: {
test: ["test"]
}
});
// If you don't want to override the data but to merge them
// The merge is recursive and work with Object and Array.
db.push("/test3", {
new: "cool",
json: {
important: 5
}
}, false);
/*
This give you this results :
{
"test":"test",
"json":{
"test":[
"test"
],
"important":5
},
"new":"cool"
}
*/
// You can't merge primitive.
// If you do this:
db.push("/test2/my/test/", 10, false);
// the data will be overriden
// Get the data from the root
var data = db.getData("/");
//From a particular DataPath
var data = db.getData("/test1");
// If you try to get some data from a DataPath that doesn't exists
// You'll get an Error
try {
var data = db.getData("/test1/test/dont/work");
} catch(error) {
// The error will tell you where the DataPath stopped. In this case test1
// Since /test1/test does't exist.
console.error(error);
}
// Deleting data
db.delete("/test1");
// Save the data (useful if you disable the saveOnPush)
db.save();
// In case you have a exterior change to the databse file and want to reload it
// use this method
db.reload();
-24
View File
@@ -1,24 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"node-json-db-tests.ts"
]
}
-80
View File
@@ -1,80 +0,0 @@
{
"extends": "dtslint/dt.json",
"rules": {
"adjacent-overload-signatures": false,
"array-type": false,
"arrow-return-shorthand": false,
"ban-types": false,
"callable-types": false,
"comment-format": false,
"dt-header": false,
"npm-naming": false,
"eofline": false,
"export-just-namespace": false,
"import-spacing": false,
"interface-name": false,
"interface-over-type-literal": false,
"jsdoc-format": false,
"max-line-length": false,
"member-access": false,
"new-parens": false,
"no-any-union": false,
"no-boolean-literal-compare": false,
"no-conditional-assignment": false,
"no-consecutive-blank-lines": false,
"no-construct": false,
"no-declare-current-package": false,
"no-duplicate-imports": false,
"no-duplicate-variable": false,
"no-empty-interface": false,
"no-for-in-array": false,
"no-inferrable-types": false,
"no-internal-module": false,
"no-irregular-whitespace": false,
"no-mergeable-namespace": false,
"no-misused-new": false,
"no-namespace": false,
"no-object-literal-type-assertion": false,
"no-padding": false,
"no-redundant-jsdoc": false,
"no-redundant-jsdoc-2": false,
"no-redundant-undefined": false,
"no-reference-import": false,
"no-relative-import-in-test": false,
"no-self-import": false,
"no-single-declare-module": false,
"no-string-throw": false,
"no-unnecessary-callback-wrapper": false,
"no-unnecessary-class": false,
"no-unnecessary-generics": false,
"no-unnecessary-qualifier": false,
"no-unnecessary-type-assertion": false,
"no-useless-files": false,
"no-var-keyword": false,
"no-var-requires": false,
"no-void-expression": false,
"no-trailing-whitespace": false,
"object-literal-key-quotes": false,
"object-literal-shorthand": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"prefer-conditional-expression": false,
"prefer-const": false,
"prefer-declare-function": false,
"prefer-for-of": false,
"prefer-method-signature": false,
"prefer-template": false,
"radix": false,
"semicolon": false,
"space-before-function-paren": false,
"space-within-parens": false,
"strict-export-declare-modifiers": false,
"trim-file": false,
"triple-equals": false,
"typedef-whitespace": false,
"unified-signatures": false,
"void-return": false,
"whitespace": false
}
}