delta-store
Version:
An API for a store with change records
71 lines • 3.19 kB
JavaScript
/**
* Created by Papa on 1/7/2016.
*/
;
var SharingAdaptor_1 = require("../SharingAdaptor");
var GoogleSharedChangeList_1 = require("./GoogleSharedChangeList");
// @Injectable()
var GoogleSharingAdaptor = (function () {
function GoogleSharingAdaptor(drive, driveAdaptor, realtime, realtimeAdaptor) {
this.drive = drive;
this.driveAdaptor = driveAdaptor;
this.realtime = realtime;
this.realtimeAdaptor = realtimeAdaptor;
}
GoogleSharingAdaptor.prototype.setupInfoBelongsTo = function (setupInfo, setupInfos) {
if (setupInfo.platformType !== SharingAdaptor_1.PlatformType.GOOGLE_DOCS) {
return false;
}
return setupInfos.some(function (otherSetupInfo) {
if (otherSetupInfo.platformType === SharingAdaptor_1.PlatformType.GOOGLE_DOCS) {
return setupInfo.apiKey === otherSetupInfo.apiKey
&& setupInfo.clientId === otherSetupInfo.clientId;
}
});
};
GoogleSharingAdaptor.prototype.initialize = function (setupInfo) {
var _this = this;
return this.driveAdaptor.initialize(setupInfo.apiKey, setupInfo.clientId).then(function () {
return _this.driveAdaptor.setup(setupInfo);
}).then(function (driveFile) {
setupInfo.sharedAppFolderId = driveFile.result.id;
return setupInfo;
});
};
GoogleSharingAdaptor.prototype.createChangeList = function (shareInfo, setupInfo) {
var _this = this;
var folderId;
var realtimeFileId;
return this.drive.findOrCreateUniqueFolder(name, setupInfo.sharedAppFolderId).then(function (driveResponse) {
folderId = driveResponse.result.id;
return _this.realtime.findOrCreateFileUniqueFile(name + ' - Realtime', folderId);
}).then(function (driveResponse) {
realtimeFileId = driveResponse.result.id;
return _this.realtimeAdaptor.startNewShare(realtimeFileId);
}).then(function (handle) {
var googleShareInfo = {
name: shareInfo.name,
dbId: shareInfo.dbId,
folderId: folderId,
realtimeFileId: realtimeFileId
};
return new GoogleSharedChangeList_1.GoogleSharedChangeList(setupInfo, googleShareInfo, handle);
});
};
GoogleSharingAdaptor.prototype.findExistingChangeLists = function (setupInfo) {
return this.driveAdaptor.listChangeLists(setupInfo).then(function (listings) {
return listings;
});
};
GoogleSharingAdaptor.prototype.loadChangeList = function (shareInfo, setupInfo) {
var _this = this;
return this.driveAdaptor.populateChangeListFileInfo(shareInfo).then(function (shareInfo) {
return _this.realtimeAdaptor.openShare(shareInfo.realtimeFileId).then(function (handle) {
return new GoogleSharedChangeList_1.GoogleSharedChangeList(setupInfo, shareInfo, handle);
});
});
};
return GoogleSharingAdaptor;
}());
exports.GoogleSharingAdaptor = GoogleSharingAdaptor;
//# sourceMappingURL=GoogleSharingAdaptor.js.map