mirror of
https://github.com/esiur/esiur-js.git
synced 2025-05-06 04:22:58 +00:00
Rename
This commit is contained in:
parent
7d2bcc60f7
commit
fb6276d6e5
@ -1,4 +1,4 @@
|
||||
# Esiur.JS
|
||||
Esiur Library for Javascript
|
||||
# Esyur.JS
|
||||
Esyur Library for Javascript
|
||||
|
||||
# Usage
|
@ -1,5 +1,5 @@
|
||||
exports.printMsg = function() {
|
||||
console.log("Esiur 1.1");
|
||||
console.log("Esyur 1.1");
|
||||
}
|
||||
|
||||
module.exports = { wh };
|
||||
|
1
src/.gitignore
vendored
Normal file
1
src/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules/
|
@ -36,7 +36,7 @@ export default class AsyncException extends Error
|
||||
|
||||
raise(type, code, message)
|
||||
{
|
||||
this.type = (type == 0 ? "Management" : "Execusion");
|
||||
this.type = type;
|
||||
this.code = code;
|
||||
|
||||
if (type == 0)
|
||||
@ -56,6 +56,6 @@ export default class AsyncException extends Error
|
||||
|
||||
toString()
|
||||
{
|
||||
return this.type + " (" + this.code + ") : " + this.message;
|
||||
return (this.type == 0 ? "Management" : "Exception") + " (" + this.code + ") : " + this.message;
|
||||
}
|
||||
}
|
@ -30,13 +30,21 @@ import AsyncException from './AsyncException.js';
|
||||
|
||||
export default class AsyncReply extends Promise
|
||||
{
|
||||
then(callback)
|
||||
then(callback, onError)
|
||||
{
|
||||
this.callbacks.push(callback);
|
||||
|
||||
if (this.ready)
|
||||
callback(this.result, this);
|
||||
|
||||
if (callback != undefined)
|
||||
{
|
||||
this.callbacks.push(callback);
|
||||
|
||||
if (this.ready)
|
||||
callback(this.result, this);
|
||||
}
|
||||
|
||||
if (onError != undefined)
|
||||
{
|
||||
this.error(onError);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -46,11 +54,6 @@ export default class AsyncReply extends Promise
|
||||
this.then(callback);
|
||||
}
|
||||
|
||||
// Alias for error()
|
||||
catch(callback)
|
||||
{
|
||||
return this.error(callback);
|
||||
}
|
||||
|
||||
error(callback)
|
||||
{
|
||||
@ -103,7 +106,7 @@ export default class AsyncReply extends Promise
|
||||
this.exception.raise(type, code, message);
|
||||
|
||||
if (this.errorCallbacks.length == 0)
|
||||
throw this.exception;
|
||||
throw this.exception;
|
||||
else
|
||||
for(var i = 0; i < this.errorCallbacks.length; i++)
|
||||
this.errorCallbacks[i](this.exception, this);
|
||||
|
@ -200,7 +200,7 @@ export default class Codec {
|
||||
}
|
||||
|
||||
static parseResource(data, offset) {
|
||||
return Warehouse.get(data.getUint32(offset));
|
||||
return Warehouse.getById(data.getUint32(offset));
|
||||
}
|
||||
|
||||
static parseDistributedResource(data, offset, connection) {
|
||||
@ -210,7 +210,7 @@ export default class Codec {
|
||||
// find the object
|
||||
var iid = data.getUint32(offset);
|
||||
|
||||
return connection.fetch(iid);// Warehouse.Get(iid);
|
||||
return connection.fetch(iid);// Warehouse.getById(iid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -241,7 +241,7 @@ export default class Codec {
|
||||
previous = new AsyncReply(null);
|
||||
else if (result == ResourceComparisonResult.Local)
|
||||
{
|
||||
previous = Warehouse.get(data.getUint32(offset));
|
||||
previous = Warehouse.getById(data.getUint32(offset));
|
||||
offset += 4;
|
||||
}
|
||||
else if (result == ResourceComparisonResult.Distributed)
|
||||
@ -269,7 +269,7 @@ export default class Codec {
|
||||
}
|
||||
else if (result == ResourceComparisonResult.Local)
|
||||
{
|
||||
current = Warehouse.get(data.getUint32(offset));
|
||||
current = Warehouse.getById(data.getUint32(offset));
|
||||
offset += 4;
|
||||
}
|
||||
else if (result == ResourceComparisonResult.Distributed)
|
||||
@ -766,7 +766,7 @@ static isLocalResource(resource, connection) {
|
||||
|
||||
|
||||
|
||||
static getDataType(value) {
|
||||
static getDataType(value, connection) {
|
||||
switch (typeof value) {
|
||||
case "number":
|
||||
// float or ?
|
||||
|
@ -68,9 +68,17 @@ import { ResourceTrigger } from '../../Resource/IResource.js';
|
||||
|
||||
export default class DistributedConnection extends IStore {
|
||||
|
||||
|
||||
send(data) {
|
||||
//console.log("Send", data.length);
|
||||
this.socket.send(data.buffer);
|
||||
|
||||
if (this.holdSending)
|
||||
{
|
||||
//console.log("hold ", data.length);
|
||||
this.sendBuffer.writeAll(data);
|
||||
}
|
||||
else
|
||||
//console.log("Send", data.length);
|
||||
this.socket.send(data.buffer);
|
||||
}
|
||||
|
||||
sendParams(doneReply) {
|
||||
@ -516,6 +524,25 @@ export default class DistributedConnection extends IStore {
|
||||
}
|
||||
}
|
||||
|
||||
hold()
|
||||
{
|
||||
this.holdSending = true;
|
||||
}
|
||||
|
||||
unhold()
|
||||
{
|
||||
if (this.holdSending)
|
||||
{
|
||||
var msg = this.sendBuffer.read();
|
||||
|
||||
if (msg == null || msg.length == 0)
|
||||
return;
|
||||
|
||||
this.socket.send(msg);
|
||||
this.holdSending = false;
|
||||
}
|
||||
}
|
||||
|
||||
trigger(trigger)
|
||||
{
|
||||
if (trigger == ResourceTrigger.Open)
|
||||
@ -576,9 +603,10 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
self.lastAction = new Date();
|
||||
|
||||
self.hold();
|
||||
while (this.networkBuffer.available > 0 && !this.networkBuffer.protected)
|
||||
self.receive(this.networkBuffer);
|
||||
|
||||
self.unhold();
|
||||
|
||||
};
|
||||
|
||||
@ -873,7 +901,7 @@ export default class DistributedConnection extends IStore {
|
||||
var self = this;
|
||||
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (r != null) {
|
||||
|
||||
if (r.instance.applicable(self.session, ActionType.Attach, null) == Ruling.Denied)
|
||||
@ -916,7 +944,7 @@ export default class DistributedConnection extends IStore {
|
||||
IIPRequestReattachResource(callback, resourceId, resourceAge) {
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (res != null) {
|
||||
r.instance.on("ResourceEventOccurred", self.instance_eventOccurred, self);
|
||||
r.instance.on("ResourceModified", self.instance_propertyModified, self);
|
||||
@ -937,7 +965,7 @@ export default class DistributedConnection extends IStore {
|
||||
IIPRequestDetachResource(callback, resourceId) {
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (r != null) {
|
||||
r.instance.off("ResourceEventOccurred", self.instance_eventOccurred);
|
||||
r.instance.off("ResourceModified", self.instance_propertyModified);
|
||||
@ -955,7 +983,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
IIPRequestCreateResource(callback, storeId, parentId, content) {
|
||||
var self = this;
|
||||
Warehouse.get(storeId).then(function(store)
|
||||
Warehouse.getById(storeId).then(function(store)
|
||||
{
|
||||
if (store == null)
|
||||
{
|
||||
@ -976,7 +1004,7 @@ export default class DistributedConnection extends IStore {
|
||||
return;
|
||||
}
|
||||
|
||||
Warehouse.get(parentId).then(function(parent)
|
||||
Warehouse.getById(parentId).then(function(parent)
|
||||
{
|
||||
|
||||
// check security
|
||||
@ -1039,7 +1067,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
IIPRequestDeleteResource(callback, resourceId) {
|
||||
var self = this;
|
||||
Warehouse.get(resourceId).then(function(r)
|
||||
Warehouse.getById(resourceId).then(function(r)
|
||||
{
|
||||
if (r == null)
|
||||
{
|
||||
@ -1096,7 +1124,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (r != null)
|
||||
self.sendReply(IIPPacketAction.TemplateFromResourceId, callback)
|
||||
.addUint32(r.instance.template.content.length)
|
||||
@ -1113,7 +1141,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (r != null) {
|
||||
Codec.parseVarArray(content, 0, content.length, self).then(function (args) {
|
||||
var ft = r.instance.template.getFunctionTemplateByIndex(index);
|
||||
@ -1194,7 +1222,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (r != null) {
|
||||
Codec.parseStructure(content, 0, content.Length, self).then(function (namedArgs) {
|
||||
var ft = r.instance.template.getFunctionTemplateByIndex(index);
|
||||
@ -1282,7 +1310,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (r != null) {
|
||||
var pt = r.instance.template.getFunctionTemplateByIndex(index);
|
||||
if (pt != null) {
|
||||
@ -1312,7 +1340,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (r != null) {
|
||||
var pt = r.instance.template.getFunctionTemplateByIndex(index);
|
||||
if (pt != null) {
|
||||
@ -1343,7 +1371,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function (r) {
|
||||
Warehouse.getById(resourceId).then(function (r) {
|
||||
if (r != null) {
|
||||
|
||||
|
||||
@ -1399,7 +1427,7 @@ export default class DistributedConnection extends IStore {
|
||||
IIPRequestInquireResourceHistory(callback, resourceId, fromDate, toDate)
|
||||
{
|
||||
var self = this;
|
||||
Warehouse.get(resourceId).then(function(r)
|
||||
Warehouse.getById(resourceId).then(function(r)
|
||||
{
|
||||
if (r != null)
|
||||
{
|
||||
@ -1678,7 +1706,7 @@ export default class DistributedConnection extends IStore {
|
||||
IIPRequestAddChild(callback, parentId, childId)
|
||||
{
|
||||
var self = this;
|
||||
Warehouse.get(parentId).then(function(parent)
|
||||
Warehouse.getById(parentId).then(function(parent)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
@ -1686,7 +1714,7 @@ export default class DistributedConnection extends IStore {
|
||||
return;
|
||||
}
|
||||
|
||||
Warehouse.get(childId).then(function(child)
|
||||
Warehouse.getById(childId).then(function(child)
|
||||
{
|
||||
if (child == null)
|
||||
{
|
||||
@ -1720,7 +1748,7 @@ export default class DistributedConnection extends IStore {
|
||||
{
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(parentId).then(function(parent)
|
||||
Warehouse.getById(parentId).then(function(parent)
|
||||
{
|
||||
if (parent == null)
|
||||
{
|
||||
@ -1728,7 +1756,7 @@ export default class DistributedConnection extends IStore {
|
||||
return;
|
||||
}
|
||||
|
||||
Warehouse.get(childId).then(function(child)
|
||||
Warehouse.getById(childId).then(function(child)
|
||||
{
|
||||
if (child == null)
|
||||
{
|
||||
@ -1761,7 +1789,7 @@ export default class DistributedConnection extends IStore {
|
||||
IIPRequestRenameResource(callback, resourceId, name)
|
||||
{
|
||||
var self = this;
|
||||
Warehouse.get(resourceId).then(function(resource)
|
||||
Warehouse.getById(resourceId).then(function(resource)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
@ -1784,7 +1812,7 @@ export default class DistributedConnection extends IStore {
|
||||
IIPRequestResourceChildren(callback, resourceId)
|
||||
{
|
||||
var self = this;
|
||||
Warehouse.get(resourceId).then(function(resource)
|
||||
Warehouse.getById(resourceId).then(function(resource)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
@ -1803,7 +1831,7 @@ export default class DistributedConnection extends IStore {
|
||||
{
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function(resource)
|
||||
Warehouse.getById(resourceId).then(function(resource)
|
||||
{
|
||||
if (resource == null)
|
||||
{
|
||||
@ -1819,7 +1847,7 @@ export default class DistributedConnection extends IStore {
|
||||
|
||||
IIPRequestClearAttributes(callback, resourceId, attributes, all = false)
|
||||
{
|
||||
Warehouse.get(resourceId).then(function(r)
|
||||
Warehouse.getById(resourceId).then(function(r)
|
||||
{
|
||||
if (r == null)
|
||||
{
|
||||
@ -1851,7 +1879,7 @@ export default class DistributedConnection extends IStore {
|
||||
{
|
||||
var self = this;
|
||||
|
||||
Warehouse.get(resourceId).then(function(r)
|
||||
Warehouse.getById(resourceId).then(function(r)
|
||||
{
|
||||
if (r == null)
|
||||
{
|
||||
|
@ -59,7 +59,8 @@ export default class IIPPacket
|
||||
{
|
||||
if (offset + needed > ends)
|
||||
{
|
||||
this.dataLengthNeeded = needed - (ends - this.originalOffset);
|
||||
this.dataLengthNeeded = needed - (ends - offset);
|
||||
// this.dataLengthNeeded = needed - (ends - this.originalOffset);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -54,7 +54,7 @@ export default class IResource extends IDestructible
|
||||
static getTemplate()
|
||||
{
|
||||
return {
|
||||
namespace: "Esiur",
|
||||
namespace: "Esyur",
|
||||
properties: [],
|
||||
functions: [],
|
||||
events: []
|
||||
|
@ -60,82 +60,78 @@ export class WH extends IEventHandler
|
||||
return res;
|
||||
}
|
||||
|
||||
getById(id)
|
||||
{
|
||||
return new AsyncReply(this.resources.item(id));
|
||||
}
|
||||
|
||||
get(id, attributes = null, parent = null, manager = null)
|
||||
{
|
||||
if (Number.isInteger(id))
|
||||
|
||||
var p = id.split('/');
|
||||
var res = null;
|
||||
|
||||
for(var s = 0; s < this.stores.length; s++)
|
||||
{
|
||||
//if (Warehouse.resources.contains(id))
|
||||
return new AsyncReply(this.resources.item(id));
|
||||
//else
|
||||
// return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var p = id.split('/');
|
||||
var res = null;
|
||||
|
||||
for(var s = 0; s < this.stores.length; s++)
|
||||
var d = this.stores.at(s);
|
||||
if (p[0] == d.instance.name)
|
||||
{
|
||||
var d = this.stores.at(s);
|
||||
if (p[0] == d.instance.name)
|
||||
var i = 1;
|
||||
res = d;
|
||||
while(p.length > i)
|
||||
{
|
||||
var i = 1;
|
||||
res = d;
|
||||
while(p.length > i)
|
||||
{
|
||||
var si = i;
|
||||
var si = i;
|
||||
|
||||
for (var r = 0; r < res.instance.children.length; r++)
|
||||
if (res.instance.children.item(r).instance.name == p[i])
|
||||
{
|
||||
i++;
|
||||
res = res.instance.children.item(r);
|
||||
break;
|
||||
}
|
||||
for (var r = 0; r < res.instance.children.length; r++)
|
||||
if (res.instance.children.item(r).instance.name == p[i])
|
||||
{
|
||||
i++;
|
||||
res = res.instance.children.item(r);
|
||||
break;
|
||||
}
|
||||
|
||||
if (si == i)
|
||||
// not found, ask the store
|
||||
return d.get(id.substring(p[0].length + 1));
|
||||
}
|
||||
|
||||
return new AsyncReply(res);
|
||||
}
|
||||
}
|
||||
|
||||
// Should we create a new store ?
|
||||
if (id.includes("://"))
|
||||
{
|
||||
var url = id.split("://", 2);
|
||||
var hostname = url[1].split("/", 2)[0];
|
||||
var pathname = url[1].split("/").splice(1).join("/");
|
||||
var handler;
|
||||
|
||||
var rt = new AsyncReply();
|
||||
var self = this;
|
||||
|
||||
if (handler = this.protocols.item(url[0]))
|
||||
{
|
||||
var store = handler();
|
||||
this.put(store, url[0] + "://" + hostname, null, parent, null, 0, manager, attributes);
|
||||
store.trigger(ResourceTrigger.Open).then(x=>{
|
||||
if (pathname.length > 0 && pathname != "")
|
||||
store.get(pathname).then(r=>{
|
||||
rt.trigger(r);
|
||||
}).error(e => rt.triggerError(e));
|
||||
else
|
||||
rt.trigger(store);
|
||||
|
||||
}).error(e => {
|
||||
rt.triggerError(e);
|
||||
self.remove(store);
|
||||
});
|
||||
if (si == i)
|
||||
// not found, ask the store
|
||||
return d.get(id.substring(p[0].length + 1));
|
||||
}
|
||||
|
||||
return rt;
|
||||
return new AsyncReply(res);
|
||||
}
|
||||
}
|
||||
|
||||
// Should we create a new store ?
|
||||
if (id.includes("://"))
|
||||
{
|
||||
var url = id.split("://", 2);
|
||||
var hostname = url[1].split("/", 2)[0];
|
||||
var pathname = url[1].split("/").splice(1).join("/");
|
||||
var handler;
|
||||
|
||||
var rt = new AsyncReply();
|
||||
var self = this;
|
||||
|
||||
if (handler = this.protocols.item(url[0]))
|
||||
{
|
||||
var store = handler();
|
||||
this.put(store, url[0] + "://" + hostname, null, parent, null, 0, manager, attributes);
|
||||
store.trigger(ResourceTrigger.Open).then(x=>{
|
||||
if (pathname.length > 0 && pathname != "")
|
||||
store.get(pathname).then(r=>{
|
||||
rt.trigger(r);
|
||||
}).error(e => rt.triggerError(e));
|
||||
else
|
||||
rt.trigger(store);
|
||||
|
||||
}).error(e => {
|
||||
rt.triggerError(e);
|
||||
self.remove(store);
|
||||
});
|
||||
}
|
||||
|
||||
return new AsyncReply(null);
|
||||
return rt;
|
||||
}
|
||||
|
||||
return new AsyncReply(null);
|
||||
}
|
||||
|
||||
|
||||
|
2
src/package-lock.json
generated
2
src/package-lock.json
generated
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "esiur",
|
||||
"name": "esyur",
|
||||
"version": "1.2.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
|
@ -1,21 +1,21 @@
|
||||
{
|
||||
"name": "esiur",
|
||||
"name": "Esyur",
|
||||
"version": "1.3.0",
|
||||
"description": "Distributed Object Framework",
|
||||
"main": "esiur.js",
|
||||
"main": "Esyur.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/esiur/esiur-js.git"
|
||||
"url": "git+https://github.com/esyur/esyur-js.git"
|
||||
},
|
||||
"author": "Ahmed Zamil",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/esiur/esiur-js/issues"
|
||||
"url": "https://github.com/esyur/esyur-js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/esiur/esiur-js#readme",
|
||||
"homepage": "https://github.com/esyur/esyur-js#readme",
|
||||
"dependencies": {
|
||||
"ws": "^6.2.0"
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ class MyStore extends IStore
|
||||
|
||||
async function load()
|
||||
{
|
||||
window.x = await wh.get("iip://localhost:5001/db/my", {username: "demo", password: "1234"});
|
||||
// window.x = await wh.get("iip://localhost:5001/db/my", {username: "demo", password: "1234"});
|
||||
window.x = await wh.get("iip://chat.go.iq:5001/sys/hd", {username: "admin", password: "delta"});
|
||||
|
||||
console.log(window.x);
|
||||
}
|
||||
|
@ -55,7 +55,7 @@
|
||||
|
||||
<script src="/iui-js/iui.js"></script>
|
||||
|
||||
<script src="viewers/Esiur.Stores.MemoryStore.js"></script>
|
||||
<script src="viewers/Esyur.Stores.MemoryStore.js"></script>
|
||||
|
||||
<script src="js/browser.js"></script>
|
||||
<script src="js/app.js"></script>
|
||||
|
@ -1,4 +1,4 @@
|
||||
class Esiur_Stores_MemoryStore extends IUIWidget
|
||||
class Esyur_Stores_MemoryStore extends IUIWidget
|
||||
{
|
||||
constuctor()
|
||||
{
|
||||
@ -6,4 +6,4 @@ class Esiur_Stores_MemoryStore extends IUIWidget
|
||||
}
|
||||
}
|
||||
|
||||
IUI.module("Esiur.Stores.MemoryStore", Esiur_Stores_MemoryStore);
|
||||
IUI.module("Esyur.Stores.MemoryStore", Esyur_Stores_MemoryStore);
|
Loading…
x
Reference in New Issue
Block a user