2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-05-06 04:22:58 +00:00

Guid to UUID

This commit is contained in:
ahmed 2025-03-03 04:47:53 +03:00
parent 1fcde7fda6
commit 9c13c3e7ae
13 changed files with 575 additions and 379 deletions

File diff suppressed because it is too large Load Diff

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "esiur",
"version": "2.3.0",
"version": "2.3.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "esiur",
"version": "2.3.0",
"version": "2.3.3",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.20.7",

View File

@ -57,13 +57,13 @@ export default class BinaryList
return this;
}
addGuid(value) {
this.addDC(DC.guidToBytes(value));
addUUID(value) {
this.addDC(DC.uuidToBytes(value));
return this;
}
insertGuid(position, value) {
this.insertDC(position, DC.guidToBytes(value));
insertUUID(position, value) {
this.insertDC(position, DC.uuidToBytes(value));
return this;
}

View File

@ -27,7 +27,7 @@
"use strict";
import BinaryList from './BinaryList.js';
import Guid from './Guid.js';
import UUID from './UUID.js';
export const UNIX_EPOCH = 621355968000000000;
export const TWO_PWR_32 = (1 << 16) * (1 << 16);
@ -54,7 +54,7 @@ export default class DC extends Uint8Array
}
static guidToBytes(value){
static uuidToBytes(value){
return value.value;
}
@ -677,9 +677,9 @@ export default class DC extends Uint8Array
return rt;
}
getGuid(offset)
getUUID(offset)
{
return new Guid(this.clip(offset, 16));
return new UUID(this.clip(offset, 16));
/*
var d = this.getUint8Array(offset, 16);
@ -692,11 +692,11 @@ export default class DC extends Uint8Array
*/
}
getGuidArray(offset, length)
getUUIDArray(offset, length)
{
var rt = [];
for(var i = 0; i < length; i+=16)
rt.push(this.getGuid(offset+i));
rt.push(this.getUUID(offset+i));
return rt;
}

View File

@ -162,7 +162,7 @@ export default class DataDeserializer {
data, offset, length, connection, requestSequence) {
var reply = new AsyncReply();
var classId = data.getGuid(offset);
var classId = data.getUUID(offset);
offset += 16;
length -= 16;
@ -212,7 +212,7 @@ export default class DataDeserializer {
}
static enumParser(data, offset, length, connection, requestSequence) {
var classId = data.getGuid(offset);
var classId = data.getUUID(offset);
offset += 16;
var index = data[offset++];

View File

@ -143,7 +143,7 @@ export default class DataSerializer {
var rt = new BinaryList();
rt.addGuid(template.classId);
rt.addUUID(template.classId);
rt.addUint8(cts[0].index);
return new DataSerializerComposeResults(
@ -361,7 +361,7 @@ export default class DataSerializer {
return new DataSerializerComposeResults(
TransmissionTypeIdentifier.Null, new DC(0));
rt.addDC(DC.guidToBytes(template.classId));
rt.addDC(DC.uuidToBytes(template.classId));
for (let pt of template.properties) {
let propValue = value[pt.name];

View File

@ -141,11 +141,11 @@ export default class RepresentationType {
if (IdentifierToTypeMap[this.identifier] != undefined)
runtimeType = IdentifierToTypeMap[this.identifier]
if (this.identifier == RepresentationTypeIdentifier.TypedResource) {
runtimeType = Warehouse.getTemplateByClassId(this.guid, TemplateType.Resource)?.definedType;
runtimeType = Warehouse.getTemplateByClassId(this.uuid, TemplateType.Resource)?.definedType;
} else if (this.identifier == RepresentationTypeIdentifier.TypedRecord) {
runtimeType = Warehouse.getTemplateByClassId(this.guid, TemplateType.Record)?.definedType;
runtimeType = Warehouse.getTemplateByClassId(this.uuid, TemplateType.Record)?.definedType;
} else if (this.identifier == RepresentationTypeIdentifier.Enum) {
runtimeType = Warehouse.getTemplateByClassId(this.guid, TemplateType.Enum)?.definedType;
runtimeType = Warehouse.getTemplateByClassId(this.uuid, TemplateType.Enum)?.definedType;
} else if (this.identifier == RepresentationTypeIdentifier.TypedList){
let elementType = this.subTypes[0].getRuntimeType();
runtimeType = TypedList.of(elementType);
@ -171,7 +171,7 @@ export default class RepresentationType {
}
toNullable() {
return new RepresentationType(this.identifier, true, this.guid, this.subTypes);
return new RepresentationType(this.identifier, true, this.uuid, this.subTypes);
}
static get Void () { return new RepresentationType(RepresentationTypeIdentifier.Void, true, null, null);}
@ -232,10 +232,10 @@ export default class RepresentationType {
}
constructor(identifier, nullable, guid, subTypes) {
constructor(identifier, nullable, uuid, subTypes) {
this.identifier = identifier;
this.nullable = nullable;
this.guid = guid;
this.uuid = uuid;
this.subTypes = subTypes;
}
@ -247,7 +247,7 @@ export default class RepresentationType {
else
rt.addUint8(this.identifier);
if (this.guid != null) rt.addDC(DC.guidToBytes(this.guid));
if (this.uuid != null) rt.addDC(DC.uuidToBytes(this.uuid));
if (this.subTypes != null)
for (var i = 0; i < this.subTypes.length; i++)
@ -267,13 +267,13 @@ export default class RepresentationType {
let identifier = (header & 0x7F);
if ((header & 0x40) > 0) {
let hasGUID = (header & 0x4) > 0;
let hasUUID = (header & 0x4) > 0;
let subsCount = (header >> 3) & 0x7;
let guid = null;
let uuid = null;
if (hasGUID) {
guid = data.getGuid(offset);
if (hasUUID) {
uuid = data.getUUID(offset);
offset += 16;
}
@ -286,7 +286,7 @@ export default class RepresentationType {
}
return new RepresentationTypeParseResults(offset - oOffset,
new RepresentationType(identifier, nullable, guid, subs));
new RepresentationType(identifier, nullable, uuid, subs));
} else {
return new RepresentationTypeParseResults(
1, new RepresentationType(identifier, nullable, null, null));

View File

@ -26,7 +26,7 @@
import DC from './DC.js';
export default class Guid
export default class UUID
{
constructor(dc)
{
@ -39,7 +39,7 @@ export default class Guid
}
static parse(data) {
return new Guid(DC.fromHex(data, ''))
return new UUID(DC.fromHex(data, ''))
}
toString() {

View File

@ -3544,7 +3544,7 @@ export default class DistributedConnection extends IStore {
this.#sendParams()
.addUint8(0x40 | IIPPacketAction.StaticCall)
.addUint32(c)
.addGuid(classId)
.addUUID(classId)
.addUint8(index)
.addUint8Array(pb)
.done();

View File

@ -297,7 +297,7 @@ export default class IIPPacket
if (this.notEnough(offset, ends, 16))
return -this.dataLengthNeeded;
this.classId = data.getGuid(offset);
this.classId = data.getUUID(offset);
offset += 16;
}
else if (this.action == IIPPacketAction.TemplateFromResourceId)
@ -471,7 +471,7 @@ export default class IIPPacket
if (this.notEnough(offset, ends, 18))
return -this.dataLengthNeeded;
this.classId = data.getGuid(offset);
this.classId = data.getUUID(offset);
offset += 16;
this.methodIndex = data[offset++];
@ -495,7 +495,7 @@ export default class IIPPacket
if (this.notEnough(offset, ends, 26))
return -this.dataLengthNeeded;
this.classId = data.getGuid(offset);
this.classId = data.getUUID(offset);
offset += 16;
this.resourceAge = data.getUint64(offset);

View File

@ -90,7 +90,7 @@ export default class TemplateGenerator {
let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.');
rt += `\r\n\tstatic get template() {\r\n\t\treturn new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${descProps.join(',\r\n')}], \r\n\t\t\t${parentName}, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.Guid.parse('${template.classId.toString()}'), '${className}');\r\n\t}`;
rt += `\r\n\tstatic get template() {\r\n\t\treturn new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${descProps.join(',\r\n')}], \r\n\t\t\t${parentName}, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.UUID.parse('${template.classId.toString()}'), '${className}');\r\n\t}`;
rt += "\r\n}";
@ -112,36 +112,36 @@ export default class TemplateGenerator {
let name;
if (representationType.identifier == RepresentationTypeIdentifier.TypedResource) {
if (representationType.guid.valueOf() == forTemplate.classId.valueOf())
if (representationType.uuid.valueOf() == forTemplate.classId.valueOf())
name = forTemplate.className.split('.').slice(-1)[0];
else {
let className = templates
.find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() &&
x.classId.valueOf() == representationType.uuid.valueOf() &&
(x.type == TemplateType.Resource))
.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())
if (representationType.uuid.valueOf() == forTemplate.classId.valueOf())
name = forTemplate.className.split('.').slice(-1)[0];
else {
let className = templates
.find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() &&
x.classId.valueOf() == representationType.uuid.valueOf() &&
x.type == TemplateType.Record)
.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())
if (representationType.uuid.valueOf() == forTemplate.classId.valueOf())
name = forTemplate.className.split('.').slice(-1)[0];
else {
let className = templates
.find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() &&
x.classId.valueOf() == representationType.uuid.valueOf() &&
x.type == TemplateType.Enum)
.className;
if (!dependencies?.includes(className)) dependencies?.push(className);
@ -357,7 +357,7 @@ export default class TemplateGenerator {
let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.');
rt += `\r\n\tstatic get template() {\r\n\t\treturn new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${descConsts.join(',\r\n')}], \r\n\t\t\tnull, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.Guid.parse('${template.classId.toString()}'), '${className}');\r\n\t}`;
rt += `\r\n\tstatic get template() {\r\n\t\treturn new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${descConsts.join(',\r\n')}], \r\n\t\t\tnull, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.UUID.parse('${template.classId.toString()}'), '${className}');\r\n\t}`;
rt += "\r\n}";
@ -450,7 +450,7 @@ export default class TemplateGenerator {
//rt += `var rt = new AsyncReply<${rtTypeName}>();\r\n`;
rt += `\t\tvar rt = new Esiur.Core.AsyncReply();\r\n`;
if (f.isStatic) {
rt += `\t\tconnection.staticCall(Esiur.Data.Guid.parse('${template.classId.toString()}'), ${f.index}, args)\r\n`;
rt += `\t\tconnection.staticCall(Esiur.Data.UUID.parse('${template.classId.toString()}'), ${f.index}, args)\r\n`;
} else {
rt += `\t\tthis._invoke(${f.index}, args)\r\n`;
}
@ -516,7 +516,7 @@ export default class TemplateGenerator {
let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.');
rt += `\r\n\tstatic get template() {\r\n\t\treturn new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${[...descProps, ...descFuncs, ...descEvents, ...descConsts].join(',\r\n')}], \r\n\t\t\t${parentName}, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.Guid.parse('${template.classId.toString()}'), '${className}');\r\n\t}`;
rt += `\r\n\tstatic get template() {\r\n\t\treturn new Esiur.Resource.Template.TemplateDescriber('${namespace}', [\r\n${[...descProps, ...descFuncs, ...descEvents, ...descConsts].join(',\r\n')}], \r\n\t\t\t${parentName}, ${template.version}, ${this.toLiteral(template.annotation)}, Esiur.Data.UUID.parse('${template.classId.toString()}'), '${className}');\r\n\t}`;
rt += "\r\n}\r\n";

View File

@ -122,13 +122,18 @@ export default class TypeTemplate {
*/
static getTypeGuid(type) {
return this.getTypeGuidByName(type.template.namespace + "." + type.prototype.constructor.name);
static getTypeUUID(type) {
return this.getTypeUUIDByName(type.template.namespace + "." + type.prototype.constructor.name);
}
static getTypeGuidByName(typeName)
static getTypeUUIDByName(typeName)
{
return SHA256.compute(DC.stringToBytes(typeName)).getGuid(0);
let hash = SHA256.compute(DC.stringToBytes(typeName));
hash.setUint8(6, (hash.getUint8(6) & 0xF) | 0x80);
hash.setUint8(8, (hash.getUint8(8) & 0xF) | 0x80);
return hash.getUUID(0);
}
@ -259,9 +264,9 @@ export default class TypeTemplate {
let describer = type.template;
// set guid
// set UUID
this.className = describer.namespace + "." + (describer.className ?? type.prototype.constructor.name);
this.classId = describer.classId ?? SHA256.compute(DC.stringToBytes(this.className)).getGuid(0);
this.classId = describer.classId ?? SHA256.compute(DC.stringToBytes(this.className)).getUUID(0);
if (addToWarehouse)
@ -419,13 +424,13 @@ export default class TypeTemplate {
od.templateType = data.getUint8(offset++) & 0xF;
od.classId = data.getGuid(offset);
od.classId = data.getUUID(offset);
offset += 16;
od.className = data.getString(offset + 1, data.getUint8(offset));
offset += data.getUint8(offset) + 1;
if (hasParent) {
od.parentId = data.getGuid(offset);
od.parentId = data.getUUID(offset);
offset += 16;
}

View File

@ -47,7 +47,7 @@ import AutoMap from './Data/AutoMap.js';
import BinaryList from './Data/BinaryList.js';
import Codec from './Data/Codec.js';
import DC from './Data/DC.js';
import Guid from './Data/Guid.js';
import UUID from './Data/UUID.js';
import IRecord from './Data/IRecord.js';
import KeyList from './Data/KeyList.js';
import NotModified from './Data/NotModified.js';
@ -112,7 +112,7 @@ import {TemplateDescriber, Prop, Func, Evt, Const, Arg} from './Resource/Templat
const namespace = {
Core: { AsyncReply, AsyncException, AsyncQueue, ErrorType, ExceptionCode, IDestructible, IEventHandler, ProgressType},
Data: {AutoList, AutoMap, BinaryList, Codec, DC, TypedList, TypedMap, Guid, IRecord, KeyList, NotModified, ResourceArrayType,
Data: {AutoList, AutoMap, BinaryList, Codec, DC, TypedList, TypedMap, UUID, 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, IEnum