From accd602ad938d9f10074438102a5c10f2409a38b Mon Sep 17 00:00:00 2001 From: remyyounes Date: Mon, 26 Oct 2015 21:26:08 -0700 Subject: [PATCH 1/4] QC-1145 - undefined/undefined request --- lib/services/nsynchronizer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/services/nsynchronizer.js b/lib/services/nsynchronizer.js index 65a06a6..9740efd 100755 --- a/lib/services/nsynchronizer.js +++ b/lib/services/nsynchronizer.js @@ -79,6 +79,7 @@ var Nsynchronizer = { * @public Populates store from remote */ populate(object, params) { + if (_.isEmpty(object) && _.isEmpty(params)) return; this.client.getAll(object, params) .then((objects) => { // @todo: find a better way to sync w/ remote From 02376e0b8f790a58ecaf683f0be142debaafb4c4 Mon Sep 17 00:00:00 2001 From: remyyounes Date: Mon, 26 Oct 2015 22:18:10 -0700 Subject: [PATCH 2/4] build filed and removed css stuff --- dist/dataloader.min.js | 368 ++++++++++++++++++----------- gulpfile.js | 30 +-- package.json | 1 - public/assets/js/dataloader.min.js | 368 ++++++++++++++++++----------- 4 files changed, 474 insertions(+), 293 deletions(-) diff --git a/dist/dataloader.min.js b/dist/dataloader.min.js index cc70761..2a67ed7 100755 --- a/dist/dataloader.min.js +++ b/dist/dataloader.min.js @@ -831,7 +831,9 @@ return /******/ (function(modules) { // webpackBootstrap currentQueue = queue; queue = []; while (++queueIndex < len) { - currentQueue[queueIndex].run(); + if (currentQueue) { + currentQueue[queueIndex].run(); + } } queueIndex = -1; len = queue.length; @@ -883,7 +885,6 @@ return /******/ (function(modules) { // webpackBootstrap throw new Error('process.binding is not supported'); }; - // TODO(shtylman) process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); @@ -4010,6 +4011,7 @@ return /******/ (function(modules) { // webpackBootstrap populate: function populate(object, params) { var _this = this; + if (_.isEmpty(object) && _.isEmpty(params)) return; this.client.getAll(object, params).then(function (objects) { // @todo: find a better way to sync w/ remote // this.store.listenables.destroyAll(); @@ -7486,7 +7488,7 @@ return /******/ (function(modules) { // webpackBootstrap } }, // used to recursively scan hierarchical transform step object for param substitution - resolveTransformObject : function (subObj, params, depth) { + resolveTransformObject: function (subObj, params, depth) { var prop, pname; @@ -7501,18 +7503,17 @@ return /******/ (function(modules) { // webpackBootstrap pname = subObj[prop].substring(8); if (params.hasOwnProperty(pname)) { subObj[prop] = params[pname]; - } - } - else if (typeof subObj[prop] === "object") { + } + } else if (typeof subObj[prop] === "object") { subObj[prop] = Utils.resolveTransformObject(subObj[prop], params, depth); } } - + return subObj; }, // top level utility to resolve an entire (single) transform (array of steps) for parameter substitution resolveTransformParams: function (transform, params) { - var idx, + var idx, prop, clonedStep, resolvedTransform = []; @@ -7520,7 +7521,7 @@ return /******/ (function(modules) { // webpackBootstrap if (typeof params === 'undefined') return transform; // iterate all steps in the transform array - for (idx=0; idx < transform.length; idx++) { + for (idx = 0; idx < transform.length; idx++) { // clone transform so our scan and replace can operate directly on cloned transform clonedStep = JSON.parse(JSON.stringify(transform[idx])); resolvedTransform.push(Utils.resolveTransformObject(clonedStep, params)); @@ -7816,21 +7817,6 @@ return /******/ (function(modules) { // webpackBootstrap this.autosaveInterval = 5000; this.autosaveHandle = null; - // experimental support for browserify's abstract syntax scan to pick up dependency of indexed adapter. - // Hopefully, once this hits npm a browserify require of lokijs should scan the main file and detect this indexed adapter reference. - // Only in that environment should you instantiate the indexed adapter via db.getters.indexedAdapter (where db is loki ref). - this.getters = { - get indexedAdapter() { - var adapter; - - if (true) { - adapter = __webpack_require__(35); - } - - return adapter; - } - }; - this.options = {}; // currently keeping persistenceMethod and persistenceAdapter as loki level properties that @@ -7849,6 +7835,7 @@ return /******/ (function(modules) { // webpackBootstrap this.events = { 'init': [], + 'loaded': [], 'flushChanges': [], 'close': [], 'changes': [], @@ -7899,6 +7886,19 @@ return /******/ (function(modules) { // webpackBootstrap // db class is an EventEmitter Loki.prototype = new LokiEventEmitter(); + // experimental support for browserify's abstract syntax scan to pick up dependency of indexed adapter. + // Hopefully, once this hits npm a browserify require of lokijs should scan the main file and detect this indexed adapter reference. + Loki.prototype.getIndexedAdapter = function () { + var adapter; + + if (true) { + adapter = __webpack_require__(35); + } + + return adapter; + }; + + /** * configureOptions - allows reconfiguring database options * @@ -7961,11 +7961,11 @@ return /******/ (function(modules) { // webpackBootstrap if (this.options.hasOwnProperty('autosave') && this.options.autosave) { this.autosaveDisable(); this.autosave = true; - - if(this.options.hasOwnProperty('autosaveCallback')){ - this.autosaveEnable(options, options.autosaveCallback); - }else{ - this.autosaveEnable(); + + if (this.options.hasOwnProperty('autosaveCallback')) { + this.autosaveEnable(options, options.autosaveCallback); + } else { + this.autosaveEnable(); } } } // end of options processing @@ -8086,7 +8086,7 @@ return /******/ (function(modules) { // webpackBootstrap */ Loki.prototype.loadJSON = function (serializedDb, options) { - if(serializedDb.length===0) serializedDb=JSON.stringify({}); + if (serializedDb.length === 0) serializedDb = JSON.stringify({}); var obj = JSON.parse(serializedDb), i = 0, len = obj.collections ? obj.collections.length : 0, @@ -8149,7 +8149,7 @@ return /******/ (function(modules) { // webpackBootstrap copyColl.uniqueNames = []; if (coll.hasOwnProperty("uniqueNames")) { copyColl.uniqueNames = coll.uniqueNames; - for (j=0; j < copyColl.uniqueNames.length; j++) { + for (j = 0; j < copyColl.uniqueNames.length; j++) { copyColl.ensureUniqueIndex(copyColl.uniqueNames[j]); } } @@ -8161,7 +8161,7 @@ return /******/ (function(modules) { // webpackBootstrap for (var idx = 0; idx < coll.DynamicViews.length; idx++) { var colldv = coll.DynamicViews[idx]; - var dv = copyColl.addDynamicView(colldv.name, colldv.persistent); + var dv = copyColl.addDynamicView(colldv.name, colldv.options); dv.resultdata = colldv.resultdata; dv.resultsdirty = colldv.resultsdirty; dv.filterPipeline = colldv.filterPipeline; @@ -8356,6 +8356,7 @@ return /******/ (function(modules) { // webpackBootstrap if (typeof (dbString) === 'string') { self.loadJSON(dbString, options || {}); cFun(null); + self.emit('loaded', 'database ' + self.filename + ' loaded'); } else { console.warn('lokijs loadDatabase : Database not found'); if (typeof (dbString) === "object") { @@ -8573,6 +8574,72 @@ return /******/ (function(modules) { // webpackBootstrap // add branch() as alias of copy() Resultset.prototype.branch = Resultset.prototype.copy; + /** + * transform() - executes a raw array of transform steps against the resultset. + * + * @param {array} : (Optional) array of transform steps to execute against this resultset. + * @param {object} : (Optional) object property hash of parameters, if the transform requires them. + * @returns {Resultset} : either (this) resultset or a clone of of this resultset (depending on steps) + */ + Resultset.prototype.transform = function (transform, parameters) { + var idx, + step, + rs = this; + + if (typeof parameters !== 'undefined') { + transform = Utils.resolveTransformParams(transform, parameters); + } + + for (idx = 0; idx < transform.length; idx++) { + step = transform[idx]; + + switch (step.type) { + case "find": + rs.find(step.value); + break; + case "where": + rs.where(step.value); + break; + case "simplesort": + rs.simplesort(step.property, step.desc); + break; + case "compoundsort": + rs.compoundsort(step.value); + break; + case "sort": + rs.sort(step.value); + break; + case "limit": + rs = rs.limit(step.value); + break; // limit makes copy so update reference + case "offset": + rs = rs.offset(step.value); + break; // offset makes copy so update reference + case "map": + rs = rs.map(step.value); + break; + case "eqJoin": + rs = rs.eqJoin(step.joinData, step.leftJoinKey, step.rightJoinKey, step.mapFun); + break; + // following cases break chain by returning array data so make any of these last in transform steps + case "mapReduce": + rs = rs.mapReduce(step.mapFunction, step.reduceFunction); + break; + // following cases update documents in current filtered resultset (use carefully) + case "update": + rs.update(step.value); + break; + case "remove": + rs.remove(); + break; + default: + break; + } + } + + return rs; + }; + /** * sort() - User supplied compare function is provided two documents to compare. (chainable) * Example: @@ -8754,7 +8821,7 @@ return /******/ (function(modules) { // webpackBootstrap return [0, -1]; } if (ltHelper(maxVal, val)) { - return [0, rcd.length-1]; + return [0, rcd.length - 1]; } break; case '$lte': @@ -8762,7 +8829,7 @@ return /******/ (function(modules) { // webpackBootstrap return [0, -1]; } if (ltHelper(maxVal, val, true)) { - return [0, rcd.length-1]; + return [0, rcd.length - 1]; } break; } @@ -9141,9 +9208,17 @@ return /******/ (function(modules) { // webpackBootstrap i = t.length; if (firstOnly) { - while (i--) { - if (fun(t[i][property], value)) { - return (t[i]); + if (usingDotNotation) { + while (i--) { + if (this.dotSubScan(t[i], property, fun, value)) { + return (t[i]); + } + } + } else { + while (i--) { + if (fun(t[i][property], value)) { + return (t[i]); + } } } @@ -9638,10 +9713,31 @@ return /******/ (function(modules) { // webpackBootstrap * Unlike this dynamic view, the branched resultset will not be 'live' updated, * so your branched query should be immediately resolved and not held for future evaluation. * + * @param {string, array} : Optional name of collection transform, or an array of transform steps + * @param {object} : optional parameters (if optional transform requires them) * @returns {Resultset} A copy of the internal resultset for branched queries. */ - DynamicView.prototype.branchResultset = function () { - return this.resultset.copy(); + DynamicView.prototype.branchResultset = function (transform, parameters) { + var rs = this.resultset.copy(); + + if (typeof transform === 'undefined') { + return rs; + } + + // if transform is name, then do lookup first + if (typeof transform === 'string') { + if (this.collection.transforms.hasOwnProperty(transform)) { + transform = this.collection.transforms[transform]; + } + } + + // either they passed in raw transform array or we looked it up, so process + if (typeof transform === 'object' && Array.isArray(transform)) { + // if parameters were passed, apply them + return rs.transform(transform, parameters); + } + + return rs; }; /** @@ -9838,7 +9934,7 @@ return /******/ (function(modules) { // webpackBootstrap * queueRebuildEvent() - When the view is not sorted we may still wish to be notified of rebuild events. * This event will throttle and queue a single rebuild event when batches of updates affect the view. */ - DynamicView.prototype.queueRebuildEvent = function() { + DynamicView.prototype.queueRebuildEvent = function () { var self = this; if (this.rebuildPending) { @@ -9847,12 +9943,12 @@ return /******/ (function(modules) { // webpackBootstrap this.rebuildPending = true; - setTimeout(function() { + setTimeout(function () { self.rebuildPending = false; self.emit('rebuild', this); }, 1); }; - + /** * queueSortPhase : If the view is sorted we will throttle sorting to either : * (1) passive - when the user calls data(), or @@ -9873,8 +9969,7 @@ return /******/ (function(modules) { // webpackBootstrap setTimeout(function () { self.performSortPhase(); }, 1); - } - else { + } else { // must be passive sorting... since not calling performSortPhase (until data call), lets use queueRebuildEvent to // potentially notify user that data has changed. this.queueRebuildEvent(); @@ -9956,8 +10051,7 @@ return /******/ (function(modules) { // webpackBootstrap // need to re-sort to sort new document if (this.sortFunction || this.sortCriteria) { this.queueSortPhase(); - } - else { + } else { this.queueRebuildEvent(); } @@ -9986,8 +10080,7 @@ return /******/ (function(modules) { // webpackBootstrap // in case changes to data altered a sort column if (this.sortFunction || this.sortCriteria) { this.queueSortPhase(); - } - else { + } else { this.queueRebuildEvent(); } @@ -10004,8 +10097,7 @@ return /******/ (function(modules) { // webpackBootstrap // in case changes to data altered a sort column if (this.sortFunction || this.sortCriteria) { this.queueSortPhase(); - } - else { + } else { this.queueRebuildEvent(); } @@ -10054,7 +10146,7 @@ return /******/ (function(modules) { // webpackBootstrap oldlen = ofr.length; for (idx = 0; idx < oldlen; idx++) { if (ofr[idx] > objIndex) { - ofr[idx] --; + ofr[idx]--; } } }; @@ -10098,7 +10190,7 @@ return /******/ (function(modules) { // webpackBootstrap // unique contraints contain duplicate object references, so they are not persisted. // we will keep track of properties which have unique contraint applied here, and regenerate on load this.uniqueNames = []; - + // transforms will be used to store frequently used query chains as a series of steps // which itself can be stored along with the database. this.transforms = {}; @@ -10126,7 +10218,7 @@ return /******/ (function(modules) { // webpackBootstrap options.unique = [options.unique]; } options.unique.forEach(function (prop) { - self.uniqueNames.push(prop); // used to regenerate on subsequent database loads + self.uniqueNames.push(prop); // used to regenerate on subsequent database loads self.constraints.unique[prop] = new UniqueIndex(prop); }); } @@ -10305,11 +10397,11 @@ return /******/ (function(modules) { // webpackBootstrap this.transforms[name] = transform; }; - Collection.prototype.removeTransform = function(name) { + Collection.prototype.removeTransform = function (name) { delete transforms[name]; }; - Collection.prototype.byExample = function(template) { + Collection.prototype.byExample = function (template) { var k, obj, query; query = []; for (k in template) { @@ -10320,12 +10412,18 @@ return /******/ (function(modules) { // webpackBootstrap obj )); } - return { '$and': query }; + return { + '$and': query + }; }; - Collection.prototype.findObject = function(template) { return this.findOne(this.byExample(template)); }; + Collection.prototype.findObject = function (template) { + return this.findOne(this.byExample(template)); + }; - Collection.prototype.findObjects = function(template) { return this.find(this.byExample(template)); }; + Collection.prototype.findObjects = function (template) { + return this.find(this.byExample(template)); + }; /*----------------------------+ | INDEXING | @@ -10451,8 +10549,8 @@ return /******/ (function(modules) { // webpackBootstrap * Each collection maintains a list of DynamicViews associated with it **/ - Collection.prototype.addDynamicView = function (name, persistent) { - var dv = new DynamicView(this, name, persistent); + Collection.prototype.addDynamicView = function (name, options) { + var dv = new DynamicView(this, name, options); this.DynamicViews.push(dv); return dv; @@ -10604,7 +10702,7 @@ return /******/ (function(modules) { // webpackBootstrap this.commit(); this.dirty = true; // for autosave scenarios this.emit('update', doc); - + return doc; } catch (err) { this.rollback(); console.error(err.message); @@ -10736,7 +10834,7 @@ return /******/ (function(modules) { // webpackBootstrap position = arr[1]; var self = this; Object.keys(this.constraints.unique).forEach(function (key) { - if( doc[key] !== null && typeof doc[key] !== 'undefined' ) { + if (doc[key] !== null && typeof doc[key] !== 'undefined') { self.constraints.unique[key].remove(doc[key]); } }); @@ -10842,9 +10940,7 @@ return /******/ (function(modules) { // webpackBootstrap * @returns {Resultset} : (or data array if any map or join functions where called) */ Collection.prototype.chain = function (transform, parameters) { - var idx, - step, - rs = new Resultset(this, null, null); + var rs = new Resultset(this, null, null); if (typeof transform === 'undefined') { return rs; @@ -10860,33 +10956,7 @@ return /******/ (function(modules) { // webpackBootstrap // either they passed in raw transform array or we looked it up, so process if (typeof transform === 'object' && Array.isArray(transform)) { // if parameters were passed, apply them - if (typeof parameters !== 'undefined') { - transform = Utils.resolveTransformParams(transform, parameters); - } - - for(idx = 0; idx < transform.length; idx++) { - step = transform[idx]; - - switch (step.type) { - case "find" : rs.find(step.value); break; - case "where" : rs.where(step.value); break; - case "simplesort" : rs.simplesort(step.property, step.desc); break; - case "compoundsort" : rs.compoundsort(step.value); break; - case "sort" : rs.sort(step.value); break; - case "limit" : rs = rs.limit(step.value); break; // limit makes copy so update reference - case "offset" : rs = rs.offset(step.value); break; // offset makes copy so update reference - case "map" : rs = rs.map(step.value); break; - case "eqJoin" : rs = rs.eqJoin (step.joinData, step.leftJoinKey, step.rightJoinKey, step.mapFun); break; - // following cases break chain by returning array data so make any of these last in transform steps - case "mapReduce" : rs = rs.mapReduce(step.mapFunction, step.reduceFunction); break; - // following cases update documents in current filtered resultset (use carefully) - case "update" : rs.update(step.value); break; - case "remove" : rs.remove(); break; - default : break; - } - } - - return rs; + return rs.transform(transform, parameters); } return null; @@ -11311,7 +11381,7 @@ return /******/ (function(modules) { // webpackBootstrap UniqueIndex.prototype.keyMap = {}; UniqueIndex.prototype.lokiMap = {}; UniqueIndex.prototype.set = function (obj) { - if (obj[this.field] !== null && typeof(obj[this.field]) !== 'undefined') { + if (obj[this.field] !== null && typeof (obj[this.field]) !== 'undefined') { if (this.keyMap[obj[this.field]]) { throw new Error('Duplicate key for property ' + this.field + ': ' + obj[this.field]); } else { @@ -11339,7 +11409,7 @@ return /******/ (function(modules) { // webpackBootstrap }; UniqueIndex.prototype.remove = function (key) { var obj = this.keyMap[key]; - if( obj !== null && typeof obj !== 'undefined') { + if (obj !== null && typeof obj !== 'undefined') { this.keyMap[key] = undefined; this.lokiMap[obj.$loki] = undefined; } else { @@ -11576,7 +11646,7 @@ return /******/ (function(modules) { // webpackBootstrap IndexedAdapter.prototype.checkAvailability = function() { if (window && window.indexedDB) return true; - + return false; }; @@ -11592,7 +11662,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference so dont -need- callback in constructor - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11635,7 +11705,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference so dont -need- callback in constructor - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11664,7 +11734,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference so dont -need- callback in constructor - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11698,7 +11768,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference so dont -need- callback in constructor - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11742,7 +11812,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11784,7 +11854,7 @@ return /******/ (function(modules) { // webpackBootstrap } }); }; - + /** * LokiCatalog - underlying App/Key/Value catalog persistence * This non-interface class implements the actual persistence. @@ -11793,12 +11863,10 @@ return /******/ (function(modules) { // webpackBootstrap function LokiCatalog(callback) { this.db = null; - this.initializeLokiCatalog(callback); } - LokiCatalog.prototype.initializeLokiCatalog = function(callback) - { + LokiCatalog.prototype.initializeLokiCatalog = function(callback) { var openRequest = indexedDB.open('LokiCatalog', 1); var cat = this; @@ -12061,6 +12129,7 @@ return /******/ (function(modules) { // webpackBootstrap }; return IndexedAdapter; + }()); })); @@ -12277,7 +12346,21 @@ return /******/ (function(modules) { // webpackBootstrap } function wrapIndex(iter, index) { - return index >= 0 ? (+index) : ensureSize(iter) + (+index); + // This implements "is array index" which the ECMAString spec defines as: + // A String property name P is an array index if and only if + // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal + // to 2^32−1. + // However note that we're currently calling ToNumber() instead of ToUint32() + // which should be improved in the future, as floating point numbers should + // not be accepted as an array index. + if (typeof index !== 'number') { + var numIndex = +index; + if ('' + numIndex !== index) { + return NaN; + } + index = numIndex; + } + return index < 0 ? ensureSize(iter) + index : index; } function returnTrue() { @@ -12947,7 +13030,7 @@ return /******/ (function(modules) { // webpackBootstrap var src_Math__imul = typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ? Math.imul : - function src_Math__imul(a, b) { + function imul(a, b) { a = a | 0; // int b = b | 0; // int var c = a & 0xffff; @@ -13498,6 +13581,15 @@ return /******/ (function(modules) { // webpackBootstrap function sliceFactory(iterable, begin, end, useKeys) { var originalSize = iterable.size; + // Sanitize begin & end using this shorthand for ToInt32(argument) + // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32 + if (begin !== undefined) { + begin = begin | 0; + } + if (end !== undefined) { + end = end | 0; + } + if (wholeSlice(begin, end, originalSize)) { return iterable; } @@ -13524,7 +13616,9 @@ return /******/ (function(modules) { // webpackBootstrap var sliceSeq = makeSequence(iterable); - sliceSeq.size = sliceSize; + // If iterable.size is undefined, the size of the realized sliceSeq is + // unknown at this point unless the number of items to slice is 0 + sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined; if (!useKeys && isSeq(iterable) && sliceSize >= 0) { sliceSeq.get = function (index, notSetValue) { @@ -13973,7 +14067,7 @@ return /******/ (function(modules) { // webpackBootstrap function src_Map__Map(value) { return value === null || value === undefined ? emptyMap() : - isMap(value) ? value : + isMap(value) && !isOrdered(value) ? value : emptyMap().withMutations(function(map ) { var iter = KeyedIterable(value); assertNotInfinite(iter.size); @@ -14820,12 +14914,12 @@ return /******/ (function(modules) { // webpackBootstrap List.prototype.get = function(index, notSetValue) { index = wrapIndex(this, index); - if (index < 0 || index >= this.size) { - return notSetValue; + if (index >= 0 && index < this.size) { + index += this._origin; + var node = listNodeFor(this, index); + return node && node.array[index & MASK]; } - index += this._origin; - var node = listNodeFor(this, index); - return node && node.array[index & MASK]; + return notSetValue; }; // @pragma Modification @@ -15021,29 +15115,25 @@ return /******/ (function(modules) { // webpackBootstrap }; VNode.prototype.removeAfter = function(ownerID, level, index) { - if (index === level ? 1 << level : 0 || this.array.length === 0) { + if (index === (level ? 1 << level : 0) || this.array.length === 0) { return this; } var sizeIndex = ((index - 1) >>> level) & MASK; if (sizeIndex >= this.array.length) { return this; } - var removingLast = sizeIndex === this.array.length - 1; + var newChild; if (level > 0) { var oldChild = this.array[sizeIndex]; newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index); - if (newChild === oldChild && removingLast) { + if (newChild === oldChild && sizeIndex === this.array.length - 1) { return this; } } - if (removingLast && !newChild) { - return this; - } + var editable = editableVNode(this, ownerID); - if (!removingLast) { - editable.array.pop(); - } + editable.array.splice(sizeIndex + 1); if (newChild) { editable.array[sizeIndex] = newChild; } @@ -15135,6 +15225,10 @@ return /******/ (function(modules) { // webpackBootstrap function updateList(list, index, value) { index = wrapIndex(list, index); + if (index !== index) { + return list; + } + if (index >= list.size || index < 0) { return list.withMutations(function(list ) { index < 0 ? @@ -15226,6 +15320,14 @@ return /******/ (function(modules) { // webpackBootstrap } function setListBounds(list, begin, end) { + // Sanitize begin & end using this shorthand for ToInt32(argument) + // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32 + if (begin !== undefined) { + begin = begin | 0; + } + if (end !== undefined) { + end = end | 0; + } var owner = list.__ownerID || new OwnerID(); var oldOrigin = list._origin; var oldCapacity = list._capacity; @@ -15738,7 +15840,7 @@ return /******/ (function(modules) { // webpackBootstrap function src_Set__Set(value) { return value === null || value === undefined ? emptySet() : - isSet(value) ? value : + isSet(value) && !isOrdered(value) ? value : emptySet().withMutations(function(set ) { var iter = SetIterable(value); assertNotInfinite(iter.size); @@ -16483,10 +16585,6 @@ return /******/ (function(modules) { // webpackBootstrap return reify(this, concatFactory(this, values)); }, - contains: function(searchValue) { - return this.includes(searchValue); - }, - includes: function(searchValue) { return this.some(function(value ) {return is(value, searchValue)}); }, @@ -16776,7 +16874,7 @@ return /******/ (function(modules) { // webpackBootstrap hashCode: function() { return this.__hash || (this.__hash = hashIterable(this)); - }, + } // ### Internal @@ -16799,6 +16897,7 @@ return /******/ (function(modules) { // webpackBootstrap IterablePrototype.inspect = IterablePrototype.toSource = function() { return this.toString(); }; IterablePrototype.chain = IterablePrototype.flatMap; + IterablePrototype.contains = IterablePrototype.includes; // Temporary warning about using length (function () { @@ -16869,7 +16968,7 @@ return /******/ (function(modules) { // webpackBootstrap function(k, v) {return mapper.call(context, k, v, this$0)} ).flip() ); - }, + } }); @@ -16924,7 +17023,10 @@ return /******/ (function(modules) { // webpackBootstrap if (numArgs === 0 || (numArgs === 2 && !removeNum)) { return this; } - index = resolveBegin(index, this.size); + // If index is negative, it should resolve relative to the size of the + // collection. However size may be expensive to compute if not cached, so + // only call count() if the number is in fact negative. + index = resolveBegin(index, index < 0 ? this.count() : this.size); var spliced = this.slice(0, index); return reify( this, @@ -16997,7 +17099,7 @@ return /******/ (function(modules) { // webpackBootstrap var iterables = arrCopy(arguments); iterables[0] = this; return reify(this, zipWithFactory(this, zipper, iterables)); - }, + } }); @@ -17023,7 +17125,7 @@ return /******/ (function(modules) { // webpackBootstrap keySeq: function() { return this.valueSeq(); - }, + } }); @@ -17127,7 +17229,7 @@ return /******/ (function(modules) { // webpackBootstrap Repeat: Repeat, is: is, - fromJS: fromJS, + fromJS: fromJS }; diff --git a/gulpfile.js b/gulpfile.js index 8a153bd..9241489 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,9 +1,7 @@ -var +var gulp = require('gulp'), - sass = require('gulp-sass'), cached = require('gulp-cached'), autoprefixer = require('gulp-autoprefixer'), - minify = require('gulp-minify-css'), sourcemaps = require('gulp-sourcemaps'), browserSync = require('browser-sync').create(), reload = browserSync.reload, @@ -11,41 +9,21 @@ var webpack = require('gulp-webpack'), webpackServer = require('./webpack-server'); -var cssPath = "lib/css/**/*.scss"; -var cssOutPath = "public/assets/css"; var jsPath = "lib/entry.js"; var jsOutName = "dataloader.min.js"; var jsOutPath = "dist"; var jsPublicPath = "public/assets/js"; -gulp.task('webpack-hot', webpackServer); +gulp.task('webpack-hot', webpackServer); gulp.task('browsersync', function() { browserSync.init({ proxy: '0.0.0.0:8081', port: 8083 }); - gulp.watch(cssPath, ['browsersync-build']); gulp.watch('public/**/*.html', reload); }); -gulp.task('browsersync-build', function() { - return gulp.src(cssPath) - .pipe(sass({errLogToConsole: true })) - .pipe(cached('styles')) - .pipe(autoprefixer({ browsers: ['last 2 versions']})) - .pipe(gulp.dest(cssOutPath)) - .pipe(reload({stream: true})); -}); - -gulp.task('build_styles', function() { - return gulp.src(cssPath) - .pipe(sass({errLogToConsole: true })) - .pipe(autoprefixer({ browsers: ['last 2 versions']})) - .pipe(minify({compatibility: 'ie9'})) - .pipe(gulp.dest(cssOutPath)); -}); - gulp.task('build_js', function() { return gulp.src(jsPath) .pipe(webpack(require('./webpack.config.js'))) @@ -58,6 +36,6 @@ gulp.task('watch', ['build_js'], function() { gulp.watch('./lib/**/*.js', ['build_js']); }); -gulp.task('dev', ['browsersync', 'webpack-hot']); +gulp.task('dev', ['browsersync', 'webpack-hot']); -gulp.task('default', ['build_js', 'build_styles']); +gulp.task('default', ['build_js']); diff --git a/package.json b/package.json index 5fba815..5ff3cd5 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "gulp-cached": "^1.0.4", "gulp-minify-css": "^1.0.0", "gulp-rename": "^1.2.2", - "gulp-sass": "^1.3.3", "gulp-sourcemaps": "^1.5.0", "gulp-webpack": "^1.3.1", "json-loader": "^0.5.1", diff --git a/public/assets/js/dataloader.min.js b/public/assets/js/dataloader.min.js index cc70761..2a67ed7 100644 --- a/public/assets/js/dataloader.min.js +++ b/public/assets/js/dataloader.min.js @@ -831,7 +831,9 @@ return /******/ (function(modules) { // webpackBootstrap currentQueue = queue; queue = []; while (++queueIndex < len) { - currentQueue[queueIndex].run(); + if (currentQueue) { + currentQueue[queueIndex].run(); + } } queueIndex = -1; len = queue.length; @@ -883,7 +885,6 @@ return /******/ (function(modules) { // webpackBootstrap throw new Error('process.binding is not supported'); }; - // TODO(shtylman) process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); @@ -4010,6 +4011,7 @@ return /******/ (function(modules) { // webpackBootstrap populate: function populate(object, params) { var _this = this; + if (_.isEmpty(object) && _.isEmpty(params)) return; this.client.getAll(object, params).then(function (objects) { // @todo: find a better way to sync w/ remote // this.store.listenables.destroyAll(); @@ -7486,7 +7488,7 @@ return /******/ (function(modules) { // webpackBootstrap } }, // used to recursively scan hierarchical transform step object for param substitution - resolveTransformObject : function (subObj, params, depth) { + resolveTransformObject: function (subObj, params, depth) { var prop, pname; @@ -7501,18 +7503,17 @@ return /******/ (function(modules) { // webpackBootstrap pname = subObj[prop].substring(8); if (params.hasOwnProperty(pname)) { subObj[prop] = params[pname]; - } - } - else if (typeof subObj[prop] === "object") { + } + } else if (typeof subObj[prop] === "object") { subObj[prop] = Utils.resolveTransformObject(subObj[prop], params, depth); } } - + return subObj; }, // top level utility to resolve an entire (single) transform (array of steps) for parameter substitution resolveTransformParams: function (transform, params) { - var idx, + var idx, prop, clonedStep, resolvedTransform = []; @@ -7520,7 +7521,7 @@ return /******/ (function(modules) { // webpackBootstrap if (typeof params === 'undefined') return transform; // iterate all steps in the transform array - for (idx=0; idx < transform.length; idx++) { + for (idx = 0; idx < transform.length; idx++) { // clone transform so our scan and replace can operate directly on cloned transform clonedStep = JSON.parse(JSON.stringify(transform[idx])); resolvedTransform.push(Utils.resolveTransformObject(clonedStep, params)); @@ -7816,21 +7817,6 @@ return /******/ (function(modules) { // webpackBootstrap this.autosaveInterval = 5000; this.autosaveHandle = null; - // experimental support for browserify's abstract syntax scan to pick up dependency of indexed adapter. - // Hopefully, once this hits npm a browserify require of lokijs should scan the main file and detect this indexed adapter reference. - // Only in that environment should you instantiate the indexed adapter via db.getters.indexedAdapter (where db is loki ref). - this.getters = { - get indexedAdapter() { - var adapter; - - if (true) { - adapter = __webpack_require__(35); - } - - return adapter; - } - }; - this.options = {}; // currently keeping persistenceMethod and persistenceAdapter as loki level properties that @@ -7849,6 +7835,7 @@ return /******/ (function(modules) { // webpackBootstrap this.events = { 'init': [], + 'loaded': [], 'flushChanges': [], 'close': [], 'changes': [], @@ -7899,6 +7886,19 @@ return /******/ (function(modules) { // webpackBootstrap // db class is an EventEmitter Loki.prototype = new LokiEventEmitter(); + // experimental support for browserify's abstract syntax scan to pick up dependency of indexed adapter. + // Hopefully, once this hits npm a browserify require of lokijs should scan the main file and detect this indexed adapter reference. + Loki.prototype.getIndexedAdapter = function () { + var adapter; + + if (true) { + adapter = __webpack_require__(35); + } + + return adapter; + }; + + /** * configureOptions - allows reconfiguring database options * @@ -7961,11 +7961,11 @@ return /******/ (function(modules) { // webpackBootstrap if (this.options.hasOwnProperty('autosave') && this.options.autosave) { this.autosaveDisable(); this.autosave = true; - - if(this.options.hasOwnProperty('autosaveCallback')){ - this.autosaveEnable(options, options.autosaveCallback); - }else{ - this.autosaveEnable(); + + if (this.options.hasOwnProperty('autosaveCallback')) { + this.autosaveEnable(options, options.autosaveCallback); + } else { + this.autosaveEnable(); } } } // end of options processing @@ -8086,7 +8086,7 @@ return /******/ (function(modules) { // webpackBootstrap */ Loki.prototype.loadJSON = function (serializedDb, options) { - if(serializedDb.length===0) serializedDb=JSON.stringify({}); + if (serializedDb.length === 0) serializedDb = JSON.stringify({}); var obj = JSON.parse(serializedDb), i = 0, len = obj.collections ? obj.collections.length : 0, @@ -8149,7 +8149,7 @@ return /******/ (function(modules) { // webpackBootstrap copyColl.uniqueNames = []; if (coll.hasOwnProperty("uniqueNames")) { copyColl.uniqueNames = coll.uniqueNames; - for (j=0; j < copyColl.uniqueNames.length; j++) { + for (j = 0; j < copyColl.uniqueNames.length; j++) { copyColl.ensureUniqueIndex(copyColl.uniqueNames[j]); } } @@ -8161,7 +8161,7 @@ return /******/ (function(modules) { // webpackBootstrap for (var idx = 0; idx < coll.DynamicViews.length; idx++) { var colldv = coll.DynamicViews[idx]; - var dv = copyColl.addDynamicView(colldv.name, colldv.persistent); + var dv = copyColl.addDynamicView(colldv.name, colldv.options); dv.resultdata = colldv.resultdata; dv.resultsdirty = colldv.resultsdirty; dv.filterPipeline = colldv.filterPipeline; @@ -8356,6 +8356,7 @@ return /******/ (function(modules) { // webpackBootstrap if (typeof (dbString) === 'string') { self.loadJSON(dbString, options || {}); cFun(null); + self.emit('loaded', 'database ' + self.filename + ' loaded'); } else { console.warn('lokijs loadDatabase : Database not found'); if (typeof (dbString) === "object") { @@ -8573,6 +8574,72 @@ return /******/ (function(modules) { // webpackBootstrap // add branch() as alias of copy() Resultset.prototype.branch = Resultset.prototype.copy; + /** + * transform() - executes a raw array of transform steps against the resultset. + * + * @param {array} : (Optional) array of transform steps to execute against this resultset. + * @param {object} : (Optional) object property hash of parameters, if the transform requires them. + * @returns {Resultset} : either (this) resultset or a clone of of this resultset (depending on steps) + */ + Resultset.prototype.transform = function (transform, parameters) { + var idx, + step, + rs = this; + + if (typeof parameters !== 'undefined') { + transform = Utils.resolveTransformParams(transform, parameters); + } + + for (idx = 0; idx < transform.length; idx++) { + step = transform[idx]; + + switch (step.type) { + case "find": + rs.find(step.value); + break; + case "where": + rs.where(step.value); + break; + case "simplesort": + rs.simplesort(step.property, step.desc); + break; + case "compoundsort": + rs.compoundsort(step.value); + break; + case "sort": + rs.sort(step.value); + break; + case "limit": + rs = rs.limit(step.value); + break; // limit makes copy so update reference + case "offset": + rs = rs.offset(step.value); + break; // offset makes copy so update reference + case "map": + rs = rs.map(step.value); + break; + case "eqJoin": + rs = rs.eqJoin(step.joinData, step.leftJoinKey, step.rightJoinKey, step.mapFun); + break; + // following cases break chain by returning array data so make any of these last in transform steps + case "mapReduce": + rs = rs.mapReduce(step.mapFunction, step.reduceFunction); + break; + // following cases update documents in current filtered resultset (use carefully) + case "update": + rs.update(step.value); + break; + case "remove": + rs.remove(); + break; + default: + break; + } + } + + return rs; + }; + /** * sort() - User supplied compare function is provided two documents to compare. (chainable) * Example: @@ -8754,7 +8821,7 @@ return /******/ (function(modules) { // webpackBootstrap return [0, -1]; } if (ltHelper(maxVal, val)) { - return [0, rcd.length-1]; + return [0, rcd.length - 1]; } break; case '$lte': @@ -8762,7 +8829,7 @@ return /******/ (function(modules) { // webpackBootstrap return [0, -1]; } if (ltHelper(maxVal, val, true)) { - return [0, rcd.length-1]; + return [0, rcd.length - 1]; } break; } @@ -9141,9 +9208,17 @@ return /******/ (function(modules) { // webpackBootstrap i = t.length; if (firstOnly) { - while (i--) { - if (fun(t[i][property], value)) { - return (t[i]); + if (usingDotNotation) { + while (i--) { + if (this.dotSubScan(t[i], property, fun, value)) { + return (t[i]); + } + } + } else { + while (i--) { + if (fun(t[i][property], value)) { + return (t[i]); + } } } @@ -9638,10 +9713,31 @@ return /******/ (function(modules) { // webpackBootstrap * Unlike this dynamic view, the branched resultset will not be 'live' updated, * so your branched query should be immediately resolved and not held for future evaluation. * + * @param {string, array} : Optional name of collection transform, or an array of transform steps + * @param {object} : optional parameters (if optional transform requires them) * @returns {Resultset} A copy of the internal resultset for branched queries. */ - DynamicView.prototype.branchResultset = function () { - return this.resultset.copy(); + DynamicView.prototype.branchResultset = function (transform, parameters) { + var rs = this.resultset.copy(); + + if (typeof transform === 'undefined') { + return rs; + } + + // if transform is name, then do lookup first + if (typeof transform === 'string') { + if (this.collection.transforms.hasOwnProperty(transform)) { + transform = this.collection.transforms[transform]; + } + } + + // either they passed in raw transform array or we looked it up, so process + if (typeof transform === 'object' && Array.isArray(transform)) { + // if parameters were passed, apply them + return rs.transform(transform, parameters); + } + + return rs; }; /** @@ -9838,7 +9934,7 @@ return /******/ (function(modules) { // webpackBootstrap * queueRebuildEvent() - When the view is not sorted we may still wish to be notified of rebuild events. * This event will throttle and queue a single rebuild event when batches of updates affect the view. */ - DynamicView.prototype.queueRebuildEvent = function() { + DynamicView.prototype.queueRebuildEvent = function () { var self = this; if (this.rebuildPending) { @@ -9847,12 +9943,12 @@ return /******/ (function(modules) { // webpackBootstrap this.rebuildPending = true; - setTimeout(function() { + setTimeout(function () { self.rebuildPending = false; self.emit('rebuild', this); }, 1); }; - + /** * queueSortPhase : If the view is sorted we will throttle sorting to either : * (1) passive - when the user calls data(), or @@ -9873,8 +9969,7 @@ return /******/ (function(modules) { // webpackBootstrap setTimeout(function () { self.performSortPhase(); }, 1); - } - else { + } else { // must be passive sorting... since not calling performSortPhase (until data call), lets use queueRebuildEvent to // potentially notify user that data has changed. this.queueRebuildEvent(); @@ -9956,8 +10051,7 @@ return /******/ (function(modules) { // webpackBootstrap // need to re-sort to sort new document if (this.sortFunction || this.sortCriteria) { this.queueSortPhase(); - } - else { + } else { this.queueRebuildEvent(); } @@ -9986,8 +10080,7 @@ return /******/ (function(modules) { // webpackBootstrap // in case changes to data altered a sort column if (this.sortFunction || this.sortCriteria) { this.queueSortPhase(); - } - else { + } else { this.queueRebuildEvent(); } @@ -10004,8 +10097,7 @@ return /******/ (function(modules) { // webpackBootstrap // in case changes to data altered a sort column if (this.sortFunction || this.sortCriteria) { this.queueSortPhase(); - } - else { + } else { this.queueRebuildEvent(); } @@ -10054,7 +10146,7 @@ return /******/ (function(modules) { // webpackBootstrap oldlen = ofr.length; for (idx = 0; idx < oldlen; idx++) { if (ofr[idx] > objIndex) { - ofr[idx] --; + ofr[idx]--; } } }; @@ -10098,7 +10190,7 @@ return /******/ (function(modules) { // webpackBootstrap // unique contraints contain duplicate object references, so they are not persisted. // we will keep track of properties which have unique contraint applied here, and regenerate on load this.uniqueNames = []; - + // transforms will be used to store frequently used query chains as a series of steps // which itself can be stored along with the database. this.transforms = {}; @@ -10126,7 +10218,7 @@ return /******/ (function(modules) { // webpackBootstrap options.unique = [options.unique]; } options.unique.forEach(function (prop) { - self.uniqueNames.push(prop); // used to regenerate on subsequent database loads + self.uniqueNames.push(prop); // used to regenerate on subsequent database loads self.constraints.unique[prop] = new UniqueIndex(prop); }); } @@ -10305,11 +10397,11 @@ return /******/ (function(modules) { // webpackBootstrap this.transforms[name] = transform; }; - Collection.prototype.removeTransform = function(name) { + Collection.prototype.removeTransform = function (name) { delete transforms[name]; }; - Collection.prototype.byExample = function(template) { + Collection.prototype.byExample = function (template) { var k, obj, query; query = []; for (k in template) { @@ -10320,12 +10412,18 @@ return /******/ (function(modules) { // webpackBootstrap obj )); } - return { '$and': query }; + return { + '$and': query + }; }; - Collection.prototype.findObject = function(template) { return this.findOne(this.byExample(template)); }; + Collection.prototype.findObject = function (template) { + return this.findOne(this.byExample(template)); + }; - Collection.prototype.findObjects = function(template) { return this.find(this.byExample(template)); }; + Collection.prototype.findObjects = function (template) { + return this.find(this.byExample(template)); + }; /*----------------------------+ | INDEXING | @@ -10451,8 +10549,8 @@ return /******/ (function(modules) { // webpackBootstrap * Each collection maintains a list of DynamicViews associated with it **/ - Collection.prototype.addDynamicView = function (name, persistent) { - var dv = new DynamicView(this, name, persistent); + Collection.prototype.addDynamicView = function (name, options) { + var dv = new DynamicView(this, name, options); this.DynamicViews.push(dv); return dv; @@ -10604,7 +10702,7 @@ return /******/ (function(modules) { // webpackBootstrap this.commit(); this.dirty = true; // for autosave scenarios this.emit('update', doc); - + return doc; } catch (err) { this.rollback(); console.error(err.message); @@ -10736,7 +10834,7 @@ return /******/ (function(modules) { // webpackBootstrap position = arr[1]; var self = this; Object.keys(this.constraints.unique).forEach(function (key) { - if( doc[key] !== null && typeof doc[key] !== 'undefined' ) { + if (doc[key] !== null && typeof doc[key] !== 'undefined') { self.constraints.unique[key].remove(doc[key]); } }); @@ -10842,9 +10940,7 @@ return /******/ (function(modules) { // webpackBootstrap * @returns {Resultset} : (or data array if any map or join functions where called) */ Collection.prototype.chain = function (transform, parameters) { - var idx, - step, - rs = new Resultset(this, null, null); + var rs = new Resultset(this, null, null); if (typeof transform === 'undefined') { return rs; @@ -10860,33 +10956,7 @@ return /******/ (function(modules) { // webpackBootstrap // either they passed in raw transform array or we looked it up, so process if (typeof transform === 'object' && Array.isArray(transform)) { // if parameters were passed, apply them - if (typeof parameters !== 'undefined') { - transform = Utils.resolveTransformParams(transform, parameters); - } - - for(idx = 0; idx < transform.length; idx++) { - step = transform[idx]; - - switch (step.type) { - case "find" : rs.find(step.value); break; - case "where" : rs.where(step.value); break; - case "simplesort" : rs.simplesort(step.property, step.desc); break; - case "compoundsort" : rs.compoundsort(step.value); break; - case "sort" : rs.sort(step.value); break; - case "limit" : rs = rs.limit(step.value); break; // limit makes copy so update reference - case "offset" : rs = rs.offset(step.value); break; // offset makes copy so update reference - case "map" : rs = rs.map(step.value); break; - case "eqJoin" : rs = rs.eqJoin (step.joinData, step.leftJoinKey, step.rightJoinKey, step.mapFun); break; - // following cases break chain by returning array data so make any of these last in transform steps - case "mapReduce" : rs = rs.mapReduce(step.mapFunction, step.reduceFunction); break; - // following cases update documents in current filtered resultset (use carefully) - case "update" : rs.update(step.value); break; - case "remove" : rs.remove(); break; - default : break; - } - } - - return rs; + return rs.transform(transform, parameters); } return null; @@ -11311,7 +11381,7 @@ return /******/ (function(modules) { // webpackBootstrap UniqueIndex.prototype.keyMap = {}; UniqueIndex.prototype.lokiMap = {}; UniqueIndex.prototype.set = function (obj) { - if (obj[this.field] !== null && typeof(obj[this.field]) !== 'undefined') { + if (obj[this.field] !== null && typeof (obj[this.field]) !== 'undefined') { if (this.keyMap[obj[this.field]]) { throw new Error('Duplicate key for property ' + this.field + ': ' + obj[this.field]); } else { @@ -11339,7 +11409,7 @@ return /******/ (function(modules) { // webpackBootstrap }; UniqueIndex.prototype.remove = function (key) { var obj = this.keyMap[key]; - if( obj !== null && typeof obj !== 'undefined') { + if (obj !== null && typeof obj !== 'undefined') { this.keyMap[key] = undefined; this.lokiMap[obj.$loki] = undefined; } else { @@ -11576,7 +11646,7 @@ return /******/ (function(modules) { // webpackBootstrap IndexedAdapter.prototype.checkAvailability = function() { if (window && window.indexedDB) return true; - + return false; }; @@ -11592,7 +11662,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference so dont -need- callback in constructor - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11635,7 +11705,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference so dont -need- callback in constructor - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11664,7 +11734,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference so dont -need- callback in constructor - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11698,7 +11768,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference so dont -need- callback in constructor - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11742,7 +11812,7 @@ return /******/ (function(modules) { // webpackBootstrap var adapter = this; // lazy open/create db reference - if (this.catalog === null) { + if (this.catalog === null || this.catalog.db === null) { this.catalog = new LokiCatalog(function(cat) { adapter.catalog = cat; @@ -11784,7 +11854,7 @@ return /******/ (function(modules) { // webpackBootstrap } }); }; - + /** * LokiCatalog - underlying App/Key/Value catalog persistence * This non-interface class implements the actual persistence. @@ -11793,12 +11863,10 @@ return /******/ (function(modules) { // webpackBootstrap function LokiCatalog(callback) { this.db = null; - this.initializeLokiCatalog(callback); } - LokiCatalog.prototype.initializeLokiCatalog = function(callback) - { + LokiCatalog.prototype.initializeLokiCatalog = function(callback) { var openRequest = indexedDB.open('LokiCatalog', 1); var cat = this; @@ -12061,6 +12129,7 @@ return /******/ (function(modules) { // webpackBootstrap }; return IndexedAdapter; + }()); })); @@ -12277,7 +12346,21 @@ return /******/ (function(modules) { // webpackBootstrap } function wrapIndex(iter, index) { - return index >= 0 ? (+index) : ensureSize(iter) + (+index); + // This implements "is array index" which the ECMAString spec defines as: + // A String property name P is an array index if and only if + // ToString(ToUint32(P)) is equal to P and ToUint32(P) is not equal + // to 2^32−1. + // However note that we're currently calling ToNumber() instead of ToUint32() + // which should be improved in the future, as floating point numbers should + // not be accepted as an array index. + if (typeof index !== 'number') { + var numIndex = +index; + if ('' + numIndex !== index) { + return NaN; + } + index = numIndex; + } + return index < 0 ? ensureSize(iter) + index : index; } function returnTrue() { @@ -12947,7 +13030,7 @@ return /******/ (function(modules) { // webpackBootstrap var src_Math__imul = typeof Math.imul === 'function' && Math.imul(0xffffffff, 2) === -2 ? Math.imul : - function src_Math__imul(a, b) { + function imul(a, b) { a = a | 0; // int b = b | 0; // int var c = a & 0xffff; @@ -13498,6 +13581,15 @@ return /******/ (function(modules) { // webpackBootstrap function sliceFactory(iterable, begin, end, useKeys) { var originalSize = iterable.size; + // Sanitize begin & end using this shorthand for ToInt32(argument) + // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32 + if (begin !== undefined) { + begin = begin | 0; + } + if (end !== undefined) { + end = end | 0; + } + if (wholeSlice(begin, end, originalSize)) { return iterable; } @@ -13524,7 +13616,9 @@ return /******/ (function(modules) { // webpackBootstrap var sliceSeq = makeSequence(iterable); - sliceSeq.size = sliceSize; + // If iterable.size is undefined, the size of the realized sliceSeq is + // unknown at this point unless the number of items to slice is 0 + sliceSeq.size = sliceSize === 0 ? sliceSize : iterable.size && sliceSize || undefined; if (!useKeys && isSeq(iterable) && sliceSize >= 0) { sliceSeq.get = function (index, notSetValue) { @@ -13973,7 +14067,7 @@ return /******/ (function(modules) { // webpackBootstrap function src_Map__Map(value) { return value === null || value === undefined ? emptyMap() : - isMap(value) ? value : + isMap(value) && !isOrdered(value) ? value : emptyMap().withMutations(function(map ) { var iter = KeyedIterable(value); assertNotInfinite(iter.size); @@ -14820,12 +14914,12 @@ return /******/ (function(modules) { // webpackBootstrap List.prototype.get = function(index, notSetValue) { index = wrapIndex(this, index); - if (index < 0 || index >= this.size) { - return notSetValue; + if (index >= 0 && index < this.size) { + index += this._origin; + var node = listNodeFor(this, index); + return node && node.array[index & MASK]; } - index += this._origin; - var node = listNodeFor(this, index); - return node && node.array[index & MASK]; + return notSetValue; }; // @pragma Modification @@ -15021,29 +15115,25 @@ return /******/ (function(modules) { // webpackBootstrap }; VNode.prototype.removeAfter = function(ownerID, level, index) { - if (index === level ? 1 << level : 0 || this.array.length === 0) { + if (index === (level ? 1 << level : 0) || this.array.length === 0) { return this; } var sizeIndex = ((index - 1) >>> level) & MASK; if (sizeIndex >= this.array.length) { return this; } - var removingLast = sizeIndex === this.array.length - 1; + var newChild; if (level > 0) { var oldChild = this.array[sizeIndex]; newChild = oldChild && oldChild.removeAfter(ownerID, level - SHIFT, index); - if (newChild === oldChild && removingLast) { + if (newChild === oldChild && sizeIndex === this.array.length - 1) { return this; } } - if (removingLast && !newChild) { - return this; - } + var editable = editableVNode(this, ownerID); - if (!removingLast) { - editable.array.pop(); - } + editable.array.splice(sizeIndex + 1); if (newChild) { editable.array[sizeIndex] = newChild; } @@ -15135,6 +15225,10 @@ return /******/ (function(modules) { // webpackBootstrap function updateList(list, index, value) { index = wrapIndex(list, index); + if (index !== index) { + return list; + } + if (index >= list.size || index < 0) { return list.withMutations(function(list ) { index < 0 ? @@ -15226,6 +15320,14 @@ return /******/ (function(modules) { // webpackBootstrap } function setListBounds(list, begin, end) { + // Sanitize begin & end using this shorthand for ToInt32(argument) + // http://www.ecma-international.org/ecma-262/6.0/#sec-toint32 + if (begin !== undefined) { + begin = begin | 0; + } + if (end !== undefined) { + end = end | 0; + } var owner = list.__ownerID || new OwnerID(); var oldOrigin = list._origin; var oldCapacity = list._capacity; @@ -15738,7 +15840,7 @@ return /******/ (function(modules) { // webpackBootstrap function src_Set__Set(value) { return value === null || value === undefined ? emptySet() : - isSet(value) ? value : + isSet(value) && !isOrdered(value) ? value : emptySet().withMutations(function(set ) { var iter = SetIterable(value); assertNotInfinite(iter.size); @@ -16483,10 +16585,6 @@ return /******/ (function(modules) { // webpackBootstrap return reify(this, concatFactory(this, values)); }, - contains: function(searchValue) { - return this.includes(searchValue); - }, - includes: function(searchValue) { return this.some(function(value ) {return is(value, searchValue)}); }, @@ -16776,7 +16874,7 @@ return /******/ (function(modules) { // webpackBootstrap hashCode: function() { return this.__hash || (this.__hash = hashIterable(this)); - }, + } // ### Internal @@ -16799,6 +16897,7 @@ return /******/ (function(modules) { // webpackBootstrap IterablePrototype.inspect = IterablePrototype.toSource = function() { return this.toString(); }; IterablePrototype.chain = IterablePrototype.flatMap; + IterablePrototype.contains = IterablePrototype.includes; // Temporary warning about using length (function () { @@ -16869,7 +16968,7 @@ return /******/ (function(modules) { // webpackBootstrap function(k, v) {return mapper.call(context, k, v, this$0)} ).flip() ); - }, + } }); @@ -16924,7 +17023,10 @@ return /******/ (function(modules) { // webpackBootstrap if (numArgs === 0 || (numArgs === 2 && !removeNum)) { return this; } - index = resolveBegin(index, this.size); + // If index is negative, it should resolve relative to the size of the + // collection. However size may be expensive to compute if not cached, so + // only call count() if the number is in fact negative. + index = resolveBegin(index, index < 0 ? this.count() : this.size); var spliced = this.slice(0, index); return reify( this, @@ -16997,7 +17099,7 @@ return /******/ (function(modules) { // webpackBootstrap var iterables = arrCopy(arguments); iterables[0] = this; return reify(this, zipWithFactory(this, zipper, iterables)); - }, + } }); @@ -17023,7 +17125,7 @@ return /******/ (function(modules) { // webpackBootstrap keySeq: function() { return this.valueSeq(); - }, + } }); @@ -17127,7 +17229,7 @@ return /******/ (function(modules) { // webpackBootstrap Repeat: Repeat, is: is, - fromJS: fromJS, + fromJS: fromJS }; From ff932ad75a09699dd9c17aa84c673aa078a815ad Mon Sep 17 00:00:00 2001 From: remyyounes Date: Mon, 26 Oct 2015 22:36:43 -0700 Subject: [PATCH 3/4] fix empty data object for 404 --- dist/dataloader.min.js | 2 +- lib/components/FilteredDatasource.react.js | 2 +- public/assets/js/dataloader.min.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/dataloader.min.js b/dist/dataloader.min.js index 2a67ed7..e105f7c 100755 --- a/dist/dataloader.min.js +++ b/dist/dataloader.min.js @@ -17748,7 +17748,7 @@ return /******/ (function(modules) { // webpackBootstrap if (props.loadId) { query.loadId = props.loadId; } - if (props.data) { + if (!_.isEmpty(props.data)) { query[fkAttr] = props.data[idAttr]; } if (props.objectId) { diff --git a/lib/components/FilteredDatasource.react.js b/lib/components/FilteredDatasource.react.js index dffef11..fdcea25 100755 --- a/lib/components/FilteredDatasource.react.js +++ b/lib/components/FilteredDatasource.react.js @@ -112,7 +112,7 @@ var FilteredDatasource = React.createClass({ if (props.autoPopulate) { if (props.rootId) { query.rootId = props.rootId; } if (props.loadId) { query.loadId = props.loadId; } - if (props.data) { query[fkAttr] = props.data[idAttr]; } + if (!_.isEmpty(props.data)) { query[fkAttr] = props.data[idAttr]; } if (props.objectId) { query[fkAttr] = props.objectId; } dataSource.listenables.populate(query, params); diff --git a/public/assets/js/dataloader.min.js b/public/assets/js/dataloader.min.js index 2a67ed7..e105f7c 100644 --- a/public/assets/js/dataloader.min.js +++ b/public/assets/js/dataloader.min.js @@ -17748,7 +17748,7 @@ return /******/ (function(modules) { // webpackBootstrap if (props.loadId) { query.loadId = props.loadId; } - if (props.data) { + if (!_.isEmpty(props.data)) { query[fkAttr] = props.data[idAttr]; } if (props.objectId) { From dba710bbc6239a4895ad8e594144e0b893e7135d Mon Sep 17 00:00:00 2001 From: remyyounes Date: Tue, 27 Oct 2015 21:17:51 -0700 Subject: [PATCH 4/4] isValidUrl --- dist/dataloader.min.js | 16 +++++++++------- lib/services/client.js | 14 ++++++++------ lib/services/nsynchronizer.js | 1 - lib/services/procoreUrlBuilder.js | 2 +- public/assets/js/dataloader.min.js | 16 +++++++++------- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/dist/dataloader.min.js b/dist/dataloader.min.js index e105f7c..7679888 100755 --- a/dist/dataloader.min.js +++ b/dist/dataloader.min.js @@ -4011,7 +4011,6 @@ return /******/ (function(modules) { // webpackBootstrap populate: function populate(object, params) { var _this = this; - if (_.isEmpty(object) && _.isEmpty(params)) return; this.client.getAll(object, params).then(function (objects) { // @todo: find a better way to sync w/ remote // this.store.listenables.destroyAll(); @@ -4127,6 +4126,10 @@ return /******/ (function(modules) { // webpackBootstrap var _ = __webpack_require__(25); var reqwest = __webpack_require__(32); + var isValidUrl = function isValidUrl(url) { + return url.indexOf('undefined') === -1; + }; + /** * @class Client * @description REST Client for Dataloader @@ -4222,7 +4225,7 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } @@ -4246,7 +4249,7 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } @@ -4273,7 +4276,7 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } @@ -4297,7 +4300,7 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } @@ -4321,10 +4324,9 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } - return deferred.promise; } }]); diff --git a/lib/services/client.js b/lib/services/client.js index f5fb302..e5d4a81 100755 --- a/lib/services/client.js +++ b/lib/services/client.js @@ -2,6 +2,9 @@ let q = require('q'); let _ = require('underscore'); let reqwest = require('reqwest'); +const isValidUrl = url => { + return url.indexOf('undefined') === -1; +}; /** * @class Client @@ -76,7 +79,7 @@ class Client { error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { reqwest(params); } + if (isValidUrl(params.url)) { reqwest(params); } return deferred.promise; } @@ -96,7 +99,7 @@ class Client { error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { reqwest(params); } + if (isValidUrl(params.url)) { reqwest(params); } return deferred.promise; } @@ -117,7 +120,7 @@ class Client { error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { reqwest(params); } + if (isValidUrl(params.url)) { reqwest(params); } return deferred.promise; } @@ -137,7 +140,7 @@ class Client { error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { reqwest(params); } + if (isValidUrl(params.url)) { reqwest(params); } return deferred.promise; } @@ -157,8 +160,7 @@ class Client { error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { reqwest(params); } - + if (isValidUrl(params.url)) { reqwest(params); } return deferred.promise; } } diff --git a/lib/services/nsynchronizer.js b/lib/services/nsynchronizer.js index 9740efd..65a06a6 100755 --- a/lib/services/nsynchronizer.js +++ b/lib/services/nsynchronizer.js @@ -79,7 +79,6 @@ var Nsynchronizer = { * @public Populates store from remote */ populate(object, params) { - if (_.isEmpty(object) && _.isEmpty(params)) return; this.client.getAll(object, params) .then((objects) => { // @todo: find a better way to sync w/ remote diff --git a/lib/services/procoreUrlBuilder.js b/lib/services/procoreUrlBuilder.js index a915074..63c86ab 100755 --- a/lib/services/procoreUrlBuilder.js +++ b/lib/services/procoreUrlBuilder.js @@ -33,7 +33,7 @@ function procoreUrlBuilder(options) { else if (loadId) { url = `${getPath()}/${this.endpoint}/${loadId}`; } - else { + else if (!parentResource){ url = `${getPath()}/${this.endpoint}`; } diff --git a/public/assets/js/dataloader.min.js b/public/assets/js/dataloader.min.js index e105f7c..7679888 100644 --- a/public/assets/js/dataloader.min.js +++ b/public/assets/js/dataloader.min.js @@ -4011,7 +4011,6 @@ return /******/ (function(modules) { // webpackBootstrap populate: function populate(object, params) { var _this = this; - if (_.isEmpty(object) && _.isEmpty(params)) return; this.client.getAll(object, params).then(function (objects) { // @todo: find a better way to sync w/ remote // this.store.listenables.destroyAll(); @@ -4127,6 +4126,10 @@ return /******/ (function(modules) { // webpackBootstrap var _ = __webpack_require__(25); var reqwest = __webpack_require__(32); + var isValidUrl = function isValidUrl(url) { + return url.indexOf('undefined') === -1; + }; + /** * @class Client * @description REST Client for Dataloader @@ -4222,7 +4225,7 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } @@ -4246,7 +4249,7 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } @@ -4273,7 +4276,7 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } @@ -4297,7 +4300,7 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } @@ -4321,10 +4324,9 @@ return /******/ (function(modules) { // webpackBootstrap error: this._error.bind(null, deferred), success: this._success.bind(null, deferred) }; - if (params.url) { + if (isValidUrl(params.url)) { reqwest(params); } - return deferred.promise; } }]);