Skip to content

Commit 8d4578b

Browse files
authored
chore(client): clean up client usage inside sdk (scaleway#1952)
1 parent f794692 commit 8d4578b

File tree

128 files changed

+2402
-13220
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+2402
-13220
lines changed

eslint.config.mjs

+49-55
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,52 @@
1-
import tsdoc from "eslint-plugin-tsdoc";
2-
import typescriptParser from "@typescript-eslint/parser";
3-
import scwTypescript from '@scaleway/eslint-config-react/typescript';
4-
1+
import scwTypescript from '@scaleway/eslint-config-react/typescript'
2+
import typescriptParser from '@typescript-eslint/parser'
3+
import tsdoc from 'eslint-plugin-tsdoc'
54

65
const scwPlugins = scwTypescript.reduce((acc, config) => {
7-
return { ...acc, ...config.plugins };
8-
}, {});
6+
return { ...acc, ...config.plugins }
7+
}, {})
98

109
export default [
1110
{
1211
ignores: [
13-
"**/node_modules/",
14-
"**/dist/",
15-
"**/examples/",
16-
"**/vite.config.ts",
17-
"packages/clients/.eslintrc.cjs",
18-
"packages/client/.eslintrc.cjs",
19-
"eslint.config.mjs",
20-
"packages/clients/src/vendor/base64/index.js",
21-
"packages/client/src/vendor/base64/index.js",
22-
"packages/configuration-loader/.eslintrc.cjs",
23-
12+
'**/node_modules/',
13+
'**/dist/',
14+
'**/examples/',
15+
'**/vite.config.ts',
16+
'packages/clients/.eslintrc.cjs',
17+
'packages/client/.eslintrc.cjs',
18+
'eslint.config.mjs',
19+
'packages/clients/src/vendor/base64/index.js',
20+
'packages/client/src/vendor/base64/index.js',
21+
'packages/configuration-loader/.eslintrc.cjs',
2422
],
2523
},
2624
{
2725
languageOptions: {
2826
ecmaVersion: 5,
29-
sourceType: "script",
27+
sourceType: 'script',
3028
parser: typescriptParser,
3129
parserOptions: {
32-
project: ["tsconfig.json"],
30+
project: ['tsconfig.json'],
3331
},
3432
},
3533
plugins: {
3634
tsdoc,
3735
...scwPlugins,
3836
},
3937
rules: {
40-
"tsdoc/syntax": "warn",
41-
"@typescript-eslint/naming-convention": [
42-
"error",
38+
'tsdoc/syntax': 'warn',
39+
'@typescript-eslint/naming-convention': [
40+
'error',
4341
{
44-
selector: "enumMember",
45-
format: ["PascalCase"],
42+
selector: 'enumMember',
43+
format: ['PascalCase'],
4644
},
4745
],
48-
"import/prefer-default-export": "off",
49-
"import/no-default-export": "error",
50-
"no-await-in-loop": "off",
51-
"@typescript-eslint/no-namespace": "off",
46+
'import/prefer-default-export': 'off',
47+
'import/no-default-export': 'error',
48+
'no-await-in-loop': 'off',
49+
'@typescript-eslint/no-namespace': 'off',
5250
},
5351
},
5452

@@ -58,54 +56,50 @@ export default [
5856
rules: {
5957
...config.rules,
6058
//new rules
61-
"no-restricted-syntax": "warn",
62-
"no-useless-escape": "warn",
63-
"max-classes-per-file": "warn",
64-
"no-underscore-dangle": "warn",
65-
"no-await-in-loop": "warn",
66-
"@typescript-eslint/no-unused-vars": "warn",
67-
"@typescript-eslint/consistent-type-definitions": "warn",
68-
"@typescript-eslint/ban-types": "warn",
59+
'no-restricted-syntax': 'warn',
60+
'no-useless-escape': 'warn',
61+
'max-classes-per-file': 'warn',
62+
'no-underscore-dangle': 'warn',
63+
'no-await-in-loop': 'warn',
64+
'@typescript-eslint/no-unused-vars': 'warn',
65+
'@typescript-eslint/consistent-type-definitions': 'warn',
66+
'@typescript-eslint/ban-types': 'warn',
6967
},
70-
})),
68+
})),
7169

