mirror of
https://github.com/esiur/esiur-js.git
synced 2025-12-15 01:40:23 +00:00
Replace .error with .catch
This commit is contained in:
170
build/esiur.js
170
build/esiur.js
@@ -1073,6 +1073,11 @@ var AsyncReply = exports["default"] = /*#__PURE__*/function (_Promise) {
|
|||||||
value: function done(callback) {
|
value: function done(callback) {
|
||||||
this.then(callback);
|
this.then(callback);
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: "catch",
|
||||||
|
value: function _catch(callback) {
|
||||||
|
this.error(callback);
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "error",
|
key: "error",
|
||||||
value: function error(callback) {
|
value: function error(callback) {
|
||||||
@@ -6356,7 +6361,7 @@ var DistributedConnection = exports["default"] = /*#__PURE__*/function (_IStore)
|
|||||||
var resource = new (Function.prototype.bind.apply(type, values))();
|
var resource = new (Function.prototype.bind.apply(type, values))();
|
||||||
_Warehouse["default"].put(name, resource, store, parent).then(function (ok) {
|
_Warehouse["default"].put(name, resource, store, parent).then(function (ok) {
|
||||||
_classPrivateMethodGet(self, _sendReply, _sendReply2).call(self, _IIPPacketAction["default"].CreateResource, callback).addUint32(resource.Instance.Id).done();
|
_classPrivateMethodGet(self, _sendReply, _sendReply2).call(self, _IIPPacketAction["default"].CreateResource, callback).addUint32(resource.Instance.Id).done();
|
||||||
}).error(function (ex) {
|
})["catch"](function (ex) {
|
||||||
// send some error
|
// send some error
|
||||||
_classPrivateMethodGet(self, _sendError, _sendError2).call(self, _ErrorType["default"].Management, callback, _ExceptionCode["default"].AddToStoreFailed);
|
_classPrivateMethodGet(self, _sendError, _sendError2).call(self, _ErrorType["default"].Management, callback, _ExceptionCode["default"].AddToStoreFailed);
|
||||||
});
|
});
|
||||||
@@ -6973,7 +6978,7 @@ var DistributedConnection = exports["default"] = /*#__PURE__*/function (_IStore)
|
|||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
_Warehouse["default"].put(id.toString(), dr, self, null, tmp).then(function (ok) {
|
_Warehouse["default"].put(id.toString(), dr, self, null, tmp).then(function (ok) {
|
||||||
initResource(ok);
|
initResource(ok);
|
||||||
}).error(function (ex) {
|
})["catch"](function (ex) {
|
||||||
reply.triggerError(ex);
|
reply.triggerError(ex);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -6984,7 +6989,7 @@ var DistributedConnection = exports["default"] = /*#__PURE__*/function (_IStore)
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
_Warehouse["default"].put(id.toString(), dr, self, null, template).then(initResource).error(function (ex) {
|
_Warehouse["default"].put(id.toString(), dr, self, null, template).then(initResource)["catch"](function (ex) {
|
||||||
return reply.triggerError(ex);
|
return reply.triggerError(ex);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -7632,7 +7637,7 @@ function _processClientAuth2(data) {
|
|||||||
(_classPrivateFieldGet5 = (0, _classPrivateFieldGet25["default"])(_this5, _openReply)) === null || _classPrivateFieldGet5 === void 0 || _classPrivateFieldGet5.trigger(true);
|
(_classPrivateFieldGet5 = (0, _classPrivateFieldGet25["default"])(_this5, _openReply)) === null || _classPrivateFieldGet5 === void 0 || _classPrivateFieldGet5.trigger(true);
|
||||||
_this5._emit("ready", _this5);
|
_this5._emit("ready", _this5);
|
||||||
(0, _classPrivateFieldSet2["default"])(_this5, _openReply, null);
|
(0, _classPrivateFieldSet2["default"])(_this5, _openReply, null);
|
||||||
}).error(function (x) {
|
})["catch"](function (x) {
|
||||||
var _classPrivateFieldGet6;
|
var _classPrivateFieldGet6;
|
||||||
(_classPrivateFieldGet6 = (0, _classPrivateFieldGet25["default"])(_this5, _openReply)) === null || _classPrivateFieldGet6 === void 0 || _classPrivateFieldGet6.triggerError(x);
|
(_classPrivateFieldGet6 = (0, _classPrivateFieldGet25["default"])(_this5, _openReply)) === null || _classPrivateFieldGet6 === void 0 || _classPrivateFieldGet6.triggerError(x);
|
||||||
(0, _classPrivateFieldSet2["default"])(_this5, _openReply, null);
|
(0, _classPrivateFieldSet2["default"])(_this5, _openReply, null);
|
||||||
@@ -7857,7 +7862,7 @@ function _processAuthorization2(results) {
|
|||||||
_this7._emit("ready", _this7);
|
_this7._emit("ready", _this7);
|
||||||
(_classPrivateFieldGet19 = (0, _classPrivateFieldGet25["default"])(_this7, _server)) === null || _classPrivateFieldGet19 === void 0 || (_classPrivateFieldGet19 = _classPrivateFieldGet19.membership) === null || _classPrivateFieldGet19 === void 0 || _classPrivateFieldGet19.login((0, _classPrivateFieldGet25["default"])(_this7, _session));
|
(_classPrivateFieldGet19 = (0, _classPrivateFieldGet25["default"])(_this7, _server)) === null || _classPrivateFieldGet19 === void 0 || (_classPrivateFieldGet19 = _classPrivateFieldGet19.membership) === null || _classPrivateFieldGet19 === void 0 || _classPrivateFieldGet19.login((0, _classPrivateFieldGet25["default"])(_this7, _session));
|
||||||
(0, _classPrivateFieldSet2["default"])(_this7, _loginDate, new Date());
|
(0, _classPrivateFieldSet2["default"])(_this7, _loginDate, new Date());
|
||||||
}).error(function (x) {
|
})["catch"](function (x) {
|
||||||
var _classPrivateFieldGet20;
|
var _classPrivateFieldGet20;
|
||||||
(_classPrivateFieldGet20 = (0, _classPrivateFieldGet25["default"])(_this7, _openReply)) === null || _classPrivateFieldGet20 === void 0 || _classPrivateFieldGet20.triggerError(x);
|
(_classPrivateFieldGet20 = (0, _classPrivateFieldGet25["default"])(_this7, _openReply)) === null || _classPrivateFieldGet20 === void 0 || _classPrivateFieldGet20.triggerError(x);
|
||||||
(0, _classPrivateFieldSet2["default"])(_this7, _openReply, null);
|
(0, _classPrivateFieldSet2["default"])(_this7, _openReply, null);
|
||||||
@@ -12516,7 +12521,7 @@ var WH = exports.WH = /*#__PURE__*/function (_IEventHandler) {
|
|||||||
var rt = new _AsyncReply["default"]();
|
var rt = new _AsyncReply["default"]();
|
||||||
this.put(name, res, store, parent, null, 0, manager, attributes).then(function () {
|
this.put(name, res, store, parent, null, 0, manager, attributes).then(function () {
|
||||||
return rt.trigger(res);
|
return rt.trigger(res);
|
||||||
}).error(function (ex) {
|
})["catch"](function (ex) {
|
||||||
return rt.triggerError(ex);
|
return rt.triggerError(ex);
|
||||||
});
|
});
|
||||||
return rt;
|
return rt;
|
||||||
@@ -12527,7 +12532,9 @@ var WH = exports.WH = /*#__PURE__*/function (_IEventHandler) {
|
|||||||
}, {
|
}, {
|
||||||
key: "getById",
|
key: "getById",
|
||||||
value: function getById(id) {
|
value: function getById(id) {
|
||||||
return new _AsyncReply["default"](this.resources.item(id));
|
var _this$resources$item;
|
||||||
|
var r = (_this$resources$item = this.resources.item(id)) === null || _this$resources$item === void 0 ? void 0 : _this$resources$item.deref();
|
||||||
|
return new _AsyncReply["default"](r);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "get",
|
key: "get",
|
||||||
@@ -12627,120 +12634,127 @@ var WH = exports.WH = /*#__PURE__*/function (_IEventHandler) {
|
|||||||
_context.next = 8;
|
_context.next = 8;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rt.triggerError(new _AsyncException["default"](0, _ExceptionCode["default"].GeneralFailure, "Resource has a store"));
|
rt.triggerError(0, _ExceptionCode["default"].GeneralFailure, "Resource has a store");
|
||||||
return _context.abrupt("return", rt);
|
return _context.abrupt("return", rt);
|
||||||
case 8:
|
case 8:
|
||||||
path = name.replace(/^\\/g, "").split("/");
|
// trim '/' character
|
||||||
|
path = name.replace(/^[\/]+/, '').split('/');
|
||||||
if (!(path.length > 1)) {
|
if (!(path.length > 1)) {
|
||||||
_context.next = 18;
|
_context.next = 20;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!(parent != null)) {
|
if (!(parent != null)) {
|
||||||
_context.next = 12;
|
_context.next = 13;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
throw new Error("Parent can't be set when using path in instance name");
|
rt.triggerError(0, _ExceptionCode["default"].GeneralFailure, "Parent can't be set when using path in instance name");
|
||||||
case 12:
|
return _context.abrupt("return", rt);
|
||||||
_context.next = 14;
|
case 13:
|
||||||
return Warehouse.get(path.slice(0, path.length - 1).join("/"));
|
_context.next = 15;
|
||||||
case 14:
|
return Warehouse.get(path.slice(0, -1).join("/"));
|
||||||
|
case 15:
|
||||||
parent = _context.sent;
|
parent = _context.sent;
|
||||||
if (!(parent == null)) {
|
if (!(parent == null)) {
|
||||||
_context.next = 17;
|
_context.next = 19;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
throw new Error("Can't find parent");
|
rt.triggerError(0, _ExceptionCode["default"].GeneralFailure, "Can't find parent.");
|
||||||
case 17:
|
return _context.abrupt("return", rt);
|
||||||
store = (_store = store) !== null && _store !== void 0 ? _store : parent.instance.store;
|
case 19:
|
||||||
case 18:
|
store = (_store = store) !== null && _store !== void 0 ? _store : parent.Instance.Store;
|
||||||
instanceName = path[path.length - 1];
|
case 20:
|
||||||
|
instanceName = path.at(-1);
|
||||||
resourceReference = new WeakRef(resource);
|
resourceReference = new WeakRef(resource);
|
||||||
if (!(store == null)) {
|
if (!(store == null)) {
|
||||||
_context.next = 30;
|
_context.next = 33;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!(parent != null)) {
|
if (!(parent != null)) {
|
||||||
_context.next = 25;
|
_context.next = 27;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// assign parent as a store
|
// assign parent as a store
|
||||||
if (parent instanceof _IStore["default"]) {
|
if (parent instanceof _IStore["default"]) {
|
||||||
store = parent;
|
store = parent;
|
||||||
list = Warehouse.stores.get(store);
|
list = this.stores.get(store);
|
||||||
if (list) list.add(resourceReference);
|
if (list) list.add(resourceReference);
|
||||||
} else {
|
} else {
|
||||||
store = parent.instance.store;
|
store = parent.instance.store;
|
||||||
_list = Warehouse.stores.get(store);
|
_list = this.stores.get(store);
|
||||||
if (_list) _list.add(resourceReference);
|
if (_list) _list.add(resourceReference);
|
||||||
}
|
}
|
||||||
_context.next = 30;
|
_context.next = 33;
|
||||||
break;
|
break;
|
||||||
case 25:
|
case 27:
|
||||||
if (!(resource instanceof _IStore["default"])) {
|
if (!(resource instanceof _IStore["default"])) {
|
||||||
_context.next = 29;
|
_context.next = 31;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
store = resource;
|
store = resource;
|
||||||
_context.next = 30;
|
_context.next = 33;
|
||||||
break;
|
break;
|
||||||
case 29:
|
case 31:
|
||||||
throw new Error("Can't find a store for the resource.");
|
rt.triggerError(0, _ExceptionCode["default"].GeneralFailure, "Can't find a store for the resource.");
|
||||||
case 30:
|
return _context.abrupt("return", rt);
|
||||||
resource.instance = new _Instance["default"](Warehouse.resourceCounter++, instanceName, resource, store, customTemplate, age);
|
case 33:
|
||||||
|
resource.instance = new _Instance["default"](this.resourceCounter++, instanceName, resource, store, customTemplate, age);
|
||||||
if (attributes != null) resource.instance.setAttributes(attributes);
|
if (attributes != null) resource.instance.setAttributes(attributes);
|
||||||
if (manager != null) resource.instance.managers.add(manager);
|
if (manager != null) resource.instance.managers.add(manager);
|
||||||
if (store == parent) parent = null;
|
if (store == parent) parent = null;
|
||||||
_context.prev = 34;
|
_context.prev = 37;
|
||||||
if (resource instanceof _IStore["default"]) stores.add(resource, []);
|
if (resource instanceof _IStore["default"]) this.stores.add(resource, []);
|
||||||
_context.next = 38;
|
_context.next = 41;
|
||||||
return store.put(resource);
|
return store.put(resource);
|
||||||
case 38:
|
case 41:
|
||||||
if (_context.sent) {
|
if (_context.sent) {
|
||||||
_context.next = 40;
|
_context.next = 44;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
throw new Error("Store failed to put the resource");
|
rt.triggerError(0, _ExceptionCode["default"].GeneralFailure, "Store failed to put the resource.");
|
||||||
case 40:
|
return _context.abrupt("return", rt);
|
||||||
|
case 44:
|
||||||
if (!(parent != null)) {
|
if (!(parent != null)) {
|
||||||
_context.next = 45;
|
_context.next = 49;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_context.next = 43;
|
_context.next = 47;
|
||||||
return parent.instance.store.addChild(parent, resource);
|
return parent.instance.store.addChild(parent, resource);
|
||||||
case 43:
|
case 47:
|
||||||
_context.next = 45;
|
|
||||||
return store.addParent(resource, parent);
|
|
||||||
case 45:
|
|
||||||
Warehouse.resources.add(resource.instance.Id, resourceReference);
|
|
||||||
if (!Warehouse.warehouseIsOpen) {
|
|
||||||
_context.next = 52;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
_context.next = 49;
|
_context.next = 49;
|
||||||
return resource.trigger(_IResource.ResourceTrigger.Initialize);
|
return store.addParent(resource, parent);
|
||||||
case 49:
|
case 49:
|
||||||
if (!(resource instanceof _IStore["default"])) {
|
this.resources.add(resource.instance.id, resourceReference);
|
||||||
_context.next = 52;
|
if (!this.warehouseIsOpen) {
|
||||||
|
_context.next = 56;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_context.next = 52;
|
_context.next = 53;
|
||||||
|
return resource.trigger(_IResource.ResourceTrigger.Initialize);
|
||||||
|
case 53:
|
||||||
|
if (!(resource instanceof _IStore["default"])) {
|
||||||
|
_context.next = 56;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
_context.next = 56;
|
||||||
return resource.trigger(_IResource.ResourceTrigger.Open);
|
return resource.trigger(_IResource.ResourceTrigger.Open);
|
||||||
case 52:
|
case 56:
|
||||||
if (resource instanceof _IStore["default"]) Warehouse._emit("StoreConnected", resource);
|
if (resource instanceof _IStore["default"]) this._emit("StoreConnected", resource);
|
||||||
_context.next = 59;
|
_context.next = 64;
|
||||||
break;
|
break;
|
||||||
case 55:
|
|
||||||
_context.prev = 55;
|
|
||||||
_context.t0 = _context["catch"](34);
|
|
||||||
Warehouse.remove(resource);
|
|
||||||
throw _context.t0;
|
|
||||||
case 59:
|
case 59:
|
||||||
return _context.abrupt("return", resource);
|
_context.prev = 59;
|
||||||
case 60:
|
_context.t0 = _context["catch"](37);
|
||||||
|
this.remove(resource);
|
||||||
|
rt.triggerError(_context.t0);
|
||||||
|
return _context.abrupt("return", rt);
|
||||||
|
case 64:
|
||||||
|
rt.trigger(resource);
|
||||||
|
return _context.abrupt("return", rt);
|
||||||
|
case 66:
|
||||||
case "end":
|
case "end":
|
||||||
return _context.stop();
|
return _context.stop();
|
||||||
}
|
}
|
||||||
}, _callee, null, [[34, 55]]);
|
}, _callee, this, [[37, 59]]);
|
||||||
}));
|
}));
|
||||||
function put(_x, _x2, _x3, _x4) {
|
function put(_x, _x2, _x3, _x4) {
|
||||||
return _put.apply(this, arguments);
|
return _put.apply(this, arguments);
|
||||||
@@ -12855,7 +12869,7 @@ var WH = exports.WH = /*#__PURE__*/function (_IEventHandler) {
|
|||||||
while (1) switch (_context2.prev = _context2.next) {
|
while (1) switch (_context2.prev = _context2.next) {
|
||||||
case 0:
|
case 0:
|
||||||
p = path.replace(/^\\/g, "").split("/");
|
p = path.replace(/^\\/g, "").split("/");
|
||||||
_iterator = _createForOfIteratorHelper(Warehouse.stores.keys);
|
_iterator = _createForOfIteratorHelper(this.stores.keys);
|
||||||
_context2.prev = 2;
|
_context2.prev = 2;
|
||||||
_iterator.s();
|
_iterator.s();
|
||||||
case 4:
|
case 4:
|
||||||
@@ -12937,7 +12951,7 @@ var WH = exports.WH = /*#__PURE__*/function (_IEventHandler) {
|
|||||||
case "end":
|
case "end":
|
||||||
return _context2.stop();
|
return _context2.stop();
|
||||||
}
|
}
|
||||||
}, _callee2, null, [[2, 37, 40, 43]]);
|
}, _callee2, this, [[2, 37, 40, 43]]);
|
||||||
}));
|
}));
|
||||||
function query(_x5) {
|
function query(_x5) {
|
||||||
return _query.apply(this, arguments);
|
return _query.apply(this, arguments);
|
||||||
@@ -12953,8 +12967,10 @@ var WH = exports.WH = /*#__PURE__*/function (_IEventHandler) {
|
|||||||
var rt = new _AsyncReply["default"]();
|
var rt = new _AsyncReply["default"]();
|
||||||
var self = this;
|
var self = this;
|
||||||
for (var i = 0; i < this.resources.length; i++) {
|
for (var i = 0; i < this.resources.length; i++) {
|
||||||
var r = this.resources.at(i);
|
var r = this.resources.at(i).deref();
|
||||||
initBag.add(r.trigger(_IResource.ResourceTrigger.Initialize));
|
if (r) {
|
||||||
|
initBag.add(r.trigger(_IResource.ResourceTrigger.Initialize));
|
||||||
|
}
|
||||||
//if (!rt)
|
//if (!rt)
|
||||||
// console.log(`Resource failed at Initialize ${r.Instance.Name} [${r.Instance.Template.ClassName}]`);
|
// console.log(`Resource failed at Initialize ${r.Instance.Name} [${r.Instance.Template.ClassName}]`);
|
||||||
}
|
}
|
||||||
@@ -12963,8 +12979,10 @@ var WH = exports.WH = /*#__PURE__*/function (_IEventHandler) {
|
|||||||
for (var _i4 = 0; _i4 < ar.length; _i4++) if (!ar[_i4]) console.log("Resource failed at Initialize ".concat(self.resources.at(_i4).instance.name, " [").concat(self.resources.at(_i4).instance.template.className, "]"));
|
for (var _i4 = 0; _i4 < ar.length; _i4++) if (!ar[_i4]) console.log("Resource failed at Initialize ".concat(self.resources.at(_i4).instance.name, " [").concat(self.resources.at(_i4).instance.template.className, "]"));
|
||||||
var sysBag = new _AsyncBag["default"]();
|
var sysBag = new _AsyncBag["default"]();
|
||||||
for (var _i5 = 0; _i5 < _this2.resources.length; _i5++) {
|
for (var _i5 = 0; _i5 < _this2.resources.length; _i5++) {
|
||||||
var r = _this2.resources.at(_i5);
|
var r = _this2.resources.at(_i5).deref();
|
||||||
sysBag.add(r.trigger(_IResource.ResourceTrigger.SystemInitialized));
|
if (r) {
|
||||||
|
sysBag.add(r.trigger(_IResource.ResourceTrigger.SystemInitialized));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sysBag.seal();
|
sysBag.seal();
|
||||||
sysBag.then(function (ar2) {
|
sysBag.then(function (ar2) {
|
||||||
@@ -13896,13 +13914,13 @@ var IndexedDBStore = exports["default"] = /*#__PURE__*/function (_IStore) {
|
|||||||
resource.instance.loadProperty(_v.name, _v.age, _v.modification, ar[i]);
|
resource.instance.loadProperty(_v.name, _v.age, _v.modification, ar[i]);
|
||||||
}
|
}
|
||||||
rt.trigger(resource);
|
rt.trigger(resource);
|
||||||
}).error(function (ex) {
|
})["catch"](function (ex) {
|
||||||
return rt.triggerError(ex);
|
return rt.triggerError(ex);
|
||||||
});
|
});
|
||||||
}).error(function (ex) {
|
})["catch"](function (ex) {
|
||||||
return rt.triggerError(ex);
|
return rt.triggerError(ex);
|
||||||
});
|
});
|
||||||
}).error(function (ex) {
|
})["catch"](function (ex) {
|
||||||
return rt.triggerError(ex);
|
return rt.triggerError(ex);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "esiur",
|
"name": "esiur",
|
||||||
"version": "2.3.5",
|
"version": "2.3.6",
|
||||||
"description": "Distributed Object Framework",
|
"description": "Distributed Object Framework",
|
||||||
"main": "esiur.js",
|
"main": "esiur.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ export default class AsyncReply extends Promise
|
|||||||
this.then(callback);
|
this.then(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
catch(callback){
|
||||||
|
this.error(callback);
|
||||||
|
}
|
||||||
|
|
||||||
error(callback)
|
error(callback)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -634,7 +634,7 @@ export default class DistributedConnection extends IStore {
|
|||||||
this._emit("ready", this);
|
this._emit("ready", this);
|
||||||
this.#openReply = null;
|
this.#openReply = null;
|
||||||
|
|
||||||
}).error((x) =>
|
}).catch((x) =>
|
||||||
{
|
{
|
||||||
this.#openReply?.triggerError(x);
|
this.#openReply?.triggerError(x);
|
||||||
this.#openReply = null;
|
this.#openReply = null;
|
||||||
@@ -1104,7 +1104,7 @@ export default class DistributedConnection extends IStore {
|
|||||||
this.#server?.membership?.login(this.#session);
|
this.#server?.membership?.login(this.#session);
|
||||||
this.#loginDate = new Date();
|
this.#loginDate = new Date();
|
||||||
|
|
||||||
}).error((x) =>
|
}).catch((x) =>
|
||||||
{
|
{
|
||||||
this.#openReply?.triggerError(x);
|
this.#openReply?.triggerError(x);
|
||||||
this.#openReply = null;
|
this.#openReply = null;
|
||||||
@@ -2153,7 +2153,7 @@ export default class DistributedConnection extends IStore {
|
|||||||
self.#sendReply(IIPPacketAction.CreateResource, callback)
|
self.#sendReply(IIPPacketAction.CreateResource, callback)
|
||||||
.addUint32(resource.Instance.Id)
|
.addUint32(resource.Instance.Id)
|
||||||
.done();
|
.done();
|
||||||
}).error(function(ex){
|
}).catch(function(ex){
|
||||||
// send some error
|
// send some error
|
||||||
self.#sendError(ErrorType.Management, callback, ExceptionCode.AddToStoreFailed);
|
self.#sendError(ErrorType.Management, callback, ExceptionCode.AddToStoreFailed);
|
||||||
});
|
});
|
||||||
@@ -3052,7 +3052,7 @@ export default class DistributedConnection extends IStore {
|
|||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
Warehouse.put(id.toString(), dr, self, null, tmp).then(function(ok){
|
Warehouse.put(id.toString(), dr, self, null, tmp).then(function(ok){
|
||||||
initResource(ok);
|
initResource(ok);
|
||||||
}).error(function(ex){
|
}).catch(function(ex){
|
||||||
reply.triggerError(ex);
|
reply.triggerError(ex);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3067,7 +3067,7 @@ export default class DistributedConnection extends IStore {
|
|||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
Warehouse.put(id.toString(), dr, self, null, template)
|
Warehouse.put(id.toString(), dr, self, null, template)
|
||||||
.then(initResource)
|
.then(initResource)
|
||||||
.error((ex) => reply.triggerError(ex));
|
.catch((ex) => reply.triggerError(ex));
|
||||||
} else {
|
} else {
|
||||||
initResource(resource);
|
initResource(resource);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ export class WH extends IEventHandler
|
|||||||
|
|
||||||
this.put(name, res, store, parent, null, 0, manager, attributes)
|
this.put(name, res, store, parent, null, 0, manager, attributes)
|
||||||
.then(()=>rt.trigger(res))
|
.then(()=>rt.trigger(res))
|
||||||
.error((ex)=>rt.triggerError(ex));
|
.catch((ex)=>rt.triggerError(ex));
|
||||||
|
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,8 @@ export class WH extends IEventHandler
|
|||||||
|
|
||||||
getById(id)
|
getById(id)
|
||||||
{
|
{
|
||||||
return new AsyncReply(this.resources.item(id));
|
let r = this.resources.item(id)?.deref();
|
||||||
|
return new AsyncReply(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
get(path, attributes = null)//, parent = null, manager = null)
|
get(path, attributes = null)//, parent = null, manager = null)
|
||||||
@@ -214,29 +215,36 @@ export class WH extends IEventHandler
|
|||||||
|
|
||||||
async put(name, resource, store, parent, customTemplate = null, age = 0, manager = null, attributes = null){
|
async put(name, resource, store, parent, customTemplate = null, age = 0, manager = null, attributes = null){
|
||||||
|
|
||||||
|
|
||||||
let rt = new AsyncReply();
|
let rt = new AsyncReply();
|
||||||
|
|
||||||
if (resource.instance != null){
|
if (resource.instance != null){
|
||||||
rt.triggerError(new AsyncException(0, ExceptionCode.GeneralFailure, "Resource has a store"));
|
rt.triggerError(0, ExceptionCode.GeneralFailure, "Resource has a store");
|
||||||
return rt;
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = name.replace(/^\\/g, "").split("/");
|
// trim '/' character
|
||||||
|
let path = name.replace(/^[\/]+/, '').split('/');
|
||||||
|
|
||||||
if (path.length > 1)
|
if (path.length > 1)
|
||||||
{
|
{
|
||||||
if (parent != null)
|
if (parent != null){
|
||||||
throw new Error("Parent can't be set when using path in instance name");
|
rt.triggerError(0, ExceptionCode.GeneralFailure, "Parent can't be set when using path in instance name");
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
|
|
||||||
parent = await Warehouse.get(path.slice(0, path.length - 1).join("/"));
|
parent = await Warehouse.get(path.slice(0, -1).join("/"));
|
||||||
|
|
||||||
if (parent == null)
|
if (parent == null){
|
||||||
throw new Error("Can't find parent");
|
rt.triggerError(0, ExceptionCode.GeneralFailure, "Can't find parent.");
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
|
|
||||||
store = store ?? parent.instance.store;
|
store = store ?? parent.Instance.Store;
|
||||||
}
|
}
|
||||||
|
|
||||||
let instanceName = path[path.length - 1];
|
let instanceName = path.at(-1);
|
||||||
|
|
||||||
|
|
||||||
let resourceReference = new WeakRef(resource);
|
let resourceReference = new WeakRef(resource);
|
||||||
|
|
||||||
@@ -249,7 +257,7 @@ export class WH extends IEventHandler
|
|||||||
if (parent instanceof IStore)
|
if (parent instanceof IStore)
|
||||||
{
|
{
|
||||||
store = parent;
|
store = parent;
|
||||||
let list = Warehouse.stores.get(store);
|
let list = this.stores.get(store);
|
||||||
if (list)
|
if (list)
|
||||||
list.add(resourceReference);
|
list.add(resourceReference);
|
||||||
}
|
}
|
||||||
@@ -257,7 +265,7 @@ export class WH extends IEventHandler
|
|||||||
{
|
{
|
||||||
store = parent.instance.store;
|
store = parent.instance.store;
|
||||||
|
|
||||||
let list = Warehouse.stores.get(store);
|
let list = this.stores.get(store);
|
||||||
if (list)
|
if (list)
|
||||||
list.add(resourceReference);
|
list.add(resourceReference);
|
||||||
}
|
}
|
||||||
@@ -268,10 +276,13 @@ export class WH extends IEventHandler
|
|||||||
store = resource;
|
store = resource;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new Error("Can't find a store for the resource.");
|
{
|
||||||
|
rt.triggerError(0, ExceptionCode.GeneralFailure, "Can't find a store for the resource.");
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource.instance = new Instance(Warehouse.resourceCounter++, instanceName, resource, store, customTemplate, age);
|
resource.instance = new Instance(this.resourceCounter++, instanceName, resource, store, customTemplate, age);
|
||||||
|
|
||||||
if (attributes != null)
|
if (attributes != null)
|
||||||
resource.instance.setAttributes(attributes);
|
resource.instance.setAttributes(attributes);
|
||||||
@@ -285,12 +296,13 @@ export class WH extends IEventHandler
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (resource instanceof IStore)
|
if (resource instanceof IStore)
|
||||||
stores.add(resource, []);
|
this.stores.add(resource, []);
|
||||||
|
|
||||||
|
|
||||||
if (!await store.put(resource))
|
if (!await store.put(resource)){
|
||||||
throw new Error("Store failed to put the resource");
|
rt.triggerError(0, ExceptionCode.GeneralFailure, "Store failed to put the resource.");
|
||||||
|
return rt;
|
||||||
|
}
|
||||||
|
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
{
|
{
|
||||||
@@ -298,9 +310,11 @@ export class WH extends IEventHandler
|
|||||||
await store.addParent(resource, parent);
|
await store.addParent(resource, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
Warehouse.resources.add(resource.instance.Id, resourceReference);
|
|
||||||
|
|
||||||
if (Warehouse.warehouseIsOpen)
|
|
||||||
|
this.resources.add(resource.instance.id, resourceReference);
|
||||||
|
|
||||||
|
if (this.warehouseIsOpen)
|
||||||
{
|
{
|
||||||
await resource.trigger(ResourceTrigger.Initialize);
|
await resource.trigger(ResourceTrigger.Initialize);
|
||||||
if (resource instanceof IStore)
|
if (resource instanceof IStore)
|
||||||
@@ -308,15 +322,127 @@ export class WH extends IEventHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resource instanceof IStore)
|
if (resource instanceof IStore)
|
||||||
Warehouse._emit("StoreConnected", resource);
|
this._emit("StoreConnected", resource);
|
||||||
}
|
}
|
||||||
catch (ex)
|
catch (ex)
|
||||||
{
|
{
|
||||||
Warehouse.remove(resource);
|
this.remove(resource);
|
||||||
throw ex;
|
rt.triggerError(ex);
|
||||||
|
return rt;
|
||||||
}
|
}
|
||||||
|
|
||||||
return resource;
|
rt.trigger(resource);
|
||||||
|
return rt;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// let rt = new AsyncReply();
|
||||||
|
|
||||||
|
// if (resource.instance != null){
|
||||||
|
// rt.triggerError(new AsyncException(0, ExceptionCode.GeneralFailure, "Resource has a store"));
|
||||||
|
// return rt;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let path = name.replace(/^\\/g, "").split("/");
|
||||||
|
|
||||||
|
// if (path.length > 1)
|
||||||
|
// {
|
||||||
|
// if (parent != null)
|
||||||
|
// throw new Error("Parent can't be set when using path in instance name");
|
||||||
|
|
||||||
|
// parent = await Warehouse.get(path.slice(0, path.length - 1).join("/"));
|
||||||
|
|
||||||
|
// if (parent == null)
|
||||||
|
// throw new Error("Can't find parent");
|
||||||
|
|
||||||
|
// store = store ?? parent.instance.store;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let instanceName = path[path.length - 1];
|
||||||
|
|
||||||
|
// let resourceReference = new WeakRef(resource);
|
||||||
|
|
||||||
|
// if (store == null)
|
||||||
|
// {
|
||||||
|
// // assign parent's store as a store
|
||||||
|
// if (parent != null)
|
||||||
|
// {
|
||||||
|
// // assign parent as a store
|
||||||
|
// if (parent instanceof IStore)
|
||||||
|
// {
|
||||||
|
// store = parent;
|
||||||
|
// let list = Warehouse.stores.get(store);
|
||||||
|
// if (list)
|
||||||
|
// list.add(resourceReference);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// store = parent.instance.store;
|
||||||
|
|
||||||
|
// let list = Warehouse.stores.get(store);
|
||||||
|
// if (list)
|
||||||
|
// list.add(resourceReference);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// // assign self as a store (root store)
|
||||||
|
// else if (resource instanceof IStore)
|
||||||
|
// {
|
||||||
|
// store = resource;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// throw new Error("Can't find a store for the resource.");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// resource.instance = new Instance(Warehouse.resourceCounter++, instanceName, resource, store, customTemplate, age);
|
||||||
|
|
||||||
|
// if (attributes != null)
|
||||||
|
// resource.instance.setAttributes(attributes);
|
||||||
|
|
||||||
|
// if (manager != null)
|
||||||
|
// resource.instance.managers.add(manager);
|
||||||
|
|
||||||
|
// if (store == parent)
|
||||||
|
// parent = null;
|
||||||
|
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// if (resource instanceof IStore)
|
||||||
|
// this.stores.add(resource, []);
|
||||||
|
|
||||||
|
|
||||||
|
// if (!await store.put(resource))
|
||||||
|
// throw new Error("Store failed to put the resource");
|
||||||
|
|
||||||
|
|
||||||
|
// if (parent != null)
|
||||||
|
// {
|
||||||
|
// await parent.instance.store.addChild(parent, resource);
|
||||||
|
// await store.addParent(resource, parent);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// Warehouse.resources.add(resource.instance.Id, resourceReference);
|
||||||
|
|
||||||
|
// if (Warehouse.warehouseIsOpen)
|
||||||
|
// {
|
||||||
|
// await resource.trigger(ResourceTrigger.Initialize);
|
||||||
|
// if (resource instanceof IStore)
|
||||||
|
// await resource.trigger(ResourceTrigger.Open);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (resource instanceof IStore)
|
||||||
|
// Warehouse._emit("StoreConnected", resource);
|
||||||
|
// }
|
||||||
|
// catch (ex)
|
||||||
|
// {
|
||||||
|
// Warehouse.remove(resource);
|
||||||
|
// throw ex;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return resource;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -528,7 +654,7 @@ export class WH extends IEventHandler
|
|||||||
let p = path.replace(/^\\/g, "").split("/");
|
let p = path.replace(/^\\/g, "").split("/");
|
||||||
let resource;
|
let resource;
|
||||||
|
|
||||||
for(let store of Warehouse.stores.keys)
|
for(let store of this.stores.keys)
|
||||||
{
|
{
|
||||||
if (p[0] == store.instance.name)
|
if (p[0] == store.instance.name)
|
||||||
{
|
{
|
||||||
@@ -576,8 +702,10 @@ export class WH extends IEventHandler
|
|||||||
|
|
||||||
for (var i = 0; i < this.resources.length; i++)
|
for (var i = 0; i < this.resources.length; i++)
|
||||||
{
|
{
|
||||||
var r = this.resources.at(i);
|
let r = this.resources.at(i).deref();
|
||||||
initBag.add(r.trigger(ResourceTrigger.Initialize));
|
if (r) {
|
||||||
|
initBag.add(r.trigger(ResourceTrigger.Initialize));
|
||||||
|
}
|
||||||
//if (!rt)
|
//if (!rt)
|
||||||
// console.log(`Resource failed at Initialize ${r.Instance.Name} [${r.Instance.Template.ClassName}]`);
|
// console.log(`Resource failed at Initialize ${r.Instance.Name} [${r.Instance.Template.ClassName}]`);
|
||||||
}
|
}
|
||||||
@@ -594,8 +722,10 @@ export class WH extends IEventHandler
|
|||||||
|
|
||||||
for (let i = 0; i < this.resources.length; i++)
|
for (let i = 0; i < this.resources.length; i++)
|
||||||
{
|
{
|
||||||
var r = this.resources.at(i);
|
var r = this.resources.at(i).deref();
|
||||||
sysBag.add(r.trigger(ResourceTrigger.SystemInitialized));
|
if (r){
|
||||||
|
sysBag.add(r.trigger(ResourceTrigger.SystemInitialized));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sysBag.seal();
|
sysBag.seal();
|
||||||
|
|||||||
@@ -211,9 +211,9 @@ export default class IndexedDBStore extends IStore
|
|||||||
}
|
}
|
||||||
|
|
||||||
rt.trigger(resource);
|
rt.trigger(resource);
|
||||||
}).error(ex => rt.triggerError(ex));
|
}).catch(ex => rt.triggerError(ex));
|
||||||
}).error(ex => rt.triggerError(ex));
|
}).catch(ex => rt.triggerError(ex));
|
||||||
}).error(ex => rt.triggerError(ex));
|
}).catch(ex => rt.triggerError(ex));
|
||||||
};
|
};
|
||||||
|
|
||||||
return rt;
|
return rt;
|
||||||
|
|||||||
@@ -210,9 +210,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
rt.trigger(resource);
|
rt.trigger(resource);
|
||||||
}).error(ex => rt.triggerError(ex));
|
}).catch(ex => rt.triggerError(ex));
|
||||||
}).error(ex => rt.triggerError(ex));
|
}).catch(ex => rt.triggerError(ex));
|
||||||
}).error(ex => rt.triggerError(ex));
|
}).catch(ex => rt.triggerError(ex));
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user