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

mvom

Package Overview
Dependencies
Maintainers
1
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.0.8 to 0.0.9

shared/constants/time.js

1

.mvomrc.json

@@ -8,4 +8,5 @@ {

"findById": "^0.0.2",
"getServerInfo": "^0.0.1",
"save": "^0.0.2"
}
}
# CHANGELOG.md
## 0.0.9
###### _2018-06-07_
- Connection instances now expose `getDbDate`, `getDbDateTime`, and `getDbTime` functions.
These can be used to calculate the date and time values as represented at the
database layer since it is likely to differ from the layer running mvom. This
will allow consumers to get these values so they can be provided in the data.
Note: This information is cached with a tunable time period (default 1 hour) in order
to provide low latency feedback but also reasonably handle shifts in the database time
(e.g. daylight saving time, server migrations, etc.) @shawnmcknight
## 0.0.8

@@ -3,0 +13,0 @@ ### Breaking change

@@ -19,2 +19,6 @@ 'use strict';

var _moment = require('moment');
var _moment2 = _interopRequireDefault(_moment);
var _semver = require('semver');

@@ -52,2 +56,4 @@

var _time = require('../shared/constants/time');
var _mvomrc = require('../.mvomrc.json');

@@ -62,2 +68,3 @@

* @param options.logger - Winston logger instance used for diagnostic logging
* @param {number} [options.cacheMaxAge=3600] - Maximum age, in seconds, of the cache of db server tier information
*/

