aotrautils 0.0.1156 → 0.0.1158

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.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- /*utils COMMONS library associated with aotra version : «1_29072022-2359 (19/03/2025-20:20:51)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (19/03/2025-23:30:09)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -4425,445 +4425,10 @@ window.clearAttribute=function(tree, attrName, maxLevel=null){
4425
4425
  // =========================================================================
4426
4426
 
4427
4427
 
4428
-
4429
- // Flattening :
4430
-
4431
4428
  window.isFlatMap=function(obj){
4432
4429
  return typeof(obj[ROOT_UUID])!=="undefined" && obj[ROOT_UUID]!=null;
4433
4430
  };
4434
4431
 
4435
- //CAUTION : KNOWN LIMITATIONS : - Does not handle root-level arrays flattening !
4436
- // - Does not handle anonymous objects functions and methods population !
4437
- window.getAsFlatStructureImpl=function(rawObject
4438
- ,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAME/* Yet Another UUID */
4439
- ,CLASSNAME_ATTR_NAME=DEFAULT_CLASSNAME_ATTR_NAME/* Yet Another Classname */
4440
- ,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME/* Yet Another PointerTo */
4441
- ){
4442
-
4443
-
4444
- // CAUTION «()=>{}» syntax does not work with methods referring «this» in attributes or methods!
4445
- // window.objectsRegistry={
4446
- var objectsRegistry={
4447
- map:{}, // This map will point to the original objects
4448
- registerIfNeeded:function(obj){
4449
- if(this.isRegistered(obj)) return false;
4450
- this.registerNewObject(obj);
4451
- return true;
4452
- },
4453
- /* private */isRegistered:function(obj){
4454
- let uuid=obj[UUID_ATTR_NAME];
4455
- if(!uuid) return false;
4456
- let foundObject=this.map[uuid];
4457
- return typeof(foundObject)!=="undefined" && foundObject;
4458
- },
4459
- /* private */registerNewObject:function(obj){
4460
- let newUUID=(empty(this.map) ? ROOT_UUID : getUUID());
4461
- obj[UUID_ATTR_NAME]=newUUID;
4462
- this.map[newUUID]=obj;
4463
- }
4464
- };
4465
- // }
4466
-
4467
- // var objectsRegistry=window.objectsRegistry;
4468
- // // We reinit the registry map :
4469
- // objectsRegistry.map={};
4470
-
4471
- // 1) First, we sort up the original structure in the registry and give them all uuids :
4472
- registerObject(objectsRegistry,rawObject, UUID_ATTR_NAME
4473
- // ,CLASSNAME_ATTR_NAME
4474
- );
4475
-
4476
- // // DBG
4477
- // console.log("¬¬¬¬objectsRegistry.map",objectsRegistry.map);
4478
-
4479
-
4480
- // 2) Second, we flatten the javascript structure.
4481
- let workingOriginalObjectsMap=objectsRegistry.map;
4482
-
4483
- let resultMap={};
4484
-
4485
- // We browse through the registry tree map to create the flat new copied structure :
4486
- foreach(workingOriginalObjectsMap,(workingOriginalObject, uuid)=>{
4487
-
4488
- addInFlatMapAndReplaceObjectsWithPointers(resultMap,workingOriginalObject,uuid
4489
- ,UUID_ATTR_NAME,CLASSNAME_ATTR_NAME,POINTER_TO_ATTR_NAME);
4490
-
4491
- });
4492
-
4493
-
4494
- // Then we remove the technical attributes in the original objects :
4495
- foreach(workingOriginalObjectsMap,(workingOriginalObject)=>{
4496
- delete workingOriginalObject[UUID_ATTR_NAME];
4497
- });
4498
-
4499
-
4500
- // CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
4501
-
4502
- return resultMap;
4503
- };
4504
-
4505
-
4506
- // (recursively called function)
4507
- /*private*/window.registerObject=function(objectsRegistry,rawObject,UUID_ATTR_NAME
4508
- // ,CLASSNAME_ATTR_NAME
4509
- ){
4510
-
4511
- if(rawObject==null)
4512
- return;
4513
-
4514
-
4515
- if(isPrimitive(rawObject)
4516
- || isArray(rawObject)
4517
- ){
4518
- return;
4519
- }
4520
-
4521
-
4522
- // // DBG
4523
- // console.log(">>>REGISTER OBJECT:",rawObject);
4524
-
4525
-
4526
- // We add the object to the registry if it is encoutered for the first time :
4527
- var hasBeenRegistered=objectsRegistry.registerIfNeeded(rawObject);
4528
-
4529
- // If object is already present, then we stop here.
4530
- if(!hasBeenRegistered) return;
4531
-
4532
-
4533
- // We browse through the subObjects in the structure, to register them :
4534
- foreach(rawObject,(subObject)=>{
4535
-
4536
-
4537
- if(isArray(subObject)){
4538
-
4539
- foreach(subObject,(item)=>{
4540
-
4541
- // We add the object to the registry :
4542
- registerObject(objectsRegistry,item, UUID_ATTR_NAME);
4543
-
4544
- },(item)=>{ return isObject(item); });
4545
-
4546
-
4547
- }else{
4548
-
4549
- // We add the object to the registry :
4550
- registerObject(objectsRegistry, subObject, UUID_ATTR_NAME);
4551
-
4552
- }
4553
-
4554
- }
4555
- // DBG
4556
- ,(subObject)=>{ return isArray(subObject) || isObject(subObject); }
4557
- );
4558
-
4559
-
4560
-
4561
- };
4562
-
4563
- //(recursively called function)
4564
- /*private*/window.addInFlatMapAndReplaceObjectsWithPointers=function(resultMap,workingOriginalObject,uuid
4565
- ,UUID_ATTR_NAME,CLASSNAME_ATTR_NAME,POINTER_TO_ATTR_NAME){
4566
-
4567
- if(workingOriginalObject==null)
4568
- return;
4569
-
4570
- let isAlreadyInNewMap=(resultMap[uuid]!=null);
4571
- if(isAlreadyInNewMap || workingOriginalObject[POINTER_TO_ATTR_NAME]!=null)
4572
- return;
4573
-
4574
-
4575
- // The new object is added to the flat map :
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.)
4577
- // OLD AND BOGUS (SERIOUSLY, DON'T USE IT ANYMORE !) : let result=cloneObjectShallow(workingOriginalObject, null, true);
4578
- let result=structuredClone(workingOriginalObject);
4579
-
4580
-
4581
- // We set the class name to the new result object :
4582
- let className=getClassName(workingOriginalObject);
4583
- if(className!=="Array"){ // No need to indicate that this JSON object is an array, since "[" indicates it by the JSON language definition.
4584
- result[CLASSNAME_ATTR_NAME]=className;
4585
- }
4586
-
4587
-
4588
- // // DBG
4589
- // console.log("result[CLASSNAME_ATTR_NAME]",result[CLASSNAME_ATTR_NAME]);
4590
-
4591
-
4592
- // We add the result to the flat map :
4593
- resultMap[uuid]=result;
4594
-
4595
-
4596
-
4597
- // Attributes processing :
4598
- foreach(workingOriginalObject,(workingAttr, attrName)=>{
4599
-
4600
-
4601
- // We replace the actual reference to a pointer to this reference :
4602
- if(isArray(workingAttr)){
4603
-
4604
- result[attrName]=[];
4605
-
4606
-
4607
- // Array items :
4608
- foreach(workingAttr,(item,i)=>{
4609
-
4610
- if(item==null){
4611
- result[attrName].push(null);
4612
- return "continue";
4613
- }
4614
- // WE ALWAYS SKIP THE FUNCTIONS !
4615
- if(isFunction(item)){
4616
- return "continue";
4617
- }
4618
-
4619
- if(isPrimitive(item)
4620
- || isArray(item)){
4621
-
4622
- // // DBG
4623
- // console.log("%%% workingAttr:",workingAttr);
4624
- // console.log("%%% result:",result);
4625
- // console.log("%%% attrName:",attrName);
4626
- // console.log("%%% item:",item);
4627
-
4628
- result[attrName].push(item);
4629
- return "continue";
4630
- }
4631
-
4632
-
4633
- let attrInArrayUUID=item[UUID_ATTR_NAME];
4634
- if(attrInArrayUUID==null){
4635
-
4636
- // // DBG
4637
- // console.log("isObject(item)",isObject(item));
4638
- // console.log("isString(item)",isString(item));
4639
- // console.log("typeof(item)",typeof(item));
4640
- // console.log("item",item);
4641
-
4642
-
4643
- // TRACE
4644
- console.log("ERROR : Attribute «"+item+"» in array should have a uuid under the member name «"+UUID_ATTR_NAME+"» but has none !" +
4645
- " Complete attribute object :", workingAttr);
4646
- return "continue";
4647
- }
4648
-
4649
-
4650
- let simpleRef={};
4651
- simpleRef[POINTER_TO_ATTR_NAME]=attrInArrayUUID;
4652
-
4653
-
4654
-
4655
- result[attrName].push(simpleRef);
4656
-
4657
-
4658
- // We add the result to the flat map :
4659
- addInFlatMapAndReplaceObjectsWithPointers(resultMap,item,attrInArrayUUID
4660
- ,UUID_ATTR_NAME,CLASSNAME_ATTR_NAME,POINTER_TO_ATTR_NAME);
4661
-
4662
-
4663
-
4664
- });
4665
-
4666
-
4667
- }else{
4668
-
4669
- if(workingAttr==null){
4670
- result[attrName]=null;
4671
- return "continue";
4672
- }
4673
- // WE ALWAYS SKIP THE FUNCTIONS !
4674
- if(isFunction(workingAttr)){
4675
- return "continue";
4676
- }
4677
- if(!isObject(workingAttr)){
4678
- result[attrName]=workingAttr;
4679
- return "continue";
4680
- }
4681
-
4682
-
4683
- let attrUUID=workingAttr[UUID_ATTR_NAME];
4684
- if(attrUUID==null){
4685
- // TRACE
4686
- console.log("ERROR : Attribute «"+attrName+"» should have a uuid under the member name «"+UUID_ATTR_NAME+"» but has none !"
4687
- +" Complete attribute object :", workingAttr
4688
- );
4689
- return "continue";
4690
- }
4691
-
4692
- let simpleRef={};
4693
- simpleRef[POINTER_TO_ATTR_NAME]=attrUUID;
4694
-
4695
-
4696
- result[attrName]=simpleRef;
4697
-
4698
-
4699
- // We add the result to the flat map :
4700
- addInFlatMapAndReplaceObjectsWithPointers(resultMap,workingAttr,attrUUID
4701
- ,UUID_ATTR_NAME,CLASSNAME_ATTR_NAME,POINTER_TO_ATTR_NAME);
4702
-
4703
-
4704
- }
4705
-
4706
-
4707
-
4708
- });
4709
-
4710
-
4711
-
4712
- return result;
4713
-
4714
- };
4715
-
4716
-
4717
- // --------------------------------
4718
- // --------------------------------
4719
-
4720
- // Unflattening :
4721
-
4722
-
4723
- // CAUTION : KNOWN LIMITATIONS : - Does not handle root-level arrays flattening !
4724
- // - Does not handle anonymous objects functions and methods population !
4725
- window.getAsTreeStructureImpl=function(oldMap, removeTypeInfo=true
4726
- ,UUID_ATTR_NAME=DEFAULT_UUID_ATTR_NAME/* Yet Another UUID */
4727
- ,CLASSNAME_ATTR_NAME=DEFAULT_CLASSNAME_ATTR_NAME/* Yet Another Classname */
4728
- ,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME/* Yet Another PointerTo */
4729
- ){
4730
-
4731
- // We have in input a map of the following form :
4732
- // { ("a uuid" : {(non-object attributes key-value pairs)*, (object attributes
4733
- // as : {<POINTER_TO_ATTR_NAME> : "a uuid"} )*}) }
4734
-
4735
- if(typeof(oldMap)==="string"){
4736
- oldMap=parseJSON(oldMap);
4737
- // oldMap=parseJSON(oldMap.replace(/"/gim,"'"));
4738
- // oldMap=eval(oldMap);
4739
- }
4740
-
4741
-
4742
- let resultMap={};
4743
-
4744
- // First we clone the existing flat map :
4745
- foreach(oldMap,(oldObj,uuid)=>{
4746
-
4747
- let className=oldObj[CLASSNAME_ATTR_NAME];
4748
-
4749
-
4750
- // // DBG
4751
- // if(className["JSONref"]){
4752
- // // DBG
4753
- // console.log("aaaaaaaaaaaaaaa oldObj:",oldObj);
4754
- // }
4755
-
4756
- // OLD AND BOGUS (SERIOUSLY, DON'T USE IT ANYMORE !) : let newObj=cloneObjectShallow(oldObj, stateOnly, className);
4757
- let newObj=structuredClone(oldObj);
4758
-
4759
-
4760
- // // DBG
4761
- // console.log(";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
4762
- // console.log(";;;;;;;;;newObj",newObj);
4763
- // console.log(";;;;;;;;;resultMap",resultMap);
4764
- // console.log(";;;;;;;;;attrName",attrName);
4765
- // console.log(";;;;;;;;;newAttr",newAttr);
4766
-
4767
-
4768
- resultMap[uuid]=newObj;
4769
-
4770
- // Then we browse the whole flat map and we remove the technical attributes if wished :
4771
- let objectToClean=resultMap[uuid];
4772
- // We always remove the uuid ! (to allow other next flattenings / unflattening cycles)
4773
- delete objectToClean[UUID_ATTR_NAME];
4774
- if(removeTypeInfo){
4775
- delete objectToClean[CLASSNAME_ATTR_NAME];
4776
-
4777
- }
4778
-
4779
- });
4780
-
4781
-
4782
-
4783
- // Second we replace all the references with pointers to the live objects :
4784
- foreach(resultMap,(newObj,uuid)=>{
4785
-
4786
- // Attributes processing :
4787
- foreach(newObj,(newAttr,attrName)=>{
4788
-
4789
-
4790
-
4791
-
4792
- if(newAttr==null){
4793
- newObj[attrName]=null;
4794
- return "continue";
4795
- }
4796
-
4797
- if(isArray(newAttr)){
4798
-
4799
- newObj[attrName]=[];
4800
-
4801
-
4802
- foreach(newAttr,(itemInArray)=>{
4803
-
4804
- // In case non-pointer type objects are also presents in the array :
4805
- // At this point, we should have only primitite-ish types items :
4806
- if( itemInArray==null
4807
- || !isObject(itemInArray)
4808
- || isArray(itemInArray)
4809
- || itemInArray[POINTER_TO_ATTR_NAME]==null){
4810
-
4811
- newObj[attrName].push(itemInArray);
4812
- return "continue";
4813
- }
4814
-
4815
-
4816
- // Pointer-type objects :
4817
- let uuidTo=itemInArray[POINTER_TO_ATTR_NAME];
4818
- let foundObjectToInNewMap=resultMap[uuidTo];
4819
-
4820
- if(!foundObjectToInNewMap){
4821
- // If we haven't found the object in the new map yet :
4822
- // TRACE
4823
- console.log("ERROR : We could'nt find the object referenced by this uuid «"+uuidTo+"» anywhere, for attribute of name «"+attrName+"». This should NEVER happen.");
4824
- }else{
4825
- newObj[attrName].push(foundObjectToInNewMap);
4826
- }
4827
-
4828
-
4829
-
4830
- });
4831
-
4832
-
4833
-
4834
- }else{
4835
-
4836
- let uuidTo=newAttr[POINTER_TO_ATTR_NAME];
4837
- let foundObjectToInNewMap=resultMap[uuidTo];
4838
-
4839
- // If object has already been entered in new map :
4840
- if(!foundObjectToInNewMap){
4841
- // If we haven't found the object in the new map yet :
4842
- // TRACE
4843
- console.log("ERROR : We could'nt find the object referenced by this uuid «"+uuidTo+"» anywhere, for attribute of name «"+attrName+"». This should NEVER happen.");
4844
- }else{
4845
- //
4846
- newObj[attrName]=foundObjectToInNewMap;
4847
- }
4848
-
4849
- }
4850
-
4851
- },(newAttr)=>{
4852
- return newAttr==null || isArray(newAttr) || (isObject(newAttr) && newAttr[POINTER_TO_ATTR_NAME]!=null);
4853
- });
4854
-
4855
- });
4856
-
4857
-
4858
-
4859
- // (We actually only return the first object, for it is the root object)
4860
- const r=getAt(resultMap,0);
4861
- return r;
4862
- };
4863
-
4864
-
4865
-
4866
-
4867
4432
 
