aotrautils 0.0.1115 → 0.0.1117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aotrautils/aotrautils.build.js +115 -195
- aotrautils/package.json +1 -1
aotrautils/aotrautils.build.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
|
2
2
|
|
3
|
-
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (
|
3
|
+
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (18/03/2025-12:49:35)»*/
|
4
4
|
/*-----------------------------------------------------------------------------*/
|
5
5
|
|
6
6
|
|
@@ -662,30 +662,17 @@ window.aotest=function(parameters,functionDefinition=null,ignoreTest=false,CLASS
|
|
662
662
|
|
663
663
|
if(!functionDefinition){
|
664
664
|
let mainInstance=parameters.mainInstance;
|
665
|
-
if(!mainInstance)
|
665
|
+
if(!mainInstance)
|
666
|
+
functionDefinition=window[methodNameParam];
|
666
667
|
else{
|
667
668
|
|
668
|
-
// // DBG
|
669
|
-
// console.log("parameters:",parameters);
|
670
|
-
|
671
669
|
functionDefinition=mainInstance[methodNameParam];
|
672
670
|
|
673
671
|
if(!functionDefinition && mainInstance[CLASSNAME_ATTR_NAME]){
|
674
672
|
let instanceTypeName=mainInstance[CLASSNAME_ATTR_NAME];
|
675
|
-
|
676
673
|
// DBG
|
677
674
|
console.log("ERROR : Could not find method «"+methodNameParam+"» on instance of the following 'alleged type' : «"+instanceTypeName+"». Test registration will be skipped.");
|
678
|
-
|
679
|
-
// // DBG
|
680
|
-
// console.log("+++instanceTypeName:",instanceTypeName);
|
681
|
-
|
682
675
|
}
|
683
|
-
|
684
|
-
// // DBG
|
685
|
-
// console.log("+++mainInstance:",mainInstance);
|
686
|
-
// console.log("+++functionDefinition:",functionDefinition);
|
687
|
-
|
688
|
-
|
689
676
|
}
|
690
677
|
}
|
691
678
|
if(!functionDefinition){
|
@@ -914,7 +901,7 @@ aotest.run=function(testName=null,scenarioName=null){
|
|
914
901
|
else expectedResult=chosenScenarioParam[1];
|
915
902
|
|
916
903
|
// We copy as flat structures and store all the possible function context objects before its execution :
|
917
|
-
currentExecutedTest.oldResultFlat=(expectedResult!=null?getAsFlatStructure(expectedResult
|
904
|
+
currentExecutedTest.oldResultFlat=(expectedResult!=null?getAsFlatStructure(expectedResult):null);
|
918
905
|
|
919
906
|
// NEW
|
920
907
|
// (special, scenario instance has priority over the main, test instance, for the function application :)
|
@@ -1143,8 +1130,8 @@ aotest.run=function(testName=null,scenarioName=null){
|
|
1143
1130
|
|
1144
1131
|
|
1145
1132
|
// At this point, we already have applied the method to the input object, in order to compare it with the output object, if necessary.
|
1146
|
-
let actualInstanceFlat=(actualInstance!=null?getAsFlatStructure(actualInstance
|
1147
|
-
let actualArgsFlat=(functionParametersPopulated!=null?getAsFlatStructure(functionParametersPopulated
|
1133
|
+
let actualInstanceFlat=(actualInstance!=null?getAsFlatStructure(actualInstance):null); // actual instance (after execution)
|
1134
|
+
let actualArgsFlat=(functionParametersPopulated!=null?getAsFlatStructure(functionParametersPopulated):null); // actual arguments (after execution)
|
1148
1135
|
|
1149
1136
|
|
1150
1137
|
let afterInstanceFlat=null;
|
@@ -1155,9 +1142,9 @@ aotest.run=function(testName=null,scenarioName=null){
|
|
1155
1142
|
afterArgsFlat=chosenScenarioParam.after.methodArgs; // EXPECTED arguments
|
1156
1143
|
afterResultFlat=functionResult; // actual result
|
1157
1144
|
}else{
|
1158
|
-
afterInstanceFlat=getAsFlatStructure(chosenScenarioParam.after.afterInstance
|
1159
|
-
afterArgsFlat=getAsFlatStructure(chosenScenarioParam.after.methodArgs
|
1160
|
-
afterResultFlat=getAsFlatStructure(functionResult
|
1145
|
+
afterInstanceFlat=getAsFlatStructure(chosenScenarioParam.after.afterInstance); // EXPECTED instance
|
1146
|
+
afterArgsFlat=getAsFlatStructure(chosenScenarioParam.after.methodArgs); // EXPECTED arguments
|
1147
|
+
afterResultFlat=getAsFlatStructure(functionResult); // actual result (after execution)
|
1161
1148
|
}
|
1162
1149
|
|
1163
1150
|
let areEquivalentInstances=(blank(actualInstanceFlat) && blank(afterInstanceFlat)) || areEquivalentFlatMaps(actualInstanceFlat,afterInstanceFlat);
|
@@ -3879,6 +3866,8 @@ window.instanciate=function(className=null){
|
|
3879
3866
|
}
|
3880
3867
|
// If class name is a simple object, a simple «{}» is enough :
|
3881
3868
|
if(className==="Object") return newObj;
|
3869
|
+
// If class name is a simple array, a simple «[]» is enough :
|
3870
|
+
if(className==="Array") return [];
|
3882
3871
|
|
3883
3872
|
try{
|
3884
3873
|
try{
|
@@ -4027,144 +4016,11 @@ window.clone=function(obj){
|
|
4027
4016
|
};
|
4028
4017
|
|
4029
4018
|
|
4030
|
-
|
4031
|
-
|
4032
|
-
//****************************************************************************************//
|
4033
|
-
// KNOWN LIMITATIONS : - Only deep-copies ARRAY-TYPE ONLY attributes up to max 99 dimentions !
|
4034
|
-
// - Not a real deep-copy
|
4035
|
-
//****************************************************************************************//
|
4036
|
-
// OLD AND BOGUS (SERIOUSLY, DON'T USE IT ANYMORE !) :
|
4037
|
-
//// DEPRECATED use structuredClone(...) instead :
|
4038
|
-
//window.cloneObjectShallow=function(obj, stateOnly=false, className=null, primitiveAttributesOnly=false
|
4039
|
-
// // If you have an array of more than 99 dimensions, then you have quite a serious problem (and in your code, too).
|
4040
|
-
// ,maxDeepness=99){
|
4041
|
-
//
|
4042
|
-
// var newObj=null;
|
4043
|
-
//
|
4044
|
-
// if(primitiveAttributesOnly){
|
4045
|
-
//
|
4046
|
-
// // We try to set the right class :
|
4047
|
-
// newObj=instanciate(className);
|
4048
|
-
//
|
4049
|
-
// // Primitive attributes means never objects, array or function attributes, as the name smartly suggests :
|
4050
|
-
// foreach(obj,(attr,attrName)=>{
|
4051
|
-
//
|
4052
|
-
// newObj[attrName]=attr;
|
4053
|
-
// },(attr)=>{ return isPrimitive(attr); });
|
4054
|
-
//
|
4055
|
-
// return newObj;
|
4056
|
-
// }
|
4057
|
-
//
|
4058
|
-
//
|
4059
|
-
//// // Case only attributes :
|
4060
|
-
//// if(stateOnly){
|
4061
|
-
//
|
4062
|
-
// // We try to set the right class :
|
4063
|
-
// newObj=instanciate(className);
|
4064
|
-
//
|
4065
|
-
//
|
4066
|
-
// foreach(obj,(attr,attrName)=>{
|
4067
|
-
// if(attr==null){
|
4068
|
-
// newObj[attrName]=null;
|
4069
|
-
// }else{
|
4070
|
-
//
|
4071
|
-
// if(isArray(attr)){
|
4072
|
-
//
|
4073
|
-
// newObj[attrName]=[];
|
4074
|
-
//
|
4075
|
-
// foreach(attr,(item,i)=>{
|
4076
|
-
//
|
4077
|
-
// if(isArray(item)){
|
4078
|
-
//
|
4079
|
-
// if(0<maxDeepness){
|
4080
|
-
// let newItem=cloneObjectShallow(item, stateOnly, getClassName(item), primitiveAttributesOnly, maxDeepness-1);
|
4081
|
-
// newObj[attrName].push(newItem);
|
4082
|
-
// }
|
4083
|
-
//
|
4084
|
-
// }else{
|
4085
|
-
// newObj[attrName].push(item);
|
4086
|
-
// }
|
4087
|
-
//
|
4088
|
-
// },(item)=>{return item==null
|
4089
|
-
// // We only copy the primitive objects,
|
4090
|
-
// // and the arrays objects :
|
4091
|
-
// || !isObject(item)
|
4092
|
-
// || isArray(item);
|
4093
|
-
// } );
|
4094
|
-
//
|
4095
|
-
// }else if(isObject(attr)){
|
4096
|
-
//
|
4097
|
-
// // THIS IS NOT A DEEP COPY !!:
|
4098
|
-
// newObj[attrName]=Object.assign({},attr);
|
4099
|
-
//
|
4100
|
-
// if(stateOnly){
|
4101
|
-
// foreach(newObj[attrName],(a,k)=>{
|
4102
|
-
// delete newObj[attrName][k];
|
4103
|
-
// },(a)=>{ return isFunction(a); });
|
4104
|
-
//
|
4105
|
-
// }
|
4106
|
-
//
|
4107
|
-
// }else if((isFunction(attr) && !stateOnly) || isPrimitive(attr)){ // If we have state only and we have a function, we DO NOT copy it :
|
4108
|
-
//
|
4109
|
-
// newObj[attrName]=attr;
|
4110
|
-
//
|
4111
|
-
// }
|
4112
|
-
//
|
4113
|
-
// }
|
4114
|
-
// // (CAUTION : not a real deep-copy)
|
4115
|
-
// });
|
4116
|
-
//
|
4117
|
-
// return newObj;
|
4118
|
-
//// }
|
4119
|
-
//
|
4120
|
-
//// // Case attributes + functions :
|
4121
|
-
////
|
4122
|
-
//// // We try to set the right class :
|
4123
|
-
//// if(className){
|
4124
|
-
//// try{
|
4125
|
-
//// // TODO : FIXME : I don't like that at all, to use eval(...), but on today I know of no other solution... :
|
4126
|
-
//// newObj=eval("new "+className+"();");
|
4127
|
-
//// }catch(e){
|
4128
|
-
//// // (CAUTION : not a real deep-copy)
|
4129
|
-
//// // Will (not-really deeply) copy the functions too :
|
4130
|
-
//// newObj=Object.assign({},obj);
|
4131
|
-
//// }
|
4132
|
-
//// }else{
|
4133
|
-
//// // (CAUTION : not deep-copy)
|
4134
|
-
//// // Will (not-really deeply) copy the functions too :
|
4135
|
-
//// newObj=Object.assign({},obj);
|
4136
|
-
//// }
|
4137
|
-
////
|
4138
|
-
////
|
4139
|
-
//// return newObj;
|
4140
|
-
//};
|
4141
|
-
|
4142
|
-
|
4143
4019
|
window.isProperAttributeName=function(key){
|
4144
4020
|
return key!==DEFAULT_UUID_ATTR_NAME && key!==DEFAULT_CLASSNAME_ATTR_NAME;
|
4145
4021
|
}
|
4146
4022
|
|
4147
4023
|
|
4148
|
-
////OLD
|
4149
|
-
//window.areEquivalentFlatMaps=function(o1,o2,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAME){
|
4150
|
-
//
|
4151
|
-
//if((o1!=null)!==(o2!=null)) return false;
|
4152
|
-
//
|
4153
|
-
//let s1="";
|
4154
|
-
//let s2="";
|
4155
|
-
//
|
4156
|
-
//// We ignore uuid keys :
|
4157
|
-
//foreach(o1,(entry)=>{
|
4158
|
-
//s1+=getSignatureOnNonCycledObject(entry,false,ignoredAttributes)+",";
|
4159
|
-
//});
|
4160
|
-
//foreach(o2,(entry)=>{
|
4161
|
-
//s2+=getSignatureOnNonCycledObject(entry,false,ignoredAttributes)+",";
|
4162
|
-
//});
|
4163
|
-
//
|
4164
|
-
//return s1===s2;
|
4165
|
-
//}
|
4166
|
-
|
4167
|
-
|
4168
4024
|
window.areEquivalentFlatMaps=function(o1,o2,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAME,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME){
|
4169
4025
|
|
4170
4026
|
if((o1!=null)!==(o2!=null)) return false;
|
@@ -4353,10 +4209,7 @@ window.areEquivalent=function(obj1Param,obj2Param,flattenBeforeCompute=false, UU
|
|
4353
4209
|
|
4354
4210
|
let obj1, obj2;
|
4355
4211
|
if(flattenBeforeCompute){
|
4356
|
-
//
|
4357
|
-
// obj1=getAsFlatStructure(obj1Param,true);
|
4358
|
-
// obj2=getAsFlatStructure(obj2Param,true);
|
4359
|
-
// YES :
|
4212
|
+
// CAUTION : The UUIDs generation can alter the result !
|
4360
4213
|
obj1=JSON.decycle(obj1Param);
|
4361
4214
|
obj2=JSON.decycle(obj2Param);
|
4362
4215
|
}else{
|
@@ -4412,8 +4265,8 @@ window.calculateProtoDelta=function(obj1,obj2,
|
|
4412
4265
|
let result={};
|
4413
4266
|
|
4414
4267
|
if(flattenBeforeCompute){
|
4415
|
-
obj1=getAsFlatStructure(o1
|
4416
|
-
obj2=getAsFlatStructure(o2
|
4268
|
+
obj1=getAsFlatStructure(o1);
|
4269
|
+
obj2=getAsFlatStructure(o2);
|
4417
4270
|
}
|
4418
4271
|
|
4419
4272
|
|
@@ -4581,7 +4434,7 @@ window.isFlatMap=function(obj){
|
|
4581
4434
|
|
4582
4435
|
//CAUTION : KNOWN LIMITATIONS : - Does not handle root-level arrays flattening !
|
4583
4436
|
// - Does not handle anonymous objects functions and methods population !
|
4584
|
-
window.getAsFlatStructureImpl=function(rawObject
|
4437
|
+
window.getAsFlatStructureImpl=function(rawObject
|
4585
4438
|
,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAME/* Yet Another UUID */
|
4586
4439
|
,CLASSNAME_ATTR_NAME=DEFAULT_CLASSNAME_ATTR_NAME/* Yet Another Classname */
|
4587
4440
|
,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME/* Yet Another PointerTo */
|
@@ -4619,7 +4472,6 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4619
4472
|
registerObject(objectsRegistry,rawObject, UUID_ATTR_NAME
|
4620
4473
|
// ,CLASSNAME_ATTR_NAME
|
4621
4474
|
);
|
4622
|
-
|
4623
4475
|
|
4624
4476
|
// // DBG
|
4625
4477
|
// console.log("¬¬¬¬objectsRegistry.map",objectsRegistry.map);
|
@@ -4634,7 +4486,7 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4634
4486
|
foreach(workingOriginalObjectsMap,(workingOriginalObject, uuid)=>{
|
4635
4487
|
|
4636
4488
|
addInFlatMapAndReplaceObjectsWithPointers(resultMap,workingOriginalObject,uuid
|
4637
|
-
,
|
4489
|
+
,UUID_ATTR_NAME,CLASSNAME_ATTR_NAME,POINTER_TO_ATTR_NAME);
|
4638
4490
|
|
4639
4491
|
});
|
4640
4492
|
|
@@ -4710,7 +4562,7 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4710
4562
|
|
4711
4563
|
//(recursively called function)
|
4712
4564
|
/*private*/window.addInFlatMapAndReplaceObjectsWithPointers=function(resultMap,workingOriginalObject,uuid
|
4713
|
-
,
|
4565
|
+
,UUID_ATTR_NAME,CLASSNAME_ATTR_NAME,POINTER_TO_ATTR_NAME){
|
4714
4566
|
|
4715
4567
|
if(workingOriginalObject==null)
|
4716
4568
|
return;
|
@@ -4722,7 +4574,7 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4722
4574
|
|
4723
4575
|
// The new object is added to the flat map :
|
4724
4576
|
// (We don't care to set the real class here, because this object will have a JSONtype attribute in the end. This new result object will be a pure JSON information.)
|
4725
|
-
// OLD AND BOGUS (SERIOUSLY, DON'T USE IT ANYMORE !) : let result=cloneObjectShallow(workingOriginalObject,
|
4577
|
+
// OLD AND BOGUS (SERIOUSLY, DON'T USE IT ANYMORE !) : let result=cloneObjectShallow(workingOriginalObject, null, true);
|
4726
4578
|
let result=structuredClone(workingOriginalObject);
|
4727
4579
|
|
4728
4580
|
|
@@ -4759,9 +4611,8 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4759
4611
|
result[attrName].push(null);
|
4760
4612
|
return "continue";
|
4761
4613
|
}
|
4614
|
+
// WE ALWAYS SKIP THE FUNCTIONS !
|
4762
4615
|
if(isFunction(item)){
|
4763
|
-
if(stateOnly) return "continue";
|
4764
|
-
result[attrName].push(item);
|
4765
4616
|
return "continue";
|
4766
4617
|
}
|
4767
4618
|
|
@@ -4806,7 +4657,7 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4806
4657
|
|
4807
4658
|
// We add the result to the flat map :
|
4808
4659
|
addInFlatMapAndReplaceObjectsWithPointers(resultMap,item,attrInArrayUUID
|
4809
|
-
,
|
4660
|
+
,UUID_ATTR_NAME,CLASSNAME_ATTR_NAME,POINTER_TO_ATTR_NAME);
|
4810
4661
|
|
4811
4662
|
|
4812
4663
|
|
@@ -4819,9 +4670,8 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4819
4670
|
result[attrName]=null;
|
4820
4671
|
return "continue";
|
4821
4672
|
}
|
4673
|
+
// WE ALWAYS SKIP THE FUNCTIONS !
|
4822
4674
|
if(isFunction(workingAttr)){
|
4823
|
-
if(stateOnly) return "continue";
|
4824
|
-
result[attrName]=workingAttr;
|
4825
4675
|
return "continue";
|
4826
4676
|
}
|
4827
4677
|
if(!isObject(workingAttr)){
|
@@ -4848,7 +4698,7 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4848
4698
|
|
4849
4699
|
// We add the result to the flat map :
|
4850
4700
|
addInFlatMapAndReplaceObjectsWithPointers(resultMap,workingAttr,attrUUID
|
4851
|
-
,
|
4701
|
+
,UUID_ATTR_NAME,CLASSNAME_ATTR_NAME,POINTER_TO_ATTR_NAME);
|
4852
4702
|
|
4853
4703
|
|
4854
4704
|
}
|
@@ -4872,16 +4722,12 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
4872
4722
|
|
4873
4723
|
// CAUTION : KNOWN LIMITATIONS : - Does not handle root-level arrays flattening !
|
4874
4724
|
// - Does not handle anonymous objects functions and methods population !
|
4875
|
-
window.getAsTreeStructureImpl=function(oldMap,
|
4725
|
+
window.getAsTreeStructureImpl=function(oldMap, removeTypeInfo=true
|
4876
4726
|
,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAME/* Yet Another UUID */
|
4877
4727
|
,CLASSNAME_ATTR_NAME=DEFAULT_CLASSNAME_ATTR_NAME/* Yet Another Classname */
|
4878
4728
|
,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME/* Yet Another PointerTo */
|
4879
4729
|
){
|
4880
4730
|
|
4881
|
-
|
4882
|
-
// TODO : FIXME : «stateOnly=false» DOESN'T WORK and only returns an empty object «{}» !
|
4883
|
-
|
4884
|
-
|
4885
4731
|
// We have in input a map of the following form :
|
4886
4732
|
// { ("a uuid" : {(non-object attributes key-value pairs)*, (object attributes
|
4887
4733
|
// as : {<POINTER_TO_ATTR_NAME> : "a uuid"} )*}) }
|
@@ -5018,34 +4864,109 @@ window.getAsTreeStructureImpl=function(oldMap, stateOnly=false, removeTypeInfo=t
|
|
5018
4864
|
|
5019
4865
|
|
5020
4866
|
|
4867
|
+
|
4868
|
+
// ----------------------------------------------------------------
|
4869
|
+
// ----------------------------------------------------------------
|
5021
4870
|
// ----------------------------------------------------------------
|
5022
4871
|
|
5023
|
-
window.getAsFlatStructure=function(rawObject
|
4872
|
+
window.getAsFlatStructure=function(rawObject
|
5024
4873
|
,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAME/* Yet Another UUID */
|
5025
4874
|
,CLASSNAME_ATTR_NAME=DEFAULT_CLASSNAME_ATTR_NAME/* Yet Another Classname */
|
5026
4875
|
,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME/* Yet Another PointerTo */
|
5027
4876
|
){
|
5028
|
-
|
5029
|
-
|
5030
|
-
return getAsFlatStructureImpl(rawObject, stateOnly
|
5031
|
-
,UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME
|
5032
|
-
);
|
4877
|
+
// OLD : return getAsFlatStructureImpl(rawObject,UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
|
4878
|
+
return flattenGraph(rawObject, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
|
5033
4879
|
};
|
5034
4880
|
|
4881
|
+
function flattenGraph(root, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME) {
|
4882
|
+
const visitedObjects = new WeakMap(); // Prevent infinite loops
|
4883
|
+
|
4884
|
+
function process(obj, map, isRoot=false) { // Store objects by ID
|
4885
|
+
|
4886
|
+
if (obj === null || isPrimitive(obj)) return obj; // Primitives stay unchanged
|
4887
|
+
if (visitedObjects.has(obj)) return { [POINTER_TO_ATTR_NAME]: visitedObjects.get(obj) }; // Return if already processed
|
4888
|
+
|
4889
|
+
const id = (isRoot?ROOT_UUID:getUUID());
|
4890
|
+
visitedObjects.set(obj, id); // Mark object as processed
|
4891
|
+
|
4892
|
+
const serialized = {
|
4893
|
+
[UUID_ATTR_NAME]: id,
|
4894
|
+
[CLASSNAME_ATTR_NAME]: getClassName(obj),
|
4895
|
+
};
|
4896
|
+
map[id] = serialized;
|
4897
|
+
|
4898
|
+
foreach(obj,(item,indexOrKey)=>{
|
4899
|
+
|
4900
|
+
let value=null;
|
4901
|
+
if (item === null || isPrimitive(item)){
|
4902
|
+
serialized[indexOrKey]=item; // Primitives stay unchanged
|
4903
|
+
return "continue";
|
4904
|
+
}
|
4905
|
+
if (!visitedObjects.has(item)){
|
4906
|
+
process(item, map);
|
4907
|
+
}
|
4908
|
+
serialized[indexOrKey] = { [POINTER_TO_ATTR_NAME]: visitedObjects.get(item) }; // Return if already processed;
|
4909
|
+
},(item)=>!isFunction(item));
|
4910
|
+
|
4911
|
+
return serialized;
|
4912
|
+
|
4913
|
+
}
|
4914
|
+
|
4915
|
+
const resultMap={};
|
4916
|
+
process(root, resultMap, true);
|
4917
|
+
return resultMap;
|
4918
|
+
}
|
4919
|
+
|
5035
4920
|
|
5036
|
-
window.getAsTreeStructure=function(oldMap,
|
4921
|
+
window.getAsTreeStructure=function(oldMap, keepClassName=false
|
5037
4922
|
,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAME/* Yet Another UUID */
|
5038
4923
|
,CLASSNAME_ATTR_NAME=DEFAULT_CLASSNAME_ATTR_NAME/* Yet Another Classname */
|
5039
4924
|
,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME/* Yet Another PointerTo */
|
5040
4925
|
){
|
5041
4926
|
|
5042
4927
|
// MAYBE DEPRECATED USE JSON.recycle(...) INSTEAD !
|
5043
|
-
return getAsTreeStructureImpl(oldMap,
|
5044
|
-
|
5045
|
-
);
|
4928
|
+
//return getAsTreeStructureImpl(oldMap, !keepClassName, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
|
4929
|
+
return restoreGraph(oldMap, keepClassName, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
|
5046
4930
|
};
|
5047
4931
|
|
5048
4932
|
|
4933
|
+
function restoreGraph(flatData, keepClassName=false, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME) {
|
4934
|
+
|
4935
|
+
function revive(id, keepClassName, restoredObjects = {}) {
|
4936
|
+
|
4937
|
+
if (!id || !flatData[id]) return null;
|
4938
|
+
const found=restoredObjects[id];
|
4939
|
+
if(restoredObjects[id]) return found;
|
4940
|
+
|
4941
|
+
const objData = flatData[id];
|
4942
|
+
const className = objData[CLASSNAME_ATTR_NAME];
|
4943
|
+
//const instance = Array.isArray(objData.value) ? [] : instanciate(className);
|
4944
|
+
const instance = instanciate(className);
|
4945
|
+
|
4946
|
+
restoredObjects[id]=instance; // Assign ID early to handle circular references
|
4947
|
+
|
4948
|
+
foreach(objData,(item,indexOrKey)=>{
|
4949
|
+
if(item==null){
|
4950
|
+
item[POINTER_TO_ATTR_NAME]=null;
|
4951
|
+
}else{
|
4952
|
+
const isRef = (!isPrimitive(item) && (POINTER_TO_ATTR_NAME in item));
|
4953
|
+
const attrName=item[POINTER_TO_ATTR_NAME];
|
4954
|
+
instance[indexOrKey] = isRef ? revive(attrName, keepClassName, restoredObjects) : item/*Case primitev or null*/;
|
4955
|
+
}
|
4956
|
+
},(item,indexOrKey)=> (
|
4957
|
+
!contains([UUID_ATTR_NAME,POINTER_TO_ATTR_NAME],indexOrKey)
|
4958
|
+
&& (keepClassName && indexOrKey===CLASSNAME_ATTR_NAME) || indexOrKey!==CLASSNAME_ATTR_NAME)
|
4959
|
+
);
|
4960
|
+
|
4961
|
+
delete instance[UUID_ATTR_NAME];
|
4962
|
+
return instance;
|
4963
|
+
}
|
4964
|
+
|
4965
|
+
return revive(ROOT_UUID, keepClassName);
|
4966
|
+
}
|
4967
|
+
|
4968
|
+
|
4969
|
+
|
5049
4970
|
|
5050
4971
|
|
5051
4972
|
/*
|
@@ -5326,7 +5247,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
|
|
5326
5247
|
|
5327
5248
|
|
5328
5249
|
|
5329
|
-
/*utils CLIENT library associated with aotra version : «1_29072022-2359 (
|
5250
|
+
/*utils CLIENT library associated with aotra version : «1_29072022-2359 (18/03/2025-12:49:35)»*/
|
5330
5251
|
/*-----------------------------------------------------------------------------*/
|
5331
5252
|
/* ## Utility global methods in a browser (htmljs) client environment.
|
5332
5253
|
*
|
@@ -13898,7 +13819,7 @@ getAORTACClient=function(clientId=getUUID(), serverNodeOrigin="ws://127.0.0.1:40
|
|
13898
13819
|
|
13899
13820
|
|
13900
13821
|
|
13901
|
-
/*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (
|
13822
|
+
/*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (18/03/2025-12:49:35)»*/
|
13902
13823
|
/*-----------------------------------------------------------------------------*/
|
13903
13824
|
|
13904
13825
|
|
@@ -15137,7 +15058,7 @@ function rayVsUnitSphereClosestPoint(p, r) {
|
|
15137
15058
|
// MUST REMAIN AT THE END OF THIS LIBRARY FILE !
|
15138
15059
|
|
15139
15060
|
AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
|
15140
|
-
/*utils AI library associated with aotra version : «1_29072022-2359 (
|
15061
|
+
/*utils AI library associated with aotra version : «1_29072022-2359 (18/03/2025-12:49:35)»*/
|
15141
15062
|
/*-----------------------------------------------------------------------------*/
|
15142
15063
|
|
15143
15064
|
|
@@ -15281,7 +15202,7 @@ getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
|
|
15281
15202
|
|
15282
15203
|
|
15283
15204
|
|
15284
|
-
/*utils SERVER library associated with aotra version : «1_29072022-2359 (
|
15205
|
+
/*utils SERVER library associated with aotra version : «1_29072022-2359 (18/03/2025-12:49:35)»*/
|
15285
15206
|
/*-----------------------------------------------------------------------------*/
|
15286
15207
|
|
15287
15208
|
|
@@ -15390,9 +15311,8 @@ if(typeof(fs)==="undefined"){
|
|
15390
15311
|
|
15391
15312
|
// 2)
|
15392
15313
|
if(!empty(resultData) && isFlatMap(resultData)){
|
15393
|
-
|
15394
|
-
|
15395
|
-
,false);
|
15314
|
+
// CAUTION : We have to keep the type information, here too ! (in the sub-objects)
|
15315
|
+
resultData=getAsTreeStructure(resultData, true);
|
15396
15316
|
}
|
15397
15317
|
|
15398
15318
|
return resultData;
|
@@ -15404,7 +15324,7 @@ if(typeof(fs)==="undefined"){
|
|
15404
15324
|
|
15405
15325
|
|
15406
15326
|
if(!empty(dataFlatForClient) && !isFlatMap(dataFlatForClient) && !forceKeepUnflatten){
|
15407
|
-
dataFlatForClient=getAsFlatStructure(dataFlatForClient
|
15327
|
+
dataFlatForClient=getAsFlatStructure(dataFlatForClient);
|
15408
15328
|
}
|
15409
15329
|
|
15410
15330
|
// reserved characters : -/\^$*+?.()|[]{}
|
aotrautils/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "aotrautils",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.1117",
|
4
4
|
"main": "aotrautils.build.js",
|
5
5
|
"description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
|
6
6
|
"author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",
|