{"version":3,"sources":["meteor://💻app/packages/ddp-common/namespace.js","meteor://💻app/packages/ddp-common/heartbeat.js","meteor://💻app/packages/ddp-common/utils.js","meteor://💻app/packages/ddp-common/method_invocation.js","meteor://💻app/packages/ddp-common/random_stream.js"],"names":["DDPCommon","Heartbeat","constructor","options","heartbeatInterval","heartbeatTimeout","_sendPing","sendPing","_onTimeout","onTimeout","_seenPacket","_heartbeatIntervalHandle","_heartbeatTimeoutHandle","stop","_clearHeartbeatIntervalTimer","_clearHeartbeatTimeoutTimer","start","_startHeartbeatIntervalTimer","Meteor","setInterval","_heartbeatIntervalFired","_startHeartbeatTimeoutTimer","setTimeout","_heartbeatTimeoutFired","clearInterval","clearTimeout","messageReceived","module","export","hasOwn","slice","keys","isEmpty","last","Object","prototype","hasOwnProperty","Array","obj","isArray","length","key","call","array","n","guard","Math","max","SUPPORTED_DDP_VERSIONS","parseDDP","stringMessage","msg","JSON","parse","e","_debug","fields","cleared","forEach","clearKey","undefined","field","EJSON","_adjustTypesFromJSONValue","stringifyDDP","copy","clone","value","push","_adjustTypesToJSONValue","id","Error","stringify","MethodInvocation","isSimulation","_unblock","unblock","_calledUnblock","userId","_setUserId","setUserId","connection","randomSeed","randomStream","RandomStream","seed","concat","randomToken","sequences","create","_sequence","name","self","sequence","sequenceSeed","i","Random","createWithSeeds","apply","hexString","get","scope","insecure","makeRpcSeed","enclosing","methodName","stream"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACAA,SAAS,GAAG,EAAZ,C;;;;;;;;;;;ACRA;AACA;AACA;AACA;AACA;AACA;AAEAA,SAAS,CAACC,SAAV,GAAsB,MAAMA,SAAN,CAAgB;AACpCC,aAAW,CAACC,OAAD,EAAU;AACnB,SAAKC,iBAAL,GAAyBD,OAAO,CAACC,iBAAjC;AACA,SAAKC,gBAAL,GAAwBF,OAAO,CAACE,gBAAhC;AACA,SAAKC,SAAL,GAAiBH,OAAO,C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AACA,SAASN,WAAT,GAAuB;AACrB,SAAOS,MAAM,CAACG,SAAP,CAAiB,EAAjB,CAAP;AACD;;AAAA,C,CAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACAnG,SAAS,CAACoF,YAAV,CAAuBgB,GAAvB,GAA6B,UAAUC,KAAV,EAAiBV,IAAjB,EAAuB;AAClD,MAAI,CAACA,IAAL,EAAW;AACTA,QAAI,GAAG,SAAP;AACD;;AACD,MAAI,CAACU,KAAL,EAAY;AACV;AACA;AACA;AACA;AACA,WAAOL,MAAM,CAACM,QAAd;AACD;;AACD,MAAInB,YAAY,GAAGkB,KAAK,CAAClB,YAAzB;;AACA,MAAI,CAACA,YAAL,EAAmB;AACjBkB,SAAK,CAAClB,YAAN,GAAqBA,YAAY,GAAG,IAAInF,SAAS,CAACoF,YAAd,CAA2B;AAC7DC,UAAI,EAAEgB,KAAK,CAACnB;AADiD,KAA3B,CAApC;AAGD;;AACD,SAAOC,YAAY,CAACO,SAAb,CAAuBC,IAAvB,CAAP;AACD,CAlBD,C,CAoBA;AACA;AACA;AACA;AACA;AACA;;;AACA3F,SAAS,CAACuG,WAAV,GAAwB,UAAUC,SAAV,EAAqBC,UAArB,EAAiC;AACvD,MAAIC,MAAM,GAAG1G,SAAS,CAACoF,YAAV,CAAuBgB,GAAvB,CAA2BI,SAA3B,EAAsC,UAAUC,UAAhD,CAAb;AACA,SAAOC,MAAM,CAACP,SAAP,CAAiB,EAAjB,CAAP;AACD,CAHD,C","file":"/packages/ddp-common.js","sourcesContent":["/**\n * @namespace DDPCommon\n * @summary Namespace for DDPCommon-related methods/classes. Shared between \n * `ddp-client` and `ddp-server`, where the ddp-client is the implementation\n * of a ddp client for both client AND server; and the ddp server is the\n * implementation of the livedata server and stream server. Common \n * functionality shared between both can be shared under this namespace\n */\nDDPCommon = {};\n","// Heartbeat options:\n// heartbeatInterval: interval to send pings, in milliseconds.\n// heartbeatTimeout: timeout to close the connection if a reply isn't\n// received, in milliseconds.\n// sendPing: function to call to send a ping on the connection.\n// onTimeout: function to call to close the connection.\n\nDDPCommon.Heartbeat = class Heartbeat {\n constructor(options) {\n this.heartbeatInterval = options.heartbeatInterval;\n this.heartbeatTimeout = options.heartbeatTimeout;\n this._sendPing = options.sendPing;\n this._onTimeout = options.onTimeout;\n this._seenPacket = false;\n\n this._heartbeatIntervalHandle = null;\n this._heartbeatTimeoutHandle = null;\n }\n\n stop() {\n this._clearHeartbeatIntervalTimer();\n this._clearHeartbeatTimeoutTimer();\n }\n\n start() {\n this.stop();\n this._startHeartbeatIntervalTimer();\n }\n\n _startHeartbeatIntervalTimer() {\n this._heartbeatIntervalHandle = Meteor.setInterval(\n () => this._heartbeatIntervalFired(),\n this.heartbeatInterval\n );\n }\n\n _startHeartbeatTimeoutTimer() {\n this._heartbeatTimeoutHandle = Meteor.setTimeout(\n () => this._heartbeatTimeoutFired(),\n this.heartbeatTimeout\n );\n }\n\n _clearHeartbeatIntervalTimer() {\n if (this._heartbeatIntervalHandle) {\n Meteor.clearInterval(this._heartbeatIntervalHandle);\n this._heartbeatIntervalHandle = null;\n }\n }\n\n _clearHeartbeatTimeoutTimer() {\n if (this._heartbeatTimeoutHandle) {\n Meteor.clearTimeout(this._heartbeatTimeoutHandle);\n this._heartbeatTimeoutHandle = null;\n }\n }\n\n // The heartbeat interval timer is fired when we should send a ping.\n _heartbeatIntervalFired() {\n // don't send ping if we've seen a packet since we last checked,\n // *or* if we have already sent a ping and are awaiting a timeout.\n // That shouldn't happen, but it's possible if\n // `this.heartbeatInterval` is smaller than\n // `this.heartbeatTimeout`.\n if (! this._seenPacket && ! this._heartbeatTimeoutHandle) {\n this._sendPing();\n // Set up timeout, in case a pong doesn't arrive in time.\n this._startHeartbeatTimeoutTimer();\n }\n this._seenPacket = false;\n }\n\n // The heartbeat timeout timer is fired when we sent a ping, but we\n // timed out waiting for the pong.\n _heartbeatTimeoutFired() {\n this._heartbeatTimeoutHandle = null;\n this._onTimeout();\n }\n\n messageReceived() {\n // Tell periodic checkin that we have seen a packet, and thus it\n // does not need to send a ping this cycle.\n this._seenPacket = true;\n // If we were waiting for a pong, we got it.\n if (this._heartbeatTimeoutHandle) {\n this._clearHeartbeatTimeoutTimer();\n }\n }\n};\n","\"use strict\";\n\nexport const hasOwn = Object.prototype.hasOwnProperty;\nexport const slice = Array.prototype.slice;\n\nexport function keys(obj) {\n return Object.keys(Object(obj));\n}\n\nexport function isEmpty(obj) {\n if (obj == null) {\n return true;\n }\n\n if (Array.isArray(obj) ||\n typeof obj === \"string\") {\n return obj.length === 0;\n }\n\n for (const key in obj) {\n if (hasOwn.call(obj, key)) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function last(array, n, guard) {\n if (array == null) {\n return;\n }\n\n if ((n == null) || guard) {\n return array[array.length - 1];\n }\n\n return slice.call(array, Math.max(array.length - n, 0));\n}\n\nDDPCommon.SUPPORTED_DDP_VERSIONS = [ '1', 'pre2', 'pre1' ];\n\nDDPCommon.parseDDP = function (stringMessage) {\n try {\n var msg = JSON.parse(stringMessage);\n } catch (e) {\n Meteor._debug(\"Discarding message with invalid JSON\", stringMessage);\n return null;\n }\n // DDP messages must be objects.\n if (msg === null || typeof msg !== 'object') {\n Meteor._debug(\"Discarding non-object DDP message\", stringMessage);\n return null;\n }\n\n // massage msg to get it into \"abstract ddp\" rather than \"wire ddp\" format.\n\n // switch between \"cleared\" rep of unsetting fields and \"undefined\"\n // rep of same\n if (hasOwn.call(msg, 'cleared')) {\n if (! hasOwn.call(msg, 'fields')) {\n msg.fields = {};\n }\n msg.cleared.forEach(clearKey => {\n msg.fields[clearKey] = undefined;\n });\n delete msg.cleared;\n }\n\n ['fields', 'params', 'result'].forEach(field => {\n if (hasOwn.call(msg, field)) {\n msg[field] = EJSON._adjustTypesFromJSONValue(msg[field]);\n }\n });\n\n return msg;\n};\n\nDDPCommon.stringifyDDP = function (msg) {\n const copy = EJSON.clone(msg);\n\n // swizzle 'changed' messages from 'fields undefined' rep to 'fields\n // and cleared' rep\n if (hasOwn.call(msg, 'fields')) {\n const cleared = [];\n\n Object.keys(msg.fields).forEach(key => {\n const value = msg.fields[key];\n\n if (typeof value === \"undefined\") {\n cleared.push(key);\n delete copy.fields[key];\n }\n });\n\n if (! isEmpty(cleared)) {\n copy.cleared = cleared;\n }\n\n if (isEmpty(copy.fields)) {\n delete copy.fields;\n }\n }\n\n // adjust types to basic\n ['fields', 'params', 'result'].forEach(field => {\n if (hasOwn.call(copy, field)) {\n copy[field] = EJSON._adjustTypesToJSONValue(copy[field]);\n }\n });\n\n if (msg.id && typeof msg.id !== 'string') {\n throw new Error(\"Message id is not a string\");\n }\n\n return JSON.stringify(copy);\n};\n","// Instance name is this because it is usually referred to as this inside a\n// method definition\n/**\n * @summary The state for a single invocation of a method, referenced by this\n * inside a method definition.\n * @param {Object} options\n * @instanceName this\n * @showInstanceName true\n */\nDDPCommon.MethodInvocation = class MethodInvocation {\n constructor(options) {\n // true if we're running not the actual method, but a stub (that is,\n // if we're on a client (which may be a browser, or in the future a\n // server connecting to another server) and presently running a\n // simulation of a server-side method for latency compensation\n // purposes). not currently true except in a client such as a browser,\n // since there's usually no point in running stubs unless you have a\n // zero-latency connection to the user.\n\n /**\n * @summary Access inside a method invocation. Boolean value, true if this invocation is a stub.\n * @locus Anywhere\n * @name isSimulation\n * @memberOf DDPCommon.MethodInvocation\n * @instance\n * @type {Boolean}\n */\n this.isSimulation = options.isSimulation;\n\n // call this function to allow other method invocations (from the\n // same client) to continue running without waiting for this one to\n // complete.\n this._unblock = options.unblock || function () {};\n this._calledUnblock = false;\n\n // current user id\n\n /**\n * @summary The id of the user that made this method call, or `null` if no user was logged in.\n * @locus Anywhere\n * @name userId\n * @memberOf DDPCommon.MethodInvocation\n * @instance\n */\n this.userId = options.userId;\n\n // sets current user id in all appropriate server contexts and\n // reruns subscriptions\n this._setUserId = options.setUserId || function () {};\n\n // On the server, the connection this method call came in on.\n\n /**\n * @summary Access inside a method invocation. The [connection](#meteor_onconnection) that this method was received on. `null` if the method is not associated with a connection, eg. a server initiated method call. Calls to methods made from a server method which was in turn initiated from the client share the same `connection`.\n * @locus Server\n * @name connection\n * @memberOf DDPCommon.MethodInvocation\n * @instance\n */\n this.connection = options.connection;\n\n // The seed for randomStream value generation\n this.randomSeed = options.randomSeed;\n\n // This is set by RandomStream.get; and holds the random stream state\n this.randomStream = null;\n }\n\n /**\n * @summary Call inside a method invocation. Allow subsequent method from this client to begin running in a new fiber.\n * @locus Server\n * @memberOf DDPCommon.MethodInvocation\n * @instance\n */\n unblock() {\n this._calledUnblock = true;\n this._unblock();\n }\n\n /**\n * @summary Set the logged in user.\n * @locus Server\n * @memberOf DDPCommon.MethodInvocation\n * @instance\n * @param {String | null} userId The value that should be returned by `userId` on this connection.\n */\n setUserId(userId) {\n if (this._calledUnblock) {\n throw new Error(\"Can't call setUserId in a method after calling unblock\");\n }\n this.userId = userId;\n this._setUserId(userId);\n }\n};\n","// RandomStream allows for generation of pseudo-random values, from a seed.\n//\n// We use this for consistent 'random' numbers across the client and server.\n// We want to generate probably-unique IDs on the client, and we ideally want\n// the server to generate the same IDs when it executes the method.\n//\n// For generated values to be the same, we must seed ourselves the same way,\n// and we must keep track of the current state of our pseudo-random generators.\n// We call this state the scope. By default, we use the current DDP method\n// invocation as our scope. DDP now allows the client to specify a randomSeed.\n// If a randomSeed is provided it will be used to seed our random sequences.\n// In this way, client and server method calls will generate the same values.\n//\n// We expose multiple named streams; each stream is independent\n// and is seeded differently (but predictably from the name).\n// By using multiple streams, we support reordering of requests,\n// as long as they occur on different streams.\n//\n// @param options {Optional Object}\n// seed: Array or value - Seed value(s) for the generator.\n// If an array, will be used as-is\n// If a value, will be converted to a single-value array\n// If omitted, a random array will be used as the seed.\nDDPCommon.RandomStream = class RandomStream {\n constructor(options) {\n this.seed = [].concat(options.seed || randomToken());\n this.sequences = Object.create(null);\n }\n\n // Get a random sequence with the specified name, creating it if does not exist.\n // New sequences are seeded with the seed concatenated with the name.\n // By passing a seed into Random.create, we use the Alea generator.\n _sequence(name) {\n var self = this;\n\n var sequence = self.sequences[name] || null;\n if (sequence === null) {\n var sequenceSeed = self.seed.concat(name);\n for (var i = 0; i < sequenceSeed.length; i++) {\n if (typeof sequenceSeed[i] === \"function\") {\n sequenceSeed[i] = sequenceSeed[i]();\n }\n }\n self.sequences[name] = sequence = Random.createWithSeeds.apply(null, sequenceSeed);\n }\n return sequence;\n }\n};\n\n// Returns a random string of sufficient length for a random seed.\n// This is a placeholder function; a similar function is planned\n// for Random itself; when that is added we should remove this function,\n// and call Random's randomToken instead.\nfunction randomToken() {\n return Random.hexString(20);\n};\n\n// Returns the random stream with the specified name, in the specified\n// scope. If a scope is passed, then we use that to seed a (not\n// cryptographically secure) PRNG using the fast Alea algorithm. If\n// scope is null (or otherwise falsey) then we use a generated seed.\n//\n// However, scope will normally be the current DDP method invocation,\n// so we'll use the stream with the specified name, and we should get\n// consistent values on the client and server sides of a method call.\nDDPCommon.RandomStream.get = function (scope, name) {\n if (!name) {\n name = \"default\";\n }\n if (!scope) {\n // There was no scope passed in; the sequence won't actually be\n // reproducible. but make it fast (and not cryptographically\n // secure) anyways, so that the behavior is similar to what you'd\n // get by passing in a scope.\n return Random.insecure;\n }\n var randomStream = scope.randomStream;\n if (!randomStream) {\n scope.randomStream = randomStream = new DDPCommon.RandomStream({\n seed: scope.randomSeed\n });\n }\n return randomStream._sequence(name);\n};\n\n// Creates a randomSeed for passing to a method call.\n// Note that we take enclosing as an argument,\n// though we expect it to be DDP._CurrentMethodInvocation.get()\n// However, we often evaluate makeRpcSeed lazily, and thus the relevant\n// invocation may not be the one currently in scope.\n// If enclosing is null, we'll use Random and values won't be repeatable.\nDDPCommon.makeRpcSeed = function (enclosing, methodName) {\n var stream = DDPCommon.RandomStream.get(enclosing, '/rpc/' + methodName);\n return stream.hexString(20);\n};\n"]}