@@ -85,3 +92,3 @@ class Connection {

*/
constructor({ connectionManagerUri, account, logger }) {
constructor({ connectionManagerUri, account, logger, cacheMaxAge = 3600 }) {
this._serverFeatureSet = { validFeatures: {}, invalidFeatures: [] };

@@ -104,2 +111,4 @@

await this._getDbServerInfo(); // establish baseline for database server information
this.logger.debug(`connection opened`);

@@ -161,3 +170,3 @@ this.status = _connectionStatus2.default.CONNECTED;

this.executeDbFeature = async (feature, options) => {
this.executeDbFeature = async (feature, options = {}) => {
this.logger.debug(`executing database feature "${feature}"`);

@@ -176,2 +185,17 @@ const data = {

this.getDbDate = async () => {
await this._getDbServerInfo();
return (0, _moment2.default)().add(this._timeDrift).format(_time.ISOCalendarDateFormat);
};
this.getDbDateTime = async () => {
await this._getDbServerInfo();
return (0, _moment2.default)().add(this._timeDrift).format(_time.ISOCalendarDateTimeFormat);
};
this.getDbTime = async () => {
await this._getDbServerInfo();
return (0, _moment2.default)().add(this._timeDrift).format(_time.ISOTimeFormat);
};
this.model = (schema, file) => {

@@ -213,2 +237,15 @@ if (this.status !== _connectionStatus2.default.CONNECTED) {

this._getDbServerInfo = async () => {
if (Date.now() > this._cacheExpiry) {
this.logger.debug('getting db server information');
const data = await this.executeDbFeature('getServerInfo');
const { date, time } = data;
this._timeDrift = (0, _moment2.default)(_time.epoch).add(date, 'days').add(time, 'ms').diff((0, _moment2.default)());
this._cacheExpiry = Date.now() + this._cacheMaxAge * 1000;
}
};
this._getFeatureState = async () => {

@@ -285,24 +322,65 @@ this.logger.debug(`getting state of database server features`);

logger.debug(`creating new connection instance`);
/**
* URI of the full endpoint for communicating with the database
* @member {string} _endpoint
* @memberof Connection
* @instance
* @private
*/
this._endpoint = `${connectionManagerUri}/${account}/subroutine/${Connection.getServerProgramName('entry')}`;
/**
* Winston logger instance used for diagnostic logging
* @member logger
* @memberof Connection
* @instance
*/
this.logger = logger;
/**
* Connection status enumeration
* @member status
* @memberof Connection
* @instance
*/
this.status = _connectionStatus2.default.DISCONNECTED;
Object.defineProperties(this, {
/**
* Winston logger instance used for diagnostic logging
* @member logger
* @memberof Connection
* @instance
*/
logger: {
value: logger
},
/**
* Connection status enumeration
* @member status
* @memberof Connection
* @instance
*/
status: {
value: _connectionStatus2.default.DISCONNECTED,
enumerable: true,
writable: true
},
/**
* Time that the connection information cache will expire
* @member _cacheExpiry
* @memberof Connection
* @instance
* @private
*/
_cacheExpiry: {
value: 0,
writable: true
},
/**
* Maximum age of the cache before it must be refreshed
* @member _cacheMaxAge
* @memberof Connection
* @instance
* @private
*/
_cacheMaxAge: {
value: cacheMaxAge
},
/**
* URI of the full endpoint for communicating with the database
* @member {string} _endpoint
* @memberof Connection
* @instance
* @private
*/
_endpoint: {
value: `${connectionManagerUri}/${account}/subroutine/${Connection.getServerProgramName('entry')}`
},
/**
* +/- in milliseconds between database server time and local server time
* @member _timeDrift
* @memberof Connection
* @instance
* @private
*/
_timeDrift: {
writable: true
}
});
}

@@ -369,3 +447,3 @@

* @param {string} feature - Name of feature to execute
* @param {*} options - Options parameter to pass to database feature
* @param {*} [options={}] - Options parameter to pass to database feature
* @returns {*} Output from database feature

@@ -378,2 +456,32 @@ * @throws {ConnectionManagerError} (indirect) An error occurred in connection manager communications

/**
* Get the current ISOCalendarDate from the database
* @function getDbDate
* @memberof Connection
* @instance
* @async
* @return {Promise.<String>} Current db server time as ISO 8601 String Date value (yyyy-mm-dd)
*/
/**
* Get the current ISOCalendarDateTime from the database
* @function getDbDateTime
* @memberof Connection
* @instance
* @async
* @return {Promise.<String>} Current db server time as ISO 8601 String date/time value (yyyy-mm-ddTHH:mm:ss.SSS)
*/
/**
* Get the current ISOTime from the database
* @function getDbTime
* @memberof Connection
* @instance
* @async
* @return {Promise.<String>} Current db server time as ISO 8601 String Time value (HH:mm:ss.SSS)
*/
/**
* Define a new model

@@ -409,2 +517,13 @@ * @function model

/**
* Get the db server information (date, time, etc.)
* @function _getDbServerInfo
* @memberof Connection
* @instance
* @private
* @async
* @modifies {this}
*/
/**
* Get the state of database server features

@@ -411,0 +530,0 @@ * @function _getFeatureState

2

package.json
{
"name": "mvom",
"author": "STORIS",
"version": "0.0.8",
"version": "0.0.9",
"description": "Multivalue Object Mapper",

@@ -6,0 +6,0 @@ "main": "./index.js",

@@ -116,3 +116,3 @@ 'use strict';

* @param {string|number|null} value - Value to transform
* @returns {string|null} Transformed ISO 8601 String Time value (HH:mm:ss.SSS)
* @returns {string|null} Transformed ISO 8601 String date/time value (yyyy-mm-ddTHH:mm:ss.SSS)
* @throws {TransformDataError} (indirect) Database value could not be transformed to external format

@@ -119,0 +119,0 @@ */

@@ -19,2 +19,4 @@ 'use strict';

var _time = require('../../shared/constants/time');
var _handleTypeValidation = require('../../shared/handleTypeValidation');

@@ -35,8 +37,2 @@

/**
* External format for ISO Calendar Date data
* @member {string} ISOCalendarDateFormat
* @memberof ISOCalendarDateType
* @static
*/
constructor(definition) {

@@ -59,8 +55,8 @@ super(definition);

return (0, _moment2.default)(ISOCalendarDateType.epoch).add(castValue, 'days').format(ISOCalendarDateType.ISOCalendarDateFormat);
return (0, _moment2.default)(_time.epoch).add(castValue, 'days').format(_time.ISOCalendarDateFormat);
};
this.transformToDb = value => value == null ? null : String((0, _moment2.default)(value).diff((0, _moment2.default)(ISOCalendarDateType.epoch), 'days'));
this.transformToDb = value => value == null ? null : String((0, _moment2.default)(value).diff((0, _moment2.default)(_time.epoch), 'days'));
this._validateType = async value => value == null || (0, _moment2.default)(value, ISOCalendarDateType.ISOCalendarDateFormat).isValid();
this._validateType = async value => value == null || (0, _moment2.default)(value, _time.ISOCalendarDateFormat).isValid();

@@ -84,10 +80,3 @@ this._validators.unshift((0, _handleTypeValidation2.default)(this._validateType));

/**
* The multivalue date epoch
* @member {string} epoch
* @memberof ISOCalendarDateType
* @static
*/
/**

@@ -119,4 +108,2 @@ * Transform ISO 8601 approved date format (yyyy-mm-dd) to mv date data

ISOCalendarDateType.ISOCalendarDateFormat = 'YYYY-MM-DD';
ISOCalendarDateType.epoch = '1967-12-31';
exports.default = ISOCalendarDateType;

@@ -19,2 +19,4 @@ 'use strict';

var _time = require('../../shared/constants/time');
var _handleTypeValidation = require('../../shared/handleTypeValidation');

@@ -34,3 +36,2 @@

class ISOTimeType extends _SimpleType2.default {
constructor(definition) {

@@ -66,3 +67,3 @@ super(definition);

return isoTime.format(ISOTimeType.ISOTimeFormat);
return isoTime.format(_time.ISOTimeFormat);
};

@@ -78,8 +79,8 @@

if (this._isDbInMs) {
return String((0, _moment2.default)(value, ISOTimeType.ISOTimeFormat).diff(startOfDay, 'milliseconds'));
return String((0, _moment2.default)(value, _time.ISOTimeFormat).diff(startOfDay, 'milliseconds'));
}
return String((0, _moment2.default)(value, ISOTimeType.ISOTimeFormat).diff(startOfDay, 'seconds'));
return String((0, _moment2.default)(value, _time.ISOTimeFormat).diff(startOfDay, 'seconds'));
};
this._validateType = async value => value == null || (0, _moment2.default)(value, ISOTimeType.ISOTimeFormat).isValid();
this._validateType = async value => value == null || (0, _moment2.default)(value, _time.ISOTimeFormat).isValid();

@@ -114,10 +115,3 @@ const { dbFormat = 's' } = definition;

/**
* External format for ISO Time data
* @member {string} ISOTimeFormat
* @memberof ISOTimeType
* @static
*/
/**

@@ -149,3 +143,2 @@ * Transform ISO 8601 approved time format (HH:mm:ss.SSS) to mv style time data

ISOTimeType.ISOTimeFormat = 'HH:mm:ss.SSS';
exports.default = ISOTimeType;
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