Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mvom

Package Overview
Dependencies
Maintainers
3
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mvom - npm Package Compare versions

Comparing version 0.9.3 to 0.9.4

6

CHANGELOG.md
# CHANGELOG.md
## 0.9.4
###### _2021_06_30_
- Update all dependencies. @shawnmcknight
- Format the ISOCalendarDateTime type to have the time component left padded with zeroes.
## 0.9.3

@@ -3,0 +9,0 @@ ###### _2021_05_07_

4

js/index.js

@@ -38,5 +38,5 @@ "use strict";

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

@@ -43,0 +43,0 @@ /**

@@ -14,5 +14,5 @@ "use strict";

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

@@ -19,0 +19,0 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

@@ -39,6 +39,6 @@ "use strict";

return (0, _lodash.compact)((0, _lodash.flatten)((await Promise.all(this._validators.map(async ({
return (0, _lodash.compact)((0, _lodash.flatten)(await Promise.all(this._validators.map(async ({
validator,
message
}) => !(await validator(castValue, document)) && message).concat(castValue.map(async arrayItem => this._valueSchemaType.validate(arrayItem, document)))))));
}) => !(await validator(castValue, document)) && message).concat(castValue.map(async arrayItem => this._valueSchemaType.validate(arrayItem, document))))));
});

@@ -45,0 +45,0 @@ }

@@ -36,9 +36,2 @@ "use strict";

_defineProperty(this, "validate", async () => {
throw new _errors.NotImplementedError({
methodName: 'validate',
className: this.constructor.name
});
});
if (new.target === BaseType) {

@@ -71,2 +64,20 @@ // disallow direct instantiation

/**
* Validate value
* @function validate
* @memberof BaseType
* @abstract
* @instance
* @async
* @param {*} value - Value to verify
* @param {Object} document - Document instance
* @throws {NotImplementedError} Thrown if called directly
*/
async validate() {
throw new _errors.NotImplementedError({
methodName: 'validate',
className: this.constructor.name
});
}
}

@@ -73,0 +84,0 @@

@@ -81,6 +81,6 @@ "use strict";

// - compact the array of resolved promises to remove any falsy values
(0, _lodash.compact)((await Promise.all(documentList.map(async document => {
(0, _lodash.compact)(await Promise.all(documentList.map(async document => {
const documentErrors = await document.validate();
return Object.keys(documentErrors).length && documentErrors;
})))));
}))));

@@ -87,0 +87,0 @@ this._valueSchema = valueSchema;

@@ -42,26 +42,2 @@ "use strict";

_defineProperty(this, "transformFromDb", value => {
if (value == null) {
return null;
}
const valueParts = String(value).split('.');
const datePart = new _ISOCalendarDateType.default({}).transformFromDb(+valueParts[0]);
const timePart = new _ISOTimeType.default({
dbFormat: this._dbFormat
}).transformFromDb(+valueParts[1]);
return `${datePart}T${timePart}`;
});
_defineProperty(this, "transformToDb", value => {
if (value == null) {
return null;
}
const [datePart, timePart] = value.split('T');
return `${new _ISOCalendarDateType.default({}).transformToDb(datePart)}.${new _ISOTimeType.default({
dbFormat: this._dbFormat
}).transformToDb(timePart)}`;
});
_defineProperty(this, "_validateType", async value => {

@@ -119,2 +95,51 @@ if (value == null) {

transformFromDb(value) {
if (value == null) {
return null;
}
const valueParts = String(value).split('.');
const datePart = new _ISOCalendarDateType.default({}).transformFromDb(+valueParts[0]);
const timePart = new _ISOTimeType.default({
dbFormat: this._dbFormat
}).transformFromDb(+valueParts[1]);
return `${datePart}T${timePart}`;
}
/**
* Transform ISO 8601 approved date/time format (yyyy-mm-ddTHH:mm:ss.SSS) to mv style timestamp data (ddddd.sssss[SSS])
* @function transformToDb
* @memberof ISOCalendarDateTimeType
* @instance
* @public
* @override
* @param {string|null} value - Value to transform
* @returns {string|null} Transformed mv style timestamp value (ddddd.sssss[SSS])
*/
transformToDb(value) {
if (value == null) {
return null;
}
const [datePart, timePart] = value.split('T');
const padLength = this._dbFormat === 'ms' ? 8 : 5;
return `${new _ISOCalendarDateType.default({}).transformToDb(datePart)}.${new _ISOTimeType.default({
dbFormat: this._dbFormat
}).transformToDb(timePart).padStart(padLength, '0')}`;
}
/* private instance methods */
/**
* ISOCalendarDateTime data type validator
* @function _validateType
* @memberof ISOCalendarDateTimeType
* @instance
* @private
* @async
* @param {*[]} value - Value to validate for data type casting
* @returns {Promise.<Boolean>} True if valid / false if invalid
*/
}

@@ -121,0 +146,0 @@

@@ -20,4 +20,2 @@ "use strict";

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**

@@ -37,23 +35,2 @@ * An ISOCalendarDate Schema Type

_defineProperty(this, "transformFromDb", value => {
if (value == null) {
return null;
}
const castValue = +value;
if (!Number.isInteger(castValue)) {
throw new _errors.TransformDataError({
transformClass: this.constructor.name,
transformValue: castValue
});
}
return (0, _moment.default)(_constants.mvEpoch).add(castValue, 'days').format(_constants.ISOCalendarDateFormat);
});
_defineProperty(this, "transformToDb", value => value == null ? null : String((0, _moment.default)(value).diff((0, _moment.default)(_constants.mvEpoch), 'days')));
_defineProperty(this, "_validateType", async value => value == null || (0, _moment.default)(value, _constants.ISOCalendarDateFormat).isValid());
this._validators.unshift((0, _utils.handleTypeValidation)(this._validateType));

@@ -76,2 +53,51 @@ }

transformFromDb(value) {
if (value == null) {
return null;
}
const castValue = +value;
if (!Number.isInteger(castValue)) {
throw new _errors.TransformDataError({
transformClass: this.constructor.name,
transformValue: castValue
});
}
return (0, _moment.default)(_constants.mvEpoch).add(castValue, 'days').format(_constants.ISOCalendarDateFormat);
}
/**
* Transform ISO 8601 approved date format (yyyy-mm-dd) to mv date data
* @function transformToDb
* @memberof ISOCalendarDateType
* @instance
* @public
* @override
* @param {string|null} value - Value to transform
* @returns {string|null} Transformed string integer representing number of days since mv epoch
*/
transformToDb(value) {
return value == null ? null : String((0, _moment.default)(value).diff((0, _moment.default)(_constants.mvEpoch), 'days'));
}
/* private instance methods */
/**
* ISOCalendarDateType data type validator
* @function _validateType
* @memberof ISOCalendarDateType
* @instance
* @private
* @async
* @param {*[]} value - Value to validate for data type casting
* @returns {Promise.<Boolean>} True if valid / false if invalid
*/
async _validateType(value) {
return value == null || (0, _moment.default)(value, _constants.ISOCalendarDateFormat).isValid();
}
}