4868
4433
  // ----------------------------------------------------------------
4869
4434
  // ----------------------------------------------------------------
@@ -4874,6 +4439,9 @@ window.getAsFlatStructure=function(rawObject
4874
4439
  ,CLASSNAME_ATTR_NAME=DEFAULT_CLASSNAME_ATTR_NAME/* Yet Another Classname */
4875
4440
  ,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME/* Yet Another PointerTo */
4876
4441
  ){
4442
+ // Flattening :
4443
+ // OLD : KNOWN LIMITATIONS : - Does not handle root-level arrays flattening !
4444
+ // - Does not handle anonymous objects functions and methods population !
4877
4445
  // OLD : return getAsFlatStructureImpl(rawObject,UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
4878
4446
  return flattenGraph(rawObject, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
4879
4447
  };
@@ -4923,8 +4491,10 @@ window.getAsTreeStructure=function(oldMap, keepClassName=false
4923
4491
  ,POINTER_TO_ATTR_NAME=DEFAULT_POINTER_TO_ATTR_NAME/* Yet Another PointerTo */
4924
4492
  ){
4925
4493
 
4926
- // MAYBE DEPRECATED USE JSON.recycle(...) INSTEAD !
4927
- //return getAsTreeStructureImpl(oldMap, !keepClassName, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
4494
+ // Unflattening :
4495
+ // OLD : KNOWN LIMITATIONS : - Does not handle root-level arrays flattening !
4496
+ // - Does not handle anonymous objects functions and methods population !
4497
+ // OLD :return getAsTreeStructureImpl(oldMap, !keepClassName, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
4928
4498
  return restoreGraph(oldMap, keepClassName, UUID_ATTR_NAME, CLASSNAME_ATTR_NAME, POINTER_TO_ATTR_NAME);
4929
4499
  };
4930
4500
 
@@ -5245,7 +4815,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
5245
4815
 
5246
4816
 
5247
4817
 
5248
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (19/03/2025-20:20:51)»*/
4818
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (19/03/2025-23:30:09)»*/
5249
4819
  /*-----------------------------------------------------------------------------*/
5250
4820
  /* ## Utility global methods in a browser (htmljs) client environment.
5251
4821
  *
@@ -13817,7 +13387,7 @@ getAORTACClient=function(clientId=getUUID(), serverNodeOrigin="ws://127.0.0.1:40
13817
13387
 
13818
13388
 
13819
13389
 
13820
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (19/03/2025-20:20:51)»*/
13390
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (19/03/2025-23:30:09)»*/
13821
13391
  /*-----------------------------------------------------------------------------*/
13822
13392
 
13823
13393
 
@@ -15056,7 +14626,7 @@ function rayVsUnitSphereClosestPoint(p, r) {
15056
14626
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
15057
14627
 
15058
14628
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
15059
- /*utils AI library associated with aotra version : «1_29072022-2359 (19/03/2025-20:20:51)»*/
14629
+ /*utils AI library associated with aotra version : «1_29072022-2359 (19/03/2025-23:30:09)»*/
15060
14630
  /*-----------------------------------------------------------------------------*/
15061
14631
 
15062
14632
 
@@ -15200,7 +14770,7 @@ getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
15200
14770
 
15201
14771
 
15202
14772
 
15203
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (19/03/2025-20:20:51)»*/
14773
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (19/03/2025-23:30:09)»*/
15204
14774
  /*-----------------------------------------------------------------------------*/
15205
14775
 
15206
14776
 
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.1156",
3
+ "version": "0.0.1158",
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)",