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

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;