2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-05-06 04:22:58 +00:00
This commit is contained in:
Esiur Project 2022-09-03 15:15:24 +03:00
parent 93ed4edcbd
commit 87e04c37ac
19 changed files with 162 additions and 565 deletions

View File

@ -4,13 +4,13 @@ if (process.argv.length == 2) {
console.log("Usage: <command> [arguments]");
console.log("");
console.log("Available commands:");
console.log("\tget-template\tGet a template from an IIP link.");
console.log("\tshell\tStart Node.js REPL with Esiur module loaded.");
console.log("\tversion: Print Esiur version.");
console.log("\tget-template\t\tGet a template from an IIP link.");
console.log("\tshell\t\tStart Node.js REPL with Esiur module loaded.");
console.log("\tversion\t\tPrint Esiur version.");
console.log("");
console.log("Global options:");
console.log("\t-u, --username\tAuthentication username");
console.log("\t-p, --password\tAuthentication password");
console.log("\t-u, --username\tAuthentication username.");
console.log("\t-p, --password\tAuthentication password.");
console.log("\t-d, --dir\tName of the directory to generate model inside.");
process.exit();
}
@ -52,10 +52,17 @@ else if (cmd == "get-template")
let getTemplate = async () => {
let Esiur = (await import('../src/esiur.js')).default;
await Esiur.Proxy.TemplateGenerator.getTemplate(url, dir, username, password, true);
process.exit();
}
getTemplate();
}
else if (cmd == "version")
{
var pkg = require('../package.json');
console.log(pkg.version);
}
function getOption(args, option, abbreviation) {
let index = args.indexOf(abbreviation);

Binary file not shown.

View File

@ -1,20 +0,0 @@
import Test_MyService from './Test.MyService.g.js';
import Test_MyGenericRecordOfTest_MyResource from './Test.MyGenericRecordOfTest_MyResource.g.js';
import Test_MyResource from './Test.MyResource.g.js';
import Test_MyRecord from './Test.MyRecord.g.js';
import Test_MyChildResource from './Test.MyChildResource.g.js';
import Test_SizeEnum from './Test.SizeEnum.g.js';
class MyChildRecord extends Test_MyRecord {
/* String */ ChildName;
static get template() {return new TemplateDescriber('Test.MyChildRecord', [
new Prop('Id', Esiur.Data.Int32, 'Int32', null),
new Prop('Name', String, 'String', null),
new Prop('Score', Esiur.Data.Float64, 'Double', null),
new Prop('ChildName', String, 'String', null)],
Test_MyRecord, 0, null);
}
}

View File

@ -1,37 +0,0 @@
import Test_MyService from './Test.MyService.g.js';
import Test_MyGenericRecordOfTest_MyResource from './Test.MyGenericRecordOfTest_MyResource.g.js';
import Test_MyResource from './Test.MyResource.g.js';
import Test_MyRecord from './Test.MyRecord.g.js';
import Test_MyChildRecord from './Test.MyChildRecord.g.js';
import Test_SizeEnum from './Test.SizeEnum.g.js';
export default class MyChildResource extends Test_MyResource {
/* Esiur.Data.Int32 */ Hell2o(/* String */ childName) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({new Esiur.Data.UInt8(0) :childName});
var rt = new Esiur.Core.AsyncReply();
this._invoke(2, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt; }
/* String */ HelloChild() {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({});
var rt = new Esiur.Core.AsyncReply();
this._invoke(3, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt; }
/* String */ get ChildName() { return this._get(2); }
set ChildName(/* String */ value) { this._set(2, value); }
static get template() {return new Esiur.Resource.Template.TemplateDescriber('Test', [
new Esiur.Resource.Template.Prop('CategoryId', Esiur.Data.Int32, 'Int32', null),
new Esiur.Resource.Template.Prop('Description', String, 'Comment', null),
new Esiur.Resource.Template.Prop('ChildName', String, 'String', null),
new Esiur.Resource.Template.Func('Hello', String, [], '() -> String'),
new Esiur.Resource.Template.Func('HelloParent', String, [], '() -> String'),
new Esiur.Resource.Template.Func('Hell2o', Esiur.Data.Int32, [new Esiur.Resource.Template.Arg('childName', String, false)], '([String] childName) -> Int32'),
new Esiur.Resource.Template.Func('HelloChild', String, [], '() -> String')],
Test_MyResource, 0, null, Esiur.Data.Guid.parse('a884cf07481805fe97e6713175a99320'), 'MyChildResource');
}
}
new Esiur.Resource.Template.TypeTemplate(MyChildResource, true);

View File

@ -1,26 +0,0 @@
import Test_MyService from './Test.MyService.g.js';
import Test_MyResource from './Test.MyResource.g.js';
import Test_MyRecord from './Test.MyRecord.g.js';
import Test_MyChildRecord from './Test.MyChildRecord.g.js';
import Test_MyChildResource from './Test.MyChildResource.g.js';
import Test_SizeEnum from './Test.SizeEnum.g.js';
class MyGenericRecordOfTest_MyResource extends IRecord {
/* Esiur.Data.Int32 */ Needed;
/* TypedList.of(Test_MyResource) */ Results;
/* Esiur.Data.Int32 */ Start;
/* Esiur.Data.Int32 */ Total;
static get template() {return new TemplateDescriber('Test.MyGenericRecordOfTest_MyResource', [
new Prop('Needed', Esiur.Data.Int32, 'Int32', null),
new Prop('Results', TypedList.of(Test_MyResource), 'MyResource[]', null),
new Prop('Start', Esiur.Data.Int32, 'Int32', null),
new Prop('Total', Esiur.Data.Int32, 'Int32', null)],
undefined, 0, null);
}
}

View File

@ -1,23 +0,0 @@
import Test_MyService from './Test.MyService.g.js';
import Test_MyGenericRecordOfTest_MyResource from './Test.MyGenericRecordOfTest_MyResource.g.js';
import Test_MyResource from './Test.MyResource.g.js';
import Test_MyChildRecord from './Test.MyChildRecord.g.js';
import Test_MyChildResource from './Test.MyChildResource.g.js';
import Test_SizeEnum from './Test.SizeEnum.g.js';
class MyRecord extends IRecord {
/* Esiur.Data.Int32 */ Id;
/* String */ Name;
/* Esiur.Data.Float64 */ Score;
static get template() {return new TemplateDescriber('Test.MyRecord', [
new Prop('Id', Esiur.Data.Int32, 'Int32', null),
new Prop('Name', String, 'String', null),
new Prop('Score', Esiur.Data.Float64, 'Double', null)],
undefined, 0, null);
}
}

View File

@ -1,36 +0,0 @@
import Test_MyService from './Test.MyService.g.js';
import Test_MyGenericRecordOfTest_MyResource from './Test.MyGenericRecordOfTest_MyResource.g.js';
import Test_MyRecord from './Test.MyRecord.g.js';
import Test_MyChildRecord from './Test.MyChildRecord.g.js';
import Test_MyChildResource from './Test.MyChildResource.g.js';
import Test_SizeEnum from './Test.SizeEnum.g.js';
export default class MyResource extends Esiur.Net.IIP.DistributedResource {
/* String */ Hello() {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({});
var rt = new Esiur.Core.AsyncReply();
this._invoke(0, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt; }
/* String */ HelloParent() {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({});
var rt = new Esiur.Core.AsyncReply();
this._invoke(1, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt; }
/* Esiur.Data.Int32 */ get CategoryId() { return this._get(0); }
set CategoryId(/* Esiur.Data.Int32 */ value) { this._set(0, value); }
/* String */ get Description() { return this._get(1); }
set Description(/* String */ value) { this._set(1, value); }
static get template() {return new Esiur.Resource.Template.TemplateDescriber('Test', [
new Esiur.Resource.Template.Prop('CategoryId', Esiur.Data.Int32, 'Int32', null),
new Esiur.Resource.Template.Prop('Description', String, 'Comment', null),
new Esiur.Resource.Template.Func('Hello', String, [], '() -> String'),
new Esiur.Resource.Template.Func('HelloParent', String, [], '() -> String')],
null, 0, "A\nB\nC\nD", Esiur.Data.Guid.parse('99ce4d8acdf8ab959b8328d636b98ba9'), 'MyResource');
}
}
new Esiur.Resource.Template.TypeTemplate(MyResource, true);

View File

@ -1,268 +0,0 @@
import Test_MyGenericRecordOfTest_MyResource from './Test.MyGenericRecordOfTest_MyResource.g.js';
import Test_MyResource from './Test.MyResource.g.js';
import Test_MyRecord from './Test.MyRecord.g.js';
import Test_MyChildRecord from './Test.MyChildRecord.g.js';
import Test_MyChildResource from './Test.MyChildResource.g.js';
import Test_SizeEnum from './Test.SizeEnum.g.js';
export default class MyService extends Esiur.Net.IIP.DistributedResource {
/* TypedList.of(Esiur.Data.Nullable.of(TypedMap.of(Esiur.Data.Int32,Esiur.Data.Nullable.of(String)))) */ AsyncHello() {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({});
var rt = new Esiur.Core.AsyncReply();
this._invoke(0, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Object */ Connection(/* Object */ a1,/* Esiur.Data.Int32 */ a2) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ (new Esiur.Data.UInt8(0)) : a1, new Esiur.Data.UInt8(1) : a2 });
var rt = new Esiur.Core.AsyncReply();
this._invoke(1, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Object */ ConnectionOptional(/* Object */ a1,/* Esiur.Data.Int32 */ a2,/* Esiur.Data.Nullable.of(String) */ a3 = null) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ new Esiur.Data.UInt8(0) : a1, new Esiur.Data.UInt8(1) : a2 });
if (a3 != null) args.set(new Esiur.Data.UInt8(2), a3);
var rt = new Esiur.Core.AsyncReply();
this._invoke(2, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Test_MyGenericRecordOfTest_MyResource */ GetGenericRecord() {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({});
var rt = new Esiur.Core.AsyncReply();
this._invoke(3, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Tuple.of(Object,Object) */ GetTuple2(/* Esiur.Data.Int32 */ a1,/* String */ a2) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ new Esiur.Data.UInt8(0) : a1, new Esiur.Data.UInt8(1) : a2 });
var rt = new Esiur.Core.AsyncReply();
this._invoke(4, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Tuple.of(Object,Object,Object) */ GetTuple3(/* Esiur.Data.Int32 */ a1,/* String */ a2,/* Esiur.Data.Float64 */ a3) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ new Esiur.Data.UInt8(0) : a1, new Esiur.Data.UInt8(1) : a2, new Esiur.Data.UInt8(2) : a3 });
var rt = new Esiur.Core.AsyncReply();
this._invoke(5, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Tuple.of(Object,Object,Object,Object) */ GetTuple4(/* Esiur.Data.Int32 */ a1,/* String */ a2,/* Esiur.Data.Float64 */ a3,/* Boolean */ a4) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ new Esiur.Data.UInt8(0) : a1, new Esiur.Data.UInt8(1) : a2, new Esiur.Data.UInt8(2) : a3, new Esiur.Data.UInt8(3) : a4 });
var rt = new Esiur.Core.AsyncReply();
this._invoke(6, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Object */ InvokeEvents(/* String */ msg) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ new Esiur.Data.UInt8(0) : msg });
var rt = new Esiur.Core.AsyncReply();
this._invoke(7, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Esiur.Data.Float64 */ Optional(/* Object */ a1,/* Esiur.Data.Int32 */ a2,/* Esiur.Data.Nullable.of(String) */ a3 = null,/* Esiur.Data.Nullable.of(String) */ a4 = null) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ new Esiur.Data.UInt8(0) : a1, new Esiur.Data.UInt8(1) : a2 });
if (a3 != null) args.set(new Esiur.Data.UInt8(2), a3);
if (a4 != null) args.set(new Esiur.Data.UInt8(3), a4);
var rt = new Esiur.Core.AsyncReply();
this._invoke(8, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Test_MyRecord */ SendRecord(/* Test_MyRecord */ record) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ new Esiur.Data.UInt8(0) : record });
var rt = new Esiur.Core.AsyncReply();
this._invoke(9, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
static /* String */ staticFunction(connection, /* String */ name) {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({ new Esiur.Data.UInt8(0) : name });
var rt = new Esiur.Core.AsyncReply();
connection.staticCall(Guid.parse('c4250e9a35c707e9280c7ff2f46d3654'), 10, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* Object */ Void() {
var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))({});
var rt = new Esiur.Core.AsyncReply();
this._invoke(11, args).then((x) => rt.trigger(x))
.error((x) => rt.triggerError(x))
.chunk((x) => rt.triggerChunk(x));
return rt;
}
/* TypedList.of(Boolean) */ get BooleanArray() { return this._get(1); }
set BooleanArray(/* TypedList.of(Boolean) */ value) { this._set(1, value); }
/* String */ get Char16() { return this._get(2); }
set Char16(/* String */ value) { this._set(2, value); }
/* TypedList.of(String) */ get Char16Array() { return this._get(3); }
set Char16Array(/* TypedList.of(String) */ value) { this._set(3, value); }
/* Test_MyChildRecord */ get ChildRecord() { return this._get(4); }
set ChildRecord(/* Test_MyChildRecord */ value) { this._set(4, value); }
/* Test_MyChildResource */ get ChildResource() { return this._get(5); }
set ChildResource(/* Test_MyChildResource */ value) { this._set(5, value); }
/* Test_SizeEnum */ get Enum() { return this._get(6); }
set Enum(/* Test_SizeEnum */ value) { this._set(6, value); }
/* Esiur.Data.Float128 */ get Float128() { return this._get(7); }
set Float128(/* Esiur.Data.Float128 */ value) { this._set(7, value); }
/* TypedList.of(Esiur.Data.Float128) */ get Float128Array() { return this._get(8); }
set Float128Array(/* TypedList.of(Esiur.Data.Float128) */ value) { this._set(8, value); }
/* Esiur.Data.Float32 */ get Float32() { return this._get(9); }
set Float32(/* Esiur.Data.Float32 */ value) { this._set(9, value); }
/* TypedList.of(Esiur.Data.Float32) */ get Float32Array() { return this._get(10); }
set Float32Array(/* TypedList.of(Esiur.Data.Float32) */ value) { this._set(10, value); }
/* Esiur.Data.Float64 */ get Float64() { return this._get(11); }
set Float64(/* Esiur.Data.Float64 */ value) { this._set(11, value); }
/* TypedList.of(Esiur.Data.Float64) */ get Float64Array() { return this._get(12); }
set Float64Array(/* TypedList.of(Esiur.Data.Float64) */ value) { this._set(12, value); }
/* Esiur.Data.Int16 */ get Int16() { return this._get(13); }
set Int16(/* Esiur.Data.Int16 */ value) { this._set(13, value); }
/* TypedList.of(Esiur.Data.Int16) */ get Int16Array() { return this._get(14); }
set Int16Array(/* TypedList.of(Esiur.Data.Int16) */ value) { this._set(14, value); }
/* TypedList.of(Esiur.Data.Int32) */ get Int32Array() { return this._get(15); }
set Int32Array(/* TypedList.of(Esiur.Data.Int32) */ value) { this._set(15, value); }
/* Esiur.Data.Int32 */ get Int32Prop() { return this._get(16); }
set Int32Prop(/* Esiur.Data.Int32 */ value) { this._set(16, value); }
/* Esiur.Data.Int64 */ get Int64() { return this._get(17); }
set Int64(/* Esiur.Data.Int64 */ value) { this._set(17, value); }
/* TypedList.of(Esiur.Data.Int64) */ get Int64Array() { return this._get(18); }
set Int64Array(/* TypedList.of(Esiur.Data.Int64) */ value) { this._set(18, value); }
/* Esiur.Data.Int8 */ get Int8() { return this._get(19); }
set Int8(/* Esiur.Data.Int8 */ value) { this._set(19, value); }
/* TypedList.of(Esiur.Data.Int8) */ get Int8Array() { return this._get(20); }
set Int8Array(/* TypedList.of(Esiur.Data.Int8) */ value) { this._set(20, value); }
/* TypedList.of(Esiur.Data.Int32) */ get IntList() { return this._get(21); }
set IntList(/* TypedList.of(Esiur.Data.Int32) */ value) { this._set(21, value); }
/* TypedMap.of(Esiur.Data.Int32,String) */ get IntStringMap() { return this._get(22); }
set IntStringMap(/* TypedMap.of(Esiur.Data.Int32,String) */ value) { this._set(22, value); }
/* undefined */ get Me() { return this._get(23); }
set Me(/* undefined */ value) { this._set(23, value); }
/* TypedList.of(Test_MyResource) */ get MyResources() { return this._get(24); }
set MyResources(/* TypedList.of(Test_MyResource) */ value) { this._set(24, value); }
/* Object */ get Object() { return this._get(25); }
set Object(/* Object */ value) { this._set(25, value); }
/* Esiur.Data.List */ get ObjectArray() { return this._get(26); }
set ObjectArray(/* Esiur.Data.List */ value) { this._set(26, value); }
/* Esiur.Data.Int32 */ get PropertyContext() { return this._get(27); }
set PropertyContext(/* Esiur.Data.Int32 */ value) { this._set(27, value); }
/* Test_MyRecord */ get Record() { return this._get(28); }
set Record(/* Test_MyRecord */ value) { this._set(28, value); }
/* TypedList.of(Esiur.Data.IRecord) */ get RecordsArray() { return this._get(29); }
set RecordsArray(/* TypedList.of(Esiur.Data.IRecord) */ value) { this._set(29, value); }
/* TypedList.of(Test_MyRecord) */ get RecordsList() { return this._get(30); }
set RecordsList(/* TypedList.of(Test_MyRecord) */ value) { this._set(30, value); }
/* Test_MyResource */ get Resource() { return this._get(31); }
set Resource(/* Test_MyResource */ value) { this._set(31, value); }
/* TypedList.of(Esiur.Resource.IResource) */ get Resources() { return this._get(32); }
set Resources(/* TypedList.of(Esiur.Resource.IResource) */ value) { this._set(32, value); }
/* TypedList.of(String) */ get StringArray() { return this._get(33); }
set StringArray(/* TypedList.of(String) */ value) { this._set(33, value); }
/* TypedMap.of(String,Object) */ get StringMap() { return this._get(34); }
set StringMap(/* TypedMap.of(String,Object) */ value) { this._set(34, value); }
/* String */ get Text() { return this._get(35); }
set Text(/* String */ value) { this._set(35, value); }
/* Date */ get Time() { return this._get(36); }
set Time(/* Date */ value) { this._set(36, value); }
/* Esiur.Data.UInt16 */ get UInt16() { return this._get(37); }
set UInt16(/* Esiur.Data.UInt16 */ value) { this._set(37, value); }
/* TypedList.of(Esiur.Data.UInt16) */ get UInt16Array() { return this._get(38); }
set UInt16Array(/* TypedList.of(Esiur.Data.UInt16) */ value) { this._set(38, value); }
/* Esiur.Data.UInt32 */ get UInt32() { return this._get(39); }
set UInt32(/* Esiur.Data.UInt32 */ value) { this._set(39, value); }
/* TypedList.of(Esiur.Data.UInt32) */ get UInt32Array() { return this._get(40); }
set UInt32Array(/* TypedList.of(Esiur.Data.UInt32) */ value) { this._set(40, value); }
/* Esiur.Data.UInt64 */ get UInt64() { return this._get(41); }
set UInt64(/* Esiur.Data.UInt64 */ value) { this._set(41, value); }
/* TypedList.of(Esiur.Data.UInt64) */ get UInt64Array() { return this._get(42); }
set UInt64Array(/* TypedList.of(Esiur.Data.UInt64) */ value) { this._set(42, value); }
/* TypedList.of(Esiur.Data.UInt8) */ get UInt8Array() { return this._get(43); }
set UInt8Array(/* TypedList.of(Esiur.Data.UInt8) */ value) { this._set(43, value); }
/* TypedList.of(Esiur.Data.Nullable.of(Esiur.Data.UInt8)) */ get UInt8ArrayNull() { return this._get(44); }
set UInt8ArrayNull(/* TypedList.of(Esiur.Data.Nullable.of(Esiur.Data.UInt8)) */ value) { this._set(44, value); }
/* Esiur.Data.Nullable.of(Esiur.Data.UInt8) */ get UInt8Null() { return this._get(45); }
set UInt8Null(/* Esiur.Data.Nullable.of(Esiur.Data.UInt8) */ value) { this._set(45, value); }
/* Esiur.Data.UInt8 */ get UInt8Test() { return this._get(46); }
set UInt8Test(/* Esiur.Data.UInt8 */ value) { this._set(46, value); }
static get template() {
return new Esiur.Resource.Template.TemplateDescriber('Test', [
new Esiur.Resource.Template.Prop('Boolean', Boolean, 'Boolean', null),
new Esiur.Resource.Template.Prop('BooleanArray', TypedList.of(Boolean), 'Boolean[]', null),
new Esiur.Resource.Template.Prop('Char16', String, 'Char', null),
new Esiur.Resource.Template.Prop('Char16Array', TypedList.of(String), 'Char[]', null),
new Esiur.Resource.Template.Prop('ChildRecord', Test_MyChildRecord, 'MyChildRecord', null),
new Esiur.Resource.Template.Prop('ChildResource', Test_MyChildResource, 'MyChildResource', null),
new Esiur.Resource.Template.Prop('Enum', Test_SizeEnum, 'SizeEnum', null),
new Esiur.Resource.Template.Prop('Float128', Esiur.Data.Float128, 'Decimal', null),
new Esiur.Resource.Template.Prop('Float128Array', TypedList.of(Esiur.Data.Float128), 'Decimal[]', null),
new Esiur.Resource.Template.Prop('Float32', Esiur.Data.Float32, 'Single', null),
new Esiur.Resource.Template.Prop('Float32Array', TypedList.of(Esiur.Data.Float32), 'Single[]', null),
new Esiur.Resource.Template.Prop('Float64', Esiur.Data.Float64, 'Double', null),
new Esiur.Resource.Template.Prop('Float64Array', TypedList.of(Esiur.Data.Float64), 'Double[]', null),
new Esiur.Resource.Template.Prop('Int16', Esiur.Data.Int16, 'Int16', null),
new Esiur.Resource.Template.Prop('Int16Array', TypedList.of(Esiur.Data.Int16), 'Int16[]', null),
new Esiur.Resource.Template.Prop('Int32Array', TypedList.of(Esiur.Data.Int32), 'Int32[]', null),
new Esiur.Resource.Template.Prop('Int32Prop', Esiur.Data.Int32, 'Int32', null),
new Esiur.Resource.Template.Prop('Int64', Esiur.Data.Int64, 'Int64', null),
new Esiur.Resource.Template.Prop('Int64Array', TypedList.of(Esiur.Data.Int64), 'Int64[]', null),
new Esiur.Resource.Template.Prop('Int8', Esiur.Data.Int8, 'SByte', null),
new Esiur.Resource.Template.Prop('Int8Array', TypedList.of(Esiur.Data.Int8), 'SByte[]', null),
new Esiur.Resource.Template.Prop('IntList', TypedList.of(Esiur.Data.Int32), 'List`1', null),
new Esiur.Resource.Template.Prop('IntStringMap', TypedMap.of(Esiur.Data.Int32, String), 'Map`2', null),
new Esiur.Resource.Template.Prop('Me', undefined, 'MyService', null),
new Esiur.Resource.Template.Prop('MyResources', TypedList.of(Test_MyResource), 'MyResource[]', null),
new Esiur.Resource.Template.Prop('Object', Object, 'Object', null),
new Esiur.Resource.Template.Prop('ObjectArray', Esiur.Data.List, 'Object[]', null),
new Esiur.Resource.Template.Prop('PropertyContext', Esiur.Data.Int32, 'DistributedPropertyContext`1', null),
new Esiur.Resource.Template.Prop('Record', Test_MyRecord, 'MyRecord', null),
new Esiur.Resource.Template.Prop('RecordsArray', TypedList.of(Esiur.Data.IRecord), 'IRecord[]', null),
new Esiur.Resource.Template.Prop('RecordsList', TypedList.of(Test_MyRecord), 'List`1', null),
new Esiur.Resource.Template.Prop('Resource', Test_MyResource, 'MyResource', null),
new Esiur.Resource.Template.Prop('Resources', TypedList.of(Esiur.Resource.IResource), 'IResource[]', null),
new Esiur.Resource.Template.Prop('StringArray', TypedList.of(String), 'String[]', null),
new Esiur.Resource.Template.Prop('StringMap', TypedMap.of(String, Object), 'Map`2', null),
new Esiur.Resource.Template.Prop('Text', String, 'String', null),
new Esiur.Resource.Template.Prop('Time', Date, 'DateTime', null),
new Esiur.Resource.Template.Prop('UInt16', Esiur.Data.UInt16, 'UInt16', null),
new Esiur.Resource.Template.Prop('UInt16Array', TypedList.of(Esiur.Data.UInt16), 'UInt16[]', null),
new Esiur.Resource.Template.Prop('UInt32', Esiur.Data.UInt32, 'UInt32', null),
new Esiur.Resource.Template.Prop('UInt32Array', TypedList.of(Esiur.Data.UInt32), 'UInt32[]', null),
new Esiur.Resource.Template.Prop('UInt64', Esiur.Data.UInt64, 'UInt64', null),
new Esiur.Resource.Template.Prop('UInt64Array', TypedList.of(Esiur.Data.UInt64), 'UInt64[]', null),
new Esiur.Resource.Template.Prop('UInt8Array', TypedList.of(Esiur.Data.UInt8), 'Byte[]', null),
new Esiur.Resource.Template.Prop('UInt8ArrayNull', TypedList.of(Esiur.Data.Nullable.of(Esiur.Data.UInt8)), 'Nullable`1[]', null),
new Esiur.Resource.Template.Prop('UInt8Null', Esiur.Data.Nullable.of(Esiur.Data.UInt8), 'Nullable`1?', null),
new Esiur.Resource.Template.Prop('UInt8Test', Esiur.Data.UInt8, 'Byte', null),
new Esiur.Resource.Template.Func('AsyncHello', TypedList.of(Esiur.Data.Nullable.of(TypedMap.of(Esiur.Data.Int32, Esiur.Data.Nullable.of(String)))), [], '() -> AsyncReply`1'),
new Esiur.Resource.Template.Func('Connection', Object, [new Esiur.Resource.Template.Arg('a1', Object, false), new Esiur.Resource.Template.Arg('a2', Esiur.Data.Int32, false)], '([Object] a1,[Int32] a2) -> Void'),
new Esiur.Resource.Template.Func('ConnectionOptional', Object, [new Esiur.Resource.Template.Arg('a1', Object, false), new Esiur.Resource.Template.Arg('a2', Esiur.Data.Int32, false), new Esiur.Resource.Template.Arg('a3', String, true)], '([Object] a1,[Int32] a2,[String] a3) -> Void'),
new Esiur.Resource.Template.Func('GetGenericRecord', Test_MyGenericRecordOfTest_MyResource, [], '() -> MyGenericRecord`1'),
new Esiur.Resource.Template.Func('GetTuple2', Tuple.of(Object, Object), [new Esiur.Resource.Template.Arg('a1', Esiur.Data.Int32, false), new Esiur.Resource.Template.Arg('a2', String, false)], '([Int32] a1,[String] a2) -> ValueTuple`2'),
new Esiur.Resource.Template.Func('GetTuple3', Tuple.of(Object, Object, Object), [new Esiur.Resource.Template.Arg('a1', Esiur.Data.Int32, false), new Esiur.Resource.Template.Arg('a2', String, false), new Esiur.Resource.Template.Arg('a3', Esiur.Data.Float64, false)], '([Int32] a1,[String] a2,[Double] a3) -> ValueTuple`3'),
new Esiur.Resource.Template.Func('GetTuple4', Tuple.of(Object, Object, Object, Object), [new Esiur.Resource.Template.Arg('a1', Esiur.Data.Int32, false), new Esiur.Resource.Template.Arg('a2', String, false), new Esiur.Resource.Template.Arg('a3', Esiur.Data.Float64, false), new Esiur.Resource.Template.Arg('a4', Boolean, false)], '([Int32] a1,[String] a2,[Double] a3,[Boolean] a4) -> ValueTuple`4'),
new Esiur.Resource.Template.Func('InvokeEvents', Object, [new Esiur.Resource.Template.Arg('msg', String, false)], '([String] msg) -> Void'),
new Esiur.Resource.Template.Func('Optional', Esiur.Data.Float64, [new Esiur.Resource.Template.Arg('a1', Object, false), new Esiur.Resource.Template.Arg('a2', Esiur.Data.Int32, false), new Esiur.Resource.Template.Arg('a3', String, true), new Esiur.Resource.Template.Arg('a4', String, true)], '([Object] a1,[Int32] a2,[String] a3,[String] a4) -> Double'),
new Esiur.Resource.Template.Func('SendRecord', Test_MyRecord, [new Esiur.Resource.Template.Arg('record', Test_MyRecord, false)], '([MyRecord] record) -> MyRecord'),
new Esiur.Resource.Template.Func('staticFunction', String, [new Esiur.Resource.Template.Arg('name', String, false)], '([String] name) -> String'),
new Esiur.Resource.Template.Func('Void', Object, [], '() -> Void'),
new Esiur.Resource.Template.Evt('ArrayEvent', Esiur.Data.List, false, null),
new Esiur.Resource.Template.Evt('StringEvent', String, false, null)],
null, 0, null, Esiur.Data.Guid.parse('c4250e9a35c707e9280c7ff2f46d3654'), 'MyService');
}
}
new Esiur.Resource.Template.TypeTemplate(MyService, true);