@@ -78,0 +104,0 @@

@@ -20,4 +20,2 @@ "use strict";

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**

@@ -33,51 +31,2 @@ * An ISOTime Schema Type

super(definition);
_defineProperty(this, "transformFromDb", value => {
if (value == null) {
return null;
}
const castValue = +value;
if (!Number.isInteger(castValue) || castValue < 0) {
throw new _errors.TransformDataError({
transformClass: this.constructor.name,
transformValue: castValue
});
}
if (castValue > 86400000 || !this._isDbInMs && castValue > 86400) {
throw new _errors.TransformDataError({
transformClass: this.constructor.name,
transformValue: castValue
});
}
const isoTime = (0, _moment.default)().startOf('day');
if (this._isDbInMs) {
isoTime.add(castValue, 'milliseconds');
} else {
isoTime.add(castValue, 'seconds');
}
return isoTime.format(_constants.ISOTimeFormat);
});
_defineProperty(this, "transformToDb", value => {
if (value == null) {
return null;
}
const startOfDay = (0, _moment.default)().startOf('day');
if (this._isDbInMs) {
return String((0, _moment.default)(value, _constants.ISOTimeFormat).diff(startOfDay, 'milliseconds'));
}
return String((0, _moment.default)(value, _constants.ISOTimeFormat).diff(startOfDay, 'seconds'));
});
_defineProperty(this, "_validateType", async value => value == null || (0, _moment.default)(value, _constants.ISOTimeFormat).isValid());
const {

@@ -113,2 +62,76 @@ dbFormat = 's'

transformFromDb(value) {
if (value == null) {
return null;
}
const castValue = +value;
if (!Number.isInteger(castValue) || castValue < 0) {
throw new _errors.TransformDataError({
transformClass: this.constructor.name,
transformValue: castValue
});
}
if (castValue > 86400000 || !this._isDbInMs && castValue > 86400) {
throw new _errors.TransformDataError({
transformClass: this.constructor.name,
transformValue: castValue
});
}
const isoTime = (0, _moment.default)().startOf('day');
if (this._isDbInMs) {
isoTime.add(castValue, 'milliseconds');
} else {
isoTime.add(castValue, 'seconds');
}
return isoTime.format(_constants.ISOTimeFormat);
}
/**
* Transform ISO 8601 approved time format (HH:mm:ss.SSS) to mv style time data
* @function transformToDb
* @memberof ISOTimeType
* @instance
* @public
* @override
* @param {string|null} value - Value to transform
* @returns {string|null} Transformed string integer representing the number of seconds or milliseconds since midnight
*/
transformToDb(value) {
if (value == null) {
return null;
}
const startOfDay = (0, _moment.default)().startOf('day');
if (this._isDbInMs) {
return String((0, _moment.default)(value, _constants.ISOTimeFormat).diff(startOfDay, 'milliseconds'));
}
return String((0, _moment.default)(value, _constants.ISOTimeFormat).diff(startOfDay, 'seconds'));
}
/* private instance methods */
/**
* ISOTimeType data type validator
* @function _validateType
* @memberof ISOTimeType
* @instance
* @private
* @async
* @param {*[]} value - Value to validate for data type casting
* @returns {Promise.<Boolean>} True if valid / false if invalid
*/
async _validateType(value) {
return value == null || (0, _moment.default)(value, _constants.ISOTimeFormat).isValid();
}
}

