@scaleway/sdk-client 1.2.0 → 1.2.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.
@@ -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;
@@ -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,
@@ -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 { marshalDecimal, marshalScwFile, marshalMoney, marshalTimeSeries, marshalBlobToScwFile, unmarshalDecimal, unmarshalMoney, unmarshalScwFile, unmarshalServiceInfo, unmarshalTimeSeries, unmarshalTimeSeriesPoint, } from './scw/custom-marshalling.js';
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';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const version = "1.1.1";
3
+ const version = "1.2.0";
4
4
  const pkg = {
5
5
  version
6
6
  };
@@ -1,4 +1,4 @@
1
- const version = "1.1.1";
1
+ const version = "1.2.0";
2
2
  const pkg = {
3
3
  version
4
4
  };
@@ -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.0",
3
+ "version": "1.2.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Scaleway SDK Client",
6
6
  "keywords": [
@@ -33,5 +33,5 @@
33
33
  "node": ">=18.0"
34
34
  },
35
35
  "type": "module",
36
- "gitHead": "ec3673d4c0a007ae40b9934f3c3eb770f45cc3bb"
36
+ "gitHead": "a3b0b412eb0b067b8f2ea61360a023f38d17f5a0"
37
37
  }