7270
...scwTypescript.map(config => ({
7371
...config,
7472
files: [
75-
"./packages/clients/src/scw/**/*.ts",
76-
"./packages/clients/src/internal/**/*.ts",
73+
'./packages/clients/src/scw/**/*.ts',
74+
'./packages/clients/src/internal/**/*.ts',
7775
],
7876
rules: {
7977
...config.rules,
80-
"@typescript-eslint/no-unused-vars": "off",
81-
"@typescript-eslint/consistent-type-definitions": "off",
78+
'@typescript-eslint/no-unused-vars': 'off',
79+
'@typescript-eslint/consistent-type-definitions': 'off',
8280
},
83-
8481
})),
8582

8683
...scwTypescript.map(config => ({
8784
...config,
88-
files: ["**/*.test.ts", "__tests__/**/*.ts", "**/vite.config.ts"],
85+
files: ['**/*.test.ts', '__tests__/**/*.ts', '**/vite.config.ts'],
8986
rules: {
9087
...config.rules,
91-
"import/no-extraneous-dependencies": "off",
88+
'import/no-extraneous-dependencies': 'off',
9289
},
93-
9490
})),
9591

9692
...scwTypescript.map(config => ({
9793
...config,
98-
files: ["packages/clients/src/api/dedibox/v1/*.ts"],
94+
files: ['packages/clients/src/api/dedibox/v1/*.ts'],
9995
rules: {
10096
...config.rules,
101-
"no-use-before-define": "off",
102-
"@typescript-eslint/no-use-before-define": "off",
103-
"@typescript-eslint/no-unused-vars": "off",
104-
"@typescript-eslint/consistent-type-definitions": "off",
105-
"max-classes-per-file": "off",
106-
"no-restricted-syntax": "off",
97+
'no-use-before-define': 'off',
98+
'@typescript-eslint/no-use-before-define': 'off',
99+
'@typescript-eslint/no-unused-vars': 'off',
100+
'@typescript-eslint/consistent-type-definitions': 'off',
101+
'max-classes-per-file': 'off',
102+
'no-restricted-syntax': 'off',
107103
},
108-
109104
})),
110-
111-
];
105+
]

examples/nodejs-minimal/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as http from 'http'
12
import { loadProfileFromConfigurationFile } from '@scaleway/configuration-loader'
23
import { Registry, createClient } from '@scaleway/sdk'
3-
import * as http from 'http'
44

55
const hostname = '127.0.0.1'
66
const port = 3000

lerna.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"packages": [
3-
"packages/*"
4-
],
2+
"packages": ["packages/*"],
53
"npmClient": "pnpm",
64
"version": "independent",
75
"command": {

package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@
4949
]
5050
},
5151
"devDependencies": {
52+
"@biomejs/biome": "1.9.4",
5253
"@commitlint/cli": "19.7.1",
5354
"@commitlint/config-conventional": "19.7.1",
55+
"@manypkg/cli": "0.23.0",
5456
"@scaleway/eslint-config-react": "4.0.9",
57+
"@scaleway/random-name": "5.1.1",
5558
"@typescript-eslint/eslint-plugin": "latest",
5659
"@vitest/coverage-istanbul": "2.1.9",
5760
"@vitest/coverage-v8": "2.1.9",
@@ -69,17 +72,13 @@
6972
"lerna": "8.1.9",
7073
"lint-staged": "15.4.3",
7174
"prettier": "3.4.2",
75+
"react": "^19.0.0",
7276
"read-pkg": "9.0.1",
7377
"tsc-alias": "^1.8.10",
7478
"typedoc": "0.27.6",
7579
"typescript": "5.7.3",
7680
"vite": "5.4.15",
7781
"vitest": "2.1.9"
7882
},
79-
"packageManager": "[email protected]",
80-
"dependencies": {
81-
"@scaleway/random-name": "5.1.1",
82-
"biome": "^0.3.3",
83-
"react": "^19.0.0"
84-
}
83+
"packageManager": "[email protected]"
8584
}

