Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP TypeScript code refactor #1128

Closed
wants to merge 86 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
34a20ab
support TypeScript
trim21 May 2, 2023
8b52976
diff
trim21 May 2, 2023
3e94577
Merge remote-tracking branch 'upstream/master' into ts
trim21 May 2, 2023
c21c335
fix lint
trim21 May 2, 2023
9844650
run on nodejs20
trim21 May 2, 2023
c03390b
fix ci
trim21 May 2, 2023
dcc4191
eslinl rule diff
trim21 May 2, 2023
56af6f2
add npm run build to "prepublishOnly"
trim21 May 2, 2023
d6289be
add eslint rule to check import/export
trim21 May 2, 2023
8edcee8
add eslint rule to disable default export
trim21 May 2, 2023
e1ad697
simplify eslint rule
trim21 May 2, 2023
ad13a82
Update CONTRIBUTING.md
trim21 May 2, 2023
6783ac0
tsconfig
trim21 May 2, 2023
8944f93
declarationMap
trim21 May 2, 2023
73c2144
migrate
trim21 May 2, 2023
ca09d53
fix
trim21 May 2, 2023
346e9ec
type
trim21 May 2, 2023
955efa8
refactor
trim21 May 2, 2023
97bd96b
assert
trim21 May 2, 2023
4dd8ae4
refactor
trim21 May 2, 2023
8df43cd
refactor
trim21 May 2, 2023
f6551a6
set readonly
trim21 May 2, 2023
21e070a
migrate helpers.js to ts
trim21 May 5, 2023
37e6528
no need @internal on un-exported variable
trim21 May 5, 2023
af73d77
remove qs
trim21 May 5, 2023
367ae09
export all
trim21 May 5, 2023
1a23207
timeout
trim21 May 5, 2023
c9d7977
fix pipesetup
trim21 May 5, 2023
a7edf5e
dead code
trim21 May 5, 2023
be1c8de
use type narrow
trim21 May 5, 2023
e77d3e5
types
trim21 May 5, 2023
be6135d
remove type without actually value
trim21 May 5, 2023
4fc5d37
region
trim21 May 5, 2023
457594a
export type
trim21 May 5, 2023
13c4ccb
no need to split
trim21 May 5, 2023
411b222
Merge branch 'master' into ts/helpers
trim21 May 5, 2023
01e5281
type check
trim21 May 5, 2023
9959a78
use enum
trim21 May 5, 2023
ebb50aa
filename
trim21 May 5, 2023
a45f7e0
diff
trim21 May 5, 2023
ca38e38
deprecated type
trim21 May 5, 2023
deb282e
helper file
trim21 May 5, 2023
767303e
fix
trim21 May 5, 2023
f9fe211
Update src/helpers.ts
trim21 May 5, 2023
4f3629a
perfer const in typescript
trim21 May 5, 2023
2815daa
fix pipesetup type
trim21 May 5, 2023
3f4cdf7
type rename
trim21 May 6, 2023
53d161f
fix type
trim21 May 6, 2023
9fe8a3d
fix type
trim21 May 6, 2023
d6cb219
ci
trim21 May 6, 2023
7d0f34c
chore: upgrade deps
trim21 May 6, 2023
5aebc4d
upgrade old deps
trim21 May 6, 2023
d2052b5
ignore pnpm lock
trim21 May 6, 2023
8195e79
speedup build
trim21 May 6, 2023
1712bd5
bucket and object js required
trim21 May 6, 2023
aafe0fa
fix request header
trim21 May 6, 2023
401aded
fix enc headers
trim21 May 6, 2023
826eda1
fix enc type
trim21 May 6, 2023
4ec735a
import first
trim21 May 6, 2023
e98ed16
import as es
trim21 May 6, 2023
d3cd80d
move to internal
trim21 May 6, 2023
c3899a1
Merge branch 'ts/helpers' into refactor-client
trim21 May 6, 2023
3dadd5e
type name
trim21 May 6, 2023
6b83b7d
fix arg name
trim21 May 6, 2023
cad3f60
fix metadata
trim21 May 6, 2023
535cbb8
fix
trim21 May 6, 2023
76afbc3
move files
trim21 May 6, 2023
1561886
fix
trim21 May 6, 2023
96b07de
fix
trim21 May 6, 2023
ab54a82
type-name
trim21 May 6, 2023
b00873e
use eventemitter3
trim21 May 9, 2023
e68ddfd
Merge branch 'master' into refactor-client
trim21 May 13, 2023
ea7500a
fix
trim21 May 13, 2023
38adaf0
remove qs
trim21 May 13, 2023
fd7a065
Merge branch 'master' into refactor-client
trim21 May 18, 2023
09a74f2
tsc
trim21 May 18, 2023
08b999b
fix fs/promise in nodejs 12
trim21 May 18, 2023
a99fc6e
dupe code
trim21 May 18, 2023
f659a06
diff
trim21 May 18, 2023
0460739
diff
trim21 May 18, 2023
9e5f09a
merge
trim21 May 21, 2023
ce87fb8
Merge branch 'master' into refactor-client
trim21 May 21, 2023
2781c16
diff
trim21 May 21, 2023
68650a8
Merge remote-tracking branch 'upstream/master' into refactor-client
trim21 May 21, 2023
63c715c
Merge branch 'master' into refactor-client
trim21 Nov 5, 2023
99386cd
fix
trim21 Nov 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 64 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@
"async": "^3.2.4",
"block-stream2": "^2.1.0",
"browser-or-node": "^2.1.1",
"buffer-crc32": "^0.2.13",
"crc-32": "^1.2.2",
"fast-xml-parser": "^4.2.2",
"ipaddr.js": "^2.0.1",
"json-stream": "^1.0.0",
"lodash": "^4.17.21",
"mime-types": "^2.1.35",
"query-string": "^7.1.3",
"query-string": "^7.1.1",
"stream-json": "^1.7.5",
"through2": "^4.0.2",
"web-encoding": "^1.1.5",
"xml": "^1.0.1",
Expand All @@ -105,9 +105,11 @@
"@babel/register": "^7.21.0",
"@nodelib/fs.walk": "^1.2.8",
"@types/async": "^3.2.20",
"@types/block-stream2": "^2.1.0",
"@types/lodash": "^4.14.194",
"@types/mime-types": "^2.1.1",
"@types/node": "^20.1.0",
"@types/stream-json": "^1.7.3",
"@types/through2": "^2.0.38",
"@types/xml": "^1.0.8",
"@types/xml2js": "^0.4.11",
Expand All @@ -125,6 +127,7 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-unicorn": "^47.0.0",
"eslint-plugin-unused-imports": "^2.0.0",
"eventemitter3": "^5.0.1",
"husky": "^8.0.3",
"lint-staged": "^13.2.2",
"mocha": "^10.2.0",
Expand Down
1 change: 1 addition & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export class InvalidXMLError extends ExtendableError {}
*/
export class S3Error extends ExtendableError {
code?: string
region?: string
}

