Remove deprecations still supported by client

This commit is contained in:
Ben Gotow 2017-06-25 01:04:02 -07:00
parent 555681546d
commit bd9983005c
47 changed files with 34 additions and 395 deletions

View file

@ -1036,11 +1036,8 @@
3662409: src/nylas-spellchecker.js
3798011: src/global/nylas-exports.js
3798011: src/global/nylas-exports.js
5912469: src/deprecate-utils.js
3668481: src/config-schema.js
5912469: src/deprecate-utils.js
3798011: src/global/nylas-exports.js
5912469: src/deprecate-utils.js
3668481: src/config-schema.js
4687050: src/global/nylas-observables.js
4697858: node_modules/rx-lite/package.json

View file

@ -6,14 +6,11 @@ import {
DatabaseStore,
SearchQueryParser,
ComponentRegistry,
NylasLongConnection,
FocusedContentStore,
MutableQuerySubscription,
} from 'nylas-exports'
import SearchActions from './search-actions'
const {LongConnectionStatus} = NylasAPI
class SearchQuerySubscription extends MutableQuerySubscription {
constructor(searchQuery, accountIds) {
@ -94,37 +91,37 @@ class SearchQuerySubscription extends MutableQuerySubscription {
}
performRemoteSearch() {
const accountsSearched = new Set()
const allAccountsSearched = () => accountsSearched.size === this._accountIds.length
this._connections = this._accountIds.map((accountId) => {
const conn = new NylasLongConnection({
accountId,
api: NylasAPI,
path: `/threads/search/streaming?q=${encodeURIComponent(this._searchQuery)}`,
onResults: (results) => {
if (!this._remoteResultsReceivedAt) {
this._remoteResultsReceivedAt = Date.now();
}
const threads = results[0];
this._remoteResultsCount += threads.length;
},
onStatusChanged: (status) => {
const hasClosed = [
LongConnectionStatus.Closed,
LongConnectionStatus.Ended,
].includes(status)
// const accountsSearched = new Set()
// const allAccountsSearched = () => accountsSearched.size === this._accountIds.length
// this._connections = this._accountIds.map((accountId) => {
// const conn = new NylasLongConnection({
// accountId,
// api: NylasAPI,
// path: `/threads/search/streaming?q=${encodeURIComponent(this._searchQuery)}`,
// onResults: (results) => {
// if (!this._remoteResultsReceivedAt) {
// this._remoteResultsReceivedAt = Date.now();
// }
// const threads = results[0];
// this._remoteResultsCount += threads.length;
// },
// onStatusChanged: (status) => {
// const hasClosed = [
// LongConnectionStatus.Closed,
// LongConnectionStatus.Ended,
// ].includes(status)
if (hasClosed) {
accountsSearched.add(accountId)
if (allAccountsSearched()) {
SearchActions.searchCompleted()
}
}
},
})
// if (hasClosed) {
// accountsSearched.add(accountId)
// if (allAccountsSearched()) {
// SearchActions.searchCompleted()
// }
// }
// },
// })
return conn.start()
})
// return conn.start()
// })
}
performExtensionSearch() {

View file

@ -5,7 +5,6 @@ class TestExtension
describe 'ExtensionRegistry', ->
beforeEach ->
@originalAdapters = ExtensionRegistry._deprecationAdapters
@registry = new ExtensionRegistry.Registry('Test')
spyOn @registry, 'triggerDebounced'
@ -43,13 +42,6 @@ describe 'ExtensionRegistry', ->
@registry.register({name: 'TestExtension'})
expect(@registry.extensions().length).toEqual 1
it 'calls deprecationAdapters if present for a role', ->
adapterSpy = jasmine.createSpy('adapterSpy').andCallFake (ext) -> ext
@registry = new ExtensionRegistry.Registry('Test', adapterSpy)
spyOn @registry, 'triggerDebounced'
@registry.register(TestExtension)
expect(adapterSpy.calls.length).toEqual 1
describe 'unregister', ->
it 'unregisters the extension if it exists', ->
@registry.register(TestExtension)

View file

@ -1,30 +0,0 @@
class DeprecateUtils
# See
# http://www.codeovertones.com/2011/08/how-to-print-stack-trace-anywhere-in.html
@parseStack: (stackString) ->
stack = stackString
.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n')
return stack
@warn: (condition, message) ->
console.warn message if condition
@deprecate: (fnName, newName, ctx, fn) ->
if NylasEnv.inDevMode() and not NylasEnv.inSpecMode()
warn = true
newFn = =>
stack = DeprecateUtils.parseStack((new Error()).stack)
DeprecateUtils.warn(
warn,
"Deprecation warning! #{fnName} is deprecated and will be removed soon.
Use #{newName} instead.\nCheck your code at #{stack[1]}"
)
warn = false
return fn.apply(ctx, arguments)
return Object.assign(newFn, fn)
return fn
module.exports = DeprecateUtils

View file

@ -1,5 +1,4 @@
import AccountStore from './stores/account-store'
import NylasLongConnection from './nylas-long-connection'
// A 0 code is when an error returns without a status code, like "ESOCKETTIMEDOUT"
const TimeoutErrorCodes = [0, 408, "ETIMEDOUT", "ESOCKETTIMEDOUT", "ECONNRESET", "ENETDOWN", "ENETUNREACH"]
@ -52,7 +51,6 @@ class NylasAPI {
this.PermanentErrorCodes = PermanentErrorCodes
this.CanceledErrorCodes = CanceledErrorCodes
this.SampleTemporaryErrorCode = SampleTemporaryErrorCode
this.LongConnectionStatus = NylasLongConnection.Status
}
accessTokenForAccountId(aid) {

View file

@ -1,246 +0,0 @@
/* eslint global-require: 0 */
import _ from 'underscore'
import url from 'url'
import {Emitter} from 'event-kit'
import {IdentityStore, APIError} from 'nylas-exports'
const CONNECTION_TIMEOUT = 60 * 60 * 1000
const PROCESS_BUFFER_THROTTLE = 400
const Status = {
None: 'none',
Connecting: 'connecting',
Connected: 'connected',
Closed: 'closed', // Socket has been closed for any reason
Ended: 'ended', // We have received 'end()' and will never open again.
}
class NylasLongConnection {
static Status = Status
constructor({api, accountId, ...opts} = {}) {
const {
path,
timeout,
onError,
onResults,
onStatusChanged,
throttleResultsInterval,
closeIfDataStopsInterval,
} = opts
this._api = api
this._accountId = accountId
this._status = Status.None
this._emitter = new Emitter()
this._req = null
this._buffer = ''
this._results = []
this._pingTimeout = null
this._httpStatusCode = null
// Options
this._path = path
this._timeout = timeout || CONNECTION_TIMEOUT
this._onError = onError || (() => {})
this._onResults = onResults || (() => {})
this._onStatusChanged = onStatusChanged || (() => {})
this._closeIfDataStopsInterval = closeIfDataStopsInterval
this._emitter.on('results-stopped-arriving', this._onResults)
this._processBufferThrottled = _.throttle(this._processBuffer, PROCESS_BUFFER_THROTTLE, {leading: false})
this._flushResultsSoon = () => {
if (this._results.length === 0) { return }
this._emitter.emit('results-stopped-arriving', this._results);
this._results = []
}
if (throttleResultsInterval != null) {
this._flushResultsSoon = _.throttle(this._flushResultsSoon, throttleResultsInterval)
}
}
_processBuffer() {
const bufferJSONs = this._buffer.split('\n')
// We can't parse the last block - we don't know whether we've
// received the entire result or only part of it. Wait
// until we have more.
this._buffer = bufferJSONs.pop()
bufferJSONs.forEach((resultJSON) => {
if (resultJSON.length === 0) { return }
let result = null
try {
result = JSON.parse(resultJSON)
} catch (e) {
console.warn(`${resultJSON} could not be parsed as JSON.`, e)
}
if (result) {
this._results.push(result)
}
})
this._flushResultsSoon()
}
get accountId() {
return this._accountId;
}
get status() {
return this._status;
}
setStatus(status) {
if (this._status === status) { return }
this._status = status
this._onStatusChanged(this._status, this._httpStatusCode)
}
onError(error) {
this._onError(error)
this.close()
}
canStart() {
return [Status.None, Status.Closed].includes(this._status)
}
start() {
if (!this.canStart()) { return this }
if (this._req != null) { return this }
try {
const accountToken = this._api.accessTokenForAccountId(this._accountId)
const identityToken = (IdentityStore.identity() || {}).token || ''
if (!accountToken) {
throw new APIError({
statusCode: 401,
message: `Can't establish NylasLongConnection: No account token available for account ${this._accountId}`,
})
}
const options = url.parse(`${this._api.APIRoot}${this._path}`)
options.auth = `${accountToken}:${identityToken}`
let lib;
if (this._api.APIRoot.indexOf('https') === -1) {
lib = require('http')
} else {
lib = require('https')
}
this._req = lib.request(options, (responseStream) => {
this._req.responseStream = responseStream
this._httpStatusCode = responseStream.statusCode
if (responseStream.statusCode !== 200) {
responseStream.on('data', (chunk) => {
const error = new APIError({
response: responseStream,
message: chunk.toString('utf8'),
statusCode: responseStream.statusCode,
})
this.onError(error)
})
return
}
responseStream.setEncoding('utf8')
responseStream.on('error', (error) => {
this.onError(new APIError({error}))
})
responseStream.on('close', () => this.close())
responseStream.on('end', () => this.close())
responseStream.on('data', (chunk) => {
this.closeIfDataStops()
// Ignore redundant newlines sent as pings. Want to avoid
// calls to this.onProcessBuffer that contain no actual updates
if (chunk === '\n' && (this._buffer.length === 0 || _.last(this._buffer) === '\n')) {
return
}
this._buffer += chunk
this._processBufferThrottled()
})
})
this._req.setTimeout(60 * 60 * 1000)
this._req.setSocketKeepAlive(true)
this._req.on('error', (error) => {
this.onError(new APIError({error}))
})
this._req.on('socket', (socket) => {
this.setStatus(Status.Connecting)
socket.on('connect', () => {
this.setStatus(Status.Connected)
this.closeIfDataStops()
})
socket.on('error', (error) => {
this.onError(new APIError({error}))
})
socket.on('close', () => this.close())
socket.on('end', () => this.close())
})
// We `end` the request to start it.
// See https://github.com/nylas/nylas-mail/pull/2004
this._req.end()
return this
} catch (err) {
// start() should not throw any errors synchronously. Any errors should be
// asynchronously transmitted to the caller via `onError`
setTimeout(() => this.onError(err), 0)
return this
}
}
closeIfDataStops() {
if (this._closeIfDataStopsInterval != null) {
clearTimeout(this._pingTimeout)
this._pingTimeout = setTimeout(() => {
this._pingTimeout = null
this.close()
}, this._closeIfDataStopsInterval)
}
}
dispose(status) {
// Process the buffer one last time before disposing of the connection
// in case there is any data left that we haven't processed
this._processBuffer()
if (this._status !== status) {
this.setStatus(status)
}
clearTimeout(this._pingTimeout)
this._pingTimeout = null
this._httpStatusCode = null
this._buffer = ''
if (this._req) {
this._req.end()
this._req.abort()
this._req.removeAllListeners()
if (this._req.responseStream) {
this._req.responseStream.removeAllListeners()
}
if (this._req.socket) {
this._req.socket.removeAllListeners()
}
// Keep an error handler to prevent from logging and reporting uncaught
// errors that may occur after aborting this current request.
// For example, if we manually close this connection before any data has
// been received (frequently happens when searching threads), this will
// throw an uncaught socket hang up error that will get unnecessarily
// reported to sentry
this._req.on('error', () => {})
this._req = null
}
return this
}
close() {
return this.dispose(Status.Closed)
}
end() {
return this.dispose(Status.Ended)
}
}
export default NylasLongConnection

View file

@ -9,7 +9,6 @@ FocusedPerspectiveStore = require('./focused-perspective-store').default
FocusedContentStore = require "./focused-content-store"
NylasAPIHelpers = require '../nylas-api-helpers'
ExtensionRegistry = require('../../registries/extension-registry')
{deprecate} = require '../../deprecate-utils'
async = require 'async'
_ = require 'underscore'
@ -67,24 +66,6 @@ class MessageStore extends NylasStore
extensions: =>
ExtensionRegistry.MessageView.extensions()
# Public: Deprecated, use {ExtensionRegistry.MessageView.register} instead.
# Registers a new extension with the MessageStore. MessageStore extensions
# make it possible to customize message body parsing, and will do more in
# the future.
#
# - `ext` A {MessageViewExtension} instance.
#
registerExtension: (ext) =>
ExtensionRegistry.MessageView.register(ext)
# Public: Deprecated, use {ExtensionRegistry.MessageView.unregister} instead.
# Unregisters the extension provided from the MessageStore.
#
# - `ext` A {MessageViewExtension} instance.
#
unregisterExtension: (ext) =>
ExtensionRegistry.MessageView.unregister(ext)
_onExtensionsChanged: (role) ->
MessageBodyProcessor = require('./message-body-processor').default
MessageBodyProcessor.resetCache()
@ -332,18 +313,6 @@ class MessageStore extends NylasStore
store = new MessageStore()
store.registerExtension = deprecate(
'MessageStore.registerExtension',
'ExtensionRegistry.MessageView.register',
store,
store.registerExtension
)
store.unregisterExtension = deprecate(
'MessageStore.unregisterExtension',
'ExtensionRegistry.MessageView.unregister',
store,
store.unregisterExtension
)
store.FolderNamesHiddenByDefault = FolderNamesHiddenByDefault
module.exports = store

View file

@ -30,19 +30,11 @@ class NylasComponentKit
exported = require "../components/#{path}"
return exported[prop]
@loadDeprecated = (prop, path, {instead} = {}) ->
{deprecate} = require '../deprecate-utils'
Object.defineProperty @prototype, prop,
get: deprecate prop, instead, @, ->
exported = NylasComponentKit.default(require "../components/#{path}")
return exported
enumerable: true
@load "Menu", 'menu'
@load "DropZone", 'drop-zone'
@load "Spinner", 'spinner'
@load "Switch", 'switch'
@loadDeprecated "Popover", 'popover', instead: 'Actions.openPopover'
@load "FixedPopover", 'fixed-popover'
@require "DatePickerPopover", 'date-picker-popover'
@load "Modal", 'modal'
@ -73,7 +65,6 @@ class NylasComponentKit
@load "InjectedComponent", 'injected-component'
@load "TokenizingTextField", 'tokenizing-text-field'
@load "ParticipantsTextField", 'participants-text-field'
@loadDeprecated "MultiselectActionBar", 'multiselect-action-bar', instead: 'MultiselectToolbar'
@load "MultiselectToolbar", 'multiselect-toolbar'
@load "InjectedComponentSet", 'injected-component-set'
@load "MetadataComposerToggleButton", 'metadata-composer-toggle-button'

View file

@ -51,16 +51,6 @@ const lazyLoadAndRegisterTask = (klassName, path) => {
DatabaseObjectRegistry.register(klassName, () => exports[klassName]);
};
const lazyLoadDeprecated = (prop, path, {instead} = {}) => {
const {deprecate} = require('../deprecate-utils');
Object.defineProperty(exports, prop, {
get: deprecate(prop, instead, exports, () => {
return resolveExport(require(`../${path}`));
}),
enumerable: true,
});
};
// Actions
lazyLoad(`Actions`, 'flux/actions');
@ -71,7 +61,6 @@ lazyLoad(`EdgehillAPI`, 'flux/edgehill-api');
lazyLoad(`LegacyEdgehillAPI`, 'flux/legacy-edgehill-api');
lazyLoad(`NylasAPIHelpers`, 'flux/nylas-api-helpers');
lazyLoad(`NylasAPIRequest`, 'flux/nylas-api-request');
lazyLoad(`NylasLongConnection`, 'flux/nylas-long-connection');
// The Database
lazyLoad(`Matcher`, 'flux/attributes/matcher');
@ -196,7 +185,6 @@ lazyLoad(`FsUtils`, 'fs-utils');
lazyLoad(`CanvasUtils`, 'canvas-utils');
lazyLoad(`RegExpUtils`, 'regexp-utils');
lazyLoad(`MenuHelpers`, 'menu-helpers');
lazyLoad(`DeprecateUtils`, 'deprecate-utils');
lazyLoad(`VirtualDOMUtils`, 'virtual-dom-utils');
lazyLoad(`Spellchecker`, 'spellchecker');
lazyLoad(`DraftHelpers`, 'flux/stores/draft-helpers');
@ -231,14 +219,3 @@ lazyLoadWithGetter(`APMWrapper`, () => require('../apm-wrapper'));
// Testing
lazyLoadWithGetter(`NylasTestUtils`, () => require('../../spec/nylas-test-utils'));
// Deprecated
lazyLoadDeprecated(`QuotedHTMLParser`, 'services/quoted-html-transformer', {
instead: 'QuotedHTMLTransformer',
});
lazyLoadDeprecated(`DraftStoreExtension`, 'flux/stores/draft-store-extension', {
instead: 'ComposerExtension',
});
lazyLoadDeprecated(`MessageStoreExtension`, 'flux/stores/message-store-extension', {
instead: 'MessageViewExtension',
});

View file

@ -6,16 +6,14 @@ export class Registry {
static include = includeModule;
constructor(name, deprecationAdapter = (ext) => ext) {
constructor(name) {
this.name = name;
this._deprecationAdapter = deprecationAdapter;
this._registry = new Map();
}
register(ext, {priority = 0} = {}) {
this.validateExtension(ext, 'register');
const extension = this._deprecationAdapter(ext)
this._registry.set(ext.name, {extension, priority});
register(extension, {priority = 0} = {}) {
this.validateExtension(extension, 'register');
this._registry.set(extension.name, {extension, priority});
this.triggerDebounced();
return this;
}

View file

@ -288,10 +288,6 @@ class ThemeManager
themePaths = []
for themeName in @getEnabledThemeNames()
if themePath = @packageManager.resolvePackagePath(themeName)
deprecatedPath = path.join(themePath, 'stylesheets')
if fs.isDirectorySync(deprecatedPath)
themePaths.push(deprecatedPath)
else
themePaths.push(path.join(themePath, 'styles'))
themePaths.push(path.join(themePath, 'styles'))
themePaths.filter (themePath) -> fs.isDirectorySync(themePath)