Comparing version 0.0.3 to 0.0.4
@@ -1,2 +0,2 @@ | ||
/*! spica v0.0.3 https://github.com/falsandtru/spica | (c) 2016, falsandtru | undefined License (undefined) */ | ||
/*! spica v0.0.4 https://github.com/falsandtru/spica | (c) 2016, falsandtru | undefined License (undefined) */ | ||
define = typeof define === 'function' && define.amd | ||
@@ -242,3 +242,3 @@ ? define | ||
default: { | ||
throw new TypeError('spica: Observable: Invalid subscriber.\n\t' + (types, subscriber)); | ||
throw new TypeError('Spica: Observable: Invalid subscriber.\n\t' + (types, subscriber)); | ||
} | ||
@@ -251,79 +251,2 @@ } | ||
}); | ||
define('src/lib/fingerprint', [ | ||
'require', | ||
'exports' | ||
], function (require, exports) { | ||
'use strict'; | ||
exports.FINGERPRINT = typeof window === 'object' ? browser() : server(); | ||
function browser() { | ||
return hash(str2digit([ | ||
stringify(window.navigator), | ||
stringify(window.screen), | ||
stringify(new Date().getTimezoneOffset()) | ||
].join())); | ||
} | ||
exports.browser = browser; | ||
function server() { | ||
return hash(str2digit([stringify(process)].join())); | ||
} | ||
exports.server = server; | ||
function hash(digit) { | ||
return digit.split('').reduce(function (a, b, i) { | ||
return (+b * i + a) % 1000000000 || a - +b; | ||
}, 0); | ||
} | ||
exports.hash = hash; | ||
function str2digit(str) { | ||
return str.split('').map(function (c) { | ||
return c.charCodeAt(0); | ||
}).join(''); | ||
} | ||
exports.str2digit = str2digit; | ||
function stringify(obj, depth) { | ||
if (depth === void 0) { | ||
depth = 5; | ||
} | ||
if (depth > 0 && obj && typeof obj === 'object') { | ||
var str = '{'; | ||
for (var p in obj) { | ||
str += '"' + p + '": ' + stringify(obj[p], depth - 1) + ','; | ||
} | ||
str += '}'; | ||
return str; | ||
} else { | ||
return !obj || obj.toString ? '"' + obj + '"' : '"' + Object.prototype.toString.call(obj) + '"'; | ||
} | ||
} | ||
exports.stringify = stringify; | ||
}); | ||
define('src/lib/uuid', [ | ||
'require', | ||
'exports', | ||
'src/lib/fingerprint' | ||
], function (require, exports, fingerprint_1) { | ||
'use strict'; | ||
var SEED = fingerprint_1.FINGERPRINT * Date.now() % 1000000000000000; | ||
if (!SEED || typeof SEED !== 'number' || SEED < 100 || 1000000000000000 < SEED) | ||
throw new Error('spica: uuid: Invalid uuid static seed.\n\t' + fingerprint_1.FINGERPRINT); | ||
var FORMAT_V4 = Object.freeze('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.split('')); | ||
var seed = SEED; | ||
function v4() { | ||
var k = seed = seed * Date.now() % 1000000000000000; | ||
if (k < 16 || 1000000000000000 < k) | ||
throw new Error('spica: uuid: Invalid uuid dynamic seed.'); | ||
var acc = ''; | ||
for (var _i = 0, FORMAT_V4_1 = FORMAT_V4; _i < FORMAT_V4_1.length; _i++) { | ||
var c = FORMAT_V4_1[_i]; | ||
if (c === 'x' || c === 'y') { | ||
var r = Math.random() * k % 16 | 0; | ||
var v = c == 'x' ? r : r & 3 | 8; | ||
acc += v.toString(16); | ||
} else { | ||
acc += c; | ||
} | ||
} | ||
return acc.toLowerCase(); | ||
} | ||
exports.v4 = v4; | ||
}); | ||
define('src/lib/sqid', [ | ||
@@ -340,149 +263,2 @@ 'require', | ||
}); | ||
define('src/lib/dict/weakmap', [ | ||
'require', | ||
'exports', | ||
'src/lib/uuid', | ||
'src/lib/sqid' | ||
], function (require, exports, uuid_1, sqid_1) { | ||
'use strict'; | ||
var UNIQUE_ATTRIBUTE = '' + uuid_1.v4(); | ||
function store(obj) { | ||
return obj[UNIQUE_ATTRIBUTE] ? obj[UNIQUE_ATTRIBUTE] : Object.defineProperty(obj, UNIQUE_ATTRIBUTE, { | ||
value: Object.create(null), | ||
enumerable: false, | ||
writable: false, | ||
configurable: true | ||
})[UNIQUE_ATTRIBUTE]; | ||
} | ||
var WeakMap = function () { | ||
function WeakMap() { | ||
this.id = +sqid_1.sqid(); | ||
} | ||
WeakMap.prototype.get = function (key) { | ||
return (store(key)[this.id] || [])[0]; | ||
}; | ||
WeakMap.prototype.set = function (key, val) { | ||
return (store(key)[this.id] = [val])[0]; | ||
}; | ||
WeakMap.prototype.has = function (key) { | ||
return !!store(key)[this.id]; | ||
}; | ||
WeakMap.prototype.delete = function (key) { | ||
void delete store(key)[this.id]; | ||
}; | ||
return WeakMap; | ||
}(); | ||
exports.WeakMap = WeakMap; | ||
}); | ||
define('src/lib/dict/map', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/weakmap', | ||
'src/lib/concat', | ||
'src/lib/sqid' | ||
], function (require, exports, weakmap_1, concat_2, sqid_2) { | ||
'use strict'; | ||
function isPrimitive(target) { | ||
return target instanceof Object === false; | ||
} | ||
exports.isPrimitive = isPrimitive; | ||
var Map = function () { | ||
function Map() { | ||
this.pstore = Object.create(null); | ||
this.ostore = Object.create(null); | ||
this.weakstore = new weakmap_1.WeakMap(); | ||
void this.reset_(); | ||
} | ||
Map.prototype.stringify = function (key) { | ||
switch (typeof key) { | ||
case 'undefined': | ||
return '0:' + key; | ||
case 'boolean': | ||
return '1:' + key; | ||
case 'number': | ||
return '2:' + (1000 + ('' + key).length) + ':' + key; | ||
case 'string': | ||
return '3:' + (100000000000000 + key.length) + ':' + key; | ||
default: { | ||
if (isPrimitive(key)) | ||
return '8:' + key; | ||
return '9:' + (this.weakstore.has(key) ? this.weakstore.get(key)[0] : sqid_2.sqid()); | ||
} | ||
} | ||
}; | ||
Map.prototype.get = function (key) { | ||
return isPrimitive(key) ? (this.pstore[this.stringify(key)] || [])[1] : (this.weakstore.get(key) || [])[1]; | ||
}; | ||
Map.prototype.set = function (key, val) { | ||
void this.reset_(); | ||
if (isPrimitive(key)) { | ||
this.pstore[this.stringify(key)] = [ | ||
key, | ||
val | ||
]; | ||
} else { | ||
var id = this.stringify(key); | ||
void this.weakstore.set(key, [ | ||
id, | ||
val | ||
]); | ||
this.ostore[id] = [ | ||
key, | ||
val, | ||
id | ||
]; | ||
} | ||
return val; | ||
}; | ||
Map.prototype.has = function (key) { | ||
return isPrimitive(key) ? !!this.pstore[this.stringify(key)] : this.weakstore.has(key); | ||
}; | ||
Map.prototype.delete = function (key) { | ||
void this.reset_(); | ||
if (isPrimitive(key)) { | ||
void delete this.pstore[this.stringify(key)]; | ||
} else { | ||
void delete this.ostore[(this.weakstore.get(key) || [])[0]]; | ||
void this.weakstore.delete(key); | ||
} | ||
}; | ||
Map.prototype.clear = function () { | ||
var _this = this; | ||
void this.reset_(); | ||
void Object.keys(this.ostore).forEach(function (id) { | ||
return void _this.delete(_this.ostore[id][0]); | ||
}); | ||
this.weakstore = new weakmap_1.WeakMap(); | ||
this.pstore = Object.create(null); | ||
this.ostore = Object.create(null); | ||
}; | ||
Map.prototype.reset_ = function () { | ||
this.size_ = NaN; | ||
this.entries_ = void 0; | ||
}; | ||
Object.defineProperty(Map.prototype, 'size', { | ||
get: function () { | ||
return this.size_ >= 0 ? this.size_ : this.size_ = Object.keys(this.pstore).length + Object.keys(this.ostore).length; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Map.prototype.entries = function () { | ||
var _this = this; | ||
return this.entries_ ? this.entries_ : this.entries_ = concat_2.concat(Object.keys(this.pstore).sort().map(function (key) { | ||
return [ | ||
_this.pstore[key][0], | ||
_this.pstore[key][1] | ||
]; | ||
}), Object.keys(this.ostore).map(function (key) { | ||
return [ | ||
_this.ostore[key][0], | ||
_this.ostore[key][1] | ||
]; | ||
})); | ||
}; | ||
return Map; | ||
}(); | ||
exports.Map = Map; | ||
}); | ||
define('src/lib/type', [ | ||
@@ -498,16 +274,16 @@ 'require', | ||
}); | ||
define('src/lib/dict/datamap', [ | ||
define('src/lib/collection/datamap', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/weakmap', | ||
'src/lib/dict/map', | ||
'src/lib/sqid', | ||
'src/lib/type' | ||
], function (require, exports, weakmap_2, map_1, sqid_3, type_1) { | ||
], function (require, exports, sqid_1, type_1) { | ||
'use strict'; | ||
function isPrimitive(target) { | ||
return target instanceof Object === false; | ||
} | ||
var DataMap = function () { | ||
function DataMap() { | ||
this.store = Object.create(null); | ||
this.weakstore = new weakmap_2.WeakMap(); | ||
void this.reset_(); | ||
this.store = new Map(); | ||
this.weakstore = new WeakMap(); | ||
} | ||
@@ -525,3 +301,3 @@ DataMap.prototype.stringify = function (key) { | ||
default: { | ||
if (map_1.isPrimitive(key)) { | ||
if (isPrimitive(key)) { | ||
return '8:' + key; | ||
@@ -532,3 +308,3 @@ } | ||
} | ||
return '9:{ ' + (this.weakstore.has(key) ? this.weakstore.get(key) : this.stringifyObject(key) || this.weakstore.set(key, sqid_3.sqid())) + ' }'; | ||
return '9:{ ' + (this.weakstore.has(key) ? this.weakstore.get(key) : this.stringifyObject(key) || this.weakstore.set(key, sqid_1.sqid())) + ' }'; | ||
} | ||
@@ -557,29 +333,22 @@ } | ||
DataMap.prototype.get = function (key) { | ||
return (this.store[this.stringify(key)] || [])[1]; | ||
return (this.store.get(this.stringify(key)) || [])[1]; | ||
}; | ||
DataMap.prototype.set = function (key, val) { | ||
void this.reset_(); | ||
return (this.store[this.stringify(key)] = [ | ||
return void this.store.set(this.stringify(key), [ | ||
key, | ||
val | ||
])[1]; | ||
]), this; | ||
}; | ||
DataMap.prototype.has = function (key) { | ||
return !!this.store[this.stringify(key)]; | ||
return this.store.has(this.stringify(key)); | ||
}; | ||
DataMap.prototype.delete = function (key) { | ||
void this.reset_(); | ||
return void delete this.store[this.stringify(key)]; | ||
return this.store.delete(this.stringify(key)); | ||
}; | ||
DataMap.prototype.clear = function () { | ||
void this.reset_(); | ||
this.store = Object.create(null); | ||
return this.store.clear(); | ||
}; | ||
DataMap.prototype.reset_ = function () { | ||
this.size_ = NaN; | ||
this.entries_ = void 0; | ||
}; | ||
Object.defineProperty(DataMap.prototype, 'size', { | ||
get: function () { | ||
return this.size_ >= 0 ? this.size_ : this.size_ = Object.keys(this.store).length; | ||
return this.store.size; | ||
}, | ||
@@ -589,8 +358,2 @@ enumerable: true, | ||
}); | ||
DataMap.prototype.entries = function () { | ||
var _this = this; | ||
return this.entries_ ? this.entries_ : this.entries_ = Object.keys(this.store).sort().map(function (key) { | ||
return _this.store[key]; | ||
}); | ||
}; | ||
return DataMap; | ||
@@ -600,46 +363,2 @@ }(); | ||
}); | ||
define('src/lib/dict/dataset', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/datamap' | ||
], function (require, exports, datamap_1) { | ||
'use strict'; | ||
var DataSet = function () { | ||
function DataSet(replacer) { | ||
this.replacer = replacer; | ||
this.store = new datamap_1.DataMap(); | ||
} | ||
DataSet.prototype.get = function (key) { | ||
return this.store.get(key); | ||
}; | ||
DataSet.prototype.add = function (key, val) { | ||
if (!this.has(key)) | ||
return this.store.set(key, val); | ||
if (!this.replacer) | ||
throw new Error('spica: Set: Cannot overwrite value of set without replacer.'); | ||
return this.store.set(key, this.replacer(this.get(key), val)); | ||
}; | ||
DataSet.prototype.has = function (key) { | ||
return this.store.has(key); | ||
}; | ||
DataSet.prototype.delete = function (key) { | ||
return void this.store.delete(key); | ||
}; | ||
DataSet.prototype.clear = function () { | ||
return void this.store.clear(); | ||
}; | ||
Object.defineProperty(DataSet.prototype, 'size', { | ||
get: function () { | ||
return this.store.size; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
DataSet.prototype.entries = function () { | ||
return this.store.entries(); | ||
}; | ||
return DataSet; | ||
}(); | ||
exports.DataSet = DataSet; | ||
}); | ||
define('src/lib/tick', [ | ||
@@ -710,3 +429,3 @@ 'require', | ||
'src/lib/observable', | ||
'src/lib/dict/dataset', | ||
'src/lib/collection/datamap', | ||
'src/lib/tick', | ||
@@ -716,3 +435,3 @@ 'src/lib/thenable', | ||
'src/lib/noop' | ||
], function (require, exports, observable_1, dataset_1, tick_1, thenable_1, concat_3, noop_1) { | ||
], function (require, exports, observable_1, datamap_1, tick_1, thenable_1, concat_2, noop_1) { | ||
'use strict'; | ||
@@ -723,3 +442,3 @@ var Supervisor = function () { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.name, name = _c === void 0 ? '' : _c, _d = _b.dependencies, dependencies = _d === void 0 ? [] : _d, _e = _b.retry, retry = _e === void 0 ? false : _e, _f = _b.timeout, timeout = _f === void 0 ? 0 : _f, _g = _b.destructor, destructor = _g === void 0 ? noop_1.noop : _g; | ||
this.deps = new dataset_1.DataSet(); | ||
this.deps = new datamap_1.DataMap(); | ||
this.events = { | ||
@@ -741,7 +460,7 @@ exec: new observable_1.Observable(), | ||
if (this.constructor === Supervisor) | ||
throw new Error('spica: Supervisor: Cannot instantiate abstract classes.'); | ||
throw new Error('Spica: Supervisor: Cannot instantiate abstract classes.'); | ||
this.name = name; | ||
void dependencies.reduce(function (_, _a) { | ||
var namespace = _a[0], deps = _a[1]; | ||
return void _this.deps.add(namespace, deps); | ||
return void _this.deps.set(namespace, deps); | ||
}, void 0); | ||
@@ -789,4 +508,4 @@ this.retry = retry; | ||
if (!this.registerable) | ||
throw new Error('spica: Supervisor: Supervisor ' + this.name + ' cannot register process during the exiting.'); | ||
namespace = concat_3.concat([], namespace); | ||
throw new Error('Spica: Supervisor: Supervisor ' + this.name + ' cannot register process during the exiting.'); | ||
namespace = concat_2.concat([], namespace); | ||
void this.schedule(); | ||
@@ -804,3 +523,3 @@ return new Worker(this, this.workerSharedResource, namespace, process, this.deps.get(namespace) || []).terminate; | ||
void this.checkState(); | ||
namespace = concat_3.concat([], namespace); | ||
namespace = concat_2.concat([], namespace); | ||
void this.queue.push([ | ||
@@ -827,3 +546,3 @@ namespace, | ||
void this.checkState(); | ||
var results = this.procs.reflect(namespace, new WorkerCommand_$Call(data)); | ||
var results = this.procs.reflect(namespace, new WorkerCommand.Call(data)); | ||
if (results.length === 0) { | ||
@@ -855,3 +574,3 @@ void this.events.fail.emit(namespace, [ | ||
} | ||
void this.procs.emit(namespace || [], new WorkerCommand_$Exit(reason)); | ||
void this.procs.emit(namespace || [], new WorkerCommand.Exit(reason)); | ||
void this.procs.off(namespace || []); | ||
@@ -864,3 +583,3 @@ if (namespace === void 0) { | ||
if (!this.alive) | ||
throw new Error('spica: Supervisor: Supervisor ' + this.name + ' already exited.'); | ||
throw new Error('Spica: Supervisor: Supervisor ' + this.name + ' already exited.'); | ||
}; | ||
@@ -876,3 +595,3 @@ Supervisor.prototype.drain = function (target) { | ||
return n === namespace[i]; | ||
}) ? this_1.procs.reflect(namespace, new WorkerCommand_$Call(data)) : []; | ||
}) ? this_1.procs.reflect(namespace, new WorkerCommand.Call(data)) : []; | ||
if (results.length === 0) { | ||
@@ -919,31 +638,37 @@ void this_1.events.fail.emit(namespace, [ | ||
exports.Supervisor = Supervisor; | ||
var AbstractWorkerCommand = function () { | ||
function AbstractWorkerCommand() { | ||
} | ||
return AbstractWorkerCommand; | ||
}(); | ||
var WorkerCommand_$Deps = function (_super) { | ||
__extends(WorkerCommand_$Deps, _super); | ||
function WorkerCommand_$Deps(namespace) { | ||
_super.call(this); | ||
this.namespace = namespace; | ||
} | ||
return WorkerCommand_$Deps; | ||
}(AbstractWorkerCommand); | ||
var WorkerCommand_$Call = function (_super) { | ||
__extends(WorkerCommand_$Call, _super); | ||
function WorkerCommand_$Call(data) { | ||
_super.call(this); | ||
this.data = data; | ||
} | ||
return WorkerCommand_$Call; | ||
}(AbstractWorkerCommand); | ||
var WorkerCommand_$Exit = function (_super) { | ||
__extends(WorkerCommand_$Exit, _super); | ||
function WorkerCommand_$Exit(reason) { | ||
_super.call(this); | ||
this.reason = reason; | ||
} | ||
return WorkerCommand_$Exit; | ||
}(AbstractWorkerCommand); | ||
var WorkerCommand; | ||
(function (WorkerCommand) { | ||
var AbstractCommand = function () { | ||
function AbstractCommand() { | ||
} | ||
return AbstractCommand; | ||
}(); | ||
var Deps = function (_super) { | ||
__extends(Deps, _super); | ||
function Deps(namespace) { | ||
_super.call(this); | ||
this.namespace = namespace; | ||
} | ||
return Deps; | ||
}(AbstractCommand); | ||
WorkerCommand.Deps = Deps; | ||
var Call = function (_super) { | ||
__extends(Call, _super); | ||
function Call(data) { | ||
_super.call(this); | ||
this.data = data; | ||
} | ||
return Call; | ||
}(AbstractCommand); | ||
WorkerCommand.Call = Call; | ||
var Exit = function (_super) { | ||
__extends(Exit, _super); | ||
function Exit(reason) { | ||
_super.call(this); | ||
this.reason = reason; | ||
} | ||
return Exit; | ||
}(AbstractCommand); | ||
WorkerCommand.Exit = Exit; | ||
}(WorkerCommand || (WorkerCommand = {}))); | ||
var Worker = function () { | ||
@@ -984,3 +709,3 @@ function Worker(sv, sharedResource, namespace, process, dependencies) { | ||
Worker.prototype.tryDependencyResolving = function (cmd) { | ||
if (this.receive(new WorkerCommand_$Deps(this.namespace))) { | ||
if (this.receive(new WorkerCommand.Deps(this.namespace))) { | ||
this.sharedResource.dependenciesStack = []; | ||
@@ -999,3 +724,3 @@ return; | ||
} | ||
if (cmd instanceof WorkerCommand_$Deps) { | ||
if (cmd instanceof WorkerCommand.Deps) { | ||
if (cmd.namespace.length !== this.namespace.length) | ||
@@ -1014,7 +739,7 @@ return false; | ||
var ns = _a[0], proc = _a[1]; | ||
return equal(ns, dep) && !!proc(new WorkerCommand_$Deps(dep)); | ||
return equal(ns, dep) && !!proc(new WorkerCommand.Deps(dep)); | ||
}); | ||
}); | ||
} | ||
if (cmd instanceof WorkerCommand_$Call) { | ||
if (cmd instanceof WorkerCommand.Call) { | ||
if (this.concurrency === 0) | ||
@@ -1055,7 +780,7 @@ throw void 0; | ||
} | ||
if (cmd instanceof WorkerCommand_$Exit) { | ||
if (cmd instanceof WorkerCommand.Exit) { | ||
void this.terminate(cmd.reason); | ||
throw void 0; | ||
} | ||
throw new TypeError('spica: Supervisor: Invalid command: ' + cmd); | ||
throw new TypeError('Spica: Supervisor: Invalid command: ' + cmd); | ||
}; | ||
@@ -1067,3 +792,3 @@ Worker.prototype.terminate = function (reason) { | ||
if (!this.alive) | ||
throw new Error('spica: Supervisor: Process ' + this.namespace + '/' + this.process + ' already exited.'); | ||
throw new Error('Spica: Supervisor: Process ' + this.namespace + '/' + this.process + ' already exited.'); | ||
}; | ||
@@ -1155,3 +880,3 @@ return Worker; | ||
} | ||
throw new TypeError('spica: Maybe: Invalid monad value.\n\t' + m); | ||
throw new TypeError('Spica: Maybe: Invalid monad value.\n\t' + m); | ||
}); | ||
@@ -1261,3 +986,3 @@ }; | ||
} | ||
throw new TypeError('spica: Either: Invalid monad value.\n\t' + m); | ||
throw new TypeError('Spica: Either: Invalid monad value.\n\t' + m); | ||
}); | ||
@@ -1346,12 +1071,10 @@ }; | ||
}); | ||
define('src/lib/dict/attrmap', [ | ||
define('src/lib/collection/attrmap', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/map', | ||
'src/lib/dict/weakmap' | ||
], function (require, exports, map_2, weakmap_3) { | ||
'exports' | ||
], function (require, exports) { | ||
'use strict'; | ||
var AttrMap = function () { | ||
function AttrMap() { | ||
this.store = new weakmap_3.WeakMap(); | ||
this.store = new WeakMap(); | ||
} | ||
@@ -1362,3 +1085,4 @@ AttrMap.prototype.get = function (obj, key) { | ||
AttrMap.prototype.set = function (obj, key, val) { | ||
return (this.store.get(obj) || this.store.set(obj, new map_2.Map())).set(key, val); | ||
var store = this.store.has(obj) ? this.store.get(obj) : this.store.set(obj, new Map()).get(obj); | ||
return void store.set(key, val), this; | ||
}; | ||
@@ -1369,3 +1093,3 @@ AttrMap.prototype.has = function (obj, key) { | ||
AttrMap.prototype.delete = function (obj, key) { | ||
return key === void 0 ? this.store.delete(obj) : this.store.get(obj) && this.store.get(obj).delete(key); | ||
return key === void 0 ? this.store.delete(obj) : this.store.has(obj) ? this.store.get(obj).delete(key) : false; | ||
}; | ||
@@ -1376,11 +1100,10 @@ return AttrMap; | ||
}); | ||
define('src/lib/dict/relationmap', [ | ||
define('src/lib/collection/relationmap', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/weakmap' | ||
], function (require, exports, weakmap_4) { | ||
'exports' | ||
], function (require, exports) { | ||
'use strict'; | ||
var RelationMap = function () { | ||
function RelationMap() { | ||
this.store = new weakmap_4.WeakMap(); | ||
this.store = new WeakMap(); | ||
} | ||
@@ -1391,3 +1114,4 @@ RelationMap.prototype.get = function (source, target) { | ||
RelationMap.prototype.set = function (source, target, val) { | ||
return (this.store.get(source) || this.store.set(source, new weakmap_4.WeakMap())).set(target, val); | ||
var store = this.store.has(source) ? this.store.get(source) : this.store.set(source, new WeakMap()).get(source); | ||
return void store.set(target, val), this; | ||
}; | ||
@@ -1398,3 +1122,3 @@ RelationMap.prototype.has = function (source, target) { | ||
RelationMap.prototype.delete = function (source, target) { | ||
return target === void 0 ? this.store.delete(source) : this.store.get(source) && this.store.get(source).delete(target); | ||
return target === void 0 ? this.store.delete(source) : this.store.has(source) ? this.store.get(source).delete(target) : false; | ||
}; | ||
@@ -1405,133 +1129,79 @@ return RelationMap; | ||
}); | ||
define('src/lib/dict/set', [ | ||
define('src/lib/fingerprint', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/map' | ||
], function (require, exports, map_3) { | ||
'exports' | ||
], function (require, exports) { | ||
'use strict'; | ||
var Set = function () { | ||
function Set(replacer) { | ||
this.replacer = replacer; | ||
this.store = new map_3.Map(); | ||
exports.FINGERPRINT = typeof window === 'object' ? browser() : server(); | ||
function browser() { | ||
return hash(str2digit([ | ||
stringify(window.navigator), | ||
stringify(window.screen), | ||
stringify(new Date().getTimezoneOffset()) | ||
].join())); | ||
} | ||
exports.browser = browser; | ||
function server() { | ||
return hash(str2digit([stringify(process)].join())); | ||
} | ||
exports.server = server; | ||
function hash(digit) { | ||
return digit.split('').reduce(function (a, b, i) { | ||
return (+b * i + a) % 1000000000 || a - +b; | ||
}, 0); | ||
} | ||
exports.hash = hash; | ||
function str2digit(str) { | ||
return str.split('').map(function (c) { | ||
return c.charCodeAt(0); | ||
}).join(''); | ||
} | ||
exports.str2digit = str2digit; | ||
function stringify(obj, depth) { | ||
if (depth === void 0) { | ||
depth = 5; | ||
} | ||
Set.prototype.get = function (key) { | ||
return this.store.get(key); | ||
}; | ||
Set.prototype.add = function (key, val) { | ||
if (!this.has(key)) | ||
return this.store.set(key, val); | ||
if (!this.replacer) | ||
throw new Error('spica: Set: Cannot overwrite value of set without replacer.'); | ||
return this.store.set(key, this.replacer(this.get(key), val)); | ||
}; | ||
Set.prototype.has = function (key) { | ||
return this.store.has(key); | ||
}; | ||
Set.prototype.delete = function (key) { | ||
return void this.store.delete(key); | ||
}; | ||
Set.prototype.clear = function () { | ||
return void this.store.clear(); | ||
}; | ||
Object.defineProperty(Set.prototype, 'size', { | ||
get: function () { | ||
return this.store.size; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Set.prototype.entries = function () { | ||
return this.store.entries(); | ||
}; | ||
return Set; | ||
}(); | ||
exports.Set = Set; | ||
}); | ||
define('src/lib/dict/weakset', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/weakmap' | ||
], function (require, exports, weakmap_5) { | ||
'use strict'; | ||
var WeakSet = function () { | ||
function WeakSet(replacer) { | ||
this.replacer = replacer; | ||
this.store = new weakmap_5.WeakMap(); | ||
if (depth > 0 && obj && typeof obj === 'object') { | ||
var str = '{'; | ||
for (var p in obj) { | ||
str += '"' + p + '": ' + stringify(obj[p], depth - 1) + ','; | ||
} | ||
str += '}'; | ||
return str; | ||
} else { | ||
return !obj || obj.toString ? '"' + obj + '"' : '"' + Object.prototype.toString.call(obj) + '"'; | ||
} | ||
WeakSet.prototype.get = function (key) { | ||
return this.store.get(key); | ||
}; | ||
WeakSet.prototype.add = function (key, val) { | ||
if (!this.has(key)) | ||
return this.store.set(key, val); | ||
if (!this.replacer) | ||
throw new Error('spica: WeakSet: Cannot overwrite value of set without replacer.'); | ||
return this.store.set(key, this.replacer(this.get(key), val)); | ||
}; | ||
WeakSet.prototype.has = function (key) { | ||
return this.store.has(key); | ||
}; | ||
WeakSet.prototype.delete = function (key) { | ||
void this.store.delete(key); | ||
}; | ||
return WeakSet; | ||
}(); | ||
exports.WeakSet = WeakSet; | ||
} | ||
exports.stringify = stringify; | ||
}); | ||
define('src/lib/dict/attrset', [ | ||
define('src/lib/uuid', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/set', | ||
'src/lib/dict/weakmap' | ||
], function (require, exports, set_1, weakmap_6) { | ||
'src/lib/fingerprint' | ||
], function (require, exports, fingerprint_1) { | ||
'use strict'; | ||
var AttrSet = function () { | ||
function AttrSet(replacer) { | ||
this.replacer = replacer; | ||
this.store = new weakmap_6.WeakMap(); | ||
var SEED = fingerprint_1.FINGERPRINT * Date.now() % 1000000000000000; | ||
if (!SEED || typeof SEED !== 'number' || SEED < 100 || 1000000000000000 < SEED) | ||
throw new Error('Spica: uuid: Invalid uuid static seed.\n\t' + fingerprint_1.FINGERPRINT); | ||
var FORMAT_V4 = Object.freeze('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.split('')); | ||
var seed = SEED; | ||
function v4() { | ||
var k = seed = seed * Date.now() % 1000000000000000; | ||
if (k < 16 || 1000000000000000 < k) | ||
throw new Error('Spica: uuid: Invalid uuid dynamic seed.'); | ||
var acc = ''; | ||
for (var _i = 0, FORMAT_V4_1 = FORMAT_V4; _i < FORMAT_V4_1.length; _i++) { | ||
var c = FORMAT_V4_1[_i]; | ||
if (c === 'x' || c === 'y') { | ||
var r = Math.random() * k % 16 | 0; | ||
var v = c == 'x' ? r : r & 3 | 8; | ||
acc += v.toString(16); | ||
} else { | ||
acc += c; | ||
} | ||
} | ||
AttrSet.prototype.get = function (obj, key) { | ||
return this.store.get(obj) && this.store.get(obj).get(key); | ||
}; | ||
AttrSet.prototype.add = function (obj, key, val) { | ||
return (this.store.get(obj) || this.store.set(obj, new set_1.Set(this.replacer))).add(key, val); | ||
}; | ||
AttrSet.prototype.has = function (obj, key) { | ||
return this.store.has(obj) && this.store.get(obj).has(key); | ||
}; | ||
AttrSet.prototype.delete = function (obj, key) { | ||
return key === void 0 ? this.store.delete(obj) : this.store.get(obj) && this.store.get(obj).delete(key); | ||
}; | ||
return AttrSet; | ||
}(); | ||
exports.AttrSet = AttrSet; | ||
return acc.toLowerCase(); | ||
} | ||
exports.v4 = v4; | ||
}); | ||
define('src/lib/dict/relationset', [ | ||
'require', | ||
'exports', | ||
'src/lib/dict/weakset', | ||
'src/lib/dict/weakmap' | ||
], function (require, exports, weakset_1, weakmap_7) { | ||
'use strict'; | ||
var RelationSet = function () { | ||
function RelationSet(replacer) { | ||
this.replacer = replacer; | ||
this.store = new weakmap_7.WeakMap(); | ||
} | ||
RelationSet.prototype.get = function (source, target) { | ||
return this.store.get(source) && this.store.get(source).get(target); | ||
}; | ||
RelationSet.prototype.add = function (source, target, val) { | ||
return (this.store.get(source) || this.store.set(source, new weakset_1.WeakSet(this.replacer))).add(target, val); | ||
}; | ||
RelationSet.prototype.has = function (source, target) { | ||
return this.store.has(source) && this.store.get(source).has(target); | ||
}; | ||
RelationSet.prototype.delete = function (source, target) { | ||
return target === void 0 ? this.store.delete(source) : this.store.get(source) && this.store.get(source).delete(target); | ||
}; | ||
return RelationSet; | ||
}(); | ||
exports.RelationSet = RelationSet; | ||
}); | ||
define('src/lib/assign', [ | ||
@@ -1589,3 +1259,3 @@ 'require', | ||
if (target === undefined || target === null) { | ||
throw new TypeError('spica: assign: Cannot walk on ' + target + '.'); | ||
throw new TypeError('Spica: assign: Cannot walk on ' + target + '.'); | ||
} | ||
@@ -1616,12 +1286,5 @@ for (var _a = 0, sources_1 = sources; _a < sources_1.length; _a++) { | ||
'src/lib/monad/either', | ||
'src/lib/dict/map', | ||
'src/lib/dict/datamap', | ||
'src/lib/dict/weakmap', | ||
'src/lib/dict/attrmap', | ||
'src/lib/dict/relationmap', | ||
'src/lib/dict/set', | ||
'src/lib/dict/dataset', | ||
'src/lib/dict/weakset', | ||
'src/lib/dict/attrset', | ||
'src/lib/dict/relationset', | ||
'src/lib/collection/datamap', | ||
'src/lib/collection/attrmap', | ||
'src/lib/collection/relationmap', | ||
'src/lib/tick', | ||
@@ -1633,3 +1296,3 @@ 'src/lib/fingerprint', | ||
'src/lib/concat' | ||
], function (require, exports, supervisor_1, observable_2, maybe_1, either_1, map_4, datamap_2, weakmap_8, attrmap_1, relationmap_1, set_2, dataset_2, weakset_2, attrset_1, relationset_1, tick_2, fingerprint_2, uuid_2, sqid_4, assign_1, concat_4) { | ||
], function (require, exports, supervisor_1, observable_2, maybe_1, either_1, datamap_2, attrmap_1, relationmap_1, tick_2, fingerprint_2, uuid_1, sqid_2, assign_1, concat_3) { | ||
'use strict'; | ||
@@ -1644,20 +1307,13 @@ exports.Supervisor = supervisor_1.Supervisor; | ||
exports.Right = either_1.Right; | ||
exports.Map = map_4.Map; | ||
exports.DataMap = datamap_2.DataMap; | ||
exports.WeakMap = weakmap_8.WeakMap; | ||
exports.AttrMap = attrmap_1.AttrMap; | ||
exports.RelationMap = relationmap_1.RelationMap; | ||
exports.Set = set_2.Set; | ||
exports.DataSet = dataset_2.DataSet; | ||
exports.WeakSet = weakset_2.WeakSet; | ||
exports.AttrSet = attrset_1.AttrSet; | ||
exports.RelationSet = relationset_1.RelationSet; | ||
exports.Tick = tick_2.Tick; | ||
exports.FINGERPRINT = fingerprint_2.FINGERPRINT; | ||
exports.uuid = uuid_2.v4; | ||
exports.sqid = sqid_4.sqid; | ||
exports.uuid = uuid_1.v4; | ||
exports.sqid = sqid_2.sqid; | ||
exports.assign = assign_1.assign; | ||
exports.clone = assign_1.clone; | ||
exports.extend = assign_1.extend; | ||
exports.concat = concat_4.concat; | ||
exports.concat = concat_3.concat; | ||
}); | ||
@@ -1664,0 +1320,0 @@ define('spica', [ |
@@ -1,2 +0,2 @@ | ||
/*! spica v0.0.3 https://github.com/falsandtru/spica | (c) 2016, falsandtru | undefined License (undefined) */ | ||
define="function"==typeof define&&define.amd?define:function(){"use strict";var t="spica",e={};return function r(i,n,o){return o?void o.apply(this,n.map(function(t){switch(t){case"require":return"function"==typeof require?require:void 0;case"exports":return-1===i.indexOf("/")?e[i]="undefined"==typeof exports?self[i]=self[i]||{}:exports:e[i]=e.hasOwnProperty(i)?e[i]:{};default:return".d"===t.slice(-2)&&{}||e.hasOwnProperty(t)&&e[t]||"function"==typeof require&&require(t)||self[t]}})):void r(t,i,n)}}();var __extends=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)};define("src/lib/concat",["require","exports"],function(t,e){"use strict";function r(t,e){for(var r=0,i=e.length,n=t.length;i>r;++r)t[r+n]=e[r];return t}e.concat=r}),define("src/lib/observable",["require","exports","src/lib/concat"],function(t,e,r){"use strict";var i=function(){function t(){this.node_={parent:void 0,childrenMap:Object.create(null),childrenList:[],registers:[]}}return t.prototype.monitor=function(t,e,r){var i=this;return void 0===r&&(r=e),void this.throwTypeErrorIfInvalidSubscriber_(e,t),void this.seekNode_(t).registers.push([t,r,!0,e]),function(){return i.off(t,r)}},t.prototype.on=function(t,e,r){var i=this;return void 0===r&&(r=e),void this.throwTypeErrorIfInvalidSubscriber_(e,t),void this.seekNode_(t).registers.push([t,r,!1,function(t){return e(t)}]),function(){return i.off(t,r)}},t.prototype.off=function(t,e){switch(typeof e){case"function":return void void this.seekNode_(t).registers.some(function(t,r,i){var n=t[1];if(e!==n)return!1;switch(r){case 0:return!void i.shift();case i.length-1:return!void i.pop();default:return!void i.splice(r,1)}});case"undefined":var r=this.seekNode_(t);return r.childrenMap=Object.create(null),r.childrenList=[],void(r.registers=[]);default:throw this.throwTypeErrorIfInvalidSubscriber_(e,t)}},t.prototype.once=function(t,e){var r=this;return void this.throwTypeErrorIfInvalidSubscriber_(e,t),this.on(t,function(i){return void r.off(t,e),e(i)},e)},t.prototype.emit=function(t,e,r){void this.drain_(t,e,r)},t.prototype.reflect=function(t,e){var r;return void this.emit(t,e,function(t,e){return r=e}),r},t.prototype.drain_=function(t,e,r){var i=[];if(void this.refsBelow_(this.seekNode_(t)).reduce(function(t,n){var o=n[2],s=n[3];if(!o)try{var c=s(e);r&&(i[i.length]=c)}catch(u){void 0!==u&&null!==u&&void console.error(u+"")}},void 0),void this.refsAbove_(this.seekNode_(t)).reduce(function(t,r){var i=r[2],n=r[3];if(i)try{void n(e)}catch(o){void 0!==o&&null!==o&&void console.error(o)}},void 0),r)try{void r(e,i)}catch(n){void console.error(n)}},t.prototype.refs=function(t){return this.refsBelow_(this.seekNode_(t))},t.prototype.refsAbove_=function(t){var e=t.parent,i=t.registers;for(i=r.concat([],i);e;)i=r.concat(i,e.registers),e=e.parent;return i},t.prototype.refsBelow_=function(t){var e=t.childrenList,i=t.childrenMap,n=t.registers;n=r.concat([],n);for(var o=0;o<e.length;++o){var s=e[o],c=this.refsBelow_(i[s]);n=r.concat(n,c),0===c.length&&(void delete i[s],void e.splice(e.indexOf(s),1),void--o)}return n},t.prototype.seekNode_=function(t){for(var e=this.node_,r=0,i=t;r<i.length;r++){var n=i[r],o=e.childrenMap;o[n+""]||(void e.childrenList.push(n+""),e.childrenList=e.childrenList.sort(),o[n+""]={parent:e,childrenMap:Object.create(null),childrenList:[],registers:[]}),e=o[n+""]}return e},t.prototype.throwTypeErrorIfInvalidSubscriber_=function(t,e){switch(typeof t){case"function":return;default:throw new TypeError("spica: Observable: Invalid subscriber.\n "+t)}},t}();e.Observable=i}),define("src/lib/fingerprint",["require","exports"],function(t,e){"use strict";function r(){return n(o([s(window.navigator),s(window.screen),s((new Date).getTimezoneOffset())].join()))}function i(){return n(o([s(process)].join()))}function n(t){return t.split("").reduce(function(t,e,r){return(+e*r+t)%1e9||t-+e},0)}function o(t){return t.split("").map(function(t){return t.charCodeAt(0)}).join("")}function s(t,e){if(void 0===e&&(e=5),e>0&&t&&"object"==typeof t){var r="{";for(var i in t)r+='"'+i+'": '+s(t[i],e-1)+",";return r+="}"}return!t||t.toString?'"'+t+'"':'"'+Object.prototype.toString.call(t)+'"'}e.FINGERPRINT="object"==typeof window?r():i(),e.browser=r,e.server=i,e.hash=n,e.str2digit=o,e.stringify=s}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(t,e,r){"use strict";function i(){var t=s=s*Date.now()%1e15;if(16>t||t>1e15)throw new Error("spica: uuid: Invalid uuid dynamic seed.");for(var e="",r=0,i=o;r<i.length;r++){var n=i[r];if("x"===n||"y"===n){var c=Math.random()*t%16|0,u="x"==n?c:3&c|8;e+=u.toString(16)}else e+=n}return e.toLowerCase()}var n=r.FINGERPRINT*Date.now()%1e15;if(!n||"number"!=typeof n||100>n||n>1e15)throw new Error("spica: uuid: Invalid uuid static seed.\n "+r.FINGERPRINT);var o=Object.freeze("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split("")),s=n;e.v4=i}),define("src/lib/sqid",["require","exports"],function(t,e){"use strict";function r(t){return void 0===t?(1e15+ ++i+"").slice(1):(1e15+t+"").slice(1)}var i=0;e.sqid=r}),define("src/lib/dict/weakmap",["require","exports","src/lib/uuid","src/lib/sqid"],function(t,e,r,i){"use strict";function n(t){return t[o]?t[o]:Object.defineProperty(t,o,{value:Object.create(null),enumerable:!1,writable:!1,configurable:!0})[o]}var o=""+r.v4(),s=function(){function t(){this.id=+i.sqid()}return t.prototype.get=function(t){return(n(t)[this.id]||[])[0]},t.prototype.set=function(t,e){return(n(t)[this.id]=[e])[0]},t.prototype.has=function(t){return!!n(t)[this.id]},t.prototype["delete"]=function(t){void delete n(t)[this.id]},t}();e.WeakMap=s}),define("src/lib/dict/map",["require","exports","src/lib/dict/weakmap","src/lib/concat","src/lib/sqid"],function(t,e,r,i,n){"use strict";function o(t){return t instanceof Object==!1}e.isPrimitive=o;var s=function(){function t(){this.pstore=Object.create(null),this.ostore=Object.create(null),this.weakstore=new r.WeakMap,void this.reset_()}return t.prototype.stringify=function(t){switch(typeof t){case"undefined":return"0:"+t;case"boolean":return"1:"+t;case"number":return"2:"+(1e3+(""+t).length)+":"+t;case"string":return"3:"+(1e14+t.length)+":"+t;default:return o(t)?"8:"+t:"9:"+(this.weakstore.has(t)?this.weakstore.get(t)[0]:n.sqid())}},t.prototype.get=function(t){return o(t)?(this.pstore[this.stringify(t)]||[])[1]:(this.weakstore.get(t)||[])[1]},t.prototype.set=function(t,e){if(void this.reset_(),o(t))this.pstore[this.stringify(t)]=[t,e];else{var r=this.stringify(t);void this.weakstore.set(t,[r,e]),this.ostore[r]=[t,e,r]}return e},t.prototype.has=function(t){return o(t)?!!this.pstore[this.stringify(t)]:this.weakstore.has(t)},t.prototype["delete"]=function(t){void this.reset_(),o(t)?void delete this.pstore[this.stringify(t)]:(void delete this.ostore[(this.weakstore.get(t)||[])[0]],void this.weakstore["delete"](t))},t.prototype.clear=function(){var t=this;void this.reset_(),void Object.keys(this.ostore).forEach(function(e){return void t["delete"](t.ostore[e][0])}),this.weakstore=new r.WeakMap,this.pstore=Object.create(null),this.ostore=Object.create(null)},t.prototype.reset_=function(){this.size_=NaN,this.entries_=void 0},Object.defineProperty(t.prototype,"size",{get:function(){return this.size_>=0?this.size_:this.size_=Object.keys(this.pstore).length+Object.keys(this.ostore).length},enumerable:!0,configurable:!0}),t.prototype.entries=function(){var t=this;return this.entries_?this.entries_:this.entries_=i.concat(Object.keys(this.pstore).sort().map(function(e){return[t.pstore[e][0],t.pstore[e][1]]}),Object.keys(this.ostore).map(function(e){return[t.ostore[e][0],t.ostore[e][1]]}))},t}();e.Map=s}),define("src/lib/type",["require","exports"],function(t,e){"use strict";function r(t){return Object.prototype.toString.call(t).split(" ").pop().slice(0,-1)}e.type=r}),define("src/lib/dict/datamap",["require","exports","src/lib/dict/weakmap","src/lib/dict/map","src/lib/sqid","src/lib/type"],function(t,e,r,i,n,o){"use strict";var s=function(){function t(){this.store=Object.create(null),this.weakstore=new r.WeakMap,void this.reset_()}return t.prototype.stringify=function(t){switch(typeof t){case"undefined":return"0:"+t;case"boolean":return"1:"+t;case"number":return"2:"+(1e3+(""+t).length)+":"+t;case"string":return"3:"+(1e14+t.length)+":"+t;default:return i.isPrimitive(t)?"8:"+t:t instanceof Array?"9:[ "+this.stringifyArray(t)+" ]":"9:{ "+(this.weakstore.has(t)?this.weakstore.get(t):this.stringifyObject(t)||this.weakstore.set(t,n.sqid()))+" }"}},t.prototype.stringifyArray=function(t){for(var e="",r=0,i=t;r<i.length;r++){var n=i[r];e+=""+this.stringify(n)}return e},t.prototype.stringifyObject=function(t){if("Object"!==o.type(t))return"";for(var e=Object.keys(t),r="",i=0,n=e;i<n.length;i++){var s=n[i];r+=this.stringify(s)+": "+this.stringify(t[s])}return r||" "},t.prototype.get=function(t){return(this.store[this.stringify(t)]||[])[1]},t.prototype.set=function(t,e){return void this.reset_(),(this.store[this.stringify(t)]=[t,e])[1]},t.prototype.has=function(t){return!!this.store[this.stringify(t)]},t.prototype["delete"]=function(t){return void this.reset_(),void delete this.store[this.stringify(t)]},t.prototype.clear=function(){void this.reset_(),this.store=Object.create(null)},t.prototype.reset_=function(){this.size_=NaN,this.entries_=void 0},Object.defineProperty(t.prototype,"size",{get:function(){return this.size_>=0?this.size_:this.size_=Object.keys(this.store).length},enumerable:!0,configurable:!0}),t.prototype.entries=function(){var t=this;return this.entries_?this.entries_:this.entries_=Object.keys(this.store).sort().map(function(e){return t.store[e]})},t}();e.DataMap=s}),define("src/lib/dict/dataset",["require","exports","src/lib/dict/datamap"],function(t,e,r){"use strict";var i=function(){function t(t){this.replacer=t,this.store=new r.DataMap}return t.prototype.get=function(t){return this.store.get(t)},t.prototype.add=function(t,e){if(!this.has(t))return this.store.set(t,e);if(!this.replacer)throw new Error("spica: Set: Cannot overwrite value of set without replacer.");return this.store.set(t,this.replacer(this.get(t),e))},t.prototype.has=function(t){return this.store.has(t)},t.prototype["delete"]=function(t){return void this.store["delete"](t)},t.prototype.clear=function(){return void this.store.clear()},Object.defineProperty(t.prototype,"size",{get:function(){return this.store.size},enumerable:!0,configurable:!0}),t.prototype.entries=function(){return this.store.entries()},t}();e.DataSet=i}),define("src/lib/tick",["require","exports"],function(t,e){"use strict";var r;!function(t){function e(t){void n.push(t),void i()}function r(){void i(),void--o;for(var t=n.length;t-- >0;)void n.shift()()}function i(){if(0!==n.length)for(;o<s.length;)void setTimeout(r,s[o%s.length]),void++o}t.queue=e;var n=[],o=0,s=[0,4,10,20,25].reverse()}(r||(r={}));var i=Function("return typeof process === 'object' && typeof window !== 'object'")();e.Tick=i?Function("return fn => process.nextTick(fn)")():r.queue}),define("src/lib/thenable",["require","exports"],function(t,e){"use strict";function r(t){return!!t&&"object"==typeof t&&void 0!==t.then}e.isThenable=r}),define("src/lib/noop",["require","exports"],function(t,e){"use strict";function r(){}e.noop=r}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/dict/dataset","src/lib/tick","src/lib/thenable","src/lib/concat","src/lib/noop"],function(t,e,r,i,n,o,s,c){"use strict";function u(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(var r=0;r<t.length;++r)if(t[r]!==e[r])return!1;return!0}var a=function(){function t(e){var n=this,o=void 0===e?{}:e,s=o.name,u=void 0===s?"":s,a=o.dependencies,h=void 0===a?[]:a,p=o.retry,f=void 0===p?!1:p,d=o.timeout,l=void 0===d?0:d,v=o.destructor,y=void 0===v?c.noop:v;if(this.deps=new i.DataSet,this.events={exec:new r.Observable,fail:new r.Observable,loss:new r.Observable,exit:new r.Observable},this.procs=new r.Observable,this.alive=!0,this.registerable=!0,this.scheduled=!1,this.workerSharedResource={procs:this.procs,dependenciesStack:[]},this.queue=[],this.constructor===t)throw new Error("spica: Supervisor: Cannot instantiate abstract classes.");this.name=u,void h.reduce(function(t,e){var r=e[0],i=e[1];return void n.deps.add(r,i)},void 0),this.retry=f,this.timeout=l,this.destructor_=y,void++this.constructor.count}return t.prototype.destructor=function(t){for(void this.checkState(),this.alive=!1;this.queue.length>0;){var e=this.queue.shift(),r=e[0],i=e[1];void this.events.loss.emit(r,[r,void 0,i])}try{void this.destructor_(t)}catch(n){void console.error(n)}void--this.constructor.count,void Object.freeze(this)},t.prototype.schedule=function(){var t=this;this.alive&&(this.scheduled||(void n.Tick(function(e){t.alive&&(t.scheduled=!1,void t.drain())}),this.scheduled=!0))},t.prototype.register=function(t,e){if(void this.checkState(),!this.registerable)throw new Error("spica: Supervisor: Supervisor "+this.name+" cannot register process during the exiting.");return t=s.concat([],t),void this.schedule(),new l(this,this.workerSharedResource,t,e,this.deps.get(t)||[]).terminate},t.prototype.call=function(t,e,r,i){var n=this;void 0===r&&(r=this.timeout),void 0===i&&(i=c.noop),void this.checkState(),t=s.concat([],t),void this.queue.push([t,e,function(t,e){return void i(e,t)},r,Date.now()]),void this.schedule(),r>0!=!1&&void setTimeout(function(){return n.drain(t)},r)},t.prototype.cast=function(t,e,r){void 0===r&&(r=this.retry),void this.checkState();var i=this.procs.reflect(t,new f(e));return 0===i.length&&void this.events.fail.emit(t,[t,void 0,e]),i.length>0||!r?i:this.cast(t,e,!1)},t.prototype.refs=function(t){return void this.checkState(),this.procs.refs(t).map(function(t){var e=(t[0],t[1]),r=e(void 0);return[r.namespace,r.process,r.terminate]})},t.prototype.terminate=function(t,e){void this.checkState(),void 0===t&&(this.registerable=!1),void this.procs.emit(t||[],new d(e)),void this.procs.off(t||[]),void 0===t&&void this.destructor(e)},t.prototype.checkState=function(){if(!this.alive)throw new Error("spica: Supervisor: Supervisor "+this.name+" already exited.")},t.prototype.drain=function(t){void 0===t&&(t=[]);for(var e,r=Date.now(),i=function(i){var o=n.queue[i],s=o[0],c=o[1],u=o[2],a=o[3],h=o[4],p=t.every(function(t,e){return t===s[e]})?n.procs.reflect(s,new f(c)):[];if(0===p.length&&void n.events.fail.emit(s,[s,void 0,c]),0===p.length&&h+a>r)return e=i,"continue";if(0===i?void n.queue.shift():void n.queue.splice(i,1),void--i,0===p.length&&void n.events.loss.emit(s,[s,void 0,c]),!u)return e=i,"continue";try{void u(c,p)}catch(d){void console.error(d)}e=i},n=this,o=0;o<this.queue.length;++o){i(o);o=e}},t.count=0,t.procs=0,t}();e.Supervisor=a;var h=function(){function t(){}return t}(),p=function(t){function e(e){t.call(this),this.namespace=e}return __extends(e,t),e}(h),f=function(t){function e(e){t.call(this),this.data=e}return __extends(e,t),e}(h),d=function(t){function e(e){t.call(this),this.reason=e}return __extends(e,t),e}(h),l=function(){function t(e,r,i,n,o){var s=this;this.sv=e,this.sharedResource=r,this.namespace=i,this.process=n,this.dependencies=o,this.alive=!0,this.called=!1,this.concurrency=1,this.receive=function(e){return t.prototype.receive.call(s,e)},this.terminate=function(e){return t.prototype.terminate.call(s,e)},this.sharedResource.allRefsCache=void 0,void++this.sv.constructor.procs,void this.sharedResource.procs.on(i,this.receive)}return t.prototype.destructor=function(t){void this.checkState(),void this.sharedResource.procs.off(this.namespace,this.receive),this.alive=!1,void--this.sv.constructor.procs,this.sharedResource.allRefsCache=void 0,void Object.freeze(this),void this.sv.events.exit.emit(this.namespace,[this.namespace,this.process,t])},t.prototype.tryDependencyResolving=function(t){if(this.receive(new p(this.namespace)))return void(this.sharedResource.dependenciesStack=[]);throw void(this.sharedResource.dependenciesStack=[])},t.prototype.receive=function(t){var e=this;if(void this.checkState(),void 0===t)return this;if(t instanceof p){if(t.namespace.length!==this.namespace.length)return!1;if(0===this.concurrency)return!1;for(var r=0,i=this.sharedResource.dependenciesStack;r<i.length;r++){var n=i[r];if(u(this.namespace,n))return!0}return void this.sharedResource.dependenciesStack.push(this.namespace),this.dependencies.every(function(t){return(e.sharedResource.allRefsCache=e.sharedResource.allRefsCache||e.sharedResource.procs.refs([])).some(function(e){var r=e[0],i=e[1];return u(r,t)&&!!i(new p(t))})})}if(t instanceof f){if(0===this.concurrency)throw void 0;void this.tryDependencyResolving(t),this.called||(this.called=!0,void this.sv.events.exec.emit(this.namespace,[this.namespace,this.process]));try{void--this.concurrency;var s=(0,this.process)(t.data);return o.isThenable(s)?void s.then(function(t){void e.sv.schedule(),e.alive&&void++e.concurrency},function(t){void e.sv.schedule(),e.alive&&(void++e.concurrency,void e.terminate(t))}):void++this.concurrency,s}catch(c){throw void void this.terminate(c)}}if(t instanceof d)throw void void this.terminate(t.reason);throw new TypeError("spica: Supervisor: Invalid command: "+t)},t.prototype.terminate=function(t){void this.destructor(t)},t.prototype.checkState=function(){if(!this.alive)throw new Error("spica: Supervisor: Process "+this.namespace+"/"+this.process+" already exited.")},t}()}),define("src/lib/monad/lazy",["require","exports"],function(t,e){"use strict";var r=function(){function t(t){this.thunk=t}return t.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},t}();e.Lazy=r}),define("src/lib/monad/functor",["require","exports","src/lib/monad/lazy"],function(t,e,r){"use strict";var i=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e}(r.Lazy);e.Functor=i}),define("src/lib/monad/monad",["require","exports","src/lib/monad/functor"],function(t,e,r){"use strict";var i=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e}(r.Functor);e.Monad=i}),define("src/lib/monad/maybe.impl",["require","exports","src/lib/monad/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return t(i.extract());if(i instanceof o)return i;if(i instanceof e)return i.bind(t);throw new TypeError("spica: Maybe: Invalid monad value.\n "+i)})},e.prototype.fmap=function(t){return this.bind(function(e){return new n(t(e))})},e.prototype.extract=function(t){return this.evaluate().extract(t)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Maybe=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Just=n;var o=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.fmap=function(t){return this},e.prototype.extract=function(t){if(!t)throw void 0;return t()},e.prototype.assert=function(t){return this},e}(i);e.Nothing=o}),define("src/lib/monad/maybe",["require","exports","src/lib/monad/maybe.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Just(t)}t.Just=e,t.Nothing=new r.Nothing,t.Return=e}(i=e.Maybe||(e.Maybe={})),e.Just=i.Just,e.Nothing=i.Nothing,e.Return=e.Just}),define("src/lib/monad/either.impl",["require","exports","src/lib/monad/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return i;if(i instanceof o)return t(i.extract());if(i instanceof e)return i.bind(t);throw new TypeError("spica: Either: Invalid monad value.\n "+i)})},e.prototype.fmap=function(t){return this.bind(function(e){return new o(t(e))})},e.prototype.extract=function(t){return this.evaluate().extract(t)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Either=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.fmap=function(t){return this},e.prototype.extract=function(t){if(!t)throw this.val_;return t(this.val_)},e.prototype.assert=function(t){return this},e}(i);e.Left=n;var o=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Right=o}),define("src/lib/monad/either",["require","exports","src/lib/monad/either.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Left(t)}function i(t){return new r.Right(t)}t.Left=e,t.Right=i,t.Return=i}(i=e.Either||(e.Either={})),e.Left=i.Left,e.Right=i.Right,e.Return=i.Return}),define("src/lib/dict/attrmap",["require","exports","src/lib/dict/map","src/lib/dict/weakmap"],function(t,e,r,i){"use strict";var n=function(){function t(){this.store=new i.WeakMap}return t.prototype.get=function(t,e){return this.store.get(t)&&this.store.get(t).get(e)},t.prototype.set=function(t,e,i){return(this.store.get(t)||this.store.set(t,new r.Map)).set(e,i)},t.prototype.has=function(t,e){return this.store.has(t)&&this.store.get(t).has(e)},t.prototype["delete"]=function(t,e){return void 0===e?this.store["delete"](t):this.store.get(t)&&this.store.get(t)["delete"](e)},t}();e.AttrMap=n}),define("src/lib/dict/relationmap",["require","exports","src/lib/dict/weakmap"],function(t,e,r){"use strict";var i=function(){function t(){this.store=new r.WeakMap}return t.prototype.get=function(t,e){return this.store.get(t)&&this.store.get(t).get(e)},t.prototype.set=function(t,e,i){return(this.store.get(t)||this.store.set(t,new r.WeakMap)).set(e,i)},t.prototype.has=function(t,e){return this.store.has(t)&&this.store.get(t).has(e)},t.prototype["delete"]=function(t,e){return void 0===e?this.store["delete"](t):this.store.get(t)&&this.store.get(t)["delete"](e)},t}();e.RelationMap=i}),define("src/lib/dict/set",["require","exports","src/lib/dict/map"],function(t,e,r){"use strict";var i=function(){function t(t){this.replacer=t,this.store=new r.Map}return t.prototype.get=function(t){return this.store.get(t)},t.prototype.add=function(t,e){if(!this.has(t))return this.store.set(t,e);if(!this.replacer)throw new Error("spica: Set: Cannot overwrite value of set without replacer.");return this.store.set(t,this.replacer(this.get(t),e))},t.prototype.has=function(t){return this.store.has(t)},t.prototype["delete"]=function(t){return void this.store["delete"](t)},t.prototype.clear=function(){return void this.store.clear()},Object.defineProperty(t.prototype,"size",{get:function(){return this.store.size},enumerable:!0,configurable:!0}),t.prototype.entries=function(){return this.store.entries()},t}();e.Set=i}),define("src/lib/dict/weakset",["require","exports","src/lib/dict/weakmap"],function(t,e,r){"use strict";var i=function(){function t(t){this.replacer=t,this.store=new r.WeakMap}return t.prototype.get=function(t){return this.store.get(t)},t.prototype.add=function(t,e){if(!this.has(t))return this.store.set(t,e);if(!this.replacer)throw new Error("spica: WeakSet: Cannot overwrite value of set without replacer.");return this.store.set(t,this.replacer(this.get(t),e))},t.prototype.has=function(t){return this.store.has(t)},t.prototype["delete"]=function(t){void this.store["delete"](t)},t}();e.WeakSet=i}),define("src/lib/dict/attrset",["require","exports","src/lib/dict/set","src/lib/dict/weakmap"],function(t,e,r,i){"use strict";var n=function(){function t(t){this.replacer=t,this.store=new i.WeakMap}return t.prototype.get=function(t,e){return this.store.get(t)&&this.store.get(t).get(e)},t.prototype.add=function(t,e,i){return(this.store.get(t)||this.store.set(t,new r.Set(this.replacer))).add(e,i)},t.prototype.has=function(t,e){return this.store.has(t)&&this.store.get(t).has(e)},t.prototype["delete"]=function(t,e){return void 0===e?this.store["delete"](t):this.store.get(t)&&this.store.get(t)["delete"](e)},t}();e.AttrSet=n}),define("src/lib/dict/relationset",["require","exports","src/lib/dict/weakset","src/lib/dict/weakmap"],function(t,e,r,i){"use strict";var n=function(){function t(t){this.replacer=t,this.store=new i.WeakMap}return t.prototype.get=function(t,e){return this.store.get(t)&&this.store.get(t).get(e)},t.prototype.add=function(t,e,i){return(this.store.get(t)||this.store.set(t,new r.WeakSet(this.replacer))).add(e,i)},t.prototype.has=function(t,e){return this.store.has(t)&&this.store.get(t).has(e)},t.prototype["delete"]=function(t,e){return void 0===e?this.store["delete"](t):this.store.get(t)&&this.store.get(t)["delete"](e)},t}();e.RelationSet=n}),define("src/lib/assign",["require","exports","src/lib/type"],function(t,e,r){"use strict";function i(t){return function(e){for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];if(void 0===e||null===e)throw new TypeError("spica: assign: Cannot walk on "+e+".");for(var n=0,o=r;n<o.length;n++){var s=o[n];if(void 0!==s&&null!==s)for(var c=0,u=Object.keys(Object(s));c<u.length;c++){var a=u[c],h=Object.getOwnPropertyDescriptor(Object(s),a);void 0!==h&&h.enumerable&&void t(a,Object(e),Object(s))}}return Object(e)}}e.assign=i(function(t,e,r){return e[t]=r[t]}),e.clone=i(function(t,i,n){switch(r.type(n[t])){case"Array":return i[t]=e.clone([],n[t]);case"Function":case"Object":return i[t]=e.clone({},n[t]);default:return i[t]=n[t]}}),e.extend=i(function(t,i,n){switch(r.type(n[t])){case"Array":return i[t]=e.extend([],n[t]);case"Function":case"Object":switch(r.type(i[t])){case"Function":case"Object":return i[t]=e.extend(i[t],n[t]);default:return i[t]=e.extend({},n[t])}default:return i[t]=n[t]}})}),define("src/export",["require","exports","src/lib/supervisor","src/lib/observable","src/lib/monad/maybe","src/lib/monad/either","src/lib/dict/map","src/lib/dict/datamap","src/lib/dict/weakmap","src/lib/dict/attrmap","src/lib/dict/relationmap","src/lib/dict/set","src/lib/dict/dataset","src/lib/dict/weakset","src/lib/dict/attrset","src/lib/dict/relationset","src/lib/tick","src/lib/fingerprint","src/lib/uuid","src/lib/sqid","src/lib/assign","src/lib/concat"],function(t,e,r,i,n,o,s,c,u,a,h,p,f,d,l,v,y,b,g,w,m,x){"use strict";e.Supervisor=r.Supervisor,e.Observable=i.Observable,e.Maybe=n.Maybe,e.Just=n.Just,e.Nothing=n.Nothing,e.Either=o.Either,e.Left=o.Left,e.Right=o.Right,e.Map=s.Map,e.DataMap=c.DataMap,e.WeakMap=u.WeakMap,e.AttrMap=a.AttrMap,e.RelationMap=h.RelationMap,e.Set=p.Set,e.DataSet=f.DataSet,e.WeakSet=d.WeakSet,e.AttrSet=l.AttrSet,e.RelationSet=v.RelationSet,e.Tick=y.Tick,e.FINGERPRINT=b.FINGERPRINT,e.uuid=g.v4,e.sqid=w.sqid,e.assign=m.assign,e.clone=m.clone,e.extend=m.extend,e.concat=x.concat}),define("spica",["require","exports","src/export"],function(t,e,r){"use strict";function i(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}i(r)}); | ||
/*! spica v0.0.4 https://github.com/falsandtru/spica | (c) 2016, falsandtru | undefined License (undefined) */ | ||
define="function"==typeof define&&define.amd?define:function(){"use strict";var t="spica",e={};return function r(i,n,o){return o?void o.apply(this,n.map(function(t){switch(t){case"require":return"function"==typeof require?require:void 0;case"exports":return-1===i.indexOf("/")?e[i]="undefined"==typeof exports?self[i]=self[i]||{}:exports:e[i]=e.hasOwnProperty(i)?e[i]:{};default:return".d"===t.slice(-2)&&{}||e.hasOwnProperty(t)&&e[t]||"function"==typeof require&&require(t)||self[t]}})):void r(t,i,n)}}();var __extends=this&&this.__extends||function(t,e){function r(){this.constructor=t}for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i]);t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)};define("src/lib/concat",["require","exports"],function(t,e){"use strict";function r(t,e){for(var r=0,i=e.length,n=t.length;i>r;++r)t[r+n]=e[r];return t}e.concat=r}),define("src/lib/observable",["require","exports","src/lib/concat"],function(t,e,r){"use strict";var i=function(){function t(){this.node_={parent:void 0,childrenMap:Object.create(null),childrenList:[],registers:[]}}return t.prototype.monitor=function(t,e,r){var i=this;return void 0===r&&(r=e),void this.throwTypeErrorIfInvalidSubscriber_(e,t),void this.seekNode_(t).registers.push([t,r,!0,e]),function(){return i.off(t,r)}},t.prototype.on=function(t,e,r){var i=this;return void 0===r&&(r=e),void this.throwTypeErrorIfInvalidSubscriber_(e,t),void this.seekNode_(t).registers.push([t,r,!1,function(t){return e(t)}]),function(){return i.off(t,r)}},t.prototype.off=function(t,e){switch(typeof e){case"function":return void void this.seekNode_(t).registers.some(function(t,r,i){var n=t[1];if(e!==n)return!1;switch(r){case 0:return!void i.shift();case i.length-1:return!void i.pop();default:return!void i.splice(r,1)}});case"undefined":var r=this.seekNode_(t);return r.childrenMap=Object.create(null),r.childrenList=[],void(r.registers=[]);default:throw this.throwTypeErrorIfInvalidSubscriber_(e,t)}},t.prototype.once=function(t,e){var r=this;return void this.throwTypeErrorIfInvalidSubscriber_(e,t),this.on(t,function(i){return void r.off(t,e),e(i)},e)},t.prototype.emit=function(t,e,r){void this.drain_(t,e,r)},t.prototype.reflect=function(t,e){var r;return void this.emit(t,e,function(t,e){return r=e}),r},t.prototype.drain_=function(t,e,r){var i=[];if(void this.refsBelow_(this.seekNode_(t)).reduce(function(t,n){var o=n[2],s=n[3];if(!o)try{var c=s(e);r&&(i[i.length]=c)}catch(u){void 0!==u&&null!==u&&void console.error(u+"")}},void 0),void this.refsAbove_(this.seekNode_(t)).reduce(function(t,r){var i=r[2],n=r[3];if(i)try{void n(e)}catch(o){void 0!==o&&null!==o&&void console.error(o)}},void 0),r)try{void r(e,i)}catch(n){void console.error(n)}},t.prototype.refs=function(t){return this.refsBelow_(this.seekNode_(t))},t.prototype.refsAbove_=function(t){var e=t.parent,i=t.registers;for(i=r.concat([],i);e;)i=r.concat(i,e.registers),e=e.parent;return i},t.prototype.refsBelow_=function(t){var e=t.childrenList,i=t.childrenMap,n=t.registers;n=r.concat([],n);for(var o=0;o<e.length;++o){var s=e[o],c=this.refsBelow_(i[s]);n=r.concat(n,c),0===c.length&&(void delete i[s],void e.splice(e.indexOf(s),1),void--o)}return n},t.prototype.seekNode_=function(t){for(var e=this.node_,r=0,i=t;r<i.length;r++){var n=i[r],o=e.childrenMap;o[n+""]||(void e.childrenList.push(n+""),e.childrenList=e.childrenList.sort(),o[n+""]={parent:e,childrenMap:Object.create(null),childrenList:[],registers:[]}),e=o[n+""]}return e},t.prototype.throwTypeErrorIfInvalidSubscriber_=function(t,e){switch(typeof t){case"function":return;default:throw new TypeError("Spica: Observable: Invalid subscriber.\n "+t)}},t}();e.Observable=i}),define("src/lib/sqid",["require","exports"],function(t,e){"use strict";function r(t){return void 0===t?(1e15+ ++i+"").slice(1):(1e15+t+"").slice(1)}var i=0;e.sqid=r}),define("src/lib/type",["require","exports"],function(t,e){"use strict";function r(t){return Object.prototype.toString.call(t).split(" ").pop().slice(0,-1)}e.type=r}),define("src/lib/collection/datamap",["require","exports","src/lib/sqid","src/lib/type"],function(t,e,r,i){"use strict";function n(t){return t instanceof Object==!1}var o=function(){function t(){this.store=new Map,this.weakstore=new WeakMap}return t.prototype.stringify=function(t){switch(typeof t){case"undefined":return"0:"+t;case"boolean":return"1:"+t;case"number":return"2:"+(1e3+(""+t).length)+":"+t;case"string":return"3:"+(1e14+t.length)+":"+t;default:return n(t)?"8:"+t:t instanceof Array?"9:[ "+this.stringifyArray(t)+" ]":"9:{ "+(this.weakstore.has(t)?this.weakstore.get(t):this.stringifyObject(t)||this.weakstore.set(t,r.sqid()))+" }"}},t.prototype.stringifyArray=function(t){for(var e="",r=0,i=t;r<i.length;r++){var n=i[r];e+=""+this.stringify(n)}return e},t.prototype.stringifyObject=function(t){if("Object"!==i.type(t))return"";for(var e=Object.keys(t),r="",n=0,o=e;n<o.length;n++){var s=o[n];r+=this.stringify(s)+": "+this.stringify(t[s])}return r||" "},t.prototype.get=function(t){return(this.store.get(this.stringify(t))||[])[1]},t.prototype.set=function(t,e){return void this.store.set(this.stringify(t),[t,e]),this},t.prototype.has=function(t){return this.store.has(this.stringify(t))},t.prototype["delete"]=function(t){return this.store["delete"](this.stringify(t))},t.prototype.clear=function(){return this.store.clear()},Object.defineProperty(t.prototype,"size",{get:function(){return this.store.size},enumerable:!0,configurable:!0}),t}();e.DataMap=o}),define("src/lib/tick",["require","exports"],function(t,e){"use strict";var r;!function(t){function e(t){void n.push(t),void i()}function r(){void i(),void--o;for(var t=n.length;t-- >0;)void n.shift()()}function i(){if(0!==n.length)for(;o<s.length;)void setTimeout(r,s[o%s.length]),void++o}t.queue=e;var n=[],o=0,s=[0,4,10,20,25].reverse()}(r||(r={}));var i=Function("return typeof process === 'object' && typeof window !== 'object'")();e.Tick=i?Function("return fn => process.nextTick(fn)")():r.queue}),define("src/lib/thenable",["require","exports"],function(t,e){"use strict";function r(t){return!!t&&"object"==typeof t&&void 0!==t.then}e.isThenable=r}),define("src/lib/noop",["require","exports"],function(t,e){"use strict";function r(){}e.noop=r}),define("src/lib/supervisor",["require","exports","src/lib/observable","src/lib/collection/datamap","src/lib/tick","src/lib/thenable","src/lib/concat","src/lib/noop"],function(t,e,r,i,n,o,s,c){"use strict";function u(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(var r=0;r<t.length;++r)if(t[r]!==e[r])return!1;return!0}var a=function(){function t(e){var n=this,o=void 0===e?{}:e,s=o.name,u=void 0===s?"":s,a=o.dependencies,h=void 0===a?[]:a,f=o.retry,d=void 0===f?!1:f,p=o.timeout,l=void 0===p?0:p,v=o.destructor,y=void 0===v?c.noop:v;if(this.deps=new i.DataMap,this.events={exec:new r.Observable,fail:new r.Observable,loss:new r.Observable,exit:new r.Observable},this.procs=new r.Observable,this.alive=!0,this.registerable=!0,this.scheduled=!1,this.workerSharedResource={procs:this.procs,dependenciesStack:[]},this.queue=[],this.constructor===t)throw new Error("Spica: Supervisor: Cannot instantiate abstract classes.");this.name=u,void h.reduce(function(t,e){var r=e[0],i=e[1];return void n.deps.set(r,i)},void 0),this.retry=d,this.timeout=l,this.destructor_=y,void++this.constructor.count}return t.prototype.destructor=function(t){for(void this.checkState(),this.alive=!1;this.queue.length>0;){var e=this.queue.shift(),r=e[0],i=e[1];void this.events.loss.emit(r,[r,void 0,i])}try{void this.destructor_(t)}catch(n){void console.error(n)}void--this.constructor.count,void Object.freeze(this)},t.prototype.schedule=function(){var t=this;this.alive&&(this.scheduled||(void n.Tick(function(e){t.alive&&(t.scheduled=!1,void t.drain())}),this.scheduled=!0))},t.prototype.register=function(t,e){if(void this.checkState(),!this.registerable)throw new Error("Spica: Supervisor: Supervisor "+this.name+" cannot register process during the exiting.");return t=s.concat([],t),void this.schedule(),new f(this,this.workerSharedResource,t,e,this.deps.get(t)||[]).terminate},t.prototype.call=function(t,e,r,i){var n=this;void 0===r&&(r=this.timeout),void 0===i&&(i=c.noop),void this.checkState(),t=s.concat([],t),void this.queue.push([t,e,function(t,e){return void i(e,t)},r,Date.now()]),void this.schedule(),r>0!=!1&&void setTimeout(function(){return n.drain(t)},r)},t.prototype.cast=function(t,e,r){void 0===r&&(r=this.retry),void this.checkState();var i=this.procs.reflect(t,new h.Call(e));return 0===i.length&&void this.events.fail.emit(t,[t,void 0,e]),i.length>0||!r?i:this.cast(t,e,!1)},t.prototype.refs=function(t){return void this.checkState(),this.procs.refs(t).map(function(t){var e=(t[0],t[1]),r=e(void 0);return[r.namespace,r.process,r.terminate]})},t.prototype.terminate=function(t,e){void this.checkState(),void 0===t&&(this.registerable=!1),void this.procs.emit(t||[],new h.Exit(e)),void this.procs.off(t||[]),void 0===t&&void this.destructor(e)},t.prototype.checkState=function(){if(!this.alive)throw new Error("Spica: Supervisor: Supervisor "+this.name+" already exited.")},t.prototype.drain=function(t){void 0===t&&(t=[]);for(var e,r=Date.now(),i=function(i){var o=n.queue[i],s=o[0],c=o[1],u=o[2],a=o[3],f=o[4],d=t.every(function(t,e){return t===s[e]})?n.procs.reflect(s,new h.Call(c)):[];if(0===d.length&&void n.events.fail.emit(s,[s,void 0,c]),0===d.length&&f+a>r)return e=i,"continue";if(0===i?void n.queue.shift():void n.queue.splice(i,1),void--i,0===d.length&&void n.events.loss.emit(s,[s,void 0,c]),!u)return e=i,"continue";try{void u(c,d)}catch(p){void console.error(p)}e=i},n=this,o=0;o<this.queue.length;++o){i(o);o=e}},t.count=0,t.procs=0,t}();e.Supervisor=a;var h;!function(t){var e=function(){function t(){}return t}(),r=function(t){function e(e){t.call(this),this.namespace=e}return __extends(e,t),e}(e);t.Deps=r;var i=function(t){function e(e){t.call(this),this.data=e}return __extends(e,t),e}(e);t.Call=i;var n=function(t){function e(e){t.call(this),this.reason=e}return __extends(e,t),e}(e);t.Exit=n}(h||(h={}));var f=function(){function t(e,r,i,n,o){var s=this;this.sv=e,this.sharedResource=r,this.namespace=i,this.process=n,this.dependencies=o,this.alive=!0,this.called=!1,this.concurrency=1,this.receive=function(e){return t.prototype.receive.call(s,e)},this.terminate=function(e){return t.prototype.terminate.call(s,e)},this.sharedResource.allRefsCache=void 0,void++this.sv.constructor.procs,void this.sharedResource.procs.on(i,this.receive)}return t.prototype.destructor=function(t){void this.checkState(),void this.sharedResource.procs.off(this.namespace,this.receive),this.alive=!1,void--this.sv.constructor.procs,this.sharedResource.allRefsCache=void 0,void Object.freeze(this),void this.sv.events.exit.emit(this.namespace,[this.namespace,this.process,t])},t.prototype.tryDependencyResolving=function(t){if(this.receive(new h.Deps(this.namespace)))return void(this.sharedResource.dependenciesStack=[]);throw void(this.sharedResource.dependenciesStack=[])},t.prototype.receive=function(t){var e=this;if(void this.checkState(),void 0===t)return this;if(t instanceof h.Deps){if(t.namespace.length!==this.namespace.length)return!1;if(0===this.concurrency)return!1;for(var r=0,i=this.sharedResource.dependenciesStack;r<i.length;r++){var n=i[r];if(u(this.namespace,n))return!0}return void this.sharedResource.dependenciesStack.push(this.namespace),this.dependencies.every(function(t){return(e.sharedResource.allRefsCache=e.sharedResource.allRefsCache||e.sharedResource.procs.refs([])).some(function(e){var r=e[0],i=e[1];return u(r,t)&&!!i(new h.Deps(t))})})}if(t instanceof h.Call){if(0===this.concurrency)throw void 0;void this.tryDependencyResolving(t),this.called||(this.called=!0,void this.sv.events.exec.emit(this.namespace,[this.namespace,this.process]));try{void--this.concurrency;var s=(0,this.process)(t.data);return o.isThenable(s)?void s.then(function(t){void e.sv.schedule(),e.alive&&void++e.concurrency},function(t){void e.sv.schedule(),e.alive&&(void++e.concurrency,void e.terminate(t))}):void++this.concurrency,s}catch(c){throw void void this.terminate(c)}}if(t instanceof h.Exit)throw void void this.terminate(t.reason);throw new TypeError("Spica: Supervisor: Invalid command: "+t)},t.prototype.terminate=function(t){void this.destructor(t)},t.prototype.checkState=function(){if(!this.alive)throw new Error("Spica: Supervisor: Process "+this.namespace+"/"+this.process+" already exited.")},t}()}),define("src/lib/monad/lazy",["require","exports"],function(t,e){"use strict";var r=function(){function t(t){this.thunk=t}return t.prototype.evaluate=function(){return this.memory_=this.memory_||this.thunk()},t}();e.Lazy=r}),define("src/lib/monad/functor",["require","exports","src/lib/monad/lazy"],function(t,e,r){"use strict";var i=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e}(r.Lazy);e.Functor=i}),define("src/lib/monad/monad",["require","exports","src/lib/monad/functor"],function(t,e,r){"use strict";var i=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e}(r.Functor);e.Monad=i}),define("src/lib/monad/maybe.impl",["require","exports","src/lib/monad/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return t(i.extract());if(i instanceof o)return i;if(i instanceof e)return i.bind(t);throw new TypeError("Spica: Maybe: Invalid monad value.\n "+i)})},e.prototype.fmap=function(t){return this.bind(function(e){return new n(t(e))})},e.prototype.extract=function(t){return this.evaluate().extract(t)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Maybe=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Just=n;var o=function(t){function e(){t.apply(this,arguments)}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.fmap=function(t){return this},e.prototype.extract=function(t){if(!t)throw void 0;return t()},e.prototype.assert=function(t){return this},e}(i);e.Nothing=o}),define("src/lib/monad/maybe",["require","exports","src/lib/monad/maybe.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Just(t)}t.Just=e,t.Nothing=new r.Nothing,t.Return=e}(i=e.Maybe||(e.Maybe={})),e.Just=i.Just,e.Nothing=i.Nothing,e.Return=e.Just}),define("src/lib/monad/either.impl",["require","exports","src/lib/monad/monad"],function(t,e,r){"use strict";var i=function(t){function e(e){t.call(this,e),this.thunk=e}return __extends(e,t),e.prototype.bind=function(t){var r=this;return new e(function(){var i=r.evaluate();if(i instanceof n)return i;if(i instanceof o)return t(i.extract());if(i instanceof e)return i.bind(t);throw new TypeError("Spica: Either: Invalid monad value.\n "+i)})},e.prototype.fmap=function(t){return this.bind(function(e){return new o(t(e))})},e.prototype.extract=function(t){return this.evaluate().extract(t)},e.prototype.assert=function(t){return this},e}(r.Monad);e.Either=i;var n=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){return this},e.prototype.fmap=function(t){return this},e.prototype.extract=function(t){if(!t)throw this.val_;return t(this.val_)},e.prototype.assert=function(t){return this},e}(i);e.Left=n;var o=function(t){function e(e){t.call(this),this.val_=e}return __extends(e,t),e.prototype.bind=function(t){var e=this;return new i(function(){return e}).bind(t)},e.prototype.extract=function(t){return this.val_},e.prototype.assert=function(t){return this},e}(i);e.Right=o}),define("src/lib/monad/either",["require","exports","src/lib/monad/either.impl"],function(t,e,r){"use strict";var i;!function(t){function e(t){return new r.Left(t)}function i(t){return new r.Right(t)}t.Left=e,t.Right=i,t.Return=i}(i=e.Either||(e.Either={})),e.Left=i.Left,e.Right=i.Right,e.Return=i.Return}),define("src/lib/collection/attrmap",["require","exports"],function(t,e){"use strict";var r=function(){function t(){this.store=new WeakMap}return t.prototype.get=function(t,e){return this.store.get(t)&&this.store.get(t).get(e)},t.prototype.set=function(t,e,r){var i=this.store.has(t)?this.store.get(t):this.store.set(t,new Map).get(t);return void i.set(e,r),this},t.prototype.has=function(t,e){return this.store.has(t)&&this.store.get(t).has(e)},t.prototype["delete"]=function(t,e){return void 0===e?this.store["delete"](t):this.store.has(t)?this.store.get(t)["delete"](e):!1},t}();e.AttrMap=r}),define("src/lib/collection/relationmap",["require","exports"],function(t,e){"use strict";var r=function(){function t(){this.store=new WeakMap}return t.prototype.get=function(t,e){return this.store.get(t)&&this.store.get(t).get(e)},t.prototype.set=function(t,e,r){var i=this.store.has(t)?this.store.get(t):this.store.set(t,new WeakMap).get(t);return void i.set(e,r),this},t.prototype.has=function(t,e){return this.store.has(t)&&this.store.get(t).has(e)},t.prototype["delete"]=function(t,e){return void 0===e?this.store["delete"](t):this.store.has(t)?this.store.get(t)["delete"](e):!1},t}();e.RelationMap=r}),define("src/lib/fingerprint",["require","exports"],function(t,e){"use strict";function r(){return n(o([s(window.navigator),s(window.screen),s((new Date).getTimezoneOffset())].join()))}function i(){return n(o([s(process)].join()))}function n(t){return t.split("").reduce(function(t,e,r){return(+e*r+t)%1e9||t-+e},0)}function o(t){return t.split("").map(function(t){return t.charCodeAt(0)}).join("")}function s(t,e){if(void 0===e&&(e=5),e>0&&t&&"object"==typeof t){var r="{";for(var i in t)r+='"'+i+'": '+s(t[i],e-1)+",";return r+="}"}return!t||t.toString?'"'+t+'"':'"'+Object.prototype.toString.call(t)+'"'}e.FINGERPRINT="object"==typeof window?r():i(),e.browser=r,e.server=i,e.hash=n,e.str2digit=o,e.stringify=s}),define("src/lib/uuid",["require","exports","src/lib/fingerprint"],function(t,e,r){"use strict";function i(){var t=s=s*Date.now()%1e15;if(16>t||t>1e15)throw new Error("Spica: uuid: Invalid uuid dynamic seed.");for(var e="",r=0,i=o;r<i.length;r++){var n=i[r];if("x"===n||"y"===n){var c=Math.random()*t%16|0,u="x"==n?c:3&c|8;e+=u.toString(16)}else e+=n}return e.toLowerCase()}var n=r.FINGERPRINT*Date.now()%1e15;if(!n||"number"!=typeof n||100>n||n>1e15)throw new Error("Spica: uuid: Invalid uuid static seed.\n "+r.FINGERPRINT);var o=Object.freeze("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split("")),s=n;e.v4=i}),define("src/lib/assign",["require","exports","src/lib/type"],function(t,e,r){"use strict";function i(t){return function(e){for(var r=[],i=1;i<arguments.length;i++)r[i-1]=arguments[i];if(void 0===e||null===e)throw new TypeError("Spica: assign: Cannot walk on "+e+".");for(var n=0,o=r;n<o.length;n++){var s=o[n];if(void 0!==s&&null!==s)for(var c=0,u=Object.keys(Object(s));c<u.length;c++){var a=u[c],h=Object.getOwnPropertyDescriptor(Object(s),a);void 0!==h&&h.enumerable&&void t(a,Object(e),Object(s))}}return Object(e)}}e.assign=i(function(t,e,r){return e[t]=r[t]}),e.clone=i(function(t,i,n){switch(r.type(n[t])){case"Array":return i[t]=e.clone([],n[t]);case"Function":case"Object":return i[t]=e.clone({},n[t]);default:return i[t]=n[t]}}),e.extend=i(function(t,i,n){switch(r.type(n[t])){case"Array":return i[t]=e.extend([],n[t]);case"Function":case"Object":switch(r.type(i[t])){case"Function":case"Object":return i[t]=e.extend(i[t],n[t]);default:return i[t]=e.extend({},n[t])}default:return i[t]=n[t]}})}),define("src/export",["require","exports","src/lib/supervisor","src/lib/observable","src/lib/monad/maybe","src/lib/monad/either","src/lib/collection/datamap","src/lib/collection/attrmap","src/lib/collection/relationmap","src/lib/tick","src/lib/fingerprint","src/lib/uuid","src/lib/sqid","src/lib/assign","src/lib/concat"],function(t,e,r,i,n,o,s,c,u,a,h,f,d,p,l){"use strict";e.Supervisor=r.Supervisor,e.Observable=i.Observable,e.Maybe=n.Maybe,e.Just=n.Just,e.Nothing=n.Nothing,e.Either=o.Either,e.Left=o.Left,e.Right=o.Right,e.DataMap=s.DataMap,e.AttrMap=c.AttrMap,e.RelationMap=u.RelationMap,e.Tick=a.Tick,e.FINGERPRINT=h.FINGERPRINT,e.uuid=f.v4,e.sqid=d.sqid,e.assign=p.assign,e.clone=p.clone,e.extend=p.extend,e.concat=l.concat}),define("spica",["require","exports","src/export"],function(t,e,r){"use strict";function i(t){for(var r in t)e.hasOwnProperty(r)||(e[r]=t[r])}i(r)}); |
{ | ||
"name": "spica", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Utils.", | ||
@@ -40,3 +40,3 @@ "private": false, | ||
"gulp-rename": "^1.2.2", | ||
"gulp-typescript": "2.13.5", | ||
"gulp-typescript": "2.13.6", | ||
"gulp-uglify": "^1.5.3", | ||
@@ -43,0 +43,0 @@ "gulp-unassert": "^1.0.0", |
@@ -5,12 +5,5 @@ export {Supervisor} from './lib/supervisor'; | ||
export {Either, Left, Right} from './lib/monad/either'; | ||
export {Map} from './lib/dict/map'; | ||
export {DataMap} from './lib/dict/datamap'; | ||
export {WeakMap} from './lib/dict/weakmap'; | ||
export {AttrMap} from './lib/dict/attrmap'; | ||
export {RelationMap} from './lib/dict/relationmap'; | ||
export {Set} from './lib/dict/set'; | ||
export {DataSet} from './lib/dict/dataset'; | ||
export {WeakSet} from './lib/dict/weakset'; | ||
export {AttrSet} from './lib/dict/attrset'; | ||
export {RelationSet} from './lib/dict/relationset'; | ||
export {DataMap} from './lib/collection/datamap'; | ||
export {AttrMap} from './lib/collection/attrmap'; | ||
export {RelationMap} from './lib/collection/relationmap'; | ||
export {Tick} from './lib/tick'; | ||
@@ -17,0 +10,0 @@ export {FINGERPRINT} from './lib/fingerprint'; |
@@ -48,3 +48,3 @@ import {type} from './type'; | ||
if (target === undefined || target === null) { | ||
throw new TypeError(`spica: assign: Cannot walk on ${target}.`); | ||
throw new TypeError(`Spica: assign: Cannot walk on ${target}.`); | ||
} | ||
@@ -51,0 +51,0 @@ |
@@ -22,3 +22,3 @@ import {Monad} from './monad'; | ||
} | ||
throw new TypeError(`spica: Either: Invalid monad value.\n\t${m}`); | ||
throw new TypeError(`Spica: Either: Invalid monad value.\n\t${m}`); | ||
}); | ||
@@ -25,0 +25,0 @@ } |
@@ -22,3 +22,3 @@ import {Monad} from './monad'; | ||
} | ||
throw new TypeError(`spica: Maybe: Invalid monad value.\n\t${m}`); | ||
throw new TypeError(`Spica: Maybe: Invalid monad value.\n\t${m}`); | ||
}); | ||
@@ -25,0 +25,0 @@ } |
@@ -180,3 +180,3 @@ import {Observer, Publisher} from 'spica'; | ||
default: { | ||
throw new TypeError(`spica: Observable: Invalid subscriber.\n\t${types, subscriber}`); | ||
throw new TypeError(`Spica: Observable: Invalid subscriber.\n\t${types, subscriber}`); | ||
} | ||
@@ -183,0 +183,0 @@ } |
import {Supervisor as ISupervisor, SupervisorSettings} from 'spica'; | ||
import {Observable} from './observable'; | ||
import {DataSet} from './dict/dataset'; | ||
import {DataMap} from './collection/datamap'; | ||
import {Tick} from './tick'; | ||
@@ -36,5 +36,5 @@ import {isThenable} from './thenable'; | ||
}: SupervisorSettings<T> = {}) { | ||
if (this.constructor === Supervisor) throw new Error('spica: Supervisor: Cannot instantiate abstract classes.'); | ||
if (this.constructor === Supervisor) throw new Error('Spica: Supervisor: Cannot instantiate abstract classes.'); | ||
this.name = name; | ||
void dependencies.reduce((_, [namespace, deps]) => void this.deps.add(namespace, deps), void 0); | ||
void dependencies.reduce((_, [namespace, deps]) => void this.deps.set(namespace, deps), void 0); | ||
this.retry = retry; | ||
@@ -65,3 +65,3 @@ this.timeout = timeout; | ||
public name: string; | ||
private deps: DataSet<T, T[]> = new DataSet<T, T[]>(); | ||
private deps: DataMap<T, T[]> = new DataMap<T, T[]>(); | ||
private retry: boolean; | ||
@@ -96,3 +96,3 @@ private timeout: number; | ||
void this.checkState(); | ||
if (!this.registerable) throw new Error(`spica: Supervisor: Supervisor ${this.name} cannot register process during the exiting.`); | ||
if (!this.registerable) throw new Error(`Spica: Supervisor: Supervisor ${this.name} cannot register process during the exiting.`); | ||
namespace = <T>concat([], namespace); | ||
@@ -112,3 +112,3 @@ void this.schedule(); | ||
void this.checkState(); | ||
const results = this.procs.reflect(namespace, new WorkerCommand_$Call(data)); | ||
const results = this.procs.reflect(namespace, new WorkerCommand.Call(data)); | ||
if (results.length === 0) { | ||
@@ -138,3 +138,3 @@ void this.events.fail.emit(namespace, [namespace, void 0, data]); | ||
void this.procs | ||
.emit(namespace || <T>[], new WorkerCommand_$Exit(reason)); | ||
.emit(namespace || <T>[], new WorkerCommand.Exit(reason)); | ||
void this.procs | ||
@@ -147,3 +147,3 @@ .off(namespace || <T>[]); | ||
private checkState(): void { | ||
if (!this.alive) throw new Error(`spica: Supervisor: Supervisor ${this.name} already exited.`); | ||
if (!this.alive) throw new Error(`Spica: Supervisor: Supervisor ${this.name} already exited.`); | ||
} | ||
@@ -156,3 +156,3 @@ private queue: [T, D, (data: D, results: R[]) => any, number, number][] = []; | ||
const results = target.every((n, i) => n === namespace[i]) | ||
? this.procs.reflect(namespace, new WorkerCommand_$Call(data)) | ||
? this.procs.reflect(namespace, new WorkerCommand.Call(data)) | ||
: []; | ||
@@ -182,26 +182,28 @@ if (results.length === 0) { | ||
type WorkerCommand<T, D> | ||
= WorkerCommand_$Deps<T> | ||
| WorkerCommand_$Call<D> | ||
| WorkerCommand_$Exit; | ||
= WorkerCommand.Deps<T> | ||
| WorkerCommand.Call<D> | ||
| WorkerCommand.Exit; | ||
abstract class AbstractWorkerCommand { | ||
private WORKER_COMMAND: void; | ||
} | ||
class WorkerCommand_$Deps<T> extends AbstractWorkerCommand { | ||
private COMMAND: this; | ||
constructor(public namespace: T) { | ||
super(); | ||
namespace WorkerCommand { | ||
abstract class AbstractCommand { | ||
private WORKER_COMMAND: void; | ||
} | ||
} | ||
class WorkerCommand_$Call<D> extends AbstractWorkerCommand { | ||
private COMMAND: this; | ||
constructor(public data: D) { | ||
super(); | ||
export class Deps<T> extends AbstractCommand { | ||
private COMMAND: this; | ||
constructor(public namespace: T) { | ||
super(); | ||
} | ||
} | ||
} | ||
class WorkerCommand_$Exit extends AbstractWorkerCommand { | ||
private COMMAND: this; | ||
constructor(public reason: any) { | ||
super(); | ||
export class Call<D> extends AbstractCommand { | ||
private COMMAND: this; | ||
constructor(public data: D) { | ||
super(); | ||
} | ||
} | ||
export class Exit extends AbstractCommand { | ||
private COMMAND: this; | ||
constructor(public reason: any) { | ||
super(); | ||
} | ||
} | ||
} | ||
@@ -239,4 +241,4 @@ | ||
private concurrency: number = 1; | ||
private tryDependencyResolving(cmd: WorkerCommand_$Call<D>): void { | ||
if (this.receive(new WorkerCommand_$Deps(this.namespace))) { | ||
private tryDependencyResolving(cmd: WorkerCommand.Call<D>): void { | ||
if (this.receive(new WorkerCommand.Deps(this.namespace))) { | ||
this.sharedResource.dependenciesStack = []; | ||
@@ -251,3 +253,3 @@ return; | ||
public receive(): Worker<T, D, R> | ||
public receive(cmd: WorkerCommand_$Deps<T>): boolean | ||
public receive(cmd: WorkerCommand.Deps<T>): boolean | ||
public receive(cmd: WorkerCommand<T, D>): R | ||
@@ -259,3 +261,3 @@ public receive(cmd?: WorkerCommand<T, D>): any { | ||
} | ||
if (cmd instanceof WorkerCommand_$Deps) { | ||
if (cmd instanceof WorkerCommand.Deps) { | ||
if (cmd.namespace.length !== this.namespace.length) return false; | ||
@@ -270,6 +272,6 @@ if (this.concurrency === 0) return false; | ||
(this.sharedResource.allRefsCache = this.sharedResource.allRefsCache || this.sharedResource.procs.refs(<T>[])) | ||
.some(([ns, proc]) => equal(ns, dep) && !!proc(new WorkerCommand_$Deps(dep))) | ||
.some(([ns, proc]) => equal(ns, dep) && !!proc(new WorkerCommand.Deps(dep))) | ||
); | ||
} | ||
if (cmd instanceof WorkerCommand_$Call) { | ||
if (cmd instanceof WorkerCommand.Call) { | ||
if (this.concurrency === 0) throw void 0; // cancel | ||
@@ -308,7 +310,7 @@ void this.tryDependencyResolving(cmd); | ||
} | ||
if (cmd instanceof WorkerCommand_$Exit) { | ||
if (cmd instanceof WorkerCommand.Exit) { | ||
void this.terminate(cmd.reason); | ||
throw void 0; | ||
} | ||
throw new TypeError(`spica: Supervisor: Invalid command: ${cmd}`); | ||
throw new TypeError(`Spica: Supervisor: Invalid command: ${cmd}`); | ||
} | ||
@@ -319,3 +321,3 @@ public terminate(reason: any): void { | ||
private checkState(): void { | ||
if (!this.alive) throw new Error(`spica: Supervisor: Process ${this.namespace}/${this.process} already exited.`); | ||
if (!this.alive) throw new Error(`Spica: Supervisor: Process ${this.namespace}/${this.process} already exited.`); | ||
} | ||
@@ -322,0 +324,0 @@ } |
import {FINGERPRINT} from './fingerprint'; | ||
const SEED = FINGERPRINT * Date.now() % 1e15; | ||
if (!SEED || typeof SEED !== 'number' || SEED < 1e2 || 1e15 < SEED) throw new Error(`spica: uuid: Invalid uuid static seed.\n\t${FINGERPRINT}`); | ||
if (!SEED || typeof SEED !== 'number' || SEED < 1e2 || 1e15 < SEED) throw new Error(`Spica: uuid: Invalid uuid static seed.\n\t${FINGERPRINT}`); | ||
@@ -11,3 +11,3 @@ const FORMAT_V4 = Object.freeze('xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.split('')); | ||
const k: number = seed = seed * Date.now() % 1e15; | ||
if (k < 16 || 1e15 < k) throw new Error(`spica: uuid: Invalid uuid dynamic seed.`); | ||
if (k < 16 || 1e15 < k) throw new Error(`Spica: uuid: Invalid uuid dynamic seed.`); | ||
let acc = ''; | ||
@@ -14,0 +14,0 @@ for (const c of FORMAT_V4) { |
@@ -6,4 +6,3 @@ import { | ||
Either, Left, Right, | ||
Map, DataMap, WeakMap, AttrMap, RelationMap, | ||
Set, DataSet, WeakSet, AttrSet, RelationSet, | ||
DataMap, AttrMap, RelationMap, | ||
Tick, | ||
@@ -77,6 +76,2 @@ FINGERPRINT, | ||
describe('Map', function () { | ||
it('Map', function () { | ||
assert(typeof Map === 'function'); | ||
}); | ||
it('DataMap', function () { | ||
@@ -86,6 +81,2 @@ assert(typeof DataMap === 'function'); | ||
it('WeakMap', function () { | ||
assert(typeof WeakMap === 'function'); | ||
}); | ||
it('AttrMap', function () { | ||
@@ -101,25 +92,2 @@ assert(typeof AttrMap === 'function'); | ||
describe('Set', function () { | ||
it('Set', function () { | ||
assert(typeof Set === 'function'); | ||
}); | ||
it('DataSet', function () { | ||
assert(typeof DataSet === 'function'); | ||
}); | ||
it('WeakSet', function () { | ||
assert(typeof WeakSet === 'function'); | ||
}); | ||
it('AttrSet', function () { | ||
assert(typeof AttrSet === 'function'); | ||
}); | ||
it('RelationSet', function () { | ||
assert(typeof RelationSet === 'function'); | ||
}); | ||
}); | ||
describe('Tick', function () { | ||
@@ -126,0 +94,0 @@ it('Tick', function () { |
@@ -19,1 +19,33 @@ interface String { | ||
} | ||
interface Map<K, V> { | ||
clear(): void; | ||
delete(key: K): boolean; | ||
forEach(callbackfn: (value: V, index: K, map: Map<K, V>) => void, thisArg?: any): void; | ||
get(key: K): V; | ||
has(key: K): boolean; | ||
set(key: K, value?: V): this; | ||
size: number; | ||
} | ||
interface MapConstructor { | ||
new (): Map<any, any>; | ||
new <K, V>(entries?: [K, V][]): Map<K, V>; | ||
prototype: Map<any, any>; | ||
} | ||
declare var Map: MapConstructor; | ||
interface WeakMap<K, V> { | ||
clear(): void; | ||
delete(key: K): boolean; | ||
get(key: K): V; | ||
has(key: K): boolean; | ||
set(key: K, value?: V): this; | ||
} | ||
interface WeakMapConstructor { | ||
new (): WeakMap<any, any>; | ||
new <K, V>(entries?: [K, V][]): WeakMap<K, V>; | ||
prototype: WeakMap<any, any>; | ||
} | ||
declare var WeakMap: WeakMapConstructor; |
@@ -163,79 +163,22 @@ /** | ||
export class Map<K, V> { | ||
get(key: K): V; | ||
set(key: K, val: V): V; | ||
has(key: K): boolean; | ||
delete(key: K): void; | ||
clear(): void; | ||
size: number; | ||
entries(): [K, V][]; | ||
} | ||
export class DataMap<K, V> { | ||
get(key: K): V; | ||
set(key: K, val: V): V; | ||
set(key: K, val: V): this; | ||
has(key: K): boolean; | ||
delete(key: K): void; | ||
delete(key: K): boolean; | ||
clear(): void; | ||
size: number; | ||
entries(): [K, V][]; | ||
} | ||
export class WeakMap<K extends Object, V> { | ||
get(key: K): V; | ||
set(key: K, val: V): V; | ||
has(key: K): boolean; | ||
delete(key: K): void; | ||
} | ||
export class AttrMap<O extends Object, K extends string | number, V> { | ||
export class AttrMap<O extends Object, K, V> { | ||
get(obj: O, key: K): V; | ||
set(obj: O, key: K, val: V): V; | ||
set(obj: O, key: K, val: V): this; | ||
has(obj: O, key: K): boolean; | ||
delete(obj: O, key?: K): void; | ||
delete(obj: O, key?: K): boolean; | ||
} | ||
export class RelationMap<S extends Object, T extends Object, V> { | ||
get(source: S, target: T): V; | ||
set(source: S, target: T, val: V): V; | ||
set(source: S, target: T, val: V): this; | ||
has(source: S, target: T): boolean; | ||
delete(source: S, target?: T): void; | ||
delete(source: S, target?: T): boolean; | ||
} | ||
export class Set<K, V> { | ||
constructor(replacer?: (oldVal: V, newVal: V) => V) | ||
get(key: K): V; | ||
add(key: K, val: V): V; | ||
has(key: K): boolean; | ||
delete(key: K): void; | ||
clear(): void; | ||
size: number; | ||
entries(): [K, V][]; | ||
} | ||
export class DataSet<K, V> { | ||
constructor(replacer?: (oldVal: V, newVal: V) => V) | ||
get(key: K): V; | ||
add(key: K, val: V): V; | ||
has(key: K): boolean; | ||
delete(key: K): void; | ||
clear(): void; | ||
size: number; | ||
entries(): [K, V][]; | ||
} | ||
export class WeakSet<K extends Object, V> { | ||
constructor(replacer?: (oldVal: V, newVal: V) => V) | ||
get(key: K): V; | ||
add(key: K, val: V): V; | ||
has(key: K): boolean; | ||
delete(key: K): void; | ||
} | ||
export class AttrSet<O extends Object, K extends string | number, V> { | ||
constructor(replacer?: (oldVal: V, newVal: V) => V) | ||
get(obj: O, key: K): V; | ||
add(obj: O, key: K, val: V): V; | ||
has(obj: O, key: K): boolean; | ||
delete(obj: O, key?: K): void; | ||
} | ||
export class RelationSet<S extends Object, T extends Object, V> { | ||
constructor(replacer?: (oldVal: V, newVal: V) => V) | ||
get(source: S, target: T): V; | ||
add(source: S, target: T, val: V): V; | ||
has(source: S, target: T): boolean; | ||
delete(source: S, target?: T): void; | ||
} | ||
@@ -242,0 +185,0 @@ export function Tick(fn: (_?: void) => any): void |
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
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
180018
56
4760