Comparing version 0.1.6 to 0.1.7
@@ -211,9 +211,2 @@ 'use strict'; | ||
} | ||
// async getDocById (collectionName, docId) { | ||
// let collection = this.getOrCreateCollection(collectionName) | ||
// | ||
// return collection[docId] | ||
// } | ||
}, { | ||
@@ -248,24 +241,6 @@ key: 'getAllDocs', | ||
}() | ||
// async getAllDocs (collectionName) { | ||
// return this.getDocsByQuery(collectionName, MongoQueries.allSelector) | ||
// } | ||
// async getDocsByQuery (collectionName, expression) { | ||
// let collection = this.getOrCreateCollection(collectionName) | ||
// | ||
// let allDocs = [] | ||
// for (let docId in collection) { | ||
// allDocs.push(collection[docId]) | ||
// } | ||
// | ||
// let docs = this.getQueryResultFromArray(allDocs, expression) | ||
// | ||
// return docs | ||
// } | ||
}, { | ||
key: 'saveDoc', | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(collectionName, docId, state, prevVersion, version, ops) { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(collectionName, docId, ops, serverVersion) { | ||
var doc, collection; | ||
@@ -278,11 +253,5 @@ return _regenerator2.default.wrap(function _callee6$(_context6) { | ||
_id: docId, | ||
// _v: version, | ||
_sv: prevVersion, | ||
_ops: ops | ||
_ops: ops, | ||
_sv: serverVersion | ||
}; | ||
// for (let key in state) { | ||
// doc[key] = state[key] | ||
// } | ||
collection = this.getOrCreateCollection(collectionName); | ||
@@ -303,3 +272,3 @@ | ||
})); | ||
return function saveDoc(_x3, _x4, _x5, _x6, _x7, _x8) { | ||
return function saveDoc(_x3, _x4, _x5, _x6) { | ||
return ref.apply(this, arguments); | ||
@@ -306,0 +275,0 @@ }; |
@@ -7,75 +7,11 @@ 'use strict'; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _Model = require('../client/Model'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var initModel = function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var storage, source, projectionHashes; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
storage = new _SqliteStorage2.default(['_app', '_session']); | ||
model.storage = storage; | ||
_context.next = 4; | ||
return storage.init(); | ||
case 4: | ||
_context.next = 6; | ||
return model.collectionSet.fillFromClientStorage(); | ||
case 6: | ||
model.set('_session.online', false); | ||
source = model.get('_app.source'); | ||
if (!source) { | ||
source = model.id(); | ||
model.source = source; | ||
model.set('_app.source', source); | ||
} else { | ||
model.source = source; | ||
} | ||
projectionHashes = model.get('_app.newProjectionHashes'); | ||
model.set('_app.projectionHashes', projectionHashes); | ||
case 11: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function initModel() { | ||
return ref.apply(this, arguments); | ||
}; | ||
}(); | ||
var _Model = require('../Model'); | ||
var _Model2 = _interopRequireDefault(_Model); | ||
var _reconnectableWebsocket = require('reconnectable-websocket'); | ||
var _WebSocketChannel = require('../client/WebSocketChannel'); | ||
var _reconnectableWebsocket2 = _interopRequireDefault(_reconnectableWebsocket); | ||
var _WebSocketChannel = require('../WebSocketChannel'); | ||
var _WebSocketChannel2 = _interopRequireDefault(_WebSocketChannel); | ||
var _SqliteStorage = require('./SqliteStorage'); | ||
var _SqliteStorage = require('../web/SqliteStorage'); | ||
@@ -86,3 +22,5 @@ var _SqliteStorage2 = _interopRequireDefault(_SqliteStorage); | ||
var model = undefined; | ||
function getStorage(collectionNames) { | ||
return new _SqliteStorage2.default(collectionNames); | ||
} | ||
@@ -92,35 +30,17 @@ function getModel(channel) { | ||
if (model) return model; | ||
var ws = undefined; | ||
if (!channel) { | ||
var wsUrl = options.wsUrl || 'ws://localhost:3000'; | ||
var url = options.url || 'ws://localhost:3000'; | ||
var wsOptions = { | ||
automaticOpen: false, | ||
reconnectOnError: true, | ||
reconnectInterval: 3000 | ||
}; | ||
ws = new _reconnectableWebsocket2.default(wsUrl, null, wsOptions); | ||
channel = new _WebSocketChannel2.default(ws); | ||
channel = new _WebSocketChannel2.default(url, options.ws); | ||
} | ||
model = new _Model2.default(channel); | ||
var model = new _Model2.default(channel, options.source, options.model); | ||
window.model = model; | ||
var initPromise = new _promise2.default(function (resolve, reject) { | ||
initModel().then(function () { | ||
if (ws) ws.open(); | ||
resolve(); | ||
}).catch(function (err) { | ||
console.error(err, err.stack); | ||
reject(err); | ||
}); | ||
}); | ||
model.getStorage = getStorage; | ||
model.init = function () { | ||
return initPromise; | ||
}; | ||
setTimeout(function () { | ||
return channel.open(); | ||
}, 0); | ||
@@ -127,0 +47,0 @@ return model; |
@@ -344,13 +344,2 @@ 'use strict'; | ||
}() | ||
// async getDocById (collectionName, docId) { | ||
// let args = await this.db.executeSql(`SELECT * FROM ${collectionName} WHERE _id = '${docId}'`) | ||
// let rows = this.getQueryRows(args) | ||
// let row = rows[0] | ||
// if (!row || !row.data) return | ||
// | ||
// let doc = JSON.parse(row.data) | ||
// return doc | ||
// } | ||
}, { | ||
@@ -452,27 +441,6 @@ key: 'getAllDocs', | ||
}() | ||
// async getAllDocs (collectionName) { | ||
// return this.getDocsByQuery(collectionName, MongoQueries.allSelector) | ||
// } | ||
// async getDocsByQuery (collectionName, expression) { | ||
// let args = await this.db.executeSql(`SELECT * FROM ${collectionName}`) | ||
// let rows = this.getQueryRows(args) | ||
// | ||
// let allDocs = [] | ||
// for (let row of rows) { | ||
// if (!row.data) continue | ||
// let doc = JSON.parse(row.data) | ||
// allDocs.push(doc) | ||
// } | ||
// | ||
// let docs = this.getQueryResultFromArray(allDocs, expression) | ||
// | ||
// return docs | ||
// } | ||
}, { | ||
key: 'saveDoc', | ||
value: function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(collectionName, docId, state, prevVersion, version, ops) { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(collectionName, docId, ops, serverVersion) { | ||
var doc, data; | ||
@@ -485,11 +453,5 @@ return _regenerator2.default.wrap(function _callee8$(_context8) { | ||
_id: docId, | ||
// _v: version, | ||
_sv: prevVersion, | ||
_ops: ops | ||
_ops: ops, | ||
_sv: serverVersion | ||
}; | ||
// for (let key in state) { | ||
// doc[key] = state[key] | ||
// } | ||
data = (0, _stringify2.default)(doc); | ||
@@ -520,3 +482,3 @@ | ||
})); | ||
return function saveDoc(_x5, _x6, _x7, _x8, _x9, _x10) { | ||
return function saveDoc(_x5, _x6, _x7, _x8) { | ||
return ref.apply(this, arguments); | ||
@@ -523,0 +485,0 @@ }; |
@@ -7,6 +7,2 @@ 'use strict'; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
@@ -16,6 +12,2 @@ | ||
var _from = require('babel-runtime/core-js/array/from'); | ||
var _from2 = _interopRequireDefault(_from); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
@@ -25,6 +17,4 @@ | ||
var initModel = function () { | ||
var onBundleReady = function () { | ||
var ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var _ref, clientStorage, collectionNames, version, storage, newProjectionHashes, source, projectionHashes; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
@@ -35,61 +25,5 @@ while (1) { | ||
_context.next = 2; | ||
return (0, _util.onDomReady)(); | ||
return (0, _dom.onDomReady)(); | ||
case 2: | ||
// unbundle _app.clientStorage, _app.collectionNames, _app.version and _app.newProjectionHashes | ||
model.unbundleLocalData(); | ||
_ref = model.get('_app') || {}; | ||
clientStorage = _ref.clientStorage; | ||
collectionNames = _ref.collectionNames; | ||
version = _ref.version; | ||
if (!clientStorage) { | ||
_context.next = 19; | ||
break; | ||
} | ||
storage = new _IndexedDbStorage2.default((0, _from2.default)(collectionNames).concat(['_app', '_session']), version); | ||
model.storage = storage; | ||
_context.next = 12; | ||
return storage.init(); | ||
case 12: | ||
_context.next = 14; | ||
return model.collectionSet.fillLocalCollectionsFromClientStorage(); | ||
case 14: | ||
// clear collections in storage, where projections have changed | ||
newProjectionHashes = model.get('_app.newProjectionHashes'); | ||
_context.next = 17; | ||
return model.onProjections(newProjectionHashes); | ||
case 17: | ||
_context.next = 19; | ||
return model.collectionSet.fillFromClientStorage(); | ||
case 19: | ||
model.set('_session.online', false); | ||
source = model.get('_app.source'); | ||
if (!source) { | ||
source = model.id(); | ||
model.source = source; | ||
model.set('_app.source', source); | ||
} else { | ||
model.source = source; | ||
} | ||
projectionHashes = model.get('_app.newProjectionHashes'); | ||
model.set('_app.projectionHashes', projectionHashes); | ||
model.unbundleData(); | ||
case 25: | ||
case 'end': | ||
@@ -101,3 +35,3 @@ return _context.stop(); | ||
})); | ||
return function initModel() { | ||
return function onBundleReady() { | ||
return ref.apply(this, arguments); | ||
@@ -107,23 +41,21 @@ }; | ||
var _IndexedDbStorage = require('../IndexedDbStorage'); | ||
var _Model = require('../client/Model'); | ||
var _IndexedDbStorage2 = _interopRequireDefault(_IndexedDbStorage); | ||
var _Model = require('../Model'); | ||
var _Model2 = _interopRequireDefault(_Model); | ||
var _reconnectableWebsocket = require('reconnectable-websocket'); | ||
var _WebSocketChannel = require('../client/WebSocketChannel'); | ||
var _reconnectableWebsocket2 = _interopRequireDefault(_reconnectableWebsocket); | ||
var _WebSocketChannel2 = _interopRequireDefault(_WebSocketChannel); | ||
var _WebSocketChannel = require('../WebSocketChannel'); | ||
var _IndexedDbStorage = require('../web/IndexedDbStorage'); | ||
var _WebSocketChannel2 = _interopRequireDefault(_WebSocketChannel); | ||
var _IndexedDbStorage2 = _interopRequireDefault(_IndexedDbStorage); | ||
var _util = require('../util'); | ||
var _dom = require('../web/dom'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var model = undefined; | ||
function getStorage(collectionNames, version) { | ||
return new _IndexedDbStorage2.default(collectionNames, version); | ||
} | ||
@@ -133,35 +65,19 @@ function getModel(channel) { | ||
if (model) return model; | ||
var ws = undefined; | ||
if (!channel) { | ||
var wsUrl = options.wsUrl || 'ws://' + window.location.host; | ||
var url = options.url || 'ws://' + window.location.host; | ||
var wsOptions = { | ||
automaticOpen: false, | ||
reconnectOnError: true, | ||
reconnectInterval: 3000 | ||
}; | ||
ws = new _reconnectableWebsocket2.default(wsUrl, null, wsOptions); | ||
channel = new _WebSocketChannel2.default(ws); | ||
channel = new _WebSocketChannel2.default(url, options.ws); | ||
} | ||
model = new _Model2.default(channel); | ||
var model = new _Model2.default(channel, options.source, options.model); | ||
window.model = model; | ||
var initPromise = new _promise2.default(function (resolve, reject) { | ||
initModel().then(function () { | ||
if (ws) ws.open(); | ||
resolve(); | ||
}).catch(function (err) { | ||
console.error(err, err.stack); | ||
reject(err); | ||
}); | ||
}); | ||
model.getStorage = getStorage; | ||
model.onBundleReady = onBundleReady; | ||
model.getBundleJsonFromDom = _dom.getBundleJsonFromDom; | ||
model.init = function () { | ||
return initPromise; | ||
}; | ||
setTimeout(function () { | ||
return channel.open(); | ||
}, 0); | ||
@@ -168,0 +84,0 @@ return model; |
@@ -7,6 +7,2 @@ 'use strict'; | ||
var _promise = require('babel-runtime/core-js/promise'); | ||
var _promise2 = _interopRequireDefault(_promise); | ||
var _from = require('babel-runtime/core-js/array/from'); | ||
@@ -43,8 +39,3 @@ | ||
function serverRequire(module, id) { | ||
if (!isServer) return; | ||
return module.require(id); | ||
} | ||
function clone(object) { | ||
function deepClone(object) { | ||
if (object == null || (typeof object === 'undefined' ? 'undefined' : (0, _typeof3.default)(object)) !== 'object') return object; | ||
@@ -55,10 +46,2 @@ | ||
function shallowClone(object) { | ||
var out = {}; | ||
for (var key in object) { | ||
out[key] = object[key]; | ||
} | ||
return out; | ||
} | ||
function fastEqual(object1, object2) { | ||
@@ -94,25 +77,12 @@ return (0, _stringify2.default)(object1) === (0, _stringify2.default)(object2); | ||
function onDomReady() { | ||
return new _promise2.default(function (resolve, reject) { | ||
if (document.readyState === 'complete') { | ||
resolve(); | ||
} else { | ||
window.addEventListener('load', resolve, false); | ||
} | ||
}); | ||
} | ||
exports.default = { | ||
arrayRemove: arrayRemove, | ||
clone: clone, | ||
deepClone: deepClone, | ||
dbFields: dbFields, | ||
fastEqual: fastEqual, | ||
isServer: isServer, | ||
shallowClone: shallowClone, | ||
serverRequire: serverRequire, | ||
isLocalCollection: isLocalCollection, | ||
parsePath: parsePath, | ||
parseArguments: parseArguments, | ||
onDomReady: onDomReady | ||
parseArguments: parseArguments | ||
}; | ||
module.exports = exports['default']; |
{ | ||
"name": "amelisa", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "", | ||
@@ -46,2 +46,3 @@ "main": "lib/index.js", | ||
"fake-indexeddb": "^1.0.3", | ||
"localStorage": "^1.0.3", | ||
"mocha": "^2.3.0", | ||
@@ -48,0 +49,0 @@ "node-jsdom": "^3.1.5", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
347489
60
8412
24
1