Skip to content

Commit

Permalink
curl & websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
kirill-782 committed Dec 29, 2023
1 parent ee775ce commit fc4eed5
Show file tree
Hide file tree
Showing 9 changed files with 493 additions and 14 deletions.
26 changes: 16 additions & 10 deletions includes/curl.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ declare module "curl" {

export function curl_easy_init(): CurlHandle;

export type HttpHeaders = Record<string, string | Array<string>>;

interface CurlOptToType {
CURLOPT_URL: string;
CURLOPT_DOH_URL: string;
Expand Down Expand Up @@ -38,6 +40,8 @@ declare module "curl" {
CURLOPT_SEEKFUNCTION: SeekCallback;
CURLOPT_XFERINFOFUNCTION: ProgressCallback;
CURLOPT_HEADERFUNCTION: HeaderCallback;

CURLOPT_HTTPHEADER: HttpHeaders;
}

export type ReaadCallback = (this: CurlHandle, buffer: ArrayBuffer) => number;
Expand Down Expand Up @@ -68,11 +72,7 @@ declare module "curl" {

export function curl_easy_pause(curl: CurlHandle, bitmask: number): void;

export function curl_easy_headers(
curl: CurlHandle,
origin: number,
request: number,
): Record<string, string | Array<string>>;
export function curl_easy_headers(curl: CurlHandle, origin: number, request: number): HttpHeaders;

export function curl_easy_cleanup(curl: CurlHandle): void;

Expand Down Expand Up @@ -113,18 +113,23 @@ declare module "curl" {

export function curl_ws_recv(curl: CurlHandle, buffer: ArrayBuffer | Uint8Array): CurlRecvResult;

interface CurlSendResult {
result: CurlEConstants[keyof CurlEConstants];
sent: number;
}

export function curl_ws_send(
curl: CurlHandle,
buffer: ArrayBuffer | Uint8Array,
fragsize: number,
flags: number,
): void;
): CurlSendResult;

export function update(): void;

export const constants: CurlEConstants & CurlConstants & CurlInfoConstants & CurlOptConstants;

type CurlEConstants = {
export type CurlEConstants = {
readonly CURLE_OK: 0;
readonly CURLE_UNSUPPORTED_PROTOCOL: 1;
readonly CURLE_FAILED_INIT: 2;
Expand Down Expand Up @@ -227,7 +232,7 @@ declare module "curl" {
readonly CURLE_UNRECOVERABLE_POLL: 99;
};

type CurlConstants = {
export type CurlConstants = {
readonly CURL_WRITEFUNC_ERROR: number;
readonly CURL_WRITEFUNC_PAUSE: number;
readonly CURL_MAX_WRITE_SIZE: number;
Expand All @@ -242,6 +247,7 @@ declare module "curl" {
readonly CURLWS_CONT: number;
readonly CURLWS_CLOSE: number;
readonly CURLWS_PING: number;
readonly CURLWS_OFFSET: number;
readonly CURLPAUSE_RECV: number;
readonly CURLPAUSE_SEND: number;
readonly CURLPAUSE_ALL: number;
Expand All @@ -253,7 +259,7 @@ declare module "curl" {
readonly CURLH_PSEUDO: number;
};

type CurlInfoConstants = {
export type CurlInfoConstants = {
readonly CURLINFO_NONE: unique symbol;
readonly CURLINFO_EFFECTIVE_URL: unique symbol;
readonly CURLINFO_RESPONSE_CODE: unique symbol;
Expand Down Expand Up @@ -329,7 +335,7 @@ declare module "curl" {
readonly CURLINFO_LASTONE: unique symbol;
};

type CurlOptConstants = {
export type CurlOptConstants = {
readonly CURLOPT_WRITEDATA: unique symbol;
readonly CURLOPT_URL: unique symbol;
readonly CURLOPT_PORT: unique symbol;
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"bundle-polyfill": "esbuild ./src/polyfill.ts --bundle --outfile=build/esbuild/polyfill.js --format=esm --external:unsafe --target=es2020 --alias:@war3js/unsafe=unsafe",
"bundle-bootstrap": "esbuild ./src/index.ts --bundle --outfile=build/esbuild/bootstrap.js --format=esm --external:unsafe --target=es2020 --alias:@war3js/unsafe=unsafe",
"bundle-polyfill": "esbuild ./src/polyfill.ts --bundle --outfile=build/esbuild/polyfill.js --format=esm --external:curl --external:unsafe --target=es2020 --alias:@war3js/unsafe=unsafe",
"bundle-bootstrap": "esbuild ./src/index.ts --bundle --outfile=build/esbuild/bootstrap.js --format=esm --external:curl --external:unsafe --target=es2020 --alias:@war3js/unsafe=unsafe",
"bundle": "npm run bundle-polyfill && npm run bundle-bootstrap",
"start": "ts-node-esm ./src/test.ts",
"lint": "eslint ./src/ --ext .ts --rulesdir ./eslint/rules/",
"typesgen": "tsc && dts-bundle-generator build/tsc/types/index.d.ts -o build/dts-bundle/out.d.ts --export-referenced-types=false --external-inlines=readable-stream --external-inlines=@war3js/events --external-imports=@war3js/unsafe --inline-declare-global=true && ts-node-esm ./src/typesAppener.ts && node ./utils/tsconfigPrepare.js && tsc -p ./build/fullTypes/tsconfig.json && node ./utils/tsconfigRemove.js",
"typesgen": "tsc && dts-bundle-generator build/tsc/types/index.d.ts -o build/dts-bundle/out.d.ts --export-referenced-types=false --external-inlines=readable-stream --external-inlines=@war3js/events --external-inlines=@war3js/headers-polyfill --external-imports=@war3js/unsafe --inline-declare-global=true && ts-node-esm ./src/typesAppener.ts && node ./utils/tsconfigPrepare.js && tsc -p ./build/fullTypes/tsconfig.json && node ./utils/tsconfigRemove.js",
"docgen": "node ./utils/tsconfigPrepare.js && typedoc && node ./utils/tsconfigRemove.js",
"clean": "node ./utils/clean.js",
"build": "npm run bundle && npm run typesgen && npm run docgen"
Expand All @@ -28,6 +28,7 @@
"dts-bundle-generator": "^8.1.1",
"esbuild": "^0.19.4",
"eslint": "^8.53.0",
"@war3js/headers-polyfill": "^4.0.3",
"jass-to-ast": "^2.0.2",
"prettier": "3.0.3",
"readable-stream": "^4.5.1",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ builder.addMethods(Destructable, "destructable");
builder.addMethods(Item, "item");

export { TextDecoder, TextEncoder } from "text-decoding";
export { Headers } from "@war3js/headers-polyfill";

export * from "./handles/Widget.js";
export * from "./handles/Unit.js";
Expand All @@ -74,6 +75,8 @@ export {

export { UnitState, LimitOp } from "./services/emitters/UnitStateEmiter.js";

export { Websocket } from "./services/websocket/Websocket.js";

// -- ONLY FOR dts-bundle

declare global {
Expand Down
7 changes: 7 additions & 0 deletions src/services/fetch/FetchRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface FetchRequest {
method?: string;
headers?: Record<string, Array<string> | string>;
credentials?: "omit" | "include";
redirect?: "flow" | "error";
signal?: AbortSignal;
}
6 changes: 6 additions & 0 deletions src/services/fetch/fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { consoleLog } from "@war3js/unsafe";
import { FetchRequest } from "./FetchRequest.js";

export const fetch = (url: string, options?: FetchRequest) => {
consoleLog(0, url, options);
};
Loading

0 comments on commit fc4eed5

Please sign in to comment.