packages/client/.eslintrc.cjs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const { join } = require('path');
1+
const { join } = require('path')
22

33
module.exports = {
44
rules: {
55
'import/no-extraneous-dependencies': [
66
'error',
7-
{ packageDir: [__dirname, join(__dirname, '../../')] }
8-
]
9-
}
10-
};
7+
{ packageDir: [__dirname, join(__dirname, '../../')] },
8+
],
9+
},
10+
}

packages/client/src/scw/errors/non-standard/unknown-resource-mapper.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ export class UnknownResourceMapper {
2525
// transform `Security group ` to `security_group`
2626
// `.replaceAll()` may be too recent to use yet.
2727
// that's why we're using `.split(' ').join('_')` for now.
28-
messageParts[0].trim().toLowerCase().split(' ').join('_'),
28+
messageParts[0]
29+
.trim()
30+
.toLowerCase()
31+
.split(' ')
32+
.join('_'),
2933
messageParts[1],
3034
)
3135
}

packages/client/src/vendor/base64/index.js

+37-37
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ for (var i = 0, len = code.length; i < len; ++i) {
1515
revLookup['-'.charCodeAt(0)] = 62
1616
revLookup['_'.charCodeAt(0)] = 63
1717

18-
function getLens (b64) {
18+
function getLens(b64) {
1919
var len = b64.length
2020

2121
if (len % 4 > 0) {
@@ -27,26 +27,24 @@ function getLens (b64) {
2727
var validLen = b64.indexOf('=')
2828
if (validLen === -1) validLen = len
2929

30-
var placeHoldersLen = validLen === len
31-
? 0
32-
: 4 - (validLen % 4)
30+
var placeHoldersLen = validLen === len ? 0 : 4 - (validLen % 4)
3331

3432
return [validLen, placeHoldersLen]
3533
}
3634

3735
// base64 is 4/3 + up to two characters of the original data
38-
export function byteLength (b64) {
36+
export function byteLength(b64) {
3937
var lens = getLens(b64)
4038
var validLen = lens[0]
4139
var placeHoldersLen = lens[1]
42-
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
40+
return ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen
4341
}
4442

45-
function _byteLength (b64, validLen, placeHoldersLen) {
46-
return ((validLen + placeHoldersLen) * 3 / 4) - placeHoldersLen
43+
function _byteLength(b64, validLen, placeHoldersLen) {
44+
return ((validLen + placeHoldersLen) * 3) / 4 - placeHoldersLen
4745
}
4846

49-
export function toByteArray (b64) {
47+
export function toByteArray(b64) {
5048
var tmp
5149
var lens = getLens(b64)
5250
var validLen = lens[0]
@@ -57,9 +55,7 @@ export function toByteArray (b64) {
5755
var curByte = 0
5856

5957
// if there are placeholders, only get up to the last complete 4 chars
60-
var len = placeHoldersLen > 0
61-
? validLen - 4
62-
: validLen
58+
var len = placeHoldersLen > 0 ? validLen - 4 : validLen
6359

6460
var i
6561
for (i = 0; i < len; i += 4) {
@@ -68,51 +64,53 @@ export function toByteArray (b64) {
6864
(revLookup[b64.charCodeAt(i + 1)] << 12) |
6965
(revLookup[b64.charCodeAt(i + 2)] << 6) |
7066
revLookup[b64.charCodeAt(i + 3)]
71-
arr[curByte++] = (tmp >> 16) & 0xFF
72-
arr[curByte++] = (tmp >> 8) & 0xFF
73-
arr[curByte++] = tmp & 0xFF
67+
arr[curByte++] = (tmp >> 16) & 0xff
68+
arr[curByte++] = (tmp >> 8) & 0xff
69+
arr[curByte++] = tmp & 0xff
7470
}
7571

7672
if (placeHoldersLen === 2) {
7773
tmp =
7874
(revLookup[b64.charCodeAt(i)] << 2) |
7975
(revLookup[b64.charCodeAt(i + 1)] >> 4)
80-
arr[curByte++] = tmp & 0xFF
76+
arr[curByte++] = tmp & 0xff
8177
}
8278

8379
if (placeHoldersLen === 1) {
8480
tmp =
8581
(revLookup[b64.charCodeAt(i)] << 10) |
8682
(revLookup[b64.charCodeAt(i + 1)] << 4) |
8783
(revLookup[b64.charCodeAt(i + 2)] >> 2)
88-
arr[curByte++] = (tmp >> 8) & 0xFF
89-
arr[curByte++] = tmp & 0xFF
84+
arr[curByte++] = (tmp >> 8) & 0xff
85+
arr[curByte++] = tmp & 0xff
9086
}
9187

9288
return arr
9389
}
9490

95-
function tripletToBase64 (num) {
96-
return lookup[num >> 18 & 0x3F] +
97-
lookup[num >> 12 & 0x3F] +
98-
lookup[num >> 6 & 0x3F] +
99-
lookup[num & 0x3F]
91+
function tripletToBase64(num) {
92+
return (
93+
lookup[(num >> 18) & 0x3f] +
94+
lookup[(num >> 12) & 0x3f] +
95+
lookup[(num >> 6) & 0x3f] +
96+
lookup[num & 0x3f]
97+
)
10098
}
10199

102-
function encodeChunk (uint8, start, end) {
100+
function encodeChunk(uint8, start, end) {
103101
var tmp
104102
var output = []
105103
for (var i = start; i < end; i += 3) {
106104
tmp =
107-
((uint8[i] << 16) & 0xFF0000) +
108-
((uint8[i + 1] << 8) & 0xFF00) +
109-
(uint8[i + 2] & 0xFF)
105+
((uint8[i] << 16) & 0xff0000) +
106+
((uint8[i + 1] << 8) & 0xff00) +
107+
(uint8[i + 2] & 0xff)
110108
output.push(tripletToBase64(tmp))
111109
}
112110
return output.join('')
113111
}
114112

115-
export function fromByteArray (uint8) {
113+
export function fromByteArray(uint8) {
116114
var tmp
117115
var len = uint8.length
118116
var extraBytes = len % 3 // if we have 1 byte left, pad 2 bytes
@@ -121,24 +119,26 @@ export function fromByteArray (uint8) {
121119

122120
// go through the array every three bytes, we'll deal with trailing stuff later
123121
for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) {
124-
parts.push(encodeChunk(uint8, i, (i + maxChunkLength) > len2 ? len2 : (i + maxChunkLength)))
122+
parts.push(
123+
encodeChunk(
124+
uint8,
125+
i,
126+
i + maxChunkLength > len2 ? len2 : i + maxChunkLength,
127+
),
128+
)
125129
}
126130

127131
// pad the end with zeros, but make sure to not forget the extra bytes
128132
if (extraBytes === 1) {
129133
tmp = uint8[len - 1]
130-
parts.push(
131-
lookup[tmp >> 2] +
132-
lookup[(tmp << 4) & 0x3F] +
133-
'=='
134-
)
134+
parts.push(lookup[tmp >> 2] + lookup[(tmp << 4) & 0x3f] + '==')
135135
} else if (extraBytes === 2) {
136136
tmp = (uint8[len - 2] << 8) + uint8[len - 1]
137137
parts.push(
138138
lookup[tmp >> 10] +
139-
lookup[(tmp >> 4) & 0x3F] +
140-
lookup[(tmp << 2) & 0x3F] +
141-
'='
139+
lookup[(tmp >> 4) & 0x3f] +
140+
lookup[(tmp << 2) & 0x3f] +
141+
'=',
142142
)
143143
}
144144

0 commit comments

Comments
 (0)