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IACH,CAAC;IAEO,wCAAW,GAAnB,UAAoB,IAAY;QAC9B,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC5B,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,uBAAY,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;SAC1D;IACH,CAAC;IACH,yBAAC;AAAD,CAAC,AAhmBD,IAgmBC;AAhmBY,gDAAkB","sourcesContent":["declare let window: any;\nconst _global = typeof global !== 'undefined' ? global : (typeof window !== 'undefined' ? window : {});\nconst NativeWebSocket = _global.WebSocket || _global.MozWebSocket;\n\nimport * as Backoff from 'backo2';\nimport { default as EventEmitterType, EventEmitter, ListenerFn } from 'eventemitter3';\nimport isString from './utils/is-string';\nimport isObject from './utils/is-object';\nimport { ExecutionResult } from 'graphql/execution/execute';\nimport { print } from 'graphql/language/printer';\nimport { DocumentNode } from 'graphql/language/ast';\nimport { getOperationAST } from 'graphql/utilities/getOperationAST';\nimport $$observable from 'symbol-observable';\n\nimport { GRAPHQL_WS } from './protocol';\nimport { MIN_WS_TIMEOUT, WS_TIMEOUT } from './defaults';\nimport MessageTypes from './message-types';\n\nexport interface Observer<T> {\n next?: (value: T) => void;\n error?: (error: Error) => void;\n complete?: () => void;\n}\n\nexport interface Observable<T> {\n subscribe(observer: Observer<T>): {\n unsubscribe: () => void;\n };\n}\n\nexport interface OperationOptions {\n query?: string | DocumentNode;\n variables?: Object;\n operationName?: string;\n [key: string]: any;\n}\n\nexport type FormatedError = Error & {\n originalError?: any;\n};\n\nexport interface Operation {\n options: OperationOptions;\n handler: (error: Error[], result?: any) => void;\n}\n\nexport interface Operations {\n [id: string]: Operation;\n}\n\nexport interface Middleware {\n applyMiddleware(options: OperationOptions, next: Function): void;\n}\n\nexport type ConnectionParams = {\n [paramName: string]: any,\n};\n\nexport type ConnectionParamsOptions = ConnectionParams | Function | Promise<ConnectionParams>;\n\nexport interface ClientOptions {\n connectionParams?: ConnectionParamsOptions;\n minTimeout?: number;\n timeout?: number;\n reconnect?: boolean;\n reconnectionAttempts?: number;\n connectionCallback?: (error: Error[], result?: any) => void;\n lazy?: boolean;\n inactivityTimeout?: number;\n wsOptionArguments?: any[];\n}\n\nexport class SubscriptionClient {\n public client: any;\n public operations: Operations;\n private url: string;\n private nextOperationId: number;\n private connectionParams: Function;\n private minWsTimeout: number;\n private wsTimeout: number;\n private unsentMessagesQueue: Array<any>; // queued messages while websocket is opening.\n private reconnect: boolean;\n private reconnecting: boolean;\n private reconnectionAttempts: number;\n private backoff: any;\n private connectionCallback: any;\n private eventEmitter: EventEmitterType;\n private lazy: boolean;\n private inactivityTimeout: number;\n private inactivityTimeoutId: any;\n private closedByUser: boolean;\n private wsImpl: any;\n private wsProtocols: string | string[];\n private wasKeepAliveReceived: boolean;\n private tryReconnectTimeoutId: any;\n private checkConnectionIntervalId: any;\n private maxConnectTimeoutId: any;\n private middlewares: Middleware[];\n private maxConnectTimeGenerator: any;\n private wsOptionArguments: any[];\n\n constructor(\n url: string,\n options?: ClientOptions,\n webSocketImpl?: any,\n webSocketProtocols?: string | string[],\n ) {\n const {\n connectionCallback = undefined,\n connectionParams = {},\n minTimeout = MIN_WS_TIMEOUT,\n timeout = WS_TIMEOUT,\n reconnect = false,\n reconnectionAttempts = Infinity,\n lazy = false,\n inactivityTimeout = 0,\n wsOptionArguments = [],\n } = (options || {});\n\n this.wsImpl = webSocketImpl || NativeWebSocket;\n if (!this.wsImpl) {\n throw new Error('Unable to find native implementation, or alternative implementation for WebSocket!');\n }\n\n this.wsProtocols = webSocketProtocols || GRAPHQL_WS;\n this.connectionCallback = connectionCallback;\n this.url = url;\n this.operations = {};\n this.nextOperationId = 0;\n this.minWsTimeout = minTimeout;\n this.wsTimeout = timeout;\n this.unsentMessagesQueue = [];\n this.reconnect = reconnect;\n this.reconnecting = false;\n this.reconnectionAttempts = reconnectionAttempts;\n this.lazy = !!lazy;\n this.inactivityTimeout = inactivityTimeout;\n this.closedByUser = false;\n this.backoff = new Backoff({ jitter: 0.5 });\n this.eventEmitter = new EventEmitter();\n this.middlewares = [];\n this.client = null;\n this.maxConnectTimeGenerator = this.createMaxConnectTimeGenerator();\n this.connectionParams = this.getConnectionParams(connectionParams);\n this.wsOptionArguments = wsOptionArguments;\n\n if (!this.lazy) {\n this.connect();\n }\n }\n\n public get status() {\n if (this.client === null) {\n return this.wsImpl.CLOSED;\n }\n\n return this.client.readyState;\n }\n\n public close(isForced = true, closedByUser = true) {\n this.clearInactivityTimeout();\n if (this.client !== null) {\n this.closedByUser = closedByUser;\n\n if (isForced) {\n this.clearCheckConnectionInterval();\n this.clearMaxConnectTimeout();\n this.clearTryReconnectTimeout();\n this.unsubscribeAll();\n this.sendMessage(undefined, MessageTypes.GQL_CONNECTION_TERMINATE, null);\n }\n\n this.client.close();\n this.client.onopen = null;\n this.client.onclose = null;\n this.client.onerror = null;\n this.client.onmessage = null;\n this.client = null;\n this.eventEmitter.emit('disconnected');\n\n if (!isForced) {\n this.tryReconnect();\n }\n }\n }\n\n public request(request: OperationOptions): Observable<ExecutionResult> {\n const getObserver = this.getObserver.bind(this);\n const executeOperation = this.executeOperation.bind(this);\n const unsubscribe = this.unsubscribe.bind(this);\n\n let opId: string;\n\n this.clearInactivityTimeout();\n\n return {\n [$$observable]() {\n return this;\n },\n subscribe(\n observerOrNext: ((Observer<ExecutionResult>) | ((v: ExecutionResult) => void)),\n onError?: (error: Error) => void,\n onComplete?: () => void,\n ) {\n const observer = getObserver(observerOrNext, onError, onComplete);\n\n opId = executeOperation(request, (error: Error[], result: any) => {\n if ( error === null && result === null ) {\n if ( observer.complete ) {\n observer.complete();\n }\n } else if (error) {\n if ( observer.error ) {\n observer.error(error[0]);\n }\n } else {\n if ( observer.next ) {\n observer.next(result);\n }\n }\n });\n\n return {\n unsubscribe: () => {\n if ( opId ) {\n unsubscribe(opId);\n opId = null;\n }\n },\n };\n },\n };\n }\n\n public on(eventName: string, callback: ListenerFn, context?: any): Function {\n const handler = this.eventEmitter.on(eventName, callback, context);\n\n return () => {\n handler.off(eventName, callback, context);\n };\n }\n\n public onConnected(callback: ListenerFn, context?: any): Function {\n return this.on('connected', callback, context);\n }\n\n public onConnecting(callback: ListenerFn, context?: any): Function {\n return this.on('connecting', callback, context);\n }\n\n public onDisconnected(callback: ListenerFn, context?: any): Function {\n return this.on('disconnected', callback, context);\n }\n\n public onReconnected(callback: ListenerFn, context?: any): Function {\n return this.on('reconnected', callback, context);\n }\n\n public onReconnecting(callback: ListenerFn, context?: any): Function {\n return this.on('reconnecting', callback, context);\n }\n\n public onError(callback: ListenerFn, context?: any): Function {\n return this.on('error', callback, context);\n }\n\n public unsubscribeAll() {\n Object.keys(this.operations).forEach( subId => {\n this.unsubscribe(subId);\n });\n }\n\n public applyMiddlewares(options: OperationOptions): Promise<OperationOptions> {\n return new Promise((resolve, reject) => {\n const queue = (funcs: Middleware[], scope: any) => {\n const next = (error?: any) => {\n if (error) {\n reject(error);\n } else {\n if (funcs.length > 0) {\n const f = funcs.shift();\n if (f) {\n f.applyMiddleware.apply(scope, [options, next]);\n }\n } else {\n resolve(options);\n }\n }\n };\n next();\n };\n\n queue([...this.middlewares], this);\n });\n }\n\n public use(middlewares: Middleware[]): SubscriptionClient {\n middlewares.map((middleware) => {\n if (typeof middleware.applyMiddleware === 'function') {\n this.middlewares.push(middleware);\n } else {\n throw new Error('Middleware must implement the applyMiddleware function.');\n }\n });\n\n return this;\n }\n\n private getConnectionParams(connectionParams: ConnectionParamsOptions): Function {\n return (): Promise<ConnectionParams> => new Promise((resolve, reject) => {\n if (typeof connectionParams === 'function') {\n try {\n return resolve(connectionParams.call(null));\n } catch (error) {\n return reject(error);\n }\n }\n\n resolve(connectionParams);\n });\n }\n\n private executeOperation(options: OperationOptions, handler: (error: Error[], result?: any) => void): string {\n if (this.client === null) {\n this.connect();\n }\n\n const opId = this.generateOperationId();\n this.operations[opId] = { options: options, handler };\n\n this.applyMiddlewares(options)\n .then(processedOptions => {\n this.checkOperationOptions(processedOptions, handler);\n if (this.operations[opId]) {\n this.operations[opId] = { options: processedOptions, handler };\n this.sendMessage(opId, MessageTypes.GQL_START, processedOptions);\n }\n })\n .catch(error => {\n this.unsubscribe(opId);\n handler(this.formatErrors(error));\n });\n\n return opId;\n }\n\n private getObserver<T>(\n observerOrNext: ((Observer<T>) | ((v: T) => void)),\n error?: (e: Error) => void,\n complete?: () => void,\n ) {\n if ( typeof observerOrNext === 'function' ) {\n return {\n next: (v: T) => observerOrNext(v),\n error: (e: Error) => error && error(e),\n complete: () => complete && complete(),\n };\n }\n\n return observerOrNext;\n }\n\n private createMaxConnectTimeGenerator() {\n const minValue = this.minWsTimeout;\n const maxValue = this.wsTimeout;\n\n return new Backoff({\n min: minValue,\n max: maxValue,\n factor: 1.2,\n });\n }\n\n private clearCheckConnectionInterval() {\n if (this.checkConnectionIntervalId) {\n clearInterval(this.checkConnectionIntervalId);\n this.checkConnectionIntervalId = null;\n }\n }\n\n private clearMaxConnectTimeout() {\n if (this.maxConnectTimeoutId) {\n clearTimeout(this.maxConnectTimeoutId);\n this.maxConnectTimeoutId = null;\n }\n }\n\n private clearTryReconnectTimeout() {\n if (this.tryReconnectTimeoutId) {\n clearTimeout(this.tryReconnectTimeoutId);\n this.tryReconnectTimeoutId = null;\n }\n }\n\n private clearInactivityTimeout() {\n if (this.inactivityTimeoutId) {\n clearTimeout(this.inactivityTimeoutId);\n this.inactivityTimeoutId = null;\n }\n }\n\n private setInactivityTimeout() {\n if (this.inactivityTimeout > 0 && Object.keys(this.operations).length === 0) {\n this.inactivityTimeoutId = setTimeout(() => {\n if (Object.keys(this.operations).length === 0) {\n this.close();\n }\n }, this.inactivityTimeout);\n }\n }\n\n private checkOperationOptions(options: OperationOptions, handler: (error: Error[], result?: any) => void) {\n const { query, variables, operationName } = options;\n\n if (!query) {\n throw new Error('Must provide a query.');\n }\n\n if (!handler) {\n throw new Error('Must provide an handler.');\n }\n\n if (\n ( !isString(query) && !getOperationAST(query, operationName)) ||\n ( operationName && !isString(operationName)) ||\n ( variables && !isObject(variables))\n ) {\n throw new Error('Incorrect option types. query must be a string or a document,' +\n '`operationName` must be a string, and `variables` must be an object.');\n }\n }\n\n private buildMessage(id: string, type: string, payload: any) {\n const payloadToReturn = payload && payload.query ?\n {\n ...payload,\n query: typeof payload.query === 'string' ? payload.query : print(payload.query),\n } :\n payload;\n\n return {\n id,\n type,\n payload: payloadToReturn,\n };\n }\n\n // ensure we have an array of errors\n private formatErrors(errors: any): FormatedError[] {\n if (Array.isArray(errors)) {\n return errors;\n }\n\n // TODO we should not pass ValidationError to callback in the future.\n // ValidationError\n if (errors && errors.errors) {\n return this.formatErrors(errors.errors);\n }\n\n if (errors && errors.message) {\n return [errors];\n }\n\n return [{\n name: 'FormatedError',\n message: 'Unknown error',\n originalError: errors,\n }];\n }\n\n private sendMessage(id: string, type: string, payload: any) {\n this.sendMessageRaw(this.buildMessage(id, type, payload));\n }\n\n // send message, or queue it if connection is not open\n private sendMessageRaw(message: Object) {\n switch (this.status) {\n case this.wsImpl.OPEN:\n let serializedMessage: string = JSON.stringify(message);\n try {\n JSON.parse(serializedMessage);\n } catch (e) {\n this.eventEmitter.emit('error', new Error(`Message must be JSON-serializable. Got: ${message}`));\n }\n\n this.client.send(serializedMessage);\n break;\n case this.wsImpl.CONNECTING:\n this.unsentMessagesQueue.push(message);\n\n break;\n default:\n if (!this.reconnecting) {\n this.eventEmitter.emit('error', new Error('A message was not sent because socket is not connected, is closing or ' +\n 'is already closed. Message was: ' + JSON.stringify(message)));\n }\n }\n }\n\n private generateOperationId(): string {\n return String(++this.nextOperationId);\n }\n\n private tryReconnect() {\n if (!this.reconnect || this.backoff.attempts >= this.reconnectionAttempts) {\n return;\n }\n\n if (!this.reconnecting) {\n Object.keys(this.operations).forEach((key) => {\n this.unsentMessagesQueue.push(\n this.buildMessage(key, MessageTypes.GQL_START, this.operations[key].options),\n );\n });\n this.reconnecting = true;\n }\n\n this.clearTryReconnectTimeout();\n\n const delay = this.backoff.duration();\n this.tryReconnectTimeoutId = setTimeout(() => {\n this.connect();\n }, delay);\n }\n\n private flushUnsentMessagesQueue() {\n this.unsentMessagesQueue.forEach((message) => {\n this.sendMessageRaw(message);\n });\n this.unsentMessagesQueue = [];\n }\n\n private checkConnection() {\n if (this.wasKeepAliveReceived) {\n this.wasKeepAliveReceived = false;\n return;\n }\n\n if (!this.reconnecting) {\n this.close(false, true);\n }\n }\n\n private checkMaxConnectTimeout() {\n this.clearMaxConnectTimeout();\n\n // Max timeout trying to connect\n this.maxConnectTimeoutId = setTimeout(() => {\n if (this.status !== this.wsImpl.OPEN) {\n this.reconnecting = true;\n this.close(false, true);\n }\n }, this.maxConnectTimeGenerator.duration());\n }\n\n private connect() {\n this.client = new this.wsImpl(this.url, this.wsProtocols, ...this.wsOptionArguments);\n\n this.checkMaxConnectTimeout();\n\n this.client.onopen = async () => {\n if (this.status === this.wsImpl.OPEN) {\n this.clearMaxConnectTimeout();\n this.closedByUser = false;\n this.eventEmitter.emit(this.reconnecting ? 'reconnecting' : 'connecting');\n\n try {\n const connectionParams: ConnectionParams = await this.connectionParams();\n\n // Send CONNECTION_INIT message, no need to wait for connection to success (reduce roundtrips)\n this.sendMessage(undefined, MessageTypes.GQL_CONNECTION_INIT, connectionParams);\n this.flushUnsentMessagesQueue();\n } catch (error) {\n this.sendMessage(undefined, MessageTypes.GQL_CONNECTION_ERROR, error);\n this.flushUnsentMessagesQueue();\n }\n }\n };\n\n this.client.onclose = () => {\n if (!this.closedByUser) {\n this.close(false, false);\n }\n };\n\n this.client.onerror = (err: Error) => {\n // Capture and ignore errors to prevent unhandled exceptions, wait for\n // onclose to fire before attempting a reconnect.\n this.eventEmitter.emit('error', err);\n };\n\n this.client.onmessage = ({ data }: {data: any}) => {\n this.processReceivedData(data);\n };\n }\n\n private processReceivedData(receivedData: any) {\n let parsedMessage: any;\n let opId: string;\n\n try {\n parsedMessage = JSON.parse(receivedData);\n opId = parsedMessage.id;\n } catch (e) {\n throw new Error(`Message must be JSON-parseable. Got: ${receivedData}`);\n }\n\n if (\n [ MessageTypes.GQL_DATA,\n MessageTypes.GQL_COMPLETE,\n MessageTypes.GQL_ERROR,\n ].indexOf(parsedMessage.type) !== -1 && !this.operations[opId]\n ) {\n this.unsubscribe(opId);\n\n return;\n }\n\n switch (parsedMessage.type) {\n case MessageTypes.GQL_CONNECTION_ERROR:\n if (this.connectionCallback) {\n this.connectionCallback(parsedMessage.payload);\n }\n break;\n\n case MessageTypes.GQL_CONNECTION_ACK:\n this.eventEmitter.emit(this.reconnecting ? 'reconnected' : 'connected', parsedMessage.payload);\n this.reconnecting = false;\n this.backoff.reset();\n this.maxConnectTimeGenerator.reset();\n\n if (this.connectionCallback) {\n this.connectionCallback();\n }\n break;\n\n case MessageTypes.GQL_COMPLETE:\n const handler = this.operations[opId].handler;\n delete this.operations[opId];\n handler.call(this, null, null);\n break;\n\n case MessageTypes.GQL_ERROR:\n this.operations[opId].handler(this.formatErrors(parsedMessage.payload), null);\n delete this.operations[opId];\n break;\n\n case MessageTypes.GQL_DATA:\n const parsedPayload = !parsedMessage.payload.errors ?\n parsedMessage.payload : {...parsedMessage.payload, errors: this.formatErrors(parsedMessage.payload.errors)};\n this.operations[opId].handler(null, parsedPayload);\n break;\n\n case MessageTypes.GQL_CONNECTION_KEEP_ALIVE:\n const firstKA = typeof this.wasKeepAliveReceived === 'undefined';\n this.wasKeepAliveReceived = true;\n\n if (firstKA) {\n this.checkConnection();\n }\n\n if (this.checkConnectionIntervalId) {\n clearInterval(this.checkConnectionIntervalId);\n this.checkConnection();\n }\n this.checkConnectionIntervalId = setInterval(this.checkConnection.bind(this), this.wsTimeout);\n break;\n\n default:\n throw new Error('Invalid message type!');\n }\n }\n\n private unsubscribe(opId: string) {\n if (this.operations[opId]) {\n delete this.operations[opId];\n this.setInactivityTimeout();\n this.sendMessage(opId, MessageTypes.GQL_STOP, undefined);\n }\n }\n}\n"]}