aotrautils-srv 0.0.597 → 0.0.599
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 (24/09/2023-
|
|
3
|
+
/*utils COMMONS library associated with aotra version : «1_29072022-2359 (24/09/2023-23:04:33)»*/
|
|
4
4
|
/*-----------------------------------------------------------------------------*/
|
|
5
5
|
|
|
6
6
|
|
|
@@ -507,7 +507,7 @@ window.aotestMethods.getScenariiInTest=function(test){
|
|
|
507
507
|
|
|
508
508
|
// CAUTION : We ABSOLUTELY need to iterate over a deep copy, or else it will create weird incomprehensible bugs
|
|
509
509
|
// if we do another recursive browsing on the initial object !!!
|
|
510
|
-
const scenario=
|
|
510
|
+
const scenario=parseJSON(stringifyObject(scenarioParam));
|
|
511
511
|
|
|
512
512
|
|
|
513
513
|
const basePath=valuePath;
|
|
@@ -3805,13 +3805,13 @@ window.instanciate=function(className=null){
|
|
|
3805
3805
|
JSON.stringifyDecycle=function(obj){
|
|
3806
3806
|
let decycled=JSON.decycle(obj,null,"$className");
|
|
3807
3807
|
// CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
|
|
3808
|
-
return
|
|
3808
|
+
return stringifyObject(decycled);
|
|
3809
3809
|
}
|
|
3810
3810
|
|
|
3811
3811
|
|
|
3812
3812
|
JSON.parseRecycle=function(str){
|
|
3813
3813
|
|
|
3814
|
-
const parsedDecycled=
|
|
3814
|
+
const parsedDecycled=parseJSON(str);
|
|
3815
3815
|
let restoreClass=function(objParam){
|
|
3816
3816
|
|
|
3817
3817
|
if(!objParam || isPrimitive(objParam)) return objParam;
|
|
@@ -4365,9 +4365,7 @@ window.getAsFlatStructureImpl=function(rawObject, stateOnly=false
|
|
|
4365
4365
|
});
|
|
4366
4366
|
|
|
4367
4367
|
|
|
4368
|
-
// // DBG
|
|
4369
4368
|
// CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
|
|
4370
|
-
// console.log("¬¬¬¬resultMap STRINGIFY",JSON.stringify(resultMap));
|
|
4371
4369
|
|
|
4372
4370
|
return resultMap;
|
|
4373
4371
|
};
|
|
@@ -4609,8 +4607,8 @@ window.getAsTreeStructureImpl=function(oldMap, stateOnly=false, removeTypeInfo=t
|
|
|
4609
4607
|
// as : {<POINTER_TO_ATTR_NAME> : "a uuid"} )*}) }
|
|
4610
4608
|
|
|
4611
4609
|
if(typeof(oldMap)==="string"){
|
|
4612
|
-
oldMap=
|
|
4613
|
-
// oldMap=
|
|
4610
|
+
oldMap=parseJSON(oldMap);
|
|
4611
|
+
// oldMap=parseJSON(oldMap.replace(/"/gim,"'"));
|
|
4614
4612
|
// oldMap=eval(oldMap);
|
|
4615
4613
|
}
|
|
4616
4614
|
|
|
@@ -4836,7 +4834,7 @@ JSON.decycle=function decycle(object, replacer, classNameAttributeName){
|
|
|
4836
4834
|
|
|
4837
4835
|
// var a=[];
|
|
4838
4836
|
// a[0]=a;
|
|
4839
|
-
// return
|
|
4837
|
+
// return stringifyObject(JSON.decycle(a));
|
|
4840
4838
|
|
|
4841
4839
|
//produces the string '[{"$ref":"$"}]'.
|
|
4842
4840
|
|
|
@@ -4900,7 +4898,7 @@ JSON.decycle=function decycle(object, replacer, classNameAttributeName){
|
|
|
4900
4898
|
nu={};
|
|
4901
4899
|
Object.keys(value).forEach(function (name){
|
|
4902
4900
|
// CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
|
|
4903
|
-
nu[name]=derez( value[name], path + "[" +
|
|
4901
|
+
nu[name]=derez( value[name], path + "[" + stringifyObject(name) + "]"
|
|
4904
4902
|
);
|
|
4905
4903
|
});
|
|
4906
4904
|
|
|
@@ -4937,7 +4935,7 @@ JSON.recycle=function recycle($){
|
|
|
4937
4935
|
|
|
4938
4936
|
//So,
|
|
4939
4937
|
// var s='[{"$ref":"$"}]';
|
|
4940
|
-
// return JSON.recycle(
|
|
4938
|
+
// return JSON.recycle(parseJSON(s));
|
|
4941
4939
|
//produces an array containing a single element which is the array itself.
|
|
4942
4940
|
|
|
4943
4941
|
var px=/^\$(?:\[(?:\d+|"(?:[^\\"\u0000-\u001f]|\\(?:[\\"\/bfnrt]|u[0-9a-zA-Z]{4}))*")\])*$/;
|
|
@@ -4985,7 +4983,66 @@ JSON.recycle=function recycle($){
|
|
|
4985
4983
|
|
|
4986
4984
|
|
|
4987
4985
|
|
|
4986
|
+
// JSON parsing management :
|
|
4987
|
+
function parseJSON(strParam){
|
|
4988
|
+
|
|
4989
|
+
if(!isString(strParam)) return strParam;
|
|
4990
|
+
|
|
4991
|
+
if (nothing(strParam))
|
|
4992
|
+
return null;
|
|
4993
|
+
var str=toOneSimplifiedLine(strParam.trim())
|
|
4994
|
+
// OLD : Safer, but necessited to never use «'» in literal strings, and use «´» acute character instead !
|
|
4995
|
+
.replace(/'/gim, "\"");
|
|
4996
|
+
// DOES NOT WORK :
|
|
4997
|
+
// .replace(/,'/gim, ",\"")
|
|
4998
|
+
// .replace(/:'/gim, ":\"")
|
|
4999
|
+
// .replace(/{'/gim, "{\"")
|
|
5000
|
+
// .replace(/}'/gim, "}\"")
|
|
5001
|
+
// .replace(/\['/gim, "[\"")
|
|
5002
|
+
// .replace(/\]'/gim, "]\"");
|
|
5003
|
+
try {
|
|
5004
|
+
|
|
5005
|
+
if((JSON && JSON.parse && typeof JSON.parse !== "undefined" && typeof JSON.parse === "function"
|
|
5006
|
+
) || jQuery)
|
|
5007
|
+
return JSON.parse(str);
|
|
5008
|
+
if(typeof jQuery !== "undefined" && typeof jQuery.parseJSON !== "undefined" && typeof jQuery.parseJSON === "function"){
|
|
5009
|
+
return jQuery.parseJSON(str);
|
|
5010
|
+
}
|
|
5011
|
+
throw new Error("ERROR : No JSON subsystem found to parse the JSON string.");
|
|
5012
|
+
|
|
5013
|
+
} catch (error){
|
|
5014
|
+
// TRACE
|
|
5015
|
+
log("WARN : Error parsing string «" + strParam + "» as JSON. Trying last-chance fallback.");
|
|
5016
|
+
try {
|
|
5017
|
+
var obj=eval("(" + str + ")");
|
|
5018
|
+
|
|
5019
|
+
return obj;
|
|
5020
|
+
} catch (error2){
|
|
5021
|
+
|
|
5022
|
+
// TRACE
|
|
5023
|
+
log(error2);
|
|
5024
|
+
log("ERROR : Error parsing string «" + strParam + "» as JSON. Last-chance fallback failed." +
|
|
5025
|
+
" CHECK IF THERE IS ANY «'» SINGLE QUOTE CHARACTER IN YOUR LITERALS STRINGS, AND REPLACE IT WITH «´» ACUTE CHARACTER INSTEAD.");
|
|
5026
|
+
|
|
5027
|
+
}
|
|
5028
|
+
|
|
5029
|
+
}
|
|
5030
|
+
return null;
|
|
5031
|
+
}
|
|
4988
5032
|
|
|
5033
|
+
function stringifyObject(objectToStringify){
|
|
5034
|
+
|
|
5035
|
+
if(nothing(objectToStringify)) return null;
|
|
5036
|
+
|
|
5037
|
+
if (JSON && JSON.stringify && typeof JSON.stringify !== "undefined" && typeof JSON.stringify === "function"){
|
|
5038
|
+
return JSON.stringify(objectToStringify);
|
|
5039
|
+
}
|
|
5040
|
+
if(typeof jQuery !== "undefined" && typeof jQuery.stringify !== "undefined" && typeof jQuery.stringify === "function"){
|
|
5041
|
+
return jQuery.stringify(objectToStringify);
|
|
5042
|
+
}
|
|
5043
|
+
log("ERROR : No JSON subsystem found to stringify the javascript object.");
|
|
5044
|
+
return null;
|
|
5045
|
+
}
|
|
4989
5046
|
|
|
4990
5047
|
|
|
4991
5048
|
|
|
@@ -4997,7 +5054,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
|
|
|
4997
5054
|
|
|
4998
5055
|
|
|
4999
5056
|
|
|
5000
|
-
/*utils SERVER library associated with aotra version : «1_29072022-2359 (24/09/2023-
|
|
5057
|
+
/*utils SERVER library associated with aotra version : «1_29072022-2359 (24/09/2023-23:04:33)»*/
|
|
5001
5058
|
/*-----------------------------------------------------------------------------*/
|
|
5002
5059
|
|
|
5003
5060
|
|
|
@@ -5102,7 +5159,7 @@ if(typeof(fs)==="undefined"){
|
|
|
5102
5159
|
let resultData={};
|
|
5103
5160
|
|
|
5104
5161
|
// 1)
|
|
5105
|
-
if(!empty(resultFlat)) resultData=
|
|
5162
|
+
if(!empty(resultFlat)) resultData=parseJSON(resultFlat);
|
|
5106
5163
|
|
|
5107
5164
|
// 2)
|
|
5108
5165
|
if(!empty(resultData) && isFlatMap(resultData)){
|
|
@@ -5125,7 +5182,7 @@ if(typeof(fs)==="undefined"){
|
|
|
5125
5182
|
|
|
5126
5183
|
// reserved characters : -/\^$*+?.()|[]{}
|
|
5127
5184
|
// CANNOT USE stringifyObject(...) function because we are in a common, lower-level library !
|
|
5128
|
-
let dataFlatStr=
|
|
5185
|
+
let dataFlatStr=stringifyObject(dataFlatForClient)
|
|
5129
5186
|
// We «aerate» the produced JSON :
|
|
5130
5187
|
.replace(/":[\w]*\{/gim,"\":{\n").replace(/,"/gim,",\n\"")
|
|
5131
5188
|
// ...except for inline, escaped JSON string representations :
|
|
@@ -5314,11 +5371,11 @@ WebsocketImplementation={
|
|
|
5314
5371
|
let dataResult=eventOrMessage;
|
|
5315
5372
|
|
|
5316
5373
|
try{
|
|
5317
|
-
dataResult=(WebsocketImplementation.useFlatStrings || isString(eventOrMessage)?
|
|
5374
|
+
dataResult=(WebsocketImplementation.useFlatStrings || isString(eventOrMessage)?parseJSOn(eventOrMessage):eventOrMessage);
|
|
5318
5375
|
}catch(error1){
|
|
5319
5376
|
// TRACE
|
|
5320
5377
|
lognow(`ERROR : Failed to parse JSON for string «${dataResult}»`,error1);
|
|
5321
|
-
dataResult=(isString(eventOrMessage)?eventOrMessage:
|
|
5378
|
+
dataResult=(isString(eventOrMessage)?eventOrMessage:stringifyObject(eventOrMessage));
|
|
5322
5379
|
}
|
|
5323
5380
|
|
|
5324
5381
|
return dataResult;
|
|
@@ -5392,7 +5449,7 @@ WebsocketImplementation={
|
|
|
5392
5449
|
// // DBG
|
|
5393
5450
|
// lognow("(SERVER) RECEIVED SOMETHING FROM CLIENT...", eventOrMessage.data);
|
|
5394
5451
|
|
|
5395
|
-
// dataWrapped=
|
|
5452
|
+
// dataWrapped=parseJSON(dataWrapped);
|
|
5396
5453
|
// dataWrapped=getAt(dataWrapped,0);// We get the root element
|
|
5397
5454
|
|
|
5398
5455
|
|
|
@@ -5477,7 +5534,7 @@ WebsocketImplementation={
|
|
|
5477
5534
|
let dataWrapped={channelName:channelName, data:data};
|
|
5478
5535
|
|
|
5479
5536
|
|
|
5480
|
-
dataWrapped=
|
|
5537
|
+
dataWrapped=stringifyObject(dataWrapped);
|
|
5481
5538
|
|
|
5482
5539
|
// TODO : FIXME : Use one single interface !
|
|
5483
5540
|
if(!WebsocketImplementation.useSocketIOImplementation) clientSocket.send(dataWrapped);
|
|
@@ -5502,7 +5559,7 @@ WebsocketImplementation={
|
|
|
5502
5559
|
|
|
5503
5560
|
// Channel information is stored in exchanged data :
|
|
5504
5561
|
let dataWrapped={channelName:channelName, data:data};
|
|
5505
|
-
dataWrapped=
|
|
5562
|
+
dataWrapped=stringifyObject(dataWrapped);
|
|
5506
5563
|
|
|
5507
5564
|
|
|
5508
5565
|
// DBG
|
|
@@ -5740,9 +5797,9 @@ WebsocketImplementation={
|
|
|
5740
5797
|
clientsRoomsTag:clientsRoomsTag,
|
|
5741
5798
|
execute:(eventOrMessage)=>{
|
|
5742
5799
|
|
|
5743
|
-
// dataWrapped=
|
|
5800
|
+
// dataWrapped=parseJSON(dataWrapped);
|
|
5744
5801
|
// dataWrapped=getAt(dataWrapped,0);// We get the root element
|
|
5745
|
-
// const dataWrapped=(WebsocketImplementation.useFlatStrings?
|
|
5802
|
+
// const dataWrapped=(WebsocketImplementation.useFlatStrings?parseJSON(eventOrMessage):eventOrMessage);
|
|
5746
5803
|
|
|
5747
5804
|
const dataWrapped=WebsocketImplementation.getMessageDataBothImplementations(eventOrMessage);
|
|
5748
5805
|
|
|
@@ -5804,7 +5861,7 @@ WebsocketImplementation={
|
|
|
5804
5861
|
// console.log("(NODE CLIENT) SENDING DATA ! dataWrapped:",dataWrapped);
|
|
5805
5862
|
|
|
5806
5863
|
|
|
5807
|
-
dataWrapped=
|
|
5864
|
+
dataWrapped=stringifyObject(dataWrapped);
|
|
5808
5865
|
|
|
5809
5866
|
|
|
5810
5867
|
// // DBG
|
|
@@ -6056,7 +6113,7 @@ WebsocketImplementation={
|
|
|
6056
6113
|
console.log("(BROWSER) SENDING... : clientSocket :",clientSocket);
|
|
6057
6114
|
|
|
6058
6115
|
|
|
6059
|
-
dataWrapped=
|
|
6116
|
+
dataWrapped=stringifyObject(dataWrapped);
|
|
6060
6117
|
|
|
6061
6118
|
|
|
6062
6119
|
// TODO : FIXME : Use one single interface !
|
|
@@ -6313,7 +6370,7 @@ initNodeServerInfrastructureWrapper=function(doOnClientConnection=null, doOnFina
|
|
|
6313
6370
|
}else if(i==3){
|
|
6314
6371
|
if(!isHashAsked){
|
|
6315
6372
|
try{
|
|
6316
|
-
const jsonConf=
|
|
6373
|
+
const jsonConf=parseJSON(val);
|
|
6317
6374
|
argCLPort=jsonConf.port;
|
|
6318
6375
|
argCLCertPath=jsonConf.sslCertPath;
|
|
6319
6376
|
argCLKeyPath=jsonConf.sslKeyPath;
|
aotrautils-srv/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aotrautils-srv",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.599",
|
|
4
4
|
"main": "aotrautils-srv.build.js",
|
|
5
5
|
"description": "A library for vanilla javascript utils (server-side) used in aotra javascript CMS",
|
|
6
6
|
"author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",
|