@onflow/util-actor
Advanced tools
Comparing version 1.1.0 to 1.1.1-alpha.0
# @onflow/util-actor | ||
## 1.1.1-alpha.0 | ||
### Patch Changes | ||
- [#1227](https://github.com/onflow/fcl-js/pull/1227) [`352f1460`](https://github.com/onflow/fcl-js/commit/352f1460a2f34d228a74fa4bbc6fcf6e68a968b6) Thanks [@jribbink](https://github.com/jribbink)! - Switch to fcl-bundle instead of microbundle for build scripts | ||
## 1.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -1,61 +0,23 @@ | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
'use strict'; | ||
var queueMicrotask = _interopDefault(require('queue-microtask')); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var _defineProperty = require('@babel/runtime/helpers/defineProperty'); | ||
var _objectSpread = require('@babel/runtime/helpers/objectSpread2'); | ||
var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper'); | ||
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator'); | ||
var _typeof = require('@babel/runtime/helpers/typeof'); | ||
var _regeneratorRuntime = require('@babel/runtime/regenerator'); | ||
var queueMicrotask = require('queue-microtask'); | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
return target; | ||
}; | ||
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); | ||
var _objectSpread__default = /*#__PURE__*/_interopDefaultLegacy(_objectSpread); | ||
var _createForOfIteratorHelper__default = /*#__PURE__*/_interopDefaultLegacy(_createForOfIteratorHelper); | ||
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator); | ||
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof); | ||
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime); | ||
var queueMicrotask__default = /*#__PURE__*/_interopDefaultLegacy(queueMicrotask); | ||
return _extends.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (it) return (it = it.call(o)).next.bind(it); | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var mailbox = function mailbox() { | ||
@@ -66,14 +28,21 @@ var queue = []; | ||
deliver: function deliver(msg) { | ||
try { | ||
queue.push(msg); | ||
return _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() { | ||
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))(); | ||
}, | ||
@@ -90,219 +59,2 @@ receive: function receive() { | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} | ||
function _finallyRethrows(body, finalizer) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return finalizer(true, e); | ||
} | ||
if (result && result.then) { | ||
return result.then(finalizer.bind(null, false), finalizer.bind(null, true)); | ||
} | ||
return finalizer(false, result); | ||
} | ||
function _settle(pact, state, value) { | ||
if (!pact.s) { | ||
if (value instanceof _Pact) { | ||
if (value.s) { | ||
if (state & 1) { | ||
state = value.s; | ||
} | ||
value = value.v; | ||
} else { | ||
value.o = _settle.bind(null, pact, state); | ||
return; | ||
} | ||
} | ||
if (value && value.then) { | ||
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2)); | ||
return; | ||
} | ||
pact.s = state; | ||
pact.v = value; | ||
var observer = pact.o; | ||
if (observer) { | ||
observer(pact); | ||
} | ||
} | ||
} | ||
var _Pact = /*#__PURE__*/function () { | ||
function _Pact() {} | ||
_Pact.prototype.then = function (onFulfilled, onRejected) { | ||
var result = new _Pact(); | ||
var state = this.s; | ||
if (state) { | ||
var callback = state & 1 ? onFulfilled : onRejected; | ||
if (callback) { | ||
try { | ||
_settle(result, 1, callback(this.v)); | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
} | ||
return result; | ||
} else { | ||
return this; | ||
} | ||
} | ||
this.o = function (_this) { | ||
try { | ||
var value = _this.v; | ||
if (_this.s & 1) { | ||
_settle(result, 1, onFulfilled ? onFulfilled(value) : value); | ||
} else if (onRejected) { | ||
_settle(result, 1, onRejected(value)); | ||
} else { | ||
_settle(result, 2, value); | ||
} | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
} | ||
}; | ||
return result; | ||
}; | ||
return _Pact; | ||
}(); | ||
function _isSettledPact(thenable) { | ||
return thenable instanceof _Pact && thenable.s & 1; | ||
} | ||
function _for(test, update, body) { | ||
var stage; | ||
for (;;) { | ||
var shouldContinue = test(); | ||
if (_isSettledPact(shouldContinue)) { | ||
shouldContinue = shouldContinue.v; | ||
} | ||
if (!shouldContinue) { | ||
return result; | ||
} | ||
if (shouldContinue.then) { | ||
stage = 0; | ||
break; | ||
} | ||
var result = body(); | ||
if (result && result.then) { | ||
if (_isSettledPact(result)) { | ||
result = result.s; | ||
} else { | ||
stage = 1; | ||
break; | ||
} | ||
} | ||
if (update) { | ||
var updateValue = update(); | ||
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) { | ||
stage = 2; | ||
break; | ||
} | ||
} | ||
} | ||
var pact = new _Pact(); | ||
var reject = _settle.bind(null, pact, 2); | ||
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject); | ||
return pact; | ||
function _resumeAfterBody(value) { | ||
result = value; | ||
do { | ||
if (update) { | ||
updateValue = update(); | ||
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) { | ||
updateValue.then(_resumeAfterUpdate).then(void 0, reject); | ||
return; | ||
} | ||
} | ||
shouldContinue = test(); | ||
if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) { | ||
_settle(pact, 1, result); | ||
return; | ||
} | ||
if (shouldContinue.then) { | ||
shouldContinue.then(_resumeAfterTest).then(void 0, reject); | ||
return; | ||
} | ||
result = body(); | ||
if (_isSettledPact(result)) { | ||
result = result.v; | ||
} | ||
} while (!result || !result.then); | ||
result.then(_resumeAfterBody).then(void 0, reject); | ||
} | ||
function _resumeAfterTest(shouldContinue) { | ||
if (shouldContinue) { | ||
result = body(); | ||
if (result && result.then) { | ||
result.then(_resumeAfterBody).then(void 0, reject); | ||
} else { | ||
_resumeAfterBody(result); | ||
} | ||
} else { | ||
_settle(pact, 1, result); | ||
} | ||
} | ||
function _resumeAfterUpdate() { | ||
if (shouldContinue = test()) { | ||
if (shouldContinue.then) { | ||
shouldContinue.then(_resumeAfterTest).then(void 0, reject); | ||
} else { | ||
_resumeAfterTest(shouldContinue); | ||
} | ||
} else { | ||
_settle(pact, 1, result); | ||
} | ||
} | ||
} | ||
var INIT = "INIT"; | ||
@@ -315,3 +67,3 @@ var SUBSCRIBE = "SUBSCRIBE"; | ||
var TERMINATE = "TERMINATE"; | ||
var root = typeof self === "object" && self.self === self && self || typeof global === "object" && global.global === global && global || typeof window === "object" && window.window === window && window; | ||
var root = (typeof self === "undefined" ? "undefined" : _typeof__default["default"](self)) === "object" && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof__default["default"](global)) === "object" && global.global === global && global || (typeof window === "undefined" ? "undefined" : _typeof__default["default"](window)) === "object" && window.window === window && window; | ||
root.FCL_REGISTRY = root.FCL_REGISTRY == null ? {} : root.FCL_REGISTRY; | ||
@@ -321,7 +73,4 @@ var pid = 0; | ||
var _send = function send(addr, tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
var _send = function send(addr, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise(function (reply, reject) { | ||
@@ -333,3 +82,3 @@ var expectReply = opts.expectReply || false; | ||
setTimeout(function () { | ||
return reject(new Error("Timeout: " + timeout + "ms passed without a response.")); | ||
return reject(new Error("Timeout: ".concat(timeout, "ms passed without a response."))); | ||
}, timeout); | ||
@@ -360,75 +109,81 @@ } | ||
var fromHandlers = function fromHandlers(handlers) { | ||
if (handlers === void 0) { | ||
handlers = {}; | ||
} | ||
var fromHandlers = function fromHandlers() { | ||
var handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(ctx) { | ||
var letter; | ||
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(typeof handlers[INIT] === "function")) { | ||
_context.next = 3; | ||
break; | ||
} | ||
return function (ctx) { | ||
try { | ||
var _temp12 = function _temp12() { | ||
var _loopInterrupt; | ||
_context.next = 3; | ||
return handlers[INIT](ctx); | ||
var _temp6 = _for(function () { | ||
return !_loopInterrupt && 1; | ||
}, void 0, function () { | ||
return Promise.resolve(ctx.receive()).then(function (letter) { | ||
var _temp5 = _finallyRethrows(function () { | ||
return _catch(function () { | ||
function _temp4() { | ||
return Promise.resolve(handlers[letter.tag](ctx, letter, letter.data || {})).then(function () {}); | ||
} | ||
case 3: | ||
var _temp3 = function () { | ||
if (letter.tag === EXIT) { | ||
var _temp10 = function _temp10() { | ||
_loopInterrupt = 1; | ||
}; | ||
_context.next = 6; | ||
return ctx.receive(); | ||
var _temp11 = function () { | ||
if (typeof handlers[TERMINATE] === "function") { | ||
return Promise.resolve(handlers[TERMINATE](ctx, letter, letter.data || {})).then(function () {}); | ||
} | ||
}(); | ||
case 6: | ||
letter = _context.sent; | ||
_context.prev = 7; | ||
return _temp11 && _temp11.then ? _temp11.then(_temp10) : _temp10(_temp11); | ||
} | ||
}(); | ||
if (!(letter.tag === EXIT)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3); | ||
}, function (error) { | ||
console.error(ctx.self() + " Error", letter, error); | ||
}); | ||
}, function (_wasThrown, _result) { | ||
return; | ||
if (_wasThrown) throw _result; | ||
return _result; | ||
}); | ||
if (!(typeof handlers[TERMINATE] === "function")) { | ||
_context.next = 12; | ||
break; | ||
} | ||
if (_temp5 && _temp5.then) return _temp5.then(function () {}); | ||
}); | ||
}); | ||
_context.next = 12; | ||
return handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
var _temp7 = function () { | ||
if (_temp6 && _temp6.then) return _temp6.then(function () {}); | ||
}(); | ||
case 12: | ||
return _context.abrupt("break", 25); | ||
if (_temp7 && _temp7.then) return _temp7.then(function () {}); | ||
}; | ||
case 13: | ||
_context.next = 15; | ||
return handlers[letter.tag](ctx, letter, letter.data || {}); | ||
var _temp13 = function () { | ||
if (typeof handlers[INIT] === "function") return Promise.resolve(handlers[INIT](ctx)).then(function () {}); | ||
}(); | ||
case 15: | ||
_context.next = 20; | ||
break; | ||
return Promise.resolve(_temp13 && _temp13.then ? _temp13.then(_temp12) : _temp12(_temp13)); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
case 17: | ||
_context.prev = 17; | ||
_context.t0 = _context["catch"](7); | ||
console.error("".concat(ctx.self(), " Error"), letter, _context.t0); | ||
case 20: | ||
_context.prev = 20; | ||
return _context.abrupt("continue", 3); | ||
case 23: | ||
_context.next = 3; | ||
break; | ||
case 25: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, null, [[7, 17, 20, 23]]); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
}; | ||
var spawn = function spawn(fn, addr) { | ||
if (addr === void 0) { | ||
addr = null; | ||
} | ||
var spawn = function spawn(fn) { | ||
var addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (addr == null) addr = ++pid; | ||
@@ -450,7 +205,4 @@ if (root.FCL_REGISTRY[addr] != null) return addr; | ||
}, | ||
send: function send(to, tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
send: function send(to, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
opts.from = addr; | ||
@@ -462,13 +214,19 @@ return _send(to, tag, data, opts); | ||
}, | ||
broadcast: function broadcast(tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
broadcast: function broadcast(tag, data) { | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
opts.from = addr; | ||
for (var _iterator = _createForOfIteratorHelperLoose(root.FCL_REGISTRY[addr].subs), _step; !(_step = _iterator()).done;) { | ||
var to = _step.value; | ||
var _iterator = _createForOfIteratorHelper__default["default"](root.FCL_REGISTRY[addr].subs), | ||
_step; | ||
_send(to, tag, data, opts); | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var to = _step.value; | ||
_send(to, tag, data, opts); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
@@ -509,12 +267,7 @@ }, | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce(function (acc, key) { | ||
var _extends2; | ||
return pattern.test(key) ? _extends({}, acc, (_extends2 = {}, _extends2[key] = root.FCL_REGISTRY[addr].kvs[key], _extends2)) : acc; | ||
return pattern.test(key) ? _objectSpread__default["default"](_objectSpread__default["default"]({}, acc), {}, _defineProperty__default["default"]({}, key, root.FCL_REGISTRY[addr].kvs[key])) : acc; | ||
}, {}); | ||
}, | ||
merge: function merge(data) { | ||
if (data === void 0) { | ||
data = {}; | ||
} | ||
merge: function merge() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(function (key) { | ||
@@ -527,19 +280,37 @@ return root.FCL_REGISTRY[addr].kvs[key] = data[key]; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(root.FCL_REGISTRY[addr].subs), _step2; !(_step2 = _iterator2()).done;) { | ||
var to = _step2.value; | ||
var _iterator2 = _createForOfIteratorHelper__default["default"](root.FCL_REGISTRY[addr].subs), | ||
_step2; | ||
_send(to, UPDATED); | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var to = _step2.value; | ||
_send(to, UPDATED); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} | ||
}; | ||
if (typeof fn === "object") fn = fromHandlers(fn); | ||
queueMicrotask(function () { | ||
try { | ||
return Promise.resolve(fn(ctx)).then(function () { | ||
kill(addr); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
if (_typeof__default["default"](fn) === "object") fn = fromHandlers(fn); | ||
queueMicrotask__default["default"]( /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2() { | ||
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return fn(ctx); | ||
case 2: | ||
kill(addr); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}))); | ||
return addr; | ||
@@ -558,33 +329,55 @@ }; // Returns an unsubscribe function | ||
var EXIT = "@EXIT"; | ||
var self = spawn(function (ctx) { | ||
try { | ||
var _exit2; | ||
var self = spawn( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(ctx) { | ||
var letter, error; | ||
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
ctx.send(address, SUBSCRIBE); | ||
ctx.send(address, SUBSCRIBE); | ||
return Promise.resolve(_for(function () { | ||
return !_exit2 && 1; | ||
}, void 0, function () { | ||
return Promise.resolve(ctx.receive()).then(function (letter) { | ||
var error = root.FCL_REGISTRY[address].error; | ||
case 1: | ||
if (letter.tag === EXIT) { | ||
ctx.send(address, UNSUBSCRIBE); | ||
_exit2 = 1; | ||
return; | ||
} | ||
_context3.next = 4; | ||
return ctx.receive(); | ||
if (error) { | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
_exit2 = 1; | ||
return; | ||
case 4: | ||
letter = _context3.sent; | ||
error = root.FCL_REGISTRY[address].error; | ||
if (!(letter.tag === EXIT)) { | ||
_context3.next = 9; | ||
break; | ||
} | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 9: | ||
if (!error) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 13: | ||
callback(letter.data, null); | ||
_context3.next = 1; | ||
break; | ||
case 16: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3); | ||
})); | ||
callback(letter.data, null); | ||
}); | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
return function (_x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
return function () { | ||
@@ -591,0 +384,0 @@ return _send(self, EXIT); |
@@ -0,59 +1,9 @@ | ||
import _defineProperty from '@babel/runtime/helpers/defineProperty'; | ||
import _objectSpread from '@babel/runtime/helpers/objectSpread2'; | ||
import _createForOfIteratorHelper from '@babel/runtime/helpers/createForOfIteratorHelper'; | ||
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator'; | ||
import _typeof from '@babel/runtime/helpers/typeof'; | ||
import _regeneratorRuntime from '@babel/runtime/regenerator'; | ||
import queueMicrotask from 'queue-microtask'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return; | ||
if (typeof o === "string") return _arrayLikeToArray(o, minLen); | ||
var n = Object.prototype.toString.call(o).slice(8, -1); | ||
if (n === "Object" && o.constructor) n = o.constructor.name; | ||
if (n === "Map" || n === "Set") return Array.from(o); | ||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (it) return (it = it.call(o)).next.bind(it); | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var mailbox = function mailbox() { | ||
@@ -64,14 +14,21 @@ var queue = []; | ||
deliver: function deliver(msg) { | ||
try { | ||
queue.push(msg); | ||
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))(); | ||
}, | ||
@@ -88,219 +45,2 @@ receive: function receive() { | ||
function _catch(body, recover) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return recover(e); | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
} | ||
return result; | ||
} | ||
function _finallyRethrows(body, finalizer) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return finalizer(true, e); | ||
} | ||
if (result && result.then) { | ||
return result.then(finalizer.bind(null, false), finalizer.bind(null, true)); | ||
} | ||
return finalizer(false, result); | ||
} | ||
function _settle(pact, state, value) { | ||
if (!pact.s) { | ||
if (value instanceof _Pact) { | ||
if (value.s) { | ||
if (state & 1) { | ||
state = value.s; | ||
} | ||
value = value.v; | ||
} else { | ||
value.o = _settle.bind(null, pact, state); | ||
return; | ||
} | ||
} | ||
if (value && value.then) { | ||
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2)); | ||
return; | ||
} | ||
pact.s = state; | ||
pact.v = value; | ||
var observer = pact.o; | ||
if (observer) { | ||
observer(pact); | ||
} | ||
} | ||
} | ||
var _Pact = /*#__PURE__*/function () { | ||
function _Pact() {} | ||
_Pact.prototype.then = function (onFulfilled, onRejected) { | ||
var result = new _Pact(); | ||
var state = this.s; | ||
if (state) { | ||
var callback = state & 1 ? onFulfilled : onRejected; | ||
if (callback) { | ||
try { | ||
_settle(result, 1, callback(this.v)); | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
} | ||
return result; | ||
} else { | ||
return this; | ||
} | ||
} | ||
this.o = function (_this) { | ||
try { | ||
var value = _this.v; | ||
if (_this.s & 1) { | ||
_settle(result, 1, onFulfilled ? onFulfilled(value) : value); | ||
} else if (onRejected) { | ||
_settle(result, 1, onRejected(value)); | ||
} else { | ||
_settle(result, 2, value); | ||
} | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
} | ||
}; | ||
return result; | ||
}; | ||
return _Pact; | ||
}(); | ||
function _isSettledPact(thenable) { | ||
return thenable instanceof _Pact && thenable.s & 1; | ||
} | ||
function _for(test, update, body) { | ||
var stage; | ||
for (;;) { | ||
var shouldContinue = test(); | ||
if (_isSettledPact(shouldContinue)) { | ||
shouldContinue = shouldContinue.v; | ||
} | ||
if (!shouldContinue) { | ||
return result; | ||
} | ||
if (shouldContinue.then) { | ||
stage = 0; | ||
break; | ||
} | ||
var result = body(); | ||
if (result && result.then) { | ||
if (_isSettledPact(result)) { | ||
result = result.s; | ||
} else { | ||
stage = 1; | ||
break; | ||
} | ||
} | ||
if (update) { | ||
var updateValue = update(); | ||
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) { | ||
stage = 2; | ||
break; | ||
} | ||
} | ||
} | ||
var pact = new _Pact(); | ||
var reject = _settle.bind(null, pact, 2); | ||
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject); | ||
return pact; | ||
function _resumeAfterBody(value) { | ||
result = value; | ||
do { | ||
if (update) { | ||
updateValue = update(); | ||
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) { | ||
updateValue.then(_resumeAfterUpdate).then(void 0, reject); | ||
return; | ||
} | ||
} | ||
shouldContinue = test(); | ||
if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) { | ||
_settle(pact, 1, result); | ||
return; | ||
} | ||
if (shouldContinue.then) { | ||
shouldContinue.then(_resumeAfterTest).then(void 0, reject); | ||
return; | ||
} | ||
result = body(); | ||
if (_isSettledPact(result)) { | ||
result = result.v; | ||
} | ||
} while (!result || !result.then); | ||
result.then(_resumeAfterBody).then(void 0, reject); | ||
} | ||
function _resumeAfterTest(shouldContinue) { | ||
if (shouldContinue) { | ||
result = body(); | ||
if (result && result.then) { | ||
result.then(_resumeAfterBody).then(void 0, reject); | ||
} else { | ||
_resumeAfterBody(result); | ||
} | ||
} else { | ||
_settle(pact, 1, result); | ||
} | ||
} | ||
function _resumeAfterUpdate() { | ||
if (shouldContinue = test()) { | ||
if (shouldContinue.then) { | ||
shouldContinue.then(_resumeAfterTest).then(void 0, reject); | ||
} else { | ||
_resumeAfterTest(shouldContinue); | ||
} | ||
} else { | ||
_settle(pact, 1, result); | ||
} | ||
} | ||
} | ||
var INIT = "INIT"; | ||
@@ -313,3 +53,3 @@ var SUBSCRIBE = "SUBSCRIBE"; | ||
var TERMINATE = "TERMINATE"; | ||
var root = typeof self === "object" && self.self === self && self || typeof global === "object" && global.global === global && global || typeof window === "object" && window.window === window && window; | ||
var root = (typeof self === "undefined" ? "undefined" : _typeof(self)) === "object" && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof(global)) === "object" && global.global === global && global || (typeof window === "undefined" ? "undefined" : _typeof(window)) === "object" && window.window === window && window; | ||
root.FCL_REGISTRY = root.FCL_REGISTRY == null ? {} : root.FCL_REGISTRY; | ||
@@ -319,7 +59,4 @@ var pid = 0; | ||
var _send = function send(addr, tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
var _send = function send(addr, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise(function (reply, reject) { | ||
@@ -331,3 +68,3 @@ var expectReply = opts.expectReply || false; | ||
setTimeout(function () { | ||
return reject(new Error("Timeout: " + timeout + "ms passed without a response.")); | ||
return reject(new Error("Timeout: ".concat(timeout, "ms passed without a response."))); | ||
}, timeout); | ||
@@ -358,75 +95,81 @@ } | ||
var fromHandlers = function fromHandlers(handlers) { | ||
if (handlers === void 0) { | ||
handlers = {}; | ||
} | ||
var fromHandlers = function fromHandlers() { | ||
var handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(ctx) { | ||
var letter; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(typeof handlers[INIT] === "function")) { | ||
_context.next = 3; | ||
break; | ||
} | ||
return function (ctx) { | ||
try { | ||
var _temp12 = function _temp12() { | ||
var _loopInterrupt; | ||
_context.next = 3; | ||
return handlers[INIT](ctx); | ||
var _temp6 = _for(function () { | ||
return !_loopInterrupt && 1; | ||
}, void 0, function () { | ||
return Promise.resolve(ctx.receive()).then(function (letter) { | ||
var _temp5 = _finallyRethrows(function () { | ||
return _catch(function () { | ||
function _temp4() { | ||
return Promise.resolve(handlers[letter.tag](ctx, letter, letter.data || {})).then(function () {}); | ||
} | ||
case 3: | ||
var _temp3 = function () { | ||
if (letter.tag === EXIT) { | ||
var _temp10 = function _temp10() { | ||
_loopInterrupt = 1; | ||
}; | ||
_context.next = 6; | ||
return ctx.receive(); | ||
var _temp11 = function () { | ||
if (typeof handlers[TERMINATE] === "function") { | ||
return Promise.resolve(handlers[TERMINATE](ctx, letter, letter.data || {})).then(function () {}); | ||
} | ||
}(); | ||
case 6: | ||
letter = _context.sent; | ||
_context.prev = 7; | ||
return _temp11 && _temp11.then ? _temp11.then(_temp10) : _temp10(_temp11); | ||
} | ||
}(); | ||
if (!(letter.tag === EXIT)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3); | ||
}, function (error) { | ||
console.error(ctx.self() + " Error", letter, error); | ||
}); | ||
}, function (_wasThrown, _result) { | ||
return; | ||
if (_wasThrown) throw _result; | ||
return _result; | ||
}); | ||
if (!(typeof handlers[TERMINATE] === "function")) { | ||
_context.next = 12; | ||
break; | ||
} | ||
if (_temp5 && _temp5.then) return _temp5.then(function () {}); | ||
}); | ||
}); | ||
_context.next = 12; | ||
return handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
var _temp7 = function () { | ||
if (_temp6 && _temp6.then) return _temp6.then(function () {}); | ||
}(); | ||
case 12: | ||
return _context.abrupt("break", 25); | ||
if (_temp7 && _temp7.then) return _temp7.then(function () {}); | ||
}; | ||
case 13: | ||
_context.next = 15; | ||
return handlers[letter.tag](ctx, letter, letter.data || {}); | ||
var _temp13 = function () { | ||
if (typeof handlers[INIT] === "function") return Promise.resolve(handlers[INIT](ctx)).then(function () {}); | ||
}(); | ||
case 15: | ||
_context.next = 20; | ||
break; | ||
return Promise.resolve(_temp13 && _temp13.then ? _temp13.then(_temp12) : _temp12(_temp13)); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
case 17: | ||
_context.prev = 17; | ||
_context.t0 = _context["catch"](7); | ||
console.error("".concat(ctx.self(), " Error"), letter, _context.t0); | ||
case 20: | ||
_context.prev = 20; | ||
return _context.abrupt("continue", 3); | ||
case 23: | ||
_context.next = 3; | ||
break; | ||
case 25: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, null, [[7, 17, 20, 23]]); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
}; | ||
var spawn = function spawn(fn, addr) { | ||
if (addr === void 0) { | ||
addr = null; | ||
} | ||
var spawn = function spawn(fn) { | ||
var addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (addr == null) addr = ++pid; | ||
@@ -448,7 +191,4 @@ if (root.FCL_REGISTRY[addr] != null) return addr; | ||
}, | ||
send: function send(to, tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
send: function send(to, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
opts.from = addr; | ||
@@ -460,13 +200,19 @@ return _send(to, tag, data, opts); | ||
}, | ||
broadcast: function broadcast(tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
broadcast: function broadcast(tag, data) { | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
opts.from = addr; | ||
for (var _iterator = _createForOfIteratorHelperLoose(root.FCL_REGISTRY[addr].subs), _step; !(_step = _iterator()).done;) { | ||
var to = _step.value; | ||
var _iterator = _createForOfIteratorHelper(root.FCL_REGISTRY[addr].subs), | ||
_step; | ||
_send(to, tag, data, opts); | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var to = _step.value; | ||
_send(to, tag, data, opts); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
@@ -507,12 +253,7 @@ }, | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce(function (acc, key) { | ||
var _extends2; | ||
return pattern.test(key) ? _extends({}, acc, (_extends2 = {}, _extends2[key] = root.FCL_REGISTRY[addr].kvs[key], _extends2)) : acc; | ||
return pattern.test(key) ? _objectSpread(_objectSpread({}, acc), {}, _defineProperty({}, key, root.FCL_REGISTRY[addr].kvs[key])) : acc; | ||
}, {}); | ||
}, | ||
merge: function merge(data) { | ||
if (data === void 0) { | ||
data = {}; | ||
} | ||
merge: function merge() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(function (key) { | ||
@@ -525,19 +266,37 @@ return root.FCL_REGISTRY[addr].kvs[key] = data[key]; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(root.FCL_REGISTRY[addr].subs), _step2; !(_step2 = _iterator2()).done;) { | ||
var to = _step2.value; | ||
var _iterator2 = _createForOfIteratorHelper(root.FCL_REGISTRY[addr].subs), | ||
_step2; | ||
_send(to, UPDATED); | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var to = _step2.value; | ||
_send(to, UPDATED); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} | ||
}; | ||
if (typeof fn === "object") fn = fromHandlers(fn); | ||
queueMicrotask(function () { | ||
try { | ||
return Promise.resolve(fn(ctx)).then(function () { | ||
kill(addr); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
if (_typeof(fn) === "object") fn = fromHandlers(fn); | ||
queueMicrotask( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { | ||
return _regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return fn(ctx); | ||
case 2: | ||
kill(addr); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}))); | ||
return addr; | ||
@@ -556,33 +315,55 @@ }; // Returns an unsubscribe function | ||
var EXIT = "@EXIT"; | ||
var self = spawn(function (ctx) { | ||
try { | ||
var _exit2; | ||
var self = spawn( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(ctx) { | ||
var letter, error; | ||
return _regeneratorRuntime.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
ctx.send(address, SUBSCRIBE); | ||
ctx.send(address, SUBSCRIBE); | ||
return Promise.resolve(_for(function () { | ||
return !_exit2 && 1; | ||
}, void 0, function () { | ||
return Promise.resolve(ctx.receive()).then(function (letter) { | ||
var error = root.FCL_REGISTRY[address].error; | ||
case 1: | ||
if (letter.tag === EXIT) { | ||
ctx.send(address, UNSUBSCRIBE); | ||
_exit2 = 1; | ||
return; | ||
} | ||
_context3.next = 4; | ||
return ctx.receive(); | ||
if (error) { | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
_exit2 = 1; | ||
return; | ||
case 4: | ||
letter = _context3.sent; | ||
error = root.FCL_REGISTRY[address].error; | ||
if (!(letter.tag === EXIT)) { | ||
_context3.next = 9; | ||
break; | ||
} | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 9: | ||
if (!error) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 13: | ||
callback(letter.data, null); | ||
_context3.next = 1; | ||
break; | ||
case 16: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3); | ||
})); | ||
callback(letter.data, null); | ||
}); | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
return function (_x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
return function () { | ||
@@ -589,0 +370,0 @@ return _send(self, EXIT); |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('queue-microtask')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'queue-microtask'], factory) : | ||
(global = global || self, factory(global.utilActor = {}, global.queueMicrotask)); | ||
}(this, (function (exports, queueMicrotask) { | ||
queueMicrotask = queueMicrotask && Object.prototype.hasOwnProperty.call(queueMicrotask, 'default') ? queueMicrotask['default'] : queueMicrotask; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["onflowUtil-actor"] = {})); | ||
})(this, (function (exports) { 'use strict'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return obj; | ||
} | ||
return target; | ||
}; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
return _extends.apply(this, arguments); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) { | ||
arr2[i] = arr[i]; | ||
} | ||
return arr2; | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { | ||
@@ -35,276 +67,537 @@ if (!o) return; | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length; | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; | ||
if (!it) { | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return arr2; | ||
} | ||
var F = function F() {}; | ||
function _createForOfIteratorHelperLoose(o, allowArrayLike) { | ||
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
if (it) return (it = it.call(o)).next.bind(it); | ||
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { | ||
if (it) o = it; | ||
var i = 0; | ||
return function () { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
s: F, | ||
n: function n() { | ||
if (i >= o.length) return { | ||
done: true | ||
}; | ||
return { | ||
done: false, | ||
value: o[i++] | ||
}; | ||
}, | ||
e: function e(_e) { | ||
throw _e; | ||
}, | ||
f: F | ||
}; | ||
}; | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
var mailbox = function mailbox() { | ||
var queue = []; | ||
var next; | ||
var normalCompletion = true, | ||
didErr = false, | ||
err; | ||
return { | ||
deliver: function deliver(msg) { | ||
s: function s() { | ||
it = it.call(o); | ||
}, | ||
n: function n() { | ||
var step = it.next(); | ||
normalCompletion = step.done; | ||
return step; | ||
}, | ||
e: function e(_e2) { | ||
didErr = true; | ||
err = _e2; | ||
}, | ||
f: function f() { | ||
try { | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
return Promise.resolve(); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
if (!normalCompletion && it["return"] != null) it["return"](); | ||
} finally { | ||
if (didErr) throw err; | ||
} | ||
}, | ||
receive: function receive() { | ||
return new Promise(function innerReceive(resolve) { | ||
var msg = queue.shift(); | ||
if (msg) return resolve(msg); | ||
next = resolve; | ||
}); | ||
} | ||
}; | ||
}; | ||
} | ||
function _catch(body, recover) { | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return recover(e); | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (result && result.then) { | ||
return result.then(void 0, recover); | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
return result; | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
function _finallyRethrows(body, finalizer) { | ||
try { | ||
var result = body(); | ||
} catch (e) { | ||
return finalizer(true, e); | ||
} | ||
function _typeof$1(obj) { | ||
"@babel/helpers - typeof"; | ||
if (result && result.then) { | ||
return result.then(finalizer.bind(null, false), finalizer.bind(null, true)); | ||
return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}, _typeof$1(obj); | ||
} | ||
var regeneratorRuntime$1 = {exports: {}}; | ||
var _typeof = {exports: {}}; | ||
(function (module) { | ||
function _typeof(obj) { | ||
"@babel/helpers - typeof"; | ||
return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { | ||
return typeof obj; | ||
} : function (obj) { | ||
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj); | ||
} | ||
return finalizer(false, result); | ||
} | ||
module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports; | ||
})(_typeof); | ||
function _settle(pact, state, value) { | ||
if (!pact.s) { | ||
if (value instanceof _Pact) { | ||
if (value.s) { | ||
if (state & 1) { | ||
state = value.s; | ||
} | ||
(function (module) { | ||
var _typeof$1 = _typeof.exports["default"]; | ||
value = value.v; | ||
} else { | ||
value.o = _settle.bind(null, pact, state); | ||
return; | ||
} | ||
function _regeneratorRuntime() { | ||
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ | ||
module.exports = _regeneratorRuntime = function _regeneratorRuntime() { | ||
return exports; | ||
}, module.exports.__esModule = true, module.exports["default"] = module.exports; | ||
var exports = {}, | ||
Op = Object.prototype, | ||
hasOwn = Op.hasOwnProperty, | ||
$Symbol = "function" == typeof Symbol ? Symbol : {}, | ||
iteratorSymbol = $Symbol.iterator || "@@iterator", | ||
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", | ||
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
function define(obj, key, value) { | ||
return Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}), obj[key]; | ||
} | ||
if (value && value.then) { | ||
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2)); | ||
return; | ||
try { | ||
define({}, ""); | ||
} catch (err) { | ||
define = function define(obj, key, value) { | ||
return obj[key] = value; | ||
}; | ||
} | ||
pact.s = state; | ||
pact.v = value; | ||
var observer = pact.o; | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, | ||
generator = Object.create(protoGenerator.prototype), | ||
context = new Context(tryLocsList || []); | ||
return generator._invoke = function (innerFn, self, context) { | ||
var state = "suspendedStart"; | ||
return function (method, arg) { | ||
if ("executing" === state) throw new Error("Generator is already running"); | ||
if (observer) { | ||
observer(pact); | ||
} | ||
} | ||
} | ||
if ("completed" === state) { | ||
if ("throw" === method) throw arg; | ||
return doneResult(); | ||
} | ||
var _Pact = /*#__PURE__*/function () { | ||
function _Pact() {} | ||
for (context.method = method, context.arg = arg;;) { | ||
var delegate = context.delegate; | ||
_Pact.prototype.then = function (onFulfilled, onRejected) { | ||
var result = new _Pact(); | ||
var state = this.s; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (state) { | ||
var callback = state & 1 ? onFulfilled : onRejected; | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if (callback) { | ||
try { | ||
_settle(result, 1, callback(this.v)); | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
} | ||
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { | ||
if ("suspendedStart" === state) throw state = "completed", context.arg; | ||
context.dispatchException(context.arg); | ||
} else "return" === context.method && context.abrupt("return", context.arg); | ||
state = "executing"; | ||
var record = tryCatch(innerFn, self, context); | ||
return result; | ||
} else { | ||
return this; | ||
} | ||
if ("normal" === record.type) { | ||
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} | ||
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); | ||
} | ||
}; | ||
}(innerFn, self, context), generator; | ||
} | ||
this.o = function (_this) { | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
var value = _this.v; | ||
return { | ||
type: "normal", | ||
arg: fn.call(obj, arg) | ||
}; | ||
} catch (err) { | ||
return { | ||
type: "throw", | ||
arg: err | ||
}; | ||
} | ||
} | ||
if (_this.s & 1) { | ||
_settle(result, 1, onFulfilled ? onFulfilled(value) : value); | ||
} else if (onRejected) { | ||
_settle(result, 1, onRejected(value)); | ||
} else { | ||
_settle(result, 2, value); | ||
exports.wrap = wrap; | ||
var ContinueSentinel = {}; | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
var IteratorPrototype = {}; | ||
define(IteratorPrototype, iteratorSymbol, function () { | ||
return this; | ||
}); | ||
var getProto = Object.getPrototypeOf, | ||
NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); | ||
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function (method) { | ||
define(prototype, method, function (arg) { | ||
return this._invoke(method, arg); | ||
}); | ||
}); | ||
} | ||
function AsyncIterator(generator, PromiseImpl) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if ("throw" !== record.type) { | ||
var result = record.arg, | ||
value = result.value; | ||
return value && "object" == _typeof$1(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { | ||
invoke("next", value, resolve, reject); | ||
}, function (err) { | ||
invoke("throw", err, resolve, reject); | ||
}) : PromiseImpl.resolve(value).then(function (unwrapped) { | ||
result.value = unwrapped, resolve(result); | ||
}, function (error) { | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
} catch (e) { | ||
_settle(result, 2, e); | ||
reject(record.arg); | ||
} | ||
}; | ||
return result; | ||
}; | ||
var previousPromise; | ||
return _Pact; | ||
}(); | ||
this._invoke = function (method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new PromiseImpl(function (resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
function _isSettledPact(thenable) { | ||
return thenable instanceof _Pact && thenable.s & 1; | ||
} | ||
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); | ||
}; | ||
} | ||
function _for(test, update, body) { | ||
var stage; | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
for (;;) { | ||
var shouldContinue = test(); | ||
if (undefined === method) { | ||
if (context.delegate = null, "throw" === context.method) { | ||
if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; | ||
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); | ||
} | ||
if (_isSettledPact(shouldContinue)) { | ||
shouldContinue = shouldContinue.v; | ||
return ContinueSentinel; | ||
} | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; | ||
var info = record.arg; | ||
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); | ||
} | ||
if (!shouldContinue) { | ||
return result; | ||
function pushTryEntry(locs) { | ||
var entry = { | ||
tryLoc: locs[0] | ||
}; | ||
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); | ||
} | ||
if (shouldContinue.then) { | ||
stage = 0; | ||
break; | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal", delete record.arg, entry.completion = record; | ||
} | ||
var result = body(); | ||
if (result && result.then) { | ||
if (_isSettledPact(result)) { | ||
result = result.s; | ||
} else { | ||
stage = 1; | ||
break; | ||
} | ||
function Context(tryLocsList) { | ||
this.tryEntries = [{ | ||
tryLoc: "root" | ||
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); | ||
} | ||
if (update) { | ||
var updateValue = update(); | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) return iteratorMethod.call(iterable); | ||
if ("function" == typeof iterable.next) return iterable; | ||
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) { | ||
stage = 2; | ||
break; | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, | ||
next = function next() { | ||
for (; ++i < iterable.length;) { | ||
if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; | ||
} | ||
return next.value = undefined, next.done = !0, next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
return { | ||
next: doneResult | ||
}; | ||
} | ||
} | ||
var pact = new _Pact(); | ||
function doneResult() { | ||
return { | ||
value: undefined, | ||
done: !0 | ||
}; | ||
} | ||
var reject = _settle.bind(null, pact, 2); | ||
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { | ||
var ctor = "function" == typeof genFun && genFun.constructor; | ||
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); | ||
}, exports.mark = function (genFun) { | ||
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; | ||
}, exports.awrap = function (arg) { | ||
return { | ||
__await: arg | ||
}; | ||
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { | ||
return this; | ||
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { | ||
void 0 === PromiseImpl && (PromiseImpl = Promise); | ||
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); | ||
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { | ||
return this; | ||
}), define(Gp, "toString", function () { | ||
return "[object Generator]"; | ||
}), exports.keys = function (object) { | ||
var keys = []; | ||
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject); | ||
return pact; | ||
for (var key in object) { | ||
keys.push(key); | ||
} | ||
function _resumeAfterBody(value) { | ||
result = value; | ||
return keys.reverse(), function next() { | ||
for (; keys.length;) { | ||
var key = keys.pop(); | ||
if (key in object) return next.value = key, next.done = !1, next; | ||
} | ||
do { | ||
if (update) { | ||
updateValue = update(); | ||
return next.done = !0, next; | ||
}; | ||
}, exports.values = values, Context.prototype = { | ||
constructor: Context, | ||
reset: function reset(skipTempReset) { | ||
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { | ||
"t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); | ||
} | ||
}, | ||
stop: function stop() { | ||
this.done = !0; | ||
var rootRecord = this.tryEntries[0].completion; | ||
if ("throw" === rootRecord.type) throw rootRecord.arg; | ||
return this.rval; | ||
}, | ||
dispatchException: function dispatchException(exception) { | ||
if (this.done) throw exception; | ||
var context = this; | ||
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) { | ||
updateValue.then(_resumeAfterUpdate).then(void 0, reject); | ||
return; | ||
function handle(loc, caught) { | ||
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; | ||
} | ||
} | ||
shouldContinue = test(); | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i], | ||
record = entry.completion; | ||
if ("root" === entry.tryLoc) return handle("end"); | ||
if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) { | ||
_settle(pact, 1, result); | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"), | ||
hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
return; | ||
} | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); | ||
} else { | ||
if (!hasFinally) throw new Error("try statement without catch or finally"); | ||
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function abrupt(type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (shouldContinue.then) { | ||
shouldContinue.then(_resumeAfterTest).then(void 0, reject); | ||
return; | ||
} | ||
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
result = body(); | ||
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); | ||
}, | ||
complete: function complete(record, afterLoc) { | ||
if ("throw" === record.type) throw record.arg; | ||
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; | ||
}, | ||
finish: function finish(finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; | ||
} | ||
}, | ||
"catch": function _catch(tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (_isSettledPact(result)) { | ||
result = result.v; | ||
} | ||
} while (!result || !result.then); | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
result.then(_resumeAfterBody).then(void 0, reject); | ||
} | ||
if ("throw" === record.type) { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
function _resumeAfterTest(shouldContinue) { | ||
if (shouldContinue) { | ||
result = body(); | ||
return thrown; | ||
} | ||
} | ||
if (result && result.then) { | ||
result.then(_resumeAfterBody).then(void 0, reject); | ||
} else { | ||
_resumeAfterBody(result); | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function delegateYield(iterable, resultName, nextLoc) { | ||
return this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}, "next" === this.method && (this.arg = undefined), ContinueSentinel; | ||
} | ||
} else { | ||
_settle(pact, 1, result); | ||
} | ||
}, exports; | ||
} | ||
function _resumeAfterUpdate() { | ||
if (shouldContinue = test()) { | ||
if (shouldContinue.then) { | ||
shouldContinue.then(_resumeAfterTest).then(void 0, reject); | ||
} else { | ||
_resumeAfterTest(shouldContinue); | ||
} | ||
} else { | ||
_settle(pact, 1, result); | ||
} | ||
module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports; | ||
})(regeneratorRuntime$1); | ||
var runtime = regeneratorRuntime$1.exports(); | ||
var regenerator = runtime; // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736= | ||
try { | ||
regeneratorRuntime = runtime; | ||
} catch (accidentalStrictMode) { | ||
if ((typeof globalThis === "undefined" ? "undefined" : _typeof$1(globalThis)) === "object") { | ||
globalThis.regeneratorRuntime = runtime; | ||
} else { | ||
Function("r", "regeneratorRuntime = r")(runtime); | ||
} | ||
} | ||
var mailbox = function mailbox() { | ||
var queue = []; | ||
var next; | ||
return { | ||
deliver: function deliver(msg) { | ||
return _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee() { | ||
return regenerator.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
queue.push(msg); | ||
if (next) { | ||
next(queue.shift()); | ||
next = undefined; | ||
} | ||
case 2: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
}))(); | ||
}, | ||
receive: function receive() { | ||
return new Promise(function innerReceive(resolve) { | ||
var msg = queue.shift(); | ||
if (msg) return resolve(msg); | ||
next = resolve; | ||
}); | ||
} | ||
}; | ||
}; | ||
var promise; | ||
var queueMicrotask_1 = typeof queueMicrotask === 'function' ? queueMicrotask // reuse resolved promise, and allocate it lazily | ||
: function (cb) { | ||
return (promise || (promise = Promise.resolve())).then(cb)["catch"](function (err) { | ||
return setTimeout(function () { | ||
throw err; | ||
}, 0); | ||
}); | ||
}; | ||
var INIT = "INIT"; | ||
@@ -317,3 +610,3 @@ var SUBSCRIBE = "SUBSCRIBE"; | ||
var TERMINATE = "TERMINATE"; | ||
var root = typeof self === "object" && self.self === self && self || typeof global === "object" && global.global === global && global || typeof window === "object" && window.window === window && window; | ||
var root = (typeof self === "undefined" ? "undefined" : _typeof$1(self)) === "object" && self.self === self && self || (typeof global === "undefined" ? "undefined" : _typeof$1(global)) === "object" && global.global === global && global || (typeof window === "undefined" ? "undefined" : _typeof$1(window)) === "object" && window.window === window && window; | ||
root.FCL_REGISTRY = root.FCL_REGISTRY == null ? {} : root.FCL_REGISTRY; | ||
@@ -323,7 +616,4 @@ var pid = 0; | ||
var _send = function send(addr, tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
var _send = function send(addr, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
return new Promise(function (reply, reject) { | ||
@@ -335,3 +625,3 @@ var expectReply = opts.expectReply || false; | ||
setTimeout(function () { | ||
return reject(new Error("Timeout: " + timeout + "ms passed without a response.")); | ||
return reject(new Error("Timeout: ".concat(timeout, "ms passed without a response."))); | ||
}, timeout); | ||
@@ -362,75 +652,81 @@ } | ||
var fromHandlers = function fromHandlers(handlers) { | ||
if (handlers === void 0) { | ||
handlers = {}; | ||
} | ||
var fromHandlers = function fromHandlers() { | ||
var handlers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee(ctx) { | ||
var letter; | ||
return regenerator.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (!(typeof handlers[INIT] === "function")) { | ||
_context.next = 3; | ||
break; | ||
} | ||
return function (ctx) { | ||
try { | ||
var _temp12 = function _temp12() { | ||
var _loopInterrupt; | ||
_context.next = 3; | ||
return handlers[INIT](ctx); | ||
var _temp6 = _for(function () { | ||
return !_loopInterrupt && 1; | ||
}, void 0, function () { | ||
return Promise.resolve(ctx.receive()).then(function (letter) { | ||
var _temp5 = _finallyRethrows(function () { | ||
return _catch(function () { | ||
function _temp4() { | ||
return Promise.resolve(handlers[letter.tag](ctx, letter, letter.data || {})).then(function () {}); | ||
} | ||
case 3: | ||
var _temp3 = function () { | ||
if (letter.tag === EXIT) { | ||
var _temp10 = function _temp10() { | ||
_loopInterrupt = 1; | ||
}; | ||
_context.next = 6; | ||
return ctx.receive(); | ||
var _temp11 = function () { | ||
if (typeof handlers[TERMINATE] === "function") { | ||
return Promise.resolve(handlers[TERMINATE](ctx, letter, letter.data || {})).then(function () {}); | ||
} | ||
}(); | ||
case 6: | ||
letter = _context.sent; | ||
_context.prev = 7; | ||
return _temp11 && _temp11.then ? _temp11.then(_temp10) : _temp10(_temp11); | ||
} | ||
}(); | ||
if (!(letter.tag === EXIT)) { | ||
_context.next = 13; | ||
break; | ||
} | ||
return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3); | ||
}, function (error) { | ||
console.error(ctx.self() + " Error", letter, error); | ||
}); | ||
}, function (_wasThrown, _result) { | ||
return; | ||
if (_wasThrown) throw _result; | ||
return _result; | ||
}); | ||
if (!(typeof handlers[TERMINATE] === "function")) { | ||
_context.next = 12; | ||
break; | ||
} | ||
if (_temp5 && _temp5.then) return _temp5.then(function () {}); | ||
}); | ||
}); | ||
_context.next = 12; | ||
return handlers[TERMINATE](ctx, letter, letter.data || {}); | ||
var _temp7 = function () { | ||
if (_temp6 && _temp6.then) return _temp6.then(function () {}); | ||
}(); | ||
case 12: | ||
return _context.abrupt("break", 25); | ||
if (_temp7 && _temp7.then) return _temp7.then(function () {}); | ||
}; | ||
case 13: | ||
_context.next = 15; | ||
return handlers[letter.tag](ctx, letter, letter.data || {}); | ||
var _temp13 = function () { | ||
if (typeof handlers[INIT] === "function") return Promise.resolve(handlers[INIT](ctx)).then(function () {}); | ||
}(); | ||
case 15: | ||
_context.next = 20; | ||
break; | ||
return Promise.resolve(_temp13 && _temp13.then ? _temp13.then(_temp12) : _temp12(_temp13)); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}; | ||
case 17: | ||
_context.prev = 17; | ||
_context.t0 = _context["catch"](7); | ||
console.error("".concat(ctx.self(), " Error"), letter, _context.t0); | ||
case 20: | ||
_context.prev = 20; | ||
return _context.abrupt("continue", 3); | ||
case 23: | ||
_context.next = 3; | ||
break; | ||
case 25: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, null, [[7, 17, 20, 23]]); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
}; | ||
var spawn = function spawn(fn, addr) { | ||
if (addr === void 0) { | ||
addr = null; | ||
} | ||
var spawn = function spawn(fn) { | ||
var addr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
if (addr == null) addr = ++pid; | ||
@@ -452,7 +748,4 @@ if (root.FCL_REGISTRY[addr] != null) return addr; | ||
}, | ||
send: function send(to, tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
send: function send(to, tag, data) { | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
opts.from = addr; | ||
@@ -464,13 +757,19 @@ return _send(to, tag, data, opts); | ||
}, | ||
broadcast: function broadcast(tag, data, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
broadcast: function broadcast(tag, data) { | ||
var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
opts.from = addr; | ||
for (var _iterator = _createForOfIteratorHelperLoose(root.FCL_REGISTRY[addr].subs), _step; !(_step = _iterator()).done;) { | ||
var to = _step.value; | ||
var _iterator = _createForOfIteratorHelper(root.FCL_REGISTRY[addr].subs), | ||
_step; | ||
_send(to, tag, data, opts); | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var to = _step.value; | ||
_send(to, tag, data, opts); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
@@ -511,12 +810,7 @@ }, | ||
return Object.keys(root.FCL_REGISTRY[addr].kvs).reduce(function (acc, key) { | ||
var _extends2; | ||
return pattern.test(key) ? _extends({}, acc, (_extends2 = {}, _extends2[key] = root.FCL_REGISTRY[addr].kvs[key], _extends2)) : acc; | ||
return pattern.test(key) ? _objectSpread2(_objectSpread2({}, acc), {}, _defineProperty({}, key, root.FCL_REGISTRY[addr].kvs[key])) : acc; | ||
}, {}); | ||
}, | ||
merge: function merge(data) { | ||
if (data === void 0) { | ||
data = {}; | ||
} | ||
merge: function merge() { | ||
var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
Object.keys(data).forEach(function (key) { | ||
@@ -529,19 +823,37 @@ return root.FCL_REGISTRY[addr].kvs[key] = data[key]; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(root.FCL_REGISTRY[addr].subs), _step2; !(_step2 = _iterator2()).done;) { | ||
var to = _step2.value; | ||
var _iterator2 = _createForOfIteratorHelper(root.FCL_REGISTRY[addr].subs), | ||
_step2; | ||
_send(to, UPDATED); | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var to = _step2.value; | ||
_send(to, UPDATED); | ||
} | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
} | ||
}; | ||
if (typeof fn === "object") fn = fromHandlers(fn); | ||
queueMicrotask(function () { | ||
try { | ||
return Promise.resolve(fn(ctx)).then(function () { | ||
kill(addr); | ||
}); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
if (_typeof$1(fn) === "object") fn = fromHandlers(fn); | ||
queueMicrotask_1( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee2() { | ||
return regenerator.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context2.next = 2; | ||
return fn(ctx); | ||
case 2: | ||
kill(addr); | ||
case 3: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2); | ||
}))); | ||
return addr; | ||
@@ -560,33 +872,55 @@ }; // Returns an unsubscribe function | ||
var EXIT = "@EXIT"; | ||
var self = spawn(function (ctx) { | ||
try { | ||
var _exit2; | ||
var self = spawn( /*#__PURE__*/function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regenerator.mark(function _callee3(ctx) { | ||
var letter, error; | ||
return regenerator.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
ctx.send(address, SUBSCRIBE); | ||
ctx.send(address, SUBSCRIBE); | ||
return Promise.resolve(_for(function () { | ||
return !_exit2 && 1; | ||
}, void 0, function () { | ||
return Promise.resolve(ctx.receive()).then(function (letter) { | ||
var error = root.FCL_REGISTRY[address].error; | ||
case 1: | ||
if (letter.tag === EXIT) { | ||
ctx.send(address, UNSUBSCRIBE); | ||
_exit2 = 1; | ||
return; | ||
} | ||
_context3.next = 4; | ||
return ctx.receive(); | ||
if (error) { | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
_exit2 = 1; | ||
return; | ||
case 4: | ||
letter = _context3.sent; | ||
error = root.FCL_REGISTRY[address].error; | ||
if (!(letter.tag === EXIT)) { | ||
_context3.next = 9; | ||
break; | ||
} | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 9: | ||
if (!error) { | ||
_context3.next = 13; | ||
break; | ||
} | ||
callback(null, error); | ||
ctx.send(address, UNSUBSCRIBE); | ||
return _context3.abrupt("return"); | ||
case 13: | ||
callback(letter.data, null); | ||
_context3.next = 1; | ||
break; | ||
case 16: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3); | ||
})); | ||
callback(letter.data, null); | ||
}); | ||
})); | ||
} catch (e) { | ||
return Promise.reject(e); | ||
} | ||
}); | ||
return function (_x2) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}()); | ||
return function () { | ||
@@ -624,3 +958,5 @@ return _send(self, EXIT); | ||
}))); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
})); | ||
//# sourceMappingURL=actor.umd.js.map |
{ | ||
"name": "@onflow/util-actor", | ||
"version": "1.1.0", | ||
"version": "1.1.1-alpha.0", | ||
"description": "A mechanism for forcing order/transitions of scoped async state", | ||
@@ -21,7 +21,8 @@ "license": "Apache-2.0", | ||
"devDependencies": { | ||
"@onflow/fcl-bundle": "^1.0.1-alpha.0", | ||
"jest": "26.4.0", | ||
"jest-esm-transformer": "1.0.0", | ||
"microbundle": "0.12.3" | ||
"jest-esm-transformer": "1.0.0" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.18.6", | ||
"queue-microtask": "1.1.2" | ||
@@ -36,6 +37,6 @@ }, | ||
"test": "jest", | ||
"build": "microbundle --no-compress", | ||
"build": "fcl-bundle", | ||
"test:watch": "jest --watch", | ||
"start": "microbundle watch --no-compress" | ||
"start": "fcl-bundle --watch" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181827
2
14
1875
1
1
+ Added@babel/runtime@^7.18.6
+ Added@babel/runtime@7.26.0(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)