From 559ecb1cda3d1f6ece588ac9a21e1acff5d17dc9 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Thu, 30 Mar 2017 17:38:07 -0700 Subject: [PATCH] [client-app] rename DatabaseTransaction -> DatabaseWriter Summary: Renamed in prep for next few diffs Test Plan: manual Reviewers: juan, mark, spang, halla Reviewed By: halla Differential Revision: https://phab.nylas.com/D4302 --- .../build/resources/asar-ordering-hint.txt | 6 +-- .../client-app/spec/nylas-api-spec.coffee | 38 +++++++++---------- .../spec/services/delta-processor-spec.coffee | 22 +++++------ .../delta-streaming-connection-spec.coffee | 4 +- .../spec/stores/database-transaction-spec.es6 | 6 +-- .../stores/draft-editing-session-spec.coffee | 12 +++--- .../spec/stores/draft-factory-spec.es6 | 4 +- .../spec/stores/draft-store-spec.es6 | 16 ++++---- .../spec/stores/identity-store-spec.es6 | 8 ++-- .../spec/tasks/change-mail-task-spec.coffee | 4 +- .../tasks/destroy-category-task-spec.coffee | 14 +++---- .../spec/tasks/destroy-model-task-spec.es6 | 6 +-- .../spec/tasks/event-rsvp-task-spec.coffee | 8 ++-- .../spec/tasks/send-draft-task-spec.es6 | 4 +- .../tasks/syncback-category-task-spec.coffee | 8 ++-- .../spec/tasks/syncback-draft-task-spec.es6 | 8 ++-- .../spec/tasks/syncback-model-task-spec.es6 | 8 ++-- .../src/flux/stores/database-store.es6 | 4 +- ...se-transaction.es6 => database-writer.es6} | 16 ++++---- .../client-app/src/global/nylas-exports.es6 | 2 +- 20 files changed, 99 insertions(+), 99 deletions(-) rename packages/client-app/src/flux/stores/{database-transaction.es6 => database-writer.es6} (93%) diff --git a/packages/client-app/build/resources/asar-ordering-hint.txt b/packages/client-app/build/resources/asar-ordering-hint.txt index 1cbb278dc..980230dd1 100644 --- a/packages/client-app/build/resources/asar-ordering-hint.txt +++ b/packages/client-app/build/resources/asar-ordering-hint.txt @@ -983,7 +983,7 @@ 3583641: src/flux/stores/database-change-record.js 3572560: node_modules/promise-queue/lib/index.js 3146093: node_modules/underscore.string/toSentenceSerial.js -3585323: src/flux/stores/database-transaction.js +3585323: src/flux/stores/database-writer.js 3146253: node_modules/underscore.string/slugify.js 3577195: src/priority-ui-coordinator.js 3146513: node_modules/underscore.string/surround.js @@ -996,7 +996,7 @@ 3583641: src/flux/stores/database-change-record.js 3149427: node_modules/underscore.string/toBoolean.js 3150095: node_modules/underscore.string/exports.js -3585323: src/flux/stores/database-transaction.js +3585323: src/flux/stores/database-writer.js 3150336: node_modules/underscore.string/wrap.js 3152857: node_modules/underscore.string/map.js 3568295: src/flux/coffee-helpers.js @@ -1012,7 +1012,7 @@ 3583641: src/flux/stores/database-change-record.js 3613961: src/buffered-process.js 3622937: src/theme-manager.js -3585323: src/flux/stores/database-transaction.js +3585323: src/flux/stores/database-writer.js 3621867: src/clipboard.js 3642517: src/style-manager.js 3648228: src/flux/action-bridge.js diff --git a/packages/client-app/spec/nylas-api-spec.coffee b/packages/client-app/spec/nylas-api-spec.coffee index fdb2115ea..6940a8d87 100644 --- a/packages/client-app/spec/nylas-api-spec.coffee +++ b/packages/client-app/spec/nylas-api-spec.coffee @@ -8,57 +8,57 @@ Thread = require('../src/flux/models/thread').default Message = require('../src/flux/models/message').default AccountStore = require('../src/flux/stores/account-store').default DatabaseStore = require('../src/flux/stores/database-store').default -DatabaseTransaction = require('../src/flux/stores/database-transaction').default +DatabaseWriter = require('../src/flux/stores/database-writer').default describe "NylasAPI", -> describe "handleModel404", -> it "should unpersist the model from the cache that was requested", -> model = new Thread(id: 'threadidhere') - spyOn(DatabaseTransaction.prototype, 'unpersistModel').andCallFake => + spyOn(DatabaseWriter.prototype, 'unpersistModel').andCallFake => return Promise.resolve() - spyOn(DatabaseTransaction.prototype, 'find').andCallFake (klass, id) => + spyOn(DatabaseWriter.prototype, 'find').andCallFake (klass, id) => return Promise.resolve(model) waitsForPromise -> NylasAPIHelpers.handleModel404("/threads/#{model.id}") runs -> - expect(DatabaseTransaction.prototype.find).toHaveBeenCalledWith(Thread, model.id) - expect(DatabaseTransaction.prototype.unpersistModel).toHaveBeenCalledWith(model) + expect(DatabaseWriter.prototype.find).toHaveBeenCalledWith(Thread, model.id) + expect(DatabaseWriter.prototype.unpersistModel).toHaveBeenCalledWith(model) it "should not do anything if the model is not in the cache", -> - spyOn(DatabaseTransaction.prototype, 'unpersistModel') - spyOn(DatabaseTransaction.prototype, 'find').andCallFake (klass, id) => + spyOn(DatabaseWriter.prototype, 'unpersistModel') + spyOn(DatabaseWriter.prototype, 'find').andCallFake (klass, id) => return Promise.resolve(null) waitsForPromise -> NylasAPIHelpers.handleModel404("/threads/1234") runs -> - expect(DatabaseTransaction.prototype.find).toHaveBeenCalledWith(Thread, '1234') - expect(DatabaseTransaction.prototype.unpersistModel).not.toHaveBeenCalledWith() + expect(DatabaseWriter.prototype.find).toHaveBeenCalledWith(Thread, '1234') + expect(DatabaseWriter.prototype.unpersistModel).not.toHaveBeenCalledWith() it "should not do anything bad if it doesn't recognize the class", -> spyOn(DatabaseStore, 'find') - spyOn(DatabaseTransaction.prototype, 'unpersistModel') + spyOn(DatabaseWriter.prototype, 'unpersistModel') waitsForPromise -> NylasAPIHelpers.handleModel404("/asdasdasd/1234") runs -> expect(DatabaseStore.find).not.toHaveBeenCalled() - expect(DatabaseTransaction.prototype.unpersistModel).not.toHaveBeenCalled() + expect(DatabaseWriter.prototype.unpersistModel).not.toHaveBeenCalled() it "should not do anything bad if the endpoint only has a single segment", -> spyOn(DatabaseStore, 'find') - spyOn(DatabaseTransaction.prototype, 'unpersistModel') + spyOn(DatabaseWriter.prototype, 'unpersistModel') waitsForPromise -> NylasAPIHelpers.handleModel404("/account") runs -> expect(DatabaseStore.find).not.toHaveBeenCalled() - expect(DatabaseTransaction.prototype.unpersistModel).not.toHaveBeenCalled() + expect(DatabaseWriter.prototype.unpersistModel).not.toHaveBeenCalled() describe "handleModelResponse", -> beforeEach -> @stubDB = {} @stubDB.upsertModel = (model) => @stubDB[model.id] = model - spyOn(DatabaseTransaction.prototype, "persistModels").andCallFake (models) => + spyOn(DatabaseWriter.prototype, "persistModels").andCallFake (models) => models.forEach(@stubDB.upsertModel) Promise.resolve(models) spyOn(DatabaseStore, "findAll").andCallFake (klass) => @@ -126,7 +126,7 @@ describe "NylasAPI", -> waitsForPromise => NylasAPIHelpers.handleModelResponse(@dupes) .then -> - models = DatabaseTransaction.prototype.persistModels.calls[0].args[0] + models = DatabaseWriter.prototype.persistModels.calls[0].args[0] expect(models.length).toBe 2 expect(models[0].id).toBe 't:a' expect(models[1].id).toBe 't:b' @@ -148,7 +148,7 @@ describe "NylasAPI", -> NylasAPIHelpers.handleModelResponse(json) .then (models) -> expect(models.length).toBe 1 - models = DatabaseTransaction.prototype.persistModels.calls[0].args[0] + models = DatabaseWriter.prototype.persistModels.calls[0].args[0] expect(models.length).toBe 1 expect(models[0].id).toBe 't:b' @@ -163,7 +163,7 @@ describe "NylasAPI", -> @stubDB.upsertModel(@existing) verifyUpdateHappened = (responseModels) -> - changedModels = DatabaseTransaction.prototype.persistModels.calls[0].args[0] + changedModels = DatabaseWriter.prototype.persistModels.calls[0].args[0] expect(changedModels.length).toBe 2 expect(responseModels.length).toBe 2 expect(responseModels[0].id).toBe 'a' @@ -193,7 +193,7 @@ describe "NylasAPI", -> verifyUpdateHappened.call(@, responseModels) verifyUpdateStopped = (responseModels) -> - changedModels = DatabaseTransaction.prototype.persistModels.calls[0].args[0] + changedModels = DatabaseWriter.prototype.persistModels.calls[0].args[0] expect(changedModels.length).toBe 1 expect(changedModels[0].id).toBe 'a' expect(changedModels[0].unread).toBe true @@ -231,7 +231,7 @@ describe "NylasAPI", -> "calendar": require('../src/flux/models/calendar').default verifyUpdateHappened = (klass, responseModels) -> - changedModels = DatabaseTransaction.prototype.persistModels.calls[0].args[0] + changedModels = DatabaseWriter.prototype.persistModels.calls[0].args[0] expect(changedModels.length).toBe 2 expect(changedModels[0].id).toBe 'a' expect(changedModels[1].id).toBe 'b' diff --git a/packages/client-app/spec/services/delta-processor-spec.coffee b/packages/client-app/spec/services/delta-processor-spec.coffee index 86dfa0d63..45115a6b2 100644 --- a/packages/client-app/spec/services/delta-processor-spec.coffee +++ b/packages/client-app/spec/services/delta-processor-spec.coffee @@ -3,7 +3,7 @@ fs = require 'fs' path = require 'path' {NylasAPIHelpers, Thread, - DatabaseTransaction, + DatabaseWriter, Actions, Message, Thread} = require 'nylas-exports' @@ -104,25 +104,25 @@ describe "DeltaProcessor", -> "objectId": @thread.id, "timestamp": "2015-08-26T17:36:45.297Z" - spyOn(DatabaseTransaction.prototype, 'unpersistModel') + spyOn(DatabaseWriter.prototype, 'unpersistModel') it "should resolve if the object cannot be found", -> - spyOn(DatabaseTransaction.prototype, 'find').andCallFake (klass, id) => + spyOn(DatabaseWriter.prototype, 'find').andCallFake (klass, id) => return Promise.resolve(null) waitsForPromise => DeltaProcessor._handleDestroyDelta(@delta) runs => - expect(DatabaseTransaction.prototype.find).toHaveBeenCalledWith(Thread, 'idhere') - expect(DatabaseTransaction.prototype.unpersistModel).not.toHaveBeenCalled() + expect(DatabaseWriter.prototype.find).toHaveBeenCalledWith(Thread, 'idhere') + expect(DatabaseWriter.prototype.unpersistModel).not.toHaveBeenCalled() it "should call unpersistModel if the object exists", -> - spyOn(DatabaseTransaction.prototype, 'find').andCallFake (klass, id) => + spyOn(DatabaseWriter.prototype, 'find').andCallFake (klass, id) => return Promise.resolve(@thread) waitsForPromise => DeltaProcessor._handleDestroyDelta(@delta) runs => - expect(DatabaseTransaction.prototype.find).toHaveBeenCalledWith(Thread, 'idhere') - expect(DatabaseTransaction.prototype.unpersistModel).toHaveBeenCalledWith(@thread) + expect(DatabaseWriter.prototype.find).toHaveBeenCalledWith(Thread, 'idhere') + expect(DatabaseWriter.prototype.unpersistModel).toHaveBeenCalledWith(@thread) describe "handleModelResponse", -> # SEE spec/nylas-api-spec.coffee @@ -130,9 +130,9 @@ describe "DeltaProcessor", -> describe "receives metadata deltas", -> beforeEach -> @stubDB = {} - spyOn(DatabaseTransaction.prototype, 'find').andCallFake (klass, id) => + spyOn(DatabaseWriter.prototype, 'find').andCallFake (klass, id) => return @stubDB[id] - spyOn(DatabaseTransaction.prototype, 'findAll').andCallFake (klass, where) => + spyOn(DatabaseWriter.prototype, 'findAll').andCallFake (klass, where) => ids = where.id models = [] ids.forEach (id) => @@ -140,7 +140,7 @@ describe "DeltaProcessor", -> if model models.push(model) return models - spyOn(DatabaseTransaction.prototype, 'persistModels').andCallFake (models) => + spyOn(DatabaseWriter.prototype, 'persistModels').andCallFake (models) => models.forEach (model) => @stubDB[model.id] = model return Promise.resolve() diff --git a/packages/client-app/spec/services/delta-streaming-connection-spec.coffee b/packages/client-app/spec/services/delta-streaming-connection-spec.coffee index 03f2d41b4..5640be77b 100644 --- a/packages/client-app/spec/services/delta-streaming-connection-spec.coffee +++ b/packages/client-app/spec/services/delta-streaming-connection-spec.coffee @@ -1,5 +1,5 @@ _ = require 'underscore' -{NylasAPI, NylasAPIHelpers, NylasAPIRequest, Actions, DatabaseStore, DatabaseTransaction, Account, Thread} = require 'nylas-exports' +{NylasAPI, NylasAPIHelpers, NylasAPIRequest, Actions, DatabaseStore, DatabaseWriter, Account, Thread} = require 'nylas-exports' DeltaStreamingConnection = require('../../src/services/delta-streaming-connection').default # TODO these are badly out of date, we need to rewrite them @@ -11,7 +11,7 @@ xdescribe "DeltaStreamingConnection", -> @localSyncCursorStub = undefined @n1CloudCursorStub = undefined # spyOn(DeltaStreamingConnection.prototype, '_fetchMetadata').andReturn(Promise.resolve()) - spyOn(DatabaseTransaction.prototype, 'persistJSONBlob').andReturn(Promise.resolve()) + spyOn(DatabaseWriter.prototype, 'persistJSONBlob').andReturn(Promise.resolve()) spyOn(DatabaseStore, 'findJSONBlob').andCallFake (key) => if key is "NylasSyncWorker:#{TEST_ACCOUNT_ID}" return Promise.resolve _.extend {}, { diff --git a/packages/client-app/spec/stores/database-transaction-spec.es6 b/packages/client-app/spec/stores/database-transaction-spec.es6 index 8c5e63a0d..5e34d1610 100644 --- a/packages/client-app/spec/stores/database-transaction-spec.es6 +++ b/packages/client-app/spec/stores/database-transaction-spec.es6 @@ -1,7 +1,7 @@ /* eslint dot-notation:0 */ import Category from '../../src/flux/models/category'; import TestModel from '../fixtures/db-test-model'; -import DatabaseTransaction from '../../src/flux/stores/database-transaction'; +import DatabaseWriter from '../../src/flux/stores/database-writer'; const testModelInstance = new TestModel({id: "1234"}); const testModelInstanceA = new TestModel({id: "AAA"}); @@ -18,7 +18,7 @@ function __range__(left, right, inclusive) { return range; } -xdescribe("DatabaseTransaction", function DatabaseTransactionSpecs() { +xdescribe("DatabaseWriter", function DatabaseWriterSpecs() { beforeEach(() => { this.databaseMutationHooks = []; this.performed = []; @@ -31,7 +31,7 @@ xdescribe("DatabaseTransaction", function DatabaseTransactionSpecs() { mutationHooks: () => this.databaseMutationHooks, }; - this.transaction = new DatabaseTransaction(this.database); + this.transaction = new DatabaseWriter(this.database); }); describe("execute", () => {}); diff --git a/packages/client-app/spec/stores/draft-editing-session-spec.coffee b/packages/client-app/spec/stores/draft-editing-session-spec.coffee index 56e9aa138..f1ef1ae3e 100644 --- a/packages/client-app/spec/stores/draft-editing-session-spec.coffee +++ b/packages/client-app/spec/stores/draft-editing-session-spec.coffee @@ -1,7 +1,7 @@ Message = require('../../src/flux/models/message').default Actions = require('../../src/flux/actions').default DatabaseStore = require('../../src/flux/stores/database-store').default -DatabaseTransaction = require('../../src/flux/stores/database-transaction').default +DatabaseWriter = require('../../src/flux/stores/database-writer').default DraftEditingSession = require '../../src/flux/stores/draft-editing-session' DraftChangeSet = DraftEditingSession.DraftChangeSet _ = require 'underscore' @@ -178,7 +178,7 @@ xdescribe "DraftEditingSession Specs", -> @session = new DraftEditingSession('client-id', @draft) advanceClock() - spyOn(DatabaseTransaction.prototype, "persistModel").andReturn Promise.resolve() + spyOn(DatabaseWriter.prototype, "persistModel").andReturn Promise.resolve() spyOn(Actions, "queueTask").andReturn Promise.resolve() it "should ignore the update unless it applies to the current draft", -> @@ -212,8 +212,8 @@ xdescribe "DraftEditingSession Specs", -> @session.changes.add({body: "123"}) waitsForPromise => @session.changes.commit().then => - expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled() - updated = DatabaseTransaction.prototype.persistModel.calls[0].args[0] + expect(DatabaseWriter.prototype.persistModel).toHaveBeenCalled() + updated = DatabaseWriter.prototype.persistModel.calls[0].args[0] expect(updated.body).toBe "123" # Note: Syncback temporarily disabled @@ -239,8 +239,8 @@ xdescribe "DraftEditingSession Specs", -> @session.changes.add({body: "123"}) waitsForPromise => @session.changes.commit().then => - expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled() - updated = DatabaseTransaction.prototype.persistModel.calls[0].args[0] + expect(DatabaseWriter.prototype.persistModel).toHaveBeenCalled() + updated = DatabaseWriter.prototype.persistModel.calls[0].args[0] expect(updated.body).toBe "123" it "does nothing if the draft is marked as destroyed", -> diff --git a/packages/client-app/spec/stores/draft-factory-spec.es6 b/packages/client-app/spec/stores/draft-factory-spec.es6 index f73685c16..bcedc69f7 100644 --- a/packages/client-app/spec/stores/draft-factory-spec.es6 +++ b/packages/client-app/spec/stores/draft-factory-spec.es6 @@ -10,7 +10,7 @@ import { AccountStore, DatabaseStore, FileDownloadStore, - DatabaseTransaction, + DatabaseWriter, SanitizeTransformer, InlineStyleTransformer, } from 'nylas-exports'; @@ -439,7 +439,7 @@ describe('DraftFactory', function draftFactory() { spyOn(Actions, 'focusDraft') spyOn(DatabaseStore, 'run').andReturn(Promise.resolve([fakeMessage1, this.existingDraft])); spyOn(DraftStore, 'sessionForClientId').andReturn(Promise.resolve(this.sessionStub)); - spyOn(DatabaseTransaction.prototype, 'persistModel').andReturn(Promise.resolve()); + spyOn(DatabaseWriter.prototype, 'persistModel').andReturn(Promise.resolve()); this.expectContactsEqual = (a, b) => { expect(a.map(c => c.email).sort()).toEqual(b.map(c => c.email).sort()); diff --git a/packages/client-app/spec/stores/draft-store-spec.es6 b/packages/client-app/spec/stores/draft-store-spec.es6 index b82b749d2..3ab21599c 100644 --- a/packages/client-app/spec/stores/draft-store-spec.es6 +++ b/packages/client-app/spec/stores/draft-store-spec.es6 @@ -12,7 +12,7 @@ import { ComposerExtension, ExtensionRegistry, FocusedContentStore, - DatabaseTransaction, + DatabaseWriter, } from 'nylas-exports'; import {remote} from 'electron'; @@ -30,7 +30,7 @@ xdescribe('DraftStore', function draftStore() { this.fakeMessage = new Message({id: 'fake-message', clientId: 'fake-message'}); spyOn(NylasEnv, 'newWindow').andCallFake(() => {}); - spyOn(DatabaseTransaction.prototype, "persistModel").andReturn(Promise.resolve()); + spyOn(DatabaseWriter.prototype, "persistModel").andReturn(Promise.resolve()); spyOn(DatabaseStore, 'run').andCallFake((query) => { if (query._klass === Thread) { return Promise.resolve(this.fakeThread); } if (query._klass === Message) { return Promise.resolve(this.fakeMessage); } @@ -130,7 +130,7 @@ xdescribe('DraftStore', function draftStore() { ); }); waitsFor(() => { - return DatabaseTransaction.prototype.persistModel.callCount > 0; + return DatabaseWriter.prototype.persistModel.callCount > 0; }); runs(() => { expect(NylasEnv.newWindow).toHaveBeenCalledWith({ @@ -152,7 +152,7 @@ xdescribe('DraftStore', function draftStore() { }); }); waitsFor(() => { - return DatabaseTransaction.prototype.persistModel.callCount > 0; + return DatabaseWriter.prototype.persistModel.callCount > 0; }); runs(() => { expect(NylasEnv.newWindow).toHaveBeenCalledWith({ @@ -504,7 +504,7 @@ xdescribe('DraftStore', function draftStore() { it("should give extensions a chance to customize the draft via ext.prepareNewDraft", () => { waitsForPromise(() => { return DraftStore._onHandleMailtoLink({}, 'mailto:bengotow@gmail.com').then(() => { - const received = DatabaseTransaction.prototype.persistModel.mostRecentCall.args[0]; + const received = DatabaseWriter.prototype.persistModel.mostRecentCall.args[0]; expect(received.body.indexOf("Edited by TestExtension!")).toBe(0); }); }); @@ -517,7 +517,7 @@ xdescribe('DraftStore', function draftStore() { spyOn(DraftStore, '_onPopoutDraftClientId'); waitsForPromise(() => { return DraftStore._onHandleMailtoLink({}, 'mailto:bengotow@gmail.com').then(() => { - const received = DatabaseTransaction.prototype.persistModel.mostRecentCall.args[0]; + const received = DatabaseWriter.prototype.persistModel.mostRecentCall.args[0]; expect(received).toEqual(draft); expect(DraftStore._onPopoutDraftClientId).toHaveBeenCalled(); }); @@ -532,9 +532,9 @@ xdescribe('DraftStore', function draftStore() { spyOn(Account.prototype, 'defaultMe').andReturn(defaultMe); spyOn(Actions, 'addAttachment').andCallFake(({onUploadCreated}) => onUploadCreated()); DraftStore._onHandleMailFiles({}, ['/Users/ben/file1.png', '/Users/ben/file2.png']); - waitsFor(() => DatabaseTransaction.prototype.persistModel.callCount > 0); + waitsFor(() => DatabaseWriter.prototype.persistModel.callCount > 0); runs(() => { - const {body, subject, from} = DatabaseTransaction.prototype.persistModel.calls[0].args[0]; + const {body, subject, from} = DatabaseWriter.prototype.persistModel.calls[0].args[0]; expect({body, subject, from}).toEqual({body: '', subject: '', from: [defaultMe]}); expect(DraftStore._onPopoutDraftClientId).toHaveBeenCalled(); }); diff --git a/packages/client-app/spec/stores/identity-store-spec.es6 b/packages/client-app/spec/stores/identity-store-spec.es6 index 89a8628cc..20c18c8ea 100644 --- a/packages/client-app/spec/stores/identity-store-spec.es6 +++ b/packages/client-app/spec/stores/identity-store-spec.es6 @@ -1,5 +1,5 @@ import {ipcRenderer} from 'electron'; -import {Utils, KeyManager, DatabaseTransaction, SendFeatureUsageEventTask} from 'nylas-exports' +import {Utils, KeyManager, DatabaseWriter, SendFeatureUsageEventTask} from 'nylas-exports' import IdentityStore from '../../src/flux/stores/identity-store' const TEST_NYLAS_ID = "icihsnqh4pwujyqihlrj70vh" @@ -30,7 +30,7 @@ describe("IdentityStore", function identityStoreSpec() { IdentityStore._identity = this.identityJSON; spyOn(KeyManager, "deletePassword") spyOn(KeyManager, "replacePassword") - spyOn(DatabaseTransaction.prototype, "persistJSONBlob").andReturn(Promise.resolve()) + spyOn(DatabaseWriter.prototype, "persistJSONBlob").andReturn(Promise.resolve()) spyOn(ipcRenderer, "send") spyOn(IdentityStore, "trigger") }); @@ -44,8 +44,8 @@ describe("IdentityStore", function identityStoreSpec() { expect(KeyManager.replacePassword).not.toHaveBeenCalled() expect(ipcRenderer.send).toHaveBeenCalled() expect(ipcRenderer.send.calls[0].args[1]).toBe("onIdentityChanged") - expect(DatabaseTransaction.prototype.persistJSONBlob).toHaveBeenCalled() - const ident = DatabaseTransaction.prototype.persistJSONBlob.calls[0].args[1] + expect(DatabaseWriter.prototype.persistJSONBlob).toHaveBeenCalled() + const ident = DatabaseWriter.prototype.persistJSONBlob.calls[0].args[1] expect(ident).toBe(null) expect(IdentityStore.trigger).toHaveBeenCalled() }) diff --git a/packages/client-app/spec/tasks/change-mail-task-spec.coffee b/packages/client-app/spec/tasks/change-mail-task-spec.coffee index 79ed00c69..c03abbbc5 100644 --- a/packages/client-app/spec/tasks/change-mail-task-spec.coffee +++ b/packages/client-app/spec/tasks/change-mail-task-spec.coffee @@ -9,7 +9,7 @@ _ = require 'underscore' NylasAPIRequest, Query, DatabaseStore, - DatabaseTransaction, + DatabaseWriter, Task, Utils, ChangeMailTask, @@ -51,7 +51,7 @@ xdescribe "ChangeMailTask", -> models = models[0] Promise.resolve(models) - @transaction = new DatabaseTransaction() + @transaction = new DatabaseWriter() spyOn(@transaction, 'persistModels').andReturn(Promise.resolve()) spyOn(@transaction, 'persistModel').andReturn(Promise.resolve()) diff --git a/packages/client-app/spec/tasks/destroy-category-task-spec.coffee b/packages/client-app/spec/tasks/destroy-category-task-spec.coffee index a80aad4d2..020a6ff44 100644 --- a/packages/client-app/spec/tasks/destroy-category-task-spec.coffee +++ b/packages/client-app/spec/tasks/destroy-category-task-spec.coffee @@ -7,7 +7,7 @@ APIError, Category, DatabaseStore, - DatabaseTransaction} = require "nylas-exports" + DatabaseWriter} = require "nylas-exports" xdescribe "DestroyCategoryTask", -> pathOf = (fn) -> @@ -36,8 +36,8 @@ xdescribe "DestroyCategoryTask", -> category: category beforeEach -> - spyOn(DatabaseTransaction.prototype, 'unpersistModel').andCallFake -> Promise.resolve() - spyOn(DatabaseTransaction.prototype, 'persistModel').andCallFake -> Promise.resolve() + spyOn(DatabaseWriter.prototype, 'unpersistModel').andCallFake -> Promise.resolve() + spyOn(DatabaseWriter.prototype, 'persistModel').andCallFake -> Promise.resolve() describe "performLocal", -> it "sets an `isDeleted` flag and persists the category", -> @@ -45,9 +45,9 @@ xdescribe "DestroyCategoryTask", -> runs => task.performLocal() waitsFor => - DatabaseTransaction.prototype.unpersistModel.callCount > 0 + DatabaseWriter.prototype.unpersistModel.callCount > 0 runs => - model = DatabaseTransaction.prototype.unpersistModel.calls[0].args[0] + model = DatabaseWriter.prototype.unpersistModel.calls[0].args[0] expect(model.serverId).toEqual "server-444" describe "performRemote", -> @@ -122,8 +122,8 @@ xdescribe "DestroyCategoryTask", -> expect(status).toEqual Task.Status.Failed expect(task._notifyUserOfError).toHaveBeenCalled() expect(NylasEnv.reportError).toHaveBeenCalled() - expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled() - model = DatabaseTransaction.prototype.persistModel.calls[0].args[0] + expect(DatabaseWriter.prototype.persistModel).toHaveBeenCalled() + model = DatabaseWriter.prototype.persistModel.calls[0].args[0] expect(model.serverId).toEqual "server-444" expect(NylasAPI.decrementRemoteChangeLock).toHaveBeenCalled diff --git a/packages/client-app/spec/tasks/destroy-model-task-spec.es6 b/packages/client-app/spec/tasks/destroy-model-task-spec.es6 index 1e139f71c..251aaad41 100644 --- a/packages/client-app/spec/tasks/destroy-model-task-spec.es6 +++ b/packages/client-app/spec/tasks/destroy-model-task-spec.es6 @@ -4,14 +4,14 @@ import { NylasAPIRequest, DatabaseStore, DestroyModelTask, - DatabaseTransaction} from 'nylas-exports' + DatabaseWriter} from 'nylas-exports' xdescribe('DestroyModelTask', function destroyModelTask() { beforeEach(() => { this.existingModel = new Model() this.existingModel.clientId = "local-123" this.existingModel.serverId = "server-123" - spyOn(DatabaseTransaction.prototype, "unpersistModel") + spyOn(DatabaseWriter.prototype, "unpersistModel") spyOn(DatabaseStore, "findBy").andCallFake(() => { return Promise.resolve(this.existingModel) }) @@ -67,7 +67,7 @@ xdescribe('DestroyModelTask', function destroyModelTask() { }); it("unpersists the new existing model properly", () => { - const unpersistFn = DatabaseTransaction.prototype.unpersistModel + const unpersistFn = DatabaseWriter.prototype.unpersistModel const t = new DestroyModelTask(this.defaultArgs) window.waitsForPromise(() => { return t.performLocal().then(() => { diff --git a/packages/client-app/spec/tasks/event-rsvp-task-spec.coffee b/packages/client-app/spec/tasks/event-rsvp-task-spec.coffee index 7016c80fb..6854c1b9d 100644 --- a/packages/client-app/spec/tasks/event-rsvp-task-spec.coffee +++ b/packages/client-app/spec/tasks/event-rsvp-task-spec.coffee @@ -7,13 +7,13 @@ _ = require 'underscore' APIError, EventRSVPTask, DatabaseStore, - DatabaseTransaction, + DatabaseWriter, AccountStore} = require 'nylas-exports' xdescribe "EventRSVPTask", -> beforeEach -> spyOn(DatabaseStore, 'find').andCallFake => Promise.resolve(@event) - spyOn(DatabaseTransaction.prototype, 'persistModel').andCallFake -> Promise.resolve() + spyOn(DatabaseWriter.prototype, 'persistModel').andCallFake -> Promise.resolve() @myName = "Ben Tester" @myEmail = "tester@nylas.com" @event = new Event @@ -46,7 +46,7 @@ xdescribe "EventRSVPTask", -> it "should trigger an action to persist the change", -> @task.performLocal() advanceClock() - expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled() + expect(DatabaseWriter.prototype.persistModel).toHaveBeenCalled() describe "performRemote", -> it "should make the POST request to the message endpoint", -> @@ -92,4 +92,4 @@ xdescribe "EventRSVPTask", -> @task.performLocal() @task.performRemote() advanceClock() - expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled() + expect(DatabaseWriter.prototype.persistModel).toHaveBeenCalled() diff --git a/packages/client-app/spec/tasks/send-draft-task-spec.es6 b/packages/client-app/spec/tasks/send-draft-task-spec.es6 index 0f325cd22..26a87a280 100644 --- a/packages/client-app/spec/tasks/send-draft-task-spec.es6 +++ b/packages/client-app/spec/tasks/send-draft-task-spec.es6 @@ -3,7 +3,7 @@ import { Actions, AccountStore, DatabaseStore, - DatabaseTransaction, + DatabaseWriter, Message, Contact, Task, @@ -16,7 +16,7 @@ import { } from 'nylas-exports'; -const DBt = DatabaseTransaction.prototype; +const DBt = DatabaseWriter.prototype; const withoutWhitespace = (s) => s.replace(/[\n\r\s]/g, ''); xdescribe('SendDraftTask', function sendDraftTask() { diff --git a/packages/client-app/spec/tasks/syncback-category-task-spec.coffee b/packages/client-app/spec/tasks/syncback-category-task-spec.coffee index 6d67fe389..16cb34906 100644 --- a/packages/client-app/spec/tasks/syncback-category-task-spec.coffee +++ b/packages/client-app/spec/tasks/syncback-category-task-spec.coffee @@ -4,7 +4,7 @@ AccountStore, DatabaseStore, SyncbackCategoryTask, - DatabaseTransaction} = require "nylas-exports" + DatabaseWriter} = require "nylas-exports" xdescribe "SyncbackCategoryTask", -> describe "performRemote", -> @@ -34,7 +34,7 @@ xdescribe "SyncbackCategoryTask", -> beforeEach -> spyOn(NylasAPIRequest.prototype, "run").andCallFake -> Promise.resolve(id: "server-444") - spyOn(DatabaseTransaction.prototype, "persistModel") + spyOn(DatabaseWriter.prototype, "persistModel") it "sends API req to /labels if the account uses labels", -> makeAccount(usesLabels: true) @@ -66,7 +66,7 @@ xdescribe "SyncbackCategoryTask", -> task = makeTask() task.performRemote({}) .then -> - expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled() - model = DatabaseTransaction.prototype.persistModel.calls[0].args[0] + expect(DatabaseWriter.prototype.persistModel).toHaveBeenCalled() + model = DatabaseWriter.prototype.persistModel.calls[0].args[0] expect(model.clientId).toBe "local-444" expect(model.serverId).toBe "server-444" diff --git a/packages/client-app/spec/tasks/syncback-draft-task-spec.es6 b/packages/client-app/spec/tasks/syncback-draft-task-spec.es6 index f132f17d4..001ecf7cf 100644 --- a/packages/client-app/spec/tasks/syncback-draft-task-spec.es6 +++ b/packages/client-app/spec/tasks/syncback-draft-task-spec.es6 @@ -1,6 +1,6 @@ import _ from 'underscore'; import { - DatabaseTransaction, + DatabaseWriter, SyncbackDraftTask, SyncbackMetadataTask, DatabaseStore, @@ -64,7 +64,7 @@ xdescribe('SyncbackDraftTask', function syncbackDraftTask() { spyOn(NylasAPI, 'incrementRemoteChangeLock'); spyOn(NylasAPI, 'decrementRemoteChangeLock'); - spyOn(DatabaseTransaction.prototype, "persistModel").andReturn(Promise.resolve()); + spyOn(DatabaseWriter.prototype, "persistModel").andReturn(Promise.resolve()); }); describe("queueing multiple tasks", () => { @@ -174,8 +174,8 @@ xdescribe('SyncbackDraftTask', function syncbackDraftTask() { it("should apply the server ID, thread ID and version to the draft", () => { const task = new SyncbackDraftTask("localDraftId"); waitsForPromise(() => task.performRemote().then(() => { - expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled(); - const saved = DatabaseTransaction.prototype.persistModel.calls[0].args[0]; + expect(DatabaseWriter.prototype.persistModel).toHaveBeenCalled(); + const saved = DatabaseWriter.prototype.persistModel.calls[0].args[0]; const remote = remoteDraft(); expect(saved.threadId).toEqual(remote.threadId); expect(saved.serverId).toEqual(remote.serverId); diff --git a/packages/client-app/spec/tasks/syncback-model-task-spec.es6 b/packages/client-app/spec/tasks/syncback-model-task-spec.es6 index f971872d5..056192058 100644 --- a/packages/client-app/spec/tasks/syncback-model-task-spec.es6 +++ b/packages/client-app/spec/tasks/syncback-model-task-spec.es6 @@ -5,7 +5,7 @@ import { Model, DatabaseStore, SyncbackModelTask, - DatabaseTransaction } from 'nylas-exports' + DatabaseWriter } from 'nylas-exports' class TestTask extends SyncbackModelTask { getModelConstructor() { @@ -16,7 +16,7 @@ class TestTask extends SyncbackModelTask { xdescribe('SyncbackModelTask', function syncbackModelTask() { beforeEach(() => { this.testModel = new Model({accountId: 'account-123'}) - spyOn(DatabaseTransaction.prototype, "persistModel") + spyOn(DatabaseWriter.prototype, "persistModel") spyOn(DatabaseStore, "findBy").andReturn(Promise.resolve(this.testModel)); spyOn(NylasEnv, "reportError") @@ -158,8 +158,8 @@ xdescribe('SyncbackModelTask', function syncbackModelTask() { const opts = this.task.updateLocalModel.calls[0].args[0] expect(opts.version).toBe(10) expect(opts.id).toBe("server-123") - expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled() - const model = DatabaseTransaction.prototype.persistModel.calls[0].args[0] + expect(DatabaseWriter.prototype.persistModel).toHaveBeenCalled() + const model = DatabaseWriter.prototype.persistModel.calls[0].args[0] expect(model.serverId).toBe('server-123') expect(model.version).toBe(10) }); diff --git a/packages/client-app/src/flux/stores/database-store.es6 b/packages/client-app/src/flux/stores/database-store.es6 index c418cf1bb..398d90285 100644 --- a/packages/client-app/src/flux/stores/database-store.es6 +++ b/packages/client-app/src/flux/stores/database-store.es6 @@ -13,7 +13,7 @@ import Utils from '../models/utils'; import Query from '../models/query'; import Actions from '../actions' import DatabaseChangeRecord from './database-change-record'; -import DatabaseTransaction from './database-transaction'; +import DatabaseWriter from './database-writer'; import DatabaseSetupQueryBuilder from './database-setup-query-builder'; import {setupDatabase, databasePath} from '../../database-helpers' @@ -676,7 +676,7 @@ class DatabaseStore extends NylasStore { // Returns a {Promise} that resolves when the transaction has successfully // completed. inTransaction(fn) { - const t = new DatabaseTransaction(this); + const t = new DatabaseWriter(this); this._transactionQueue = this._transactionQueue || new PromiseQueue(1, Infinity); return this._transactionQueue.add(() => t.execute(fn) diff --git a/packages/client-app/src/flux/stores/database-transaction.es6 b/packages/client-app/src/flux/stores/database-writer.es6 similarity index 93% rename from packages/client-app/src/flux/stores/database-transaction.es6 rename to packages/client-app/src/flux/stores/database-writer.es6 index a5f42d095..74f0ceba8 100644 --- a/packages/client-app/src/flux/stores/database-transaction.es6 +++ b/packages/client-app/src/flux/stores/database-writer.es6 @@ -7,7 +7,7 @@ import Attributes from '../attributes'; const {AttributeCollection, AttributeJoinedData} = Attributes; -export default class DatabaseTransaction { +export default class DatabaseWriter { constructor(database) { this.database = database; this._changeRecords = []; @@ -23,7 +23,7 @@ export default class DatabaseTransaction { execute(fn) { if (this._opened) { - throw new Error("DatabaseTransaction:execute was already called"); + throw new Error("DatabaseWriter:execute was already called"); } return this._query("BEGIN IMMEDIATE TRANSACTION").then(() => { @@ -66,7 +66,7 @@ export default class DatabaseTransaction { // callbacks failed persistModel(model, opts = {}) { if (!model || !(model instanceof Model)) { - throw new Error("DatabaseTransaction::persistModel - You must pass an instance of the Model class."); + throw new Error("DatabaseWriter::persistModel - You must pass an instance of the Model class."); } return this.persistModels([model], opts); } @@ -102,15 +102,15 @@ export default class DatabaseTransaction { const ids = {}; if (!(models[0] instanceof Model)) { - throw new Error(`DatabaseTransaction::persistModels - You must pass an array of items which descend from the Model class.`); + throw new Error(`DatabaseWriter::persistModels - You must pass an array of items which descend from the Model class.`); } for (const model of models) { if (!model || (model.constructor !== klass)) { - throw new Error(`DatabaseTransaction::persistModels - When you batch persist objects, they must be of the same type`); + throw new Error(`DatabaseWriter::persistModels - When you batch persist objects, they must be of the same type`); } if (ids[model.id]) { - throw new Error(`DatabaseTransaction::persistModels - You must pass an array of models with different ids. ID ${model.id} is in the set multiple times.`) + throw new Error(`DatabaseWriter::persistModels - You must pass an array of models with different ids. ID ${model.id} is in the set multiple times.`) } clones.push(model.clone()); ids[model.id] = true; @@ -183,7 +183,7 @@ export default class DatabaseTransaction { return Promise.all(beforePromises).catch((e) => { if (!NylasEnv.inSpecMode()) { - console.warn(`DatabaseTransaction Hook: ${selectorName} failed`, e); + console.warn(`DatabaseWriter Hook: ${selectorName} failed`, e); } return Promise.resolve([]); }); @@ -365,7 +365,7 @@ export default class DatabaseTransaction { } return query } catch (error) { - throw new Error(`DatabaseTransaction: Error trying to perform ${operation} on database. Is it defined?`) + throw new Error(`DatabaseWriter: Error trying to perform ${operation} on database. Is it defined?`) } } } diff --git a/packages/client-app/src/global/nylas-exports.es6 b/packages/client-app/src/global/nylas-exports.es6 index 66fbcfabf..73012ab14 100644 --- a/packages/client-app/src/global/nylas-exports.es6 +++ b/packages/client-app/src/global/nylas-exports.es6 @@ -80,7 +80,7 @@ lazyLoad(`DatabaseStore`, 'flux/stores/database-store'); lazyLoad(`QueryResultSet`, 'flux/models/query-result-set'); lazyLoad(`QuerySubscription`, 'flux/models/query-subscription'); lazyLoad(`CalendarDataSource`, 'components/nylas-calendar/calendar-data-source'); -lazyLoad(`DatabaseTransaction`, 'flux/stores/database-transaction'); +lazyLoad(`DatabaseWriter`, 'flux/stores/database-writer'); lazyLoad(`MutableQueryResultSet`, 'flux/models/mutable-query-result-set'); lazyLoad(`QuerySubscriptionPool`, 'flux/models/query-subscription-pool'); lazyLoad(`ObservableListDataSource`, 'flux/stores/observable-list-data-source');