@scaleway/sdk-client 1.2.0 → 1.2.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/dist/helpers/json.cjs +40 -0
- package/dist/helpers/json.js +40 -0
- package/dist/index.cjs +1 -0
- package/dist/index.js +2 -1
- package/dist/internals.d.ts +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/scw/custom-marshalling.cjs +26 -0
- package/dist/scw/custom-marshalling.js +27 -1
- package/package.json +9 -10
package/dist/helpers/json.cjs
CHANGED
|
@@ -4,4 +4,44 @@ const isJSONObject = (obj) => {
|
|
|
4
4
|
const objT = typeof obj;
|
|
5
5
|
return obj !== void 0 && obj !== null && objT !== "string" && objT !== "number" && objT !== "boolean" && !Array.isArray(obj) && objT === "object";
|
|
6
6
|
};
|
|
7
|
+
const camelize = (str) => {
|
|
8
|
+
const strLength = str.length;
|
|
9
|
+
if (strLength <= 0) {
|
|
10
|
+
return str;
|
|
11
|
+
}
|
|
12
|
+
let out = "";
|
|
13
|
+
for (let capNext = false, index = 0; index < strLength; index += 1) {
|
|
14
|
+
const char = str.charAt(index);
|
|
15
|
+
if (char >= "a" && char <= "z") {
|
|
16
|
+
if (capNext) {
|
|
17
|
+
out += char.toUpperCase();
|
|
18
|
+
} else {
|
|
19
|
+
out += char;
|
|
20
|
+
}
|
|
21
|
+
} else if (char >= "A" && char <= "Z") {
|
|
22
|
+
out += char;
|
|
23
|
+
} else if (char >= "0" && char <= "9") {
|
|
24
|
+
out += char;
|
|
25
|
+
}
|
|
26
|
+
capNext = char === "_" || char === " " || char === "-" || char === ".";
|
|
27
|
+
}
|
|
28
|
+
return out.charAt(0).toLowerCase() + out.substring(1);
|
|
29
|
+
};
|
|
30
|
+
const camelizeKeys = (obj, ignoreKeys = []) => {
|
|
31
|
+
if (Array.isArray(obj)) {
|
|
32
|
+
return obj.map((v) => camelizeKeys(v, ignoreKeys));
|
|
33
|
+
}
|
|
34
|
+
if (obj && typeof obj === "object" && !(obj instanceof Date)) {
|
|
35
|
+
return Object.entries(obj).reduce(
|
|
36
|
+
(acc, [key, value]) => ({
|
|
37
|
+
...acc,
|
|
38
|
+
[camelize(key)]: ignoreKeys.includes(key) ? value : camelizeKeys(value, ignoreKeys)
|
|
39
|
+
}),
|
|
40
|
+
{}
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return obj;
|
|
44
|
+
};
|
|
45
|
+
exports.camelize = camelize;
|
|
46
|
+
exports.camelizeKeys = camelizeKeys;
|
|
7
47
|
exports.isJSONObject = isJSONObject;
|
package/dist/helpers/json.js
CHANGED
|
@@ -2,6 +2,46 @@ const isJSONObject = (obj) => {
|
|
|
2
2
|
const objT = typeof obj;
|
|
3
3
|
return obj !== void 0 && obj !== null && objT !== "string" && objT !== "number" && objT !== "boolean" && !Array.isArray(obj) && objT === "object";
|
|
4
4
|
};
|
|
5
|
+
const camelize = (str) => {
|
|
6
|
+
const strLength = str.length;
|
|
7
|
+
if (strLength <= 0) {
|
|
8
|
+
return str;
|
|
9
|
+
}
|
|
10
|
+
let out = "";
|
|
11
|
+
for (let capNext = false, index = 0; index < strLength; index += 1) {
|
|
12
|
+
const char = str.charAt(index);
|
|
13
|
+
if (char >= "a" && char <= "z") {
|
|
14
|
+
if (capNext) {
|
|
15
|
+
out += char.toUpperCase();
|
|
16
|
+
} else {
|
|
17
|
+
out += char;
|
|
18
|
+
}
|
|
19
|
+
} else if (char >= "A" && char <= "Z") {
|
|
20
|
+
out += char;
|
|
21
|
+
} else if (char >= "0" && char <= "9") {
|
|
22
|
+
out += char;
|
|
23
|
+
}
|
|
24
|
+
capNext = char === "_" || char === " " || char === "-" || char === ".";
|
|
25
|
+
}
|
|
26
|
+
return out.charAt(0).toLowerCase() + out.substring(1);
|
|
27
|
+
};
|
|
28
|
+
const camelizeKeys = (obj, ignoreKeys = []) => {
|
|
29
|
+
if (Array.isArray(obj)) {
|
|
30
|
+
return obj.map((v) => camelizeKeys(v, ignoreKeys));
|
|
31
|
+
}
|
|
32
|
+
if (obj && typeof obj === "object" && !(obj instanceof Date)) {
|
|
33
|
+
return Object.entries(obj).reduce(
|
|
34
|
+
(acc, [key, value]) => ({
|
|
35
|
+
...acc,
|
|
36
|
+
[camelize(key)]: ignoreKeys.includes(key) ? value : camelizeKeys(value, ignoreKeys)
|
|
37
|
+
}),
|
|
38
|
+
{}
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
};
|
|
5
43
|
export {
|
|
44
|
+
camelize,
|
|
45
|
+
camelizeKeys,
|
|
6
46
|
isJSONObject
|
|
7
47
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -40,6 +40,7 @@ exports.marshalDecimal = customMarshalling.marshalDecimal;
|
|
|
40
40
|
exports.marshalMoney = customMarshalling.marshalMoney;
|
|
41
41
|
exports.marshalScwFile = customMarshalling.marshalScwFile;
|
|
42
42
|
exports.marshalTimeSeries = customMarshalling.marshalTimeSeries;
|
|
43
|
+
exports.unmarshalAnyRes = customMarshalling.unmarshalAnyRes;
|
|
43
44
|
exports.unmarshalDecimal = customMarshalling.unmarshalDecimal;
|
|
44
45
|
exports.unmarshalMoney = customMarshalling.unmarshalMoney;
|
|
45
46
|
exports.unmarshalScwFile = customMarshalling.unmarshalScwFile;
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { createExponentialBackoffStrategy, tryAtIntervals, waitForResource } fro
|
|
|
9
9
|
import { addAsyncHeaderInterceptor } from "./internal/interceptors/helpers.js";
|
|
10
10
|
import { API } from "./scw/api.js";
|
|
11
11
|
import { authenticateWithSessionToken } from "./scw/auth.js";
|
|
12
|
-
import { marshalBlobToScwFile, marshalDecimal, marshalMoney, marshalScwFile, marshalTimeSeries, unmarshalDecimal, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint } from "./scw/custom-marshalling.js";
|
|
12
|
+
import { marshalBlobToScwFile, marshalDecimal, marshalMoney, marshalScwFile, marshalTimeSeries, unmarshalAnyRes, unmarshalDecimal, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint } from "./scw/custom-marshalling.js";
|
|
13
13
|
import { resolveOneOf, unmarshalArrayOfObject, unmarshalDate, unmarshalMapOfObject, urlParams, validatePathParam } from "./helpers/marshalling.js";
|
|
14
14
|
import { enrichForPagination } from "./scw/fetch/resource-paginator.js";
|
|
15
15
|
export {
|
|
@@ -34,6 +34,7 @@ export {
|
|
|
34
34
|
resolveOneOf,
|
|
35
35
|
setLogger,
|
|
36
36
|
tryAtIntervals,
|
|
37
|
+
unmarshalAnyRes,
|
|
37
38
|
unmarshalArrayOfObject,
|
|
38
39
|
unmarshalDate,
|
|
39
40
|
unmarshalDecimal,
|
package/dist/internals.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { addAsyncHeaderInterceptor } from './internal/interceptors/helpers.js';
|
|
|
4
4
|
export { API } from './scw/api.js';
|
|
5
5
|
export { authenticateWithSessionToken } from './scw/auth.js';
|
|
6
6
|
export type { DefaultValues } from './scw/client-settings.js';
|
|
7
|
-
export {
|
|
7
|
+
export { marshalBlobToScwFile, marshalDecimal, marshalMoney, marshalScwFile, marshalTimeSeries, unmarshalAnyRes, unmarshalDecimal, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint, } from './scw/custom-marshalling.js';
|
|
8
8
|
export type { ServiceInfo } from './scw/custom-types.js';
|
|
9
9
|
export { resolveOneOf, unmarshalDate, unmarshalArrayOfObject, unmarshalMapOfObject, urlParams, validatePathParam, } from './helpers/marshalling.js';
|
|
10
10
|
export { enrichForPagination } from './scw/fetch/resource-paginator.js';
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
|
@@ -112,12 +112,38 @@ const marshalTimeSeries = (obj) => ({
|
|
|
112
112
|
const marshalDecimal = (obj) => ({
|
|
113
113
|
value: obj.toString()
|
|
114
114
|
});
|
|
115
|
+
const unmarshalDates = (obj, keys) => {
|
|
116
|
+
if (Array.isArray(obj)) {
|
|
117
|
+
return obj.map((v) => unmarshalDates(v, keys));
|
|
118
|
+
}
|
|
119
|
+
if (obj && typeof obj === "object") {
|
|
120
|
+
return Object.entries(obj).reduce(
|
|
121
|
+
(acc, [key, value]) => ({
|
|
122
|
+
...acc,
|
|
123
|
+
[key]: typeof value === "string" && keys.includes(key) ? new Date(value) : unmarshalDates(value, keys)
|
|
124
|
+
}),
|
|
125
|
+
{}
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
return obj;
|
|
129
|
+
};
|
|
130
|
+
const unmarshalAnyRes = (obj, ignoreKeys = [], dateKeys) => {
|
|
131
|
+
if (!json.isJSONObject(obj)) {
|
|
132
|
+
throw new TypeError(`Data isn't a dictionary.`);
|
|
133
|
+
}
|
|
134
|
+
return json.camelizeKeys(
|
|
135
|
+
dateKeys && dateKeys.length > 0 ? unmarshalDates(obj, dateKeys) : obj,
|
|
136
|
+
ignoreKeys
|
|
137
|
+
);
|
|
138
|
+
};
|
|
115
139
|
exports.marshalBlobToScwFile = marshalBlobToScwFile;
|
|
116
140
|
exports.marshalDecimal = marshalDecimal;
|
|
117
141
|
exports.marshalMoney = marshalMoney;
|
|
118
142
|
exports.marshalScwFile = marshalScwFile;
|
|
119
143
|
exports.marshalTimeSeries = marshalTimeSeries;
|
|
120
144
|
exports.marshalTimeSeriesPoint = marshalTimeSeriesPoint;
|
|
145
|
+
exports.unmarshalAnyRes = unmarshalAnyRes;
|
|
146
|
+
exports.unmarshalDates = unmarshalDates;
|
|
121
147
|
exports.unmarshalDecimal = unmarshalDecimal;
|
|
122
148
|
exports.unmarshalMoney = unmarshalMoney;
|
|
123
149
|
exports.unmarshalScwFile = unmarshalScwFile;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isJSONObject } from "../helpers/json.js";
|
|
1
|
+
import { isJSONObject, camelizeKeys } from "../helpers/json.js";
|
|
2
2
|
import { unmarshalArrayOfObject, unmarshalDate } from "../helpers/marshalling.js";
|
|
3
3
|
import { fromByteArray } from "../vendor/base64/index.js";
|
|
4
4
|
import { Decimal } from "./custom-types.js";
|
|
@@ -110,6 +110,30 @@ const marshalTimeSeries = (obj) => ({
|
|
|
110
110
|
const marshalDecimal = (obj) => ({
|
|
111
111
|
value: obj.toString()
|
|
112
112
|
});
|
|
113
|
+
const unmarshalDates = (obj, keys) => {
|
|
114
|
+
if (Array.isArray(obj)) {
|
|
115
|
+
return obj.map((v) => unmarshalDates(v, keys));
|
|
116
|
+
}
|
|
117
|
+
if (obj && typeof obj === "object") {
|
|
118
|
+
return Object.entries(obj).reduce(
|
|
119
|
+
(acc, [key, value]) => ({
|
|
120
|
+
...acc,
|
|
121
|
+
[key]: typeof value === "string" && keys.includes(key) ? new Date(value) : unmarshalDates(value, keys)
|
|
122
|
+
}),
|
|
123
|
+
{}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
return obj;
|
|
127
|
+
};
|
|
128
|
+
const unmarshalAnyRes = (obj, ignoreKeys = [], dateKeys) => {
|
|
129
|
+
if (!isJSONObject(obj)) {
|
|
130
|
+
throw new TypeError(`Data isn't a dictionary.`);
|
|
131
|
+
}
|
|
132
|
+
return camelizeKeys(
|
|
133
|
+
dateKeys && dateKeys.length > 0 ? unmarshalDates(obj, dateKeys) : obj,
|
|
134
|
+
ignoreKeys
|
|
135
|
+
);
|
|
136
|
+
};
|
|
113
137
|
export {
|
|
114
138
|
marshalBlobToScwFile,
|
|
115
139
|
marshalDecimal,
|
|
@@ -117,6 +141,8 @@ export {
|
|
|
117
141
|
marshalScwFile,
|
|
118
142
|
marshalTimeSeries,
|
|
119
143
|
marshalTimeSeriesPoint,
|
|
144
|
+
unmarshalAnyRes,
|
|
145
|
+
unmarshalDates,
|
|
120
146
|
unmarshalDecimal,
|
|
121
147
|
unmarshalMoney,
|
|
122
148
|
unmarshalScwFile,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scaleway/sdk-client",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Scaleway SDK Client",
|
|
6
6
|
"keywords": [
|
|
@@ -12,12 +12,6 @@
|
|
|
12
12
|
"main": "dist/index.cjs",
|
|
13
13
|
"module": "dist/index.js",
|
|
14
14
|
"types": "dist/index.d.ts",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"typecheck": "tsc --noEmit",
|
|
17
|
-
"type:generate": "tsc --declaration -p tsconfig.build.json",
|
|
18
|
-
"build": "vite build --config ../../vite.config.ts && pnpm run type:generate && tsc-alias -p tsconfig.build.json",
|
|
19
|
-
"build:profile": "npx vite-bundle-visualizer -c ../../vite.config.ts"
|
|
20
|
-
},
|
|
21
15
|
"files": [
|
|
22
16
|
"dist"
|
|
23
17
|
],
|
|
@@ -30,8 +24,13 @@
|
|
|
30
24
|
"directory": "packages/client"
|
|
31
25
|
},
|
|
32
26
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
27
|
+
"node": ">=20.19.1"
|
|
34
28
|
},
|
|
35
29
|
"type": "module",
|
|
36
|
-
"
|
|
37
|
-
|
|
30
|
+
"scripts": {
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"type:generate": "tsc --declaration -p tsconfig.build.json",
|
|
33
|
+
"build": "vite build --config ../../vite.config.ts && pnpm run type:generate && tsc-alias -p tsconfig.build.json",
|
|
34
|
+
"build:profile": "npx vite-bundle-visualizer -c ../../vite.config.ts"
|
|
35
|
+
}
|
|
36
|
+
}
|