View File

@ -1,16 +0,0 @@
import Test_MyService from './Test.MyService.g.js';
import Test_MyGenericRecordOfTest_MyResource from './Test.MyGenericRecordOfTest_MyResource.g.js';
import Test_MyResource from './Test.MyResource.g.js';
import Test_MyRecord from './Test.MyRecord.g.js';
import Test_MyChildRecord from './Test.MyChildRecord.g.js';
import Test_MyChildResource from './Test.MyChildResource.g.js';
class SizeEnum extends IEnum {
static SizeEnum Large = SizeEnum(0, 1, 'Large');
static SizeEnum Medium = SizeEnum(1, 0, 'Medium');
static SizeEnum Small = SizeEnum(2, -10, 'Small');
static SizeEnum XLarge = SizeEnum(3, 22, 'XLarge');
static SizeEnum xSmall = SizeEnum(4, -11, 'xSmall');
SizeEnum([int index = 0, value, String name = '']) : super(index, value, name);TemplateDescriber get template => TemplateDescriber('Test.SizeEnum', constants: [Const('Large', getTypeOf<undefined>(), 1, null), Const('Medium', getTypeOf<undefined>(), 0, null), Const('Small', getTypeOf<undefined>(), -10, null), Const('XLarge', getTypeOf<undefined>(), 22, null), Const('xSmall', getTypeOf<undefined>(), -11, null)], annotation: null);
}

