@jsarc/cp-request 0.0.0 → 0.0.1-beta.0.2

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.
package/index.ts CHANGED
@@ -4,13 +4,6 @@ import { qust, Qust } from '@jsarc/qust';
4
4
 
5
5
  // @ts-nocheck
6
6
 
7
- interface Window {
8
- default: typeof defaultElementGF;
9
- HttpRequest: any;
10
- WsRequest: any;
11
- __bundledModules: any;
12
- }
13
-
14
7
  interface HTTPRequestParams {
15
8
  method: "GET" | "POST" | "PUT" | "DELETE";
16
9
  path: string;
@@ -78,7 +71,7 @@ type WsRequestMapAction = (
78
71
 
79
72
  type WsRequestReponseAction = (response: WSMessageResponse) => Promise<void> | void;
80
73
 
81
- const globalFunct = (function(global: any) {
74
+ const globalFunct = (function() {
82
75
  'use strict';
83
76
 
84
77
 
@@ -114,12 +107,6 @@ const globalFunct = (function(global: any) {
114
107
  const tabAlphanumeriqueInsensitive = [...tabNumerique, ...tabAlphabetiqueInsensitive];
115
108
 
116
109
 
117
-
118
-
119
-
120
-
121
-
122
-
123
110
  function defaultMapAction(
124
111
  code: number,
125
112
  type: string,
@@ -648,32 +635,14 @@ const globalFunct = (function(global: any) {
648
635
  }
649
636
 
650
637
  protected getFetchClass() {
651
- return (typeof window !== "undefined") ? (window as any).fetch : fetch;
652
- }
653
-
654
- static exposeToGlobal(): void {
655
- if (typeof window !== "undefined") {
656
- (window as any).HttpRequest = HttpRequest;
657
- }
638
+ return fetch;
658
639
  }
659
640
  }
660
641
 
661
- if (typeof window !== "undefined") {
662
- (window as any).HttpRequest = HttpRequest;
663
- }
664
-
665
642
 
666
643
 
667
644
 
668
645
 
669
-
670
-
671
-
672
-
673
-
674
-
675
-
676
-
677
646
  function defaultMapActionWS(
678
647
  code: number,
679
648
  type: string,
@@ -979,17 +948,8 @@ const globalFunct = (function(global: any) {
979
948
  }
980
949
 
981
950
  protected getWsClass() {
982
- return (typeof window !== "undefined") ? (window as any).WebSocket : WebSocket;
951
+ return WebSocket;
983
952
  }
984
- static exposeToGlobal(): void {
985
- if (typeof window !== "undefined") {
986
- (window as any).WsRequest = WsRequest;
987
- }
988
- }
989
- }
990
-
991
- if (typeof window !== "undefined") {
992
- (window as any).WsRequest = WsRequest;
993
953
  }
994
954
 
995
955
 
@@ -1014,32 +974,9 @@ const globalFunct = (function(global: any) {
1014
974
 
1015
975
  const __bundledModules = globalFunctModule;
1016
976
 
1017
- if (typeof global !== 'undefined') {
1018
- (global as any).default = defaultExport;
1019
- (global as any).HttpRequest = HttpRequest;
1020
- (global as any).WsRequest = WsRequest;
1021
- (global as any).__bundledModules = __bundledModules;
1022
- }
1023
-
1024
- if (typeof window !== "undefined") {
1025
- (window as any).default = defaultExport;
1026
- (window as any).HttpRequest = HttpRequest;
1027
- (window as any).WsRequest = WsRequest;
1028
- (window as any).__bundledModules = __bundledModules;
1029
- }
1030
-
1031
- if (typeof exports !== 'undefined') {
1032
- exports.default = defaultExport;
1033
- exports.HttpRequest = HttpRequest;
1034
- exports.WsRequest = WsRequest;
1035
- }
1036
977
  return globalFunctModule;
1037
978
 
1038
- })(typeof global !== 'undefined' ? global :
1039
- typeof window !== 'undefined' ? window :
1040
- typeof self !== 'undefined' ? self :
1041
- typeof globalThis !== 'undefined' ? globalThis :
1042
- {});
979
+ })();
1043
980
 
1044
981
  type HttpRequestElementTypeGF = typeof globalFunct.HttpRequest;
1045
982
 
package/js/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import JON from '@jsarc/jon';
2
2
  import { Pajo } from '@jsarc/pajo';
3
3
  import { qust } from '@jsarc/qust';
4
- const globalFunct = (function (global) {
4
+ const globalFunct = (function () {
5
5
  'use strict';
6
6
  const NODEENV = 'development';
7
7
  const langs = ['en', 'fr'];
@@ -410,16 +410,8 @@ const globalFunct = (function (global) {
410
410
  await this.actionRequest(urlParams, otherParams, schema, mapAction, errMapAction, successAction, errorAction);
411
411
  }
412
412
  getFetchClass() {
413
- return (typeof window !== "undefined") ? window.fetch : fetch;
413
+ return fetch;
414
414
  }
415
- static exposeToGlobal() {
416
- if (typeof window !== "undefined") {
417
- window.HttpRequest = HttpRequest;
418
- }
419
- }
420
- }
421
- if (typeof window !== "undefined") {
422
- window.HttpRequest = HttpRequest;
423
415
  }
424
416
  function defaultMapActionWS(code, type, message, data, cleanedData, error, errors) {
425
417
  return {
@@ -615,17 +607,9 @@ const globalFunct = (function (global) {
615
607
  return await this.actionMessage(message, schema, mapAction, mapAction, successAction, errorAction);
616
608
  }
617
609
  getWsClass() {
618
- return (typeof window !== "undefined") ? window.WebSocket : WebSocket;
619
- }
620
- static exposeToGlobal() {
621
- if (typeof window !== "undefined") {
622
- window.WsRequest = WsRequest;
623
- }
610
+ return WebSocket;
624
611
  }
625
612
  }
626
- if (typeof window !== "undefined") {
627
- window.WsRequest = WsRequest;
628
- }
629
613
  const defaultExport = {
630
614
  HttpRequest,
631
615
  WsRequest,
@@ -636,29 +620,8 @@ const globalFunct = (function (global) {
636
620
  WsRequest: WsRequest,
637
621
  };
638
622
  const __bundledModules = globalFunctModule;
639
- if (typeof global !== 'undefined') {
640
- global.default = defaultExport;
641
- global.HttpRequest = HttpRequest;
642
- global.WsRequest = WsRequest;
643
- global.__bundledModules = __bundledModules;
644
- }
645
- if (typeof window !== "undefined") {
646
- window.default = defaultExport;
647
- window.HttpRequest = HttpRequest;
648
- window.WsRequest = WsRequest;
649
- window.__bundledModules = __bundledModules;
650
- }
651
- if (typeof exports !== 'undefined') {
652
- exports.default = defaultExport;
653
- exports.HttpRequest = HttpRequest;
654
- exports.WsRequest = WsRequest;
655
- }
656
623
  return globalFunctModule;
657
- })(typeof global !== 'undefined' ? global :
658
- typeof window !== 'undefined' ? window :
659
- typeof self !== 'undefined' ? self :
660
- typeof globalThis !== 'undefined' ? globalThis :
661
- {});
624
+ })();
662
625
  const HttpRequestElementGF = globalFunct.HttpRequest;
663
626
  const WsRequestElementGF = globalFunct.WsRequest;
664
627
  const defaultElementGF = globalFunct.default;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.0.0",
6
+ "version": "0.0.1-beta.0.2",
7
7
  "description": "CP-REQUEST est une bibliothèque TypeScript complète pour gérer les requêtes HTTP et WebSocket avec une API unifiée et type-safe. Elle offre une solution robuste pour les communications client-serveur avec gestion automatique des erreurs, validation des schémas et support multi-langue.",
8
8
  "main": "index.ts",
9
9
  "keywords": [],
@@ -15,8 +15,8 @@
15
15
  },
16
16
  "devDependencies": {},
17
17
  "dependencies": {
18
- "@jsarc/jon": "^0.0.1",
19
- "@jsarc/pajo": "^0.0.1-beta.0.1",
20
- "@jsarc/qust": "^0.0.1-beta.0.1"
18
+ "@jsarc/jon": "^0.0.2-beta.0.2",
19
+ "@jsarc/pajo": "^0.0.1-beta.0.3",
20
+ "@jsarc/qust": "^0.0.1-beta.0.3"
21
21
  }
22
22
  }
package/web/cp-request.js CHANGED
@@ -1,4 +1,4 @@
1
- const globalFunct = (function (global) {
1
+ const globalFunct = (function () {
2
2
  'use strict';
3
3
  const NODEENV = 'development';
4
4
  const langs = ['en', 'fr'];
@@ -299,12 +299,6 @@ const globalFunct = (function (global) {
299
299
  getOptions() {
300
300
  return { ...this.options };
301
301
  }
302
-
303
- static exposeToGlobal() {
304
- if (typeof window !== "undefined") {
305
- window.Qust = Qust;
306
- }
307
- }
308
302
  }
309
303
 
310
304
  const qust = {
@@ -317,11 +311,6 @@ const globalFunct = (function (global) {
317
311
  return new Qust(options).parse(queryString);
318
312
  }
319
313
  };
320
-
321
- if (typeof window !== "undefined") {
322
- window.Qust = Qust;
323
- window.qust = qust;
324
- }
325
314
  class Pajo {
326
315
  static PROTOCOL_REGEX = new RegExp('^[a-zA-Z]+://');
327
316
  static DOUBLE_SLASH_REGEX = new RegExp('/+', 'g');
@@ -509,16 +498,6 @@ const globalFunct = (function (global) {
509
498
  static toWindowsPath(path) {
510
499
  return path.replace(new RegExp('/', 'g'), '\\\\');
511
500
  }
512
-
513
- static exposeToGlobal() {
514
- if (typeof window !== "undefined") {
515
- window.Pajo = Pajo;
516
- }
517
- }
518
- }
519
-
520
- if (typeof window !== "undefined") {
521
- Pajo.exposeToGlobal();
522
501
  }
523
502
  function getLang(lang) {
524
503
  let result = lang;
@@ -6077,9 +6056,6 @@ const globalFunct = (function (global) {
6077
6056
  'ChosenType': ChosenTypeSchema,
6078
6057
  'AnyType': AnyTypeSchema,
6079
6058
  };
6080
- if (typeof window !== 'undefined') {
6081
- window.JON = JONSchemas;
6082
- }
6083
6059
  function defaultMapAction(code, type, message, data, cleanedData, error, errors) {
6084
6060
  return ({
6085
6061
  response: {
@@ -6688,29 +6664,8 @@ const globalFunct = (function (global) {
6688
6664
  WsRequest: WsRequest,
6689
6665
  };
6690
6666
  const __bundledModules = globalFunctModule;
6691
- if (typeof global !== 'undefined') {
6692
- global.default = defaultExport;
6693
- global.HttpRequest = HttpRequest;
6694
- global.WsRequest = WsRequest;
6695
- global.__bundledModules = __bundledModules;
6696
- }
6697
- if (typeof window !== "undefined") {
6698
- window.default = defaultExport;
6699
- window.HttpRequest = HttpRequest;
6700
- window.WsRequest = WsRequest;
6701
- window.__bundledModules = __bundledModules;
6702
- }
6703
- if (typeof exports !== 'undefined') {
6704
- exports.default = defaultExport;
6705
- exports.HttpRequest = HttpRequest;
6706
- exports.WsRequest = WsRequest;
6707
- }
6708
6667
  return globalFunctModule;
6709
- })(typeof global !== 'undefined' ? global :
6710
- typeof window !== 'undefined' ? window :
6711
- typeof self !== 'undefined' ? self :
6712
- typeof globalThis !== 'undefined' ? globalThis :
6713
- {});
6668
+ })();
6714
6669
  const HttpRequestElementGF = globalFunct.HttpRequest;
6715
6670
  const WsRequestElementGF = globalFunct.WsRequest;
6716
6671
  const defaultElementGF = globalFunct.default;
@@ -1 +1 @@
1
- let globalFunct=(e=>{let G=["en","fr"],_="%Y-%m-%dT%H:%M:%S.%fZ";var t="%Y/%m/%d",r="%H:%M:%S.%f",i=["0","1","2","3","4","5","6","7","8","9"],a=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],s=[...a,...a.map(e=>e.toUpperCase())];[...i,...a],[...i,...s];let V={arrayFormat:"bracket",arraySeparator:",",skipNull:!0,skipEmptyString:!1,encode:!0,decode:!0,depth:10};class o{options;constructor(e={}){this.options={...V,...e}}stringify(e){return e&&"object"==typeof e&&(this.processObject("",e,e=[],0),0<e.length)?"?"+e.join("&"):""}parse(e){if(!e||"string"!=typeof e)return{};e=e.startsWith("?")?e.slice(1):e;if(!e)return{};var t,r,i,a={};for(t of e.split("&"))t&&([r,i]=t.split("="),r)&&(r=this.options.decode?decodeURIComponent(r):r,i=this.options.decode&&void 0!==i?decodeURIComponent(i):i,this.setValue(a,r,i));return this.transformArrays(a)}processObject(e,t,r,i){if(i>this.options.depth)console.warn("Qust: Profondeur maximale atteinte, arrêt de la récursion");else if(null==t)this.options.skipNull||r.push(this.encodeKey(e));else if("string"!=typeof t||""!==t||!this.options.skipEmptyString)if(Array.isArray(t))this.processArray(e,t,r,i+1);else if("object"!=typeof t||this.isPrimitive(t)){var a=this.encodeKey(e),_=(this.options.encode&&"string"==typeof t?encodeURIComponent:String)(t);r.push(a+"="+_)}else for(var[s,o]of Object.entries(t)){s=e?`${e}[${s}]`:s;this.processObject(s,o,r,i+1)}}processArray(r,e,i,a){if(0!==e.length){let t=this.encodeKey(r);switch(this.options.arrayFormat){case"comma":var _=e.map(e=>(this.options.encode&&"string"==typeof e?encodeURIComponent:String)(e)).join(this.options.arraySeparator);i.push(t+"="+_);break;case"index":e.forEach((e,t)=>{this.processObject(r+`[${t}]`,e,i,a)});break;case"separator":e.forEach(e=>{e=(this.options.encode&&"string"==typeof e?encodeURIComponent:String)(e);i.push(t+"="+e)});break;case"none":e.forEach(e=>{this.processObject(r,e,i,a)});break;default:e.forEach(e=>{this.processObject(r+"[]",e,i,a)})}}}encodeKey(t){if(!this.options.encode)return t;var r=[];let i="";for(let e=0;e<t.length;e++){var a=t[e];"["===a||"]"===a?(i&&(r.push(encodeURIComponent(i)),i=""),r.push(a)):i+=a}return i&&r.push(encodeURIComponent(i)),r.join("")}setValue(e,t,r){var i=t.match(/([^\[\]]+)|(\[\])/g);if(i){let t=e;for(let e=0;e<i.length;e++){var a,_,s=i[e],o=e===i.length-1;"[]"===s?(Array.isArray(t)||(t=[]),o?r&&t.push(this.parseValue(r)):(a=i[e+1],a=parseInt(a,10),isNaN(a)?(_={},t.push(_),t=_):(void 0===t[a]&&(t[a]={}),t=t[a],e++))):o?void 0!==r&&(t[s]=this.parseValue(r)):(void 0!==t[s]&&"object"==typeof t[s]||(_=i[e+1],t[s]="[]"===_?[]:{}),t=t[s])}}else void 0!==r&&(e[t]=this.parseValue(r))}transformArrays(i){if(Array.isArray(i))return i.map(e=>"object"==typeof e&&null!==e?this.transformArrays(e):e);if("object"!=typeof i||null===i)return i;let r={};var e=Object.keys(i);if(e.every(e=>{var t=parseInt(e,10);return!isNaN(t)&&0<=t&&t.toString()===e})&&0<e.length){let r=[];return e.forEach(e=>{var t=parseInt(e,10);r[t]=this.transformArrays(i[e])}),r}return e.forEach(e=>{var t=i[e];r[e]="object"==typeof t&&null!==t?this.transformArrays(t):t}),r}parseValue(e){var t;return"true"===e||"false"!==e&&("null"===e?null:"undefined"!==e?(t=Number(e),isNaN(t)||""===e.trim()?e:t):void 0)}isPrimitive(e){return null===e||"object"!=typeof e&&"function"!=typeof e}setOptions(e){this.options={...this.options,...e}}getOptions(){return{...this.options}}static exposeToGlobal(){"undefined"!=typeof window&&(window.Qust=o)}}let w={stringify(e,t){return new o(t).stringify(e)},parse(e,t){return new o(t).parse(e)}};"undefined"!=typeof window&&(window.Qust=o,window.qust=w);class C{static PROTOCOL_REGEX=new RegExp("^[a-zA-Z]+://");static DOUBLE_SLASH_REGEX=new RegExp("/+","g");static DOUBLE_BACKSLASH_REGEX=new RegExp("\\\\+","g");static TRAILING_SLASH_REGEX=new RegExp("/+$");static TRAILING_BACKSLASH_REGEX=new RegExp("\\\\+$");static LEADING_SLASH_REGEX=new RegExp("^/+");static WINDOWS_DRIVE_REGEX=new RegExp("^[a-zA-Z]:\\\\");static MIXED_SEPARATORS_REGEX=new RegExp("[\\\\/]+","g");static join(...r){if(0!==r.length){let t=r.some(e=>this.isWindowsPath(e));var i=r.filter(e=>null!=e&&0<e.trim().length).map(e=>this.normalizePathSegment(e,t));if(0!==i.length){var a=t?"\\":"/";let e=i.join(a);return t?e=e.replace(this.DOUBLE_BACKSLASH_REGEX,"\\"):(e=e.replace(this.DOUBLE_SLASH_REGEX,"/"),r[0]?.startsWith("/")&&!e.startsWith("/")&&(e="/"+e)),e||void 0}}}static joinWithHost(e,...t){var r;return e&&0!==e.trim().length?(e=e.trim().replace(this.TRAILING_SLASH_REGEX,""),e=this.PROTOCOL_REGEX.test(e)?e:"https:
1
+ let globalFunct=(()=>{let b=["en","fr"],_="%Y-%m-%dT%H:%M:%S.%fZ";var e="%Y/%m/%d",t="%H:%M:%S.%f",r=["0","1","2","3","4","5","6","7","8","9"],i=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],V=[...i,...i.map(e=>e.toUpperCase())];[...r,...i],[...r,...V];let J={arrayFormat:"bracket",arraySeparator:",",skipNull:!0,skipEmptyString:!1,encode:!0,decode:!0,depth:10};class a{options;constructor(e={}){this.options={...J,...e}}stringify(e){return e&&"object"==typeof e&&(this.processObject("",e,e=[],0),0<e.length)?"?"+e.join("&"):""}parse(e){if(!e||"string"!=typeof e)return{};e=e.startsWith("?")?e.slice(1):e;if(!e)return{};var t,r,i,a={};for(t of e.split("&"))t&&([r,i]=t.split("="),r)&&(r=this.options.decode?decodeURIComponent(r):r,i=this.options.decode&&void 0!==i?decodeURIComponent(i):i,this.setValue(a,r,i));return this.transformArrays(a)}processObject(e,t,r,i){if(i>this.options.depth)console.warn("Qust: Profondeur maximale atteinte, arrêt de la récursion");else if(null==t)this.options.skipNull||r.push(this.encodeKey(e));else if("string"!=typeof t||""!==t||!this.options.skipEmptyString)if(Array.isArray(t))this.processArray(e,t,r,i+1);else if("object"!=typeof t||this.isPrimitive(t)){var a=this.encodeKey(e),_=(this.options.encode&&"string"==typeof t?encodeURIComponent:String)(t);r.push(a+"="+_)}else for(var[s,o]of Object.entries(t)){s=e?`${e}[${s}]`:s;this.processObject(s,o,r,i+1)}}processArray(r,e,i,a){if(0!==e.length){let t=this.encodeKey(r);switch(this.options.arrayFormat){case"comma":var _=e.map(e=>(this.options.encode&&"string"==typeof e?encodeURIComponent:String)(e)).join(this.options.arraySeparator);i.push(t+"="+_);break;case"index":e.forEach((e,t)=>{this.processObject(r+`[${t}]`,e,i,a)});break;case"separator":e.forEach(e=>{e=(this.options.encode&&"string"==typeof e?encodeURIComponent:String)(e);i.push(t+"="+e)});break;case"none":e.forEach(e=>{this.processObject(r,e,i,a)});break;default:e.forEach(e=>{this.processObject(r+"[]",e,i,a)})}}}encodeKey(t){if(!this.options.encode)return t;var r=[];let i="";for(let e=0;e<t.length;e++){var a=t[e];"["===a||"]"===a?(i&&(r.push(encodeURIComponent(i)),i=""),r.push(a)):i+=a}return i&&r.push(encodeURIComponent(i)),r.join("")}setValue(e,t,r){var i=t.match(/([^\[\]]+)|(\[\])/g);if(i){let t=e;for(let e=0;e<i.length;e++){var a,_,s=i[e],o=e===i.length-1;"[]"===s?(Array.isArray(t)||(t=[]),o?r&&t.push(this.parseValue(r)):(a=i[e+1],a=parseInt(a,10),isNaN(a)?(_={},t.push(_),t=_):(void 0===t[a]&&(t[a]={}),t=t[a],e++))):o?void 0!==r&&(t[s]=this.parseValue(r)):(void 0!==t[s]&&"object"==typeof t[s]||(_=i[e+1],t[s]="[]"===_?[]:{}),t=t[s])}}else void 0!==r&&(e[t]=this.parseValue(r))}transformArrays(i){if(Array.isArray(i))return i.map(e=>"object"==typeof e&&null!==e?this.transformArrays(e):e);if("object"!=typeof i||null===i)return i;let r={};var e=Object.keys(i);if(e.every(e=>{var t=parseInt(e,10);return!isNaN(t)&&0<=t&&t.toString()===e})&&0<e.length){let r=[];return e.forEach(e=>{var t=parseInt(e,10);r[t]=this.transformArrays(i[e])}),r}return e.forEach(e=>{var t=i[e];r[e]="object"==typeof t&&null!==t?this.transformArrays(t):t}),r}parseValue(e){var t;return"true"===e||"false"!==e&&("null"===e?null:"undefined"!==e?(t=Number(e),isNaN(t)||""===e.trim()?e:t):void 0)}isPrimitive(e){return null===e||"object"!=typeof e&&"function"!=typeof e}setOptions(e){this.options={...this.options,...e}}getOptions(){return{...this.options}}}let C={stringify(e,t){return new a(t).stringify(e)},parse(e,t){return new a(t).parse(e)}};class w{static PROTOCOL_REGEX=new RegExp("^[a-zA-Z]+://");static DOUBLE_SLASH_REGEX=new RegExp("/+","g");static DOUBLE_BACKSLASH_REGEX=new RegExp("\\\\+","g");static TRAILING_SLASH_REGEX=new RegExp("/+$");static TRAILING_BACKSLASH_REGEX=new RegExp("\\\\+$");static LEADING_SLASH_REGEX=new RegExp("^/+");static WINDOWS_DRIVE_REGEX=new RegExp("^[a-zA-Z]:\\\\");static MIXED_SEPARATORS_REGEX=new RegExp("[\\\\/]+","g");static join(...r){if(0!==r.length){let t=r.some(e=>this.isWindowsPath(e));var i=r.filter(e=>null!=e&&0<e.trim().length).map(e=>this.normalizePathSegment(e,t));if(0!==i.length){var a=t?"\\":"/";let e=i.join(a);return t?e=e.replace(this.DOUBLE_BACKSLASH_REGEX,"\\"):(e=e.replace(this.DOUBLE_SLASH_REGEX,"/"),r[0]?.startsWith("/")&&!e.startsWith("/")&&(e="/"+e)),e||void 0}}}static joinWithHost(e,...t){var r;return e&&0!==e.trim().length?(e=e.trim().replace(this.TRAILING_SLASH_REGEX,""),e=this.PROTOCOL_REGEX.test(e)?e:"https: