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", "name": "esiur",
"version": "2.3.0", "version": "2.3.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "esiur", "name": "esiur",
"version": "2.3.0", "version": "2.3.3",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.20.7", "@babel/runtime": "^7.20.7",

View File

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

View File

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

View File

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

View File

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

View File

@ -141,11 +141,11 @@ export default class RepresentationType {
if (IdentifierToTypeMap[this.identifier] != undefined) if (IdentifierToTypeMap[this.identifier] != undefined)
runtimeType = IdentifierToTypeMap[this.identifier] runtimeType = IdentifierToTypeMap[this.identifier]
if (this.identifier == RepresentationTypeIdentifier.TypedResource) { 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) { } 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) { } 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){ } else if (this.identifier == RepresentationTypeIdentifier.TypedList){
let elementType = this.subTypes[0].getRuntimeType(); let elementType = this.subTypes[0].getRuntimeType();
runtimeType = TypedList.of(elementType); runtimeType = TypedList.of(elementType);
@ -171,7 +171,7 @@ export default class RepresentationType {
} }
toNullable() { 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);} 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.identifier = identifier;
this.nullable = nullable; this.nullable = nullable;
this.guid = guid; this.uuid = uuid;
this.subTypes = subTypes; this.subTypes = subTypes;
} }
@ -247,7 +247,7 @@ export default class RepresentationType {
else else
rt.addUint8(this.identifier); 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) if (this.subTypes != null)
for (var i = 0; i < this.subTypes.length; i++) for (var i = 0; i < this.subTypes.length; i++)
@ -267,13 +267,13 @@ export default class RepresentationType {
let identifier = (header & 0x7F); let identifier = (header & 0x7F);
if ((header & 0x40) > 0) { if ((header & 0x40) > 0) {
let hasGUID = (header & 0x4) > 0; let hasUUID = (header & 0x4) > 0;
let subsCount = (header >> 3) & 0x7; let subsCount = (header >> 3) & 0x7;
let guid = null; let uuid = null;
if (hasGUID) { if (hasUUID) {
guid = data.getGuid(offset); uuid = data.getUUID(offset);
offset += 16; offset += 16;
} }
@ -286,7 +286,7 @@ export default class RepresentationType {
} }
return new RepresentationTypeParseResults(offset - oOffset, return new RepresentationTypeParseResults(offset - oOffset,
new RepresentationType(identifier, nullable, guid, subs)); new RepresentationType(identifier, nullable, uuid, subs));
} else { } else {
return new RepresentationTypeParseResults( return new RepresentationTypeParseResults(
1, new RepresentationType(identifier, nullable, null, null)); 1, new RepresentationType(identifier, nullable, null, null));

View File

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

View File

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

View File

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

View File

@ -90,7 +90,7 @@ export default class TemplateGenerator {
let cls = template.className.split('.'); let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.'); 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}"; rt += "\r\n}";
@ -112,36 +112,36 @@ export default class TemplateGenerator {
let name; let name;
if (representationType.identifier == RepresentationTypeIdentifier.TypedResource) { 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]; name = forTemplate.className.split('.').slice(-1)[0];
else { else {
let className = templates let className = templates
.find((x) => .find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() && x.classId.valueOf() == representationType.uuid.valueOf() &&
(x.type == TemplateType.Resource)) (x.type == TemplateType.Resource))
.className; .className;
if (!dependencies?.includes(className)) dependencies?.push(className); if (!dependencies?.includes(className)) dependencies?.push(className);
name = this._translateClassName(className); name = this._translateClassName(className);
} }
} else if (representationType.identifier == RepresentationTypeIdentifier.TypedRecord) { } 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]; name = forTemplate.className.split('.').slice(-1)[0];
else { else {
let className = templates let className = templates
.find((x) => .find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() && x.classId.valueOf() == representationType.uuid.valueOf() &&
x.type == TemplateType.Record) x.type == TemplateType.Record)
.className; .className;
if (!dependencies?.includes(className)) dependencies?.push(className); if (!dependencies?.includes(className)) dependencies?.push(className);
name = this._translateClassName(className); name = this._translateClassName(className);
} }
} else if (representationType.identifier == RepresentationTypeIdentifier.Enum) { } 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]; name = forTemplate.className.split('.').slice(-1)[0];
else { else {
let className = templates let className = templates
.find((x) => .find((x) =>
x.classId.valueOf() == representationType.guid.valueOf() && x.classId.valueOf() == representationType.uuid.valueOf() &&
x.type == TemplateType.Enum) x.type == TemplateType.Enum)
.className; .className;
if (!dependencies?.includes(className)) dependencies?.push(className); if (!dependencies?.includes(className)) dependencies?.push(className);
@ -357,7 +357,7 @@ export default class TemplateGenerator {
let cls = template.className.split('.'); let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.'); 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}"; rt += "\r\n}";
@ -450,7 +450,7 @@ export default class TemplateGenerator {
//rt += `var rt = new AsyncReply<${rtTypeName}>();\r\n`; //rt += `var rt = new AsyncReply<${rtTypeName}>();\r\n`;
rt += `\t\tvar rt = new Esiur.Core.AsyncReply();\r\n`; rt += `\t\tvar rt = new Esiur.Core.AsyncReply();\r\n`;
if (f.isStatic) { 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 { } else {
rt += `\t\tthis._invoke(${f.index}, args)\r\n`; rt += `\t\tthis._invoke(${f.index}, args)\r\n`;
} }
@ -516,7 +516,7 @@ export default class TemplateGenerator {
let cls = template.className.split('.'); let cls = template.className.split('.');
let namespace = cls.slice(0, cls.length - 1).join('.'); 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"; rt += "\r\n}\r\n";

View File

@ -122,13 +122,18 @@ export default class TypeTemplate {
*/ */
static getTypeGuid(type) { static getTypeUUID(type) {
return this.getTypeGuidByName(type.template.namespace + "." + type.prototype.constructor.name); 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; let describer = type.template;
// set guid // set UUID
this.className = describer.namespace + "." + (describer.className ?? type.prototype.constructor.name); 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) if (addToWarehouse)
@ -419,13 +424,13 @@ export default class TypeTemplate {
od.templateType = data.getUint8(offset++) & 0xF; od.templateType = data.getUint8(offset++) & 0xF;
od.classId = data.getGuid(offset); od.classId = data.getUUID(offset);
offset += 16; offset += 16;
od.className = data.getString(offset + 1, data.getUint8(offset)); od.className = data.getString(offset + 1, data.getUint8(offset));
offset += data.getUint8(offset) + 1; offset += data.getUint8(offset) + 1;
if (hasParent) { if (hasParent) {
od.parentId = data.getGuid(offset); od.parentId = data.getUUID(offset);
offset += 16; offset += 16;
} }

View File

@ -47,7 +47,7 @@ import AutoMap from './Data/AutoMap.js';
import BinaryList from './Data/BinaryList.js'; import BinaryList from './Data/BinaryList.js';
import Codec from './Data/Codec.js'; import Codec from './Data/Codec.js';
import DC from './Data/DC.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 IRecord from './Data/IRecord.js';
import KeyList from './Data/KeyList.js'; import KeyList from './Data/KeyList.js';
import NotModified from './Data/NotModified.js'; import NotModified from './Data/NotModified.js';
@ -112,7 +112,7 @@ import {TemplateDescriber, Prop, Func, Evt, Const, Arg} from './Resource/Templat
const namespace = { const namespace = {
Core: { AsyncReply, AsyncException, AsyncQueue, ErrorType, ExceptionCode, IDestructible, IEventHandler, ProgressType}, 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, PropertyValue, Record, ResourceArray, RepresentationType, RepresentationTypeIdentifier, TransmissionType, TransmissionTypeIdentifier,
Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128, Float32, Float64, Float128, Char16, Char8, Tuple, Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64, UInt64, Int128, UInt128, Float32, Float64, Float128, Char16, Char8, Tuple,
Nullable, Void, IEnum Nullable, Void, IEnum