first commit
This commit is contained in:
63
node_modules/warehouse/dist/database.d.ts
generated
vendored
Normal file
63
node_modules/warehouse/dist/database.d.ts
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import Bluebird from 'bluebird';
|
||||
import Model from './model';
|
||||
import Schema from './schema';
|
||||
import SchemaType from './schematype';
|
||||
import type { AddSchemaTypeOptions, NodeJSLikeCallback } from './types';
|
||||
interface DatabaseOptions {
|
||||
version: number;
|
||||
path: string;
|
||||
onUpgrade: (...args: any[]) => any;
|
||||
onDowngrade: (...args: any[]) => any;
|
||||
}
|
||||
declare class Database {
|
||||
options: DatabaseOptions;
|
||||
_models: Record<string, Model<any>>;
|
||||
Model: typeof Model;
|
||||
/**
|
||||
* Database constructor.
|
||||
*
|
||||
* @param {object} [options]
|
||||
* @param {number} [options.version=0] Database version
|
||||
* @param {string} [options.path] Database path
|
||||
* @param {function} [options.onUpgrade] Triggered when the database is upgraded
|
||||
* @param {function} [options.onDowngrade] Triggered when the database is downgraded
|
||||
*/
|
||||
constructor(options?: {
|
||||
path: string;
|
||||
} & Partial<DatabaseOptions>);
|
||||
/**
|
||||
* Creates a new model.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {Schema|object} [schema]
|
||||
* @return {Model}
|
||||
*/
|
||||
model(name: string, schema?: Schema | Record<string, AddSchemaTypeOptions>): Model<any>;
|
||||
/**
|
||||
* Loads database.
|
||||
*
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
load(callback?: NodeJSLikeCallback<any>): Bluebird<any>;
|
||||
/**
|
||||
* Saves database.
|
||||
*
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
save(callback?: NodeJSLikeCallback<any>): Bluebird<void>;
|
||||
toJSON(): {
|
||||
meta: {
|
||||
version: number;
|
||||
warehouse: string;
|
||||
};
|
||||
models: Record<string, Model<any>>;
|
||||
};
|
||||
static Schema: typeof Schema;
|
||||
Schema: typeof Schema;
|
||||
static SchemaType: typeof SchemaType;
|
||||
SchemaType: typeof SchemaType;
|
||||
static version: number;
|
||||
}
|
||||
export default Database;
|
||||
186
node_modules/warehouse/dist/database.js
generated
vendored
Normal file
186
node_modules/warehouse/dist/database.js
generated
vendored
Normal file
@@ -0,0 +1,186 @@
|
||||
"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());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const jsonstream_1 = require("./lib/jsonstream");
|
||||
const bluebird_1 = __importDefault(require("bluebird"));
|
||||
const graceful_fs_1 = require("graceful-fs");
|
||||
const stream_1 = require("stream");
|
||||
const model_1 = __importDefault(require("./model"));
|
||||
const schema_1 = __importDefault(require("./schema"));
|
||||
const schematype_1 = __importDefault(require("./schematype"));
|
||||
const error_1 = __importDefault(require("./error"));
|
||||
const hexo_log_1 = require("hexo-log");
|
||||
const log = (0, hexo_log_1.logger)();
|
||||
const pkg = require('../package.json');
|
||||
const { open } = graceful_fs_1.promises;
|
||||
const pipelineAsync = bluebird_1.default.promisify(stream_1.pipeline);
|
||||
let _writev;
|
||||
if (typeof graceful_fs_1.writev === 'function') {
|
||||
_writev = (handle, buffers) => handle.writev(buffers);
|
||||
}
|
||||
else {
|
||||
_writev = (handle, buffers) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
for (const buffer of buffers)
|
||||
yield handle.write(buffer);
|
||||
});
|
||||
}
|
||||
function exportAsync(database, path) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const handle = yield open(path, 'w');
|
||||
try {
|
||||
// Start body & Meta & Start models
|
||||
yield handle.write(`{"meta":${JSON.stringify({
|
||||
version: database.options.version,
|
||||
warehouse: pkg.version
|
||||
})},"models":{`);
|
||||
const models = database._models;
|
||||
const keys = Object.keys(models);
|
||||
const { length } = keys;
|
||||
// models body
|
||||
for (let i = 0; i < length; i++) {
|
||||
const key = keys[i];
|
||||
if (!models[key])
|
||||
continue;
|
||||
const buffers = [];
|
||||
if (i)
|
||||
buffers.push(Buffer.from(',', 'ascii'));
|
||||
buffers.push(Buffer.from(`"${key}":`));
|
||||
buffers.push(Buffer.from(models[key]._export()));
|
||||
yield _writev(handle, buffers);
|
||||
}
|
||||
// End models
|
||||
yield handle.write('}}');
|
||||
}
|
||||
catch (e) {
|
||||
log.error(e);
|
||||
if (e instanceof RangeError && e.message.includes('Invalid string length')) {
|
||||
// NOTE: Currently, we can't deal with anything about this issue.
|
||||
// If do not `catch` the exception after the process will not work (e.g: `after_generate` filter.)
|
||||
// A side-effect of this workaround is the `db.json` will not generate.
|
||||
log.warn('see: https://github.com/nodejs/node/issues/35973');
|
||||
}
|
||||
else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
yield handle.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
class Database {
|
||||
/**
|
||||
* Database constructor.
|
||||
*
|
||||
* @param {object} [options]
|
||||
* @param {number} [options.version=0] Database version
|
||||
* @param {string} [options.path] Database path
|
||||
* @param {function} [options.onUpgrade] Triggered when the database is upgraded
|
||||
* @param {function} [options.onDowngrade] Triggered when the database is downgraded
|
||||
*/
|
||||
constructor(options) {
|
||||
this.options = Object.assign({ version: 0,
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
onUpgrade() { },
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
onDowngrade() { } }, options);
|
||||
this._models = {};
|
||||
class _Model extends model_1.default {
|
||||
}
|
||||
this.Model = _Model;
|
||||
_Model.prototype._database = this;
|
||||
}
|
||||
/**
|
||||
* Creates a new model.
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {Schema|object} [schema]
|
||||
* @return {Model}
|
||||
*/
|
||||
model(name, schema) {
|
||||
if (this._models[name]) {
|
||||
return this._models[name];
|
||||
}
|
||||
this._models[name] = new this.Model(name, schema);
|
||||
const model = this._models[name];
|
||||
return model;
|
||||
}
|
||||
/**
|
||||
* Loads database.
|
||||
*
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
load(callback) {
|
||||
const { path, onUpgrade, onDowngrade, version: newVersion } = this.options;
|
||||
if (!path)
|
||||
throw new error_1.default('options.path is required');
|
||||
let oldVersion = 0;
|
||||
const getMetaCallBack = data => {
|
||||
if (data.meta && data.meta.version) {
|
||||
oldVersion = data.meta.version;
|
||||
}
|
||||
};
|
||||
// data event arg0 wrap key/value pair.
|
||||
const parseStream = (0, jsonstream_1.parse)('models.$*');
|
||||
parseStream.once('header', getMetaCallBack);
|
||||
parseStream.once('footer', getMetaCallBack);
|
||||
parseStream.on('data', data => {
|
||||
this.model(data.key)._import(data.value);
|
||||
});
|
||||
const rs = (0, graceful_fs_1.createReadStream)(path, 'utf8');
|
||||
return pipelineAsync(rs, parseStream).then(() => {
|
||||
if (newVersion > oldVersion) {
|
||||
return onUpgrade(oldVersion, newVersion);
|
||||
}
|
||||
else if (newVersion < oldVersion) {
|
||||
return onDowngrade(oldVersion, newVersion);
|
||||
}
|
||||
}).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Saves database.
|
||||
*
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
save(callback) {
|
||||
const { path } = this.options;
|
||||
if (!path)
|
||||
throw new error_1.default('options.path is required');
|
||||
return bluebird_1.default.resolve(exportAsync(this, path)).asCallback(callback);
|
||||
}
|
||||
toJSON() {
|
||||
const models = Object.keys(this._models)
|
||||
.reduce((obj, key) => {
|
||||
const value = this._models[key];
|
||||
if (value != null)
|
||||
obj[key] = value;
|
||||
return obj;
|
||||
}, {});
|
||||
return {
|
||||
meta: {
|
||||
version: this.options.version,
|
||||
warehouse: pkg.version
|
||||
}, models
|
||||
};
|
||||
}
|
||||
}
|
||||
Database.Schema = schema_1.default;
|
||||
Database.SchemaType = schematype_1.default;
|
||||
Database.prototype.Schema = schema_1.default;
|
||||
Database.prototype.SchemaType = schematype_1.default;
|
||||
Database.version = pkg.version;
|
||||
exports.default = Database;
|
||||
//# sourceMappingURL=database.js.map
|
||||
1
node_modules/warehouse/dist/database.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/database.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"database.js","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,iDAAkE;AAClE,wDAAgC;AAChC,6CAA+E;AAC/E,mCAA0C;AAC1C,oDAA4B;AAC5B,sDAA8B;AAC9B,8DAAsC;AACtC,oDAAqC;AACrC,uCAAkC;AAGlC,MAAM,GAAG,GAAG,IAAA,iBAAM,GAAE,CAAC;AACrB,MAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AACvC,MAAM,EAAE,IAAI,EAAE,GAAG,sBAAU,CAAC;AAC5B,MAAM,aAAa,GAAG,kBAAQ,CAAC,SAAS,CAAC,iBAAQ,CAAwD,CAAC;AAE1G,IAAI,OAA+E,CAAC;AAEpF,IAAI,OAAO,oBAAM,KAAK,UAAU,EAAE,CAAC;IACjC,OAAO,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACxD,CAAC;KAAM,CAAC;IACN,OAAO,GAAG,CAAO,MAAM,EAAE,OAAO,EAAE,EAAE;QAClC,KAAK,MAAM,MAAM,IAAI,OAAO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
generated
vendored
Normal file
69
node_modules/warehouse/dist/document.d.ts
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import type Model from './model';
|
||||
import type Schema from './schema';
|
||||
import type { NodeJSLikeCallback } from './types';
|
||||
declare abstract class Document<T> {
|
||||
abstract _model: Model<T>;
|
||||
_id: string | number | undefined;
|
||||
abstract _schema: Schema;
|
||||
[key: string]: any;
|
||||
/**
|
||||
* Document constructor.
|
||||
*
|
||||
* @param {object} data
|
||||
*/
|
||||
constructor(data?: T);
|
||||
/**
|
||||
* Saves the document.
|
||||
*
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
save(callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Updates the document.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
update(data: object, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Replaces the document.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
replace(data: T | Document<T>, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Removes the document.
|
||||
*
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
remove(callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Returns a plain JavaScript object.
|
||||
*
|
||||
* @return {object}
|
||||
*/
|
||||
toObject(): T;
|
||||
/**
|
||||
* Returns a string representing the document.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
toString(): string;
|
||||
/**
|
||||
* Populates document references.
|
||||
*
|
||||
* @param {String|Object} expr
|
||||
* @return {Document}
|
||||
*/
|
||||
populate(expr: string | any[] | {
|
||||
path?: string;
|
||||
model?: any;
|
||||
[key: PropertyKey]: any;
|
||||
}): Document<T>;
|
||||
}
|
||||
export default Document;
|
||||
96
node_modules/warehouse/dist/document.js
generated
vendored
Normal file
96
node_modules/warehouse/dist/document.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const rfdc_1 = __importDefault(require("rfdc"));
|
||||
const cloneDeep = (0, rfdc_1.default)();
|
||||
class Document {
|
||||
/**
|
||||
* Document constructor.
|
||||
*
|
||||
* @param {object} data
|
||||
*/
|
||||
constructor(data) {
|
||||
if (data) {
|
||||
Object.assign(this, data);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Saves the document.
|
||||
*
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
save(callback) {
|
||||
return this._model.save(this, callback);
|
||||
}
|
||||
/**
|
||||
* Updates the document.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
update(data, callback) {
|
||||
return this._model.updateById(this._id, data, callback);
|
||||
}
|
||||
/**
|
||||
* Replaces the document.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
replace(data, callback) {
|
||||
return this._model.replaceById(this._id, data, callback);
|
||||
}
|
||||
/**
|
||||
* Removes the document.
|
||||
*
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
remove(callback) {
|
||||
return this._model.removeById(this._id, callback);
|
||||
}
|
||||
/**
|
||||
* Returns a plain JavaScript object.
|
||||
*
|
||||
* @return {object}
|
||||
*/
|
||||
toObject() {
|
||||
const keys = Object.keys(this);
|
||||
const obj = {};
|
||||
for (let i = 0, len = keys.length; i < len; i++) {
|
||||
const key = keys[i];
|
||||
// Don't deep clone getters in order to avoid "Maximum call stack size
|
||||
// exceeded" error
|
||||
obj[key] = isGetter(this, key) ? this[key] : cloneDeep(this[key]);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
/**
|
||||
* Returns a string representing the document.
|
||||
*
|
||||
* @return {String}
|
||||
*/
|
||||
toString() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
/**
|
||||
* Populates document references.
|
||||
*
|
||||
* @param {String|Object} expr
|
||||
* @return {Document}
|
||||
*/
|
||||
populate(expr) {
|
||||
const stack = this._schema._parsePopulate(expr);
|
||||
return this._model._populate(this, stack);
|
||||
}
|
||||
}
|
||||
function isGetter(obj, key) {
|
||||
return Object.getOwnPropertyDescriptor(obj, key).get;
|
||||
}
|
||||
exports.default = Document;
|
||||
//# sourceMappingURL=document.js.map
|
||||
1
node_modules/warehouse/dist/document.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/document.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"document.js","sourceRoot":"","sources":["../src/document.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAIxB,MAAM,SAAS,GAAG,IAAA,cAAI,GAAE,CAAC;AAEzB,MAAe,QAAQ;IAMrB;;;;OAIG;IACH,YAAY,IAAQ;QAClB,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,IAAI,CAAC,QAAkC;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,IAAY,EAAE,QAAkC;QACrD,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;OAMG;IACH,OAAO,CAAC,IAAqB,EAAE,QAAkC;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,EA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}
|
||||
14
node_modules/warehouse/dist/error.d.ts
generated
vendored
Normal file
14
node_modules/warehouse/dist/error.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
declare class WarehouseError extends Error {
|
||||
code?: string;
|
||||
/**
|
||||
* WarehouseError constructor
|
||||
*
|
||||
* @param {string} msg
|
||||
* @param {string} code
|
||||
*/
|
||||
constructor(msg: string, code?: string);
|
||||
static ID_EXIST: string;
|
||||
static ID_NOT_EXIST: string;
|
||||
static ID_UNDEFINED: string;
|
||||
}
|
||||
export default WarehouseError;
|
||||
21
node_modules/warehouse/dist/error.js
generated
vendored
Normal file
21
node_modules/warehouse/dist/error.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class WarehouseError extends Error {
|
||||
/**
|
||||
* WarehouseError constructor
|
||||
*
|
||||
* @param {string} msg
|
||||
* @param {string} code
|
||||
*/
|
||||
constructor(msg, code) {
|
||||
super(msg);
|
||||
Error.captureStackTrace(this);
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
WarehouseError.ID_EXIST = 'ID_EXIST';
|
||||
WarehouseError.ID_NOT_EXIST = 'ID_NOT_EXIST';
|
||||
WarehouseError.ID_UNDEFINED = 'ID_UNDEFINED';
|
||||
WarehouseError.prototype.name = 'WarehouseError';
|
||||
exports.default = WarehouseError;
|
||||
//# sourceMappingURL=error.js.map
|
||||
1
node_modules/warehouse/dist/error.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/error.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;AAAA,MAAM,cAAe,SAAQ,KAAK;IAGhC;;;;;OAKG;IACH,YAAY,GAAW,EAAE,IAAa;QACpC,KAAK,CAAC,GAAG,CAAC,CAAC;QAEX,KAAK,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAE9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;;AACM,uBAAQ,GAAG,UAAU,CAAC;AACtB,2BAAY,GAAG,cAAc,CAAC;AAC9B,2BAAY,GAAG,cAAc,CAAC;AAGvC,cAAc,CAAC,SAAS,CAAC,IAAI,GAAG,gBAAgB,CAAC;AAEjD,kBAAe,cAAc,CAAC"}
|
||||
4
node_modules/warehouse/dist/error/population.d.ts
generated
vendored
Normal file
4
node_modules/warehouse/dist/error/population.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import WarehouseError from '../error';
|
||||
declare class PopulationError extends WarehouseError {
|
||||
}
|
||||
export default PopulationError;
|
||||
11
node_modules/warehouse/dist/error/population.js
generated
vendored
Normal file
11
node_modules/warehouse/dist/error/population.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const error_1 = __importDefault(require("../error"));
|
||||
class PopulationError extends error_1.default {
|
||||
}
|
||||
PopulationError.prototype.name = 'PopulationError';
|
||||
exports.default = PopulationError;
|
||||
//# sourceMappingURL=population.js.map
|
||||
1
node_modules/warehouse/dist/error/population.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/error/population.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"population.js","sourceRoot":"","sources":["../../src/error/population.ts"],"names":[],"mappings":";;;;;AAAA,qDAAsC;AAEtC,MAAM,eAAgB,SAAQ,eAAc;CAAG;AAE/C,eAAe,CAAC,SAAS,CAAC,IAAI,GAAG,iBAAiB,CAAC;AAEnD,kBAAe,eAAe,CAAC"}
|
||||
4
node_modules/warehouse/dist/error/validation.d.ts
generated
vendored
Normal file
4
node_modules/warehouse/dist/error/validation.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import WarehouseError from '../error';
|
||||
declare class ValidationError extends WarehouseError {
|
||||
}
|
||||
export default ValidationError;
|
||||
11
node_modules/warehouse/dist/error/validation.js
generated
vendored
Normal file
11
node_modules/warehouse/dist/error/validation.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const error_1 = __importDefault(require("../error"));
|
||||
class ValidationError extends error_1.default {
|
||||
}
|
||||
ValidationError.prototype.name = 'ValidationError';
|
||||
exports.default = ValidationError;
|
||||
//# sourceMappingURL=validation.js.map
|
||||
1
node_modules/warehouse/dist/error/validation.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/error/validation.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/error/validation.ts"],"names":[],"mappings":";;;;;AAAA,qDAAsC;AAEtC,MAAM,eAAgB,SAAQ,eAAc;CAAG;AAE/C,eAAe,CAAC,SAAS,CAAC,IAAI,GAAG,iBAAiB,CAAC;AAEnD,kBAAe,eAAe,CAAC"}
|
||||
2
node_modules/warehouse/dist/lib/jsonstream/index.d.ts
generated
vendored
Normal file
2
node_modules/warehouse/dist/lib/jsonstream/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/// <reference types="node" />
|
||||
export declare function parse(path: string | any[], map?: any): import("stream").Transform;
|
||||
191
node_modules/warehouse/dist/lib/jsonstream/index.js
generated
vendored
Normal file
191
node_modules/warehouse/dist/lib/jsonstream/index.js
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parse = void 0;
|
||||
const through2_1 = __importDefault(require("through2"));
|
||||
const jsonparse_1 = __importDefault(require("jsonparse"));
|
||||
/**
|
||||
* Check whether a x and y are equal, or x matches y, or x(y) is truthy.
|
||||
* @param {boolean | string | RegExp | (args: any[]) => boolean} x
|
||||
* @param {*} y
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const check = (x, y) => {
|
||||
if (typeof x === 'string') {
|
||||
return y === x;
|
||||
}
|
||||
if (x && typeof x.exec === 'function') {
|
||||
return x.exec(y);
|
||||
}
|
||||
if (typeof x === 'boolean' || typeof x === 'object') {
|
||||
return x;
|
||||
}
|
||||
if (typeof x === 'function') {
|
||||
return x(y);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
function parse(path, map = null) {
|
||||
let header, footer;
|
||||
const parser = new jsonparse_1.default();
|
||||
const stream = through2_1.default.obj((chunk, enc, cb) => {
|
||||
if (typeof chunk === 'string') {
|
||||
chunk = Buffer.from(chunk);
|
||||
}
|
||||
parser.write(chunk);
|
||||
cb();
|
||||
}, cb => {
|
||||
if (header) {
|
||||
stream.emit('header', header);
|
||||
}
|
||||
if (footer) {
|
||||
stream.emit('footer', footer);
|
||||
}
|
||||
if (parser.tState !== jsonparse_1.default.C.START || parser.stack.length > 0) {
|
||||
// @ts-ignore
|
||||
cb(new Error('Incomplete JSON'));
|
||||
return;
|
||||
}
|
||||
cb();
|
||||
});
|
||||
if (typeof path === 'string') {
|
||||
path = path.split('.').map(e => {
|
||||
if (e === '$*') {
|
||||
return { emitKey: true };
|
||||
}
|
||||
if (e === '*') {
|
||||
return true;
|
||||
}
|
||||
if (e === '') {
|
||||
// '..'.split('.') returns an empty string
|
||||
return { recurse: true };
|
||||
}
|
||||
return e;
|
||||
});
|
||||
}
|
||||
if (!path || !path.length) {
|
||||
path = null;
|
||||
}
|
||||
parser.onValue = function (value) {
|
||||
// @ts-ignore
|
||||
if (!this.root) {
|
||||
stream.root = value;
|
||||
}
|
||||
if (!path)
|
||||
return;
|
||||
let i = 0; // iterates on path
|
||||
let j = 0; // iterates on stack
|
||||
let emitKey = false;
|
||||
let emitPath = false;
|
||||
while (i < path.length) {
|
||||
const key = path[i];
|
||||
let c;
|
||||
j++;
|
||||
if (key && !key.recurse) {
|
||||
c = j === this.stack.length ? this : this.stack[j];
|
||||
if (!c)
|
||||
return;
|
||||
if (!check(key, c.key)) {
|
||||
setHeaderFooter(c.key, value);
|
||||
return;
|
||||
}
|
||||
emitKey = !!key.emitKey;
|
||||
emitPath = !!key.emitPath;
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
i++;
|
||||
const nextKey = path[i];
|
||||
if (!nextKey)
|
||||
return;
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
c = j === this.stack.length ? this : this.stack[j];
|
||||
if (!c)
|
||||
return;
|
||||
if (check(nextKey, c.key)) {
|
||||
i++;
|
||||
if (!Object.isFrozen(this.stack[j])) {
|
||||
this.stack[j].value = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else {
|
||||
setHeaderFooter(c.key, value);
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// emit header
|
||||
if (header) {
|
||||
stream.emit('header', header);
|
||||
header = false;
|
||||
}
|
||||
if (j !== this.stack.length)
|
||||
return;
|
||||
const actualPath = this.stack.slice(1).map(element => element.key);
|
||||
actualPath.push(this.key);
|
||||
let data = this.value[this.key];
|
||||
if (data != null) {
|
||||
if ((data = map ? map(data, actualPath) : data) != null) {
|
||||
if (emitKey || emitPath) {
|
||||
data = {
|
||||
value: data
|
||||
};
|
||||
if (emitKey) {
|
||||
data.key = this.key;
|
||||
}
|
||||
if (emitPath) {
|
||||
data.path = actualPath;
|
||||
}
|
||||
}
|
||||
stream.push(data);
|
||||
}
|
||||
}
|
||||
delete this.value[this.key];
|
||||
for (const k in this.stack) {
|
||||
if (!Object.isFrozen(this.stack[k])) {
|
||||
this.stack[k].value = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
parser._onToken = parser.onToken;
|
||||
parser.onToken = function (token, value) {
|
||||
parser._onToken(token, value);
|
||||
if (this.stack.length === 0) {
|
||||
// @ts-ignore
|
||||
if (stream.root) {
|
||||
// @ts-ignore
|
||||
if (!path) {
|
||||
stream.push(stream.root);
|
||||
}
|
||||
// @ts-ignore
|
||||
stream.root = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
parser.onError = function (err) {
|
||||
if (err.message.includes('at position')) {
|
||||
err.message = 'Invalid JSON (' + err.message + ')';
|
||||
}
|
||||
stream.destroy(err);
|
||||
};
|
||||
return stream;
|
||||
function setHeaderFooter(key, value) {
|
||||
// header has not been emitted yet
|
||||
if (header !== false) {
|
||||
header = header || {};
|
||||
header[key] = value;
|
||||
}
|
||||
// footer has not been emitted yet but header has
|
||||
if (footer !== false && header === false) {
|
||||
footer = footer || {};
|
||||
footer[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.parse = parse;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/warehouse/dist/lib/jsonstream/index.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/lib/jsonstream/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
389
node_modules/warehouse/dist/model.d.ts
generated
vendored
Normal file
389
node_modules/warehouse/dist/model.d.ts
generated
vendored
Normal file
@@ -0,0 +1,389 @@
|
||||
/// <reference types="node" />
|
||||
import { EventEmitter } from 'events';
|
||||
import Promise from 'bluebird';
|
||||
import Document from './document';
|
||||
import Query from './query';
|
||||
import Schema from './schema';
|
||||
import Mutex from './mutex';
|
||||
import type Database from './database';
|
||||
import type { AddSchemaTypeOptions, NodeJSLikeCallback, Options, PopulateResult } from './types';
|
||||
declare class Model<T> extends EventEmitter {
|
||||
name: string;
|
||||
_mutex: Mutex;
|
||||
data: Record<PropertyKey, T>;
|
||||
schema: Schema;
|
||||
length: number;
|
||||
Document: any;
|
||||
Query: any;
|
||||
_database: Database;
|
||||
/**
|
||||
* Model constructor.
|
||||
*
|
||||
* @param {string} name Model name
|
||||
* @param {Schema|object} [schema_] Schema
|
||||
*/
|
||||
constructor(name: string, schema_: Schema | Record<string, AddSchemaTypeOptions>);
|
||||
/**
|
||||
* Creates a new document.
|
||||
*
|
||||
* @param {object} data
|
||||
* @return {Document}
|
||||
*/
|
||||
new(data?: T): Document<T>;
|
||||
/**
|
||||
* Finds a document by its identifier.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {object} options
|
||||
* @param {boolean} [options.lean=false] Returns a plain JavaScript object
|
||||
* @return {Document|object}
|
||||
*/
|
||||
findById(id: PropertyKey, options_?: Options): Document<T> | T;
|
||||
/**
|
||||
* Checks if the model contains a document with the specified id.
|
||||
*
|
||||
* @param {*} id
|
||||
* @return {boolean}
|
||||
*/
|
||||
has(id: PropertyKey): boolean;
|
||||
/**
|
||||
* Acquires write lock.
|
||||
*
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_acquireWriteLock(): Promise.Disposer<void>;
|
||||
/**
|
||||
* Inserts a document.
|
||||
*
|
||||
* @param {Document|object} data
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_insertOne(data_: Document<T> | T): Promise<any>;
|
||||
/**
|
||||
* Inserts a document.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
insertOne(data: Document<T> | T, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Inserts documents.
|
||||
*
|
||||
* @param {object|array} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
insert(data: Document<T> | T | Document<T>[] | T[], callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Inserts the document if it does not exist; otherwise updates it.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
save(data: Document<T> | T, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Updates a document with a compiled stack.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {array} stack
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_updateWithStack(id: string | number, stack: ((data: any) => void)[]): Promise<any>;
|
||||
/**
|
||||
* Finds a document by its identifier and update it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {object} update
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
updateById(id: string | number, update: object, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Updates matching documents.
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
update(query: object, data: object, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Finds a document by its identifier and replace it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {object} data
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_replaceById(id: string | number, data_: Document<T> | T): Promise<any>;
|
||||
/**
|
||||
* Finds a document by its identifier and replace it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
replaceById(id: string | number, data: Document<T> | T, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Replaces matching documents.
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
replace(query: object, data: any, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Finds a document by its identifier and remove it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_removeById(id: string | number): Promise<any>;
|
||||
/**
|
||||
* Finds a document by its identifier and remove it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
removeById(id: string | number, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Removes matching documents.
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
remove(query: object, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Deletes a model.
|
||||
*/
|
||||
destroy(): void;
|
||||
/**
|
||||
* Returns the number of elements.
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
count(): number;
|
||||
/**
|
||||
* Iterates over all documents.
|
||||
*
|
||||
* @param {function} iterator
|
||||
* @param {object} [options] See {@link Model#findById}.
|
||||
*/
|
||||
forEach(iterator: (value: any, index: number) => void, options?: Options): void;
|
||||
/**
|
||||
* Returns an array containing all documents.
|
||||
*
|
||||
* @param {Object} [options] See {@link Model#findById}.
|
||||
* @return {Array}
|
||||
*/
|
||||
toArray(options?: Options): any[];
|
||||
/**
|
||||
* Finds matching documents.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @param {Object} [options]
|
||||
* @param {Number} [options.limit=0] Limits the number of documents returned.
|
||||
* @param {Number} [options.skip=0] Skips the first elements.
|
||||
* @param {Boolean} [options.lean=false] Returns a plain JavaScript object.
|
||||
* @return {Query|Array}
|
||||
*/
|
||||
find(query: object): Query<T>;
|
||||
find(query: object, options: Options): Query<T> | T[];
|
||||
/**
|
||||
* Finds the first matching documents.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @param {Object} [options]
|
||||
* @param {Number} [options.skip=0] Skips the first elements.
|
||||
* @param {Boolean} [options.lean=false] Returns a plain JavaScript object.
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
findOne(query: object): Document<T>;
|
||||
findOne(query: object, options_: Options): Document<T> | T;
|
||||
/**
|
||||
* Sorts documents. See {@link Query#sort}.
|
||||
*
|
||||
* @param {String|Object} orderby
|
||||
* @param {String|Number} [order]
|
||||
* @return {Query}
|
||||
*/
|
||||
sort(orderby: string | object, order?: string | number): Query<T>;
|
||||
/**
|
||||
* Returns the document at the specified index. `num` can be a positive or
|
||||
* negative number.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @param {Object} [options] See {@link Model#findById}.
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
eq(i_: number, options?: Options): Document<T> | Record<PropertyKey, any>;
|
||||
/**
|
||||
* Returns the first document.
|
||||
*
|
||||
* @param {Object} [options] See {@link Model#findById}.
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
first(options?: Options): Document<T> | Record<PropertyKey, any>;
|
||||
/**
|
||||
* Returns the last document.
|
||||
*
|
||||
* @param {Object} [options] See {@link Model#findById}.
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
last(options?: Options): Document<T> | Record<PropertyKey, any>;
|
||||
/**
|
||||
* Returns the specified range of documents.
|
||||
*
|
||||
* @param {Number} start
|
||||
* @param {Number} [end]
|
||||
* @return {Query}
|
||||
*/
|
||||
slice(start_?: number, end_?: number): Query<T>;
|
||||
/**
|
||||
* Limits the number of documents returned.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Query}
|
||||
*/
|
||||
limit(i: number): Query<T>;
|
||||
/**
|
||||
* Specifies the number of items to skip.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Query}
|
||||
*/
|
||||
skip(i: number): Query<T>;
|
||||
/**
|
||||
* Returns documents in a reversed order.
|
||||
*
|
||||
* @return {Query}
|
||||
*/
|
||||
reverse(): Query<T>;
|
||||
/**
|
||||
* Returns documents in random order.
|
||||
*
|
||||
* @return {Query}
|
||||
*/
|
||||
shuffle(): Query<T>;
|
||||
/**
|
||||
* Creates an array of values by iterating each element in the collection.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {Object} [options]
|
||||
* @return {Array}
|
||||
*/
|
||||
map<T>(iterator: (value: any, index: number) => T, options?: Options): T[];
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of iterating
|
||||
* each element in the collection.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {*} [initial] By default, the initial value is the first document.
|
||||
* @return {*}
|
||||
*/
|
||||
reduce<T>(iterator: (pre: any, cur: any, index: number) => T, initial?: T): T;
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of iterating
|
||||
* each element in the collection from right to left.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {*} [initial] By default, the initial value is the last document.
|
||||
* @return {*}
|
||||
*/
|
||||
reduceRight<T>(iterator: (pre: any, cur: any, index: number) => T, initial?: T): T;
|
||||
/**
|
||||
* Creates a new array with all documents that pass the test implemented by the
|
||||
* provided function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {Object} [options]
|
||||
* @return {Query}
|
||||
*/
|
||||
filter(iterator: (value: any, index: number) => any, options?: Options): Query<T>;
|
||||
/**
|
||||
* Tests whether all documents pass the test implemented by the provided
|
||||
* function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Boolean}
|
||||
*/
|
||||
every(iterator: (value: any, index: number) => any): boolean;
|
||||
/**
|
||||
* Tests whether some documents pass the test implemented by the provided
|
||||
* function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Boolean}
|
||||
*/
|
||||
some(iterator: (value: any, index: number) => any): boolean;
|
||||
/**
|
||||
* Returns a getter function for normal population.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Model} model
|
||||
* @param {Object} options
|
||||
* @return {Function}
|
||||
* @private
|
||||
*/
|
||||
_populateGetter(data: string | number, model: Model<T>, options: unknown): () => Document<T> | Record<PropertyKey, any>;
|
||||
/**
|
||||
* Returns a getter function for array population.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Model} model
|
||||
* @param {Object} options
|
||||
* @return {Function}
|
||||
* @private
|
||||
*/
|
||||
_populateGetterArray(data: any[], model: Model<T>, options: Options): () => any[] | Query<T>;
|
||||
/**
|
||||
* Populates document references with a compiled stack.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Array} stack
|
||||
* @return {Object}
|
||||
* @private
|
||||
*/
|
||||
_populate(data: Document<T>, stack: PopulateResult[]): Document<T>;
|
||||
/**
|
||||
* Populates document references.
|
||||
*
|
||||
* @param {String|Object} path
|
||||
* @return {Query}
|
||||
*/
|
||||
populate(path: string | any[] | {
|
||||
path?: string;
|
||||
model?: any;
|
||||
[key: PropertyKey]: any;
|
||||
}): Query<T>;
|
||||
/**
|
||||
* Imports data.
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @private
|
||||
*/
|
||||
_import(arr: any[]): void;
|
||||
/**
|
||||
* Exports data.
|
||||
*
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
_export(): string;
|
||||
toJSON(): any[];
|
||||
get: Model<T>['findById'];
|
||||
size: Model<T>['count'];
|
||||
each: Model<T>['forEach'];
|
||||
random: Model<T>['shuffle'];
|
||||
}
|
||||
export default Model;
|
||||
847
node_modules/warehouse/dist/model.js
generated
vendored
Normal file
847
node_modules/warehouse/dist/model.js
generated
vendored
Normal file
@@ -0,0 +1,847 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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 });
|
||||
const events_1 = require("events");
|
||||
const rfdc_1 = __importDefault(require("rfdc"));
|
||||
const cloneDeep = (0, rfdc_1.default)();
|
||||
const bluebird_1 = __importDefault(require("bluebird"));
|
||||
const util_1 = require("./util");
|
||||
const document_1 = __importDefault(require("./document"));
|
||||
const query_1 = __importDefault(require("./query"));
|
||||
const schema_1 = __importDefault(require("./schema"));
|
||||
const Types = __importStar(require("./types/index"));
|
||||
const error_1 = __importDefault(require("./error"));
|
||||
const population_1 = __importDefault(require("./error/population"));
|
||||
const mutex_1 = __importDefault(require("./mutex"));
|
||||
class Model extends events_1.EventEmitter {
|
||||
/**
|
||||
* Model constructor.
|
||||
*
|
||||
* @param {string} name Model name
|
||||
* @param {Schema|object} [schema_] Schema
|
||||
*/
|
||||
constructor(name, schema_) {
|
||||
super();
|
||||
this.name = name;
|
||||
this._mutex = new mutex_1.default();
|
||||
this.data = {};
|
||||
this.length = 0;
|
||||
let schema;
|
||||
// Define schema
|
||||
if (schema_ instanceof schema_1.default) {
|
||||
schema = schema_;
|
||||
}
|
||||
else if (typeof schema_ === 'object') {
|
||||
schema = new schema_1.default(schema_);
|
||||
}
|
||||
else {
|
||||
schema = new schema_1.default();
|
||||
}
|
||||
// Set `_id` path for schema
|
||||
if (!schema.path('_id')) {
|
||||
schema.path('_id', { type: Types.CUID, required: true });
|
||||
}
|
||||
this.schema = schema;
|
||||
class _Document extends document_1.default {
|
||||
constructor(data) {
|
||||
super(data);
|
||||
// Apply getters
|
||||
schema._applyGetters(this);
|
||||
}
|
||||
}
|
||||
this.Document = _Document;
|
||||
_Document.prototype._model = this;
|
||||
_Document.prototype._schema = schema;
|
||||
class _Query extends query_1.default {
|
||||
}
|
||||
this.Query = _Query;
|
||||
_Query.prototype._model = this;
|
||||
_Query.prototype._schema = schema;
|
||||
// Apply static methods
|
||||
Object.assign(this, schema.statics);
|
||||
// Apply instance methods
|
||||
Object.assign(_Document.prototype, schema.methods);
|
||||
}
|
||||
/**
|
||||
* Creates a new document.
|
||||
*
|
||||
* @param {object} data
|
||||
* @return {Document}
|
||||
*/
|
||||
new(data) {
|
||||
return new this.Document(data);
|
||||
}
|
||||
/**
|
||||
* Finds a document by its identifier.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {object} options
|
||||
* @param {boolean} [options.lean=false] Returns a plain JavaScript object
|
||||
* @return {Document|object}
|
||||
*/
|
||||
findById(id, options_) {
|
||||
const raw = this.data[id];
|
||||
if (!raw)
|
||||
return;
|
||||
const options = Object.assign({
|
||||
lean: false
|
||||
}, options_);
|
||||
const data = cloneDeep(raw);
|
||||
return options.lean ? data : this.new(data);
|
||||
}
|
||||
/**
|
||||
* Checks if the model contains a document with the specified id.
|
||||
*
|
||||
* @param {*} id
|
||||
* @return {boolean}
|
||||
*/
|
||||
has(id) {
|
||||
return Boolean(this.data[id]);
|
||||
}
|
||||
/**
|
||||
* Acquires write lock.
|
||||
*
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_acquireWriteLock() {
|
||||
const mutex = this._mutex;
|
||||
return new bluebird_1.default((resolve, reject) => {
|
||||
mutex.lock(resolve);
|
||||
}).disposer(() => {
|
||||
mutex.unlock();
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Inserts a document.
|
||||
*
|
||||
* @param {Document|object} data
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_insertOne(data_) {
|
||||
const schema = this.schema;
|
||||
// Apply getters
|
||||
const data = (data_ instanceof this.Document ? data_ : this.new(data_));
|
||||
const id = data._id;
|
||||
// Check ID
|
||||
if (!id) {
|
||||
return bluebird_1.default.reject(new error_1.default('ID is not defined', error_1.default.ID_UNDEFINED));
|
||||
}
|
||||
if (this.has(id)) {
|
||||
return bluebird_1.default.reject(new error_1.default('ID `' + id + '` has been used', error_1.default.ID_EXIST));
|
||||
}
|
||||
// Apply setters
|
||||
const result = data.toObject();
|
||||
schema._applySetters(result);
|
||||
// Pre-hooks
|
||||
return execHooks(schema, 'pre', 'save', data).then(data => {
|
||||
// Insert data
|
||||
this.data[id] = result;
|
||||
this.length++;
|
||||
this.emit('insert', data);
|
||||
return execHooks(schema, 'post', 'save', data);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Inserts a document.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
insertOne(data, callback) {
|
||||
return bluebird_1.default.using(this._acquireWriteLock(), () => this._insertOne(data)).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Inserts documents.
|
||||
*
|
||||
* @param {object|array} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
insert(data, callback) {
|
||||
if (Array.isArray(data)) {
|
||||
return bluebird_1.default.mapSeries(data, item => this.insertOne(item)).asCallback(callback);
|
||||
}
|
||||
return this.insertOne(data, callback);
|
||||
}
|
||||
/**
|
||||
* Inserts the document if it does not exist; otherwise updates it.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
save(data, callback) {
|
||||
const id = data._id;
|
||||
if (!id)
|
||||
return this.insertOne(data, callback);
|
||||
return bluebird_1.default.using(this._acquireWriteLock(), () => {
|
||||
if (this.has(id)) {
|
||||
return this._replaceById(id, data);
|
||||
}
|
||||
return this._insertOne(data);
|
||||
}).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Updates a document with a compiled stack.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {array} stack
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_updateWithStack(id, stack) {
|
||||
const schema = this.schema;
|
||||
const data = this.data[id];
|
||||
if (!data) {
|
||||
return bluebird_1.default.reject(new error_1.default('ID `' + id + '` does not exist', error_1.default.ID_NOT_EXIST));
|
||||
}
|
||||
// Clone data
|
||||
let result = cloneDeep(data);
|
||||
// Update
|
||||
for (let i = 0, len = stack.length; i < len; i++) {
|
||||
stack[i](result);
|
||||
}
|
||||
// Apply getters
|
||||
const doc = this.new(result);
|
||||
// Apply setters
|
||||
result = doc.toObject();
|
||||
schema._applySetters(result);
|
||||
// Pre-hooks
|
||||
return execHooks(schema, 'pre', 'save', doc).then(data => {
|
||||
// Update data
|
||||
this.data[id] = result;
|
||||
this.emit('update', data);
|
||||
return execHooks(schema, 'post', 'save', data);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Finds a document by its identifier and update it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {object} update
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
updateById(id, update, callback) {
|
||||
return bluebird_1.default.using(this._acquireWriteLock(), () => {
|
||||
const stack = this.schema._parseUpdate(update);
|
||||
return this._updateWithStack(id, stack);
|
||||
}).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Updates matching documents.
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
update(query, data, callback) {
|
||||
return this.find(query).update(data, callback);
|
||||
}
|
||||
/**
|
||||
* Finds a document by its identifier and replace it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {object} data
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_replaceById(id, data_) {
|
||||
const schema = this.schema;
|
||||
if (!this.has(id)) {
|
||||
return bluebird_1.default.reject(new error_1.default('ID `' + id + '` does not exist', error_1.default.ID_NOT_EXIST));
|
||||
}
|
||||
data_._id = id;
|
||||
// Apply getters
|
||||
const data = (data_ instanceof this.Document ? data_ : this.new(data_));
|
||||
// Apply setters
|
||||
const result = data.toObject();
|
||||
schema._applySetters(result);
|
||||
// Pre-hooks
|
||||
return execHooks(schema, 'pre', 'save', data).then(data => {
|
||||
// Replace data
|
||||
this.data[id] = result;
|
||||
this.emit('update', data);
|
||||
return execHooks(schema, 'post', 'save', data);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Finds a document by its identifier and replace it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
replaceById(id, data, callback) {
|
||||
return bluebird_1.default.using(this._acquireWriteLock(), () => this._replaceById(id, data)).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Replaces matching documents.
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {object} data
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
replace(query, data, callback) {
|
||||
return this.find(query).replace(data, callback);
|
||||
}
|
||||
/**
|
||||
* Finds a document by its identifier and remove it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @return {Promise}
|
||||
* @private
|
||||
*/
|
||||
_removeById(id) {
|
||||
const schema = this.schema;
|
||||
const data = this.data[id];
|
||||
if (!data) {
|
||||
return bluebird_1.default.reject(new error_1.default('ID `' + id + '` does not exist', error_1.default.ID_NOT_EXIST));
|
||||
}
|
||||
// Pre-hooks
|
||||
return execHooks(schema, 'pre', 'remove', data).then(data => {
|
||||
// Remove data
|
||||
this.data[id] = null;
|
||||
this.length--;
|
||||
this.emit('remove', data);
|
||||
return execHooks(schema, 'post', 'remove', data);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Finds a document by its identifier and remove it.
|
||||
*
|
||||
* @param {*} id
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
removeById(id, callback) {
|
||||
return bluebird_1.default.using(this._acquireWriteLock(), () => this._removeById(id)).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Removes matching documents.
|
||||
*
|
||||
* @param {object} query
|
||||
* @param {function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
remove(query, callback) {
|
||||
return this.find(query).remove(callback);
|
||||
}
|
||||
/**
|
||||
* Deletes a model.
|
||||
*/
|
||||
destroy() {
|
||||
this._database._models[this.name] = null;
|
||||
}
|
||||
/**
|
||||
* Returns the number of elements.
|
||||
*
|
||||
* @return {number}
|
||||
*/
|
||||
count() {
|
||||
return this.length;
|
||||
}
|
||||
/**
|
||||
* Iterates over all documents.
|
||||
*
|
||||
* @param {function} iterator
|
||||
* @param {object} [options] See {@link Model#findById}.
|
||||
*/
|
||||
forEach(iterator, options) {
|
||||
const keys = Object.keys(this.data);
|
||||
let num = 0;
|
||||
for (let i = 0, len = keys.length; i < len; i++) {
|
||||
const data = this.findById(keys[i], options);
|
||||
if (data)
|
||||
iterator(data, num++);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an array containing all documents.
|
||||
*
|
||||
* @param {Object} [options] See {@link Model#findById}.
|
||||
* @return {Array}
|
||||
*/
|
||||
toArray(options) {
|
||||
const result = new Array(this.length);
|
||||
this.forEach((item, i) => {
|
||||
result[i] = item;
|
||||
}, options);
|
||||
return result;
|
||||
}
|
||||
find(query, options = {}) {
|
||||
const filter = this.schema._execQuery(query);
|
||||
const keys = Object.keys(this.data);
|
||||
const len = keys.length;
|
||||
let limit = options.limit || this.length;
|
||||
let skip = options.skip;
|
||||
const data = this.data;
|
||||
const arr = [];
|
||||
for (let i = 0; limit && i < len; i++) {
|
||||
const key = keys[i];
|
||||
const item = data[key];
|
||||
if (item && filter(item)) {
|
||||
if (skip) {
|
||||
skip--;
|
||||
}
|
||||
else {
|
||||
arr.push(this.findById(key, options));
|
||||
limit--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return options.lean ? arr : new this.Query(arr);
|
||||
}
|
||||
findOne(query, options_ = {}) {
|
||||
const options = Object.assign(options_, { limit: 1 });
|
||||
const result = this.find(query, options);
|
||||
return options.lean ? result[0] : result.toArray()[0];
|
||||
}
|
||||
/**
|
||||
* Sorts documents. See {@link Query#sort}.
|
||||
*
|
||||
* @param {String|Object} orderby
|
||||
* @param {String|Number} [order]
|
||||
* @return {Query}
|
||||
*/
|
||||
sort(orderby, order) {
|
||||
const sort = (0, util_1.parseArgs)(orderby, order);
|
||||
const fn = this.schema._execSort(sort);
|
||||
return new this.Query(this.toArray().sort(fn));
|
||||
}
|
||||
/**
|
||||
* Returns the document at the specified index. `num` can be a positive or
|
||||
* negative number.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @param {Object} [options] See {@link Model#findById}.
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
eq(i_, options) {
|
||||
let index = i_ < 0 ? this.length + i_ : i_;
|
||||
const data = this.data;
|
||||
const keys = Object.keys(data);
|
||||
for (let i = 0, len = keys.length; i < len; i++) {
|
||||
const key = keys[i];
|
||||
const item = data[key];
|
||||
if (!item)
|
||||
continue;
|
||||
if (index) {
|
||||
index--;
|
||||
}
|
||||
else {
|
||||
return this.findById(key, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the first document.
|
||||
*
|
||||
* @param {Object} [options] See {@link Model#findById}.
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
first(options) {
|
||||
return this.eq(0, options);
|
||||
}
|
||||
/**
|
||||
* Returns the last document.
|
||||
*
|
||||
* @param {Object} [options] See {@link Model#findById}.
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
last(options) {
|
||||
return this.eq(-1, options);
|
||||
}
|
||||
/**
|
||||
* Returns the specified range of documents.
|
||||
*
|
||||
* @param {Number} start
|
||||
* @param {Number} [end]
|
||||
* @return {Query}
|
||||
*/
|
||||
slice(start_, end_) {
|
||||
const total = this.length;
|
||||
let start = start_ | 0;
|
||||
if (start < 0)
|
||||
start += total;
|
||||
if (start > total - 1)
|
||||
return new this.Query([]);
|
||||
let end = end_ | 0 || total;
|
||||
if (end < 0)
|
||||
end += total;
|
||||
let len = start > end ? 0 : end - start;
|
||||
if (len > total)
|
||||
len = total - start;
|
||||
if (!len)
|
||||
return new this.Query([]);
|
||||
const arr = new Array(len);
|
||||
const keys = Object.keys(this.data);
|
||||
const keysLen = keys.length;
|
||||
let num = 0;
|
||||
for (let i = 0; num < len && i < keysLen; i++) {
|
||||
const data = this.findById(keys[i]);
|
||||
if (!data)
|
||||
continue;
|
||||
if (start) {
|
||||
start--;
|
||||
}
|
||||
else {
|
||||
arr[num++] = data;
|
||||
}
|
||||
}
|
||||
return new this.Query(arr);
|
||||
}
|
||||
/**
|
||||
* Limits the number of documents returned.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Query}
|
||||
*/
|
||||
limit(i) {
|
||||
return this.slice(0, i);
|
||||
}
|
||||
/**
|
||||
* Specifies the number of items to skip.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Query}
|
||||
*/
|
||||
skip(i) {
|
||||
return this.slice(i);
|
||||
}
|
||||
/**
|
||||
* Returns documents in a reversed order.
|
||||
*
|
||||
* @return {Query}
|
||||
*/
|
||||
reverse() {
|
||||
return new this.Query(this.toArray().reverse());
|
||||
}
|
||||
/**
|
||||
* Returns documents in random order.
|
||||
*
|
||||
* @return {Query}
|
||||
*/
|
||||
shuffle() {
|
||||
return new this.Query((0, util_1.shuffle)(this.toArray()));
|
||||
}
|
||||
/**
|
||||
* Creates an array of values by iterating each element in the collection.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {Object} [options]
|
||||
* @return {Array}
|
||||
*/
|
||||
map(iterator, options) {
|
||||
const result = new Array(this.length);
|
||||
const keys = Object.keys(this.data);
|
||||
const len = keys.length;
|
||||
for (let i = 0, num = 0; i < len; i++) {
|
||||
const data = this.findById(keys[i], options);
|
||||
if (data) {
|
||||
result[num] = iterator(data, num);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of iterating
|
||||
* each element in the collection.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {*} [initial] By default, the initial value is the first document.
|
||||
* @return {*}
|
||||
*/
|
||||
reduce(iterator, initial) {
|
||||
const arr = this.toArray();
|
||||
const len = this.length;
|
||||
let i, result;
|
||||
if (initial === undefined) {
|
||||
i = 1;
|
||||
result = arr[0];
|
||||
}
|
||||
else {
|
||||
i = 0;
|
||||
result = initial;
|
||||
}
|
||||
for (; i < len; i++) {
|
||||
result = iterator(result, arr[i], i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of iterating
|
||||
* each element in the collection from right to left.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {*} [initial] By default, the initial value is the last document.
|
||||
* @return {*}
|
||||
*/
|
||||
reduceRight(iterator, initial) {
|
||||
const arr = this.toArray();
|
||||
const len = this.length;
|
||||
let i, result;
|
||||
if (initial === undefined) {
|
||||
i = len - 2;
|
||||
result = arr[len - 1];
|
||||
}
|
||||
else {
|
||||
i = len - 1;
|
||||
result = initial;
|
||||
}
|
||||
for (; i >= 0; i--) {
|
||||
result = iterator(result, arr[i], i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Creates a new array with all documents that pass the test implemented by the
|
||||
* provided function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {Object} [options]
|
||||
* @return {Query}
|
||||
*/
|
||||
filter(iterator, options) {
|
||||
const arr = [];
|
||||
this.forEach((item, i) => {
|
||||
if (iterator(item, i))
|
||||
arr.push(item);
|
||||
}, options);
|
||||
return new this.Query(arr);
|
||||
}
|
||||
/**
|
||||
* Tests whether all documents pass the test implemented by the provided
|
||||
* function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Boolean}
|
||||
*/
|
||||
every(iterator) {
|
||||
const keys = Object.keys(this.data);
|
||||
const len = keys.length;
|
||||
let num = 0;
|
||||
if (!len)
|
||||
return true;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const data = this.findById(keys[i]);
|
||||
if (data) {
|
||||
if (!iterator(data, num++))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Tests whether some documents pass the test implemented by the provided
|
||||
* function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Boolean}
|
||||
*/
|
||||
some(iterator) {
|
||||
const keys = Object.keys(this.data);
|
||||
const len = keys.length;
|
||||
let num = 0;
|
||||
if (!len)
|
||||
return false;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const data = this.findById(keys[i]);
|
||||
if (data) {
|
||||
if (iterator(data, num++))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns a getter function for normal population.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Model} model
|
||||
* @param {Object} options
|
||||
* @return {Function}
|
||||
* @private
|
||||
*/
|
||||
_populateGetter(data, model, options) {
|
||||
let hasCache = false;
|
||||
let cache;
|
||||
return () => {
|
||||
if (!hasCache) {
|
||||
cache = model.findById(data);
|
||||
hasCache = true;
|
||||
}
|
||||
return cache;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns a getter function for array population.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Model} model
|
||||
* @param {Object} options
|
||||
* @return {Function}
|
||||
* @private
|
||||
*/
|
||||
_populateGetterArray(data, model, options) {
|
||||
const Query = model.Query;
|
||||
let hasCache = false;
|
||||
let cache;
|
||||
return () => {
|
||||
if (!hasCache) {
|
||||
let arr = [];
|
||||
for (let i = 0, len = data.length; i < len; i++) {
|
||||
arr.push(model.findById(data[i]));
|
||||
}
|
||||
if (options.match) {
|
||||
cache = new Query(arr).find(options.match, options);
|
||||
}
|
||||
else if (options.skip) {
|
||||
if (options.limit) {
|
||||
arr = arr.slice(options.skip, options.skip + options.limit);
|
||||
}
|
||||
else {
|
||||
arr = arr.slice(options.skip);
|
||||
}
|
||||
cache = new Query(arr);
|
||||
}
|
||||
else if (options.limit) {
|
||||
cache = new Query(arr.slice(0, options.limit));
|
||||
}
|
||||
else {
|
||||
cache = new Query(arr);
|
||||
}
|
||||
if (options.sort) {
|
||||
cache = cache.sort(options.sort);
|
||||
}
|
||||
hasCache = true;
|
||||
}
|
||||
return cache;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Populates document references with a compiled stack.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Array} stack
|
||||
* @return {Object}
|
||||
* @private
|
||||
*/
|
||||
_populate(data, stack) {
|
||||
const models = this._database._models;
|
||||
for (let i = 0, len = stack.length; i < len; i++) {
|
||||
const item = stack[i];
|
||||
const model = models[item.model];
|
||||
if (!model) {
|
||||
throw new population_1.default('Model `' + item.model + '` does not exist');
|
||||
}
|
||||
const path = item.path;
|
||||
const prop = (0, util_1.getProp)(data, path);
|
||||
if (Array.isArray(prop)) {
|
||||
(0, util_1.setGetter)(data, path, this._populateGetterArray(prop, model, item));
|
||||
}
|
||||
else {
|
||||
(0, util_1.setGetter)(data, path, this._populateGetter(prop, model, item));
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/**
|
||||
* Populates document references.
|
||||
*
|
||||
* @param {String|Object} path
|
||||
* @return {Query}
|
||||
*/
|
||||
populate(path) {
|
||||
if (!path)
|
||||
throw new TypeError('path is required');
|
||||
const stack = this.schema._parsePopulate(path);
|
||||
const arr = new Array(this.length);
|
||||
this.forEach((item, i) => {
|
||||
arr[i] = this._populate(item, stack);
|
||||
});
|
||||
return new this.Query(arr);
|
||||
}
|
||||
/**
|
||||
* Imports data.
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @private
|
||||
*/
|
||||
_import(arr) {
|
||||
const len = arr.length;
|
||||
const data = this.data;
|
||||
const schema = this.schema;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const item = arr[i];
|
||||
data[item._id] = schema._parseDatabase(item);
|
||||
}
|
||||
this.length = len;
|
||||
}
|
||||
/**
|
||||
* Exports data.
|
||||
*
|
||||
* @return {String}
|
||||
* @private
|
||||
*/
|
||||
_export() {
|
||||
return JSON.stringify(this.toJSON());
|
||||
}
|
||||
toJSON() {
|
||||
const result = new Array(this.length);
|
||||
const { data, schema } = this;
|
||||
const keys = Object.keys(data);
|
||||
const { length } = keys;
|
||||
for (let i = 0, num = 0; i < length; i++) {
|
||||
const raw = data[keys[i]];
|
||||
if (raw) {
|
||||
result[num++] = schema._exportDatabase(cloneDeep(raw));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Model.prototype.get = Model.prototype.findById;
|
||||
function execHooks(schema, type, event, data) {
|
||||
const hooks = schema.hooks[type][event];
|
||||
if (!hooks.length)
|
||||
return bluebird_1.default.resolve(data);
|
||||
return bluebird_1.default.each(hooks, hook => hook(data)).thenReturn(data);
|
||||
}
|
||||
Model.prototype.size = Model.prototype.count;
|
||||
Model.prototype.each = Model.prototype.forEach;
|
||||
Model.prototype.random = Model.prototype.shuffle;
|
||||
exports.default = Model;
|
||||
//# sourceMappingURL=model.js.map
|
||||
1
node_modules/warehouse/dist/model.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/model.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
8
node_modules/warehouse/dist/mutex.d.ts
generated
vendored
Normal file
8
node_modules/warehouse/dist/mutex.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
declare class Mutex {
|
||||
private _locked;
|
||||
private readonly _queue;
|
||||
constructor();
|
||||
lock(fn: () => void): void;
|
||||
unlock(): void;
|
||||
}
|
||||
export default Mutex;
|
||||
29
node_modules/warehouse/dist/mutex.js
generated
vendored
Normal file
29
node_modules/warehouse/dist/mutex.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class Mutex {
|
||||
constructor() {
|
||||
this._locked = false;
|
||||
this._queue = [];
|
||||
}
|
||||
lock(fn) {
|
||||
if (this._locked) {
|
||||
this._queue.push(fn);
|
||||
return;
|
||||
}
|
||||
this._locked = true;
|
||||
fn();
|
||||
}
|
||||
unlock() {
|
||||
if (!this._locked)
|
||||
return;
|
||||
const next = this._queue.shift();
|
||||
if (next) {
|
||||
next();
|
||||
}
|
||||
else {
|
||||
this._locked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.default = Mutex;
|
||||
//# sourceMappingURL=mutex.js.map
|
||||
1
node_modules/warehouse/dist/mutex.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/mutex.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"mutex.js","sourceRoot":"","sources":["../src/mutex.ts"],"names":[],"mappings":";;AAAA,MAAM,KAAK;IAGT;QACE,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,EAAc;QACjB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACrB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,EAAE,EAAE,CAAC;IACP,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,OAAO;QAE1B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEjC,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,EAAE,CAAC;QACT,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACvB,CAAC;IACH,CAAC;CACF;AAED,kBAAe,KAAK,CAAC"}
|
||||
218
node_modules/warehouse/dist/query.d.ts
generated
vendored
Normal file
218
node_modules/warehouse/dist/query.d.ts
generated
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
import Promise from 'bluebird';
|
||||
import type Model from './model';
|
||||
import type Schema from './schema';
|
||||
import type Document from './document';
|
||||
import type { NodeJSLikeCallback, Options } from './types';
|
||||
declare abstract class Query<T> {
|
||||
data: Document<T>[];
|
||||
length: number;
|
||||
abstract _model: Model<T>;
|
||||
abstract _schema: Schema;
|
||||
/**
|
||||
* Query constructor.
|
||||
*
|
||||
* @param {Array} data
|
||||
*/
|
||||
constructor(data: Document<T>[]);
|
||||
/**
|
||||
* Returns the number of elements.
|
||||
*
|
||||
* @return Number
|
||||
*/
|
||||
count(): number;
|
||||
/**
|
||||
* Iterates over all documents.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
*/
|
||||
forEach(iterator: (item: any, index: number) => void): void;
|
||||
/**
|
||||
* Returns an array containing all documents.
|
||||
*
|
||||
* @return {Array}
|
||||
*/
|
||||
toArray(): Document<T>[];
|
||||
/**
|
||||
* Returns the document at the specified index. `num` can be a positive or
|
||||
* negative number.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
eq(i: number): Document<T>;
|
||||
/**
|
||||
* Returns the first document.
|
||||
*
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
first(): Document<T>;
|
||||
/**
|
||||
* Returns the last document.
|
||||
*
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
last(): Document<T>;
|
||||
/**
|
||||
* Returns the specified range of documents.
|
||||
*
|
||||
* @param {Number} start
|
||||
* @param {Number} [end]
|
||||
* @return {Query}
|
||||
*/
|
||||
slice(start: number, end?: number): Query<T>;
|
||||
/**
|
||||
* Limits the number of documents returned.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Query}
|
||||
*/
|
||||
limit(i: number): Query<T>;
|
||||
/**
|
||||
* Specifies the number of items to skip.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Query}
|
||||
*/
|
||||
skip(i: number): Query<T>;
|
||||
/**
|
||||
* Returns documents in a reversed order.
|
||||
*
|
||||
* @return {Query}
|
||||
*/
|
||||
reverse(): Query<T>;
|
||||
/**
|
||||
* Returns documents in random order.
|
||||
*
|
||||
* @return {Query}
|
||||
*/
|
||||
shuffle(): Query<T>;
|
||||
/**
|
||||
* Finds matching documents.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @param {Object} [options]
|
||||
* @param {Number} [options.limit=0] Limits the number of documents returned.
|
||||
* @param {Number} [options.skip=0] Skips the first elements.
|
||||
* @param {Boolean} [options.lean=false] Returns a plain JavaScript object.
|
||||
* @return {Query|Array}
|
||||
*/
|
||||
find(query: object): Query<T>;
|
||||
find(query: object, options: Options): T[] | Query<T>;
|
||||
/**
|
||||
* Finds the first matching documents.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @param {Object} [options]
|
||||
* @param {Number} [options.skip=0] Skips the first elements.
|
||||
* @param {Boolean} [options.lean=false] Returns a plain JavaScript object.
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
findOne(query: object): Document<T>;
|
||||
findOne(query: object, options: any): Document<T> | T;
|
||||
/**
|
||||
* Sorts documents.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ``` js
|
||||
* query.sort('date', -1);
|
||||
* query.sort({date: -1, title: 1});
|
||||
* query.sort('-date title');
|
||||
* ```
|
||||
*
|
||||
* If the `order` equals to `-1`, `desc` or `descending`, the data will be
|
||||
* returned in reversed order.
|
||||
*
|
||||
* @param {String|Object} orderby
|
||||
* @param {String|Number} [order]
|
||||
* @return {Query}
|
||||
*/
|
||||
sort(orderby: string | object, order?: string | number | object): Query<T>;
|
||||
/**
|
||||
* Creates an array of values by iterating each element in the collection.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Array}
|
||||
*/
|
||||
map<T>(iterator: (item: any, index: number) => T): T[];
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of iterating
|
||||
* each element in the collection.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {*} [initial] By default, the initial value is the first document.
|
||||
* @return {*}
|
||||
*/
|
||||
reduce<R>(iterator: (pre: any, cur: any, index: number) => R, initial?: R): R;
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of iterating
|
||||
* each element in the collection from right to left.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {*} [initial] By default, the initial value is the last document.
|
||||
* @return {*}
|
||||
*/
|
||||
reduceRight<R>(iterator: (pre: any, cur: any, index: number) => R, initial?: R): R;
|
||||
/**
|
||||
* Creates a new array with all documents that pass the test implemented by the
|
||||
* provided function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Query}
|
||||
*/
|
||||
filter(iterator: (item: any, index: number) => boolean): Query<T>;
|
||||
/**
|
||||
* Tests whether all documents pass the test implemented by the provided
|
||||
* function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Boolean}
|
||||
*/
|
||||
every(iterator: (item: any, index: number) => boolean): boolean;
|
||||
/**
|
||||
* Tests whether some documents pass the test implemented by the provided
|
||||
* function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Boolean}
|
||||
*/
|
||||
some(iterator: (item: any, index: number) => boolean): boolean;
|
||||
/**
|
||||
* Update all documents.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
update(data: any, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Replace all documents.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
replace(data: any, callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Remove all documents.
|
||||
*
|
||||
* @param {Function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
remove(callback?: NodeJSLikeCallback<any>): Promise<any>;
|
||||
/**
|
||||
* Populates document references.
|
||||
*
|
||||
* @param {String|Object} expr
|
||||
* @return {Query}
|
||||
*/
|
||||
populate(expr: string | any[] | {
|
||||
path?: string;
|
||||
model?: any;
|
||||
[key: PropertyKey]: any;
|
||||
}): Query<T>;
|
||||
size: Query<T>['count'];
|
||||
each: Query<T>['forEach'];
|
||||
random: Query<T>['shuffle'];
|
||||
}
|
||||
export default Query;
|
||||
326
node_modules/warehouse/dist/query.js
generated
vendored
Normal file
326
node_modules/warehouse/dist/query.js
generated
vendored
Normal file
@@ -0,0 +1,326 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const bluebird_1 = __importDefault(require("bluebird"));
|
||||
const util_1 = require("./util");
|
||||
class Query {
|
||||
/**
|
||||
* Query constructor.
|
||||
*
|
||||
* @param {Array} data
|
||||
*/
|
||||
constructor(data) {
|
||||
this.data = data;
|
||||
this.length = data.length;
|
||||
}
|
||||
/**
|
||||
* Returns the number of elements.
|
||||
*
|
||||
* @return Number
|
||||
*/
|
||||
count() {
|
||||
return this.length;
|
||||
}
|
||||
/**
|
||||
* Iterates over all documents.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
*/
|
||||
forEach(iterator) {
|
||||
const { data, length } = this;
|
||||
for (let i = 0; i < length; i++) {
|
||||
iterator(data[i], i);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns an array containing all documents.
|
||||
*
|
||||
* @return {Array}
|
||||
*/
|
||||
toArray() {
|
||||
return this.data;
|
||||
}
|
||||
/**
|
||||
* Returns the document at the specified index. `num` can be a positive or
|
||||
* negative number.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
eq(i) {
|
||||
const index = i < 0 ? this.length + i : i;
|
||||
return this.data[index];
|
||||
}
|
||||
/**
|
||||
* Returns the first document.
|
||||
*
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
first() {
|
||||
return this.eq(0);
|
||||
}
|
||||
/**
|
||||
* Returns the last document.
|
||||
*
|
||||
* @return {Document|Object}
|
||||
*/
|
||||
last() {
|
||||
return this.eq(-1);
|
||||
}
|
||||
/**
|
||||
* Returns the specified range of documents.
|
||||
*
|
||||
* @param {Number} start
|
||||
* @param {Number} [end]
|
||||
* @return {Query}
|
||||
*/
|
||||
slice(start, end) {
|
||||
return Reflect.construct(this.constructor, [this.data.slice(start, end)]);
|
||||
}
|
||||
/**
|
||||
* Limits the number of documents returned.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Query}
|
||||
*/
|
||||
limit(i) {
|
||||
return this.slice(0, i);
|
||||
}
|
||||
/**
|
||||
* Specifies the number of items to skip.
|
||||
*
|
||||
* @param {Number} i
|
||||
* @return {Query}
|
||||
*/
|
||||
skip(i) {
|
||||
return this.slice(i);
|
||||
}
|
||||
/**
|
||||
* Returns documents in a reversed order.
|
||||
*
|
||||
* @return {Query}
|
||||
*/
|
||||
reverse() {
|
||||
return Reflect.construct(this.constructor, [this.data.slice().reverse()]);
|
||||
}
|
||||
/**
|
||||
* Returns documents in random order.
|
||||
*
|
||||
* @return {Query}
|
||||
*/
|
||||
shuffle() {
|
||||
return Reflect.construct(this.constructor, [(0, util_1.shuffle)(this.data)]);
|
||||
}
|
||||
find(query, options = {}) {
|
||||
const filter = this._schema._execQuery(query);
|
||||
const { data, length } = this;
|
||||
const { lean = false } = options;
|
||||
let { limit = length, skip } = options;
|
||||
const arr = [];
|
||||
for (let i = 0; limit && i < length; i++) {
|
||||
const item = data[i];
|
||||
if (filter(item)) {
|
||||
if (skip) {
|
||||
skip--;
|
||||
}
|
||||
else {
|
||||
arr.push(lean ? item.toObject() : item);
|
||||
limit--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lean ? arr : Reflect.construct(this.constructor, [arr]);
|
||||
}
|
||||
findOne(query, options = {}) {
|
||||
const _options = Object.assign(options, { limit: 1 });
|
||||
const result = this.find(query, _options);
|
||||
return Array.isArray(result) ? result[0] : result.data[0];
|
||||
}
|
||||
/**
|
||||
* Sorts documents.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ``` js
|
||||
* query.sort('date', -1);
|
||||
* query.sort({date: -1, title: 1});
|
||||
* query.sort('-date title');
|
||||
* ```
|
||||
*
|
||||
* If the `order` equals to `-1`, `desc` or `descending`, the data will be
|
||||
* returned in reversed order.
|
||||
*
|
||||
* @param {String|Object} orderby
|
||||
* @param {String|Number} [order]
|
||||
* @return {Query}
|
||||
*/
|
||||
sort(orderby, order) {
|
||||
const sort = (0, util_1.parseArgs)(orderby, order);
|
||||
const fn = this._schema._execSort(sort);
|
||||
return Reflect.construct(this.constructor, [this.data.slice().sort(fn)]);
|
||||
}
|
||||
/**
|
||||
* Creates an array of values by iterating each element in the collection.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Array}
|
||||
*/
|
||||
map(iterator) {
|
||||
const { data, length } = this;
|
||||
const result = new Array(length);
|
||||
for (let i = 0; i < length; i++) {
|
||||
result[i] = iterator(data[i], i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of iterating
|
||||
* each element in the collection.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {*} [initial] By default, the initial value is the first document.
|
||||
* @return {*}
|
||||
*/
|
||||
reduce(iterator, initial) {
|
||||
const { data, length } = this;
|
||||
let result, i;
|
||||
if (initial === undefined) {
|
||||
i = 1;
|
||||
result = data[0];
|
||||
}
|
||||
else {
|
||||
i = 0;
|
||||
result = initial;
|
||||
}
|
||||
for (; i < length; i++) {
|
||||
result = iterator(result, data[i], i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Reduces a collection to a value which is the accumulated result of iterating
|
||||
* each element in the collection from right to left.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @param {*} [initial] By default, the initial value is the last document.
|
||||
* @return {*}
|
||||
*/
|
||||
reduceRight(iterator, initial) {
|
||||
const { data, length } = this;
|
||||
let result, i;
|
||||
if (initial === undefined) {
|
||||
i = length - 2;
|
||||
result = data[length - 1];
|
||||
}
|
||||
else {
|
||||
i = length - 1;
|
||||
result = initial;
|
||||
}
|
||||
for (; i >= 0; i--) {
|
||||
result = iterator(result, data[i], i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Creates a new array with all documents that pass the test implemented by the
|
||||
* provided function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Query}
|
||||
*/
|
||||
filter(iterator) {
|
||||
const { data, length } = this;
|
||||
const arr = [];
|
||||
for (let i = 0; i < length; i++) {
|
||||
const item = data[i];
|
||||
if (iterator(item, i))
|
||||
arr.push(item);
|
||||
}
|
||||
return Reflect.construct(this.constructor, [arr]);
|
||||
}
|
||||
/**
|
||||
* Tests whether all documents pass the test implemented by the provided
|
||||
* function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Boolean}
|
||||
*/
|
||||
every(iterator) {
|
||||
const { data, length } = this;
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (!iterator(data[i], i))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Tests whether some documents pass the test implemented by the provided
|
||||
* function.
|
||||
*
|
||||
* @param {Function} iterator
|
||||
* @return {Boolean}
|
||||
*/
|
||||
some(iterator) {
|
||||
const { data, length } = this;
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (iterator(data[i], i))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Update all documents.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
update(data, callback) {
|
||||
const model = this._model;
|
||||
const stack = this._schema._parseUpdate(data);
|
||||
return bluebird_1.default.mapSeries(this.data, item => model._updateWithStack(item._id, stack)).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Replace all documents.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @param {Function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
replace(data, callback) {
|
||||
const model = this._model;
|
||||
return bluebird_1.default.map(this.data, item => model.replaceById(item._id, data)).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Remove all documents.
|
||||
*
|
||||
* @param {Function} [callback]
|
||||
* @return {Promise}
|
||||
*/
|
||||
remove(callback) {
|
||||
const model = this._model;
|
||||
return bluebird_1.default.mapSeries(this.data, item => model.removeById(item._id)).asCallback(callback);
|
||||
}
|
||||
/**
|
||||
* Populates document references.
|
||||
*
|
||||
* @param {String|Object} expr
|
||||
* @return {Query}
|
||||
*/
|
||||
populate(expr) {
|
||||
const stack = this._schema._parsePopulate(expr);
|
||||
const { data, length } = this;
|
||||
const model = this._model;
|
||||
for (let i = 0; i < length; i++) {
|
||||
data[i] = model._populate(data[i], stack);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Query.prototype.size = Query.prototype.count;
|
||||
Query.prototype.each = Query.prototype.forEach;
|
||||
Query.prototype.random = Query.prototype.shuffle;
|
||||
exports.default = Query;
|
||||
//# sourceMappingURL=query.js.map
|
||||
1
node_modules/warehouse/dist/query.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/query.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
192
node_modules/warehouse/dist/schema.d.ts
generated
vendored
Normal file
192
node_modules/warehouse/dist/schema.d.ts
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
import SchemaType from './schematype';
|
||||
import * as Types from './types/index';
|
||||
import Promise from 'bluebird';
|
||||
import SchemaTypeVirtual from './types/virtual';
|
||||
import type { AddSchemaTypeOptions, PopulateResult } from './types';
|
||||
/**
|
||||
* @callback queryFilterCallback
|
||||
* @param {*} data
|
||||
* @return {boolean}
|
||||
*/
|
||||
type queryFilterCallback = (data: unknown) => boolean;
|
||||
/**
|
||||
* @callback queryCallback
|
||||
* @param {*} data
|
||||
* @return {void}
|
||||
*/
|
||||
type queryCallback = (data: unknown) => void;
|
||||
/**
|
||||
* @callback queryParseCallback
|
||||
* @param {*} a
|
||||
* @param {*} b
|
||||
* @returns {*}
|
||||
*/
|
||||
type queryParseCallback = (a: unknown, b: unknown) => number;
|
||||
declare class Schema {
|
||||
paths: Record<string, SchemaType<any>>;
|
||||
statics: Record<string, (...args: any[]) => any>;
|
||||
methods: Record<string, (...args: any[]) => any>;
|
||||
hooks: {
|
||||
pre: {
|
||||
save: ((...args: any[]) => Promise<any>)[];
|
||||
remove: ((...args: any[]) => Promise<any>)[];
|
||||
};
|
||||
post: {
|
||||
save: ((...args: any[]) => Promise<any>)[];
|
||||
remove: ((...args: any[]) => Promise<any>)[];
|
||||
};
|
||||
};
|
||||
stacks: {
|
||||
getter: ((data: object) => void)[];
|
||||
setter: ((data: object) => void)[];
|
||||
import: ((data: object) => void)[];
|
||||
export: ((data: object) => void)[];
|
||||
};
|
||||
/**
|
||||
* Schema constructor.
|
||||
*
|
||||
* @param {Object} [schema]
|
||||
*/
|
||||
constructor(schema?: Record<string, AddSchemaTypeOptions>);
|
||||
/**
|
||||
* Adds paths.
|
||||
*
|
||||
* @param {Object} schema
|
||||
* @param {String} prefix
|
||||
*/
|
||||
add(schema: Record<string, AddSchemaTypeOptions>, prefix?: string): void;
|
||||
/**
|
||||
* Gets/Sets a path.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {*} obj
|
||||
* @return {SchemaType | undefined}
|
||||
*/
|
||||
path(name: string): SchemaType<any>;
|
||||
path(name: string, obj: AddSchemaTypeOptions): void;
|
||||
/**
|
||||
* Updates cache stacks.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {SchemaType} type
|
||||
* @private
|
||||
*/
|
||||
_updateStack(name: string, type: SchemaType<unknown>): void;
|
||||
/**
|
||||
* Adds a virtual path.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Function} [getter]
|
||||
* @return {SchemaType.Virtual}
|
||||
*/
|
||||
virtual(name: string, getter?: () => any): SchemaTypeVirtual;
|
||||
/**
|
||||
* Adds a pre-hook.
|
||||
*
|
||||
* @param {String} type Hook type. One of `save` or `remove`.
|
||||
* @param {Function} fn
|
||||
*/
|
||||
pre(type: 'save' | 'remove', fn: (...args: any[]) => void): void;
|
||||
/**
|
||||
* Adds a post-hook.
|
||||
*
|
||||
* @param {String} type Hook type. One of `save` or `remove`.
|
||||
* @param {Function} fn
|
||||
*/
|
||||
post(type: 'save' | 'remove', fn: (...args: any[]) => void): void;
|
||||
/**
|
||||
* Adds a instance method.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
method(name: string, fn: (...args: any[]) => any): void;
|
||||
/**
|
||||
* Adds a static method.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
static(name: string, fn: (...args: any[]) => any): void;
|
||||
/**
|
||||
* Apply getters.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @return {void}
|
||||
* @private
|
||||
*/
|
||||
_applyGetters(data: object): void;
|
||||
/**
|
||||
* Apply setters.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @return {void}
|
||||
* @private
|
||||
*/
|
||||
_applySetters(data: object): void;
|
||||
/**
|
||||
* Parses database.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @return {Object}
|
||||
* @private
|
||||
*/
|
||||
_parseDatabase(data: object): object;
|
||||
/**
|
||||
* Exports database.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @return {Object}
|
||||
* @private
|
||||
*/
|
||||
_exportDatabase(data: object): object;
|
||||
/**
|
||||
* Parses updating expressions and returns a stack.
|
||||
*
|
||||
* @param {Object} updates
|
||||
* @return {queryCallback[]}
|
||||
* @private
|
||||
*/
|
||||
_parseUpdate(updates: object): queryCallback[];
|
||||
/**
|
||||
* Returns a function for querying.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @return {queryFilterCallback}
|
||||
* @private
|
||||
*/
|
||||
_execQuery(query: object): queryFilterCallback;
|
||||
/**
|
||||
* Parses sorting expressions and returns a stack.
|
||||
*
|
||||
* @param {Object} sorts
|
||||
* @param {string} [prefix]
|
||||
* @param {queryParseCallback[]} [stack]
|
||||
* @return {queryParseCallback[]}
|
||||
* @private
|
||||
*/
|
||||
_parseSort(sorts: object, prefix?: string, stack?: queryParseCallback[]): queryParseCallback[];
|
||||
/**
|
||||
* Returns a function for sorting.
|
||||
*
|
||||
* @param {Object} sorts
|
||||
* @return {queryParseCallback}
|
||||
* @private
|
||||
*/
|
||||
_execSort(sorts: object): queryParseCallback;
|
||||
/**
|
||||
* Parses population expression and returns a stack.
|
||||
*
|
||||
* @param {String|Object} expr
|
||||
* @return {PopulateResult[]}
|
||||
* @private
|
||||
*/
|
||||
_parsePopulate(expr: string | any[] | {
|
||||
path?: string;
|
||||
model?: any;
|
||||
[key: PropertyKey]: any;
|
||||
}): PopulateResult[];
|
||||
Types: typeof Types;
|
||||
static Types: typeof Types;
|
||||
}
|
||||
export default Schema;
|
||||
692
node_modules/warehouse/dist/schema.js
generated
vendored
Normal file
692
node_modules/warehouse/dist/schema.js
generated
vendored
Normal file
@@ -0,0 +1,692 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (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 });
|
||||
const schematype_1 = __importDefault(require("./schematype"));
|
||||
const Types = __importStar(require("./types/index"));
|
||||
const bluebird_1 = __importDefault(require("bluebird"));
|
||||
const util_1 = require("./util");
|
||||
const population_1 = __importDefault(require("./error/population"));
|
||||
const is_plain_object_1 = require("is-plain-object");
|
||||
const builtinTypes = new Set(['String', 'Number', 'Boolean', 'Array', 'Object', 'Date', 'Buffer']);
|
||||
const getSchemaType = (name, options) => {
|
||||
const Type = options.type || options;
|
||||
const typeName = Type.name;
|
||||
if (builtinTypes.has(typeName)) {
|
||||
return new Types[typeName](name, options);
|
||||
}
|
||||
return new Type(name, options);
|
||||
};
|
||||
const checkHookType = (type) => {
|
||||
if (type !== 'save' && type !== 'remove') {
|
||||
throw new TypeError('Hook type must be `save` or `remove`!');
|
||||
}
|
||||
};
|
||||
const hookWrapper = (fn) => {
|
||||
if (fn.length > 1) {
|
||||
return bluebird_1.default.promisify(fn);
|
||||
}
|
||||
return bluebird_1.default.method(fn);
|
||||
};
|
||||
/**
|
||||
* @param {Function[]} stack
|
||||
*/
|
||||
const execSortStack = (stack) => {
|
||||
const len = stack.length;
|
||||
return (a, b) => {
|
||||
let result;
|
||||
for (let i = 0; i < len; i++) {
|
||||
result = stack[i](a, b);
|
||||
if (result)
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
const sortStack = (path_, key, sort) => {
|
||||
const path = path_ || new schematype_1.default(key);
|
||||
const descending = sort === 'desc' || sort === -1;
|
||||
return (a, b) => {
|
||||
const result = path.compare((0, util_1.getProp)(a, key), (0, util_1.getProp)(b, key));
|
||||
return descending && result ? result * -1 : result;
|
||||
};
|
||||
};
|
||||
class UpdateParser {
|
||||
static updateStackNormal(key, update) {
|
||||
return (data) => { (0, util_1.setProp)(data, key, update); };
|
||||
}
|
||||
static updateStackOperator(path_, ukey, key, update) {
|
||||
const path = path_ || new schematype_1.default(key);
|
||||
return (data) => {
|
||||
const result = path[ukey]((0, util_1.getProp)(data, key), update, data);
|
||||
(0, util_1.setProp)(data, key, result);
|
||||
};
|
||||
}
|
||||
// eslint-disable-next-line no-useless-constructor
|
||||
constructor(paths) {
|
||||
this.paths = paths;
|
||||
}
|
||||
/**
|
||||
* Parses updating expressions and returns a stack.
|
||||
*
|
||||
* @param {Object} updates
|
||||
* @param {queryCallback[]} [stack]
|
||||
* @private
|
||||
*/
|
||||
parseUpdate(updates, prefix = '', stack = []) {
|
||||
const { paths } = this;
|
||||
const { updateStackOperator } = UpdateParser;
|
||||
const keys = Object.keys(updates);
|
||||
let path, prefixNoDot;
|
||||
if (prefix) {
|
||||
prefixNoDot = prefix.substring(0, prefix.length - 1);
|
||||
path = paths[prefixNoDot];
|
||||
}
|
||||
for (let i = 0, len = keys.length; i < len; i++) {
|
||||
const key = keys[i];
|
||||
const update = updates[key];
|
||||
const name = prefix + key;
|
||||
// Update operators
|
||||
if (key[0] === '$') {
|
||||
const ukey = `u${key}`;
|
||||
// First-class update operators
|
||||
if (prefix) {
|
||||
stack.push(updateStackOperator(path, ukey, prefixNoDot, update));
|
||||
}
|
||||
else { // Inline update operators
|
||||
const fields = Object.keys(update);
|
||||
const fieldLen = fields.length;
|
||||
for (let j = 0; j < fieldLen; j++) {
|
||||
const field = fields[i];
|
||||
stack.push(updateStackOperator(paths[field], ukey, field, update[field]));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((0, is_plain_object_1.isPlainObject)(update)) {
|
||||
this.parseUpdate(update, `${name}.`, stack);
|
||||
}
|
||||
else {
|
||||
stack.push(UpdateParser.updateStackNormal(name, update));
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
class QueryParser {
|
||||
// eslint-disable-next-line no-useless-constructor
|
||||
constructor(paths) {
|
||||
this.paths = paths;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {string} name
|
||||
* @param {*} query
|
||||
* @return {queryFilterCallback}
|
||||
*/
|
||||
queryStackNormal(name, query) {
|
||||
const path = this.paths[name] || new schematype_1.default(name);
|
||||
return (data) => path.match((0, util_1.getProp)(data, name), query, data);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param {string} qkey
|
||||
* @param {string} name
|
||||
* @param {*} query
|
||||
* @return {queryFilterCallback}
|
||||
*/
|
||||
queryStackOperator(qkey, name, query) {
|
||||
const path = this.paths[name] || new schematype_1.default(name);
|
||||
return data => path[qkey]((0, util_1.getProp)(data, name), query, data);
|
||||
}
|
||||
/**
|
||||
* @param {Array} arr
|
||||
* @param {queryFilterCallback[]} stack The function generated by query is added to the stack.
|
||||
* @return {void}
|
||||
* @private
|
||||
*/
|
||||
$and(arr, stack) {
|
||||
for (let i = 0, len = arr.length; i < len; i++) {
|
||||
stack.push(this.execQuery(arr[i]));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param {Array} query
|
||||
* @return {queryFilterCallback}
|
||||
* @private
|
||||
*/
|
||||
$or(query) {
|
||||
const stack = this.parseQueryArray(query);
|
||||
const len = stack.length;
|
||||
return data => {
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (stack[i](data))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @param {Array} query
|
||||
* @return {queryFilterCallback}
|
||||
* @private
|
||||
*/
|
||||
$nor(query) {
|
||||
const stack = this.parseQueryArray(query);
|
||||
const len = stack.length;
|
||||
return data => {
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (stack[i](data))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @param {*} query
|
||||
* @return {queryFilterCallback}
|
||||
* @private
|
||||
*/
|
||||
$not(query) {
|
||||
const stack = this.parseQuery(query);
|
||||
const len = stack.length;
|
||||
return data => {
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (!stack[i](data))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* @callback queryWherecallback
|
||||
* @return {boolean}
|
||||
* @this {QueryPerser}
|
||||
*/
|
||||
/**
|
||||
* @param {queryWherecallback} fn
|
||||
* @return {queryFilterCallback}
|
||||
* @private
|
||||
*/
|
||||
$where(fn) {
|
||||
return data => Reflect.apply(fn, data, []);
|
||||
}
|
||||
/**
|
||||
* Parses array of query expressions and returns a stack.
|
||||
*
|
||||
* @param {Array} arr
|
||||
* @return {queryFilterCallback[]}
|
||||
* @private
|
||||
*/
|
||||
parseQueryArray(arr) {
|
||||
const stack = [];
|
||||
this.$and(arr, stack);
|
||||
return stack;
|
||||
}
|
||||
/**
|
||||
* Parses normal query expressions and returns a stack.
|
||||
*
|
||||
* @param {Object} queries
|
||||
* @param {String} prefix
|
||||
* @param {queryFilterCallback[]} [stack] The function generated by query is added to the stack passed in this argument. If not passed, a new stack will be created.
|
||||
* @return {void}
|
||||
* @private
|
||||
*/
|
||||
parseNormalQuery(queries, prefix, stack = []) {
|
||||
const keys = Object.keys(queries);
|
||||
for (let i = 0, len = keys.length; i < len; i++) {
|
||||
const key = keys[i];
|
||||
const query = queries[key];
|
||||
if (key[0] === '$') {
|
||||
stack.push(this.queryStackOperator(`q${key}`, prefix, query));
|
||||
continue;
|
||||
}
|
||||
const name = `${prefix}.${key}`;
|
||||
if ((0, is_plain_object_1.isPlainObject)(query)) {
|
||||
this.parseNormalQuery(query, name, stack);
|
||||
}
|
||||
else {
|
||||
stack.push(this.queryStackNormal(name, query));
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parses query expressions and returns a stack.
|
||||
*
|
||||
* @param {Object} queries
|
||||
* @return {queryFilterCallback[]}
|
||||
* @private
|
||||
*/
|
||||
parseQuery(queries) {
|
||||
/** @type {queryFilterCallback[]} */
|
||||
const stack = [];
|
||||
const keys = Object.keys(queries);
|
||||
for (let i = 0, len = keys.length; i < len; i++) {
|
||||
const key = keys[i];
|
||||
const query = queries[key];
|
||||
switch (key) {
|
||||
case '$and':
|
||||
this.$and(query, stack);
|
||||
break;
|
||||
case '$or':
|
||||
stack.push(this.$or(query));
|
||||
break;
|
||||
case '$nor':
|
||||
stack.push(this.$nor(query));
|
||||
break;
|
||||
case '$not':
|
||||
stack.push(this.$not(query));
|
||||
break;
|
||||
case '$where':
|
||||
stack.push(this.$where(query));
|
||||
break;
|
||||
default:
|
||||
if ((0, is_plain_object_1.isPlainObject)(query)) {
|
||||
this.parseNormalQuery(query, key, stack);
|
||||
}
|
||||
else {
|
||||
stack.push(this.queryStackNormal(key, query));
|
||||
}
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
/**
|
||||
* Returns a function for querying.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @return {queryFilterCallback}
|
||||
* @private
|
||||
*/
|
||||
execQuery(query) {
|
||||
const stack = this.parseQuery(query);
|
||||
const len = stack.length;
|
||||
return data => {
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (!stack[i](data))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
class Schema {
|
||||
/**
|
||||
* Schema constructor.
|
||||
*
|
||||
* @param {Object} [schema]
|
||||
*/
|
||||
constructor(schema) {
|
||||
this.paths = {};
|
||||
this.statics = {};
|
||||
this.methods = {};
|
||||
this.hooks = {
|
||||
pre: {
|
||||
save: [],
|
||||
remove: []
|
||||
},
|
||||
post: {
|
||||
save: [],
|
||||
remove: []
|
||||
}
|
||||
};
|
||||
this.stacks = {
|
||||
getter: [],
|
||||
setter: [],
|
||||
import: [],
|
||||
export: []
|
||||
};
|
||||
if (schema) {
|
||||
this.add(schema);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Adds paths.
|
||||
*
|
||||
* @param {Object} schema
|
||||
* @param {String} prefix
|
||||
*/
|
||||
add(schema, prefix = '') {
|
||||
const keys = Object.keys(schema);
|
||||
const len = keys.length;
|
||||
if (!len)
|
||||
return;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const key = keys[i];
|
||||
const value = schema[key];
|
||||
this.path(prefix + key, value);
|
||||
}
|
||||
}
|
||||
path(name, obj) {
|
||||
if (obj == null) {
|
||||
return this.paths[name];
|
||||
}
|
||||
let type;
|
||||
let nested = false;
|
||||
if (obj instanceof schematype_1.default) {
|
||||
type = obj;
|
||||
}
|
||||
else {
|
||||
switch (typeof obj) {
|
||||
case 'function':
|
||||
type = getSchemaType(name, { type: obj });
|
||||
break;
|
||||
case 'object':
|
||||
if (Array.isArray(obj)) {
|
||||
type = new Types.Array(name, {
|
||||
child: obj.length ? getSchemaType(name, obj[0]) : new schematype_1.default(name)
|
||||
});
|
||||
}
|
||||
else if (obj.type) {
|
||||
type = getSchemaType(name, obj);
|
||||
}
|
||||
else {
|
||||
type = new Types.Object();
|
||||
nested = Object.keys(obj).length > 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new TypeError(`Invalid value for schema path \`${name}\``);
|
||||
}
|
||||
}
|
||||
this.paths[name] = type;
|
||||
this._updateStack(name, type);
|
||||
if (nested)
|
||||
this.add(obj, `${name}.`);
|
||||
}
|
||||
/**
|
||||
* Updates cache stacks.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {SchemaType} type
|
||||
* @private
|
||||
*/
|
||||
_updateStack(name, type) {
|
||||
const { stacks } = this;
|
||||
stacks.getter.push(data => {
|
||||
const value = (0, util_1.getProp)(data, name);
|
||||
const result = type.cast(value, data);
|
||||
if (result !== undefined) {
|
||||
(0, util_1.setProp)(data, name, result);
|
||||
}
|
||||
});
|
||||
stacks.setter.push(data => {
|
||||
const value = (0, util_1.getProp)(data, name);
|
||||
const result = type.validate(value, data);
|
||||
if (result !== undefined) {
|
||||
(0, util_1.setProp)(data, name, result);
|
||||
}
|
||||
else {
|
||||
(0, util_1.delProp)(data, name);
|
||||
}
|
||||
});
|
||||
stacks.import.push(data => {
|
||||
const value = (0, util_1.getProp)(data, name);
|
||||
const result = type.parse(value);
|
||||
if (result !== undefined) {
|
||||
(0, util_1.setProp)(data, name, result);
|
||||
}
|
||||
});
|
||||
stacks.export.push(data => {
|
||||
const value = (0, util_1.getProp)(data, name);
|
||||
const result = type.value(value, data);
|
||||
if (result !== undefined) {
|
||||
(0, util_1.setProp)(data, name, result);
|
||||
}
|
||||
else {
|
||||
(0, util_1.delProp)(data, name);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Adds a virtual path.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Function} [getter]
|
||||
* @return {SchemaType.Virtual}
|
||||
*/
|
||||
virtual(name, getter) {
|
||||
const virtual = new Types.Virtual(name, {});
|
||||
if (getter)
|
||||
virtual.get(getter);
|
||||
this.path(name, virtual);
|
||||
return virtual;
|
||||
}
|
||||
/**
|
||||
* Adds a pre-hook.
|
||||
*
|
||||
* @param {String} type Hook type. One of `save` or `remove`.
|
||||
* @param {Function} fn
|
||||
*/
|
||||
pre(type, fn) {
|
||||
checkHookType(type);
|
||||
if (typeof fn !== 'function')
|
||||
throw new TypeError('Hook must be a function!');
|
||||
this.hooks.pre[type].push(hookWrapper(fn));
|
||||
}
|
||||
/**
|
||||
* Adds a post-hook.
|
||||
*
|
||||
* @param {String} type Hook type. One of `save` or `remove`.
|
||||
* @param {Function} fn
|
||||
*/
|
||||
post(type, fn) {
|
||||
checkHookType(type);
|
||||
if (typeof fn !== 'function')
|
||||
throw new TypeError('Hook must be a function!');
|
||||
this.hooks.post[type].push(hookWrapper(fn));
|
||||
}
|
||||
/**
|
||||
* Adds a instance method.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
method(name, fn) {
|
||||
if (!name)
|
||||
throw new TypeError('Method name is required!');
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Instance method must be a function!');
|
||||
}
|
||||
this.methods[name] = fn;
|
||||
}
|
||||
/**
|
||||
* Adds a static method.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Function} fn
|
||||
*/
|
||||
static(name, fn) {
|
||||
if (!name)
|
||||
throw new TypeError('Method name is required!');
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Static method must be a function!');
|
||||
}
|
||||
this.statics[name] = fn;
|
||||
}
|
||||
/**
|
||||
* Apply getters.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @return {void}
|
||||
* @private
|
||||
*/
|
||||
_applyGetters(data) {
|
||||
const stack = this.stacks.getter;
|
||||
for (let i = 0, len = stack.length; i < len; i++) {
|
||||
stack[i](data);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Apply setters.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @return {void}
|
||||
* @private
|
||||
*/
|
||||
_applySetters(data) {
|
||||
const stack = this.stacks.setter;
|
||||
for (let i = 0, len = stack.length; i < len; i++) {
|
||||
stack[i](data);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parses database.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @return {Object}
|
||||
* @private
|
||||
*/
|
||||
_parseDatabase(data) {
|
||||
const stack = this.stacks.import;
|
||||
for (let i = 0, len = stack.length; i < len; i++) {
|
||||
stack[i](data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/**
|
||||
* Exports database.
|
||||
*
|
||||
* @param {Object} data
|
||||
* @return {Object}
|
||||
* @private
|
||||
*/
|
||||
_exportDatabase(data) {
|
||||
const stack = this.stacks.export;
|
||||
for (let i = 0, len = stack.length; i < len; i++) {
|
||||
stack[i](data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
/**
|
||||
* Parses updating expressions and returns a stack.
|
||||
*
|
||||
* @param {Object} updates
|
||||
* @return {queryCallback[]}
|
||||
* @private
|
||||
*/
|
||||
_parseUpdate(updates) {
|
||||
return new UpdateParser(this.paths).parseUpdate(updates);
|
||||
}
|
||||
/**
|
||||
* Returns a function for querying.
|
||||
*
|
||||
* @param {Object} query
|
||||
* @return {queryFilterCallback}
|
||||
* @private
|
||||
*/
|
||||
_execQuery(query) {
|
||||
return new QueryParser(this.paths).execQuery(query);
|
||||
}
|
||||
/**
|
||||
* Parses sorting expressions and returns a stack.
|
||||
*
|
||||
* @param {Object} sorts
|
||||
* @param {string} [prefix]
|
||||
* @param {queryParseCallback[]} [stack]
|
||||
* @return {queryParseCallback[]}
|
||||
* @private
|
||||
*/
|
||||
_parseSort(sorts, prefix = '', stack = []) {
|
||||
const { paths } = this;
|
||||
const keys = Object.keys(sorts);
|
||||
for (let i = 0, len = keys.length; i < len; i++) {
|
||||
const key = keys[i];
|
||||
const sort = sorts[key];
|
||||
const name = prefix + key;
|
||||
if (typeof sort === 'object') {
|
||||
this._parseSort(sort, `${name}.`, stack);
|
||||
}
|
||||
else {
|
||||
stack.push(sortStack(paths[name], name, sort));
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
/**
|
||||
* Returns a function for sorting.
|
||||
*
|
||||
* @param {Object} sorts
|
||||
* @return {queryParseCallback}
|
||||
* @private
|
||||
*/
|
||||
_execSort(sorts) {
|
||||
const stack = this._parseSort(sorts);
|
||||
return execSortStack(stack);
|
||||
}
|
||||
/**
|
||||
* Parses population expression and returns a stack.
|
||||
*
|
||||
* @param {String|Object} expr
|
||||
* @return {PopulateResult[]}
|
||||
* @private
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
_parsePopulate(expr) {
|
||||
const { paths } = this;
|
||||
const arr = [];
|
||||
if (typeof expr === 'string') {
|
||||
const split = expr.split(' ');
|
||||
for (let i = 0, len = split.length; i < len; i++) {
|
||||
arr[i] = { path: split[i] };
|
||||
}
|
||||
}
|
||||
else if (Array.isArray(expr)) {
|
||||
for (let i = 0, len = expr.length; i < len; i++) {
|
||||
const item = expr[i];
|
||||
arr[i] = typeof item === 'string' ? { path: item } : item;
|
||||
}
|
||||
}
|
||||
else {
|
||||
arr[0] = expr;
|
||||
}
|
||||
for (let i = 0, len = arr.length; i < len; i++) {
|
||||
const item = arr[i];
|
||||
const key = item.path;
|
||||
if (!key) {
|
||||
throw new population_1.default('path is required');
|
||||
}
|
||||
if (!item.model) {
|
||||
const path = paths[key];
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
const ref = path.child ? path.child.options.ref : path.options.ref;
|
||||
if (!ref) {
|
||||
throw new population_1.default('model is required');
|
||||
}
|
||||
item.model = ref;
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
Schema.Types = Types;
|
||||
Schema.prototype.Types = Types;
|
||||
exports.default = Schema;
|
||||
//# sourceMappingURL=schema.js.map
|
||||
1
node_modules/warehouse/dist/schema.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/schema.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
216
node_modules/warehouse/dist/schematype.d.ts
generated
vendored
Normal file
216
node_modules/warehouse/dist/schematype.d.ts
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
/**
|
||||
* This is the basic schema type.
|
||||
* All schema types should inherit from this class.
|
||||
* For example:
|
||||
*
|
||||
* ``` js
|
||||
* class SchemaTypeCustom extends SchemaType {};
|
||||
* ```
|
||||
*
|
||||
* **Query operators**
|
||||
*
|
||||
* To add a query operator, defines a method whose name is started with `q$`.
|
||||
* For example:
|
||||
*
|
||||
* ``` js
|
||||
* SchemaTypeCustom.q$foo = function(value, query, data){
|
||||
* // ...
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* The `value` parameter is the value of specified field; the `query` parameter
|
||||
* is the value passed to the query operator; the `data` parameter is the
|
||||
* complete data.
|
||||
*
|
||||
* The return value must be a boolean indicating whether the data passed.
|
||||
*
|
||||
* **Update operators**
|
||||
*
|
||||
* To add a update operator, defines a method whose name is started with `u$`.
|
||||
* For example:
|
||||
*
|
||||
* ``` js
|
||||
* SchemaTypeCustom.u$foo = function(value, update, data){
|
||||
* // ...
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* The `value` parameter is the value of specified field; the `update` parameter
|
||||
* is the value passed to the update operator; the `data` parameter is the
|
||||
* complete data.
|
||||
*
|
||||
* The return value will replace the original data.
|
||||
*/
|
||||
declare class SchemaType<T> {
|
||||
name: string;
|
||||
options: {
|
||||
required: boolean;
|
||||
default?: (() => T) | T;
|
||||
};
|
||||
default: () => T;
|
||||
/**
|
||||
* SchemaType constructor.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.required=false]
|
||||
* @param {*} [options.default]
|
||||
*/
|
||||
constructor(name?: string, options?: {
|
||||
required?: boolean;
|
||||
default?: (() => T) | T;
|
||||
});
|
||||
/**
|
||||
* Casts data. This function is used by getters to cast an object to document
|
||||
* instances. If the value is null, the default value will be returned.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
cast(value?: unknown, data?: unknown): unknown;
|
||||
/**
|
||||
* Validates data. This function is used by setters.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*|Error}
|
||||
*/
|
||||
validate(value: unknown, data?: unknown): unknown;
|
||||
/**
|
||||
* Compares data. This function is used when sorting.
|
||||
*
|
||||
* @param {*} a
|
||||
* @param {*} b
|
||||
* @return {Number}
|
||||
*/
|
||||
compare(a: unknown, b: unknown): number;
|
||||
/**
|
||||
* Parses data. This function is used when restoring data from database files.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
parse(value: unknown): any;
|
||||
/**
|
||||
* Transforms value. This function is used when saving data to database files.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
value(value: unknown, data?: unknown): any;
|
||||
/**
|
||||
* Checks the equality of data.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value: T, query: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks the existance of data.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$exist(value: unknown, query: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks the equality of data. Returns true if the value doesn't match.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {boolean}
|
||||
*/
|
||||
q$ne(value: T, query: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether `value` is less than (i.e. <) the `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$lt(value: unknown, query: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether `value` is less than or equal to (i.e. <=) the `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$lte(value: unknown, query: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether `value` is greater than (i.e. >) the `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$gt(value: unknown, query: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether `value` is greater than or equal to (i.e. >=) the `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$gte(value: unknown, query: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether `value` is equal to one of elements in `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$in(value: unknown, query: unknown[], data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether `value` is not equal to any elements in `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$nin(value: unknown, query: unknown[], data?: unknown): boolean;
|
||||
/**
|
||||
* Sets the value.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
u$set<T>(value: unknown, update: T, data?: unknown): T;
|
||||
/**
|
||||
* Unsets the value.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
u$unset<T>(value: T, update: boolean, data?: unknown): T | undefined;
|
||||
/**
|
||||
* Renames a field.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
u$rename(value: unknown, update: unknown, data: unknown): void;
|
||||
q$exists: SchemaType<T>['q$exist'];
|
||||
q$max: SchemaType<T>['q$lte'];
|
||||
q$min: SchemaType<T>['q$gte'];
|
||||
}
|
||||
export default SchemaType;
|
||||
273
node_modules/warehouse/dist/schematype.js
generated
vendored
Normal file
273
node_modules/warehouse/dist/schematype.js
generated
vendored
Normal file
@@ -0,0 +1,273 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const util_1 = require("./util");
|
||||
const validation_1 = __importDefault(require("./error/validation"));
|
||||
/**
|
||||
* This is the basic schema type.
|
||||
* All schema types should inherit from this class.
|
||||
* For example:
|
||||
*
|
||||
* ``` js
|
||||
* class SchemaTypeCustom extends SchemaType {};
|
||||
* ```
|
||||
*
|
||||
* **Query operators**
|
||||
*
|
||||
* To add a query operator, defines a method whose name is started with `q$`.
|
||||
* For example:
|
||||
*
|
||||
* ``` js
|
||||
* SchemaTypeCustom.q$foo = function(value, query, data){
|
||||
* // ...
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* The `value` parameter is the value of specified field; the `query` parameter
|
||||
* is the value passed to the query operator; the `data` parameter is the
|
||||
* complete data.
|
||||
*
|
||||
* The return value must be a boolean indicating whether the data passed.
|
||||
*
|
||||
* **Update operators**
|
||||
*
|
||||
* To add a update operator, defines a method whose name is started with `u$`.
|
||||
* For example:
|
||||
*
|
||||
* ``` js
|
||||
* SchemaTypeCustom.u$foo = function(value, update, data){
|
||||
* // ...
|
||||
* };
|
||||
* ```
|
||||
*
|
||||
* The `value` parameter is the value of specified field; the `update` parameter
|
||||
* is the value passed to the update operator; the `data` parameter is the
|
||||
* complete data.
|
||||
*
|
||||
* The return value will replace the original data.
|
||||
*/
|
||||
class SchemaType {
|
||||
/**
|
||||
* SchemaType constructor.
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.required=false]
|
||||
* @param {*} [options.default]
|
||||
*/
|
||||
constructor(name = '', options) {
|
||||
this.name = name;
|
||||
this.options = Object.assign({
|
||||
required: false
|
||||
}, options);
|
||||
const default_ = this.options.default;
|
||||
if (typeof default_ === 'function') {
|
||||
this.default = default_;
|
||||
}
|
||||
else {
|
||||
this.default = () => default_;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Casts data. This function is used by getters to cast an object to document
|
||||
* instances. If the value is null, the default value will be returned.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
cast(value, data) {
|
||||
if (value == null) {
|
||||
return this.default();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Validates data. This function is used by setters.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*|Error}
|
||||
*/
|
||||
validate(value, data) {
|
||||
if (this.options.required && value == null) {
|
||||
throw new validation_1.default(`\`${this.name}\` is required!`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Compares data. This function is used when sorting.
|
||||
*
|
||||
* @param {*} a
|
||||
* @param {*} b
|
||||
* @return {Number}
|
||||
*/
|
||||
compare(a, b) {
|
||||
if (a > b) {
|
||||
return 1;
|
||||
}
|
||||
else if (a < b) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
* Parses data. This function is used when restoring data from database files.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
parse(value) {
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Transforms value. This function is used when saving data to database files.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
value(value, data) {
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Checks the equality of data.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value, query, data) {
|
||||
return value === query;
|
||||
}
|
||||
/**
|
||||
* Checks the existance of data.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$exist(value, query, data) {
|
||||
return (value != null) === query;
|
||||
}
|
||||
/**
|
||||
* Checks the equality of data. Returns true if the value doesn't match.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {boolean}
|
||||
*/
|
||||
q$ne(value, query, data) {
|
||||
return !this.match(value, query, data);
|
||||
}
|
||||
/**
|
||||
* Checks whether `value` is less than (i.e. <) the `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$lt(value, query, data) {
|
||||
return value < query;
|
||||
}
|
||||
/**
|
||||
* Checks whether `value` is less than or equal to (i.e. <=) the `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$lte(value, query, data) {
|
||||
return value <= query;
|
||||
}
|
||||
/**
|
||||
* Checks whether `value` is greater than (i.e. >) the `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$gt(value, query, data) {
|
||||
return value > query;
|
||||
}
|
||||
/**
|
||||
* Checks whether `value` is greater than or equal to (i.e. >=) the `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$gte(value, query, data) {
|
||||
return value >= query;
|
||||
}
|
||||
/**
|
||||
* Checks whether `value` is equal to one of elements in `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$in(value, query, data) {
|
||||
return query.includes(value);
|
||||
}
|
||||
/**
|
||||
* Checks whether `value` is not equal to any elements in `query`.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$nin(value, query, data) {
|
||||
return !query.includes(value);
|
||||
}
|
||||
/**
|
||||
* Sets the value.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
u$set(value, update, data) {
|
||||
return update;
|
||||
}
|
||||
/**
|
||||
* Unsets the value.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
u$unset(value, update, data) { return update ? undefined : value; }
|
||||
/**
|
||||
* Renames a field.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
u$rename(value, update, data) {
|
||||
if (value !== undefined)
|
||||
(0, util_1.setProp)(data, update, value);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
SchemaType.prototype.q$exists = SchemaType.prototype.q$exist;
|
||||
SchemaType.prototype.q$max = SchemaType.prototype.q$lte;
|
||||
SchemaType.prototype.q$min = SchemaType.prototype.q$gte;
|
||||
exports.default = SchemaType;
|
||||
//# sourceMappingURL=schematype.js.map
|
||||
1
node_modules/warehouse/dist/schematype.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/schematype.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"schematype.js","sourceRoot":"","sources":["../src/schematype.ts"],"names":[],"mappings":";;;;;AAAA,iCAAiC;AACjC,oEAAiD;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,UAAU;IAId;;;;;;;OAOG;IACH,YAAmB,OAAe,EAAE,EAAE,OAA0D;QAA7E,SAAI,GAAJ,IAAI,CAAa;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;YAC3B,QAAQ,EAAE,KAAK;SAChB,EAAE,OAAO,CAAC,CAAC;QAEZ,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAEtC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;YACnC,IAAI,CAAC,OAAO,GAAG,QAAmB,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC;QAChC,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,CAAC,KAAe,EAAE,IAAc;QAClC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACxB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,KAAc,EAAE,IAAc;QACrC,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YA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.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import type SchemaType from './schematype';
|
||||
export type NodeJSLikeCallback<R, E = any> = (err: E, result?: R) => void;
|
||||
export interface Options {
|
||||
lean?: boolean;
|
||||
skip?: number;
|
||||
limit?: number;
|
||||
[key: PropertyKey]: any;
|
||||
}
|
||||
export type SchemaTypeOptions = typeof SchemaType<unknown> | SchemaType<unknown> | ((...args: any[]) => any);
|
||||
export type AddSchemaTypeSimpleOptions = SchemaTypeOptions | {
|
||||
type: SchemaTypeOptions;
|
||||
[key: string]: any;
|
||||
};
|
||||
export type AddSchemaTypeMixedOptions = AddSchemaTypeSimpleOptions | AddSchemaTypeSimpleOptions[];
|
||||
export interface AddSchemaTypeLoopOptions {
|
||||
[key: string]: AddSchemaTypeMixedOptions | AddSchemaTypeLoopOptions;
|
||||
}
|
||||
export type AddSchemaTypeOptions = AddSchemaTypeMixedOptions | AddSchemaTypeLoopOptions;
|
||||
/**
|
||||
* @typedef PopulateResult
|
||||
* @property {string} path
|
||||
* @property {*} model
|
||||
*/
|
||||
export type PopulateResult = {
|
||||
path: string;
|
||||
model: any;
|
||||
};
|
||||
3
node_modules/warehouse/dist/types.js
generated
vendored
Normal file
3
node_modules/warehouse/dist/types.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
//# sourceMappingURL=types.js.map
|
||||
1
node_modules/warehouse/dist/types.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
||||
166
node_modules/warehouse/dist/types/array.d.ts
generated
vendored
Normal file
166
node_modules/warehouse/dist/types/array.d.ts
generated
vendored
Normal file
@@ -0,0 +1,166 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* Array schema type.
|
||||
*/
|
||||
declare class SchemaTypeArray<I, T extends SchemaType<I>> extends SchemaType<I[]> {
|
||||
options: SchemaType<I[]>['options'] & {
|
||||
child?: T;
|
||||
};
|
||||
child: T;
|
||||
/**
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.required=false]
|
||||
* @param {Array|Function} [options.default=[]]
|
||||
* @param {SchemaType} [options.child]
|
||||
*/
|
||||
constructor(name: string, options?: Partial<SchemaType<I[]>['options']> & {
|
||||
child?: T;
|
||||
});
|
||||
/**
|
||||
* Casts an array and its child elements.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
cast(value_: Exclude<unknown, null | undefined>, data?: unknown): I[];
|
||||
cast(value_?: unknown, data?: unknown): I[] | undefined;
|
||||
/**
|
||||
* Validates an array and its child elements.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Array|Error}
|
||||
*/
|
||||
validate(value_?: unknown, data?: unknown): I[];
|
||||
/**
|
||||
* Compares an array by its child elements and the size of the array.
|
||||
*
|
||||
* @param {Array} a
|
||||
* @param {Array} b
|
||||
* @return {Number}
|
||||
*/
|
||||
compare(a?: I[], b?: I[]): number;
|
||||
/**
|
||||
* Parses data.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @return {Array}
|
||||
*/
|
||||
parse(value: unknown[]): I[];
|
||||
parse(): undefined;
|
||||
/**
|
||||
* Transforms data.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
value(value: unknown[], data?: unknown): any[];
|
||||
value(): undefined;
|
||||
/**
|
||||
* Checks the equality of an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value?: I[], query?: unknown[], data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether the number of elements in an array is equal to `query`.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Number} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$size(value?: unknown[], query?: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether an array contains one of elements in `query`.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$in(value?: unknown[], query?: unknown[], data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether an array does not contain in any elements in `query`.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$nin<T>(value?: T[], query?: T[], data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether an array contains all elements in `query`.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$all<T>(value?: T[], query?: T[], data?: unknown): boolean;
|
||||
/**
|
||||
* Add elements to an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$push<T>(value?: T[], update?: T | T[], data?: unknown): T[];
|
||||
/**
|
||||
* Add elements in front of an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$unshift<T>(value?: T[], update?: T | T[], data?: unknown): T[];
|
||||
/**
|
||||
* Removes elements from an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$pull<T>(value?: T[], update?: T | T[], data?: unknown): T[];
|
||||
/**
|
||||
* Removes the first element from an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Number|Boolean} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$shift<T>(value?: T[], update?: number | boolean, data?: unknown): T[];
|
||||
/**
|
||||
* Removes the last element from an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Number|Boolean} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$pop<T>(value?: T[], update?: number | boolean, data?: unknown): T[];
|
||||
/**
|
||||
* Add elements to an array only if the value is not already in the array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$addToSet<T>(value?: T[], update?: T | T[], data?: unknown): T[];
|
||||
q$length: SchemaTypeArray<I, T>['q$size'];
|
||||
u$append: SchemaTypeArray<I, T>['u$push'];
|
||||
u$prepend: SchemaTypeArray<I, T>['u$unshift'];
|
||||
}
|
||||
export default SchemaTypeArray;
|
||||
319
node_modules/warehouse/dist/types/array.js
generated
vendored
Normal file
319
node_modules/warehouse/dist/types/array.js
generated
vendored
Normal file
@@ -0,0 +1,319 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
const { isArray } = Array;
|
||||
/**
|
||||
* Array schema type.
|
||||
*/
|
||||
class SchemaTypeArray extends schematype_1.default {
|
||||
/**
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.required=false]
|
||||
* @param {Array|Function} [options.default=[]]
|
||||
* @param {SchemaType} [options.child]
|
||||
*/
|
||||
constructor(name, options) {
|
||||
super(name, Object.assign({
|
||||
default: []
|
||||
}, options));
|
||||
this.child = this.options.child || new schematype_1.default(name);
|
||||
}
|
||||
cast(value_, data) {
|
||||
value_ = super.cast(value_, data);
|
||||
if (value_ == null)
|
||||
return value_;
|
||||
const value = isArray(value_) ? value_ : value_ = [value_];
|
||||
if (!value.length)
|
||||
return value;
|
||||
const child = this.child;
|
||||
for (let i = 0, len = value.length; i < len; i++) {
|
||||
value[i] = child.cast(value[i], data);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Validates an array and its child elements.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Array|Error}
|
||||
*/
|
||||
validate(value_, data) {
|
||||
const value = super.validate(value_, data);
|
||||
if (!isArray(value)) {
|
||||
throw new validation_1.default(`\`${value}\` is not an array!`);
|
||||
}
|
||||
if (!value.length)
|
||||
return value;
|
||||
const child = this.child;
|
||||
for (let i = 0, len = value.length; i < len; i++) {
|
||||
value[i] = child.validate(value[i], data);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Compares an array by its child elements and the size of the array.
|
||||
*
|
||||
* @param {Array} a
|
||||
* @param {Array} b
|
||||
* @return {Number}
|
||||
*/
|
||||
compare(a, b) {
|
||||
if (a) {
|
||||
if (!b)
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return b ? -1 : 0;
|
||||
}
|
||||
const lenA = a.length;
|
||||
const lenB = b.length;
|
||||
const child = this.child;
|
||||
for (let i = 0, len = Math.min(lenA, lenB); i < len; i++) {
|
||||
const result = child.compare(a[i], b[i]);
|
||||
if (result !== 0)
|
||||
return result;
|
||||
}
|
||||
// Compare by length
|
||||
return lenA - lenB;
|
||||
}
|
||||
parse(value) {
|
||||
if (!value)
|
||||
return value;
|
||||
const len = value.length;
|
||||
if (!len)
|
||||
return [];
|
||||
const result = new Array(len);
|
||||
const child = this.child;
|
||||
for (let i = 0; i < len; i++) {
|
||||
result[i] = child.parse(value[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
value(value, data) {
|
||||
if (!value)
|
||||
return value;
|
||||
const len = value.length;
|
||||
if (!len)
|
||||
return [];
|
||||
const result = new Array(len);
|
||||
const child = this.child;
|
||||
for (let i = 0; i < len; i++) {
|
||||
result[i] = child.value(value[i], data);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Checks the equality of an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value, query, data) {
|
||||
if (!value || !query) {
|
||||
return value === query;
|
||||
}
|
||||
const lenA = value.length;
|
||||
const lenB = query.length;
|
||||
if (lenA !== lenB)
|
||||
return false;
|
||||
const child = this.child;
|
||||
for (let i = 0; i < lenA; i++) {
|
||||
if (!child.match(value[i], query[i], data))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Checks whether the number of elements in an array is equal to `query`.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Number} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$size(value, query, data) {
|
||||
return (value ? value.length : 0) === query;
|
||||
}
|
||||
/**
|
||||
* Checks whether an array contains one of elements in `query`.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$in(value, query, data) {
|
||||
if (!value)
|
||||
return false;
|
||||
for (let i = 0, len = query.length; i < len; i++) {
|
||||
if (value.includes(query[i]))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Checks whether an array does not contain in any elements in `query`.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$nin(value, query, data) {
|
||||
if (!value)
|
||||
return true;
|
||||
for (let i = 0, len = query.length; i < len; i++) {
|
||||
if (value.includes(query[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Checks whether an array contains all elements in `query`.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$all(value, query, data) {
|
||||
if (!value)
|
||||
return false;
|
||||
for (let i = 0, len = query.length; i < len; i++) {
|
||||
if (!value.includes(query[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Add elements to an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$push(value, update, data) {
|
||||
if (isArray(update)) {
|
||||
return value ? value.concat(update) : update;
|
||||
}
|
||||
if (value) {
|
||||
value.push(update);
|
||||
return value;
|
||||
}
|
||||
return [update];
|
||||
}
|
||||
/**
|
||||
* Add elements in front of an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$unshift(value, update, data) {
|
||||
if (isArray(update)) {
|
||||
return value ? update.concat(value) : update;
|
||||
}
|
||||
if (value) {
|
||||
value.unshift(update);
|
||||
return value;
|
||||
}
|
||||
return [update];
|
||||
}
|
||||
/**
|
||||
* Removes elements from an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$pull(value, update, data) {
|
||||
if (!value)
|
||||
return value;
|
||||
if (isArray(update)) {
|
||||
return value.filter(item => !update.includes(item));
|
||||
}
|
||||
return value.filter(item => item !== update);
|
||||
}
|
||||
/**
|
||||
* Removes the first element from an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Number|Boolean} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$shift(value, update, data) {
|
||||
if (!value || !update)
|
||||
return value;
|
||||
if (update === true) {
|
||||
return value.slice(1);
|
||||
}
|
||||
else if (update > 0) {
|
||||
return value.slice(update);
|
||||
}
|
||||
return value.slice(0, value.length + update);
|
||||
}
|
||||
/**
|
||||
* Removes the last element from an array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {Number|Boolean} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$pop(value, update, data) {
|
||||
if (!value || !update)
|
||||
return value;
|
||||
const length = value.length;
|
||||
if (update === true) {
|
||||
return value.slice(0, length - 1);
|
||||
}
|
||||
else if (update > 0) {
|
||||
return value.slice(0, length - update);
|
||||
}
|
||||
return value.slice(-update, length);
|
||||
}
|
||||
/**
|
||||
* Add elements to an array only if the value is not already in the array.
|
||||
*
|
||||
* @param {Array} value
|
||||
* @param {*} update
|
||||
* @param {Object} data
|
||||
* @return {Array}
|
||||
*/
|
||||
u$addToSet(value, update, data) {
|
||||
if (isArray(update)) {
|
||||
if (!value)
|
||||
return update;
|
||||
for (let i = 0, len = update.length; i < len; i++) {
|
||||
const item = update[i];
|
||||
if (!value.includes(item))
|
||||
value.push(item);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
if (!value)
|
||||
return [update];
|
||||
if (!value.includes(update)) {
|
||||
value.push(update);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
SchemaTypeArray.prototype.q$length = SchemaTypeArray.prototype.q$size;
|
||||
SchemaTypeArray.prototype.u$append = SchemaTypeArray.prototype.u$push;
|
||||
SchemaTypeArray.prototype.u$prepend = SchemaTypeArray.prototype.u$unshift;
|
||||
exports.default = SchemaTypeArray;
|
||||
//# sourceMappingURL=array.js.map
|
||||
1
node_modules/warehouse/dist/types/array.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/array.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
37
node_modules/warehouse/dist/types/boolean.d.ts
generated
vendored
Normal file
37
node_modules/warehouse/dist/types/boolean.d.ts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* Boolean schema type.
|
||||
*/
|
||||
declare class SchemaTypeBoolean extends SchemaType<boolean> {
|
||||
/**
|
||||
* Casts a boolean.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
cast(value_?: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Validates a boolean.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Boolean|Error}
|
||||
*/
|
||||
validate(value_: unknown, data?: unknown): boolean;
|
||||
/**
|
||||
* Parses data and transform them into boolean values.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
parse(value: unknown): boolean;
|
||||
/**
|
||||
* Transforms data into number to compress the size of database files.
|
||||
*
|
||||
* @param {Boolean} value
|
||||
* @return {Number}
|
||||
*/
|
||||
value(value: unknown): number;
|
||||
}
|
||||
export default SchemaTypeBoolean;
|
||||
59
node_modules/warehouse/dist/types/boolean.js
generated
vendored
Normal file
59
node_modules/warehouse/dist/types/boolean.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
/**
|
||||
* Boolean schema type.
|
||||
*/
|
||||
class SchemaTypeBoolean extends schematype_1.default {
|
||||
/**
|
||||
* Casts a boolean.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
cast(value_, data) {
|
||||
const value = super.cast(value_, data);
|
||||
if (value === 'false' || value === '0')
|
||||
return false;
|
||||
return Boolean(value);
|
||||
}
|
||||
/**
|
||||
* Validates a boolean.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Boolean|Error}
|
||||
*/
|
||||
validate(value_, data) {
|
||||
const value = super.validate(value_, data);
|
||||
if (value != null && typeof value !== 'boolean') {
|
||||
throw new validation_1.default(`\`${value}\` is not a boolean!`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Parses data and transform them into boolean values.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
parse(value) {
|
||||
return Boolean(value);
|
||||
}
|
||||
/**
|
||||
* Transforms data into number to compress the size of database files.
|
||||
*
|
||||
* @param {Boolean} value
|
||||
* @return {Number}
|
||||
*/
|
||||
value(value) {
|
||||
return +value;
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeBoolean;
|
||||
//# sourceMappingURL=boolean.js.map
|
||||
1
node_modules/warehouse/dist/types/boolean.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/boolean.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../src/types/boolean.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,qEAAkD;AAElD;;GAEG;AACH,MAAM,iBAAkB,SAAQ,oBAAmB;IAEjD;;;;;;OAMG;IACH,IAAI,CAAC,MAAgB,EAAE,IAAc;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEvC,IAAI,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,GAAG;YAAE,OAAO,KAAK,CAAC;QAErD,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,MAAe,EAAE,IAAc;QACtC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAE3C,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK,KAAK,SAAS,EAAE,CAAC;YAChD,MAAM,IAAI,oBAAe,CAAC,KAAK,KAAK,sBAAsB,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO,KAAgB,CAAC;IAC1B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAc;QAClB,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAc;QAClB,OAAO,CAAC,KAAK,CAAC;IAChB,CAAC;CACF;AAED,kBAAe,iBAAiB,CAAC"}
|
||||
69
node_modules/warehouse/dist/types/buffer.d.ts
generated
vendored
Normal file
69
node_modules/warehouse/dist/types/buffer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/// <reference types="node" />
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* Boolean schema type.
|
||||
*/
|
||||
declare class SchemaTypeBuffer extends SchemaType<Buffer> {
|
||||
options: SchemaType<Buffer>['options'] & {
|
||||
encoding: BufferEncoding;
|
||||
};
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {object} [options]
|
||||
* @param {boolean} [options.required=false]
|
||||
* @param {boolean|Function} [options.default]
|
||||
* @param {string} [options.encoding=hex]
|
||||
*/
|
||||
constructor(name: string, options?: Partial<SchemaType<Buffer>['options']> & {
|
||||
encoding?: BufferEncoding;
|
||||
});
|
||||
/**
|
||||
* Casts data.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Buffer}
|
||||
*/
|
||||
cast(value_: WithImplicitCoercion<Uint8Array | ReadonlyArray<number> | string>, data?: unknown): Buffer;
|
||||
cast(value_?: unknown, data?: unknown): Buffer | undefined;
|
||||
/**
|
||||
* Validates data.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Buffer}
|
||||
*/
|
||||
validate(value_: unknown, data?: unknown): Buffer;
|
||||
/**
|
||||
* Compares between two buffers.
|
||||
*
|
||||
* @param {Buffer} a
|
||||
* @param {Buffer} b
|
||||
* @return {Number}
|
||||
*/
|
||||
compare(a?: Buffer, b?: Buffer): number;
|
||||
/**
|
||||
* Parses data and transform them into buffer values.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {Boolean}
|
||||
*/
|
||||
parse(value: WithImplicitCoercion<Uint8Array | ReadonlyArray<number> | string>): Buffer;
|
||||
parse(value?: unknown): Buffer | null | undefined;
|
||||
/**
|
||||
* Transforms data into number to compress the size of database files.
|
||||
*
|
||||
* @param {Buffer} value
|
||||
* @return {String}
|
||||
*/
|
||||
value(value?: Buffer): string;
|
||||
/**
|
||||
* Checks the equality of data.
|
||||
*
|
||||
* @param {Buffer} value
|
||||
* @param {Buffer} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value: Buffer, query: Buffer): boolean;
|
||||
}
|
||||
export default SchemaTypeBuffer;
|
||||
87
node_modules/warehouse/dist/types/buffer.js
generated
vendored
Normal file
87
node_modules/warehouse/dist/types/buffer.js
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
/**
|
||||
* Boolean schema type.
|
||||
*/
|
||||
class SchemaTypeBuffer extends schematype_1.default {
|
||||
/**
|
||||
* @param {string} name
|
||||
* @param {object} [options]
|
||||
* @param {boolean} [options.required=false]
|
||||
* @param {boolean|Function} [options.default]
|
||||
* @param {string} [options.encoding=hex]
|
||||
*/
|
||||
constructor(name, options) {
|
||||
super(name, Object.assign({
|
||||
encoding: 'hex'
|
||||
}, options));
|
||||
}
|
||||
cast(value_, data) {
|
||||
const value = super.cast(value_, data);
|
||||
if (value == null || Buffer.isBuffer(value))
|
||||
return value;
|
||||
if (typeof value === 'string')
|
||||
return Buffer.from(value, this.options.encoding);
|
||||
if (Array.isArray(value))
|
||||
return Buffer.from(value);
|
||||
}
|
||||
/**
|
||||
* Validates data.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Buffer}
|
||||
*/
|
||||
validate(value_, data) {
|
||||
const value = super.validate(value_, data);
|
||||
if (!Buffer.isBuffer(value)) {
|
||||
throw new validation_1.default(`\`${value}\` is not a valid buffer!`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Compares between two buffers.
|
||||
*
|
||||
* @param {Buffer} a
|
||||
* @param {Buffer} b
|
||||
* @return {Number}
|
||||
*/
|
||||
compare(a, b) {
|
||||
if (Buffer.isBuffer(a)) {
|
||||
return Buffer.isBuffer(b) ? a.compare(b) : 1;
|
||||
}
|
||||
return Buffer.isBuffer(b) ? -1 : 0;
|
||||
}
|
||||
parse(value) {
|
||||
return value ? Buffer.from(value, this.options.encoding) : value;
|
||||
}
|
||||
/**
|
||||
* Transforms data into number to compress the size of database files.
|
||||
*
|
||||
* @param {Buffer} value
|
||||
* @return {String}
|
||||
*/
|
||||
value(value) {
|
||||
return Buffer.isBuffer(value) ? value.toString(this.options.encoding) : value;
|
||||
}
|
||||
/**
|
||||
* Checks the equality of data.
|
||||
*
|
||||
* @param {Buffer} value
|
||||
* @param {Buffer} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value, query) {
|
||||
if (Buffer.isBuffer(value) && Buffer.isBuffer(query)) {
|
||||
return value.equals(query);
|
||||
}
|
||||
return value === query;
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeBuffer;
|
||||
//# sourceMappingURL=buffer.js.map
|
||||
1
node_modules/warehouse/dist/types/buffer.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/buffer.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../src/types/buffer.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,qEAAkD;AAElD;;GAEG;AACH,MAAM,gBAAiB,SAAQ,oBAAkB;IAG/C;;;;;;OAMG;IACH,YAAY,IAAY,EAAE,OAAiF;QACzG,KAAK,CAA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CAAC,CAAC,CAAC;IACrC,CAAC;IAUD,KAAK,CAAC,KAAW;QACf,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACnE,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,KAAc;QAClB,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAChF,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAa,EAAE,KAAa;QAChC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,CAAC;QAED,OAAO,KAAK,KAAK,KAAK,CAAC;IACzB,CAAC;CACF;AAED,kBAAe,gBAAgB,CAAC"}
|
||||
22
node_modules/warehouse/dist/types/cuid.d.ts
generated
vendored
Normal file
22
node_modules/warehouse/dist/types/cuid.d.ts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* [CUID](https://github.com/ericelliott/cuid) schema type.
|
||||
*/
|
||||
declare class SchemaTypeCUID extends SchemaType<string> {
|
||||
/**
|
||||
* Casts data. Returns a new CUID only if value is null and the field is
|
||||
* required.
|
||||
*
|
||||
* @param {String} value
|
||||
* @return {String}
|
||||
*/
|
||||
cast(value?: string): string;
|
||||
/**
|
||||
* Validates data. A valid CUID must be started with `c` and 25 in length.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {String|Error}
|
||||
*/
|
||||
validate(value?: string): string;
|
||||
}
|
||||
export default SchemaTypeCUID;
|
||||
40
node_modules/warehouse/dist/types/cuid.js
generated
vendored
Normal file
40
node_modules/warehouse/dist/types/cuid.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const cuid_1 = __importDefault(require("cuid"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
/**
|
||||
* [CUID](https://github.com/ericelliott/cuid) schema type.
|
||||
*/
|
||||
class SchemaTypeCUID extends schematype_1.default {
|
||||
/**
|
||||
* Casts data. Returns a new CUID only if value is null and the field is
|
||||
* required.
|
||||
*
|
||||
* @param {String} value
|
||||
* @return {String}
|
||||
*/
|
||||
cast(value) {
|
||||
if (value == null && this.options.required) {
|
||||
return (0, cuid_1.default)();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Validates data. A valid CUID must be started with `c` and 25 in length.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {String|Error}
|
||||
*/
|
||||
validate(value) {
|
||||
if (value && (value[0] !== 'c' || value.length !== 25)) {
|
||||
throw new validation_1.default(`\`${value}\` is not a valid CUID`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeCUID;
|
||||
//# sourceMappingURL=cuid.js.map
|
||||
1
node_modules/warehouse/dist/types/cuid.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/cuid.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"cuid.js","sourceRoot":"","sources":["../../src/types/cuid.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,gDAAwB;AACxB,qEAAkD;AAElD;;GAEG;AACH,MAAM,cAAe,SAAQ,oBAAkB;IAE7C;;;;;;OAMG;IACH,IAAI,CAAC,KAAc;QACjB,IAAI,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YAC3C,OAAO,IAAA,cAAI,GAAE,CAAC;QAChB,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,KAAc;QACrB,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,oBAAe,CAAC,KAAK,KAAK,wBAAwB,CAAC,CAAC;QAChE,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,kBAAe,cAAc,CAAC"}
|
||||
95
node_modules/warehouse/dist/types/date.d.ts
generated
vendored
Normal file
95
node_modules/warehouse/dist/types/date.d.ts
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* Date schema type.
|
||||
*/
|
||||
declare class SchemaTypeDate extends SchemaType<Date> {
|
||||
/**
|
||||
* Casts data.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @return {Date | null | undefined}
|
||||
*/
|
||||
cast(value_: Date | number | string): Date;
|
||||
cast(value_?: unknown): Date | undefined;
|
||||
/**
|
||||
* Validates data.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Date|Error}
|
||||
*/
|
||||
validate(value_: unknown, data?: unknown): Date;
|
||||
/**
|
||||
* Checks the equality of data.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Date} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value: Date, query: Date): boolean;
|
||||
/**
|
||||
* Compares between two dates.
|
||||
*
|
||||
* @param {Date} a
|
||||
* @param {Date} b
|
||||
* @return {Number}
|
||||
*/
|
||||
compare(a?: Date, b?: Date): number;
|
||||
/**
|
||||
* Parses data and transforms it into a date object.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {Date}
|
||||
*/
|
||||
parse(value: string | number | Date): Date;
|
||||
parse(): undefined;
|
||||
/**
|
||||
* Transforms a date object to a string.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @return {String}
|
||||
*/
|
||||
value(value: Date): string;
|
||||
value(): undefined;
|
||||
/**
|
||||
* Finds data by its date.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$day(value: Date | undefined, query: number): boolean;
|
||||
/**
|
||||
* Finds data by its month. (Start from 0)
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$month(value: Date | undefined, query: number): boolean;
|
||||
/**
|
||||
* Finds data by its year. (4-digit)
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$year(value: Date | undefined, query: number): boolean;
|
||||
/**
|
||||
* Adds milliseconds to date.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} update
|
||||
* @return {Date}
|
||||
*/
|
||||
u$inc(value: Date | undefined, update: number): Date;
|
||||
/**
|
||||
* Subtracts milliseconds from date.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} update
|
||||
* @return {Date}
|
||||
*/
|
||||
u$dec(value: Date | undefined, update: number): Date;
|
||||
}
|
||||
export default SchemaTypeDate;
|
||||
119
node_modules/warehouse/dist/types/date.js
generated
vendored
Normal file
119
node_modules/warehouse/dist/types/date.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
/**
|
||||
* Date schema type.
|
||||
*/
|
||||
class SchemaTypeDate extends schematype_1.default {
|
||||
cast(value_) {
|
||||
const value = super.cast(value_, null);
|
||||
if (value == null || value instanceof Date)
|
||||
return value;
|
||||
return new Date(value);
|
||||
}
|
||||
/**
|
||||
* Validates data.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Date|Error}
|
||||
*/
|
||||
validate(value_, data) {
|
||||
const value = super.validate(value_, data);
|
||||
if (value != null && (!(value instanceof Date) || isNaN(value.getTime()))) {
|
||||
throw new validation_1.default(`\`${value}\` is not a valid date!`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Checks the equality of data.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Date} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value, query) {
|
||||
if (!value || !query) {
|
||||
return value === query;
|
||||
}
|
||||
return value.getTime() === query.getTime();
|
||||
}
|
||||
/**
|
||||
* Compares between two dates.
|
||||
*
|
||||
* @param {Date} a
|
||||
* @param {Date} b
|
||||
* @return {Number}
|
||||
*/
|
||||
compare(a, b) {
|
||||
if (a) {
|
||||
return b ? a.getTime() - b.getTime() : 1;
|
||||
}
|
||||
return b ? -1 : 0;
|
||||
}
|
||||
parse(value) {
|
||||
if (value)
|
||||
return new Date(value);
|
||||
}
|
||||
value(value) {
|
||||
return value ? value.toISOString() : value;
|
||||
}
|
||||
/**
|
||||
* Finds data by its date.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$day(value, query) {
|
||||
return value ? value.getDate() === query : false;
|
||||
}
|
||||
/**
|
||||
* Finds data by its month. (Start from 0)
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$month(value, query) {
|
||||
return value ? value.getMonth() === query : false;
|
||||
}
|
||||
/**
|
||||
* Finds data by its year. (4-digit)
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$year(value, query) {
|
||||
return value ? value.getFullYear() === query : false;
|
||||
}
|
||||
/**
|
||||
* Adds milliseconds to date.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} update
|
||||
* @return {Date}
|
||||
*/
|
||||
u$inc(value, update) {
|
||||
if (value)
|
||||
return new Date(value.getTime() + update);
|
||||
}
|
||||
/**
|
||||
* Subtracts milliseconds from date.
|
||||
*
|
||||
* @param {Date} value
|
||||
* @param {Number} update
|
||||
* @return {Date}
|
||||
*/
|
||||
u$dec(value, update) {
|
||||
if (value)
|
||||
return new Date(value.getTime() - update);
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeDate;
|
||||
//# sourceMappingURL=date.js.map
|
||||
1
node_modules/warehouse/dist/types/date.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/date.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/types/date.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,qEAAkD;AAElD;;GAEG;AACH,MAAM,cAAe,SAAQ,oBAAgB;IAU3C,IAAI,CAAC,MAAgB;QACnB,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEvC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,YAAY,IAAI;YAAE,OAAO,KAAyB,CAAC;QAE7E,OAAO,IAAI,IAAI,CAAC,KAAY,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,MAAe,EAAE,IAAc;QACtC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAE3C,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,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;IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAuB,EAAE,KAAa;QAC3C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IACvD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAuB,EAAE,MAAc;QAC3C,IAAI,KAAK;YAAE,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;IACvD,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAuB,EAAE,MAAc;QAC3C,IAAI,KAAK;YAAE,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;IACvD,CAAC;CACF;AAED,kBAAe,cAAc,CAAC"}
|
||||
29
node_modules/warehouse/dist/types/enum.d.ts
generated
vendored
Normal file
29
node_modules/warehouse/dist/types/enum.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* Enum schema type.
|
||||
*/
|
||||
declare class SchemaTypeEnum extends SchemaType<any[]> {
|
||||
options: SchemaType<any[]>['options'] & {
|
||||
elements: any[];
|
||||
};
|
||||
/**
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} options
|
||||
* @param {Boolean} [options.required=false]
|
||||
* @param {Array} options.elements
|
||||
* @param {*} [options.default]
|
||||
*/
|
||||
constructor(name: string, options?: Partial<SchemaType<any[]>['options']> & {
|
||||
elements?: any[];
|
||||
});
|
||||
/**
|
||||
* Validates data. The value must be one of elements set in the options.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
validate(value_: unknown, data?: unknown): unknown;
|
||||
}
|
||||
export default SchemaTypeEnum;
|
||||
42
node_modules/warehouse/dist/types/enum.js
generated
vendored
Normal file
42
node_modules/warehouse/dist/types/enum.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
/**
|
||||
* Enum schema type.
|
||||
*/
|
||||
class SchemaTypeEnum extends schematype_1.default {
|
||||
/**
|
||||
*
|
||||
* @param {String} name
|
||||
* @param {Object} options
|
||||
* @param {Boolean} [options.required=false]
|
||||
* @param {Array} options.elements
|
||||
* @param {*} [options.default]
|
||||
*/
|
||||
constructor(name, options) {
|
||||
super(name, Object.assign({
|
||||
elements: []
|
||||
}, options));
|
||||
}
|
||||
/**
|
||||
* Validates data. The value must be one of elements set in the options.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
validate(value_, data) {
|
||||
const value = super.validate(value_, data);
|
||||
const elements = this.options.elements;
|
||||
if (!elements.includes(value)) {
|
||||
throw new validation_1.default(`The value must be one of ${elements.join(', ')}`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeEnum;
|
||||
//# sourceMappingURL=enum.js.map
|
||||
1
node_modules/warehouse/dist/types/enum.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/enum.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"enum.js","sourceRoot":"","sources":["../../src/types/enum.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,qEAAkD;AAElD;;GAEG;AACH,MAAM,cAAe,SAAQ,oBAAiB;IAG5C;;;;;;;OAOG;IACH,YAAY,IAAY,EAAE,OAAsE;QAC9F,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC;YACxB,QAAQ,EAAE,EAAE;SACb,EAAE,OAAO,CAAC,CAAC,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,MAAe,EAAE,IAAc;QACtC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QAEvC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,oBAAe,CAAC,4BAA4B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC/E,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,kBAAe,cAAc,CAAC"}
|
||||
13
node_modules/warehouse/dist/types/index.d.ts
generated
vendored
Normal file
13
node_modules/warehouse/dist/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import SchemaType from '../schematype';
|
||||
import SchemaTypeString from './string';
|
||||
import SchemaTypeNumber from './number';
|
||||
import SchemaTypeBoolean from './boolean';
|
||||
import SchemaTypeArray from './array';
|
||||
import SchemaTypeObject from './object';
|
||||
import SchemaTypeDate from './date';
|
||||
import SchemaTypeVirtual from './virtual';
|
||||
import SchemaTypeCUID from './cuid';
|
||||
import SchemaTypeEnum from './enum';
|
||||
import SchemaTypeInteger from './integer';
|
||||
import SchemaTypeBuffer from './buffer';
|
||||
export { SchemaType as Mixed, SchemaTypeString as String, SchemaTypeNumber as Number, SchemaTypeBoolean as Boolean, SchemaTypeArray as Array, SchemaTypeObject as Object, SchemaTypeDate as Date, SchemaTypeVirtual as Virtual, SchemaTypeCUID as CUID, SchemaTypeEnum as Enum, SchemaTypeInteger as Integer, SchemaTypeBuffer as Buffer };
|
||||
31
node_modules/warehouse/dist/types/index.js
generated
vendored
Normal file
31
node_modules/warehouse/dist/types/index.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Buffer = exports.Integer = exports.Enum = exports.CUID = exports.Virtual = exports.Date = exports.Object = exports.Array = exports.Boolean = exports.Number = exports.String = exports.Mixed = void 0;
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
exports.Mixed = schematype_1.default;
|
||||
const string_1 = __importDefault(require("./string"));
|
||||
exports.String = string_1.default;
|
||||
const number_1 = __importDefault(require("./number"));
|
||||
exports.Number = number_1.default;
|
||||
const boolean_1 = __importDefault(require("./boolean"));
|
||||
exports.Boolean = boolean_1.default;
|
||||
const array_1 = __importDefault(require("./array"));
|
||||
exports.Array = array_1.default;
|
||||
const object_1 = __importDefault(require("./object"));
|
||||
exports.Object = object_1.default;
|
||||
const date_1 = __importDefault(require("./date"));
|
||||
exports.Date = date_1.default;
|
||||
const virtual_1 = __importDefault(require("./virtual"));
|
||||
exports.Virtual = virtual_1.default;
|
||||
const cuid_1 = __importDefault(require("./cuid"));
|
||||
exports.CUID = cuid_1.default;
|
||||
const enum_1 = __importDefault(require("./enum"));
|
||||
exports.Enum = enum_1.default;
|
||||
const integer_1 = __importDefault(require("./integer"));
|
||||
exports.Integer = integer_1.default;
|
||||
const buffer_1 = __importDefault(require("./buffer"));
|
||||
exports.Buffer = buffer_1.default;
|
||||
//# sourceMappingURL=index.js.map
|
||||
1
node_modules/warehouse/dist/types/index.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/index.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;AAAA,+DAAuC;AAcvB,gBAdT,oBAAU,CAcI;AAbrB,sDAAwC;AAclB,iBAdf,gBAAgB,CAcK;AAb5B,sDAAwC;AAclB,iBAdf,gBAAgB,CAcK;AAb5B,wDAA0C;AAcnB,kBAdhB,iBAAiB,CAcM;AAb9B,oDAAsC;AAcjB,gBAdd,eAAe,CAcI;AAb1B,sDAAwC;AAclB,iBAdf,gBAAgB,CAcK;AAb5B,kDAAoC;AAchB,eAdb,cAAc,CAcG;AAbxB,wDAA0C;AAcnB,kBAdhB,iBAAiB,CAcM;AAb9B,kDAAoC;AAchB,eAdb,cAAc,CAcG;AAbxB,kDAAoC;AAchB,eAdb,cAAc,CAcG;AAbxB,wDAA0C;AAcnB,kBAdhB,iBAAiB,CAcM;AAb9B,sDAAwC;AAclB,iBAdf,gBAAgB,CAcK"}
|
||||
23
node_modules/warehouse/dist/types/integer.d.ts
generated
vendored
Normal file
23
node_modules/warehouse/dist/types/integer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import SchemaTypeNumber from './number';
|
||||
/**
|
||||
* Integer schema type.
|
||||
*/
|
||||
declare class SchemaTypeInteger extends SchemaTypeNumber {
|
||||
/**
|
||||
* Casts a integer.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Number}
|
||||
*/
|
||||
cast(value_?: unknown, data?: unknown): number;
|
||||
/**
|
||||
* Validates an integer.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Number|Error}
|
||||
*/
|
||||
validate(value_?: unknown, data?: unknown): number;
|
||||
}
|
||||
export default SchemaTypeInteger;
|
||||
39
node_modules/warehouse/dist/types/integer.js
generated
vendored
Normal file
39
node_modules/warehouse/dist/types/integer.js
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const number_1 = __importDefault(require("./number"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
/**
|
||||
* Integer schema type.
|
||||
*/
|
||||
class SchemaTypeInteger extends number_1.default {
|
||||
/**
|
||||
* Casts a integer.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Number}
|
||||
*/
|
||||
cast(value_, data) {
|
||||
const value = super.cast(value_, data);
|
||||
return parseInt(value, 10);
|
||||
}
|
||||
/**
|
||||
* Validates an integer.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {Number|Error}
|
||||
*/
|
||||
validate(value_, data) {
|
||||
const value = super.validate(value_, data);
|
||||
if (!Number.isInteger(value)) {
|
||||
throw new validation_1.default(`\`${value}\` is not an integer!`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeInteger;
|
||||
//# sourceMappingURL=integer.js.map
|
||||
1
node_modules/warehouse/dist/types/integer.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/integer.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"integer.js","sourceRoot":"","sources":["../../src/types/integer.ts"],"names":[],"mappings":";;;;;AAAA,sDAAwC;AACxC,qEAAkD;AAElD;;GAEG;AACH,MAAM,iBAAkB,SAAQ,gBAAgB;IAE9C;;;;;;OAMG;IACH,IAAI,CAAC,MAAgB,EAAE,IAAc;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEvC,OAAO,QAAQ,CAAC,KAAY,EAAE,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,MAAgB,EAAE,IAAc;QACvC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAE3C,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,oBAAe,CAAC,KAAK,KAAK,uBAAuB,CAAC,CAAC;QAC/D,CAAC;QAED,OAAO,KAAe,CAAC;IACzB,CAAC;CACF;AAED,kBAAe,iBAAiB,CAAC"}
|
||||
80
node_modules/warehouse/dist/types/number.d.ts
generated
vendored
Normal file
80
node_modules/warehouse/dist/types/number.d.ts
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* Number schema type.
|
||||
*/
|
||||
declare class SchemaTypeNumber extends SchemaType<number> {
|
||||
/**
|
||||
* Casts a number.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {Number}
|
||||
*/
|
||||
cast(value_: Exclude<unknown, undefined | null>, data?: unknown): number;
|
||||
cast(value_?: unknown, data?: unknown): number | undefined;
|
||||
/**
|
||||
* Validates a number.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {Number|Error}
|
||||
*/
|
||||
validate(value_?: unknown, data?: unknown): number;
|
||||
/**
|
||||
* Adds value to a number.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$inc(value: number | undefined, update: number): number;
|
||||
/**
|
||||
* Subtracts value from a number.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$dec(value: number | undefined, update: number): number;
|
||||
/**
|
||||
* Multiplies value to a number.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$mul(value: number | undefined, update: number): number;
|
||||
/**
|
||||
* Divides a number by a value.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$div(value: number | undefined, update: number): number;
|
||||
/**
|
||||
* Divides a number by a value and returns the remainder.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$mod(value: number | undefined, update: number): number;
|
||||
/**
|
||||
* Updates a number if the value is greater than the current value.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$max(value: number | undefined, update: number): number;
|
||||
/**
|
||||
* Updates a number if the value is less than the current value.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$min(value: number | undefined, update: number): number;
|
||||
}
|
||||
export default SchemaTypeNumber;
|
||||
104
node_modules/warehouse/dist/types/number.js
generated
vendored
Normal file
104
node_modules/warehouse/dist/types/number.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
/**
|
||||
* Number schema type.
|
||||
*/
|
||||
class SchemaTypeNumber extends schematype_1.default {
|
||||
cast(value_, data) {
|
||||
const value = super.cast(value_, data);
|
||||
if (value == null || typeof value === 'number')
|
||||
return value;
|
||||
return +value;
|
||||
}
|
||||
/**
|
||||
* Validates a number.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {Number|Error}
|
||||
*/
|
||||
validate(value_, data) {
|
||||
const value = super.validate(value_, data);
|
||||
if (value !== undefined && (typeof value !== 'number' || isNaN(value))) {
|
||||
throw new validation_1.default(`\`${value}\` is not a number!`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Adds value to a number.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$inc(value, update) {
|
||||
return value ? value + update : update;
|
||||
}
|
||||
/**
|
||||
* Subtracts value from a number.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$dec(value, update) {
|
||||
return value ? value - update : -update;
|
||||
}
|
||||
/**
|
||||
* Multiplies value to a number.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$mul(value, update) {
|
||||
return value ? value * update : 0;
|
||||
}
|
||||
/**
|
||||
* Divides a number by a value.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$div(value, update) {
|
||||
return value ? value / update : 0;
|
||||
}
|
||||
/**
|
||||
* Divides a number by a value and returns the remainder.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$mod(value, update) {
|
||||
return value ? value % update : 0;
|
||||
}
|
||||
/**
|
||||
* Updates a number if the value is greater than the current value.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$max(value, update) {
|
||||
return update > value ? update : value;
|
||||
}
|
||||
/**
|
||||
* Updates a number if the value is less than the current value.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {Number} update
|
||||
* @return {Number}
|
||||
*/
|
||||
u$min(value, update) {
|
||||
return update < value ? update : value;
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeNumber;
|
||||
//# sourceMappingURL=number.js.map
|
||||
1
node_modules/warehouse/dist/types/number.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/number.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../src/types/number.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,qEAAkD;AAElD;;GAEG;AACH,MAAM,gBAAiB,SAAQ,oBAAkB;IAW/C,IAAI,CAAC,MAAgB,EAAE,IAAc;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEvC,IAAI,KAAK,IAAI,IAAI,IAAI,OAAO,KAAK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CAAC,KAAyB,EAAE,MAAc;QAC7C,OAAO,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACzC,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAyB,EAAE,MAAc;QAC7C,OAAO,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;IACzC,CAAC;CACF;AAED,kBAAe,gBAAgB,CAAC"}
|
||||
15
node_modules/warehouse/dist/types/object.d.ts
generated
vendored
Normal file
15
node_modules/warehouse/dist/types/object.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* Object schema type.
|
||||
*/
|
||||
declare class SchemaTypeObject extends SchemaType<Record<string, any>> {
|
||||
/**
|
||||
*
|
||||
* @param {String} [name]
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.required=false]
|
||||
* @param {Object|Function} [options.default={}]
|
||||
*/
|
||||
constructor(name?: string, options?: Partial<SchemaType<Record<string, any>>['options']>);
|
||||
}
|
||||
export default SchemaTypeObject;
|
||||
23
node_modules/warehouse/dist/types/object.js
generated
vendored
Normal file
23
node_modules/warehouse/dist/types/object.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
/**
|
||||
* Object schema type.
|
||||
*/
|
||||
class SchemaTypeObject extends schematype_1.default {
|
||||
/**
|
||||
*
|
||||
* @param {String} [name]
|
||||
* @param {Object} [options]
|
||||
* @param {Boolean} [options.required=false]
|
||||
* @param {Object|Function} [options.default={}]
|
||||
*/
|
||||
constructor(name, options) {
|
||||
super(name, Object.assign({ default: {} }, options));
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeObject;
|
||||
//# sourceMappingURL=object.js.map
|
||||
1
node_modules/warehouse/dist/types/object.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/object.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"object.js","sourceRoot":"","sources":["../../src/types/object.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AAEvC;;GAEG;AACH,MAAM,gBAAiB,SAAQ,oBAA+B;IAE5D;;;;;;OAMG;IACH,YAAY,IAAa,EAAE,OAA6D;QACtF,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IACvD,CAAC;CACF;AAED,kBAAe,gBAAgB,CAAC"}
|
||||
61
node_modules/warehouse/dist/types/string.d.ts
generated
vendored
Normal file
61
node_modules/warehouse/dist/types/string.d.ts
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* String schema type.
|
||||
*/
|
||||
declare class SchemaTypeString extends SchemaType<string> {
|
||||
/**
|
||||
* Casts a string.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {String}
|
||||
*/
|
||||
cast(value_: {
|
||||
toString(): string;
|
||||
}, data?: unknown): string;
|
||||
cast(value_?: unknown, data?: unknown): string | undefined;
|
||||
/**
|
||||
* Validates a string.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {String|Error}
|
||||
*/
|
||||
validate(value_?: unknown, data?: unknown): string;
|
||||
/**
|
||||
* Checks the equality of data.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {String|RegExp} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value: string | undefined, query: string | RegExp | undefined, data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether a string is equal to one of elements in `query`.
|
||||
*
|
||||
* @param {String} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$in(value: string | undefined, query: string[] | RegExp[], data?: unknown): boolean;
|
||||
/**
|
||||
* Checks whether a string is not equal to any elements in `query`.
|
||||
*
|
||||
* @param {String} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$nin(value: string | undefined, query: string[] | RegExp[], data?: unknown): boolean;
|
||||
/**
|
||||
* Checks length of a string.
|
||||
*
|
||||
* @param {String} value
|
||||
* @param {Number} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$length(value: string | undefined, query: number): boolean;
|
||||
}
|
||||
export default SchemaTypeString;
|
||||
88
node_modules/warehouse/dist/types/string.js
generated
vendored
Normal file
88
node_modules/warehouse/dist/types/string.js
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const validation_1 = __importDefault(require("../error/validation"));
|
||||
/**
|
||||
* String schema type.
|
||||
*/
|
||||
class SchemaTypeString extends schematype_1.default {
|
||||
cast(value_, data) {
|
||||
const value = super.cast(value_, data);
|
||||
if (value == null || typeof value === 'string')
|
||||
return value;
|
||||
if (typeof value.toString === 'function')
|
||||
return value.toString();
|
||||
}
|
||||
/**
|
||||
* Validates a string.
|
||||
*
|
||||
* @param {*} value_
|
||||
* @param {Object} data
|
||||
* @return {String|Error}
|
||||
*/
|
||||
validate(value_, data) {
|
||||
const value = super.validate(value_, data);
|
||||
if (value !== undefined && typeof value !== 'string') {
|
||||
throw new validation_1.default(`\`${value}\` is not a string!`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Checks the equality of data.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {String|RegExp} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
match(value, query, data) {
|
||||
if (!value || !query) {
|
||||
return value === query;
|
||||
}
|
||||
if (typeof query.test === 'function') {
|
||||
return query.test(value);
|
||||
}
|
||||
return value === query;
|
||||
}
|
||||
/**
|
||||
* Checks whether a string is equal to one of elements in `query`.
|
||||
*
|
||||
* @param {String} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$in(value, query, data) {
|
||||
for (let i = 0, len = query.length; i < len; i++) {
|
||||
if (this.match(value, query[i], data))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Checks whether a string is not equal to any elements in `query`.
|
||||
*
|
||||
* @param {String} value
|
||||
* @param {Array} query
|
||||
* @param {Object} data
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$nin(value, query, data) {
|
||||
return !this.q$in(value, query, data);
|
||||
}
|
||||
/**
|
||||
* Checks length of a string.
|
||||
*
|
||||
* @param {String} value
|
||||
* @param {Number} query
|
||||
* @return {Boolean}
|
||||
*/
|
||||
q$length(value, query) {
|
||||
return (value ? value.length : 0) === query;
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeString;
|
||||
//# sourceMappingURL=string.js.map
|
||||
1
node_modules/warehouse/dist/types/string.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/string.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/types/string.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,qEAAkD;AAElD;;GAEG;AACH,MAAM,gBAAiB,SAAQ,oBAAkB;IAW/C,IAAI,CAAC,MAAgB,EAAE,IAAc;QACnC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAEvC,IAAI,KAAK,IAAI,IAA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KAA0B,EAAE,IAAc;QACzE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,KAAyB,EAAE,KAAa;QAC/C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC;IAC9C,CAAC;CACF;AAED,kBAAe,gBAAgB,CAAC"}
|
||||
38
node_modules/warehouse/dist/types/virtual.d.ts
generated
vendored
Normal file
38
node_modules/warehouse/dist/types/virtual.d.ts
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
import SchemaType from '../schematype';
|
||||
/**
|
||||
* Virtual schema type.
|
||||
*/
|
||||
declare class SchemaTypeVirtual extends SchemaType<any> {
|
||||
getter: (() => any) | undefined;
|
||||
setter: ((value: any) => void) | undefined;
|
||||
/**
|
||||
* Add a getter.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @chainable
|
||||
*/
|
||||
get(fn: () => any): SchemaTypeVirtual;
|
||||
/**
|
||||
* Add a setter.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @chainable
|
||||
*/
|
||||
set(fn: (value: any) => void): SchemaTypeVirtual;
|
||||
/**
|
||||
* Applies getters.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
cast(value: unknown, data: any): void;
|
||||
/**
|
||||
* Applies setters.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
*/
|
||||
validate(value: any, data: any): void;
|
||||
}
|
||||
export default SchemaTypeVirtual;
|
||||
72
node_modules/warehouse/dist/types/virtual.js
generated
vendored
Normal file
72
node_modules/warehouse/dist/types/virtual.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const schematype_1 = __importDefault(require("../schematype"));
|
||||
const util_1 = require("../util");
|
||||
/**
|
||||
* Virtual schema type.
|
||||
*/
|
||||
class SchemaTypeVirtual extends schematype_1.default {
|
||||
/**
|
||||
* Add a getter.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @chainable
|
||||
*/
|
||||
get(fn) {
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Getter must be a function!');
|
||||
}
|
||||
this.getter = fn;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Add a setter.
|
||||
*
|
||||
* @param {Function} fn
|
||||
* @chainable
|
||||
*/
|
||||
set(fn) {
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('Setter must be a function!');
|
||||
}
|
||||
this.setter = fn;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Applies getters.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
* @return {*}
|
||||
*/
|
||||
cast(value, data) {
|
||||
if (typeof this.getter !== 'function')
|
||||
return;
|
||||
const getter = this.getter;
|
||||
let hasCache = false;
|
||||
let cache;
|
||||
(0, util_1.setGetter)(data, this.name, () => {
|
||||
if (!hasCache) {
|
||||
cache = getter.call(data);
|
||||
hasCache = true;
|
||||
}
|
||||
return cache;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Applies setters.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {Object} data
|
||||
*/
|
||||
validate(value, data) {
|
||||
if (typeof this.setter === 'function') {
|
||||
this.setter.call(data, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.default = SchemaTypeVirtual;
|
||||
//# sourceMappingURL=virtual.js.map
|
||||
1
node_modules/warehouse/dist/types/virtual.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/types/virtual.js.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"virtual.js","s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,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;CACF;AAED,kBAAe,iBAAiB,CAAC"}
|
||||
8
node_modules/warehouse/dist/util.d.ts
generated
vendored
Normal file
8
node_modules/warehouse/dist/util.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export declare function shuffle(array: any): any[];
|
||||
export declare function getProp(obj: any, key: any): any;
|
||||
export declare function setProp(obj: any, key: any, value: any): void;
|
||||
export declare function delProp(obj: any, key: any): void;
|
||||
export declare function setGetter(obj: any, key: any, fn: any): void;
|
||||
export declare function arr2obj(arr: any, value: any): {};
|
||||
export declare function reverse(arr: any): any[];
|
||||
export declare function parseArgs(orderby: string | object, order?: string | number | object): any;
|
||||
170
node_modules/warehouse/dist/util.js
generated
vendored
Normal file
170
node_modules/warehouse/dist/util.js
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseArgs = exports.reverse = exports.arr2obj = exports.setGetter = exports.delProp = exports.setProp = exports.getProp = exports.shuffle = void 0;
|
||||
function extractPropKey(key) {
|
||||
return key.split('.');
|
||||
}
|
||||
function _parseArgs(args) {
|
||||
if (typeof args !== 'string')
|
||||
return args;
|
||||
const arr = args.split(' ');
|
||||
const result = {};
|
||||
for (let i = 0, len = arr.length; i < len; i++) {
|
||||
const key = arr[i];
|
||||
switch (key[0]) {
|
||||
case '+':
|
||||
result[key.slice(1)] = 1;
|
||||
break;
|
||||
case '-':
|
||||
result[key.slice(1)] = -1;
|
||||
break;
|
||||
default:
|
||||
result[key] = 1;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function shuffle(array) {
|
||||
if (!Array.isArray(array))
|
||||
throw new TypeError('array must be an Array!');
|
||||
const $array = array.slice();
|
||||
const { length } = $array;
|
||||
const { random, floor } = Math;
|
||||
for (let i = 0; i < length; i++) {
|
||||
// @see https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L6718
|
||||
// @see https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L3884
|
||||
const rand = i + floor(random() * (length - i));
|
||||
const temp = $array[i];
|
||||
$array[i] = $array[rand];
|
||||
$array[rand] = temp;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
exports.shuffle = shuffle;
|
||||
function getProp(obj, key) {
|
||||
if (typeof obj !== 'object')
|
||||
throw new TypeError('obj must be an object!');
|
||||
if (!key)
|
||||
throw new TypeError('key is required!');
|
||||
if (!key.includes('.')) {
|
||||
return obj[key];
|
||||
}
|
||||
const token = extractPropKey(key);
|
||||
let result = obj;
|
||||
const len = token.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
result = result[token[i]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.getProp = getProp;
|
||||
function setProp(obj, key, value) {
|
||||
if (typeof obj !== 'object')
|
||||
throw new TypeError('obj must be an object!');
|
||||
if (!key)
|
||||
throw new TypeError('key is required!');
|
||||
if (!key.includes('.')) {
|
||||
obj[key] = value;
|
||||
return;
|
||||
}
|
||||
const token = extractPropKey(key);
|
||||
const lastKey = token.pop();
|
||||
const len = token.length;
|
||||
let cursor = obj;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const name = token[i];
|
||||
cursor[name] = cursor[name] || {};
|
||||
cursor = cursor[name];
|
||||
}
|
||||
cursor[lastKey] = value;
|
||||
}
|
||||
exports.setProp = setProp;
|
||||
function delProp(obj, key) {
|
||||
if (typeof obj !== 'object')
|
||||
throw new TypeError('obj must be an object!');
|
||||
if (!key)
|
||||
throw new TypeError('key is required!');
|
||||
if (!key.includes('.')) {
|
||||
delete obj[key];
|
||||
return;
|
||||
}
|
||||
const token = extractPropKey(key);
|
||||
const lastKey = token.pop();
|
||||
const len = token.length;
|
||||
let cursor = obj;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const name = token[i];
|
||||
if (cursor[name]) {
|
||||
cursor = cursor[name];
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
delete cursor[lastKey];
|
||||
}
|
||||
exports.delProp = delProp;
|
||||
function setGetter(obj, key, fn) {
|
||||
if (typeof obj !== 'object')
|
||||
throw new TypeError('obj must be an object!');
|
||||
if (!key)
|
||||
throw new TypeError('key is required!');
|
||||
if (typeof fn !== 'function')
|
||||
throw new TypeError('fn must be a function!');
|
||||
if (!key.includes('.')) {
|
||||
obj.__defineGetter__(key, fn);
|
||||
return;
|
||||
}
|
||||
const token = extractPropKey(key);
|
||||
const lastKey = token.pop();
|
||||
const len = token.length;
|
||||
let cursor = obj;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const name = token[i];
|
||||
cursor[name] = cursor[name] || {};
|
||||
cursor = cursor[name];
|
||||
}
|
||||
cursor.__defineGetter__(lastKey, fn);
|
||||
}
|
||||
exports.setGetter = setGetter;
|
||||
function arr2obj(arr, value) {
|
||||
if (!Array.isArray(arr))
|
||||
throw new TypeError('arr must be an array!');
|
||||
const obj = {};
|
||||
let i = arr.length;
|
||||
while (i--) {
|
||||
obj[arr[i]] = value;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
exports.arr2obj = arr2obj;
|
||||
function reverse(arr) {
|
||||
if (!Array.isArray(arr))
|
||||
throw new TypeError('arr must be an array!');
|
||||
const len = arr.length;
|
||||
if (!len)
|
||||
return arr;
|
||||
for (let left = 0, right = len - 1; left < right; left++, right--) {
|
||||
const tmp = arr[left];
|
||||
arr[left] = arr[right];
|
||||
arr[right] = tmp;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
exports.reverse = reverse;
|
||||
function parseArgs(orderby, order) {
|
||||
let result;
|
||||
if (order) {
|
||||
result = {};
|
||||
result[orderby] = order;
|
||||
}
|
||||
else if (typeof orderby === 'string') {
|
||||
result = _parseArgs(orderby);
|
||||
}
|
||||
else {
|
||||
result = orderby;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
exports.parseArgs = parseArgs;
|
||||
//# sourceMappingURL=util.js.map
|
||||
1
node_modules/warehouse/dist/util.js.map
generated
vendored
Normal file
1
node_modules/warehouse/dist/util.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user