diff --git a/.gitignore b/.gitignore index fc59888..89400d4 100644 --- a/.gitignore +++ b/.gitignore @@ -109,4 +109,5 @@ dist *.akvdbi database/ -akivadb/ \ No newline at end of file +akivadb/ +lib/ \ No newline at end of file diff --git a/lib/constants.js b/lib/constants.js deleted file mode 100644 index 1236ab2..0000000 --- a/lib/constants.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.MAX_SIZE = void 0; -/** - * 1MB - */ -exports.MAX_SIZE = 1048576; -//# sourceMappingURL=constants.js.map \ No newline at end of file diff --git a/lib/constants.js.map b/lib/constants.js.map deleted file mode 100644 index e9668a9..0000000 --- a/lib/constants.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,QAAQ,GAAG,OAAO,CAAC"} \ No newline at end of file diff --git a/lib/errorHandler.js b/lib/errorHandler.js deleted file mode 100644 index 4defc6c..0000000 --- a/lib/errorHandler.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.AkivaDBError = void 0; -/** - * The custom error that used by the db - * @extends {Error} - * @author Bolorunduro Valiant-Joshua - */ -class AkivaDBError extends Error { - /** - * @param {!String} message The error message - * @param {!Number} code The error code - */ - constructor(message, code) { - super(message); - this.stack = null; - Object.setPrototypeOf(this, new.target.prototype); - // Error.captureStackTrace(this, AkivaDBError); - code = code; - } -} -exports.AkivaDBError = AkivaDBError; -//# sourceMappingURL=errorHandler.js.map \ No newline at end of file diff --git a/lib/errorHandler.js.map b/lib/errorHandler.js.map deleted file mode 100644 index ad89fc8..0000000 --- a/lib/errorHandler.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../src/errorHandler.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC;;;OAGG;IACH,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAElB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QAElD,+CAA+C;QAE/C,IAAI,GAAG,IAAI,CAAC;IACd,CAAC;CACF;AAfD,oCAeC"} \ No newline at end of file diff --git a/lib/errors.js b/lib/errors.js deleted file mode 100644 index e13cfcc..0000000 --- a/lib/errors.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DB_CONTAINS_SPECIAL_CHARS = exports.NOT_OBJECT = exports.NOT_NUMBER = exports.NOT_ARRAY = exports.INVALID_PROJECTION = exports.INVALID_MODIFIER = exports.INVALID_OPERATOR = exports.INVALID_UPDATE = exports.INVALID_QUERY = exports.INVALID_ID = exports.INVALID_DOC = exports.DUPLICATE_DOC = exports.MEMORY_MODE = void 0; -/** - * Converts the passed value to a string. - * @param {unknown} x - * @returns {string} stringified value - */ -const toString = (value) => { - typeof value === "object" ? JSON.stringify(value) : `${value}`; -}; -const MEMORY_MODE = (fn) => `Tried to call '${fn}()' in memory mode`; -exports.MEMORY_MODE = MEMORY_MODE; -const DUPLICATE_DOC = (doc) => `Duplicate document: ${doc._id}`; -exports.DUPLICATE_DOC = DUPLICATE_DOC; -/** - * Formats an invalid value message. - * @param {string} param - * @param {unknown} value - * @returns {string} message - */ -const INVALID = (param, value) => `Invalid ${param}: ${toString(value)}`; -const INVALID_DOC = (doc) => INVALID("doc", doc); -exports.INVALID_DOC = INVALID_DOC; -const INVALID_ID = (_id) => INVALID("_id", _id); -exports.INVALID_ID = INVALID_ID; -const INVALID_QUERY = (query) => INVALID("query", query); -exports.INVALID_QUERY = INVALID_QUERY; -const INVALID_UPDATE = (update) => INVALID("update", update); -exports.INVALID_UPDATE = INVALID_UPDATE; -const INVALID_OPERATOR = (operator) => INVALID("operator", operator); -exports.INVALID_OPERATOR = INVALID_OPERATOR; -const INVALID_MODIFIER = (modifier) => INVALID("modifier", modifier); -exports.INVALID_MODIFIER = INVALID_MODIFIER; -const INVALID_PROJECTION = (projection) => INVALID("projection", projection); -exports.INVALID_PROJECTION = INVALID_PROJECTION; -/** - * Format invalid type message. - * @param {unknown} value - * @param {string} type - * @returns {string} message - */ -const NOT = (value, type) => `Invalid value '${toString(value)} (${typeof value})', expected type '${type}'`; -const NOT_ARRAY = (value) => NOT(value, "Array"); -exports.NOT_ARRAY = NOT_ARRAY; -const NOT_NUMBER = (value) => NOT(value, "Number"); -exports.NOT_NUMBER = NOT_NUMBER; -const NOT_OBJECT = (value) => NOT(value, "Object"); -exports.NOT_OBJECT = NOT_OBJECT; -/** - * Format special character type message. - * @param {unknown} value - * @param {string} name - * @returns {string} message - */ -const CONTAINS_SPECIAL_CHARS = (name, value) => `Special characters in ${name} not allowed`; -const DB_CONTAINS_SPECIAL_CHARS = (value) => CONTAINS_SPECIAL_CHARS("Database Name", value); -exports.DB_CONTAINS_SPECIAL_CHARS = DB_CONTAINS_SPECIAL_CHARS; -//# sourceMappingURL=errors.js.map \ No newline at end of file diff --git a/lib/errors.js.map b/lib/errors.js.map deleted file mode 100644 index 9d42a1f..0000000 --- a/lib/errors.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAE,EAAE;IAClC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC;AACjE,CAAC,CAAC;AAEK,MAAM,WAAW,GAAG,CAAC,EAAU,EAAE,EAAE,CACxC,kBAAkB,EAAE,oBAAoB,CAAC;AAD9B,Q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,kBAAkB,QAAQ,CACxB,KAAK,CACN,KAAK,OAAO,KAAK,sBAAsB,IAAI,GAAG,CAAC;AAC3C,MAAM,SAAS,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAApD,QAAA,SAAS,aAA2C;AAC1D,MAAM,UAAU,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAAtD,QAAA,UAAU,cAA4C;AAC5D,MAAM,UAAU,GAAG,CAAC,KAAc,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAAtD,QAAA,UAAU,cAA4C;AAEnE;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAE,KAAc,EAAE,EAAE,CAC9D,yBAAyB,IAAI,cAAc,CAAC;AACvC,MAAM,yBAAyB,GAAG,CAAC,KAAc,EAAE,EAAE,CAC1D,sBAAsB,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;AADpC,QAAA,yBAAyB,6BACW"} \ No newline at end of file diff --git a/lib/idGenerator.js b/lib/idGenerator.js deleted file mode 100644 index bd6bacb..0000000 --- a/lib/idGenerator.js +++ /dev/null @@ -1,50 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.generateUIDWithCollisionChecking = exports.generateUIDByTimestamp = exports.generateUID = void 0; -const crypto_1 = __importDefault(require("crypto")); -let _generatedUIDs = {}; -/** - * Generate UID - * @author Bolorunduro Valiant-Joshua - * @returns {string} UUID - */ -const generateUID = () => { - let firstPart = (Math.random() * 46656) | 0; - let secondPart = (Math.random() * 46656) | 0; - firstPart = ("000" + firstPart.toString(36)).slice(-3); - secondPart = ("000" + secondPart.toString(36)).slice(-3); - return firstPart + secondPart; -}; -exports.generateUID = generateUID; -/** - * Generate UID based on datetime - * @author Bolorunduro Valiant-Joshua - * @returns {string} UUID - */ -const generateUIDByTimestamp = (seed) => { - seed = seed || crypto_1.default.randomBytes(1).readUInt8(); - const timestamp = Date.now().toString(16); - const random = crypto_1.default.randomBytes(5).toString('hex'); - seed += 1; - return `${timestamp}${random}${seed.toString(16)}`; -}; -exports.generateUIDByTimestamp = generateUIDByTimestamp; -/** - * Generates UID and checks if Identifier id duplicated - * @author Bolorunduro Valiant-Joshua - * @returns {string} UUID - */ -const generateUIDWithCollisionChecking = () => { - while (true) { - const uid = ("0000" + ((Math.random() * Math.pow(36, 4)) | 0).toString(36)).slice(-4); - if (!_generatedUIDs.hasOwnProperty(uid)) { - _generatedUIDs[uid] = true; - return uid; - } - } -}; -exports.generateUIDWithCollisionChecking = generateUIDWithCollisionChecking; -//# sourceMappingURL=idGenerator.js.map \ No newline at end of file diff --git a/lib/idGenerator.js.map b/lib/idGenerator.js.map deleted file mode 100644 index 38eb633..0000000 --- a/lib/idGenerator.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"idGenerator.js","sourceRoot":"","sources":["../src/idGenerator.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAE5B,IAAI,cAAc,GAAG,EAAE,CAAC;AAExB;;;;GAIG;AACI,MAAM,WAAW,GAAG,GAAG,EAAE;IAC5B,IAAI,SAAS,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5C,IAAI,UAAU,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5C,SAAiB,GAAG,CAAC,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,UAAkB,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,KA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; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.mid = void 0; -const fs_1 = __importStar(require("fs")); -const path_1 = __importDefault(require("path")); -const events_1 = __importDefault(require("events")); -const utils_1 = require("./utils"); -const validators_1 = require("./validators"); -const modifiers_1 = require("./modifiers"); -const errors_1 = require("./errors"); -const idGenerator_1 = require("./idGenerator"); -const errorHandler_1 = require("./errorHandler"); -const _ = __importStar(require("lodash")); -class AkivaDB extends events_1.default { - /** - * @param options.name - Database name, if empty, will run `AkivaDB` in-memory - * @param options.root - Database path - * @param options.disableAutoload - If true, disable automatic loading file data into memory - * @param options.inMemory - If true, disables persistence to file - */ - constructor(options) { - super(); - this.inMemory = false; - this.map = {}; - this.indexes = new Set(); - this.dbName = "akivadb"; - /** - * Add document to database and emit `insert` - * @param {Doc} doc Document - * @returns {DocPrivate} doc - */ - this._addAndEmit = (doc) => { - const x = Object.assign(Object.assign({}, doc), { _id: !!doc._id ? doc._id.toString() : (0, idGenerator_1.generateUIDByTimestamp)() }); - this.add(x); - this.emit("insert", x); - if (this.inMemory == false) { - this.persist(); - } - return x; - }; - /** - * Add documents to database and emit `insert` - * @param {Array>} docs Documents - * @returns {Array>} docs - */ - this._addManyAndEmit = (docs) => { - const arr = _.map(docs, (x) => { - return _.assign(x, { - _id: !!x._id ? x._id.toString() : (0, idGenerator_1.generateUIDByTimestamp)(), - }); - }); - this.addMany(arr); - this.emit("insertMany", arr); - if (this.inMemory == false) { - this.persist(); - } - return arr; - }; - this.dbName = !!(options === null || options === void 0 ? void 0 : options.name) ? options === null || options === void 0 ? void 0 : options.name : "akivadb"; - if ((options === null || options === void 0 ? void 0 : options.name) && typeof options.name !== "string") { - throw new errorHandler_1.AkivaDBError("Database name must be typeof string!", 0); - } - if ((options === null || options === void 0 ? void 0 : options.name) && (0, utils_1.containsSpecialChars)(options.name)) { - throw new errorHandler_1.AkivaDBError((0, errors_1.DB_CONTAINS_SPECIAL_CHARS)(options.name), 0); - } - if (!!(options === null || options === void 0 ? void 0 : options.inMemory) || !!!(options === null || options === void 0 ? void 0 : options.name) || !!!(options === null || options === void 0 ? void 0 : options.root)) { - this.inMemory = true; - } - if (options === null || options === void 0 ? void 0 : options.root) { - fs_1.default.mkdirSync(options.root, { recursive: true }); - this.file = path_1.default.resolve(options.root, `${(options === null || options === void 0 ? void 0 : options.name) || "akivadb"}.akvdb`); - if (!(options === null || options === void 0 ? void 0 : options.disableAutoload)) - this.load(); - } - } - /** - * Reset `map` and `indexes`. - * - * Remove all listeners. - */ - flush() { - this.map = {}; - this.indexes = new Set(); - this.removeAllListeners(); - } - add(doc) { - this.indexes.add(doc._id); - this.map[doc._id] = doc; - return doc; - } - addMany(docs) { - _.forEach(docs, (doc) => { - this.indexes.add(doc._id); - _.set(this.map, doc._id, doc); - }); - return docs; - } - get(_id) { - const doc = this.map[_id]; - return !(doc === null || doc === void 0 ? void 0 : doc.$deleted) ? doc : null; - } - remove(_id) { - this.indexes.delete(_id); - delete this.map[_id]; - } - get name() { - return this.dbName; - } - get size() { - return this.indexes.size; - } - get version() { - return require("../package.json").version; - } - get fileSize() { - if (this.inMemory) { - return "N/A"; - } - else { - if (fs_1.default.existsSync(this.file)) { - return (0, utils_1.humanReadableFileSize)((0, fs_1.statSync)(this.file).size); - } - else { - return (0, utils_1.humanReadableFileSize)(0); - } - } - } - get memoryMode() { - return this.inMemory ? "memory" : "disk"; - } - /** - * Load persistent data into memory. - * @param strict - * @returns {string[]} List of documents - */ - load(strict = false) { - if (!this.file) - throw new errorHandler_1.AkivaDBError((0, errors_1.MEMORY_MODE)("load"), 3); - if (!fs_1.default.existsSync(this.file)) - return []; - this.flush(); - return fs_1.default - .readFileSync(this.file, "utf-8") - .split("\n") - .filter((raw) => { - try { - const doc = JSON.parse(raw); - if (!(0, validators_1.isDocPrivate)(doc)) { - throw new errorHandler_1.AkivaDBError((0, errors_1.INVALID_DOC)(doc), 4); - } - this.add(doc); - return false; - } - catch (err) { - if (strict) { - throw err; - } - return true; - } - }); - } - /** - * Persist to database file. - * - * Any documents marked for deletion will be cleaned up here. - * If `strict` is enabled, this will throw an error if persisting fails. - * @param {boolean} strict - */ - persist(strict = false) { - if (!this.file) - throw new errorHandler_1.AkivaDBError((0, errors_1.MEMORY_MODE)("persist"), 3); - const data = []; - // _.forEach(this.indexes, (_id: string) => { - // try { - // const doc = this.get(_id); - // if (doc) { - // data.push(JSON.stringify(doc)); - // } - // } catch (err) { - // this.remove(_id); - // if (strict) { - // throw err; - // } - // } - // }); - this.indexes.forEach((_id) => { - try { - const doc = this.get(_id); - if (doc) { - data.push(JSON.stringify(doc)); - } - } - catch (err) { - this.remove(_id); - if (strict) { - throw err; - } - } - }); - fs_1.default.writeFileSync(this.file, data.join("\n")); - } - /** - * Drop the database. - * @param {boolean} strict If `true` will delete the file on disk, else will reset the database. - */ - drop(strict = false) { - this.flush(); - if (!this.inMemory) { - this.persist(); - if (strict && fs_1.default.existsSync(this.file)) { - fs_1.default.unlinkSync(this.file); - } - } - } - /** - * Insert single document, returns created document. - * @param newDoc - * @param {{strict?: boolean}} options - * @param {boolean} options.strict If `true`, rejects on failed insert - * @returns {Promise>} doc - * @todo optimize processing time - */ - insert(newDoc, options) { - if (!(0, validators_1.isDoc)(newDoc)) { - if (options === null || options === void 0 ? void 0 : options.strict) { - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_DOC)(newDoc), 1)); - } - return null; - } - if (!!(newDoc === null || newDoc === void 0 ? void 0 : newDoc._id) && (0, utils_1.containsSpecialChars)(newDoc._id)) { - throw new errorHandler_1.AkivaDBError(`Id cannot contain special characters`, 1); - } - if (!!(newDoc === null || newDoc === void 0 ? void 0 : newDoc._id) && this.indexes.has(newDoc._id.toString())) { - throw new errorHandler_1.AkivaDBError(`Id ${newDoc._id} already exists`, 1); - } - return Promise.resolve(this._addAndEmit(newDoc)); - } - /** - * Insert a document or multiple documents. - * @param docs document(s) - * @param {{strict?: boolean}} options - * @param {boolean} options.strict If `true`, rejects on first failed insert - * @returns documents - * @todo optimize processing time - */ - insertMany(docs, options) { - { - docs = (0, utils_1.toArray)(docs); - return Promise.resolve(this._addManyAndEmit(docs)); - } - } - /** - * Find single document. - * @param {Query} query - * @param {{projection?: P}} options - * @param {Array} options.projection - * @returns {DocPrivate} document - */ - findOne(query = {}, options) { - if (!(0, validators_1.isQuery)(query)) { - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_QUERY)(query), 1)); - } - for (let i = 0, ids = Array.from(this.indexes); i < ids.length; i += 1) { - const doc = this._findDoc(ids[i], query, options === null || options === void 0 ? void 0 : options.projection); - if (doc) { - return Promise.resolve(doc); - } - } - return Promise.resolve(null); - } - /** - * Find document(s) by id. - * @param id ID(s) - * @param {{projection?: P}} options - * @param {Array} options.projection - * @returns {Promise[]>} documents - */ - findById(id, options) { - return Promise.all((0, utils_1.toArray)(id).map((_id) => this.findOneById(_id, options === null || options === void 0 ? void 0 : options.projection))).then((docs) => docs.reduce((acc, doc) => { - if (doc !== null) { - acc.push(doc); - } - return acc; - }, [])); - } - /** - * Find all matching documents. - * @param {Query} query - * @param {{projection?: P}} options - * @param {Array} options.projection - * @returns {DocPrivate[]} documents - * @todo add sort to options - */ - find(query = {}, options) { - if (!(0, validators_1.isQuery)(query)) { - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_QUERY)(query), 1)); - } - const docs = Array.from(this.indexes).reduce((acc, _id) => { - const doc = this._findDoc(_id, query, options === null || options === void 0 ? void 0 : options.projection); - if (doc) { - acc.push(doc); - } - return acc; - }, []); - return Promise.resolve(docs); - } - /** - * Retrieve document by id. - * @param {string} _id Document ID - * @param {Query} query Query Object - * @param {P} projection Projection Array - * @returns doc - */ - findOneById(_id, projection) { - if (!(0, validators_1.isId)(_id)) - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_ID)(_id), 1)); - const doc = this.get(_id); - if (doc) { - if (projection) { - return Promise.resolve((0, modifiers_1.project)(doc, projection)); - } - return Promise.resolve(doc); - } - return Promise.resolve(null); - } - /** - * Delete a document by ID. - * @param id document id - * @returns {Promise} boolean - */ - deleteOneById(id) { - return __awaiter(this, void 0, void 0, function* () { - if (!(0, validators_1.isId)(id)) { - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_ID)(id), 1)); - } - const doc = yield this.findOneById(id); - if (!!!doc) { - return Promise.resolve(false); - } - this._deleteDoc(doc); - return Promise.resolve(true); - }); - } - /** - * Delete document(s) by id. - * @param docs document(s) - * @returns {Promise} 1 or 0 - * @todo return array of deleted ids - */ - deleteById(docs) { - return Promise.all((0, utils_1.toArray)(docs).map((_id) => this.deleteOneById(_id))).then((n) => n.reduce((acc, cur) => acc + (0, utils_1.boolToNumber)(cur), 0)); - } - /** - * Delete single document - * @param {Query} query - * @returns {Promise} boolean - */ - deleteOne(query = {}) { - return __awaiter(this, void 0, void 0, function* () { - const doc = yield this.findOne(query); - if (!doc) - return Promise.resolve(false); - this._deleteDoc(doc); - return Promise.resolve(true); - }); - } - /** - * Delete many documents. will delete all if no query is passed. - * @param {Query} query - * @returns {Promise} deletedCount - * @todo retrun array of deleted documents - */ - deleteMany(query = {}) { - return __awaiter(this, void 0, void 0, function* () { - return this.find(query).then((docs) => docs.reduce((acc, cur) => { - this._deleteDoc(cur); - return acc + 1; - }, 0)); - }); - } - /** - * Update single document by ID - * @param {string} _id Document id - * @param {Update} update - * @param {{projection?: P}} options - * @param {Array} options.projection - * @returns {Promise} document - */ - updateOneById(_id, update = {}, options) { - return __awaiter(this, void 0, void 0, function* () { - if (!(0, validators_1.isId)(_id)) - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_ID)(_id), 1)); - if (!(0, validators_1.isUpdate)(update)) - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_UPDATE)(update), 1)); - const doc = yield this.findOneById(_id); - if (!doc) - return Promise.resolve(null); - const newDoc = this._updateDoc(doc, update); - if (options === null || options === void 0 ? void 0 : options.projection) - return Promise.resolve((0, modifiers_1.project)(newDoc, options.projection)); - return Promise.resolve(newDoc); - }); - } - /** - * Update document(s) by id. - * @param {OneOrMore} x Document id(s) - * @param {Update} update - * @param {{projection?: P}} options - * @param {Array} options.projection - * @returns {Promise>} documents - */ - updateById(x, update = {}, options) { - if (!(0, validators_1.isUpdate)(update)) - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_UPDATE)(update), 1)); - return Promise.all((0, utils_1.toArray)(x).map((_id) => this.updateOneById(_id, update, options))).then((docs) => docs.reduce((acc, doc) => { - if (doc !== null) - acc.push(doc); - return acc; - }, [])); - } - /** - * Update single document matching query - * @param {Query} query - * @param {Update} update - * @param {{projection?: P}} options - * @param {Array} options.projection - * @returns {Promise} document - */ - updateOne(query = {}, update = {}, options) { - return __awaiter(this, void 0, void 0, function* () { - if (!(0, validators_1.isQuery)(query)) - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_QUERY)(query), 1)); - if (!(0, validators_1.isUpdate)(update)) - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_UPDATE)(update), 1)); - const doc = yield this.findOne(query); - if (!doc) - return Promise.resolve(null); - const newDoc = this._updateDoc(doc, update); - if (options === null || options === void 0 ? void 0 : options.projection) - return Promise.resolve((0, modifiers_1.project)(newDoc, options.projection)); - return Promise.resolve(newDoc); - }); - } - /** - * Update all documents matching query - * @param {Query} query - * @param {Update} update - * @param {{projection?: P}} options - * @param {Array} options.projection - * @returns {Promise>} document - */ - updateMany(query = {}, update = {}, options) { - if (!(0, validators_1.isQuery)(query)) { - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_QUERY)(query), 1)); - } - if (!(0, validators_1.isUpdate)(update)) { - return Promise.reject(new errorHandler_1.AkivaDBError((0, errors_1.INVALID_UPDATE)(update), 1)); - } - const newDocs = this.find(query).then((docs) => docs.map((doc) => { - const newDoc = this._updateDoc(doc, update); - if (options === null || options === void 0 ? void 0 : options.projection) - return (0, modifiers_1.project)(newDoc, options.projection); - return newDoc; - })); - return Promise.resolve(newDocs); - } - /** - * Mark document as deleted against persistence. - * @param doc document - */ - _deleteDoc(doc) { - this.map[doc._id] = Object.assign(Object.assign({}, doc), { $deleted: true }); - this.emit("delete", doc); - if (this.inMemory == false) { - this.persist(); - } - } - /** - * Retrieve document and match query. - * @param {string} _id Document ID - * @param {Query} query Query Object - * @param {P} projection Projection Array - * @todo Parse data types - * @returns doc - */ - _findDoc(_id, query, projection) { - const doc = this.get(_id); - if (doc && (0, validators_1.isQueryMatch)(doc, query)) { - if (projection) - return (0, modifiers_1.project)(doc, projection); - return doc; - } - return null; - } - /** - * Update document - * @param {DocPrivate} doc Document - * @param {Update} update - * @returns {DocPrivate} document - * @todo update only passed fields not entire document - */ - _updateDoc(doc, update) { - const newDoc = (0, validators_1.isModifier)(update) - ? (0, modifiers_1.modify)(doc, update) - : Object.assign(Object.assign({}, update), { _id: doc._id }); - this.map[doc._id] = newDoc; - this.emit("update", newDoc); - if (this.inMemory == false) { - this.persist(); - } - return newDoc; - } -} -exports.default = AkivaDB; -const mid = (req, res, next) => { - if (/^\/akivadb/i.test(String(req.path)) && - /^\/akivadb/i.test(String(req.originalUrl))) { - if (req.method == "GET" && - /^\/akivadb\/login/i.test(String(req.path)) && - /^\/akivadb\/login/i.test(String(req.originalUrl))) { - res.send("post login"); - } - else { - const file = path_1.default.join(__dirname, "..", "pages", "login.html"); - const content = fs_1.default.readFileSync(file, { encoding: "utf8", flag: "r" }); - res.send(content); - } - } - next(); -}; -exports.mid = mid; -//# sourceMappingURL=main.js.map \ No newline at end of file diff --git a/lib/main.js.map b/lib/main.js.map deleted file mode 100644 index c4d3558..0000000 --- a/lib/main.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA4C;AAC5C,gDAAwB;AACxB,oDAAkC;AAClC,mCAKiB;AAUjB,6CAQsB;AACtB,2CAA8C;AAC9C,qCAOkB;AAClB,+CAAuD;AACvD,iDAA8C;AAC9C,0CAA4B;AAE5B,MAAqB,OAA0B,SAAQ,gBAAY;IASjE;;;;;OAKG;IACH,YAAY,OAKX;QACC,KAAK,EAAE,CAAC;QAjBF,aAAQ,GAAY,KAAK,CAAC;QAC1B,QAAG,GAAkC,EAAE,CAAC;QACxC,YAAO,GAAgB,IAAI,GAAG,EAAE,CAAC;QACjC,WAAM,GAAW,SAAS,CAAC;QAufnC;;;;WAIG;QACK,gBAAW,GAAG,CAAC,GAAW,EAAiB,EAAE;YACnD,MAAM,CAAC,mCACF,GAAG,KACN,GAA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AM,GAAG,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IACpC,IACE,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAC3C;QACA,IACE,GAAG,CAAC,MAAM,IAAI,KAAK;YACnB,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC3C,oBAAoB,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,EAClD;YACA,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SACxB;aAAM;YACL,MAAM,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;YAC/D,MAAM,OAAO,GAAG,YAAE,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC;YACvE,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACnB;KACF;IAED,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAnBW,QAAA,GAAG,OAmBd"} \ No newline at end of file diff --git a/lib/modifiers.js b/lib/modifiers.js deleted file mode 100644 index 956f470..0000000 --- a/lib/modifiers.js +++ /dev/null @@ -1,81 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.modify = exports.project = void 0; -const dot = __importStar(require("@chronocide/dot-obj")); -const errorHandler_1 = require("./errorHandler"); -const errors_1 = require("./errors"); -const validators_1 = require("./validators"); -/** - * Projects the selected field(s). - * @param {T} doc - * @param {P} projection - * @returns {Projection} doc - * @todo Add `_id` by default - */ -const project = (doc, projection) => { - if (!Array.isArray(projection)) - throw new errorHandler_1.AkivaDBError((0, errors_1.NOT_ARRAY)(projection), 2); - return projection.reduce((acc, key) => (Object.assign(Object.assign({}, acc), { [key]: doc[key] })), {}); -}; -exports.project = project; -/** - * Modifies the document based on the provided modifier(s). - * @param {T} doc - * @param {Partial} modifiers - * @returns {T} doc - */ -const modify = (doc, modifiers) => { - Object.entries(modifiers).forEach(([modifier, value]) => { - switch (modifier) { - case "$push": - if (!(0, validators_1.hasModifier)(modifier, value)) - break; - Object.entries(value).forEach((entry) => { - const cur = dot.get(doc, entry[0]); - if (!Array.isArray(cur)) - throw new errorHandler_1.AkivaDBError((0, errors_1.NOT_ARRAY)(cur), 2); - dot.set(doc, entry[0], [...cur, entry[1]]); - }); - break; - case "$set": - if (!(0, validators_1.hasModifier)(modifier, value)) - break; - Object.entries(value).forEach((entry) => dot.set(doc, entry[0], entry[1])); - break; - case "$add": - if (!(0, validators_1.hasModifier)(modifier, value)) - break; - Object.entries(value).forEach((entry) => { - const cur = dot.get(doc, entry[0]); - if (typeof cur !== "number") - throw new errorHandler_1.AkivaDBError((0, errors_1.NOT_NUMBER)(cur), 2); - dot.set(doc, entry[0], cur + entry[1]); - }); - break; - default: - throw new errorHandler_1.AkivaDBError((0, errors_1.INVALID_MODIFIER)(modifier), 1); - } - }); - return doc; -}; -exports.modify = modify; -//# sourceMappingURL=modifiers.js.map \ No newline at end of file diff --git a/lib/modifiers.js.map b/lib/modifiers.js.map deleted file mode 100644 index bd75758..0000000 --- a/lib/modifiers.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"modifiers.js","sourceRoot":"","sources":["../src/modifiers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,yDAA2C;AAC3C,iDAA8C;AAE9C,qCAAmE;AAEnE,6CAA2C;AAE3C;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,CACrB,GAAM,EACN,UAAa,EACb,EAAE;IACF,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC;QAC5B,MAAM,IAAI,2BAAY,CAAC,IAAA,kBAAS,EAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,OAAO,UAAU,CAAC,MAAM,CACtB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,iCACT,GAAG,KACN,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,IACf,EACF,EAAsB,CACvB,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,OAAO,WAalB;AAEF;;;;;GAKG;AACI,MAAM,MAAM,GAAG,CACpB,GAAM,EACN,SAA6B,EAC1B,EAAE;IACL,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE;QACtD,QAAQ,QAAQ,EAAE;YAChB,KAAK,OAAO;gBACV,IAAI,CAAC,IAAA,wBAAW,EAAC,QAAQ,EAAE,KAAK,CAAC;oBAAE,MAAM;gBACzC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;oBACtC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;oBACnC,IAAI,CAAC,KAAK,CA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AE,CAAC,CAAC,CAAC;SACzD;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAnCW,QAAA,MAAM,UAmCjB"} \ No newline at end of file diff --git a/lib/types.js b/lib/types.js deleted file mode 100644 index 11e638d..0000000 --- a/lib/types.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=types.js.map \ No newline at end of file diff --git a/lib/types.js.map b/lib/types.js.map deleted file mode 100644 index c768b79..0000000 --- a/lib/types.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib/utils.js b/lib/utils.js deleted file mode 100644 index 783fddc..0000000 --- a/lib/utils.js +++ /dev/null @@ -1,128 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.decode = exports.encode = exports.splitArray = exports.boolToNumber = exports.humanReadableFileSize = exports.containsSpecialChars = exports.toArray = void 0; -const CHUNK = 16384; -const characterFormat = /[ `!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/; -/** - * Converts passed value to an array. - * @param {T | T[]} x - * @returns {Array} array - */ -const toArray = (x) => (Array.isArray(x) ? x : [x]); -exports.toArray = toArray; -/** - * Checks for special characters. - * @param {string} x - * @returns {boolean} boolean - */ -const containsSpecialChars = (x) => characterFormat.test(x); -exports.containsSpecialChars = containsSpecialChars; -/** - * Convert bytes to human readable formats. - * @param {number} x - * @returns {string} formattedSize - */ -const humanReadableFileSize = (x) => { - const units = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; - let l = 0, n = x || 0; - while (n >= 1024 && ++l) { - n = n / 1024; - } - return n.toFixed(n < 10 && l > 0 ? 1 : 0) + " " + units[l]; -}; -exports.humanReadableFileSize = humanReadableFileSize; -/** - * Covert boolean to number - * @param x boolean - * @returns {number} 1 or 0 - */ -const boolToNumber = (x) => (x ? 1 : 0); -exports.boolToNumber = boolToNumber; -/** - * Split array - * @param {[]} array The array to split - * @param {!Number} [pages] array to split every pages - * @returns {Array>} array - */ -const splitArray = (array, pages = 2) => __awaiter(void 0, void 0, void 0, function* () { - if (!array.length) - return []; - const chunks = []; - for (let i = 0; i < array.length;) { - chunks.push(array.slice(i, (i += pages))); - } - return chunks; -}); -exports.splitArray = splitArray; -/** - * Encode strings - * @param {string} string The string to encode - * @returns encodedString - */ -const encode = (string) => { - const b64 = Buffer.from(string).toString("base64"); - let enc = ""; - let l = 0; - while (l < b64.length) { - const str = b64.substring(l, l + CHUNK); - let codes = []; - let i = 0; - while (i < str.length) { - const strng = str.substring(i, i + 2); - const code = [strng.charCodeAt(0), strng.charCodeAt(1)]; - const first = code[0] - 33; - const second = (code[1] || 93) - 33; - codes.push(`${first}${second}`); - i += 2; - } - const encStr = String.fromCharCode(...codes); - enc += encStr; - l += CHUNK; - if (l < b64.length) - enc += "\n"; - } - return enc; -}; -exports.encode = encode; -/** - * Decode strings - * @param {string} string The string to Decode - * @returns decodedString - */ -const decode = (string) => { - if (!string.length) - return ""; - const strings = string.replace(/\n/g, ""); - let b64 = ""; - let l = 0; - while (l < strings.length) { - const str = strings.substring(l, l + CHUNK / 2); - let codes = []; - let i = 0; - while (i < str.length) { - const code = `${str[i].charCodeAt(0)}`; - const first = 1 * parseInt(code.substring(0, 2)) + 33; - const second = 1 * parseInt(code.substring(2)) + 33; - codes.push(first); - if (second != 93) - codes.push(second); - i++; - } - const decStr = String.fromCharCode(...codes); - b64 += decStr; - l += CHUNK / 2; - } - const decoded = Buffer.from(b64, "base64").toString(); - return decoded; -}; -exports.decode = decode; -//# sourceMappingURL=utils.js.map \ No newline at end of file diff --git a/lib/utils.js.map b/lib/utils.js.map deleted file mode 100644 index 0a7baff..0000000 --- a/lib/utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,KAAK,GAAG,KAAK,CAAC;AACpB,MAAM,eAAe,GAAW,0CAA0C,CAAC;AAE3E;;;;GAIG;AACI,MAAM,OAAO,GAAG,CAAI,CAAU,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAA1D,QAAA,OAAO,WAAmD;AAEvE;;;;GAIG;AACI,MAAM,oBAAoB,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAA9D,QAAA,oBAAoB,wBAA0C;AAE3E;;;;GAIG;AACI,MAAM,qBAAqB,GAAG,CAAC,CAAS,EAAE,EAAE;IACjD,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACxE,IAAI,CAAC,GAAG,CAAC,EACP,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACb,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,EAAE;QACvB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;KACd;IACD,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CA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AAE,CAAC;QACf,IAAI,CAAC,GAAG,CAAC,CAAC;QAEV,OAAO,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE;YACrB,MAAM,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;YAEvC,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;YACtD,MAAM,MAAM,GAAG,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;YAEpD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAElB,IAAI,MAAM,IAAI,EAAE;gBAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAErC,CAAC,EAAE,CAAC;SACL;QAED,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC;QAE7C,GAAG,IAAI,MAAM,CAAC;QAEd,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;KAChB;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;IAEtD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAtCW,QAAA,MAAM,UAsCjB"} \ No newline at end of file diff --git a/lib/validators.js b/lib/validators.js deleted file mode 100644 index 3421873..0000000 --- a/lib/validators.js +++ /dev/null @@ -1,299 +0,0 @@ -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.isQueryMatch = exports.hasModifier = exports.hasOperator = exports.isUpdate = exports.isModifier = exports.isQuery = exports.isDocPrivate = exports.isDoc = exports.hasKey = exports.hasDot = exports.hasTag = exports.isTag = exports.isId = exports.isObjectEmtpy = exports.isObject = void 0; -/** - * Validators - * @module Validators - */ -const fast_deep_equal_1 = __importDefault(require("fast-deep-equal")); -const dot = __importStar(require("@chronocide/dot-obj")); -const errors_1 = require("./errors"); -const errorHandler_1 = require("./errorHandler"); -const utils_1 = require("./utils"); -/** - * Validates if value is an object. - * @namespace PrimitiveGuard - * @memberof Validators - * @param {unknown} x - * @returns {boolean} boolean - */ -const isObject = (x) => x !== null && !Array.isArray(x) && typeof x === "object"; -exports.isObject = isObject; -/** - * Validates if an object is empty. - * @namespace PrimitiveGuard - * @memberof Validators - * @param {object} x - * @returns {boolean} boolean - */ -const isObjectEmtpy = (x) => Object.keys(x).length === 0; -exports.isObjectEmtpy = isObjectEmtpy; -/** - * Validates if value is a valid ID. - * @namespace PrimitiveGuard - * @memberof Validators - * @param {string} x - * @returns {boolean} boolean - */ -const isId = (x) => { - return typeof x === "string" && !(0, utils_1.containsSpecialChars)(x) && x.length > 0; -}; -exports.isId = isId; -/** - * Validates if value is a tag. - * @namespace PrimitiveGuard - * @memberof Validators - * @param {string} x - * @returns {boolean} boolean - */ -const isTag = (x) => x[0] === "$"; -exports.isTag = isTag; -/** - * Validates if key has a tag. - * @namespace PrimitiveValidator - * @memberof Validators - * @param {Array.<{key: string, value: unknown}>} param0 - * @returns {boolean} boolean - */ -const hasTag = ([key, value]) => (0, exports.isTag)(key) && value !== undefined; -exports.hasTag = hasTag; -/** - * Validates if key has a dit. - * @namespace PrimitiveValidator - * @memberof Validators - * @param {Array.<{key: string, value: unknown}>} param0 - * @returns {boolean} boolean - */ -const hasDot = ([key, value]) => key.includes(".") && value !== undefined; -exports.hasDot = hasDot; -/** - * Validates if entry has a key. - * @namespace PrimitiveValidator - * @memberof Validators - * @param {Array.<{string, unknown}>, string} param0 - * @returns {boolean} boolean - */ -const hasKey = (entry, key) => entry[0] === key && entry[1] !== undefined; -exports.hasKey = hasKey; -/** - * Validates if value is a document. - * @namespace DatabaseGuard - * @memberof Validators - * @param {unknown} x - * @returns {boolean} boolean - */ -const isDoc = (x) => (0, exports.isObject)(x) && dot.every(x, (entry) => !(0, exports.hasDot)(entry) && !(0, exports.hasTag)(entry)); -exports.isDoc = isDoc; -/** - * Validates if value is a private document. - * @namespace DatabaseGuard - * @memberof Validators - * @param {unknown} x - * @returns {boolean} boolean - */ -const isDocPrivate = (x) => (0, exports.isDoc)(x) && !!x._id && (0, exports.isId)(x._id); -exports.isDocPrivate = isDocPrivate; -/** - * Validates if value is a query. - * @namespace DatabaseGuard - * @memberof Validators - * @param {unknown} x - * @returns {boolean} boolean - */ -const isQuery = (x) => (0, exports.isObject)(x) && dot.every(x, (entry) => !(0, exports.hasKey)(entry, "$deleted")); -exports.isQuery = isQuery; -/** - * Validates if value is a modifer. - * @namespace DatabaseGuard - * @memberof Validators - * @param {unknown} x - * @returns {boolean} boolean - */ -const isModifier = (x) => (0, exports.isObject)(x) && - dot.every(x, (entry) => !(0, exports.hasKey)(entry, "$deleted") && - !(0, exports.hasKey)(entry, "_id") && - ((0, exports.hasKey)(entry, "$push") || (0, exports.hasKey)(entry, "$set") || (0, exports.hasKey)(entry, "$add"))); -exports.isModifier = isModifier; -/** - * Validates if value is a update op. - * @namespace DatabaseGuard - * @memberof Validators - * @param {unknown} x - * @returns {boolean} boolean - */ -const isUpdate = (x) => { - return ((0, exports.isObject)(x) && !((0, exports.isDoc)(x) && (0, exports.isModifier)(x)) && ((0, exports.isDoc)(x) || (0, exports.isModifier)(x))); -}; -exports.isUpdate = isUpdate; -/** - * Validates if operator exists and is valid. - * @namespace DatabaseValidator - * @memberof Validators - * @param {T} operator - * @param {unknown} x - * @returns {boolean} boolean - */ -const hasOperator = (operator, x) => { - switch (operator) { - case "$gt": - case "$gte": - case "$lt": - case "$lte": - if (!(0, exports.isObject)(x)) - return false; - if (dot.some(x, (entry) => typeof entry[1] !== "number")) - return false; - return true; - case "$string": - case "$stringStrict": - if (!(0, exports.isObject)(x)) - return false; - if (dot.some(x, (entry) => typeof entry[1] !== "string")) - return false; - return true; - case "$includes": - case "$not": - return (0, exports.isObject)(x); - case "$keys": - if (!Array.isArray(x)) - return false; - return x.every((i) => typeof i === "string"); - case "$or": - if (!Array.isArray(x)) - return false; - return x.every(exports.isQuery); - default: - return false; - } -}; -exports.hasOperator = hasOperator; -/** - * Validates if modifier exists and is valid. - * @namespace DatabaseValidator - * @memberof Validators - * @param {T} modifer - * @param {unknown} x - * @returns {boolean} boolean - */ -const hasModifier = (modifier, x) => { - switch (modifier) { - case "$push": - case "$set": - if (!(0, exports.isObject)(x)) - return false; - if (dot.some(x, (entry) => typeof entry[1] !== "number")) - return false; - return true; - case "add": - if (!(0, exports.isObject)(x)) - return false; - if (dot.some(x, (entry) => !(0, exports.isObject)(entry[1]))) - return false; - return true; - default: - return false; - } -}; -exports.hasModifier = hasModifier; -/** - * Validates if Query is valid. - * @namespace Query - * @memberof Validators - * @param {Doc} doc - * @param {Query} query - * @returns {boolean} boolean - * @throws {AkivaDBError} InvalidOperatorError - */ -const isQueryMatch = (doc, query) => { - if ((0, exports.isObjectEmtpy)(query)) - return true; - const isMatchMath = (match) => (value) => Object.entries(value).every((entry) => { - const cur = dot.get(doc, entry[0]); - if (typeof cur !== "number") - return false; - return match(cur, entry[1]); - }); - const isMatchString = (match) => (value) => Object.entries(value).every((entry) => { - const cur = dot.get(doc, entry[0]); - if (typeof cur !== "string") - return false; - return match(cur, entry[1]); - }); - return Object.entries(query).every(([operator, value]) => { - if (!(0, exports.isTag)(operator)) - return (0, fast_deep_equal_1.default)(dot.get(doc, operator), value); - switch (operator) { - case "$gt": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return isMatchMath((x, y) => x > y)(value); - case "$gte": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return isMatchMath((x, y) => x >= y)(value); - case "$lt": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return isMatchMath((x, y) => x < y)(value); - case "$lte": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return isMatchMath((x, y) => x <= y)(value); - case "$string": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return isMatchString((a, b) => a.toLocaleLowerCase().includes(b.toLocaleLowerCase()))(value); - case "$stringStrict": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return isMatchString((a, b) => a.includes(b))(value); - case "$includes": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return Object.entries(value).every((e) => { - const current = dot.get(doc, e[0]); - if (!Array.isArray(current)) - return false; - return current.some((item) => (0, fast_deep_equal_1.default)(item, e[1])); - }); - case "$not": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return Object.entries(value).every((e) => !(0, fast_deep_equal_1.default)(dot.get(doc, e[0]), e[1])); - case "$keys": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return value.every((key) => dot.get(doc, key) !== undefined); - case "$or": - if (!(0, exports.hasOperator)(operator, value)) - return false; - return value.some((q) => (0, exports.isQueryMatch)(doc, q)); - default: - throw new errorHandler_1.AkivaDBError((0, errors_1.INVALID_OPERATOR)(operator), 1); - } - }); -}; -exports.isQueryMatch = isQueryMatch; -//# sourceMappingURL=validators.js.map \ No newline at end of file diff --git a/lib/validators.js.map b/lib/validators.js.map deleted file mode 100644 index ac1353f..0000000 --- a/lib/validators.js.map +++ /dev/null @@ -1 +0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