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

refactor!: replace to fetch api #636

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
File renamed without changes.
10 changes: 10 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { defaults: tsjPreset } = require('ts-jest/presets');

module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['<rootDir>/test/integration/**/*.ts'],
transform: {
...tsjPreset.transform
}
};
10 changes: 0 additions & 10 deletions jest.config.js

This file was deleted.

File renamed without changes.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
"devDependencies": {
"@commitlint/cli": "^17.4.3",
"@commitlint/config-conventional": "^17.4.3",
"@types/jest": "^27.0.1",
"@types/node": "^16.18.12",
"@typescript-eslint/eslint-plugin": "~5.52.0",
"@typescript-eslint/parser": "~5.52.0",
"@types/jest": "^29.5.10",
"@types/node": "^18.18.12",
"@typescript-eslint/eslint-plugin": "~6.12.0",
"@typescript-eslint/parser": "~6.12.0",
"conventional-github-releaser": "^3.1.5",
"eslint": "^8.34.0",
"eslint-config-prettier": "~8.6.0",
"eslint-plugin-prettier": "~4.2.1",
"get-port": "^5.1.1",
"husky": "^6.0.0",
"is-ci": "^3.0.0",
"jest": "^27.0.0",
"jest": "^29.7.0",
"lint-staged": "^13.1.2",
"microbundle": "^0.15.1",
"prettier": "~2.8.4",
"ts-jest": "^27.0.1",
"typescript": "~4.9.5"
"ts-jest": "^29.1.1",
"typescript": "~5.3.2"
},
"engines": {
"node": ">= 16.13.0"
"node": ">= 18.12.0"
},
"exports": {
"import": "./dist/index.modern.js",
Expand Down
File renamed without changes.
34 changes: 0 additions & 34 deletions src/formdata.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@

export { default as XMLHttpRequest } from './xmlhttprequest';
export { default as XMLHttpRequestUpload } from './xmlhttprequestupload';
export { default as FormData } from './formdata';
107 changes: 107 additions & 0 deletions src/internal/dispatchprogress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* @license
* Copyright (c) 2023 Yamagishi Kazutoshi
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

type DispatchProgressOptions = {
target: EventTarget;
total?: number;
};

export class DispatchProgressTransformer
implements Transformer<Uint8Array, Uint8Array>
{
readonly #target: EventTarget;
readonly #total: number;

#loaded = 0;

constructor({ target, total = 0 }: DispatchProgressOptions) {
this.#target = target;
this.#total = total;
}

flush() {
console.log('flush');

this.#target.dispatchEvent(
new ProgressEvent('load', {
loaded: this.#loaded,
total: this.#total
})
);
this.#target.dispatchEvent(
new ProgressEvent('loadend', {
loaded: this.#loaded,
total: this.#total
})
);
}

start() {
console.log('start');

this.#target.dispatchEvent(
new ProgressEvent('loadstart', {
loaded: this.#loaded,
total: this.#total
})
);
}

transform(
chunk: Uint8Array,
controller: TransformStreamDefaultController<Uint8Array>
) {
controller.enqueue(chunk);

console.log('transform: ', chunk);

this.#loaded += chunk.length;

this.#target.dispatchEvent(
new ProgressEvent('progress', {
loaded: this.#loaded,
total: this.#total
})
);
}
}

export class DispatchProgressStream
implements TransformStream<Uint8Array, Uint8Array>
{
readonly #transformStream: TransformStream<Uint8Array, Uint8Array>;

constructor({ target, total = 0 }: DispatchProgressOptions) {
this.#transformStream = new TransformStream(
new DispatchProgressTransformer({ target, total })
);
}

get readable(): ReadableStream<Uint8Array> {
return this.#transformStream.readable;
}

get writable(): WritableStream<Uint8Array> {
return this.#transformStream.writable;
}
}
7 changes: 7 additions & 0 deletions src/internal/readablestream.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function createEmptyReadableStream(): ReadableStream<Uint8Array> {
return new ReadableStream({
start(controller) {
controller.close();
}
});
}
Loading
Loading