View File

@ -1,30 +0,0 @@
import 'dart:async';
import 'package:esiur/esiur.dart';
import 'Test.MyService.g.js' as myservice;import 'Test.MyGenericRecordOfTest_MyResource.g.js' as mygenericrecordoftest_myresource;import 'Test.MyResource.g.js' as myresource;import 'Test.MyRecord.g.js' as myrecord;import 'Test.MyChildRecord.g.js' as mychildrecord;import 'Test.MyChildResource.g.js' as mychildresource;import 'Test.SizeEnum.g.js' as sizeenum;
void init_333(){
Warehouse.defineType<myservice.MyService>(() => myservice.MyService(), RepresentationType(RepresentationTypeIdentifier.TypedResource, false, Guid.parse('')));
Warehouse.defineType<mygenericrecordoftest_myresource.MyGenericRecordOfTest_MyResource>(() => mygenericrecordoftest_myresource.MyGenericRecordOfTest_MyResource(), RepresentationType(RepresentationTypeIdentifier.TypedRecord, false, Guid.parse('')));
Warehouse.defineType<myresource.MyResource>(() => myresource.MyResource(), RepresentationType(RepresentationTypeIdentifier.TypedResource, false, Guid.parse('')));
Warehouse.defineType<myrecord.MyRecord>(() => myrecord.MyRecord(), RepresentationType(RepresentationTypeIdentifier.TypedRecord, false, Guid.parse('')));
Warehouse.defineType<mychildrecord.MyChildRecord>(() => mychildrecord.MyChildRecord(), RepresentationType(RepresentationTypeIdentifier.TypedRecord, false, Guid.parse('')));
Warehouse.defineType<mychildresource.MyChildResource>(() => mychildresource.MyChildResource(), RepresentationType(RepresentationTypeIdentifier.TypedResource, false, Guid.parse('')));
Warehouse.defineType<sizeenum.SizeEnum>(() => sizeenum.SizeEnum(), RepresentationType(RepresentationTypeIdentifier.Enum, false, Guid.parse('')));
Esiur.Resource.Warehouse.putTemplate(Esiur.Resource.Template.TypeTemplate.fromType(myservice.MyService));
Warehouse.putTemplate(TypeTemplate.fromType(mygenericrecordoftest_myresource.MyGenericRecordOfTest_MyResource));
Warehouse.putTemplate(TypeTemplate.fromType(myresource.MyResource));
Warehouse.putTemplate(TypeTemplate.fromType(myrecord.MyRecord));
Warehouse.putTemplate(TypeTemplate.fromType(mychildrecord.MyChildRecord));
Warehouse.putTemplate(TypeTemplate.fromType(mychildresource.MyChildResource));
Warehouse.putTemplate(TypeTemplate.fromType(sizeenum.SizeEnum));}

