mezon-js 2.13.78 → 2.13.80

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.
Files changed (38) hide show
  1. package/client.ts +3279 -2482
  2. package/dist/client.d.ts +163 -349
  3. package/dist/gateway.api.d.ts +33 -0
  4. package/dist/index.d.ts +2 -4
  5. package/dist/{api.gen.d.ts → mezon-js/api.gen.d.ts} +1 -0
  6. package/dist/mezon-js/client.d.ts +347 -0
  7. package/dist/mezon-js/gateway.api.d.ts +33 -0
  8. package/dist/mezon-js/index.d.ts +23 -0
  9. package/dist/mezon-js/session.d.ts +61 -0
  10. package/dist/mezon-js/socket.d.ts +1212 -0
  11. package/dist/mezon-js/types/index.d.ts +2212 -0
  12. package/dist/mezon-js/utils.d.ts +6 -0
  13. package/dist/mezon-js/web_socket_adapter.d.ts +83 -0
  14. package/dist/mezon-js.cjs.js +9038 -21145
  15. package/dist/mezon-js.esm.mjs +9038 -21145
  16. package/dist/mezon-js.esm.mjs.map +1 -0
  17. package/dist/session.d.ts +11 -11
  18. package/dist/socket.d.ts +385 -386
  19. package/dist/types/index.d.ts +2212 -0
  20. package/dist/utils.d.ts +2 -0
  21. package/dist/webrpc/index.d.ts +3 -0
  22. package/gateway.api.ts +577 -0
  23. package/index.ts +2 -5
  24. package/package.json +3 -2
  25. package/rollup.config.js +64 -30
  26. package/session.ts +22 -22
  27. package/socket.ts +921 -846
  28. package/types/index.ts +3883 -0
  29. package/utils.ts +107 -47
  30. package/api/api.ts +0 -39185
  31. package/api.gen.ts +0 -11777
  32. package/google/protobuf/struct.ts +0 -554
  33. package/google/protobuf/timestamp.ts +0 -223
  34. package/google/protobuf/wrappers.ts +0 -670
  35. /package/dist/{api → mezon-js/api}/api.d.ts +0 -0
  36. /package/dist/{google → mezon-js/google}/protobuf/struct.d.ts +0 -0
  37. /package/dist/{google → mezon-js/google}/protobuf/timestamp.d.ts +0 -0
  38. /package/dist/{google → mezon-js/google}/protobuf/wrappers.d.ts +0 -0
package/utils.ts CHANGED
@@ -1,65 +1,125 @@
1
- import {encode, decode} from "js-base64"
1
+ import { encode, decode } from "js-base64";
2
2
 
