Socket
Socket
Sign inDemoInstall

twilio-sync

Package Overview
Dependencies
Maintainers
2
Versions
608
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twilio-sync - npm Package Compare versions

Comparing version 0.4.2-dev.5-build.202 to 0.4.2-test.1

237

browser/client.js
"use strict";
var _stringify = require("babel-runtime/core-js/json/stringify");
var _stringify2 = _interopRequireDefault(_stringify);
var _regenerator = require("babel-runtime/regenerator");

@@ -88,6 +92,6 @@

if (!arg) {
return { id: null, purpose: null, data: null, context: null, mode: null };
return { id: null, purpose: null, data: null, context: null, mode: null, optimistic: false };
}
if (typeof arg === 'string') {
return { id: arg, purpose: null, data: null, context: null, mode: null };
return { id: arg, purpose: null, data: null, context: null, mode: null, optimistic: false };
}

@@ -98,3 +102,4 @@ return { id: arg.uniqueName || arg.sid || arg.id,

context: arg.context,
mode: arg.mode
mode: arg.mode,
optimistic: arg.optimistic
};

@@ -130,2 +135,3 @@ }

}
_this.serviceSid = null;
var productId = options.productId = options.productId || SYNC_PRODUCT_ID;

@@ -187,3 +193,3 @@ var twilsock = options.twilsockClient = options.twilsockClient || new Twilsock(fpaToken, options);

return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee() {
var uri, response, objects;
var uri, response, objects, result;
return _regenerator2.default.wrap(function _callee$(_context) {

@@ -208,5 +214,11 @@ while (1) {

objects = response.body.documents || response.body.lists || response.body.maps || [];
return _context.abrupt("return", objects.length === 0 ? null : objects[0]);
result = objects.length === 0 ? null : objects[0];
// Hacky optimization - here we learn the service sid
case 8:
if (result && result.service_sid && !this.serviceSid) {
this.serviceSid = result.service_sid;
}
return _context.abrupt("return", { root: result, items: [] });
case 10:
case "end":

@@ -230,3 +242,9 @@ return _context.stop();

value: function _getDocument(id) {
return this._get(this.services.config.documentsUri, id);
var cachedRoot = this.getRoot(id, 'document');
if (cachedRoot) {
return cachedRoot;
}
return this._get(this.services.config.documentsUri, id).then(function (body) {
return body.root;
});
}

@@ -244,3 +262,9 @@ }, {

value: function _getList(id) {
return this._get(this.services.config.listsUri, id);
var cachedRoot = this.getRoot(id, 'list');
if (cachedRoot) {
return cachedRoot;
}
return this._get(this.services.config.listsUri, id).then(function (body) {
return body.root;
});
}

@@ -252,3 +276,3 @@ }, {

return this.services.network.post(this.services.config.mapsUri, payload).then(function (response) {
return response.body;
return { root: response.body, items: [] };
});

@@ -259,3 +283,57 @@ }

value: function _getMap(id) {
return this._get(this.services.config.mapsUri, id);
var optimistic = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee2() {
var url, response, cachedRoot;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
if (id) {
_context2.next = 2;
break;
}
return _context2.abrupt("return", null);
case 2:
if (!(optimistic && this.serviceSid)) {
_context2.next = 14;
break;
}
_context2.prev = 3;
url = new utils_1.UriBuilder(this.services.config.baseUri).path('v3').path('Services').path(this.serviceSid).path('Maps').path(id).path('Items').arg('Metadata', 'map').build();
_context2.next = 7;
return this.services.network.get(url);
case 7:
response = _context2.sent;
return _context2.abrupt("return", { root: response.body.map, items: response.body.items });
case 11:
_context2.prev = 11;
_context2.t0 = _context2["catch"](3);
return _context2.abrupt("return", null);
case 14:
cachedRoot = this.getRoot(id, 'map');
if (!cachedRoot) {
_context2.next = 17;
break;
}
return _context2.abrupt("return", { root: cachedRoot, items: [] });
case 17:
return _context2.abrupt("return", this._get(this.services.config.mapsUri, id));
case 18:
case "end":
return _context2.stop();
}
}
}, _callee2, this, [[3, 11]]);
}));
}

@@ -282,3 +360,3 @@ }, {

value: function document(arg) {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee2() {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee3() {
var _this3 = this;

@@ -288,7 +366,7 @@

return _regenerator2.default.wrap(function _callee2$(_context2) {
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context2.prev = _context2.next) {
switch (_context3.prev = _context3.next) {
case 0:
_context2.next = 2;
_context3.next = 2;
return this.ensureReady();

@@ -298,3 +376,3 @@

_decompose = decompose(arg), id = _decompose.id, purpose = _decompose.purpose, data = _decompose.data, mode = _decompose.mode;
return _context2.abrupt("return", this.getCached(id, 'document') || this._getDocument(id).then(function (body) {
return _context3.abrupt("return", this.getCached(id, 'document') || this._getDocument(id).then(function (body) {
if (body) {

@@ -307,2 +385,3 @@ return body;

}).then(function (body) {
_this3.storeRoot(id, 'document', body);
return new syncdocument_1.SyncDocument(_this3.services, body, function (sid) {

@@ -317,6 +396,6 @@ return _this3.removeFromCache(sid);

case "end":
return _context2.stop();
return _context3.stop();
}
}
}, _callee2, this);
}, _callee3, this);
}));

@@ -334,37 +413,58 @@ }

value: function map(arg) {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee3() {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee4() {
var _this4 = this;
var _decompose2, id, purpose, context, mode;
var _decompose2, id, purpose, context, mode, optimistic, cachedMap, map;
return _regenerator2.default.wrap(function _callee3$(_context3) {
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context4.prev = _context4.next) {
case 0:
_context3.next = 2;
_context4.next = 2;
return this.ensureReady();
case 2:
_decompose2 = decompose(arg), id = _decompose2.id, purpose = _decompose2.purpose, context = _decompose2.context, mode = _decompose2.mode;
return _context3.abrupt("return", this.getCached(id, 'map') || this._getMap(id).then(function (body) {
if (body) {
_decompose2 = decompose(arg), id = _decompose2.id, purpose = _decompose2.purpose, context = _decompose2.context, mode = _decompose2.mode, optimistic = _decompose2.optimistic;
cachedMap = this.getCached(id, 'map');
if (!cachedMap) {
_context4.next = 6;
break;
}
return _context4.abrupt("return", cachedMap);
case 6:
console.log('----------xxxx1');
_context4.next = 9;
return this._getMap(id, optimistic).then(function (body) {
console.log('----------xxxx1', body);
if (body.root) {
return body;
} else if (mode !== 'open') {
return _this4._createMap(id, purpose, context);
}
throw new syncerror_1.default('Not found', 404);
}).then(function (body) {
return new syncmap_1.SyncMap(_this4.services, body, function (sid) {
if (mode === 'open') {
throw new syncerror_1.default('Not found', 404);
}
console.log('Creating');
return _this4._createMap(id, purpose, context);
}).then(function (map) {
_this4.storeRoot(id, 'map', map.root);
return new syncmap_1.SyncMap(_this4.services, map.root, map.items, function (sid) {
return _this4.removeFromCache(sid);
});
}).then(function (entity) {
return _this4.entities.store(entity);
}).then(subscribe));
});
case 4:
case 9:
map = _context4.sent;
this.entities.store(map);
subscribe(map);
return _context4.abrupt("return", map);
case 13:
case "end":
return _context3.stop();
return _context4.stop();
}
}
}, _callee3, this);
}, _callee4, this);
}));

@@ -382,3 +482,3 @@ }

value: function list(arg) {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee4() {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee5() {
var _this5 = this;

@@ -388,7 +488,7 @@

return _regenerator2.default.wrap(function _callee4$(_context4) {
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context5.prev = _context5.next) {
case 0:
_context4.next = 2;
_context5.next = 2;
return this.ensureReady();

@@ -398,3 +498,3 @@

_decompose3 = decompose(arg), id = _decompose3.id, purpose = _decompose3.purpose, context = _decompose3.context, mode = _decompose3.mode;
return _context4.abrupt("return", this.getCached(id, 'list') || this._getList(id).then(function (body) {
return _context5.abrupt("return", this.getCached(id, 'list') || this._getList(id).then(function (body) {
if (body) {

@@ -407,2 +507,3 @@ return body;

}).then(function (body) {
_this5.storeRoot(id, 'list', body);
return new synclist_1.SyncList(_this5.services, body, function (sid) {

@@ -417,6 +518,6 @@ return _this5.removeFromCache(sid);

case "end":
return _context4.stop();
return _context5.stop();
}
}
}, _callee4, this);
}, _callee5, this);
}));

@@ -434,12 +535,12 @@ }

value: function shutdown() {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee5() {
return _regenerator2.default.wrap(function _callee5$(_context5) {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee6() {
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context6.prev = _context6.next) {
case 0:
_context5.next = 2;
_context6.next = 2;
return this.services.subscriptions.shutdown();
case 2:
_context5.next = 4;
_context6.next = 4;
return this.services.twilsock.disconnect();

@@ -449,6 +550,6 @@

case "end":
return _context5.stop();
return _context6.stop();
}
}
}, _callee5, this);
}, _callee6, this);
}));

@@ -466,9 +567,9 @@ }

value: function updateToken(fpaToken) {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee6() {
return _regenerator2.default.wrap(function _callee6$(_context6) {
return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee7() {
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
switch (_context6.prev = _context6.next) {
switch (_context7.prev = _context7.next) {
case 0:
this.fpaToken = fpaToken;
_context6.next = 3;
_context7.next = 3;
return _promise2.default.all([this.services.config.updateToken(fpaToken), this.services.notifications.updateToken(fpaToken), this.services.twilsock.updateToken(fpaToken)]);

@@ -478,9 +579,33 @@

case "end":
return _context6.stop();
return _context7.stop();
}
}
}, _callee6, this);
}, _callee7, this);
}));
}
}, {
key: "storeRoot",
value: function storeRoot(id, type, object) {
try {
if (sessionStorage) {
var entryId = type + '::' + id;
sessionStorage.setItem(entryId, (0, _stringify2.default)(object));
}
} catch (e) {}
}
}, {
key: "getRoot",
value: function getRoot(id, type) {
try {
if (sessionStorage) {
var entryId = type + '::' + id;
var data = sessionStorage.getItem(entryId);
if (data) {
return JSON.parse(data);
}
}
} catch (e) {}
return null;
}
}, {
key: "connectionState",

@@ -487,0 +612,0 @@ get: function get() {

@@ -33,2 +33,3 @@ "use strict";

this.settings = {
baseUri: baseUri,
subscriptionsUri: baseUri + SUBSCRIPTIONS_PATH,

@@ -52,2 +53,7 @@ documentsUri: baseUri + DOCUMENTS_PATH,

}, {
key: 'baseUri',
get: function get() {
return this.settings.baseUri;
}
}, {
key: 'subscriptionsUri',

@@ -54,0 +60,0 @@ get: function get() {

@@ -22,59 +22,61 @@ "use strict";

var MapItem = function () {
/**
* @private
* @constructor
* @param {Object} data Item descriptor
* @param {String} data.key Item identifier
* @param {String} data.uri Item URI
* @param {Object} data.value Item data
*/
function MapItem(data) {
(0, _classCallCheck3.default)(this, MapItem);
this.data = data;
}
(0, _createClass3.default)(MapItem, [{
key: "update",
/**
* Update item data
* @param {Number} EventId Update event id
* @param {String} Revision Updated item revision
* @param {Object} Value Updated item data
* @private
* @constructor
* @param {Object} data Item descriptor
* @param {String} data.key Item identifier
* @param {String} data.uri Item URI
* @param {Object} data.value Item data
*/
value: function update(eventId, revision, value) {
this.data.lastEventId = eventId;
this.data.revision = revision;
this.data.value = value;
return this;
function MapItem(data) {
(0, _classCallCheck3.default)(this, MapItem);
this.data = data;
}
}, {
key: "uri",
get: function get() {
return this.data.uri;
}
}, {
key: "revision",
get: function get() {
return this.data.revision;
}
}, {
key: "lastEventId",
get: function get() {
return this.data.lastEventId;
}
}, {
key: "key",
get: function get() {
return this.data.key;
}
}, {
key: "value",
get: function get() {
return this.data.value;
}
}]);
return MapItem;
(0, _createClass3.default)(MapItem, [{
key: "update",
/**
* Update item data
* @param {Number} EventId Update event id
* @param {String} Revision Updated item revision
* @param {Object} Value Updated item data
* @private
*/
value: function update(eventId, revision, value) {
if (eventId > this.data.last_event_id) {
this.data.last_event_id = eventId;
this.data.revision = revision;
this.data.data = value;
}
return this;
}
}, {
key: "uri",
get: function get() {
return this.data.url;
}
}, {
key: "revision",
get: function get() {
return this.data.revision;
}
}, {
key: "lastEventId",
get: function get() {
return this.data.last_event_id;
}
}, {
key: "key",
get: function get() {
return this.data.key;
}
}, {
key: "value",
get: function get() {
return this.data.data;
}
}]);
return MapItem;
}();

@@ -81,0 +83,0 @@

@@ -91,3 +91,3 @@ "use strict";

*/
function SyncMap(services, descriptor, onRemoveMap) {
function SyncMap(services, descriptor, items, onRemoveMap) {
(0, _classCallCheck3.default)(this, SyncMap);

@@ -97,2 +97,3 @@

console.log('Got descriptor', descriptor);
_this.actionQueue = new retryingqueue_1.RetryingQueue();

@@ -102,2 +103,3 @@ _this.cache = new cache_1.Cache();

_this.onRemoveMap = onRemoveMap;
_this.populateItems(items);
return _this;

@@ -107,2 +109,11 @@ }

(0, _createClass3.default)(SyncMap, [{
key: "populateItems",
value: function populateItems(items) {
var _this2 = this;
items.forEach(function (item) {
return _this2.cache.store(item.key, new mapitem_1.MapItem(item), item.last_event_id);
});
}
}, {
key: "_get",

@@ -135,3 +146,3 @@ value: function _get(key) {

return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee2() {
var _this2 = this;
var _this3 = this;

@@ -153,3 +164,3 @@ var _resolver;

_resolver = function _resolver(err) {
return __awaiter(_this2, void 0, void 0, _regenerator2.default.mark(function _callee() {
return __awaiter(_this3, void 0, void 0, _regenerator2.default.mark(function _callee() {
var item;

@@ -284,3 +295,3 @@ return _regenerator2.default.wrap(function _callee$(_context) {

return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee4() {
var _this3 = this;
var _this4 = this;

@@ -301,3 +312,3 @@ var uri, response;

response.body.events.forEach(function (ev) {
return _this3._update(ev);
return _this4._update(ev);
});

@@ -414,3 +425,3 @@ _context4.next = 12;

return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee7() {
var item, arg, response, _ref, added, result, descriptor;
var item, arg, response, _ref, added, descriptor;

@@ -446,18 +457,13 @@ return _regenerator2.default.wrap(function _callee7$(_context7) {

added = _ref.added;
result = _ref.value;
descriptor = { key: result.key,
revision: result.revision,
lastEventId: result.last_event_id,
uri: result.url,
value: result.data };
_context7.next = 17;
descriptor = _ref.value;
_context7.next = 16;
return this.cache.get(key);
case 17:
case 16:
item = _context7.sent;
if (item && descriptor.lastEventId > item.lastEventId) {
item.update(descriptor.lastEventId, descriptor.revision, descriptor.value);
if (item) {
item.update(descriptor.last_event_id, descriptor.revision, descriptor.data);
} else if (!item) {
item = this.cache.store(key, new mapitem_1.MapItem(descriptor), descriptor.lastEventId);
item = this.cache.store(key, new mapitem_1.MapItem(descriptor), descriptor.last_event_id);
if (added) {

@@ -471,3 +477,3 @@ this.emit('itemAdded', item, true);

case 20:
case 19:
case "end":

@@ -637,3 +643,3 @@ return _context7.stop();

return __awaiter(this, void 0, void 0, _regenerator2.default.mark(function _callee12() {
var _this4 = this;
var _this5 = this;

@@ -653,11 +659,7 @@ var uri, response, items, meta;

items = response.body.items.map(function (el) {
return _this4.cache.store(el.key, new mapitem_1.MapItem({ key: el.key,
uri: el.url,
revision: el.revision,
lastEventId: el.last_event_id,
value: el.data }), el.last_event_id);
return _this5.cache.store(el.key, new mapitem_1.MapItem(el), el.last_event_id);
});
meta = response.body.meta;
return _context12.abrupt("return", new paginator_1.Paginator(items, function (pageToken) {
return _this4.queryItems({ pageToken: pageToken });
return _this5.queryItems({ pageToken: pageToken });
}, meta.previous_token, meta.next_token));

@@ -761,3 +763,3 @@

value: function forEach(handler) {
var _this5 = this;
var _this6 = this;

@@ -775,3 +777,3 @@ return new _promise2.default(function (resolve, reject) {

}
_this5.queryItems().then(processPage).catch(reject);
_this6.queryItems().then(processPage).catch(reject);
});

@@ -833,3 +835,3 @@ }

if (!this.cache.has(key) && !this.shouldIgnoreEvent(key, eventId)) {
var item = new mapitem_1.MapItem({ key: key, uri: uri, lastEventId: eventId, revision: revision, value: value });
var item = new mapitem_1.MapItem({ key: key, url: uri, last_event_id: eventId, revision: revision, data: value });
this.cache.store(key, item, eventId);

@@ -850,3 +852,3 @@ this.emit('itemAdded', item, false);

if (!item && !this.shouldIgnoreEvent(key, eventId)) {
item = new mapitem_1.MapItem({ key: key, uri: uri, lastEventId: eventId, revision: revision, value: value });
item = new mapitem_1.MapItem({ key: key, url: uri, last_event_id: eventId, revision: revision, data: value });
this.cache.store(key, item, eventId);

@@ -853,0 +855,0 @@ this.emit('itemUpdated', item, false);

@@ -37,5 +37,12 @@ "use strict";

this.args = new Array();
this.paths = new Array();
}
(0, _createClass3.default)(UriBuilder, [{
key: 'path',
value: function path(name) {
this.paths.push(name);
return this;
}
}, {
key: 'arg',

@@ -51,3 +58,10 @@ value: function arg(name, value) {

value: function build() {
return this.args.length === 0 ? this.base : this.base + '?' + this.args.join('&');
var result = this.base;
if (this.paths.length) {
result += '/' + this.paths.join('/');
}
if (this.args.length) {
result += '?' + this.args.join('&');
}
return result;
}

@@ -54,0 +68,0 @@ }]);

@@ -17,2 +17,3 @@ /// <reference types="node" />

private fpaToken;
private serviceSid;
constructor(fpaToken: string, options?: any);

@@ -38,3 +39,3 @@ /**

private _createMap(id, purpose, context);
private _getMap(id);
private _getMap(id, optimistic?);
private getCached<T>(id, type);

@@ -77,2 +78,4 @@ private removeFromCache(sid);

updateToken(fpaToken: any): Promise<void>;
private storeRoot(id, type, object);
private getRoot(id, type);
}

@@ -79,0 +82,0 @@ declare module SyncClient {

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

if (!arg) {
return { id: null, purpose: null, data: null, context: null, mode: null };
return { id: null, purpose: null, data: null, context: null, mode: null, optimistic: false };
}
if (typeof arg === 'string') {
return { id: arg, purpose: null, data: null, context: null, mode: null };
return { id: arg, purpose: null, data: null, context: null, mode: null, optimistic: false };
}

@@ -51,3 +51,4 @@ return { id: arg.uniqueName || arg.sid || arg.id,

context: arg.context,
mode: arg.mode
mode: arg.mode,
optimistic: arg.optimistic
};

@@ -76,2 +77,3 @@ }

}
this.serviceSid = null;
let productId = options.productId = options.productId || SYNC_PRODUCT_ID;

@@ -127,3 +129,8 @@ let twilsock = options.twilsockClient = options.twilsockClient || new Twilsock(fpaToken, options);

let objects = (response.body.documents || response.body.lists || response.body.maps || []);
return objects.length === 0 ? null : objects[0];
let result = objects.length === 0 ? null : objects[0];
// Hacky optimization - here we learn the service sid
if (result && result.service_sid && !this.serviceSid) {
this.serviceSid = result.service_sid;
}
return { root: result, items: [] };
});

@@ -136,3 +143,7 @@ }

_getDocument(id) {
return this._get(this.services.config.documentsUri, id);
let cachedRoot = this.getRoot(id, 'document');
if (cachedRoot) {
return cachedRoot;
}
return this._get(this.services.config.documentsUri, id).then(body => body.root);
}

@@ -144,10 +155,43 @@ _createList(id, purpose, context) {

_getList(id) {
return this._get(this.services.config.listsUri, id);
let cachedRoot = this.getRoot(id, 'list');
if (cachedRoot) {
return cachedRoot;
}
return this._get(this.services.config.listsUri, id).then(body => body.root);
}
_createMap(id, purpose, context) {
let payload = createPayload(id, purpose, context);
return this.services.network.post(this.services.config.mapsUri, payload).then(response => response.body);
return this.services.network.post(this.services.config.mapsUri, payload)
.then(response => ({ root: response.body, items: [] }));
}
_getMap(id) {
return this._get(this.services.config.mapsUri, id);
_getMap(id, optimistic = false) {
return __awaiter(this, void 0, void 0, function* () {
if (!id) {
return null;
}
if (optimistic && this.serviceSid) {
// Hacky optimization - here we use service sid
try {
let url = new utils_1.UriBuilder(this.services.config.baseUri)
.path('v3')
.path('Services')
.path(this.serviceSid)
.path('Maps')
.path(id)
.path('Items')
.arg('Metadata', 'map')
.build();
let response = yield this.services.network.get(url);
return { root: response.body.map, items: response.body.items };
}
catch (e) {
return null;
}
}
let cachedRoot = this.getRoot(id, 'map');
if (cachedRoot) {
return { root: cachedRoot, items: [] };
}
return this._get(this.services.config.mapsUri, id);
});
}

@@ -180,3 +224,6 @@ getCached(id, type) {

})
.then(body => new syncdocument_1.SyncDocument(this.services, body, sid => this.removeFromCache(sid)))
.then(body => {
this.storeRoot(id, 'document', body);
return new syncdocument_1.SyncDocument(this.services, body, sid => this.removeFromCache(sid));
})
.then(entity => this.entities.store(entity))

@@ -195,16 +242,27 @@ .then(subscribe);

yield this.ensureReady();
let { id, purpose, context, mode } = decompose(arg);
return this.getCached(id, 'map') || this._getMap(id)
let { id, purpose, context, mode, optimistic } = decompose(arg);
let cachedMap = this.getCached(id, 'map');
if (cachedMap) {
return cachedMap;
}
console.log('----------xxxx1');
let map = yield this._getMap(id, optimistic)
.then(body => {
if (body) {
console.log('----------xxxx1', body);
if (body.root) {
return body;
}
else if (mode !== 'open') {
return this._createMap(id, purpose, context);
if (mode === 'open') {
throw new syncerror_1.default('Not found', 404);
}
throw new syncerror_1.default('Not found', 404);
console.log('Creating');
return this._createMap(id, purpose, context);
})
.then(body => new syncmap_1.SyncMap(this.services, body, sid => this.removeFromCache(sid)))
.then(entity => this.entities.store(entity))
.then(subscribe);
.then(map => {
this.storeRoot(id, 'map', map.root);
return new syncmap_1.SyncMap(this.services, map.root, map.items, sid => this.removeFromCache(sid));
});
this.entities.store(map);
subscribe(map);
return map;
});

@@ -232,3 +290,6 @@ }

})
.then(body => new synclist_1.SyncList(this.services, body, sid => this.removeFromCache(sid)))
.then(body => {
this.storeRoot(id, 'list', body);
return new synclist_1.SyncList(this.services, body, sid => this.removeFromCache(sid));
})
.then(entity => this.entities.store(entity))

@@ -266,2 +327,26 @@ .then(subscribe);

}
storeRoot(id, type, object) {
try {
if (sessionStorage) {
let entryId = type + '::' + id;
sessionStorage.setItem(entryId, JSON.stringify(object));
}
}
catch (e) {
}
}
getRoot(id, type) {
try {
if (sessionStorage) {
let entryId = type + '::' + id;
let data = sessionStorage.getItem(entryId);
if (data) {
return JSON.parse(data);
}
}
}
catch (e) {
}
return null;
}
}

@@ -268,0 +353,0 @@ exports.SyncClient = SyncClient;

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

readonly token: string;
readonly baseUri: string;
readonly subscriptionsUri: string;

@@ -14,0 +15,0 @@ readonly documentsUri: string;

@@ -19,2 +19,3 @@ "use strict";

this.settings = {
baseUri: baseUri,
subscriptionsUri: baseUri + SUBSCRIPTIONS_PATH,

@@ -27,2 +28,3 @@ documentsUri: baseUri + DOCUMENTS_PATH,

get token() { return this._token; }
get baseUri() { return this.settings.baseUri; }
get subscriptionsUri() { return this.settings.subscriptionsUri; }

@@ -29,0 +31,0 @@ get documentsUri() { return this.settings.documentsUri; }

export interface MapItemDescriptor {
key: string;
uri: string;
value: Object;
url: string;
revision: string;
lastEventId: number;
last_event_id: number;
data: Object;
}

@@ -8,0 +8,0 @@ /**

@@ -22,11 +22,11 @@ "use strict";

}
get uri() { return this.data.uri; }
get uri() { return this.data.url; }
;
get revision() { return this.data.revision; }
;
get lastEventId() { return this.data.lastEventId; }
get lastEventId() { return this.data.last_event_id; }
;
get key() { return this.data.key; }
;
get value() { return this.data.value; }
get value() { return this.data.data; }
;

@@ -41,5 +41,7 @@ /**

update(eventId, revision, value) {
this.data.lastEventId = eventId;
this.data.revision = revision;
this.data.value = value;
if (eventId > this.data.last_event_id) {
this.data.last_event_id = eventId;
this.data.revision = revision;
this.data.data = value;
}
return this;

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

import { SyncEntity, EntityServices } from './entity';
import { MapItem as Item } from './mapitem';
import { MapItem as Item, MapItemDescriptor } from './mapitem';
import { Paginator } from './paginator';

@@ -40,3 +40,3 @@ import { Mutator } from './interfaces/mutator';

*/
constructor(services: MapServices, descriptor: MapDescriptor, onRemoveMap: any);
constructor(services: MapServices, descriptor: MapDescriptor, items: MapItemDescriptor[], onRemoveMap: any);
readonly uri: string;

@@ -50,2 +50,3 @@ readonly links: any;

readonly type: string;
private populateItems(items);
_get(key: any): Promise<Item>;

@@ -52,0 +53,0 @@ __set(location: any, param: any): any;

@@ -37,4 +37,5 @@ "use strict";

*/
constructor(services, descriptor, onRemoveMap) {
constructor(services, descriptor, items, onRemoveMap) {
super(services);
console.log('Got descriptor', descriptor);
this.actionQueue = new retryingqueue_1.RetryingQueue();

@@ -44,2 +45,3 @@ this.cache = new cache_1.Cache();

this.onRemoveMap = onRemoveMap;
this.populateItems(items);
}

@@ -58,2 +60,5 @@ get uri() { return this.descriptor.url; }

get type() { return 'map'; }
populateItems(items) {
items.forEach(item => this.cache.store(item.key, new mapitem_1.MapItem(item), item.last_event_id));
}
_get(key) {

@@ -196,14 +201,9 @@ return this.queryItems({ key: key }).then(result => {

}
let { added, value: result } = yield this._tryAddOrUpdate(this.links.items, { key: key, data: value }, resolver);
let descriptor = { key: result.key,
revision: result.revision,
lastEventId: result.last_event_id,
uri: result.url,
value: result.data };
let { added, value: descriptor } = yield this._tryAddOrUpdate(this.links.items, { key: key, data: value }, resolver);
item = yield this.cache.get(key);
if (item && descriptor.lastEventId > item.lastEventId) {
item.update(descriptor.lastEventId, descriptor.revision, descriptor.value);
if (item) {
item.update(descriptor.last_event_id, descriptor.revision, descriptor.data);
}
else if (!item) {
item = this.cache.store(key, new mapitem_1.MapItem(descriptor), descriptor.lastEventId);
item = this.cache.store(key, new mapitem_1.MapItem(descriptor), descriptor.last_event_id);
if (added) {

@@ -286,7 +286,3 @@ this.emit('itemAdded', item, true);

let response = yield this.services.network.get(uri);
let items = response.body.items.map(el => this.cache.store(el.key, new mapitem_1.MapItem({ key: el.key,
uri: el.url,
revision: el.revision,
lastEventId: el.last_event_id,
value: el.data }), el.last_event_id));
let items = response.body.items.map(el => this.cache.store(el.key, new mapitem_1.MapItem(el), el.last_event_id));
const meta = response.body.meta;

@@ -406,3 +402,3 @@ return new paginator_1.Paginator(items, pageToken => this.queryItems({ pageToken }), meta.previous_token, meta.next_token);

if (!this.cache.has(key) && !this.shouldIgnoreEvent(key, eventId)) {
let item = new mapitem_1.MapItem({ key, uri, lastEventId: eventId, revision, value });
let item = new mapitem_1.MapItem({ key, url: uri, last_event_id: eventId, revision, data: value });
this.cache.store(key, item, eventId);

@@ -420,3 +416,3 @@ this.emit('itemAdded', item, false);

if (!item && !this.shouldIgnoreEvent(key, eventId)) {
item = new mapitem_1.MapItem({ key, uri, lastEventId: eventId, revision, value });
item = new mapitem_1.MapItem({ key, url: uri, last_event_id: eventId, revision, data: value });
this.cache.store(key, item, eventId);

@@ -423,0 +419,0 @@ this.emit('itemUpdated', item, false);

@@ -14,3 +14,5 @@ /**

args: string[];
paths: string[];
constructor(base: string);
path(name: string): UriBuilder;
arg(name: string, value: any): UriBuilder;

@@ -17,0 +19,0 @@ build(): string;

@@ -19,3 +19,8 @@ "use strict";

this.args = new Array();
this.paths = new Array();
}
path(name) {
this.paths.push(name);
return this;
}
arg(name, value) {

@@ -29,5 +34,10 @@ if (typeof value !== 'undefined') {

build() {
return this.args.length === 0
? this.base
: this.base + '?' + this.args.join('&');
let result = this.base;
if (this.paths.length) {
result += '/' + this.paths.join('/');
}
if (this.args.length) {
result += '?' + this.args.join('&');
}
return result;
}

@@ -34,0 +44,0 @@ ;

{
"name": "twilio-sync",
"version": "0.4.2-dev.5-build.202",
"version": "0.4.2-test.1",
"description": "Twilio Sync client library",

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

@@ -11,5 +11,5 @@ {

"target": "es6",
"lib": [ "es6" ],
"lib": [ "es6", "dom" ],
"outDir": "lib"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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