View File

@ -1,6 +1,6 @@
{
"name": "esiur",
"version": "2.1.4",
"version": "2.1.10",
"description": "Distributed Object Framework",
"main": "esiur.js",
"type": "module",

View File

@ -54,6 +54,10 @@ export default class DC extends Uint8Array
}
static guidToBytes(value){
return value.value;
}
static boolToBytes(value)
{
var rt = new DC(1);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 Ahmed Kh. Zamil
* Copyright (c) 2017-2022 Ahmed Kh. Zamil
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal

View File

@ -3,12 +3,12 @@ export default class Nullable {
static cache = { };
static getType(nullableType){
return nullableType.constructor.type;
return nullableType.constructor.underlyingType;
}
static of(type){
if (type.constructor.isNullable)
if (type.isNullable)
return type;
if (Nullable.cache[type] != null)
@ -16,7 +16,7 @@ export default class Nullable {
let c = class extends type{}
Object.defineProperty(c, "isNullable", {value: true});
Object.defineProperty(c, "type", {value: type});
Object.defineProperty(c, "underlyingType", {value: type});
Nullable.cache[type] = c;

View File

@ -110,6 +110,7 @@ TypeToIdentifierMap[Array] = RepresentationTypeIdentifier.List;
TypeToIdentifierMap[Map] = RepresentationTypeIdentifier.Map;
TypeToIdentifierMap[RecordArray] = RepresentationTypeIdentifier.RecordArray;
TypeToIdentifierMap[ResourceArray] = RepresentationTypeIdentifier.ResourceArray;
TypeToIdentifierMap[Object] = RepresentationTypeIdentifier.Dynamic;
const TupleIdentifierByLength = {
2: RepresentationTypeIdentifier.Tuple2,
@ -181,10 +182,10 @@ export default class RepresentationType {
if (type == null)
throw new Error("Type can't be null.");
let nullable = type.constructor.isNullable;
let nullable = type.isNullable;
if (nullable)
type = type.constructor.type; // original type
type = type.underlyingType; // original type
let identifier = TypeToIdentifierMap[type];
@ -208,19 +209,18 @@ export default class RepresentationType {
} else if (type.prototype instanceof TypedList) {
let elementType = RepresentationType.fromType(TypedList.getType(type));
let elementType = RepresentationType.fromType(type.elementType);
return new RepresentationType(RepresentationTypeIdentifier.TypedList, null, null, [elementType]);
} else if (type.prototype instanceof TypedMap) {
let subs = TypedMap.getTypes(type);
let keyType = RepresentationType.fromType(subs[0]);
let valueType = RepresentationType.fromType(subs[1]);
let keyType = RepresentationType.fromType(type.keyType);
let valueType = RepresentationType.fromType(type.valueType);
return new RepresentationType(RepresentationTypeIdentifier.TypedMap, null, null, [keyType, valueType]);
} else if (type.prototype instanceof Tuple) {
let subs = Tuple.gettypes(type).map(x=> RepresentationType.fromType(x));
let subs = type.subTypes.map(x => RepresentationType.fromType(x));
return new RepresentationType(TupleIdentifierByLength[subs.length], nullable, null, subs);
}

View File

@ -2,7 +2,7 @@ export default class Tuple extends Array {
static cache = {};
static getTypes(tuple){
return tuple.constructor.types;
return tuple.constructor.subTypes;
}
static of(){
@ -17,7 +17,7 @@ export default class Tuple extends Array {
let c = class extends Tuple{}
Object.defineProperty(c, "name", {value: types.map(x => x.name).join('') + "Tuple"});
Object.defineProperty(c, "types", {value: types});
Object.defineProperty(c, "subTypes", {value: types});
Tuple.cache[types] = c;

View File

@ -23,7 +23,7 @@ export default class TypedList extends Array
};
static getType(typedList){
return typedList.constructor.type;
return typedList.constructor.elementType;
}
static of(type){
@ -32,7 +32,7 @@ export default class TypedList extends Array
let c = class extends TypedList{}
Object.defineProperty(c, "name", {value: type.name + "List"});
Object.defineProperty(c, "type", {value: type});
Object.defineProperty(c, "elementType", {value: type});
TypedList.cache[type] = c;

View File

@ -56,16 +56,19 @@ export default class TemplateGenerator {
let rt = "";
let parentName;
let dependencies = [];
if (template.parentId != null) {
parentName = this._translateClassName(templates
let parentClassName = templates
.find((x) =>
(x.classId.valueOf() == template.parentId.valueOf()) &&
(x.type == TemplateType.Record))
.className);
rt += `class ${className} extends ${parentName} {\r\n`;
.className;
parentName = this._translateClassName(parentClassName);
dependencies.push(parentClassName);
rt += `export default class ${className} extends ${parentName} {\r\n`;
} else {
rt += `class ${className} extends IRecord { \r\n`;
rt += `export default class ${className} extends Esiur.Data.IRecord { \r\n`;
}
template.properties.forEach((p) => {
@ -76,36 +79,24 @@ export default class TemplateGenerator {
rt += "\r\n";
// rt += "deserialize(Map<String, dynamic> value) {");
// template.properties.forEach((p) {
// rt.writeln("${p.name} = value['${p.name}'];");
// });
//rt += "}\r\n";
// rt.writeln("Map<String, dynamic> serialize() {");
// rt.writeln("var rt = Map<String, dynamic>();");
// template.properties.forEach((p) {
// rt.writeln("rt['${p.name}'] = ${p.name};");
// });
// rt.writeln("return rt;");
// rt.writeln("}");
// add template
var descProps = template.properties
.map((p) => {
var ptTypeName = this.getTypeName(template, p.valueType, templates);
return `new Prop('${p.name}', ${ptTypeName}, ${this._escape(p.readAnnotation)}, ${this._escape(p.writeAnnotation)})`;
var ptTypeName = this.getTypeName(template, p.valueType, templates, dependencies);
return `new Esiur.Resource.Template.Prop('${p.name}', ${ptTypeName}, ${this._escape(p.readAnnotation)}, ${this._escape(p.writeAnnotation)})`;
});
rt += `\r\nstatic get template() {return new TemplateDescriber('${template.className}', [\r\n${descProps.join(',\r\n')}], \r\n${parentName}, ${template.version}, ${this.toLiteral(template.annotation)});\r\n}`;
let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.');
rt += `\r\nstatic get template() {return new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${descProps.join(',\r\n')}], \r\n${parentName}, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.Guid.parse('${template.classId.toString()}'), '${className}');\r\n}`;
rt += "\r\n}";
rt += `\r\nnew Esiur.Resource.Template.TypeTemplate(${className}, true);\r\n`
rt = this._getDependenciesImports(dependencies) + rt;
return rt;
}
@ -118,45 +109,54 @@ export default class TemplateGenerator {
return `/* ${this.getTypeName(forTemplate, representationType, templates)} */`;
}
static getTypeName(forTemplate, representationType, templates) {
static getTypeName(forTemplate, representationType, templates, dependencies) {
let name;
if (representationType.identifier == RepresentationTypeIdentifier.TypedResource) {
if (representationType.guid.valueOf() == forTemplate.classId.valueOf())
name = forTemplate.className.split('.').last;
else
name = this._translateClassName(templates
name = forTemplate.className.split('.').slice(-1)[0];
else {
let className = templates
.find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() &&
(x.type == TemplateType.Resource ||
x.type == TemplateType.Wrapper))
.className);
.className;
if (!dependencies?.includes(className)) dependencies?.push(className);
name = this._translateClassName(className);
}
} else if (representationType.identifier == RepresentationTypeIdentifier.TypedRecord) {
if (representationType.guid.valueOf() == forTemplate.classId.valueOf())
name = forTemplate.className.split('.').last;
else
name = this._translateClassName(templates
name = forTemplate.className.split('.').slice(-1)[0];
else {
let className = templates
.find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() &&
x.type == TemplateType.Record)
.className);
.className;
if (!dependencies?.includes(className)) dependencies?.push(className);
name = this._translateClassName(className);
}
} else if (representationType.identifier == RepresentationTypeIdentifier.Enum) {
if (representationType.guid.valueOf() == forTemplate.classId.valueOf())
name = forTemplate.className.split('.').last;
else
name = this._translateClassName(templates
name = forTemplate.className.split('.').slice(-1)[0];
else {
let className = templates
.find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() &&
x.type == TemplateType.Enum)
.className);
.className;
if (!dependencies?.includes(className)) dependencies?.push(className);
name = this._translateClassName(className);
}
} else if (representationType.identifier == RepresentationTypeIdentifier.TypedList)
name = "TypedList.of(" + this.getTypeName(forTemplate, representationType.subTypes[0], templates) + ")";
name = "Esiur.Data.TypedList.of(" + this.getTypeName(forTemplate, representationType.subTypes[0], templates, dependencies) + ")";
else if (representationType.identifier ==
RepresentationTypeIdentifier.TypedMap)
name = "TypedMap.of(" +
this.getTypeName(forTemplate, representationType.subTypes[0], templates) +
name = "Esiur.Data.TypedMap.of(" +
this.getTypeName(forTemplate, representationType.subTypes[0], templates, dependencies) +
"," +
this.getTypeName(forTemplate, representationType.subTypes[1], templates) +
this.getTypeName(forTemplate, representationType.subTypes[1], templates, dependencies) +
")";
else if (representationType.identifier ==
RepresentationTypeIdentifier.Tuple2 ||
@ -165,7 +165,7 @@ export default class TemplateGenerator {
representationType.identifier == RepresentationTypeIdentifier.Tuple5 ||
representationType.identifier == RepresentationTypeIdentifier.Tuple6 ||
representationType.identifier == RepresentationTypeIdentifier.Tuple7)
name = "Tuple.of(" + representationType.subTypes.map( x => this.getTypeName(x, templates)).join(',') + ")";
name = "Esiur.Data.Tuple.of(" + representationType.subTypes.map( x => this.getTypeName(forTemplate, x, templates, dependencies)).join(',') + ")";
else {
switch (representationType.identifier) {
case RepresentationTypeIdentifier.Dynamic:
@ -286,10 +286,11 @@ export default class TemplateGenerator {
}
});
imports += "\r\n";
imports += "\r\n\r\n";
return imports;
};
// make sources
templates.forEach(async (tmp) => {
console.log(`Generating '${tmp.className}'.`);
@ -297,17 +298,29 @@ export default class TemplateGenerator {
var source = "";
if (tmp.type == TemplateType.Resource) {
source = makeImports(tmp) + this.generateClass(tmp, templates, asyncSetters);
source = this.generateClass(tmp, templates, asyncSetters);
} else if (tmp.type == TemplateType.Record) {
source = makeImports(tmp) + this.generateRecord(tmp, templates);
source = this.generateRecord(tmp, templates);
} else if (tmp.type == TemplateType.Enum) {
source = makeImports(tmp) + this.generateEnum(tmp, templates);
source = this.generateEnum(tmp, templates);
}
fs.writeFileSync(filePath, source);
});
// make module
let modulePath = `${dstDir}/init.g.js`;
let module = makeImports() + `\r\nlet module = {}; \r\n`;
templates.forEach((tmp) => {
let typeName = tmp.className.split('.').join('_');
module += `Esiur.define(module, ${typeName}, '${tmp.className}');\r\n`;
});
module += "\r\nexport default module;";
fs.writeFileSync(modulePath, module);
return dstDir;
@ -321,46 +334,63 @@ export default class TemplateGenerator {
}
static generateEnum(template, templates) {
var className = template.className.split('.').slice(-1)[0];
var rt = "";
let className = template.className.split('.').slice(-1)[0];
let rt = "";
let dependencies = [];
rt += `class ${className} extends IEnum {\r\n`;
rt += `export default class ${className} extends Esiur.Data.IEnum {\r\n`;
template.constants.forEach((c) => {
rt += `static ${className} ${c.name} = ${className}(${c.index}, ${c.value}, '${c.name}');\r\n`;
rt += `static ${c.name} = new ${className}(${c.index}, ${c.value}, '${c.name}');\r\n`;
});
rt += "\r\n";
rt += `${className}([int index = 0, value, String name = '']) : super(index, value, name);`;
// add template
var descConsts = template.constants.map((p) => {
var ctTypeName = this.getTypeName(template, p.valueType, templates);
return `Const('${p.name}', getTypeOf<${ctTypeName}>(), ${p.value}, ${this._escape(p.annotation)})`;
}).join(', ');
var ctTypeName = this.getTypeName(template, p.valueType, templates, dependencies);
return `new Esiur.Resource.Template.Const('${p.name}', ${ctTypeName}, ${p.value}, ${this._escape(p.annotation)})`;
});
rt += `TemplateDescriber get template => TemplateDescriber('${template.className}', constants: [${descConsts}], annotation: ${this.toLiteral(template.annotation)});`;
let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.');
rt += `\r\nstatic get template() {return new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${descConsts.join(',\r\n')}], \r\n null, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.Guid.parse('${template.classId.toString()}'), '${className}');\r\n}`;
rt += "\r\n}";
rt += `\r\nnew Esiur.Resource.Template.TypeTemplate(${className}, true);\r\n`
rt = this._getDependenciesImports(dependencies) + rt;
return rt;
}
static _getDependenciesImports(dependencies){
let rt = "";
dependencies.forEach(className => {
rt += `import ${className.split('.').join('_')} from './${className}.g.js';\r\n`;
});
return rt + "\r\n";
}
static generateClass(template, templates, asyncSetters = true) {
let className = template.className.split('.').slice(-1)[0];
let parentName = null;
let rt = "";
let dependencies = [];
if (template.parentId != null) {
parentName = this._translateClassName(templates
let parentClassName = templates
.find((x) =>
(x.classId.valueOf() == template.parentId.valueOf()) &&
(x.type == TemplateType.Resource ||
x.type == TemplateType.Wrapper))
.className);
.className;
parentName = this._translateClassName(parentClassName);
dependencies.push(parentClassName);
rt += `export default class ${className} extends ${parentName} {\r\n`;
} else {
rt += `export default class ${className} extends Esiur.Net.IIP.DistributedResource {\r\n`;
@ -374,6 +404,10 @@ export default class TemplateGenerator {
// rt += "}\r\n";
template.constants.forEach((c) => {
var ctTypeName = this.getTypeName(template, c.valueType, templates, dependencies);
rt += `static ${c.name} = new ${ctTypeName}(${c.value});\r\n`;
});
template.functions.filter((f) => !f.inherited).forEach((f) => {
var rtTypeName = this.getDecoratedTypeName(template, f.returnType, templates);
@ -382,7 +416,7 @@ export default class TemplateGenerator {
if (f.isStatic) {
//rt += `static AsyncReply<${rtTypeName}> ${f.name}(DistributedConnection connection`;
rt += `static ${rtTypeName} ${f.name}(connection`;
rt += `${rtTypeName} \r\n static ${f.name}(connection`;
if (positionalArgs.length > 0)
rt += `, ${positionalArgs.map((a) => this.getDecoratedTypeName(template, a.type, templates) + " " + a.name).join(',')}`;
@ -392,7 +426,7 @@ export default class TemplateGenerator {
}
} else {
//rt += `AsyncReply<${rtTypeName}> ${f.name}(`;
rt += `${rtTypeName} ${f.name}(`;
rt += `${rtTypeName} \r\n ${f.name}(`;
if (positionalArgs.length > 0)
rt += `${positionalArgs.map((a) => this.getDecoratedTypeName(template, a.type, templates) + " " + a.name).join(',')}`;
@ -407,8 +441,8 @@ export default class TemplateGenerator {
rt += ") {\r\n";
// var argsMap = new (TypedMap.of(UInt8, Object));
rt += "var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))(";
rt += `{${positionalArgs.map((e) => "new Esiur.Data.UInt8(" + e.index.toString() + ') :' + e.name).join(',')}});\r\n`;
rt += "var args = new (Esiur.Data.TypedMap.of(Esiur.Data.UInt8, Object))();\r\n";
rt += `${positionalArgs.map((e) => `args.set(new Esiur.Data.UInt8(${e.index.toString()}), ${e.name});`).join('\r\n')}\r\n`;
optionalArgs.forEach((a) => {
rt += `if (${a.name} != null) args.set(new Esiur.Data.UInt8(${a.index}), ${a.name});\r\n`;
@ -424,7 +458,7 @@ export default class TemplateGenerator {
rt += `.then((x) => rt.trigger(x))\r\n`;
rt += `.error((x) => rt.triggerError(x))\r\n`;
rt += `.chunk((x) => rt.triggerChunk(x));\r\n`;
rt += `return rt; }\r\n`;
rt += `return rt; \r\n}\r\n`;
});
template.properties.filter((p) => !p.inherited).forEach((p) => {
@ -449,16 +483,16 @@ export default class TemplateGenerator {
// add template
var descProps = template.properties //.where((p) => !p.inherited)
.map((p) => {
var ptTypeName = this.getTypeName(template, p.valueType, templates);
var ptTypeName = this.getTypeName(template, p.valueType, templates, dependencies);
return `new Esiur.Resource.Template.Prop('${p.name}', ${ptTypeName}, ${this._escape(p.readAnnotation)}, ${this._escape(p.writeAnnotation)})`;
});
var descFuncs = template.functions
.map((f) => {
var ftTypeName = this.getTypeName(template, f.returnType, templates);
var ftTypeName = this.getTypeName(template, f.returnType, templates, dependencies);
var args = f.args.map((a) => {
var atTypeName = this.getTypeName(template, a.type, templates);
var atTypeName = this.getTypeName(template, a.type, templates, dependencies);
return `new Esiur.Resource.Template.Arg('${a.name}', ${atTypeName}, ${a.optional})`;
}).join(', ');
@ -466,23 +500,30 @@ export default class TemplateGenerator {
});
var descEvents = template.events
//.where((e) => !e.inherited)
//.where((e) => !e.inherited) @REVIEW
.map((e) => {
var etTypeName = this.getTypeName(template, e.argumentType, templates);
var etTypeName = this.getTypeName(template, e.argumentType, templates, dependencies);
return `new Esiur.Resource.Template.Evt('${e.name}', ${etTypeName}, ${e.listenable}, ${this._escape(e.annotation)})`;
});
// constructor(namespace, members, parent, version = 0, annotation = null){
var descConsts = template.constants.map((p) => {
var ctTypeName = this.getTypeName(template, p.valueType, templates, dependencies);
return `new Esiur.Resource.Template.Const('${p.name}', ${ctTypeName}, ${p.value}, ${this._escape(p.annotation)})`;
});
let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.');
rt += `\r\nstatic get template() {return new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${[...descProps, ...descFuncs, ...descEvents].join(',\r\n')}], \r\n${parentName}, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.Guid.parse('${template.classId.toString()}'), '${className}');\r\n}`;
rt += `\r\nstatic get template() {return new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${[...descProps, ...descFuncs, ...descEvents, ...descConsts].join(',\r\n')}], \r\n${parentName}, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.Guid.parse('${template.classId.toString()}'), '${className}');\r\n}`;
rt += "\r\n}\r\n";
rt += `new Esiur.Resource.Template.TypeTemplate(${className}, true);\r\n`
rt += `\r\nnew Esiur.Resource.Template.TypeTemplate(${className}, true);\r\n`
rt = this._getDependenciesImports(dependencies) + rt;
return rt;
}
}

View File

@ -90,13 +90,15 @@ import { Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt1
import Tuple from './Data/Tuple.js';
import Nullable from './Data/Nullable.js';
import Void from './Data/Void.js';
import IEnum from './Data/IEnum.js';
import {TemplateDescriber, Prop, Func, Evt, Const, Arg} from './Resource/Template/TemplateDescriber.js';
const namespace = {
Core: { AsyncReply, AsyncException, AsyncQueue, ErrorType, ExceptionCode, IDestructible, IEventHandler, ProgressType},
Data: {AutoList, AutoMap, BinaryList, Codec, DC, TypedList, TypedMap, Guid, IRecord, KeyList, NotModified, ResourceArrayType,
PropertyValue, Record, ResourceArray, RepresentationType, RepresentationTypeIdentifier, TransmissionType, TransmissionTypeIdentifier,
Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128, Float32, Float64, Float128, Char16, Char8, Tuple,
Nullable, Void
Nullable, Void, IEnum
},
Net: {INetworkReceiver, NetworkBuffer, NetworkConnections, NetworkServer, NetworkSession, SendList,
IIP: {DistributedConnection, DistributedPropertyContext, DistributedResource, DistributedResourceQueueItem,
@ -109,7 +111,8 @@ const namespace = {
Resource: {CustomResourceEvent, Instance, IResource, IStore, Warehouse,
Template: {
ArgumentTemplate, EventTemplate, FunctionTemplate, MemberTemplate,
MemberType, PropertyTemplate, TemplateType, TypeTemplate
MemberType, PropertyTemplate, TemplateType, TypeTemplate,
TemplateDescriber, Prop, Func, Evt, Const, Arg
}
},
Security: {
@ -122,12 +125,9 @@ const namespace = {
Permissions: {ActionType, IPermissionsManager, Ruling},
},
Stores: {IndexedDBStore, MemoryStore},
Generated: {},
};
namespace.define = function(type, className) {
define: function(target, type, className) {
let sc = className.split('.');
let target = namespace.Generated;
for(let i = 0; i < sc.length; i++) {
if (target[sc[i]] == undefined)
@ -136,7 +136,8 @@ namespace.define = function(type, className) {
}
target[sc[sc.length - 1]] = type;
}
}
};
if (typeof window !== 'undefined')