3
- export function buildFetchOptions(method: string, options: any, bodyJson: string) {
4
- const fetchOptions = {...{ method: method }, ...options};
5
- fetchOptions.headers = {...options.headers};
3
+ export function buildFetchOptions(
4
+ method: string,
5
+ options: any,
6
+ bodyJson: string
7
+ ) {
8
+ const fetchOptions = { ...{ method: method }, ...options };
9
+ fetchOptions.headers = { ...options.headers };
6
10
 
7
- if (typeof XMLHttpRequest !== "undefined") {
8
- const descriptor = Object.getOwnPropertyDescriptor(XMLHttpRequest.prototype, "withCredentials");
11
+ if (typeof XMLHttpRequest !== "undefined") {
12
+ const descriptor = Object.getOwnPropertyDescriptor(
13
+ XMLHttpRequest.prototype,
14
+ "withCredentials"
15
+ );
9
16
 
10
- // in Cocos Creator, XMLHttpRequest.withCredentials is not writable, so make the fetch
11
- // polyfill avoid writing to it.
12
- if (!descriptor?.set) {
13
- fetchOptions.credentials = 'cocos-ignore'; // string value is arbitrary, cannot be 'omit' or 'include
14
- }
17
+ // in Cocos Creator, XMLHttpRequest.withCredentials is not writable, so make the fetch
18
+ // polyfill avoid writing to it.
19
+ if (!descriptor?.set) {
20
+ fetchOptions.credentials = "cocos-ignore"; // string value is arbitrary, cannot be 'omit' or 'include
15
21
  }
22
+ }
16
23
 
17
- if(!Object.keys(fetchOptions.headers).includes("Accept")) {
18
- fetchOptions.headers["Accept"] = "application/json";
19
- }
24
+ if (!Object.keys(fetchOptions.headers).includes("Accept")) {
25
+ fetchOptions.headers["Accept"] = "application/json";
26
+ }
20
27
 
21
- if(!Object.keys(fetchOptions.headers).includes("Content-Type")) {
22
- fetchOptions.headers["Content-Type"] = "application/json";
23
- }
28
+ if (!Object.keys(fetchOptions.headers).includes("Content-Type")) {
29
+ fetchOptions.headers["Content-Type"] = "application/json";
30
+ }
24
31
 
25
- Object.keys(fetchOptions.headers).forEach((key: string) => {
26
- if (!fetchOptions.headers[key]) {
27
- delete fetchOptions.headers[key];
28
- }
29
- });
30
-
31
- if (bodyJson) {
32
- fetchOptions.body = bodyJson;
32
+ Object.keys(fetchOptions.headers).forEach((key: string) => {
33
+ if (!fetchOptions.headers[key]) {
34
+ delete fetchOptions.headers[key];
33
35
  }
36
+ });
37
+
38
+ if (bodyJson) {
39
+ fetchOptions.body = bodyJson;
40
+ }
34
41
 
35
- return fetchOptions;
42
+ return fetchOptions;
36
43
  }
37
44
 
38
- export function b64EncodeUnicode(str:string) {
39
- return encode(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g,
40
- function toSolidBytes(_match:string, p1) {
41
- return String.fromCharCode(Number('0x' + p1));
42
- }));
45
+ export function b64EncodeUnicode(str: string) {
46
+ return encode(
47
+ encodeURIComponent(str).replace(
48
+ /%([0-9A-F]{2})/g,
49
+ function toSolidBytes(_match: string, p1) {
50
+ return String.fromCharCode(Number("0x" + p1));
51
+ }
52
+ )
53
+ );
43
54
  }
44
55
 
45
56
  export function b64DecodeUnicode(str: string) {
46
- return decodeURIComponent(decode(str).split('').map(function(c) {
47
- return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
48
- }).join(''));
57
+ return decodeURIComponent(
58
+ decode(str)
59
+ .split("")
60
+ .map(function (c) {
61
+ return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
62
+ })
63
+ .join("")
64
+ );
49
65
  }
50
66
 
51
67
  export function safeJSONParse(jsonStr: string) {
52
- try {
53
- return JSON.parse(jsonStr);
54
- } catch (error) {
55
- if (jsonStr !== "") {
56
- const fixedJsonStr = jsonStr.replace(/\n/g, "\\n");
57
- try {
58
- return JSON.parse(fixedJsonStr);
59
- } catch (e) {
60
- console.error('Error parsing JSON:', jsonStr, error);
61
- }
62
- }
63
- return {t: jsonStr}; // Handle the error gracefully or throw an exception if necessary
68
+ try {
69
+ return JSON.parse(jsonStr);
70
+ } catch (error) {
71
+ if (jsonStr !== "") {
72
+ const fixedJsonStr = jsonStr.replace(/\n/g, "\\n");
73
+ try {
74
+ return JSON.parse(fixedJsonStr);
75
+ } catch (e) {
76
+ console.error("Error parsing JSON:", jsonStr, error);
77
+ }
78
+ }
79
+ return { t: jsonStr }; // Handle the error gracefully or throw an exception if necessary
80
+ }
81
+ }
82
+
83
+ export function mapToSnakeCase(obj: any): any {
84
+ if (typeof obj !== "object" || obj === null) {
85
+ return obj;
86
+ }
87
+
88
+ if (Array.isArray(obj)) {
89
+ return obj.map(mapToSnakeCase);
90
+ }
91
+
92
+ const newObj: { [key: string]: any } = {};
93
+ for (const key in obj) {
94
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
95
+ const newKey = camelToSnakeCase(key);
96
+ newObj[newKey] = mapToSnakeCase(obj[key]);
97
+ }
98
+ }
99
+ return newObj;
100
+ }
101
+
102
+ export function mapToCamelCase(obj: any): any {
103
+ if (typeof obj !== "object" || obj === null) {
104
+ return obj;
105
+ }
106
+
107
+ if (Array.isArray(obj)) {
108
+ return obj.map(mapToCamelCase);
109
+ }
110
+
111
+ const newObj: { [key: string]: any } = {};
112
+ for (const key in obj) {
113
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
114
+ const newKey = snakeToCamelCase(key);
115
+ newObj[newKey] = mapToCamelCase(obj[key]);
64
116
  }
65
- }
117
+ }
118
+ return newObj;
119
+ }
120
+
121
+ const camelToSnakeCase = (str: string): string =>
122
+ str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
123
+
124
+ const snakeToCamelCase = (str: string): string =>
125
+ str.replace(/_([a-z])/g, (_match, letter) => letter.toUpperCase());