export class IsValidBucketNameError extends ExtendableError {}
32 changes: 32 additions & 0 deletions src/internal/as-callback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { isFunction } from './helper.ts'

export function asCallback<T = void>(
cb: undefined | ((err: unknown | null, result: T) => void),
promise: Promise<T>,
): Promise<T> | void {
if (cb === undefined) {
return promise
}

if (!isFunction(cb)) {
throw new TypeError(`callback should be of type "function", got ${cb}`)
}

promise.then(
(result) => {
cb(null, result)
},
(err) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
cb(err)
},
)
}

export function asCallbackFn<T = void>(
cb: undefined | ((err: unknown | null, result: T) => void),
asyncFn: () => Promise<T>,
): Promise<T> | void {
return asCallback(cb, asyncFn())
}
14 changes: 14 additions & 0 deletions src/internal/async.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// promise helper for stdlib

import * as fs from 'node:fs'
import * as stream from 'node:stream'
import { promisify } from 'node:util'

// TODO: use "node:fs/promise" directly after we stop testing on nodejs 12
export { promises as fsp } from 'node:fs'
export const streamPromise = {
// node:stream/promises Added in: v15.0.0
pipeline: promisify(stream.pipeline),
}

export const fstat = promisify(fs.fstat)
10 changes: 10 additions & 0 deletions src/internal/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ export function isFunction(arg: unknown): arg is AnyFunction {
return typeof arg === 'function'
}

/**
* check if typeof arg function or undefined
*/
export function isOptionalFunction(arg: unknown): arg is undefined | AnyFunction {
if (arg === undefined) {
return true
}
return typeof arg === 'function'
}

/**
* check if typeof arg string
*/
Expand Down
Loading