@@ -115,0 +138,0 @@

@@ -40,6 +40,6 @@ "use strict";

return (0, _lodash.compact)((0, _lodash.flatten)((await Promise.all(this._validators.map(async ({
return (0, _lodash.compact)((0, _lodash.flatten)(await Promise.all(this._validators.map(async ({
validator,
message
}) => !(await validator(castValue, document)) && message).concat((0, _lodash.flatten)(castValue).map(async arrayItem => this._valueSchemaType.validate(arrayItem, document)))))));
}) => !(await validator(castValue, document)) && message).concat((0, _lodash.flatten)(castValue).map(async arrayItem => this._valueSchemaType.validate(arrayItem, document))))));
});

@@ -46,0 +46,0 @@ }

@@ -69,26 +69,4 @@ "use strict";

_defineProperty(this, "transformFromDb", () => {
throw new _errors.NotImplementedError({
methodName: 'transformFromDb',
className: this.constructor.name
});
});
_defineProperty(this, "transformToDb", () => {
throw new _errors.NotImplementedError({
methodName: 'transformToDb',
className: this.constructor.name
});
});
_defineProperty(this, "transformToQuery", value => value);
_defineProperty(this, "validate", async (value, document) => // combining all the validation into one array of promise.all
// - a validator will return false or the appropriate error message
// - compact the array of resolved promises to remove any falsy values
(0, _lodash.compact)((await Promise.all(this._validators.concat((0, _utils.handleRequiredValidation)(this._required, this._validateRequired)).map(async ({
validator,
message
}) => !(await validator(value, document)) && message)))));
_defineProperty(this, "_normalizeMvPath", path => {

@@ -214,2 +192,80 @@ if (path == null) {

/**
* Transform from mv data to externally formatted data
* @function transformFromDb
* @memberof SimpleType
* @abstract
* @instance
* @param {*} value - Value to transform
* @returns {*} Transformed value
* @throws {NotImplementedError} Thrown if called directly
*/
transformFromDb() {
throw new _errors.NotImplementedError({
methodName: 'transformFromDb',
className: this.constructor.name
});
}
/**
* Transform from externally formatted data to mv data
* @function transformToDb
* @memberof SimpleType
* @abstract
* @instance
* @param {*} value - Value to transform
* @returns {*} Transformed value
* @throws {NotImplementedError} Thrown if called directly
*/
transformToDb() {
throw new _errors.NotImplementedError({
methodName: 'transformToDb',
className: this.constructor.name
});
}
/**
* Transform query constants to the format schema
* @function transformToQuery
* @memberof SimpleType
* @instance
* @public
* @param {*} value - Value to convert
* @returns {*} No transformation - returns original input value
*/
/**
* Validate the simple type
* @function validate
* @memberof SimpleType
* @instance
* @async
* @param {*} value - Simple type value to validate
* @param {Document} document - Document object
* @returns {Promise.<string[]>} List of errors found while validating
*/
async validate(value, document) {
// combining all the validation into one array of promise.all
// - a validator will return false or the appropriate error message
// - compact the array of resolved promises to remove any falsy values
return (0, _lodash.compact)(await Promise.all(this._validators.concat((0, _utils.handleRequiredValidation)(this._required, this._validateRequired)).map(async ({
validator,
message
}) => !(await validator(value, document)) && message)));
}
/* private instance methods */
/**
* Convert a 1-index string array path definition (e.g. '1.1.1') to a 0-index array path definition (e.g. [0, 0, 0])
* @function _normalizeMvPath
* @memberof SimpleType
* @instance
* @private
* @param {string} [path] - 1-indexed String path
* @returns {number[]} 0-indexed Array path
* @throws {InvalidParameterError} Path definition must be a string of integers split by periods
*/
}

@@ -216,0 +272,0 @@

{
"name": "mvom",
"author": "STORIS",
"version": "0.9.3",
"version": "0.9.4",
"description": "Multivalue Object Mapper",

@@ -19,7 +19,7 @@ "main": "./js/index.js",

"axios": "^0.21.1",
"fs-extra": "^7.0.1",
"fs-extra": "^10.0.0",
"lodash": "^4.17.21",
"moment": "^2.24.0",
"semver": "^6.3.0"
"moment": "^2.29.1",
"semver": "^7.3.5"
}
}

@@ -1,1 +0,5 @@

"use strict";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc