puvox-library 1.0.88 → 1.1.1

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.
@@ -356,9 +356,8 @@ declare class PuvoxLibrary {
356
356
  enable_jquery_errors(): void;
357
357
  encode_chars(str: any, chars?: any[]): any;
358
358
  telegramMessage(textOriginal: any, chat_id: any, bot_key: any, extra_opts?: {}): Promise<any>;
359
- telegram_interval_ms: number;
360
- telegram_last_sent_time: number;
361
- telegramMessageCached(text: any, chat_id: any, bot_key: any, extra_opts?: {}, customCacheId?: null): Promise<any>;
359
+ telegram_interval_ms: number | undefined;
360
+ telegram_last_sent_timestamp: number | undefined;
362
361
  openUrlInBrowser(url: any): void;
363
362
  stringify(obj_or_str: any): any;
364
363
  stringify_plain(data: any): string;
@@ -374,6 +373,7 @@ declare class PuvoxLibrary {
374
373
  privateAppName__: null;
375
374
  setAppName(name: any): void;
376
375
  getAppName(): never;
376
+ stringifyForWrite(content: any): any;
377
377
  Cookies: {
378
378
  parentClass: null;
379
379
  mainClass(): null;
@@ -395,24 +395,32 @@ declare class PuvoxLibrary {
395
395
  cache: {
396
396
  parentClass: null;
397
397
  mainClass(): null;
398
- helper_read(groupName: any, storageType: any, expireSeconds?: number): any;
399
- helper_write(groupName: any, content: any, storageType: any): true | undefined;
400
- helper_delete(groupName: any, storageType: any): true | undefined;
401
- get(groupName: any, defaultVal?: null, storageType?: string, expireSeconds?: number): any;
402
- set(groupName: any, content: any, storageType?: string): void;
403
- delete(groupName: any, storageType?: string): void;
404
- getChild(groupName: any, optName: any, defaultVal?: null, storageType?: string, expireSeconds?: number): any;
405
- setChild(groupName: any, optName: any, val: any, storageType?: string): void;
406
- deleteChild(groupName: any, optName: any, storageType?: string): void;
398
+ helper_get_child(instanceClass: any, optName: any, subKeyName: any, defaultVal?: null, expireSeconds?: number): any;
399
+ helper_set_child(instanceClass: any, optName: any, subKeyName: any, val: any): void;
400
+ helper_delete_child(instanceClass: any, optName: any, subKeyName: any): void;
401
+ localstorage: {
402
+ parentClass: null;
403
+ mainClass(): any;
404
+ get(optName: any, defaultValue?: null, decode?: boolean, expireSeconds?: number): any;
405
+ set(optName: any, content: any): true | undefined;
406
+ delete(optName: any): boolean;
407
+ get_child(optName: any, subKeyName: any, defaultVal?: null, expireSeconds?: number): any;
408
+ set_child(optName: any, subKeyName: any, val: any): any;
409
+ delete_child(optName: any, subKeyName: any): any;
410
+ };
407
411
  file: {
408
412
  parentClass: null;
409
413
  mainClass(): any;
410
414
  customCacheDir: null;
411
- get_dir(): any;
415
+ file_path(optName: any): string;
416
+ get(optName: any, defaultValue?: null, decode?: boolean, expire_seconds?: number): any;
417
+ set(optName: any, content: any): any;
418
+ delete(optName: any): any;
419
+ get_child(optName: any, subKeyName: any, defaultVal?: null, expireSeconds?: number): any;
420
+ set_child(optName: any, subKeyName: any, val: any): any;
421
+ delete_child(optName: any, subKeyName: any): any;
412
422
  set_dir(dir: any, auto_clear_seconds?: null): any;
413
423
  filePath(uniqFileName: any): string;
414
- get(uniqFileName: any, defaultContent?: string, expire_seconds?: number, decode?: boolean): any;
415
- set(uniqFileName: any, content: any): any;
416
424
  containerDefaultPrefix: string;
417
425
  tempIds: {};
418
426
  idForContent(slugOrContent: any): any;
@@ -439,8 +447,9 @@ declare class PuvoxLibrary {
439
447
  delete(filePath: any): any;
440
448
  unlink(filePath: any): any;
441
449
  createDirectory(dirPath: any): any;
442
- read(filePath: any, defaultContent?: string): any;
443
- write(filePath: any, content: any): void;
450
+ read(filePath: any, defaultValue?: string): any;
451
+ readCustom(filePath: any, defaultValue?: string, decode?: boolean, expireSeconds?: number): any;
452
+ write(filePath: any, content: any): any;
444
453
  getFilesListFromDir(dir: any): any[];
445
454
  };
446
455
  catchUnhandledExceptions(callback: any): void;
@@ -1 +1 @@
1
- {"version":3,"file":"library_standard.d.ts","sourceRoot":"","sources":["library_standard.js"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;AAEF;IAGC,0BAEC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IACD,gCAEC;IAGD,uBAAwB;IACxB,4BAAkD;IAClD,oBAKC;IAID;;;;;;;;;;;;;;;;;MAwES;IAGT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MA2OS;IAaT;;;;;;;;;;;;;;;;;;;MAuFS;IAET,8CAIC;IAiBD;;;MAAkB;IACf,oBAAkE;IAClE,4BAAuD;IACvD,mBAAyE;IACzE,wBAA6C;IAC7C,qBAAuB;IACvB,sBAAgD;IAChD,iCAA0C;IAI1C,0BAEC;IACD,8BAKC;IACD,8BAKC;IACD,sCASC;IACD,sCAUC;IACD,gEAQC;IACD,4EAUF;IACE,yFAgBF;IACE,oCASC;IACD,2BAA+E;IAC/E,kCAeC;IACD,uBAGC;IACD,8BAeC;IAEJ,uCAA0B;IAGvB,0BAA0D;IAG1D,0BAA4C;IAC5C,8BAA4I;IAC5I,+BAAuF;IAC1F,0BAA6F;IAC7F,sDAA8G;IAC9G,wBAA4G;IAC5G,0BAAqH;IAUrH,uCAaC;IACD,wEAKC;IACD,4CAAgE;IAChE,0CAMC;IAEE,wCAIC;IAEJ,sCAGC;IACD,4BAEC;IAED,mBAAwC;IACxC,oBAA0I;IAC1I,qBAA6F;IAC7F,mBAA0E;IAE1E,gBAA4H;IAC5H,2BAAmB;IAEnB,kBAAgI;IAChI,wBAAmF;IAChF,mBAAgD;IAEnD,kBAAe;IACf,2BAAsB;IACtB,kBAAoD;CAEpD"}
1
+ {"version":3,"file":"library_standard.d.ts","sourceRoot":"","sources":["library_standard.js"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;EAeE;AAEF;IAGC,0BAEC;IAJD,uBAAgB;IAQhB,uDAEC;IACD,4DAGC;IACD,4DAGC;IACD,6CAIC;IACD,8CAIC;IAykDE,uCAGC;IA3kDJ,iDAMC;IACD,oCAEC;IACD,6DAYC;IACD,kCAA8D;IAC9D,+BAAkD;IAClD,6BAAuD;IACvD,uCAOC;IACD,6CAOC;IACD,6CAEC;IACD,kDAEC;IACD,uCAsDC;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vD,mBAAyE;IACzE,wBAA6C;IAC7C,qBAAuB;IACvB,sBAAgD;IAChD,iCAA0C;IAI1C,0BAEC;IACD,8BAKC;IACD,8BAKC;IACD,sCASC;IACD,sCAUC;IACD,gEAQC;IACD,4EAUF;IACE,yFAgBF;IACE,oCASC;IACD,2BAA+E;IAC/E,kCAeC;IACD,uBAGC;IACD,8BAeC;IAEJ,uCAA0B;IAGvB,0BAA0D;IAG1D,0BAA4C;IAC5C,8BAA4I;IAC5I,+BAAuF;IAC1F,0BAA6F;IAC7F,sDAA8G;IAC9G,wBAA4G;IAC5G,0BAAqH;IAUrH,uCAaC;IACD,wEAKC;IACD,4CAAgE;IAChE,0CAMC;IAEE,wCAIC;IAEJ,sCAGC;IACD,4BAEC;IAED,mBAAwC;IACxC,oBAA0I;IAC1I,qBAA6F;IAC7F,mBAA0E;IAE1E,gBAA4H;IAC5H,2BAAmB;IAEnB,kBAAgI;IAChI,wBAAmF;IAChF,mBAAgD;IAEnD,kBAAe;IACf,2BAAsB;IACtB,kBAAoD;CAEpD"}
@@ -2697,8 +2697,9 @@ class PuvoxLibrary {
2697
2697
  return str;
2698
2698
  }
2699
2699
 
2700
+
2700
2701
  // region ### TELEGRAM FUNCTIONS ###
2701
- async telegramMessage(textOriginal, chat_id, bot_key, extra_opts={}){
2702
+ async telegramMessage(textOriginal, chat_id, bot_key, extra_opts={}){
2702
2703
  if (!extra_opts) extra_opts = {};
2703
2704
  if (! ('parse_mode' in extra_opts)){
2704
2705
  extra_opts['parse_mode'] = 'html';
@@ -2716,8 +2717,45 @@ class PuvoxLibrary {
2716
2717
  //
2717
2718
  const is_repeated_call = ('is_repeated_call' in extra_opts);
2718
2719
  delete extra_opts['is_repeated_call'];
2720
+ // ###############################################
2721
+ // ############## support caching ###############
2722
+ // ########## (ppl can remove this part) #########
2723
+ // ###############################################
2724
+ //
2725
+ // you can set custom random cache_id, so if that cache_id is found in store datas, it avoids sending the same message to telegram
2726
+ //
2727
+ if ('cache_id' in extra_opts){
2728
+ if (!this.telegram_interval_ms) {
2729
+ this.telegram_interval_ms= 50; // telegram seems to accept around 30 times per second, so we'd better wait around that milliseconds
2730
+ }
2731
+ if (!this.telegram_last_sent_timestamp) {
2732
+ this.telegram_last_sent_timestamp= 0;
2733
+ }
2734
+ const curMS = this.milliseconds();
2735
+ const goneMS = curMS - this.telegram_last_sent_timestamp;
2736
+ if ( goneMS < this.telegram_interval_ms ){
2737
+ await this.sleep (this.telegram_interval_ms - goneMS);
2738
+ }
2739
+ this.telegram_last_sent_timestamp = curMS;
2740
+ const opt_cache_id = extra_opts['cache_id'];
2741
+ delete extra_opts['cache_id'];
2742
+ const cacheId = opt_cache_id ? opt_cache_id : this.cache.file.idForContent( text +'_'+ chat_id +'_'+ bot_key +'_'+ JSON.stringify(extra_opts) );
2743
+ if (!this.cache.file.addIdIfNotExists('function_telegram_message', cacheId) ){
2744
+ return {'ok': true, 'cached':true};
2745
+ }
2746
+ }
2747
+ // ###############################################
2748
+ // ################ [ END CACHING ]###############
2749
+ // ###############################################
2719
2750
  const requestOpts = Object.assign({'chat_id':chat_id, 'text':text}, extra_opts);
2720
- let responseText = await this.getRemoteData('https://api.telegram.org/bot'+ bot_key +'/sendMessage', requestOpts); // pastebin_com/u0J1Cph3 //'sendMessage?'.http_build_query(opts, '');
2751
+ let responseText = undefined;
2752
+ const isPhotoMessage = ('photo' in extra_opts);
2753
+ if (!isPhotoMessage) {
2754
+ responseText = await this.getRemoteData('https://api.telegram.org/bot'+ bot_key +'/sendMessage', requestOpts); // pastebin_com/u0J1Cph3 //'sendMessage?'.http_build_query(opts, '');
2755
+ } else {
2756
+ requestOpts['caption'] = requestOpts['text'].substring(0, 1023);
2757
+ responseText = await this.getRemoteData('https://api.telegram.org/bot'+ bot_key +'/sendPhoto', requestOpts); // pastebin_com/u0J1Cph3 //'sendMessage?'.http_build_query(opts, '');
2758
+ }
2721
2759
  try {
2722
2760
  const responseJson = JSON.parse(responseText);
2723
2761
  if (responseJson.ok){
@@ -2743,29 +2781,6 @@ class PuvoxLibrary {
2743
2781
  }
2744
2782
  }
2745
2783
 
2746
- telegram_interval_ms= 50; // telegram seems to accept around 30 times per second, so we'd better wait around that milliseconds
2747
- telegram_last_sent_time= 0;
2748
-
2749
- async telegramMessageCached(text, chat_id, bot_key, extra_opts={}, customCacheId=null){
2750
- if (!extra_opts) extra_opts = {};
2751
- const curMS = this.milliseconds();
2752
- const goneMS = curMS - this.telegram_last_sent_time;
2753
- if ( goneMS < this.telegram_interval_ms ){
2754
- await this.sleep (this.telegram_interval_ms - goneMS);
2755
- }
2756
- this.telegram_last_sent_time = curMS;
2757
- const cacheId = customCacheId ? customCacheId : this.cache.file.idForContent( text +'_'+ chat_id +'_'+ bot_key +'_'+ JSON.stringify(extra_opts) );
2758
- if (this.cache.file.addIdIfNotExists('function_telegram_message', cacheId) ){
2759
- return this.telegramMessage(text, chat_id, bot_key, extra_opts);
2760
- }
2761
- else {
2762
- return false;
2763
- }
2764
- //if(is_callable([$this,'notifications_db_entry']))
2765
- // $this->notifications_db_entry($key, $array['chat_id'], $this->stringify($res), time(), $ok );
2766
- //return $res;
2767
- }
2768
-
2769
2784
  openUrlInBrowser(url)
2770
2785
  {
2771
2786
  var cmd = (process.platform == 'darwin'? `open ${url}`: process.platform == 'win32'? `start ${url}`: `xdg-open ${url}`);
@@ -2884,6 +2899,18 @@ class PuvoxLibrary {
2884
2899
  return this.privateAppName__;
2885
2900
  }
2886
2901
 
2902
+ stringifyForWrite(content) {
2903
+ if (this.isString(content)) {
2904
+ return content;
2905
+ }
2906
+ else if (this.isNumeric(content)) {
2907
+ return content.toString();
2908
+ }
2909
+ else if (this.isObject(content) || this.isArray(content)) {
2910
+ return JSON.stringify(content);
2911
+ }
2912
+ return content;
2913
+ }
2887
2914
 
2888
2915
  // ######## Cookies: https://github.com/ttodua/useful-javascript/blob/master/cookies-library.js ######## //
2889
2916
  Cookies = new (class {
@@ -2967,107 +2994,78 @@ class PuvoxLibrary {
2967
2994
  this.parentClass = parentClass;
2968
2995
  }
2969
2996
  mainClass() { return this.parentClass; }
2997
+
2998
+ helper_get_child(instanceClass, optName, subKeyName, defaultVal = null, expireSeconds = 0){
2999
+ const json = instanceClass.get(optName, {}, true, expireSeconds);
3000
+ return (subKeyName in json) ? json[subKeyName] : defaultVal;
3001
+ }
3002
+ helper_set_child(instanceClass, optName, subKeyName, val){
3003
+ const json = instanceClass.get(optName, {}, true, 0);
3004
+ json[subKeyName] = val;
3005
+ instanceClass.set(optName, json);
3006
+ }
3007
+ helper_delete_child(instanceClass, optName, subKeyName){
3008
+ const json = instanceClass.get(optName, {}, true, 0);
3009
+ delete json[subKeyName];
3010
+ instanceClass.set(optName, json);
3011
+ }
3012
+
3013
+ // lets localstrage be under cache class
3014
+ localstorage = new (class {
3015
+ parentClass = null;
3016
+ constructor(parentClass){
3017
+ this.parentClass = parentClass;
3018
+ }
3019
+ mainClass() { return this.parentClass.parentClass; }
2970
3020
 
2971
- helper_read(groupName, storageType, expireSeconds = 0){
2972
- const appName = this.mainClass().getAppName();
2973
- if (storageType === 'file'){
2974
- const dir = this.mainClass().file.tempDir() + appName + '/';
2975
- const filepath = dir + groupName + '.json';
2976
- // todo: add expiration
2977
- return this.mainClass().file.read(filepath);
2978
- } else if (storageType === 'localStorage') {
3021
+ // ###################
3022
+ get(optName, defaultValue = null, decode = true, expireSeconds = 0){
3023
+ const appName = this.mainClass().getAppName();
2979
3024
  const storage = window.localStorage;
2980
- let val = storage.getItem(appName + '_' + groupName);
2981
- let expireVal = parseInt(storage.getItem(appName + '_' + groupName + '_t'));
3025
+ const tsValue = storage.getItem(appName + '_' + optName + '_t');
3026
+ let expireVal = tsValue ? parseInt(tsValue) : 0;
2982
3027
  // if it's expired, then return null
2983
3028
  if (expireSeconds !== 0 && (new Date()).getTime() - expireVal > expireSeconds*1000){
2984
- this.storage.removeItem(appName + '_' + groupName);
2985
- this.storage.removeItem(appName + '_' + groupName + '_t');
2986
- return null;
3029
+ storage.removeItem(appName + '_' + optName);
3030
+ storage.removeItem(appName + '_' + optName + '_t');
3031
+ return defaultValue;
2987
3032
  } else {
3033
+ const val = storage.getItem(appName + '_' + optName);
3034
+ if (decode) { try { return JSON.parse(val) } catch(e) {} }
2988
3035
  return val;
2989
3036
  }
2990
- } else {
2991
- if (typeof alert !== 'undefined') alert(`storageType ${storageType} not supported`);
2992
- throw new Error(`storageType ${storageType} not supported`);
2993
- }
2994
- }
2995
- helper_write(groupName, content, storageType){
2996
- content = this.mainClass().isString (content) ? content : (this.mainClass().isArray(content) || this.mainClass().isObject(content) ? JSON.stringify(content) : content);
2997
- const appName = this.mainClass().getAppName();
2998
- if (storageType === 'file'){
2999
- const dir = this.mainClass().file.tempDir() + appName + '/';
3000
- this.mainClass().file.createDirectory(dir);
3001
- const filepath = dir + groupName + '.json';
3002
- // todo: add expiration
3003
- this.mainClass().file.write(filepath, content);
3004
- return true;
3005
- } else if (storageType === 'localStorage') {
3006
- try{
3007
- const storage = window.localStorage;
3008
- storage.setItem(appName + '_' + groupName, content);
3009
- storage.setItem(appName + '_' + groupName + '_t', (new Date()).getTime());
3010
- return true;
3011
- }
3012
- catch(ex){ alert("Cache storage quote exceeded. can't save value. err598 |" + ex.message); }
3013
- } else {
3014
- if (typeof alert !== 'undefined') alert(`storageType ${storageType} not supported`);
3015
- throw new Error(`storageType ${storageType} not supported`);
3016
- }
3017
- }
3018
- helper_delete(groupName, storageType){
3019
- const appName = this.mainClass().getAppName();
3020
- if (storageType === 'file'){
3021
- const filepath = this.mainClass().file.tempDir() + appName + '/' + groupName + '.json';
3022
- // todo: better delete
3023
- this.mainClass().file.delete(filepath);
3024
- return true;
3025
- } else if (storageType === 'localStorage') {
3037
+ }
3038
+ set(optName, content){
3026
3039
  try{
3027
3040
  const storage = window.localStorage;
3028
- storage.setItem(appName + '_' + groupName, content);
3029
- storage.setItem(appName + '_' + groupName + '_t', (new Date()).getTime());
3041
+ const finalContent = this.mainClass().stringifyForWrite(content);
3042
+ storage.setItem(appName + '_' + optName, finalContent);
3043
+ storage.setItem(appName + '_' + optName + '_t', (new Date()).getTime());
3030
3044
  return true;
3031
3045
  }
3032
- catch(ex){ alert("Cache storage quote exceeded. can't save value. err598 |" + ex.message); }
3033
- } else {
3034
- alert(`storageType ${storageType} not supported`);
3035
- throw new Error(`storageType ${storageType} not supported`);
3046
+ catch(ex){ alert("Can't save value. Might be exceeding cache size. err598 |" + ex.message); }
3036
3047
  }
3037
- }
3038
-
3039
- get(groupName, defaultVal = null, storageType = 'localStorage', expireSeconds = 0){
3040
- const content = this.helper_read(groupName, storageType, expireSeconds);
3041
- return (content !== null && content !== '') ? content : defaultVal;
3042
- }
3043
- set(groupName, content, storageType = 'localStorage'){
3044
- this.helper_write(groupName, content, storageType);
3045
- }
3046
- delete(groupName, storageType = 'localStorage'){
3047
- this.helper_delete(groupName, storageType);
3048
- }
3049
- getChild(groupName, optName, defaultVal = null, storageType = 'localStorage', expireSeconds = 0){
3050
- // todo: individual sub-item expiration
3051
- const content = this.get(groupName, '{}', storageType, expireSeconds);
3052
- const json = JSON.parse(content);
3053
- return (optName in json) ? json[optName] : defaultVal;
3054
- }
3055
- setChild(groupName, optName, val, storageType = 'localStorage'){
3056
- const content = this.get(groupName, '{}', storageType);
3057
- const json = JSON.parse(content);
3058
- json[optName] = val;
3059
- this.set(groupName, JSON.stringify(json), storageType);
3060
- }
3061
- deleteChild(groupName, optName, storageType = 'localStorage'){
3062
- const content = this.get(groupName, '{}', storageType, expireSeconds);
3063
- // if it's empty, no need to do anything
3064
- if (content === '{}') return;
3065
- const json = JSON.parse(content);
3066
- delete json[optName];
3067
- this.set(groupName, JSON.stringify(json), storageType);
3068
- }
3069
-
3048
+ delete(optName){
3049
+ const storage = window.localStorage;
3050
+ storage.removeItem(appName + '_' + optName);
3051
+ storage.removeItem(appName + '_' + optName + '_t');
3052
+ return true;
3053
+ }
3054
+ // ################ child methods ################## //
3055
+ get_child(optName, subKeyName, defaultVal = null, expireSeconds = 0){
3056
+ return this.parentClass.helper_get_child(this, optName, subKeyName, defaultVal, expireSeconds);
3057
+ }
3058
+ set_child(optName, subKeyName, val){
3059
+ return this.parentClass.helper_set_child(this, optName, subKeyName, val);
3060
+ }
3061
+ delete_child(optName, subKeyName){
3062
+ return this.parentClass.helper_delete_child(this, optName, subKeyName);
3063
+ }
3064
+ // ########################################### //
3065
+ })(this);
3070
3066
 
3067
+
3068
+ // server-side caching
3071
3069
  file = new (class {
3072
3070
  parentClass = null;
3073
3071
  constructor(parentClass){
@@ -3075,15 +3073,38 @@ class PuvoxLibrary {
3075
3073
  }
3076
3074
  mainClass() { return this.parentClass.parentClass; }
3077
3075
 
3078
- // ########## CACHE DIRS (server-side JS) ##########
3076
+ // ###################
3079
3077
  customCacheDir = null;
3080
- get_dir(){
3078
+ file_path(optName) {
3081
3079
  if (!this.customCacheDir){
3082
- this.customCacheDir = this.mainClass().file.tempDir();
3080
+ this.customCacheDir = this.mainClass().file.tempDir() + this.mainClass().getAppName() + '/';
3083
3081
  }
3084
- let finaldir = this.mainClass().trailingSlash(this.customCacheDir + this.mainClass().getAppName() + '_cache_');
3085
- return finaldir;
3082
+ return this.customCacheDir + optName + '.json';
3083
+ }
3084
+ get(optName, defaultValue = null, decode = true, expire_seconds=0)
3085
+ {
3086
+ return this.mainClass().file.readCustom(this.file_path(optName), defaultValue, decode, expire_seconds);
3086
3087
  }
3088
+ set(optName, content)
3089
+ {
3090
+ return this.mainClass().file.write(this.file_path(optName), content);
3091
+ }
3092
+ delete (optName) {
3093
+ return this.mainClass().file.delete(this.file_path(optName));
3094
+ }
3095
+ // ################ child methods ################## //
3096
+ get_child(optName, subKeyName, defaultVal = null, expireSeconds = 0){
3097
+ return this.parentClass.helper_get_child(this, optName, subKeyName, defaultVal, expireSeconds);
3098
+ }
3099
+ set_child(optName, subKeyName, val){
3100
+ return this.parentClass.helper_set_child(this, optName, subKeyName, val);
3101
+ }
3102
+ delete_child(optName, subKeyName){
3103
+ return this.parentClass.helper_delete_child(this, optName, subKeyName);
3104
+ }
3105
+ // #############################################
3106
+
3107
+ // old
3087
3108
  set_dir(dir, auto_clear_seconds=null){
3088
3109
  if(dir) this.customCacheDir = dir;
3089
3110
  const res = this.mainClass().file.createDirectory(this.customCacheDir);
@@ -3101,69 +3122,8 @@ class PuvoxLibrary {
3101
3122
  const filePath = this.get_dir() + uniqFileName + "_tmp"; //"/".
3102
3123
  return filePath;
3103
3124
  }
3104
- //
3105
- get(uniqFileName, defaultContent ='', expire_seconds=8640000, decode = true)
3106
- {
3107
- const parent = this.mainClass();
3108
- let filePath = this.filePath(uniqFileName);
3109
- if ( parent.file.exists(filePath) ){
3110
- if ( parent.file.mtime(filePath) + expire_seconds *1000 < (new Date()).getTime() ){
3111
- parent.file.unlink(filePath);
3112
- return defaultContent;
3113
- }
3114
- else{
3115
- const cont = parent.file.read(filePath, null);
3116
- // if specifically array, then on empty, reckon as array
3117
- if (cont===null)
3118
- {
3119
- return defaultContent;
3120
- }
3121
- if (decode){
3122
- try{
3123
- return JSON.parse(cont);
3124
- }
3125
- catch(ex){
3126
- return cont;
3127
- }
3128
- }
3129
- else{
3130
- return cont;
3131
- }
3132
- }
3133
- }
3134
- else {
3135
- return defaultContent;
3136
- }
3137
- }
3138
- set(uniqFileName, content)
3139
- {
3140
- const parent = this.mainClass();
3141
- let filePath= this.filePath(uniqFileName);
3142
- let contentFinal = parent.isString(content) ? content : ((parent.isArray(content) || parent.isObject(content)) ? JSON.stringify(content) : content);
3143
- return parent.file.write(filePath, contentFinal);
3144
- }
3145
3125
 
3146
-
3147
- //
3148
- // writeFileAppendJson(filePath, jsonContent, callback){
3149
- // try{
3150
- // var callback = callback || function(){};
3151
- // var self = this;
3152
- // this.mainClass().modules('fs').readFile(filePath, 'utf8', function(err,data) {
3153
- // let json = {};
3154
- // if (typeof data !="undefined" && data!=''){
3155
- // json=JSON.parse(data);
3156
- // }
3157
- // let jsonNew = self.jsonConcat(json, jsonContent);
3158
- // let content = JSON.stringify(jsonNew);
3159
- // this.mainClass().modules('fs').writeFile(filePath, content, 'utf8', function(callback_) {
3160
- // });
3161
- // });
3162
- // }
3163
- // catch(e){
3164
- // console.log("writeFileAppendJson", e);
3165
- // }
3166
- // },
3126
+ // ids
3167
3127
  containerDefaultPrefix = "_cached_ids_";
3168
3128
  tempIds = {};
3169
3129
  idForContent(slugOrContent){
@@ -3195,6 +3155,26 @@ class PuvoxLibrary {
3195
3155
  }
3196
3156
  return false;
3197
3157
  }
3158
+ //
3159
+ // writeFileAppendJson(filePath, jsonContent, callback){
3160
+ // try{
3161
+ // var callback = callback || function(){};
3162
+ // var self = this;
3163
+ // this.mainClass().modules('fs').readFile(filePath, 'utf8', function(err,data) {
3164
+ // let json = {};
3165
+ // if (typeof data !="undefined" && data!=''){
3166
+ // json=JSON.parse(data);
3167
+ // }
3168
+ // let jsonNew = self.jsonConcat(json, jsonContent);
3169
+ // let content = JSON.stringify(jsonNew);
3170
+ // this.mainClass().modules('fs').writeFile(filePath, content, 'utf8', function(callback_) {
3171
+ // });
3172
+ // });
3173
+ // }
3174
+ // catch(e){
3175
+ // console.log("writeFileAppendJson", e);
3176
+ // }
3177
+ // },
3198
3178
  })(this);
3199
3179
  })(this);
3200
3180
 
@@ -3274,16 +3254,40 @@ class PuvoxLibrary {
3274
3254
  }
3275
3255
  return true;
3276
3256
  }
3277
- read(filePath, defaultContent = ''){
3257
+ read(filePath, defaultValue = ''){
3278
3258
  if (!this.exists(filePath)){
3279
- return defaultContent;
3259
+ return defaultValue;
3280
3260
  }
3281
3261
  return this.fs().readFileSync(filePath, 'utf8');
3282
3262
  }
3263
+ readCustom(filePath, defaultValue = '', decode = true, expireSeconds = 0){
3264
+ if (!this.exists(filePath)){
3265
+ return defaultValue;
3266
+ }
3267
+ else {
3268
+ if ( this.mtime(filePath) + expireSeconds*1000 < (new Date()).getTime() ){
3269
+ this.unlink(filePath);
3270
+ return defaultValue;
3271
+ }
3272
+ else{
3273
+ const cont = this.read(filePath, null);
3274
+ // if specifically array, then on empty, reckon as array
3275
+ if (cont===null) {
3276
+ return defaultValue;
3277
+ }
3278
+ if (decode){
3279
+ try { return JSON.parse(cont); }
3280
+ catch(ex){ }
3281
+ }
3282
+ return cont;
3283
+ }
3284
+ }
3285
+ }
3283
3286
  write(filePath, content){
3284
3287
  const dir = this.path().dirname(filePath);
3285
3288
  this.createDirectory(dir);
3286
- this.fs().writeFileSync(filePath, content, 'utf8', function(err){
3289
+ const finalContent = this.mainClass().stringifyForWrite(content);
3290
+ return this.fs().writeFileSync(filePath, finalContent, 'utf8', function(err){
3287
3291
  if (err) throw err;
3288
3292
  });
3289
3293
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puvox-library",
3
- "version": "1.0.88",
3
+ "version": "1.1.1",
4
4
  "description": "library-class-javascript",
5
5
  "main": "library_standard.js",
6
6
  "scripts": {