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

mapql

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapql - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

2

package.json
{
"name": "mapql",
"version": "0.0.8",
"version": "0.0.9",
"description": "A MongoDB inspired ES6 Map() query langauge.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -80,4 +80,9 @@ MapQL (WIP)

* Extended support
* Array, Function, Date, Map, Set, Buffer/Uint8Array, RegExp
* Array, Function, Date, Map, Set, Buffer/Uint8Array, RegExp, NaN
* Experimental support
* [TypedArray]
Typed arrays are tested with [ArrayBuffer.isView()], this is an experimental (under tested) feature of MapQL.
See [TypedArray] for more information about typed arrays.
Example: `MapQL.find()`

@@ -236,1 +241,3 @@ -

[Primitives]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types
[ArrayBuffer.isView()]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView
[TypedArray]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

@@ -46,3 +46,3 @@ /*!

Array.prototype.sort.call(this, (a, b) => {
if (!(Helpers.is(a.value, 'object') && Helpers.is(b.value, 'object'))) {
if (!(Helpers.is(a.value, 'Object') && Helpers.is(b.value, 'Object'))) {
return 0;

@@ -63,3 +63,3 @@ }

limit (num = 1) {
return Helpers.is((this[_limit] = num), 'number') ? this.slice(0, this[_limit]) : this;
return Helpers.is((this[_limit] = num), 'Number') ? this.slice(0, this[_limit]) : this;
}

@@ -66,0 +66,0 @@ }

@@ -37,3 +37,3 @@ /*!

try {
return _apply(keys, obj, (opts.value ? (is(opts.value, '!function') ? (current, next) => { return next } : opts.value) : opts.value));
return _apply(keys, obj, (opts.value ? (is(opts.value, '!Function') ? (current, next) => { return next } : opts.value) : opts.value));
} catch (e) {

@@ -67,19 +67,19 @@ return undefined; // Value must not exist; return undefined!

function deepClone (obj, _Map = Map) {
if (is(obj, 'null') || is(obj, '!object', true)) {
if (is(obj, 'Null') || is(obj, '!Object', true)) {
return obj;
}
switch (getType(obj).toLowerCase()) {
case 'date':
switch (getType(obj)) {
case 'Date':
return new Date(obj.getTime());
case 'map': case 'mapql':
case 'Map': case 'MapQL':
return new _Map(deepClone(Array.from(obj), _Map));
case 'set':
case 'Set':
return new Set(deepClone(Array.from(obj), _Map));
case 'regexp':
case 'RegExp':
return new RegExp(obj);
case 'array':
case 'Array':
return new Array(obj.length).fill(0).map((val, idx) => {
return deepClone(obj[idx], _Map)
});
case 'object':
case 'Object':
return ((cloned) => {

@@ -86,0 +86,0 @@ for (let prop in obj) {

@@ -13,3 +13,5 @@ /*!

GenerateID = new (require('./GenerateID'))(),
isEqual = require('is-equal');
isEqual = require('is-equal'),
// Choose between global for Node.js or Window for browser, used with import().
__GLOBAL = new Function("try { return this === global; } catch (e) { return false; }")() ? global : window;

@@ -68,3 +70,3 @@ class MapQL extends Map {

let isLO = this.isLogicalOperator(key);
if (Helpers.is(queries[key], 'object')) {
if (Helpers.is(queries[key], 'Object')) {
for (let mode of Object.keys(queries[key])) {

@@ -188,3 +190,3 @@ results.list.push([key, mode, queries[key][mode]]);

find (queries = {}, projections = {}, one = false, bykey = false) {
if (Helpers.is(queries, '!object')) {
if (Helpers.is(queries, '!Object')) {
let value;

@@ -251,3 +253,3 @@ if ((value = this.get(queries, false)) !== Helpers._null) {

}, options),
cursor = this[Helpers.is(queries, 'string') ? 'findByKey' : 'find'](queries, opts.projections, !opts.multi);
cursor = this[Helpers.is(queries, 'String') ? 'findByKey' : 'find'](queries, opts.projections, !opts.multi);
if (!cursor.empty()) {

@@ -274,3 +276,3 @@ let update = this.compile(modifiers, true);

let removed = [];
if (Helpers.is(queries, '!object')) {
if (Helpers.is(queries, '!Object')) {
for (let key of (Array.isArray(queries) ? queries : [queries])) {

@@ -312,15 +314,17 @@ if (this.has(key) && this.delete(key)) {

try {
let _export = (m) => {
if (Helpers.is(m, 'set')) {
return [...m].map((k) => [_export(k), Helpers.typeToInt(Helpers.getType(k))]);
} else if (Helpers.is(m, 'map')) {
return [...m].map(([k,v]) => [_export(k), _export(v), Helpers.typeToInt(Helpers.getType(k)), Helpers.typeToInt(Helpers.getType(v))]);
} else if (Helpers.is(m, 'object')) {
for (let key of Object.keys(m)) {
m[key] = [_export(m[key]), Helpers.typeToInt(Helpers.getType(m[key]))];
let _export = (value) => {
if (Helpers.is(value, 'Set')) {
return [...value].map((k) => [_export(k), Helpers.typeToInt(Helpers.getType(k))]);
} else if (Helpers.is(value, 'Map')) {
return [...value].map(([k,v]) => [_export(k), _export(v), Helpers.typeToInt(Helpers.getType(k)), Helpers.typeToInt(Helpers.getType(v))]);
} else if (Helpers.is(value, 'Array')) {
return value.map((value) => { return [_export(value), Helpers.typeToInt(Helpers.getType(value))]; });
} else if (Helpers.is(value, 'Object')) {
for (let key of Object.keys(value)) {
value[key] = convertValueByType(value[key], Helpers.getType(value[key]), _export);
}
} else if (Helpers.is(m, 'array')) {
return m.map((value) => { return [_export(value), Helpers.typeToInt(Helpers.getType(value))]; });
} else if (isTypedArray(value)) {
return Array.from(value);
}
return Helpers.is(m, ['!null', '!number', '!boolean', '!object']) ? m.toString() : m;
return convertValueByType(value, Helpers.getType(value));
},

@@ -330,3 +334,3 @@ exported = _export(Helpers.deepClone(this, MapQL));

return ((res) => {
return (opts.promise ? Promise.resolve(res) : res);
return (opts.provalueise ? Promise.resolve(res) : res);
})(opts.stringify ? JSON.stringify(exported, null, (opts.pretty ? 4 : 0)) : exported);

@@ -351,3 +355,3 @@ } catch (error) {

try {
(Helpers.is(json, 'string') ? JSON.parse(json) : json).map((entry) => {
(Helpers.is(json, 'String') ? JSON.parse(json) : json).map((entry) => {
this.set(fromType(entry[0], entry[2] || ''), fromType(entry[1], entry[3] || ''));

@@ -367,21 +371,54 @@ });

/*
* Check if is typed array.
*/
function isTypedArray (value) {
try {
if (ArrayBuffer.isView(value) && !(value instanceof DataView)) {
return true;
}
} catch (error) { }
return false;
}
/*
* Convert specific data types to specific values based on type for export().
*/
function convertValueByType (value, type, _export = false) {
let _return = ((_exp) => {
return (v, t) => {
return _exp ? [_exp(v), t] : v
}
})(_export);
let typeint = Helpers.typeToInt(type);
switch (type) {
case 'Date':
return _return(value.getTime(), typeint);
case 'Number':
return _return(isNaN(value) ? value.toString() : Number(value), typeint)
default:
if (_export) {
return _return (value, typeint);
} else {
return _return(Helpers.is(value, ['!Null', '!Number', '!Boolean', '!Object']) ? value.toString() : value);
}
}
};
/*
* Convert strings to required data type, used in import().
*/
let Mapper = (value) => {
return value.map((val) => {
return fromType(val[0], val[1]);
});
};
function fromType (entry, type) {
let inttype = Helpers.intToType(type);
switch (inttype) {
case 'Map':
case 'Map': case 'MapQL':
return (new MapQL()).import(entry); // Convert all 'Map()' entries to MapQL.
case 'Set':
return new Set(Mapper(entry));
// XXX: Function() is a form of eval()!
case 'Function':
return new Function(`return ${entry};`)();
return new Set(entry.map((val) => {
return fromType(val[0], val[1]);
}));
case 'Array':
return Mapper(entry);
return entry.map((val) => {
return fromType(val[0], val[1]);
});
case 'Object':

@@ -394,6 +431,13 @@ return ((obj) => {

})(entry);
case 'Function':
// XXX: Function() is a form of eval()!
return new Function(`return ${entry};`)();
case 'RegExp':
return RegExp.apply(null, entry.match(/\/(.*?)\/([gimuy])?$/).slice(1));
case 'Date':
return new Date(entry);
case 'Uint8Array':
case 'Buffer':
try {
if (Uint8Array && Helpers.getType(Uint8Array) === 'function') {
if (Uint8Array && Helpers.getType(Uint8Array) === 'Function') {
return new Uint8Array(entry);

@@ -404,5 +448,8 @@ }

}
case 'RegExp':
return RegExp.apply(null, entry.match(/\/(.*?)\/([gimuy])?$/).slice(1));
default: return entry;
default:
// Execute the function/constructor with the entry value. If type is not a
// function or constructor, just return the value. Try without `new`, if
// that fails try again with `new`. This attempts to import unknown types.
let _fn = (__GLOBAL[inttype] ? (new Function(`return ${inttype}`))() : (e) => { return e });
try { return _fn(entry); } catch (e) { try { return new _fn(entry); } catch (error) { console.trace(error); } }
}

@@ -409,0 +456,0 @@ }

@@ -11,3 +11,3 @@ /*!

fn: function (key, val, entry) {
if (Helpers.is(entry.value, 'object')) {
if (Helpers.is(entry.value, 'Object')) {
Helpers.dotNotation(key, entry.value, {

@@ -21,3 +21,3 @@ value: (current) => {

});
} else if (Helpers.is(entry.value, 'array')) {
} else if (Helpers.is(entry.value, 'Array')) {
entry.value[(val == -1 ? 'pop' : 'shift')]();

@@ -24,0 +24,0 @@ }

@@ -12,3 +12,3 @@ /*!

fn: function (key, val, entry) {
Helpers.is(entry.value, '!object') ? this.set(entry._id, (entry.value = val)) : Helpers.dotNotation(key, entry.value, {
Helpers.is(entry.value, '!Object') ? this.set(entry._id, (entry.value = val)) : Helpers.dotNotation(key, entry.value, {
value: () => {

@@ -23,3 +23,3 @@ return val;

let _val = parseInt(val, 10);
Helpers.is(entry.value, '!object') ? this.set(entry._id, (entry.value = (parseInt(entry.value, 10) + _val))) : Helpers.dotNotation(key, entry.value, {
Helpers.is(entry.value, '!Object') ? this.set(entry._id, (entry.value = (parseInt(entry.value, 10) + _val))) : Helpers.dotNotation(key, entry.value, {
value: (current) => {

@@ -34,3 +34,3 @@ return (current !== Helpers._null ? parseInt(current, 10) + _val : _val);

let _val = parseInt(val, 10);
Helpers.is(entry.value, '!object') ? this.set(entry._id, (entry.value = parseInt(entry.value, 10) * _val)) : Helpers.dotNotation(key, entry.value, {
Helpers.is(entry.value, '!Object') ? this.set(entry._id, (entry.value = parseInt(entry.value, 10) * _val)) : Helpers.dotNotation(key, entry.value, {
value: (current) => {

@@ -44,5 +44,5 @@ return (current !== Helpers._null ? parseInt(current, 10) * _val : _val);

fn: function (key, val, entry) {
Helpers.is(entry.value, '!object') ? this.delete(entry._id, (entry.value = undefined)) : Helpers.dotNotation(key, entry.value, { unset: true });
Helpers.is(entry.value, '!Object') ? this.delete(entry._id, (entry.value = undefined)) : Helpers.dotNotation(key, entry.value, { unset: true });
}
}
};

@@ -11,3 +11,3 @@ /*!

chain: function (key, val) {
let isbool = Helpers.is(key, 'boolean'),
let isbool = Helpers.is(key, 'Boolean'),
check = val !== Helpers._null ? val : (isbool ? key : true);

@@ -14,0 +14,0 @@ return !isbool || val !== Helpers._null ? { [key] : { '$exists': check } } : { '$exists': check };

@@ -11,3 +11,3 @@ /*!

fn: function (val, regex = /./gi) {
return (Helpers.is(regex, 'regexp') ? new RegExp(regex) : new RegExp(regex, 'gi')).test(val);
return (Helpers.is(regex, 'RegExp') ? new RegExp(regex) : new RegExp(regex, 'gi')).test(val);
}

@@ -19,5 +19,5 @@ },

// Need to figure out if this is the best method of handling this.
return Helpers.is(fn, 'function') ? fn.call(Helpers.is(entry[1], 'object') ? entry[1] : {}, entry[1]) : false;
return Helpers.is(fn, 'Function') ? fn.call(Helpers.is(entry[1], 'Object') ? entry[1] : {}, entry[1]) : false;
}
}
};

@@ -259,5 +259,7 @@ /*!

MapQL3 = new MapQL(),
MapQL4 = new MapQL(),
data =[
'[["test0",{"foo":[1,3]},4,6]]',
'[[{"foo":[1,3]},"test1",6,4]]'
'[[{"foo":[1,3]},"test1",6,4]]',
'[["test2",[0,0,0,0],4,"Int32Array"]]'
];

@@ -271,2 +273,5 @@ describe('#import()', () => {

});
it('it should import '+data[2], () => {
assert.equal(MapQL4.import(data[2]).has('test2'), true);
});
});

@@ -280,3 +285,6 @@ describe('#export()', () => {

});
it('it should export '+data[2], () => {
assert.deepEqual(JSON.parse(MapQL4.export())[0][0], 'test2');
});
});
});

@@ -259,5 +259,7 @@ /*!

MapQL3 = new MapQL(),
MapQL4 = new MapQL(),
data =[
'[["test0",{"foo":[1,3]},4,6]]',
'[[{"foo":[1,3]},"test1",6,4]]'
'[[{"foo":[1,3]},"test1",6,4]]',
'[["test2",[0,0,0,0],4,"Int32Array"]]'
];

@@ -271,2 +273,5 @@ describe('#import()', () => {

});
it('it should import '+data[2], () => {
assert.equal(MapQL4.import(data[2]).has('test2'), true);
});
});

@@ -280,3 +285,6 @@ describe('#export()', () => {

});
it('it should export '+data[2], () => {
assert.deepEqual(JSON.parse(MapQL4.export())[0][0], 'test2');
});
});
});

@@ -16,3 +16,4 @@ /*!

require('core-js/es6/promise');
require('core-js/fn/typed/array-buffer');
module.exports = (typeof window !== 'undefined' ? window : {}).MapQL = require('../src/MapQL');

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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